2024-02-14 03:21:02 +00:00
|
|
|
import h2d.Layers;
|
|
|
|
import h2d.Console;
|
2024-02-16 06:51:57 +00:00
|
|
|
import h3d.Vector4;
|
2024-02-14 03:21:02 +00:00
|
|
|
import scene.TitleScene;
|
|
|
|
import scene.WorldMapScene;
|
|
|
|
import scene.GameScene;
|
|
|
|
import event.EventBus;
|
|
|
|
import event.ChangeSceneEvent;
|
2024-02-12 16:53:47 +00:00
|
|
|
import Const;
|
2024-02-18 15:25:03 +00:00
|
|
|
import listeners.DialogueBoxController;
|
2024-02-15 04:54:01 +00:00
|
|
|
import dialogue.DialogueManager;
|
2024-02-16 05:38:52 +00:00
|
|
|
import dialogue.command.OpenRoomCommand;
|
|
|
|
|
2024-02-14 03:21:02 +00:00
|
|
|
@:uiComp("game-container")
|
|
|
|
class GameContainer extends h2d.Flow implements h2d.domkit.Object {
|
|
|
|
static var SRC = <game-container>
|
|
|
|
${scene}
|
|
|
|
</game-container>;
|
|
|
|
|
|
|
|
public var scene:GameScene;
|
|
|
|
|
|
|
|
public function new(?parent) {
|
|
|
|
super(parent);
|
|
|
|
initComponent();
|
2024-02-18 16:38:32 +00:00
|
|
|
this.maxWidth = Const.W;
|
|
|
|
this.minWidth = Const.W;
|
2024-02-14 03:21:02 +00:00
|
|
|
}
|
|
|
|
}
|
2024-02-12 16:53:47 +00:00
|
|
|
|
|
|
|
class Game extends hxd.App {
|
2024-02-18 15:25:03 +00:00
|
|
|
public static var loader = new tiled.Tiled();
|
|
|
|
public static var current:Game; // Current Game (singleton)
|
|
|
|
|
2024-02-12 21:30:13 +00:00
|
|
|
public var font:h2d.Font;
|
2024-02-15 04:54:01 +00:00
|
|
|
public var options:Array<h2d.ScaleGrid> = [];
|
2024-02-13 00:58:44 +00:00
|
|
|
public var dialogueManager:DialogueManager;
|
2024-02-14 03:21:02 +00:00
|
|
|
public var root:GameContainer;
|
2024-02-16 04:53:38 +00:00
|
|
|
public var console:Console;
|
2024-02-18 15:25:03 +00:00
|
|
|
public var globalEventBus:EventBus;
|
2024-02-16 06:52:16 +00:00
|
|
|
|
2024-02-18 15:25:03 +00:00
|
|
|
var dialogueBoxController:DialogueBoxController;
|
|
|
|
var layer:Layers;
|
2024-02-14 03:21:02 +00:00
|
|
|
var style = null;
|
|
|
|
|
2024-02-12 16:53:47 +00:00
|
|
|
override function init() {
|
2024-02-15 05:08:08 +00:00
|
|
|
s2d.scaleMode = Stretch(Const.W, Const.H);
|
|
|
|
layer = new Layers(s2d);
|
2024-02-12 16:53:47 +00:00
|
|
|
|
2024-02-14 03:21:02 +00:00
|
|
|
#if hl
|
|
|
|
hxd.res.Resource.LIVE_UPDATE = true;
|
|
|
|
hxd.Res.initLocal();
|
|
|
|
#else
|
|
|
|
hxd.Res.initEmbed();
|
|
|
|
#end
|
|
|
|
|
|
|
|
root = new GameContainer();
|
|
|
|
root.horizontalAlign = root.verticalAlign = Middle;
|
2024-02-15 05:08:08 +00:00
|
|
|
layer.addChildAt(root, 1);
|
2024-02-14 03:21:02 +00:00
|
|
|
onResize();
|
2024-02-12 21:03:26 +00:00
|
|
|
|
2024-02-14 03:21:02 +00:00
|
|
|
style = new h2d.domkit.Style();
|
|
|
|
style.load(hxd.Res.style);
|
|
|
|
style.allowInspect = true;
|
|
|
|
style.addObject(root);
|
2024-02-13 00:58:44 +00:00
|
|
|
|
2024-02-15 04:54:01 +00:00
|
|
|
font = Res.font.minecraftia_regular_6.toFont();
|
2024-02-18 15:25:03 +00:00
|
|
|
font.resizeTo(18);
|
2024-02-15 04:54:01 +00:00
|
|
|
|
|
|
|
#if debug
|
|
|
|
console = new Console(font);
|
|
|
|
layer.addChildAt(console, 4);
|
|
|
|
#end
|
|
|
|
|
2024-02-14 03:21:02 +00:00
|
|
|
globalEventBus = new EventBus(console);
|
|
|
|
globalEventBus.subscribe(ChangeSceneEvent, onChangeScene);
|
|
|
|
|
2024-02-15 04:54:01 +00:00
|
|
|
dialogueManager = new DialogueManager(globalEventBus);
|
2024-02-14 15:13:29 +00:00
|
|
|
|
2024-02-16 06:52:16 +00:00
|
|
|
var yarnText = [hxd.Res.text.intro.entry.getText(), hxd.Res.text.rooms.entry.getText(),];
|
|
|
|
var yarnFileNames = [hxd.Res.text.intro.entry.name, hxd.Res.text.rooms.entry.name,];
|
2024-02-14 15:13:29 +00:00
|
|
|
dialogueManager.load(yarnText, yarnFileNames);
|
2024-02-14 17:25:04 +00:00
|
|
|
|
2024-02-16 05:38:52 +00:00
|
|
|
dialogueManager.addCommandHandler(new OpenRoomCommand(globalEventBus));
|
2024-02-15 04:54:01 +00:00
|
|
|
|
2024-02-18 15:25:03 +00:00
|
|
|
var dialogueParent = new h2d.Flow();
|
|
|
|
dialogueParent.dom = domkit.Properties.create("flow", dialogueParent);
|
|
|
|
dialogueParent.dom.addClass('dialogue-container');
|
|
|
|
layer.addChildAt(dialogueParent, 2);
|
2024-02-18 16:38:32 +00:00
|
|
|
style.addObject(dialogueParent);
|
2024-02-18 15:25:03 +00:00
|
|
|
dialogueBoxController = new DialogueBoxController(globalEventBus, dialogueParent, style);
|
|
|
|
|
2024-02-14 17:25:04 +00:00
|
|
|
#if debug
|
|
|
|
setGameScene(new WorldMapScene(root));
|
|
|
|
#else
|
|
|
|
setGameScene(new TitleScene(root));
|
|
|
|
#end
|
2024-02-12 21:03:26 +00:00
|
|
|
}
|
2024-02-13 06:27:07 +00:00
|
|
|
|
2024-02-14 03:21:02 +00:00
|
|
|
public function new() {
|
|
|
|
super();
|
|
|
|
current = this;
|
2024-02-13 06:27:07 +00:00
|
|
|
}
|
|
|
|
|
2024-02-14 03:21:02 +00:00
|
|
|
override function onResize() {
|
|
|
|
root.minWidth = root.maxWidth = s2d.width;
|
|
|
|
root.minHeight = root.maxHeight = s2d.height;
|
2024-02-13 06:27:07 +00:00
|
|
|
}
|
|
|
|
|
2024-02-14 03:21:02 +00:00
|
|
|
override function update(dt:Float) {
|
|
|
|
style.sync();
|
2024-02-13 06:27:07 +00:00
|
|
|
}
|
|
|
|
|
2024-02-14 03:21:02 +00:00
|
|
|
public function onChangeScene(event:ChangeSceneEvent) {
|
|
|
|
setGameScene(event.newScene);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setGameScene(gs:GameScene) {
|
|
|
|
#if debug
|
2024-02-15 04:54:01 +00:00
|
|
|
console.resetCommands();
|
2024-02-14 03:21:02 +00:00
|
|
|
#end
|
|
|
|
|
|
|
|
if (root.scene != null) {
|
|
|
|
root.scene.getH2dObject().remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
root.scene = gs;
|
|
|
|
style.addObject(gs.getH2dObject());
|
|
|
|
}
|
2024-02-17 02:57:17 +00:00
|
|
|
|
|
|
|
static function main() {
|
|
|
|
new Game();
|
|
|
|
}
|
2024-02-12 16:53:47 +00:00
|
|
|
}
|