-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathgenerate.js
More file actions
122 lines (114 loc) · 4 KB
/
generate.js
File metadata and controls
122 lines (114 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const { promises: fs } = require('node:fs')
const Fetch = require('node-fetch')
const { generate } = require('pogo-data-generator')
const formatOutput = (templateName, data) =>
templateName === 'master-latest-rotomata.json'
? JSON.stringify(data)
: JSON.stringify(data, null, 2)
const fetch = async (url) => {
try {
const data = await Fetch(url)
if (!data.ok) {
throw new Error(`${data.status} ${data.statusText} URL: ${url}`)
}
return await data.json()
} catch (e) {
console.error(e, `Unable to fetch ${url}`)
}
}
async function masterfile() {
const templates = await fs.readdir('./templates')
const pmsfQuestTypes = await fetch(
'https://raw.githubusercontent.com/pmsf/PMSF/develop/static/data/questtype.json'
)
await Promise.all(
templates.map(async (templateName) => {
try {
console.log('Generating', templateName)
const template = JSON.parse(
await fs.readFile(`./templates/${templateName}`)
)
const newData = await generate({
template,
raw: templateName === 'master-latest-raw.json',
// translationApkUrl:
// 'https://raw.githubusercontent.com/turtiesocks/pogo_assets/master/Texts/Latest%20APK/JSON/i18n_english.json',
})
if (
templateName === 'master-latest-poracle.json' ||
templateName === 'master-latest.json'
) {
const mergedQuestTypes = {}
const questKey =
templateName === 'master-latest-poracle.json'
? 'questTypes'
: 'quest_types'
Object.keys(newData[questKey]).forEach((key) => {
mergedQuestTypes[key] =
pmsfQuestTypes[key] && pmsfQuestTypes[key].text.includes('{')
? pmsfQuestTypes[key]
: newData[questKey][key]
})
newData[questKey] = mergedQuestTypes
if (templateName === 'master-latest.json') {
newData.type_ids = JSON.parse(
await fs.readFile('./master-latest-react-map.json')
).types
newData.throw_types = {
10: 'Nice',
11: 'Great',
12: 'Excellent',
13: 'Curveball',
}
}
}
if (
templateName === 'master-latest-poracle.json' ||
templateName === 'master-latest-everything.json'
) {
delete newData.translations
}
await fs.writeFile(
`./${templateName}`,
formatOutput(templateName, newData)
)
if (templateName === 'master-latest.json') {
const pokedex = []
for (const [pokemonId, pokemon] of Object.entries(newData.pokemon)) {
if (!(pokemon.attack && pokemon.defense && pokemon.stamina))
continue
const pushEntry = (stats, name) =>
pokedex.push(
`{id:${pokemonId},name:` +
JSON.stringify(
name === null ? pokemon.name : `${pokemon.name} (${name})`
) +
`,at:${stats.attack},df:${stats.defense},st:${stats.stamina}}`
)
pushEntry(pokemon, null)
for (const form of Object.values(pokemon.forms)) {
if (form.attack && form.defense && form.stamina)
pushEntry(form, form.name)
}
for (const [id, evo] of Object.entries(
pokemon.temp_evolutions || {}
)) {
if (evo.attack && evo.defense && evo.stamina)
pushEntry(
evo,
['Unset', 'Mega', 'Mega X', 'Mega Y', 'Primal', 'Mega Z'][id]
)
}
}
await fs.writeFile('./pokedex.js', `pokedex=[${pokedex.join(',')}]`)
}
} catch (e) {
console.error(e, `Unable to process ${templateName}`)
}
})
)
}
module.exports.masterfile = masterfile
if (require.main === module) {
masterfile().then(() => console.log('Masterfiles Generated'))
}