glasshouse/src/scene/WorldMapScene.hx

54 lines
1.3 KiB
Haxe

package scene;
import dialogue.event.StartDialogueNode;
import TilemapLayer;
@:uiComp("world-map-scene")
class WorldMapScene extends h2d.Flow implements GameScene implements h2d.domkit.Object {
public var width:Int;
public var height:Int;
public function new(?parent) {
super(parent);
initComponent();
var root = new h2d.Object(this);
var map = Game.loader.loadTMX("map.tmx");
for (layer in (map.layers)) {
switch(layer.kind) {
case TTileLayer:
var l = new TilemapLayer(map, layer, root);
case TObjectGroup:
for (obj in layer.objects) {
var rect = new h2d.Graphics(root);
rect.beginFill(0x333333);
rect.alpha = 0.8;
rect.drawRect(obj.x, obj.y, obj.width, obj.height);
rect.endFill();
var area = new h2d.Interactive(obj.width, obj.height, root);
area.x = obj.x;
area.y = obj.y;
area.onClick = function(_) {
trace("Room:" + obj.name);
Game.current.globalEventBus.publishEvent(new StartDialogueNode("Room:" + obj.name));
};
}
case TImageLayer:
case TGroup:
}
}
#if debug
trace('skipping intro dialogue');
#else
Game.current.globalEventBus.publishEvent(new StartDialogueNode("Intro"));
#end
}
public function getH2dObject() {
return this;
}
}