-
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.
moved juego constructors to a file in the library. added deep-copy fu…
…nction to Entity
- Loading branch information
1 parent
eb378cf
commit 81fdb80
Showing
9 changed files
with
222 additions
and
44 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
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,33 @@ | ||
export type Newable = { new ( ...args: any[] ): any } | ||
|
||
export function factory( newable: Newable ): ( () => Object ) { | ||
return () => { | ||
let obj = new newable(); | ||
return obj; | ||
} | ||
} | ||
|
||
// map from class names to constructors | ||
// used to make highlightable text in instructions | ||
export let classMap: { [ key: string ]: Newable } = {}; | ||
|
||
// list of constructor functions | ||
// (need to access static props, not sure how to define this as a type in TS, so type is vague) | ||
|
||
// if a class is not in this list, it is instantiated as new Class() | ||
export let constructors : { [key: string]: () => Object } = {}; | ||
|
||
export function addClass( className: string, constr: Newable ) { | ||
classMap[className] = constr; | ||
|
||
if ( !( className in constructors ) ) { | ||
constructors[className] = factory( classMap[className] ); | ||
} | ||
|
||
if ( !( className in nameMap ) ) { | ||
nameMap[constr.name] = className; | ||
} | ||
} | ||
|
||
// create a map so constructor names can be retrieved post-obfuscation | ||
export let nameMap: { [ key: string ]: string } = {}; |
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,33 @@ | ||
import { addClass, constructors } from './constructors.js' | ||
|
||
import { Chrono, Anim, AnimField, AnimFrame, AnimTarget, PhysField } from './Anim.js' | ||
import { Camera } from './Camera.js' | ||
import { Entity } from './Entity.js' | ||
import { GridArea } from './GridArea.js' | ||
import { Line } from './Line.js' | ||
import { Material } from './Material.js' | ||
import { Shape } from './Shape.js' | ||
import { Sound } from './Sound.js' | ||
import { TileArray } from './TileArray.js' | ||
import { Vec2 } from './Vec2.js' | ||
|
||
export let empty = 0; // export so that webpack doesn't ignore the file | ||
|
||
addClass( 'Vec2', Vec2 ); // no loops | ||
addClass( 'Material', Material ); // no loops | ||
addClass( 'Line', Line ); // no loops | ||
addClass( 'Shape', Shape ); // could loop via .parent but currently not stored by parent | ||
addClass( 'Entity', Entity ); // no loops | ||
addClass( 'GridArea', GridArea ); | ||
addClass( 'TileArray', TileArray ); | ||
addClass( 'Anim', Anim ); | ||
addClass( 'AnimField', AnimField ); | ||
addClass( 'AnimFrame', AnimFrame ); | ||
addClass( 'Chrono', Chrono ); | ||
addClass( 'PhysField', PhysField ); | ||
addClass( 'Sound', Sound ); | ||
addClass( 'Camera', Camera ); | ||
addClass( 'AnimTarget', AnimTarget ); | ||
|
||
// define special constructors here | ||
// constructors[className] = () => new Class( false ); |
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
Oops, something went wrong.