77 lines
1.9 KiB
Haxe
77 lines
1.9 KiB
Haxe
package scene;
|
|
|
|
import dialogue.event.StartDialogueNode;
|
|
import event.OpenRoomEvent;
|
|
import TilemapLayer;
|
|
|
|
typedef Room = {
|
|
rect:h2d.Graphics,
|
|
area:h2d.Interactive,
|
|
isOpen:Bool
|
|
}
|
|
|
|
@:uiComp("world-map-scene")
|
|
class WorldMapScene extends h2d.Flow implements GameScene implements h2d.domkit.Object {
|
|
public var width:Int;
|
|
public var height:Int;
|
|
|
|
var rooms:Map<String, Room> = new Map<String, Room>();
|
|
|
|
public function new(?parent) {
|
|
super(parent);
|
|
initComponent();
|
|
|
|
var root = new h2d.Object(this);
|
|
|
|
var map = Game.loader.loadTMX("map.tmx");
|
|
|
|
Game.current.globalEventBus.subscribe(OpenRoomEvent, openRoom);
|
|
|
|
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(_) {
|
|
var room = rooms.get(obj.name);
|
|
if (room.isOpen) {
|
|
Game.current.globalEventBus.publishEvent(new StartDialogueNode("Room:" + obj.name));
|
|
} else {
|
|
Game.current.globalEventBus.publishEvent(new StartDialogueNode("Room not open"));
|
|
}
|
|
};
|
|
rooms.set(obj.name, {rect: rect, area: area, isOpen: false});
|
|
}
|
|
case TImageLayer:
|
|
case TGroup:
|
|
}
|
|
}
|
|
|
|
#if debug
|
|
trace('skipping intro dialogue');
|
|
Game.current.globalEventBus.publishEvent(new OpenRoomEvent("quarters"));
|
|
#else
|
|
Game.current.globalEventBus.publishEvent(new StartDialogueNode("Intro"));
|
|
#end
|
|
}
|
|
|
|
public function openRoom(event:OpenRoomEvent) {
|
|
var room = rooms.get(event.roomName);
|
|
room.isOpen = true;
|
|
room.rect.alpha = 0;
|
|
}
|
|
|
|
public function getH2dObject() {
|
|
return this;
|
|
}
|
|
}
|