forked from FreezingMoon/AncientBeast
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request FreezingMoon#2436 from allmtz/master
Replace units.json with units.ts FreezingMoon#1969
- Loading branch information
Showing
7 changed files
with
4,041 additions
and
4,013 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { unitData } from './units'; | ||
|
||
// Enables autocomplete for `key` | ||
function getKeyValue<T extends object, K extends keyof T>(obj: T, key: K) { | ||
return obj[key]; | ||
} | ||
|
||
// Generate several arrays, each containing the values corresponding to the specified key | ||
const realms = unitData.map((unit) => getKeyValue(unit, 'realm')); | ||
const unitNames = unitData.map((unit) => getKeyValue(unit, 'name')); | ||
const unitLevels = unitData.map((unit) => getKeyValue(unit, 'level')); | ||
|
||
// Create an array containing the possible `creature.type` combinations. | ||
// In `game.ts`: creature.type = realm.toUpperCase() + level, | ||
const creatureTypes = realms.map((realm) => { | ||
for (let i in unitLevels) { | ||
return `${realm}${unitLevels[i]}` as const; | ||
} | ||
}); | ||
|
||
// Create unions from the various arrays | ||
export type UnitName = typeof unitNames[number]; | ||
export type Realm = typeof realms[number]; | ||
export type Level = typeof unitLevels[number]; | ||
export type CreatureType = typeof creatureTypes[number]; |
Oops, something went wrong.