Skip to content

Commit

Permalink
Merge pull request FreezingMoon#2436 from allmtz/master
Browse files Browse the repository at this point in the history
Replace units.json with units.ts FreezingMoon#1969
  • Loading branch information
DreadKnight authored Jul 19, 2023
2 parents e13801e + 2c5db70 commit 0439f68
Show file tree
Hide file tree
Showing 7 changed files with 4,041 additions and 4,013 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/creature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ const getHexesMock = () => {
return arr;
};

import data from '../data/units.json';
import { unitData } from '../data/units';
import Game from '../game';

const getGameMock = () => {
Expand All @@ -263,7 +263,7 @@ const getGameMock = () => {
},
Phaser: getPhaserMock(),
retrieveCreatureStats: (type: number) => {
for (const d of data) {
for (const d of unitData) {
if (d.id === type) {
return d;
}
Expand Down
6 changes: 3 additions & 3 deletions src/creature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type Movement = 'normal' | 'flying';
/**
* Creature Class
*
* Creature contains all creatures properties and attacks
* Creature contains all creatures properties and attacks/imgres?imgurl=https://i.pinimg.com/originals/e0/f0/53/e0f05354e9ca1ab73b860a896238d553.jpg&tbnid=FRJ2QLlrmIxDtM&vet=1&imgrefurl=https://www.pinterest.com/pin/346706871308486887/&docid=GMQJmxHxt2C2zM&w=931&h=807&hl=en-US&source=sh/x/im/4
*/
export class Creature {
//TODO: This can be removed when it is factored out of get fatigueText
Expand All @@ -97,14 +97,14 @@ export class Creature {
* name : String : Creature name
* id : Integer : Creature Id incrementing for each creature starting to 1
* size : Integer : Creature size in hexes (1,2 or 3)
* type : Integer : Type of the creature stocked in the database
* type : String : Type of the creature stocked in the database. Made up of `creature.realm` + `creature.level`. exception for Dark Priest "--"
* team : Integer : Owner's ID (0,1,2 or 3)
* player : Player : Player object shortcut
* hexagons : Array : Array containing the hexes where the creature is
*
* dead : Boolean : True if dead
* stats : Object : Object containing stats of the creature
* statsAlt : Object : Object containing the alteration value for each stat //todo
* statsAlt : Object : Object containing the alteration value for each stat // TODO
* abilities : Array : Array containing the 4 abilities
* remainingMove : Integer : Remaining moves allowed until the end of turn
* temp : Boolean : True if the creature is only temporary for preview, false otherwise
Expand Down
25 changes: 25 additions & 0 deletions src/data/types.ts
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];
Loading

0 comments on commit 0439f68

Please sign in to comment.