Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 1.65 KB | None | 0 0
  1.  
  2. enum GameType
  3. {
  4.     None = 0;
  5.     PvP = 2;
  6.     PvE;
  7.     Tutorial;
  8. }
  9.  
  10. class Consumables
  11. {
  12.     private var path : String;
  13.    
  14.     public function Consumables(pathToConsumable : String)
  15.     {
  16.         path = pathToConsumable;
  17.        
  18.         // TODO: add path check
  19.         // TODO: add uint to int wrong cast check
  20.        
  21.         tag = ExternalInterface.call("DataProvider.GetKeyValue", path + ".Tag");
  22.         cost = parseInt( ExternalInterface.call("DataProvider.GetKeyValue", path + ".Cost") );
  23.         delay = parseFloat( ExternalInterface.call("DataProvider.GetKeyValue", path + ".Delay") );
  24.         gameType = Type.createEnumIndex(GameType, parseInt( ExternalInterface.call("DataProvider.GetKeyValue", path + ".gameType") ));
  25.     }
  26.    
  27.     // data
  28.     public var tag(default, never) : String;
  29.     public var cost(default, never) : Int;
  30.     public var delay(default, never) : Float;
  31.     public var gameType(default, never) : GameType;
  32.    
  33.     // for each subtable collection codegen will generate three methods like these:
  34.     public function GetRPGStatsValue(id : String) : RPGStats
  35.     {
  36.         return new RPGStats(path + ".RPGStats." + id);
  37.     }
  38.    
  39.     public function GetRPGStatsCount() : Int
  40.     {
  41.         return parseInt( ExternalInterface.call("DataProvider.GetSubtablesCount", path + ".RPGStats") );
  42.     }
  43.    
  44.     public function GetRPGStatsIterator() : Iterator<RPGStats>
  45.     {
  46.         var names : Array = ...; // here some code to get array of subtable name
  47.        
  48.         return {
  49.             function hasNext() : Bool
  50.             {
  51.                 return idx < subtableNames.length-1;
  52.             }
  53.             function next() : RPGStats
  54.             {
  55.                 idx++;
  56.                 return new RPGStats(path + ".RPGStats." + subtableNames[idx-1]);
  57.             }
  58.             private var subtableNames : Array = names;
  59.             private var idx : Int = 0;
  60.         }
  61.     }
  62.    
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement