Advertisement
Guest User

Untitled

a guest
Oct 20th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 3.19 KB | None | 0 0
  1. package;
  2.  
  3. // import haxe.ds.Map;
  4. // import kha.Assets;
  5. // import kha.Framebuffer;
  6. // import kha.Scheduler;
  7. // import kha.System;
  8. // import kha.math.Random;
  9. interface IFuel {}
  10.  
  11. class Fuel implements IFuel {
  12.     public function new() {}
  13. }
  14.  
  15. class FuelBio extends Fuel {
  16.     public function new() {
  17.         super();
  18.     }
  19.  
  20.     public function calculateSomeShit():String {
  21.         return "tadaaa";
  22.     }
  23. }
  24.  
  25. interface IMaterialProperty {}
  26.  
  27. class MaterialProperty implements IMaterialProperty {
  28.     public function new() {}
  29. }
  30.  
  31. class MaterialPropertyTransport extends MaterialProperty {
  32.     public function new() {
  33.         super();
  34.     }
  35. }
  36.  
  37. class MaterialPropertyFuel extends MaterialProperty {
  38.     @:isVar public var fuel(get, null):Fuel;
  39.  
  40.     public function new(fuel:Fuel) {
  41.         super();
  42.         this.fuel = fuel;
  43.     }
  44.  
  45.     public function get_fuel():Fuel {
  46.         return fuel;
  47.     }
  48. }
  49.  
  50. enum MaterialEnum {
  51.     M1;
  52. }
  53.  
  54. class Material {
  55.     @:isVar public var properties(get, null):Array<MaterialProperty>;
  56.     @:isVar public var material(get, null):MaterialEnum;
  57.  
  58.     public function new(material:MaterialEnum, properties:Array<MaterialProperty>) {
  59.         this.properties = properties;
  60.         this.material = material;
  61.     }
  62.  
  63.     public function get_properties():Array<MaterialProperty> {
  64.         return properties;
  65.     }
  66.  
  67.     public function get_material():MaterialEnum {
  68.         return material;
  69.     }
  70. }
  71.  
  72. class MaterialPool {
  73.     @:isVar public var materials(get, null):Array<Material> = [];
  74.  
  75.     public function new() {
  76.         var m1 = new Material(MaterialEnum.M1, [new MaterialPropertyTransport(), new MaterialPropertyFuel(new FuelBio())]);
  77.         materials.push(m1);
  78.     }
  79.  
  80.     public function get_materials():Array<Material> {
  81.         return materials;
  82.     }
  83. }
  84.  
  85. class DNA {
  86.     public function new() {}
  87.  
  88.     public function generateDNA(materialPool:MaterialPool) {
  89.         for (material in materialPool.get_materials()) {
  90.             trace("Matrial: " + material.material);
  91.             var properties = material.properties;
  92.  
  93.             for (property in properties) {
  94.                 switch Type.typeof(property) {
  95.                     case TClass(MaterialPropertyFuel):
  96.                         trace("Fuel property");
  97.                         var materialPropertyFuel = cast(property, MaterialPropertyFuel);
  98.  
  99.                         switch Type.typeof(materialPropertyFuel.fuel) {
  100.                             case TClass(FuelBio):
  101.                                 var fuelBio:FuelBio = cast(materialPropertyFuel.fuel, FuelBio);
  102.                                 trace("Do bio fuel stuff: " + fuelBio.calculateSomeShit());
  103.                             case _:
  104.                                 trace("Other fuel stuff");
  105.                         }
  106.                     case _:
  107.                         trace("Other property");
  108.                 }
  109.             }
  110.         }
  111.     }
  112. }
  113.  
  114. class Test {
  115.     public function new() {
  116.         var dna = new DNA();
  117.         var mp = new MaterialPool();
  118.         dna.generateDNA(mp);
  119.     }
  120. }
  121.  
  122. class Main {
  123.     /*static function update():Void {}
  124.         static function render(frames:Array<Framebuffer>):Void {
  125.     }*/
  126.     public static function main() {
  127.         var t = new Test();
  128.  
  129.         /*System.start({title: "Project", width: 1024, height: 768}, function(_) {
  130.             // Just loading everything is ok for small projects
  131.             Assets.loadEverything(function() {
  132.                 // Avoid passing update/render directly,
  133.                 // so replacing them via code injection works
  134.                 Scheduler.addTimeTask(function() {
  135.                     update();
  136.                 }, 0, 1 / 60);
  137.                 System.notifyOnFrames(function(frames) {
  138.                     render(frames);
  139.                 });
  140.             });
  141.         });*/
  142.     }
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement