Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package;
- import haxe.Constraints.FlatEnum;
- import haxe.ds.Map;
- // import kha.Assets;
- // import kha.Framebuffer;
- // import kha.Scheduler;
- // import kha.System;
- // import kha.math.Random;
- /**
- * Core: Will not change frequently
- */
- interface IFuel {
- @:isVar public var requiredMaterials(get, null):Array<MaterialEnum>;
- @:isVar public var requiredfuels(get, null):Array<FuelEnum>;
- @:isVar public var fuel(get, null):FuelEnum;
- public function addRequiredMaterial(material:MaterialEnum):Void;
- public function addRequiredFuel(fuel:FuelEnum):Void;
- }
- /**
- * Core: Will not change frequently
- */
- enum FuelEnum {
- Bio;
- Sun;
- }
- /**
- * Core: Will not change frequently
- */
- class Fuel implements IFuel {
- @:isVar public var requiredMaterials(get, null):Array<MaterialEnum> = [];
- @:isVar public var requiredfuels(get, null):Array<FuelEnum> = [];
- @:isVar public var fuel(get, null):FuelEnum;
- public function new(fuel:FuelEnum) {
- this.fuel = fuel;
- }
- public function addRequiredMaterial(requiredMaterial:MaterialEnum) {
- this.requiredMaterials.push(requiredMaterial);
- }
- public function addRequiredFuel(requiredfuel:FuelEnum) {
- this.requiredfuels.push(requiredfuel);
- }
- public function get_requiredMaterials():Array<MaterialEnum> {
- return requiredMaterials;
- }
- public function get_requiredfuels():Array<FuelEnum> {
- return requiredfuels;
- }
- public function get_fuel():FuelEnum {
- return fuel;
- }
- }
- /**
- * Will change frequently/maybe will be replaced
- */
- class FuelBio extends Fuel {
- public function new() {
- super(FuelEnum.Bio);
- this.addRequiredMaterial(MaterialEnum.M0);
- this.addRequiredFuel(FuelEnum.Sun);
- }
- public function calculateSomeShit():String {
- return "tadaaa";
- }
- }
- /**
- * Will change frequently/maybe will be replaced
- */
- class FuelSun extends Fuel {
- public function new() {
- super(FuelEnum.Sun);
- }
- }
- /**
- * Core: Will not change frequently
- */
- interface IMaterialProperty {}
- /**
- * Core: Will not change frequently
- */
- class MaterialProperty implements IMaterialProperty {
- public function new() {}
- }
- /**
- * Will change frequently/maybe will be replaced
- */
- class MaterialPropertyTransport extends MaterialProperty {
- @:isVar public var transportsMaterials(get, null):Array<MaterialEnum> = [];
- @:isVar public var transportsFuels(get, null):Array<FuelEnum> = [];
- public function new(transportsMaterials:Array<MaterialEnum>, transportsFuels:Array<FuelEnum>) {
- this.transportsMaterials = transportsMaterials;
- this.transportsFuels = transportsFuels;
- super();
- }
- public function get_transportsMaterials():Array<MaterialEnum> {
- return transportsMaterials;
- }
- public function get_transportsFuels():Array<FuelEnum> {
- return transportsFuels;
- }
- }
- /**
- * Will change frequently/maybe will be replaced
- */
- 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;
- }
- }
- /**
- * Will change frequently/maybe will be replaced
- */
- enum MaterialEnum {
- M0;
- M1;
- M2;
- }
- /**
- * Core: Will not change frequently
- */
- 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;
- }
- }
- /**
- * Core: Will not change frequently
- */
- class MaterialGroup {
- @:isVar public var materials(get, null):Array<Material> = [];
- public function new() {}
- public function addMaterial(material:Material) {
- this.materials.push(material);
- }
- public function get_materials():Array<Material> {
- return materials;
- }
- public function minFuelRequired():Fuel {
- return null; // TODO
- }
- }
- /**
- * Will change frequently
- */
- class MaterialPool {
- @:isVar public var materials(get, null):Map<MaterialEnum, Material> = new Map();
- public function new() {
- var m1 = new Material(MaterialEnum.M1, [
- new MaterialPropertyTransport([MaterialEnum.M0], []),
- new MaterialPropertyFuel(new FuelBio())
- ]);
- var m2 = new Material(MaterialEnum.M2, [
- new MaterialPropertyTransport([], [FuelEnum.Sun]),
- new MaterialPropertyFuel(new FuelBio())
- ]);
- materials.set(MaterialEnum.M1, m1);
- materials.set(MaterialEnum.M2, m2);
- }
- public function get_materials():Map<MaterialEnum, Material> {
- return materials;
- }
- public function getGrops():Array<MaterialGroup> {
- // var group = new MaterialGroup();
- for (material in materials) {
- var properties = material.properties;
- for (property in properties) {
- switch Type.typeof(property) {
- case TClass(MaterialPropertyFuel):
- var materialPropertyFuel = cast(property, MaterialPropertyFuel);
- var fuel = materialPropertyFuel.fuel;
- var fuelRequiredMaterials = fuel.requiredMaterials;
- var fuelRequiredfuels = fuel.requiredfuels;
- for (fuelRequiredMaterial in fuelRequiredMaterials) {
- // TODO: add material to group, as fuel depends on it;
- // var xx = materials.get(MaterialEnum.M1); // Null if not
- }
- for (fuelRequiredfuel in fuelRequiredfuels) {
- // TODO: calculte other material depencies, that this sub-fuel requires and populate group;
- }
- case _:
- }
- }
- }
- return []; // TODO
- }
- }
- /**
- * Will change frequently
- */
- class DNA {
- public function new() {}
- public function generateDNA(groups:Array<MaterialGroup>) {
- for (group in groups) {
- for (material in group.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.getGrops());
- }
- }
- 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