Advertisement
Guest User

Untitled

a guest
Oct 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 3.12 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.             var properties = material.properties;
  91.  
  92.             for (property in properties) {
  93.                 switch Type.typeof(property) {
  94.                     case TClass(MaterialPropertyFuel):
  95.                         var materialPropertyFuel = cast(property, MaterialPropertyFuel);
  96.  
  97.                         switch Type.typeof(materialPropertyFuel.fuel) {
  98.                             case TClass(FuelBio):
  99.                                 var fuelBio:FuelBio = cast(materialPropertyFuel.fuel, FuelBio);
  100.                                 trace("Do bio fuel stuff:" + fuelBio.calculateSomeShit());
  101.                             case _:
  102.                                 trace("Other fuel stuff");
  103.                         }
  104.                     case _:
  105.                         trace("Other material");
  106.                 }
  107.             }
  108.         }
  109.     }
  110. }
  111.  
  112. class Test {
  113.     public function new() {
  114.         var dna = new DNA();
  115.         var mp = new MaterialPool();
  116.         dna.generateDNA(mp);
  117.     }
  118. }
  119.  
  120. class Main {
  121.     /*static function update():Void {}
  122.         static function render(frames:Array<Framebuffer>):Void {
  123.     }*/
  124.     public static function main() {
  125.         var t = new Test();
  126.  
  127.         /*System.start({title: "Project", width: 1024, height: 768}, function(_) {
  128.             // Just loading everything is ok for small projects
  129.             Assets.loadEverything(function() {
  130.                 // Avoid passing update/render directly,
  131.                 // so replacing them via code injection works
  132.                 Scheduler.addTimeTask(function() {
  133.                     update();
  134.                 }, 0, 1 / 60);
  135.                 System.notifyOnFrames(function(frames) {
  136.                     render(frames);
  137.                 });
  138.             });
  139.         });*/
  140.     }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement