1
0

Skills.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /// <reference path="../common/GameObject.ts" />
  2. class Skills extends GameObject{
  3. static createProxy(skills:Skills):{[skillId:string]:Skill}{
  4. return new Proxy(skills, {
  5. get(skillsObject, skillId){
  6. if(typeof skillId != "string"){
  7. if(skillId == Symbol.toStringTag)
  8. return JSON.stringify(skillsObject);
  9. throw new Error(`Unexpected symbol in Skills.Proxy.get(): '${skillId.toString()}'`);
  10. }
  11. if(!skillsObject._skills[skillId]){
  12. skillsObject._skills[skillId] = new Skill();
  13. skillsObject._skills[skillId].$skillExperienceGainCallback = (gain:number) => {skillsObject.$skillExperienceGainCallback(skillId,gain)};
  14. }
  15. return skillsObject._skills[skillId];
  16. },
  17. ownKeys(skillsObject) {
  18. return Object.keys(skillsObject._skills);
  19. },
  20. }) as unknown as {[skillId:string]:Skill};
  21. }
  22. _skills: {[skillID:string]: Skill} = {};
  23. set skillExperienceGainCallback(v: (skillId:string, gain:number) => any){
  24. this.$skillExperienceGainCallback = v;
  25. for(const [skillId, skill] of Object.entries(this._skills)){
  26. skill.$skillExperienceGainCallback = (gain:number) => {this.$skillExperienceGainCallback(skillId,gain)};
  27. }
  28. }
  29. $skillExperienceGainCallback: (skillId:string, gain:number) => any = (skillId:string, gain:number) => undefined;
  30. //#region SYSTEM
  31. constructor(
  32. ){
  33. super();
  34. }
  35. clone = function () {
  36. return (new setup.Skills())._init(this.clonableFields);
  37. };
  38. toJSON = function () {
  39. return JSON.reviveWrapper('(new setup.Skills())._init($ReviveData$)', this.ownData);
  40. };
  41. //#endregion
  42. }
  43. setup.Skills = Skills;