Add RoomOpen command / event
This commit is contained in:
parent
c1b102860e
commit
e0d3ca8021
1
res/.tmp/cache.dat
Normal file
1
res/.tmp/cache.dat
Normal file
@ -0,0 +1 @@
|
||||
by25:minecraftia_regular_6.fntaoy3:veri1y4:timei1707771858y4:hashy40:985b62563507866445c3c81a04f7e6645d90dad5y3:outy33:.tmp%2Fminecraftia_regular_6.bfntghy40:font%2Fpixel_unicode%2FPixel-UniCode.fntaoR1i1R2i1707784556R3y40:bc4073da70385f93ae70e391a786e346daac2b1fR5y48:.tmp%2Ffont%2Fpixel_unicode%2FPixel-UniCode.bfntghy32:font%2Fminecraftia_regular_6.fntaoR1i1R2i1707771858R3R4R5y40:.tmp%2Ffont%2Fminecraftia_regular_6.bfntghh
|
BIN
res/.tmp/font/minecraftia_regular_6.bfnt
Normal file
BIN
res/.tmp/font/minecraftia_regular_6.bfnt
Normal file
Binary file not shown.
BIN
res/.tmp/font/pixel_unicode/Pixel-UniCode.bfnt
Normal file
BIN
res/.tmp/font/pixel_unicode/Pixel-UniCode.bfnt
Normal file
Binary file not shown.
BIN
res/.tmp/minecraftia_regular_6.bfnt
Normal file
BIN
res/.tmp/minecraftia_regular_6.bfnt
Normal file
Binary file not shown.
14
res/rewild.tiled-project
Normal file
14
res/rewild.tiled-project
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"automappingRulesFile": "",
|
||||
"commands": [
|
||||
],
|
||||
"compatibilityVersion": 1100,
|
||||
"extensionsPath": "extensions",
|
||||
"folders": [
|
||||
"."
|
||||
],
|
||||
"properties": [
|
||||
],
|
||||
"propertyTypes": [
|
||||
]
|
||||
}
|
45
res/rewild.tiled-session
Normal file
45
res/rewild.tiled-session
Normal file
@ -0,0 +1,45 @@
|
||||
{
|
||||
"activeFile": "map.tmx",
|
||||
"expandedProjectPaths": [
|
||||
],
|
||||
"fileStates": {
|
||||
"/home/f/Projects/Rewild/references/ld28/res/map.tmx": {
|
||||
"scale": 1.5684895833333334,
|
||||
"selectedLayer": 6,
|
||||
"viewCenter": {
|
||||
"x": 191.90436659472022,
|
||||
"y": 144.08766395483977
|
||||
}
|
||||
},
|
||||
"/home/f/Projects/Rewild/references/ld28/res/map.tmx#tiles": {
|
||||
"scaleInDock": 1
|
||||
},
|
||||
"/home/f/Projects/Rewild/references/ld28/res/spaaace.tsx": {
|
||||
"scaleInEditor": 1
|
||||
},
|
||||
"map.tmx": {
|
||||
"expandedObjectLayers": [
|
||||
3
|
||||
],
|
||||
"scale": 0.75,
|
||||
"selectedLayer": 1,
|
||||
"viewCenter": {
|
||||
"x": 479.3333333333333,
|
||||
"y": 320
|
||||
}
|
||||
},
|
||||
"map.tmx#tiles": {
|
||||
"scaleInDock": 1
|
||||
}
|
||||
},
|
||||
"openFiles": [
|
||||
"map.tmx",
|
||||
"/home/f/Projects/Rewild/references/ld28/res/map.tmx"
|
||||
],
|
||||
"project": "rewild.tiled-project",
|
||||
"recentFiles": [
|
||||
"/home/f/Projects/Rewild/references/ld28/res/map.tmx",
|
||||
"map.tmx",
|
||||
"/home/f/Projects/Rewild/references/ld28/res/spaaace.tsx"
|
||||
]
|
||||
}
|
@ -11,5 +11,13 @@ You: Let's have another look around...
|
||||
===
|
||||
title: Room:quarters
|
||||
---
|
||||
It's the crew quarters
|
||||
You: It's the crew quarters
|
||||
===
|
||||
title: Room:hangar
|
||||
---
|
||||
You: The **hangar** seems eerily deserted
|
||||
===
|
||||
title: Room not open
|
||||
---
|
||||
You: Hmm, that part of the ship is still inaccessible. I wonder how to get in?
|
||||
===
|
||||
|
@ -17,6 +17,8 @@ import dialogue.event.OptionSelected;
|
||||
import dialogue.event.DialogueComplete;
|
||||
import dialogue.event.NextLine;
|
||||
|
||||
import dialogue.command.OpenRoomCommand;
|
||||
|
||||
@:uiComp("game-container")
|
||||
class GameContainer extends h2d.Flow implements h2d.domkit.Object {
|
||||
static var SRC = <game-container>
|
||||
@ -95,6 +97,7 @@ class Game extends hxd.App {
|
||||
globalEventBus.subscribe(OptionsShown, renderOptions);
|
||||
globalEventBus.subscribe(OptionSelected, onOptionSelected);
|
||||
globalEventBus.subscribe(DialogueComplete, onDialogueComplete);
|
||||
dialogueManager.addCommandHandler(new OpenRoomCommand(globalEventBus));
|
||||
|
||||
#if debug
|
||||
setGameScene(new WorldMapScene(root));
|
||||
|
@ -12,6 +12,7 @@ import hxyarn.compiler.Compiler;
|
||||
import hxyarn.compiler.CompilationJob;
|
||||
|
||||
import event.EventBus;
|
||||
import dialogue.command.ICommandHandler;
|
||||
import dialogue.event.LineShown;
|
||||
import dialogue.event.OptionsShown;
|
||||
import dialogue.event.OptionsShown.OptionChoice;
|
||||
@ -26,6 +27,7 @@ class DialogueManager {
|
||||
var storage = new MemoryVariableStore();
|
||||
var dialogue:Dialogue;
|
||||
var stringTable:Map<String, StringInfo>;
|
||||
var commandHandlers = new Map<String, ICommandHandler>();
|
||||
|
||||
public var waitingForOption:Bool = false;
|
||||
|
||||
@ -118,6 +120,25 @@ class DialogueManager {
|
||||
}
|
||||
|
||||
public function commandHandler(command:Command) {
|
||||
var parts = command.text.split(' ');
|
||||
var key = parts.shift();
|
||||
if (commandHandlers.exists(key)) {
|
||||
if (commandHandlers.get(key).handleCommand(parts)) {
|
||||
resume();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
resume();
|
||||
}
|
||||
|
||||
public function addCommandHandler(handler:ICommandHandler) {
|
||||
if (handler.commandName == null || handler.commandName == "") {
|
||||
trace("Command handler has no command name");
|
||||
return;
|
||||
}
|
||||
|
||||
commandHandlers.set(handler.commandName, handler);
|
||||
}
|
||||
|
||||
public function nodeCompleteHandler(nodeName:String) {}
|
||||
|
6
src/dialogue/command/ICommandHandler.hx
Normal file
6
src/dialogue/command/ICommandHandler.hx
Normal file
@ -0,0 +1,6 @@
|
||||
package dialogue.command;
|
||||
|
||||
interface ICommandHandler {
|
||||
var commandName:String;
|
||||
function handleCommand(args:Array<String>):Bool;
|
||||
}
|
19
src/dialogue/command/OpenRoomCommand.hx
Normal file
19
src/dialogue/command/OpenRoomCommand.hx
Normal file
@ -0,0 +1,19 @@
|
||||
package dialogue.command;
|
||||
|
||||
import event.EventBus;
|
||||
import event.OpenRoomEvent;
|
||||
|
||||
class OpenRoomCommand implements ICommandHandler {
|
||||
public var commandName:String = "room";
|
||||
|
||||
var eventBus:EventBus;
|
||||
|
||||
public function new(eventBus:EventBus) {
|
||||
this.eventBus = eventBus;
|
||||
}
|
||||
|
||||
public function handleCommand(args:Array<String>):Bool {
|
||||
eventBus.publishEvent(new OpenRoomEvent(args[0]));
|
||||
return true;
|
||||
}
|
||||
}
|
9
src/event/OpenRoomEvent.hx
Normal file
9
src/event/OpenRoomEvent.hx
Normal file
@ -0,0 +1,9 @@
|
||||
package event;
|
||||
|
||||
class OpenRoomEvent implements IEvent {
|
||||
public var roomName:String;
|
||||
|
||||
public function new(rn:String) {
|
||||
this.roomName = rn;
|
||||
}
|
||||
}
|
@ -1,13 +1,22 @@
|
||||
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();
|
||||
@ -16,6 +25,8 @@ class WorldMapScene extends h2d.Flow implements GameScene implements h2d.domkit.
|
||||
|
||||
var map = Game.loader.loadTMX("map.tmx");
|
||||
|
||||
Game.current.globalEventBus.subscribe(OpenRoomEvent, openRoom);
|
||||
|
||||
for (layer in (map.layers)) {
|
||||
switch(layer.kind) {
|
||||
case TTileLayer:
|
||||
@ -32,8 +43,14 @@ class WorldMapScene extends h2d.Flow implements GameScene implements h2d.domkit.
|
||||
area.y = obj.y;
|
||||
area.onClick = function(_) {
|
||||
trace("Room:" + obj.name);
|
||||
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:
|
||||
@ -42,11 +59,18 @@ class WorldMapScene extends h2d.Flow implements GameScene implements h2d.domkit.
|
||||
|
||||
#if debug
|
||||
trace('skipping intro dialogue');
|
||||
Game.current.globalEventBus.publishEvent(new OpenRoomEvent("hangar"));
|
||||
#else
|
||||
Game.current.globalEventBus.publishEvent(new StartDialogueNode("Intro"));
|
||||
#end
|
||||
}
|
||||
|
||||
public function openRoom(event:OpenRoomEvent) {
|
||||
var room = rooms.get(event.roomName);
|
||||
room.isOpen = true;
|
||||
room.area.alpha = 0;
|
||||
}
|
||||
|
||||
public function getH2dObject() {
|
||||
return this;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user