Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package;
- // import haxe.ds.Map;
- // import kha.Assets;
- // import kha.Framebuffer;
- // import kha.Scheduler;
- // import kha.System;
- // import kha.math.Random;
- interface IFuel {}
- class Fuel implements IFuel {
- public function new() {}
- }
- class FuelBio extends Fuel {
- public function new() {
- super();
- }
- public function calculateSomeShit():String {
- return "tadaaa";
- }
- }
- interface IMaterialProperty {}
- class MaterialProperty implements IMaterialProperty {
- public function new() {}
- }
- class MaterialPropertyTransport extends MaterialProperty {
- public function new() {
- super();
- }
- }
- class MaterialPropertyFuel extends MaterialProperty {
- @:isVar public var fuel(get, null):Fuel;
- public function new(fuel:Fuel) {
- super();
- this.fuel = fuel;
- }
- public function get_fuel():Fuel {
- return fuel;
- }
- }
- enum MaterialEnum {
- M1;
- }
- class Material {
- @:isVar public var properties(get, null):Array<MaterialProperty>;
- @:isVar public var material(get, null):MaterialEnum;
- public function new(material:MaterialEnum, properties:Array<MaterialProperty>) {
- this.properties = properties;
- this.material = material;
- }
- public function get_properties():Array<MaterialProperty> {
- return properties;
- }
- public function get_material():MaterialEnum {
- return material;
- }
- }
- class MaterialPool {
- @:isVar public var materials(get, null):Array<Material> = [];
- public function new() {
- var m1 = new Material(MaterialEnum.M1, [new MaterialPropertyTransport(), new MaterialPropertyFuel(new FuelBio())]);
- materials.push(m1);
- }
- public function get_materials():Array<Material> {
- return materials;
- }
- }
- class DNA {
- public function new() {}
- public function generateDNA(materialPool:MaterialPool) {
- for (material in materialPool.get_materials()) {
- trace("Matrial: " + material.material);
- var properties = material.properties;
- for (property in properties) {
- switch Type.typeof(property) {
- case TClass(MaterialPropertyFuel):
- trace("Fuel property");
- var materialPropertyFuel = cast(property, MaterialPropertyFuel);
- switch Type.typeof(materialPropertyFuel.fuel) {
- case TClass(FuelBio):
- var fuelBio:FuelBio = cast(materialPropertyFuel.fuel, FuelBio);
- trace("Do bio fuel stuff: " + fuelBio.calculateSomeShit());
- case _:
- trace("Other fuel stuff");
- }
- case _:
- trace("Other property");
- }
- }
- }
- }
- }
- class Test {
- public function new() {
- var dna = new DNA();
- var mp = new MaterialPool();
- dna.generateDNA(mp);
- }
- }
- class Main {
- /*static function update():Void {}
- static function render(frames:Array<Framebuffer>):Void {
- }*/
- public static function main() {
- var t = new Test();
- /*System.start({title: "Project", width: 1024, height: 768}, function(_) {
- // Just loading everything is ok for small projects
- Assets.loadEverything(function() {
- // Avoid passing update/render directly,
- // so replacing them via code injection works
- Scheduler.addTimeTask(function() {
- update();
- }, 0, 1 / 60);
- System.notifyOnFrames(function(frames) {
- render(frames);
- });
- });
- });*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement