1
1

CharacterOrigin.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. class CharacterOrigin {
  2. public id : string;
  3. public name : string;
  4. public description : string | Say;
  5. public bonusStats : string;
  6. public confirmPicked : (() => void) = () => {};
  7. public constructor (id : string) {
  8. this.id = id;
  9. CharacterOrigin.storeOrigin(this);
  10. }
  11. public static origins : {[id : string] : CharacterOrigin} = {};
  12. public static storeOrigin (origin : CharacterOrigin) {
  13. CharacterOrigin.origins[origin.id] = origin;
  14. }
  15. public static getOrigin (id : string) {
  16. return CharacterOrigin.origins[id];
  17. }
  18. public static getOrigins () : Array<CharacterOrigin> {
  19. let origins = [];
  20. for (let id in CharacterOrigin.origins) {
  21. origins.push(CharacterOrigin.origins[id]);
  22. }
  23. origins.sort((a : CharacterOrigin, b : CharacterOrigin) => {
  24. let na = a.name.toUpperCase();
  25. let nb = b.name.toUpperCase();
  26. if (na < nb) return -1;
  27. if (na > nb) return 1;
  28. return 0;
  29. });
  30. return origins;
  31. }
  32. }