Advertisement
Guest User

Untitled

a guest
Oct 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 7.22 KB | None | 0 0
  1. package;
  2.  
  3. import haxe.Constraints.FlatEnum;
  4.  
  5. import haxe.ds.Map;
  6. // import kha.Assets;
  7. // import kha.Framebuffer;
  8. // import kha.Scheduler;
  9. // import kha.System;
  10. // import kha.math.Random;
  11.  
  12. /**
  13.  * Core: Will not change frequently
  14.  */
  15. interface IFuel {
  16.     @:isVar public var requiredMaterials(get, null):Array<MaterialEnum>;
  17.     @:isVar public var requiredfuels(get, null):Array<FuelEnum>;
  18.     @:isVar public var fuel(get, null):FuelEnum;
  19.     public function addRequiredMaterial(material:MaterialEnum):Void;
  20.     public function addRequiredFuel(fuel:FuelEnum):Void;
  21. }
  22.  
  23. /**
  24.  * Core: Will not change frequently
  25.  */
  26. enum FuelEnum {
  27.     Bio;
  28.     Sun;
  29. }
  30.  
  31. /**
  32.  * Core: Will not change frequently
  33.  */
  34. class Fuel implements IFuel {
  35.     @:isVar public var requiredMaterials(get, null):Array<MaterialEnum> = [];
  36.     @:isVar public var requiredfuels(get, null):Array<FuelEnum> = [];
  37.     @:isVar public var fuel(get, null):FuelEnum;
  38.  
  39.     public function new(fuel:FuelEnum) {
  40.         this.fuel = fuel;
  41.     }
  42.  
  43.     public function addRequiredMaterial(requiredMaterial:MaterialEnum) {
  44.         this.requiredMaterials.push(requiredMaterial);
  45.     }
  46.  
  47.     public function addRequiredFuel(requiredfuel:FuelEnum) {
  48.         this.requiredfuels.push(requiredfuel);
  49.     }
  50.  
  51.     public function get_requiredMaterials():Array<MaterialEnum> {
  52.         return requiredMaterials;
  53.     }
  54.  
  55.     public function get_requiredfuels():Array<FuelEnum> {
  56.         return requiredfuels;
  57.     }
  58.  
  59.     public function get_fuel():FuelEnum {
  60.         return fuel;
  61.     }
  62. }
  63.  
  64. /**
  65.  * Will change frequently/maybe will be replaced
  66.  */
  67. class FuelBio extends Fuel {
  68.     public function new() {
  69.         super(FuelEnum.Bio);
  70.         this.addRequiredMaterial(MaterialEnum.M0);
  71.         this.addRequiredFuel(FuelEnum.Sun);
  72.     }
  73.  
  74.     public function calculateSomeShit():String {
  75.         return "tadaaa";
  76.     }
  77. }
  78.  
  79. /**
  80.  * Will change frequently/maybe will be replaced
  81.  */
  82. class FuelSun extends Fuel {
  83.     public function new() {
  84.         super(FuelEnum.Sun);
  85.     }
  86. }
  87.  
  88. /**
  89.  * Core: Will not change frequently
  90.  */
  91. interface IMaterialProperty {}
  92.  
  93. /**
  94.  * Core: Will not change frequently
  95.  */
  96. class MaterialProperty implements IMaterialProperty {
  97.     public function new() {}
  98. }
  99.  
  100. /**
  101.  * Will change frequently/maybe will be replaced
  102.  */
  103. class MaterialPropertyTransport extends MaterialProperty {
  104.     @:isVar public var transportsMaterials(get, null):Array<MaterialEnum> = [];
  105.     @:isVar public var transportsFuels(get, null):Array<FuelEnum> = [];
  106.  
  107.     public function new(transportsMaterials:Array<MaterialEnum>, transportsFuels:Array<FuelEnum>) {
  108.         this.transportsMaterials = transportsMaterials;
  109.         this.transportsFuels = transportsFuels;
  110.         super();
  111.     }
  112.  
  113.     public function get_transportsMaterials():Array<MaterialEnum> {
  114.         return transportsMaterials;
  115.     }
  116.  
  117.     public function get_transportsFuels():Array<FuelEnum> {
  118.         return transportsFuels;
  119.     }
  120. }
  121.  
  122. /**
  123.  * Will change frequently/maybe will be replaced
  124.  */
  125. class MaterialPropertyFuel extends MaterialProperty {
  126.     @:isVar public var fuel(get, null):Fuel;
  127.  
  128.     public function new(fuel:Fuel) {
  129.         super();
  130.         this.fuel = fuel;
  131.     }
  132.  
  133.     public function get_fuel():Fuel {
  134.         return fuel;
  135.     }
  136. }
  137.  
  138. /**
  139.  * Will change frequently/maybe will be replaced
  140.  */
  141. enum MaterialEnum {
  142.     M0;
  143.     M1;
  144.     M2;
  145. }
  146.  
  147. /**
  148.  * Core: Will not change frequently
  149.  */
  150. class Material {
  151.     @:isVar public var properties(get, null):Array<MaterialProperty>;
  152.     @:isVar public var material(get, null):MaterialEnum;
  153.  
  154.     public function new(material:MaterialEnum, properties:Array<MaterialProperty>) {
  155.         this.properties = properties;
  156.         this.material = material;
  157.     }
  158.  
  159.     public function get_properties():Array<MaterialProperty> {
  160.         return properties;
  161.     }
  162.  
  163.     public function get_material():MaterialEnum {
  164.         return material;
  165.     }
  166. }
  167.  
  168. /**
  169.  * Core: Will not change frequently
  170.  */
  171. class MaterialGroup {
  172.     @:isVar public var materials(get, null):Array<Material> = [];
  173.  
  174.     public function new() {}
  175.  
  176.     public function addMaterial(material:Material) {
  177.         this.materials.push(material);
  178.     }
  179.  
  180.     public function get_materials():Array<Material> {
  181.         return materials;
  182.     }
  183.  
  184.     public function minFuelRequired():Fuel {
  185.         return null; // TODO
  186.     }
  187. }
  188.  
  189. /**
  190.  * Will change frequently
  191.  */
  192. class MaterialPool {
  193.     @:isVar public var materials(get, null):Map<MaterialEnum, Material> = new Map();
  194.  
  195.     public function new() {
  196.         var m1 = new Material(MaterialEnum.M1, [
  197.             new MaterialPropertyTransport([MaterialEnum.M0], []),
  198.             new MaterialPropertyFuel(new FuelBio())
  199.         ]);
  200.         var m2 = new Material(MaterialEnum.M2, [
  201.             new MaterialPropertyTransport([], [FuelEnum.Sun]),
  202.             new MaterialPropertyFuel(new FuelBio())
  203.         ]);
  204.         materials.set(MaterialEnum.M1, m1);
  205.         materials.set(MaterialEnum.M2, m2);
  206.     }
  207.  
  208.     public function get_materials():Map<MaterialEnum, Material> {
  209.         return materials;
  210.     }
  211.  
  212.     public function getGrops():Array<MaterialGroup> {
  213.         // var group = new MaterialGroup();
  214.  
  215.         for (material in materials) {
  216.             var properties = material.properties;
  217.  
  218.             for (property in properties) {
  219.                 switch Type.typeof(property) {
  220.                     case TClass(MaterialPropertyFuel):
  221.                         var materialPropertyFuel = cast(property, MaterialPropertyFuel);
  222.                         var fuel = materialPropertyFuel.fuel;
  223.                         var fuelRequiredMaterials = fuel.requiredMaterials;
  224.                         var fuelRequiredfuels = fuel.requiredfuels;
  225.  
  226.                         for (fuelRequiredMaterial in fuelRequiredMaterials) {
  227.                             // TODO: add material to group, as fuel depends on it;
  228.                             // var xx = materials.get(MaterialEnum.M1); // Null if not
  229.                         }
  230.                         for (fuelRequiredfuel in fuelRequiredfuels) {
  231.                             // TODO: calculte other material depencies, that this sub-fuel requires and populate group;
  232.                         }
  233.                     case _:
  234.                 }
  235.             }
  236.         }
  237.  
  238.         return []; // TODO
  239.     }
  240. }
  241.  
  242. /**
  243.  * Will change frequently
  244.  */
  245. class DNA {
  246.     public function new() {}
  247.  
  248.     public function generateDNA(groups:Array<MaterialGroup>) {
  249.         for (group in groups) {
  250.             for (material in group.materials) {
  251.                 trace("Matrial: " + material.material);
  252.                 var properties = material.properties;
  253.  
  254.                 for (property in properties) {
  255.                     switch Type.typeof(property) {
  256.                         case TClass(MaterialPropertyFuel):
  257.                             trace("Fuel property");
  258.                             var materialPropertyFuel = cast(property, MaterialPropertyFuel);
  259.  
  260.                             switch Type.typeof(materialPropertyFuel.fuel) {
  261.                                 case TClass(FuelBio):
  262.                                     var fuelBio:FuelBio = cast(materialPropertyFuel.fuel, FuelBio);
  263.                                     trace("Do bio fuel stuff: " + fuelBio.calculateSomeShit());
  264.                                 case _:
  265.                                     trace("Other fuel stuff");
  266.                             }
  267.                         case _:
  268.                             trace("Other property");
  269.                     }
  270.                 }
  271.             }
  272.         }
  273.     }
  274. }
  275.  
  276. class Test {
  277.     public function new() {
  278.         var dna = new DNA();
  279.         var mp = new MaterialPool();
  280.         dna.generateDNA(mp.getGrops());
  281.     }
  282. }
  283.  
  284. class Main {
  285.     /*static function update():Void {}
  286.         static function render(frames:Array<Framebuffer>):Void {
  287.     }*/
  288.     public static function main() {
  289.         var t = new Test();
  290.  
  291.         /*System.start({title: "Project", width: 1024, height: 768}, function(_) {
  292.             // Just loading everything is ok for small projects
  293.             Assets.loadEverything(function() {
  294.                 // Avoid passing update/render directly,
  295.                 // so replacing them via code injection works
  296.                 Scheduler.addTimeTask(function() {
  297.                     update();
  298.                 }, 0, 1 / 60);
  299.                 System.notifyOnFrames(function(frames) {
  300.                     render(frames);
  301.                 });
  302.             });
  303.         });*/
  304.     }
  305. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement