73 lines
1.4 KiB
Haxe
73 lines
1.4 KiB
Haxe
package scene;
|
|
|
|
@:uiComp("world-map-scene")
|
|
class WorldMapScene extends h2d.Flow implements GameScene implements h2d.domkit.Object {
|
|
var map:hxd.res.TiledMap.TiledMapData;
|
|
|
|
var layers:Map<String, {
|
|
name:String,
|
|
data:Array<Int>,
|
|
g:h2d.TileGroup,
|
|
alpha:Float
|
|
}>;
|
|
var tiles:Array<h2d.Tile>;
|
|
|
|
public var width:Int;
|
|
public var height:Int;
|
|
|
|
public function new(?parent) {
|
|
super(parent);
|
|
initComponent();
|
|
|
|
var root = new h2d.Object(this);
|
|
|
|
map = Res.map.toMap();
|
|
width = map.width;
|
|
height = map.height;
|
|
var t = Res.tiles.toTile();
|
|
layers = new Map();
|
|
this.tiles = [
|
|
for (y in 0...Std.int(t.height) >> 5) for (x in 0...Std.int(t.width) >> 5) t.sub(x * 32, y * 32, 32, 32)
|
|
];
|
|
for (ld in map.layers) {
|
|
if (ld.name == "hotspots")
|
|
continue;
|
|
var l = {
|
|
name: ld.name,
|
|
data: ld.data,
|
|
g: new h2d.TileGroup(t, root),
|
|
alpha: ld.opacity,
|
|
}
|
|
l.g.alpha = ld.opacity;
|
|
layers.set(ld.name, l);
|
|
rebuildLayer(ld.name);
|
|
}
|
|
|
|
Game.current.dialogueManager.runNode("Intro");
|
|
}
|
|
|
|
public function getH2dObject() {
|
|
return this;
|
|
}
|
|
|
|
function rebuildLayer(name:String) {
|
|
var l = layers.get(name);
|
|
if (l == null)
|
|
return;
|
|
var pos = 0;
|
|
var g = l.g;
|
|
g.clear();
|
|
while (g.numChildren > 0) {
|
|
g.getChildAt(0).remove();
|
|
}
|
|
|
|
for (y in 0...height)
|
|
for (x in 0...width) {
|
|
var t = l.data[pos++] - 1;
|
|
if (t < 0)
|
|
continue;
|
|
g.add(x * 32, y * 32, tiles[t]);
|
|
}
|
|
}
|
|
}
|