Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Dec 4, 2022
1 parent f09df77 commit ae6cba5
Show file tree
Hide file tree
Showing 16 changed files with 722 additions and 258 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
41 changes: 35 additions & 6 deletions devWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,51 @@ const main = async () => {
const data = await generate({
raw: process.argv.includes('--raw'),
test: process.argv.includes('--test'),
pokeApi: process.argv.includes('--pokeapi') || { baseStats, tempEvos, types },
pokeApi: process.argv.includes('--pokeapi') || {
baseStats,
tempEvos,
types,
},
})

if (process.argv.includes('--test')) {
if (process.argv.includes('--invasions')) {
fs.writeFile('./invasions.json', JSON.stringify(await invasions(), null, 2), 'utf8', () => {})
fs.writeFile(
'./invasions.json',
JSON.stringify(await invasions(), null, 2),
'utf8',
() => {},
)
}
if (data?.AllPokeApi) {
const { baseStats, tempEvos, types } = data.AllPokeApi
fs.writeFile('./static/baseStats.json', JSON.stringify(baseStats, null, 2), 'utf8', () => {})
fs.writeFile('./static/tempEvos.json', JSON.stringify(tempEvos, null, 2), 'utf8', () => {})
fs.writeFile('./static/types.json', JSON.stringify(types, null, 2), 'utf8', () => {})
fs.writeFile(
'./static/baseStats.json',
JSON.stringify(baseStats, null, 2),
'utf8',
() => {},
)
fs.writeFile(
'./static/tempEvos.json',
JSON.stringify(tempEvos, null, 2),
'utf8',
() => {},
)
fs.writeFile(
'./static/types.json',
JSON.stringify(types, null, 2),
'utf8',
() => {},
)
delete data.AllPokeApi
}
if (data) {
fs.writeFile('./masterfile.json', JSON.stringify(data, null, 2), 'utf8', () => {})
fs.writeFile(
'./masterfile.json',
JSON.stringify(data, null, 2),
'utf8',
() => {},
)
}
}
console.timeEnd('Generated in')
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"invasions": "ts-node devWrapper.ts --test --invasions",
"test": "tsc && ./node_modules/.bin/jest",
"format": "prettier --config .prettierrc 'src/**/*.ts' --write",
"publishBuild": "rm -r dist && tsc"
"publishBuild": "rm -r dist && tsc",
"prettier": "prettier --write \"**/*.ts\""
},
"repository": {
"type": "git",
Expand Down
11 changes: 10 additions & 1 deletion src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,16 @@ const baseTemplate: FullTemplate = {
prefix: '{{',
suffix: '}}',
},
questTitleTermsToSkip: ['gofest', 'gotour', 'dialog', 'title', 'summer_return', '_complete_', 'location', 'vote'],
questTitleTermsToSkip: [
'gofest',
'gotour',
'dialog',
'title',
'summer_return',
'_complete_',
'location',
'vote',
],
masterfileLocale: false,
manualTranslations: true,
mergeCategories: true,
Expand Down
51 changes: 39 additions & 12 deletions src/classes/Invasion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export default class Invasion extends Masterfile {

async customInvasions(override: boolean = false): Promise<InvasionInfo> {
try {
if (this.options.customInvasions === true || (this.options.customInvasions === undefined && override)) {
if (
this.options.customInvasions === true ||
(this.options.customInvasions === undefined && override)
) {
return this.fetch(
'https://raw.githubusercontent.com/WatWowMap/Masterfile-Generator/master/custom-invasions.json',
)
Expand Down Expand Up @@ -47,10 +50,20 @@ export default class Invasion extends Masterfile {
}

formatGrunts(character: string) {
const base = character.replace('CHARACTER_', '').replace('_MALE', '').replace('_FEMALE', '')
const type = base.replace('EXECUTIVE_', '').replace('_GRUNT', '').replace('EVENT_', '')
const grunt = base.split('_').length > 1 ? base.replace(`${type}`, '').replace('_', '') : base
let gender = character.includes('MALE') || character.includes('FEMALE') ? 1 : 0
const base = character
.replace('CHARACTER_', '')
.replace('_MALE', '')
.replace('_FEMALE', '')
const type = base
.replace('EXECUTIVE_', '')
.replace('_GRUNT', '')
.replace('EVENT_', '')
const grunt =
base.split('_').length > 1
? base.replace(`${type}`, '').replace('_', '')
: base
let gender =
character.includes('MALE') || character.includes('FEMALE') ? 1 : 0
if (character.includes('FEMALE')) {
gender = 2
}
Expand All @@ -70,7 +83,10 @@ export default class Invasion extends Masterfile {
Object.entries(Rpc.EnumWrapper.InvasionCharacter).forEach((proto) => {
try {
const [name, id] = proto
if ((this.options.includeBalloons && name.includes('BALLOON')) || !name.includes('BALLOON_')) {
if (
(this.options.includeBalloons && name.includes('BALLOON')) ||
!name.includes('BALLOON_')
) {
const pogoInfo = invasionData[id]
this.parsedInvasions[id] = {
id: +id,
Expand All @@ -82,20 +98,31 @@ export default class Invasion extends Masterfile {
thirdReward: false,
}
if (pogoInfo && pogoInfo.active) {
this.parsedInvasions[id].firstReward = pogoInfo.lineup.rewards.includes(0)
this.parsedInvasions[id].secondReward = pogoInfo.lineup.rewards.includes(1)
this.parsedInvasions[id].thirdReward = pogoInfo.lineup.rewards.includes(2)
this.parsedInvasions[id].firstReward =
pogoInfo.lineup.rewards.includes(0)
this.parsedInvasions[id].secondReward =
pogoInfo.lineup.rewards.includes(1)
this.parsedInvasions[id].thirdReward =
pogoInfo.lineup.rewards.includes(2)
this.parsedInvasions[id].encounters = []

positions.forEach((position, i) => {
pogoInfo.lineup.team[i].forEach((pkmn) => {
this.parsedInvasions[id].encounters.push({ id: pkmn.id, formId: pkmn.form, position })
this.parsedInvasions[id].encounters.push({
id: pkmn.id,
formId: pkmn.form,
position,
})
})
this.parsedInvasions[id].encounters.sort((a, b) => a.id - b.id)
this.parsedInvasions[id].encounters.sort((a, b) => a.position.localeCompare(b.position))
this.parsedInvasions[id].encounters.sort((a, b) =>
a.position.localeCompare(b.position),
)
})
} else if (this.options.placeholderData) {
this.parsedInvasions[id].encounters = positions.map((position) => ({ position }))
this.parsedInvasions[id].encounters = positions.map((position) => ({
position,
}))
}
}
} catch (e) {
Expand Down
9 changes: 7 additions & 2 deletions src/classes/Item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ export default class Item extends Masterfile {
},
templateId,
} = object
if (!this.options.minTrainerLevel || !dropTrainerLevel || dropTrainerLevel <= this.options.minTrainerLevel) {
const id = typeof itemId === 'string' ? Rpc.Item[itemId as ItemProto] : itemId
if (
!this.options.minTrainerLevel ||
!dropTrainerLevel ||
dropTrainerLevel <= this.options.minTrainerLevel
) {
const id =
typeof itemId === 'string' ? Rpc.Item[itemId as ItemProto] : itemId
this.parsedItems[id] = {
itemId: id,
itemName: this.capitalize(templateId.replace('ITEM_', '')),
Expand Down
21 changes: 10 additions & 11 deletions src/classes/Masterfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ if (typeof fetch === 'undefined') {
export default class Masterfile {
customFieldNames: { [id: string]: string }
genders: { [id: string]: string }
protos: any


constructor() {
this.customFieldNames = {}
this.genders = {
Expand All @@ -20,7 +19,7 @@ export default class Masterfile {

static templateMerger(
template: { [key: string]: any },
base: FullTemplate
base: FullTemplate,
): FullTemplate {
const baseline: { [key: string]: any } = base
const merged: { [key: string]: any } = {}
Expand Down Expand Up @@ -126,7 +125,7 @@ export default class Masterfile {
templater(
data: any,
settings: { template: any; options: Options },
reference: FinalResult = {}
reference: FinalResult = {},
) {
// loops through the raw data and outputs the desired template
const { template, options } = settings
Expand All @@ -145,7 +144,7 @@ export default class Masterfile {
fieldKey: string,
fieldValue: any,
templateChild: any,
data: any
data: any,
) => {
// turns integer references into values
const isObj = options.keys[fieldKey]
Expand Down Expand Up @@ -192,7 +191,7 @@ export default class Masterfile {
fieldKey: string,
x: number,
templateChild: any,
data: any
data: any,
) => {
// checks which fields are in the template and if the data is an object, loops through again
let returnedObj: any = {}
Expand Down Expand Up @@ -224,15 +223,15 @@ export default class Masterfile {
subFieldKey,
subFieldValue,
templateChild[fieldKey],
data
data,
)
} else {
if (options.customChildObj[subFieldKey]) {
customChildObj(
returnedObj,
subFieldKey,
customKey,
subFieldValue
subFieldValue,
)
} else if (subFieldValue !== undefined) {
returnedObj[customKey] = subFieldValue
Expand All @@ -242,7 +241,7 @@ export default class Masterfile {
})
} catch (e) {
console.warn(
`Ref or X is undefined and it probably shouldn't be for ${reference}[${fieldKey}][${x}]`
`Ref or X is undefined and it probably shouldn't be for ${reference}[${fieldKey}][${x}]`,
)
}
return returnedObj
Expand All @@ -252,7 +251,7 @@ export default class Masterfile {
target: any,
key: string,
customKey: string,
field: any
field: any,
) => {
const customObj = options.customChildObj[key]
if (!target[customObj]) {
Expand Down Expand Up @@ -280,7 +279,7 @@ export default class Masterfile {
fieldKey,
fieldValue,
template,
data[id]
data[id],
)
} else {
if (options.customChildObj[fieldKey]) {
Expand Down
3 changes: 2 additions & 1 deletion src/classes/Move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export default class Moves extends Masterfile {
data: { combatMove },
} = object
try {
const id: number = Rpc.HoloPokemonMove[templateId.substring(18) as MoveProto]
const id: number =
Rpc.HoloPokemonMove[templateId.substring(18) as MoveProto]
this.parsedMoves[id] = {
moveId: id,
moveName: this.capitalize(combatMove.uniqueId.replace('_FAST', '')),
Expand Down
Loading

0 comments on commit ae6cba5

Please sign in to comment.