1
0

Overwrite.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. class Overwrite{
  2. _func = {};
  3. func(passage,args){
  4. passage = passage.toLowerCase();
  5. if(this._func[passage] === undefined)
  6. return undefined;
  7. if(typeof this._func[passage] == "function")
  8. return this._func[passage](args);
  9. return this._func[passage];
  10. }
  11. funcRegister(passage,code){
  12. this._func[passage.toLowerCase()] = code;
  13. }
  14. _gs = {};
  15. gs(passage,args){
  16. passage = passage.toLowerCase();
  17. if(this._gs[passage] === undefined)
  18. return undefined;
  19. if(typeof this._gs[passage] == "function")
  20. return this._gs[passage](args);
  21. return this._gs[passage];
  22. }
  23. gsRegister(passage,code){
  24. this._gs[passage.toLowerCase()] = code;
  25. }
  26. _var = {};
  27. varGet(id,index){
  28. if(this._var[id] === undefined || this._var[id].get === undefined)
  29. return undefined;
  30. if(typeof this._var[id].get == "function")
  31. return this._var[id].get(index);
  32. if(Array.isArray(this._var[id].get) && typeof index == "number")
  33. return this._var[id].get[index];
  34. return this._var[id].get;
  35. }
  36. varSet(id,index,val){
  37. if(this._var[id] === undefined || this._var[id].set === undefined)
  38. return undefined;
  39. if(typeof this._var[id].set == "function")
  40. return this._var[id].set(index,val);
  41. console.error("Unsupported type for Overwrite.var.set (id,val)",id,val);
  42. }
  43. varRegister(id,get,set){
  44. this._var[id.toLowerCase()] = {get:get, set:set};
  45. }
  46. }
  47. setup.Overwrite = new Overwrite();