Add EventBus and GameScene from ecs

This commit is contained in:
3wc
2024-02-14 00:21:02 -03:00
parent cd8be645a3
commit 87302a3713
11 changed files with 297 additions and 163 deletions

55
src/scene/TitleScene.hx Normal file
View File

@ -0,0 +1,55 @@
package scene;
import scene.WorldMapScene;
import event.ChangeSceneEvent;
import components.MenubuttonComponent;
@:uiComp("heading")
class HeadingComp extends h2d.Flow implements h2d.domkit.Object {
static var SRC = <heading class="mybox" min-width="200">
<text text={"Glass House"}/>
for( i in icons )
<bitmap src={i} id="icons[]"/>
</heading>;
public function new(icons:Array<h2d.Tile>, ?parent) {
super(parent);
initComponent();
}
}
@:uiComp("title-scene")
class TitleScene extends h2d.Flow implements GameScene implements h2d.domkit.Object {
static var SRC = <title-scene>
<heading([]) id="view"/>
<menubutton("New game") public id="btnNewGame"/>
<menubutton("Continue game") public id="btnContinueGame"/>
<menubutton("Credits") public id="btnCredits"/>
<menubutton("Quit") public id="btnQuit"/>
</title-scene>;
public function new(?parent) {
super(parent);
initComponent();
btnNewGame.onClick = function() {
Game.current.globalEventBus.publishEvent(new ChangeSceneEvent(new WorldMapScene(Game.current.root)));
}
btnContinueGame.onClick = function() {
btnContinueGame.dom.addClass("highlight");
}
#if hl
btnQuit.onClick = function() {
Sys.exit(0);
}
#else
btnQuit.remove();
#end
}
public function getH2dObject() {
return this;
}
}