Compare commits

...

10 Commits

Author SHA1 Message Date
3wc
2ad54aa613 WIP: Switch to domkit for dialogue 2024-02-18 12:25:03 -03:00
3wc
ed8bc13402 Moar TODO 2024-02-16 23:57:42 -03:00
3wc
d6b042f2a4 Drop useless Main file 2024-02-16 23:57:17 -03:00
3wc
c768073503 Uncomment quarters dialogue 2024-02-16 23:38:39 -03:00
3wc
32885707de Moar TODO 2024-02-16 23:38:29 -03:00
3wc
bb7690e606 Add TODO 2024-02-16 21:53:53 -03:00
3wc
4b00d713a9 Twiddle text a bit 2024-02-16 03:55:49 -03:00
3wc
8be7c18d4f 4matting 2024-02-16 03:52:16 -03:00
3wc
fd6b9ee8dd Split yarn, handle inactive options 2024-02-16 03:51:57 -03:00
3wc
808958f7cc Tidy up some temp files 2024-02-16 03:51:49 -03:00
23 changed files with 709 additions and 609 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
/bin/*
/res/.tmp/
/res/rewild.tiled-*

27
TODO.md Normal file
View File

@ -0,0 +1,27 @@
# TODO
## Features
- Saving and loading games
- Character select
- Stats
- Better open / closed state graphics for rooms
- Displaying sprites (characters, objects)
- Inventory
- Room labels
- Background music
- Sound effects
## Bugs
- Fix console rendering issues
### Dialogue
- Text formatting
- Character profiles / speaker ID
## Code architecture
- Move dialogue- and option-drawing out of `Game.hx`
- Use domkit for dialogue

View File

@ -3,5 +3,5 @@
-lib heaps:git:https://github.com/HeapsIO/heaps.git
-lib tiledhx
-lib hxyarn
-main Main
-main Game
-lib domkit

View File

@ -1 +0,0 @@
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

Binary file not shown.

View File

@ -1,14 +0,0 @@
{
"automappingRulesFile": "",
"commands": [
],
"compatibilityVersion": 1100,
"extensionsPath": "extensions",
"folders": [
"."
],
"properties": [
],
"propertyTypes": [
]
}

View File

@ -1,45 +0,0 @@
{
"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"
]
}

View File

@ -52,3 +52,22 @@ menubutton:hover text {
menubutton:active {
background: #666;
}
flow.dialogue-container {
fill-width: true;
height: 20;
debug: true;
}
dialogue-box {
fill-width: true;
height: 20;
}
scale-grid#dialogueBackground {
/* fill-width: true; */
}
/* text#dialogueText { */
/* font : url("res/font/minecraftia_regular_6.fnt"); */
/* } */

View File

@ -10,35 +10,3 @@ You: What happened to the updates from mission control?
You: Let's have another look around...
<<room quarters>>
===
title: Room:quarters
---
<<declare $roll = 0>>
// You: It's the crew quarters.
// You: Well, it will be. Set-up hasn't started yet.
// You: That was meant to be one of my first jobs after defrost...
// You: ...but it doesn't exactly seem like a priority now.
You: Maybe there's something useful here?
-> Search the lockers [perception]
<<set $roll to dice(6)>>
<<if $roll > 2>>
You: Aha! A small piece of paper with the **hangar access code**.
<<room hangar>>
<<else>>
You: Just some dust bunnies. Guess they stowed away from Earth.
<<endif>>
-> Set up a sleeping mat [ingenuity]
<<set $roll to dice(6)>>
<<if $roll > 2>>
You: Nice, at least I have somewhere to crash now.
<<else>>
You: Hmm, I was never good at this camping stuff. Maybe I can find somewhere else to rest.
<<endif>>
===
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?
===

37
res/text/rooms.yarn Normal file
View File

@ -0,0 +1,37 @@
title: Room:quarters
---
<<declare $roll = 0>>
<<declare $hangarKeyFound = false>>
<<declare $sleepingMatSetUp = false>>
You: It's the crew quarters.
You: Well, it will be. Set-up hasn't started yet.
You: That was meant to be one of my first jobs after defrost...
You: ...but it doesn't exactly seem like a priority now.
You: Maybe there's something useful here?
-> Search the lockers (perception) <<if not $hangarKeyFound>>
<<set $roll to dice(6)>>
<<if $roll > 2>>
You: Aha! A small piece of paper with the **hangar access code**.
<<room hangar>>
<<set $hangarKeyFound to true>>
<<else>>
You: Just some dust bunnies. Guess they stowed away from Earth.
<<endif>>
-> Set up a sleeping mat (ingenuity) <<if not $sleepingMatSetUp>>
<<set $roll to dice(6)>>
<<if $roll > 2>>
You: Nice, at least I have somewhere to crash now.
<<set $sleepingMatSetUp to true>>
<<else>>
You: Hmm, I was never good at this camping stuff. Maybe I can find somewhere else to rest.
<<endif>>
-> Leave
===
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?
===

View File

@ -1,22 +1,14 @@
import h2d.Layers;
import h2d.Console;
import h3d.Vector4;
import scene.TitleScene;
import scene.WorldMapScene;
import scene.GameScene;
import event.EventBus;
import event.ChangeSceneEvent;
import Const;
import dialogue.DialogueBox;
import listeners.DialogueBoxController;
import dialogue.DialogueManager;
import dialogue.event.LineShown;
import dialogue.event.OptionsShown;
import dialogue.event.OptionSelected;
import dialogue.event.DialogueComplete;
import dialogue.event.NextLine;
import dialogue.command.OpenRoomCommand;
@:uiComp("game-container")
@ -34,20 +26,19 @@ class GameContainer extends h2d.Flow implements h2d.domkit.Object {
}
class Game extends hxd.App {
public static var loader = new tiled.Tiled();
public static var current:Game; // Current Game (singleton)
public var font:h2d.Font;
public var curDialogue:h2d.Object;
public var options:Array<h2d.ScaleGrid> = [];
public var dialogueManager:DialogueManager;
public var globalEventBus:EventBus;
public static var current:Game; // Current Game (singleton)
var layer:Layers;
public var root:GameContainer;
public var console:Console;
var style = null;
public var globalEventBus:EventBus;
public static var loader = new tiled.Tiled();
var dialogueBoxController:DialogueBoxController;
var layer:Layers;
var style = null;
override function init() {
s2d.scaleMode = Stretch(Const.W, Const.H);
@ -62,7 +53,6 @@ class Game extends hxd.App {
root = new GameContainer();
root.horizontalAlign = root.verticalAlign = Middle;
// s2d.add(root);
layer.addChildAt(root, 1);
onResize();
@ -72,33 +62,31 @@ class Game extends hxd.App {
style.addObject(root);
font = Res.font.minecraftia_regular_6.toFont();
font.resizeTo(18);
#if debug
console = new Console(font);
layer.addChildAt(console, 4);
#end
font.resizeTo(20);
globalEventBus = new EventBus(console);
globalEventBus.subscribe(ChangeSceneEvent, onChangeScene);
dialogueManager = new DialogueManager(globalEventBus);
var yarnText = [
hxd.Res.text.intro.entry.getText(),
];
var yarnFileNames = [
hxd.Res.text.intro.entry.name,
];
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,];
dialogueManager.load(yarnText, yarnFileNames);
globalEventBus.subscribe(LineShown, dialogue);
globalEventBus.subscribe(OptionsShown, renderOptions);
globalEventBus.subscribe(OptionSelected, onOptionSelected);
globalEventBus.subscribe(DialogueComplete, onDialogueComplete);
dialogueManager.addCommandHandler(new OpenRoomCommand(globalEventBus));
var dialogueParent = new h2d.Flow();
dialogueParent.dom = domkit.Properties.create("flow", dialogueParent);
dialogueParent.dom.addClass('dialogue-container');
style.addObject(dialogueParent);
layer.addChildAt(dialogueParent, 2);
dialogueBoxController = new DialogueBoxController(globalEventBus, dialogueParent, style);
#if debug
setGameScene(new WorldMapScene(root));
#else
@ -120,65 +108,6 @@ class Game extends hxd.App {
style.sync();
}
function dialogue(event:LineShown) {
if (curDialogue != null) {
curDialogue.remove();
}
var d = new DialogueBox(Const.W, 100, event.line());
d.y = 0;
d.onClick = function() {
globalEventBus.publishEvent(new NextLine());
};
curDialogue = d;
}
function renderOptions(event:OptionsShown) {
for (option in event.options) {
addOption(option.text, function() {
globalEventBus.publishEvent(new OptionSelected(option.index));
});
}
}
function newPanel(w, h) {
var g = new h2d.ScaleGrid(Res.ui.toTile(), 5, 5);
g.width = w;
g.height = h;
g.colorKey = 0xFF00FF;
root.scene.getH2dObject().getScene().add(g, 1);
return g;
}
function addOption(o: String, callback: () -> Void) {
var spr = newPanel(Const.W, 60);
curDialogue.addChild(spr);
var tf = new h2d.Text(font, spr);
tf.text = o;
tf.x = 10;
tf.y = 10;
spr.x = 0;
spr.y = 100 + options.length * 60;
var int = new h2d.Interactive(spr.width, spr.height, spr);
int.onClick = function(_) {
callback();
}
int.cursor = Button;
options.push(spr);
return spr;
}
function onOptionSelected(event:OptionSelected) {
for (o in options) {
o.remove();
}
options.splice(0, options.length);
}
function onDialogueComplete(event:DialogueComplete) {
curDialogue.remove();
}
public function onChangeScene(event:ChangeSceneEvent) {
setGameScene(event.newScene);
}
@ -195,4 +124,8 @@ class Game extends hxd.App {
root.scene = gs;
style.addObject(gs.getH2dObject());
}
static function main() {
new Game();
}
}

View File

@ -1,5 +0,0 @@
class Main {
static function main() {
new Game();
}
}

View File

@ -1,197 +1,229 @@
import h2d.col.Point;
import h2d.Object;
import h2d.SpriteBatch;
import tiled.types.TmxLayer;
import tiled.types.TmxMap;
using tiled.TiledTools;
class TilemapLayer extends h2d.TileGroup {
public var map:TmxMap;
public var layer:TmxLayer;
public var map:TmxMap;
public var layer:TmxLayer;
public function new(map:TmxMap, layer:TmxLayer, ?parent:Object) {
this.map = map;
this.layer = layer;
super(parent);
for (c in layer.tileChunks) {
addChunk(c);
}
// TODO: Animations
}
public function new (map:TmxMap, layer:TmxLayer, ?parent:Object) {
this.map = map;
this.layer = layer;
super(parent);
for (c in layer.tileChunks) {
addChunk(c);
}
// TODO: Animations
}
// public function gidAt(x:Int, y:Int):Int {
// if (x < 0 || x >= layer.width || y < 0 || y >= layer.height) return 0;
// return layer.data.tiles[y * layer.width + x].gid;
// }
public function addChunk(chunk:TileChunk) {
var tw = map.tileWidth;
var th = map.tileHeight;
var ix = 0, iy = 0;
var tiles = chunk.tiles, i = 0;
var tsets = map.tilesets;
switch (map.orientation) {
case Orthogonal:
var cx = chunk.x * tw + layer.offsetX;
var cy = chunk.y * th + layer.offsetY;
while (i < tiles.length) {
var gid = tiles[i++];
if (gid != 0) {
var t = tsets.getImage(gid);
var x = cx + ix * tw;
var y = cy + iy * th + th - t.height;
if (gid.flippedHorizontally) addTransform(x + t.width, y, -1, 1, 0, t);
else if (gid.flippedVertically) addTransform(x, y + t.height, 1, -1, 0, t);
else if (gid.flippedDiagonally) addTransform(x + t.width, y + t.height, -1, -1, 0, t);
else add(x, y, t);
}
if (++ix == chunk.width) { iy++; ix = 0; }
}
case Isometric:
var isoW = tw >> 1;
var isoH = th >> 1;
var cx = (chunk.x - chunk.y) * isoW + layer.offsetX;
var cy = (chunk.x + chunk.y) * isoH + layer.offsetY;
while (i < tiles.length) {
var gid = tiles[i++];
if (gid != 0) {
var t = tsets.getImage(gid);
var x = cx + (ix - iy) * isoW;
var y = cy + (ix + iy) * isoH + th - t.height;
if (gid.flippedHorizontally) addTransform(x + t.width, y, -1, 1, 0, t);
else if (gid.flippedVertically) addTransform(x, y + t.height, 1, -1, 0, t);
else if (gid.flippedDiagonally) addTransform(x + t.width, y + t.height, -1, -1, 0, t);
else add(x, y, t);
}
if (++ix == chunk.width) { iy++; ix = 0; }
}
case Staggered(staggerYAxis, staggerIndexOdd):
var staggerX = 0, staggerY = 0, stepX = tw >> 1, stepY = th >> 1;
var cx = chunk.x * stepX + layer.offsetX;
var cy = chunk.y * stepY + layer.offsetY;
if (staggerYAxis) {
if (staggerIndexOdd) {
staggerX = tw >> 1;
} else {
staggerX = -(tw >> 1);
cx -= staggerX;
}
} else {
if (staggerIndexOdd) {
staggerY = th >> 1;
} else {
staggerY = -(tw >> 1);
cy -= staggerY;
}
}
cx += (chunk.x % 2) * staggerX;
cy += (chunk.y % 2) * staggerY;
while (i < tiles.length) {
var gid = tiles[i++];
if (gid != 0) {
var t = tsets.getImage(gid);
var x = cx + ix * stepX + staggerX * (ix % 1);
var y = cy + iy * stepY + th - t.height;
if (gid.flippedHorizontally) addTransform(x + t.width, y, -1, 1, 0, t);
else if (gid.flippedVertically) addTransform(x, y + t.height, 1, -1, 0, t);
else if (gid.flippedDiagonally) addTransform(x + t.width, y + t.height, -1, -1, 0, t);
else add(x, y, t);
}
if (++ix == chunk.width) { iy++; ix = 0; }
}
case Hexagonal(sideLength, staggerYAxis, staggerIndexOdd):
// TODO: Fix
var staggerX = 0, staggerY = 0, stepX, stepY;
var cx, cy;
if (staggerYAxis) {
stepX = tw;
stepY = (th + sideLength) >> 1;
cx = chunk.x * stepX + layer.offsetX;
cy = chunk.y * stepY + layer.offsetY;
if (staggerIndexOdd) {
staggerX = tw >> 1;
} else {
staggerX = -(tw >> 1);
cx -= staggerX;
}
} else {
stepX = (tw + sideLength) >> 1;
stepY = th;
cx = chunk.x * stepX + layer.offsetX;
cy = chunk.y * stepY + layer.offsetY;
if (staggerIndexOdd) {
staggerY = th >> 1;
} else {
staggerY = -(tw >> 1);
cy -= staggerY;
}
}
while (i < tiles.length) {
var gid = tiles[i++];
if (gid != 0) {
var t = tsets.getImage(gid);
var x = cx + ix * stepX;
var y = cy + iy * stepY + th - t.height;
if (gid.flippedHorizontally) addTransform(x + t.width, y, -1, 1, 0, t);
else if (gid.flippedVertically) addTransform(x, y + t.height, 1, -1, 0, t);
else if (gid.flippedDiagonally) addTransform(x + t.width, y + t.height, -1, -1, 0, t);
else add(x, y, t);
}
if (++ix == chunk.width) { iy++; ix = 0; }
}
}
}
public function addTile(tx:Int, ty:Int, ox:Float, oy:Float, gid:TmxTileIndex) {
if (gid == 0) return;
var t = map.tilesets.getImage(gid);
if (t != null) {
var x, y;
switch (map.orientation) {
case Orthogonal:
x = tx * map.tileWidth + ox;
y = ty * map.tileHeight + oy;
case Isometric:
x = (tx - ty) * (map.tileWidth >> 1) + ox;
y = (tx + ty) * (map.tileHeight >> 1) + oy;
case Staggered(staggerYAxis, staggerIndexOdd):
if (staggerYAxis) {
y = ty * (map.tileHeight >> 1);
if (staggerIndexOdd)
x = tx * map.tileWidth + (tx % 2) * (map.tileWidth >> 1);
else
x = tx * map.tileWidth + ((tx + 1) % 2) * (map.tileWidth >> 1);
} else {
x = tx * (map.tileWidth >> 1);
if (staggerIndexOdd)
y = ty * map.tileHeight + (tx % 2) * (map.tileHeight >> 1);
else
y = ty * map.tileHeight + ((tx + 1) % 2) * (map.tileHeight >> 1);
}
case Hexagonal(sideLength, staggerYAxis, staggerIndexOdd):
if (staggerYAxis) {
y = ty * ((map.tileHeight + sideLength) >> 1);
if (staggerIndexOdd)
x = tx * map.tileWidth + (tx % 2) * (map.tileWidth >> 1);
else
x = tx * map.tileWidth + ((tx + 1) % 2) * (map.tileWidth >> 1);
} else {
x = tx * ((map.tileWidth + sideLength) >> 1);
if (staggerIndexOdd)
y = ty * map.tileHeight + (tx % 2) * (map.tileHeight >> 1);
else
y = ty * map.tileHeight + ((tx + 1) % 2) * (map.tileHeight >> 1);
}
}
if (gid.flippedHorizontally) addTransform(x + t.width, y, -1, 1, 0, t);
else if (gid.flippedVertically) addTransform(x, y + t.height, 1, -1, 0, t);
else if (gid.flippedDiagonally) addTransform(x + t.width, y + t.height, -1, -1, 0, t);
else add(x, y, t);
}
}
// public function gidAt(x:Int, y:Int):Int {
// if (x < 0 || x >= layer.width || y < 0 || y >= layer.height) return 0;
// return layer.data.tiles[y * layer.width + x].gid;
// }
public function addChunk(chunk:TileChunk) {
var tw = map.tileWidth;
var th = map.tileHeight;
var ix = 0, iy = 0;
var tiles = chunk.tiles, i = 0;
var tsets = map.tilesets;
switch (map.orientation) {
case Orthogonal:
var cx = chunk.x * tw + layer.offsetX;
var cy = chunk.y * th + layer.offsetY;
while (i < tiles.length) {
var gid = tiles[i++];
if (gid != 0) {
var t = tsets.getImage(gid);
var x = cx + ix * tw;
var y = cy + iy * th + th - t.height;
if (gid.flippedHorizontally)
addTransform(x + t.width, y, -1, 1, 0, t);
else if (gid.flippedVertically)
addTransform(x, y + t.height, 1, -1, 0, t);
else if (gid.flippedDiagonally)
addTransform(x + t.width, y + t.height, -1, -1, 0, t);
else
add(x, y, t);
}
if (++ix == chunk.width) {
iy++;
ix = 0;
}
}
case Isometric:
var isoW = tw >> 1;
var isoH = th >> 1;
var cx = (chunk.x - chunk.y) * isoW + layer.offsetX;
var cy = (chunk.x + chunk.y) * isoH + layer.offsetY;
while (i < tiles.length) {
var gid = tiles[i++];
if (gid != 0) {
var t = tsets.getImage(gid);
var x = cx + (ix - iy) * isoW;
var y = cy + (ix + iy) * isoH + th - t.height;
if (gid.flippedHorizontally)
addTransform(x + t.width, y, -1, 1, 0, t);
else if (gid.flippedVertically)
addTransform(x, y + t.height, 1, -1, 0, t);
else if (gid.flippedDiagonally)
addTransform(x + t.width, y + t.height, -1, -1, 0, t);
else
add(x, y, t);
}
if (++ix == chunk.width) {
iy++;
ix = 0;
}
}
case Staggered(staggerYAxis, staggerIndexOdd):
var staggerX = 0,
staggerY = 0,
stepX = tw >> 1,
stepY = th >> 1;
var cx = chunk.x * stepX + layer.offsetX;
var cy = chunk.y * stepY + layer.offsetY;
if (staggerYAxis) {
if (staggerIndexOdd) {
staggerX = tw >> 1;
} else {
staggerX = -(tw >> 1);
cx -= staggerX;
}
} else {
if (staggerIndexOdd) {
staggerY = th >> 1;
} else {
staggerY = -(tw >> 1);
cy -= staggerY;
}
}
cx += (chunk.x % 2) * staggerX;
cy += (chunk.y % 2) * staggerY;
while (i < tiles.length) {
var gid = tiles[i++];
if (gid != 0) {
var t = tsets.getImage(gid);
var x = cx + ix * stepX + staggerX * (ix % 1);
var y = cy + iy * stepY + th - t.height;
if (gid.flippedHorizontally)
addTransform(x + t.width, y, -1, 1, 0, t);
else if (gid.flippedVertically)
addTransform(x, y + t.height, 1, -1, 0, t);
else if (gid.flippedDiagonally)
addTransform(x + t.width, y + t.height, -1, -1, 0, t);
else
add(x, y, t);
}
if (++ix == chunk.width) {
iy++;
ix = 0;
}
}
case Hexagonal(sideLength, staggerYAxis, staggerIndexOdd):
// TODO: Fix
var staggerX = 0, staggerY = 0, stepX, stepY;
var cx, cy;
if (staggerYAxis) {
stepX = tw;
stepY = (th + sideLength) >> 1;
cx = chunk.x * stepX + layer.offsetX;
cy = chunk.y * stepY + layer.offsetY;
if (staggerIndexOdd) {
staggerX = tw >> 1;
} else {
staggerX = -(tw >> 1);
cx -= staggerX;
}
} else {
stepX = (tw + sideLength) >> 1;
stepY = th;
cx = chunk.x * stepX + layer.offsetX;
cy = chunk.y * stepY + layer.offsetY;
if (staggerIndexOdd) {
staggerY = th >> 1;
} else {
staggerY = -(tw >> 1);
cy -= staggerY;
}
}
while (i < tiles.length) {
var gid = tiles[i++];
if (gid != 0) {
var t = tsets.getImage(gid);
var x = cx + ix * stepX;
var y = cy + iy * stepY + th - t.height;
if (gid.flippedHorizontally)
addTransform(x + t.width, y, -1, 1, 0, t);
else if (gid.flippedVertically)
addTransform(x, y + t.height, 1, -1, 0, t);
else if (gid.flippedDiagonally)
addTransform(x + t.width, y + t.height, -1, -1, 0, t);
else
add(x, y, t);
}
if (++ix == chunk.width) {
iy++;
ix = 0;
}
}
}
}
public function addTile(tx:Int, ty:Int, ox:Float, oy:Float, gid:TmxTileIndex) {
if (gid == 0)
return;
var t = map.tilesets.getImage(gid);
if (t != null) {
var x, y;
switch (map.orientation) {
case Orthogonal:
x = tx * map.tileWidth + ox;
y = ty * map.tileHeight + oy;
case Isometric:
x = (tx - ty) * (map.tileWidth >> 1) + ox;
y = (tx + ty) * (map.tileHeight >> 1) + oy;
case Staggered(staggerYAxis, staggerIndexOdd):
if (staggerYAxis) {
y = ty * (map.tileHeight >> 1);
if (staggerIndexOdd)
x = tx * map.tileWidth + (tx % 2) * (map.tileWidth >> 1);
else
x = tx * map.tileWidth + ((tx + 1) % 2) * (map.tileWidth >> 1);
} else {
x = tx * (map.tileWidth >> 1);
if (staggerIndexOdd)
y = ty * map.tileHeight + (tx % 2) * (map.tileHeight >> 1);
else
y = ty * map.tileHeight + ((tx + 1) % 2) * (map.tileHeight >> 1);
}
case Hexagonal(sideLength, staggerYAxis, staggerIndexOdd):
if (staggerYAxis) {
y = ty * ((map.tileHeight + sideLength) >> 1);
if (staggerIndexOdd)
x = tx * map.tileWidth + (tx % 2) * (map.tileWidth >> 1);
else
x = tx * map.tileWidth + ((tx + 1) % 2) * (map.tileWidth >> 1);
} else {
x = tx * ((map.tileWidth + sideLength) >> 1);
if (staggerIndexOdd)
y = ty * map.tileHeight + (tx % 2) * (map.tileHeight >> 1);
else
y = ty * map.tileHeight + ((tx + 1) % 2) * (map.tileHeight >> 1);
}
}
if (gid.flippedHorizontally)
addTransform(x + t.width, y, -1, 1, 0, t);
else if (gid.flippedVertically)
addTransform(x, y + t.height, 1, -1, 0, t);
else if (gid.flippedDiagonally)
addTransform(x + t.width, y + t.height, -1, -1, 0, t);
else
add(x, y, t);
}
}
}

View File

@ -0,0 +1,135 @@
package components;
import dialogue.event.NextLine;
@:uiComp("dialogue-option")
class DialogueOptionComponent extends h2d.Flow implements h2d.domkit.Object {
static var SRC = <dialogue-option>
<text text={label} public font={Game.current.font} id="labelTxt" />
</dialogue-option>;
public var label(get, set):String;
function get_label()
return labelTxt.text;
function set_label(s) {
labelTxt.text = s;
return s;
}
public function new(label:String, ?parent) {
super(parent);
initComponent();
enableInteractive = true;
interactive.onClick = function(_) onClick();
interactive.onOver = function(_) {
dom.hover = true;
};
interactive.onPush = function(_) {
dom.active = true;
};
interactive.onRelease = function(_) {
dom.active = false;
};
interactive.onOut = function(_) {
dom.hover = false;
};
}
public dynamic function onClick() {}
}
@:uiComp("dialogue-options")
class DialogueOptionsComponent extends h2d.Flow implements h2d.domkit.Object {
static var SRC = <dialogue-options>
${options}
</dialogue-options>;
public var options:Array<DialogueOptionComponent>;
}
@:uiComp("dialogue-box")
class DialogueBoxComponent extends h2d.Flow implements h2d.domkit.Object {
var timer:haxe.Timer;
var chan:hxd.snd.Channel;
var textPos:Int = 0;
var game:Game;
static var SRC = <dialogue-box>
<scale-grid id="dialogueBackground">
<text text={displayedText} public font={Game.current.font} id="dialogueText" />
</scale-grid>
</dialogue-box>
public var displayedText(get, set):String;
function get_displayedText()
return dialogueText.text;
function set_displayedText(s) {
dialogueText.text = s;
return s;
}
public var internalText(default, set):String;
function set_internalText(t) {
internalText = t;
timer = new haxe.Timer(30);
timer.run = updateText;
displayedText = "";
textPos = 0;
return t;
}
public function new(text:String, ?parent) {
this.game = Game.current;
super(parent);
initComponent();
internalText = text;
this.dialogueBackground.tile = Res.ui.toTile();
this.dialogueBackground.borderWidth = 5;
this.dialogueBackground.borderHeight = 5;
this.dialogueBackground.colorKey = 0xFF00FF;
this.dialogueBackground.width = this.innerWidth;
this.dialogueBackground.height = this.innerHeight;
// trace(this.dialogueBackground.width);
enableInteractive = true;
interactive.onClick = function(_) onClick();
}
function updateText() {
if (textPos == internalText.length) {
timer.stop();
// onReady();
// if (chan != null)
// chan.stop();
return;
}
// if (chan != null) {
// switch (text.charCodeAt(textPos)) {
// case " ".code, "\n".code:
// chan.volume = 0;
// default:
// if (chan.volume == 0)
// chan.volume = 1
// else
// chan.volume *= 0.9;
// }
// }
textPos++;
displayedText = internalText.substr(0, textPos);
}
public dynamic function onClick() {
if (textPos == internalText.length)
Game.current.globalEventBus.publishEvent(new NextLine());
else if (textPos < internalText.length) {
textPos = internalText.length;
displayedText = internalText;
updateText();
};
}
}

View File

@ -1,107 +0,0 @@
package dialogue;
class DialogueBox extends h2d.Object {
var game:Game;
var bg:h2d.ScaleGrid;
var tf:h2d.Text;
var timer:haxe.Timer;
var int:h2d.Interactive;
public var width(default, set):Int;
public var height(default, set):Int;
public var text(default, set):String;
var textPos:Int = 0;
var chan:hxd.snd.Channel;
public function new(width:Int, height:Int, text:String) {
super();
if (text == null)
text = "NULL";
game = Game.current;
cast(game.root, h2d.Object).getScene().add(this, 1);
bg = new h2d.ScaleGrid(Res.ui.toTile(), 5, 5, this);
bg.colorKey = 0xFF00FF;
tf = new h2d.Text(game.font, this);
tf.y = 5;
tf.x = 7;
tf.dropShadow = {
dx: 0,
dy: 1,
color: 0,
alpha: 0.3
};
int = new h2d.Interactive(0, 0, this);
int.onClick = function(_) click();
this.width = width;
this.height = height;
this.text = text;
}
override function onRemove() {
super.onRemove();
if (chan != null)
chan.stop();
timer.stop();
}
function updateText() {
if (textPos == text.length) {
timer.stop();
onReady();
if (chan != null)
chan.stop();
return;
}
if (chan != null) {
switch (text.charCodeAt(textPos)) {
case " ".code, "\n".code:
chan.volume = 0;
default:
if (chan.volume == 0)
chan.volume = 1
else
chan.volume *= 0.9;
}
}
textPos++;
tf.text = text.substr(0, textPos);
}
public function click() {
if (textPos == text.length)
onClick()
else if (textPos < text.length) {
textPos = text.length;
tf.text = text;
updateText();
};
}
public dynamic function onClick() {}
public dynamic function onReady() {}
function set_text(t) {
text = t;
timer = new haxe.Timer(30);
timer.run = updateText;
tf.text = "";
textPos = 0;
return t;
}
function set_width(w:Int) {
bg.width = w;
int.width = w;
tf.maxWidth = w - 14;
tf.text = text;
return width = w;
}
function set_height(h:Int) {
bg.height = h;
int.height = h;
return height = h;
}
}

View File

@ -10,7 +10,6 @@ import hxyarn.dialogue.OptionSet;
import hxyarn.dialogue.markup.MarkupParseResult;
import hxyarn.compiler.Compiler;
import hxyarn.compiler.CompilationJob;
import event.EventBus;
import dialogue.command.ICommandHandler;
import dialogue.event.LineShown;
@ -22,146 +21,144 @@ import dialogue.event.StartDialogueNode;
import dialogue.event.DialogueComplete;
class DialogueManager {
public var eventBus:EventBus;
public var eventBus:EventBus;
var storage = new MemoryVariableStore();
var dialogue:Dialogue;
var stringTable:Map<String, StringInfo>;
var commandHandlers = new Map<String, ICommandHandler>();
var storage = new MemoryVariableStore();
var dialogue:Dialogue;
var stringTable:Map<String, StringInfo>;
var commandHandlers = new Map<String, ICommandHandler>();
public var waitingForOption:Bool = false;
public var waitingForOption:Bool = false;
public function new(eventBus:EventBus) {
this.eventBus = eventBus;
dialogue = new Dialogue(new MemoryVariableStore());
public function new(eventBus:EventBus) {
this.eventBus = eventBus;
dialogue = new Dialogue(new MemoryVariableStore());
dialogue.logDebugMessage = this.logDebugMessage;
dialogue.logErrorMessage = this.logErrorMessage;
dialogue.lineHandler = this.lineHandler;
dialogue.optionsHandler = this.optionsHandler;
dialogue.commandHandler = this.commandHandler;
dialogue.nodeCompleteHandler = this.nodeCompleteHandler;
dialogue.nodeStartHandler = this.nodeStartHandler;
dialogue.dialogueCompleteHandler = this.dialogueCompleteHandler;
dialogue.logDebugMessage = this.logDebugMessage;
dialogue.logErrorMessage = this.logErrorMessage;
dialogue.lineHandler = this.lineHandler;
dialogue.optionsHandler = this.optionsHandler;
dialogue.commandHandler = this.commandHandler;
dialogue.nodeCompleteHandler = this.nodeCompleteHandler;
dialogue.nodeStartHandler = this.nodeStartHandler;
dialogue.dialogueCompleteHandler = this.dialogueCompleteHandler;
eventBus.subscribe(NextLine, this.nextLine);
eventBus.subscribe(OptionSelected, this.optionSelected);
eventBus.subscribe(StartDialogueNode, function(event) {
this.runNode(event.node);
});
}
eventBus.subscribe(NextLine, this.nextLine);
eventBus.subscribe(OptionSelected, this.optionSelected);
eventBus.subscribe(StartDialogueNode, function(event) {
this.runNode(event.node);
});
}
public function load(text:Array<String>, fileNames:Array<String>) {
var job = CompilationJob.createFromStrings(text, fileNames, dialogue.library);
var compiler = Compiler.compile(job);
stringTable = compiler.stringTable;
public function load(text:Array<String>, fileNames:Array<String>) {
var job = CompilationJob.createFromStrings(text, fileNames, dialogue.library);
var compiler = Compiler.compile(job);
stringTable = compiler.stringTable;
dialogue.addProgram(compiler.program);
}
dialogue.addProgram(compiler.program);
}
public function runNode(nodeName:String) {
dialogue.setNode(nodeName);
dialogue.resume();
}
public function runNode(nodeName:String) {
dialogue.setNode(nodeName);
dialogue.resume();
}
public function unload() {
dialogue.unloadAll();
}
public function unload() {
dialogue.unloadAll();
}
public function resume() {
dialogue.resume();
}
public function resume() {
dialogue.resume();
}
public function logDebugMessage(message:String):Void {
}
public function logDebugMessage(message:String):Void {}
public function logErrorMessage(message:String):Void {
}
public function logErrorMessage(message:String):Void {}
public function nextLine(event:NextLine) {
if ((dialogue.isActive()) && (!waitingForOption))
dialogue.resume();
}
public function nextLine(event:NextLine) {
if ((dialogue.isActive()) && (!waitingForOption))
dialogue.resume();
}
public function lineHandler(line:Line):Void {
var text = getComposedTextForLine(line);
eventBus.publishEvent(new LineShown(text));
}
public function lineHandler(line:Line):Void {
var text = getComposedTextForLine(line);
eventBus.publishEvent(new LineShown(text));
}
public function optionSelected(event:OptionSelected) {
dialogue.setSelectedOption(event.index);
dialogue.resume();
waitingForOption = false;
}
public function optionSelected(event:OptionSelected) {
dialogue.setSelectedOption(event.index);
dialogue.resume();
waitingForOption = false;
}
public function optionsHandler(options:OptionSet) {
var optionCount = options.options.length;
var optionChoices = new Array<OptionChoice>();
public function optionsHandler(options:OptionSet) {
var optionCount = options.options.length;
var optionChoices = new Array<OptionChoice>();
for (i => option in options.options) {
var markup = getComposedTextForLine(option.line);
optionChoices.push({
text: markup.text,
index: i,
enabled: option.enabled,
markup: markup
});
}
for (i => option in options.options) {
var markup = getComposedTextForLine(option.line);
optionChoices.push({
text: markup.text,
index: i,
enabled: option.enabled,
markup: markup
});
}
eventBus.publishEvent(new OptionsShown(optionChoices));
eventBus.publishEvent(new OptionsShown(optionChoices));
waitingForOption = true;
}
waitingForOption = true;
}
public function getComposedTextForLine(line:Line):MarkupParseResult {
var substitutedText = Dialogue.expandSubstitutions(stringTable[line.id].text, line.substitutions);
public function getComposedTextForLine(line:Line):MarkupParseResult {
var substitutedText = Dialogue.expandSubstitutions(stringTable[line.id].text, line.substitutions);
return dialogue.parseMarkup(substitutedText);
}
return dialogue.parseMarkup(substitutedText);
}
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;
}
}
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;
}
public function addCommandHandler(handler:ICommandHandler) {
if (handler.commandName == null || handler.commandName == "") {
trace("Command handler has no command name");
return;
commandHandlers.set(handler.commandName, handler);
}
commandHandlers.set(handler.commandName, handler);
}
public function nodeCompleteHandler(nodeName:String) {}
public function nodeCompleteHandler(nodeName:String) {}
public function nodeStartHandler(nodeName:String) {}
public function nodeStartHandler(nodeName:String) {}
public function dialogueCompleteHandler() {
eventBus.publishEvent(new DialogueComplete(""));
}
public function dialogueCompleteHandler() {
eventBus.publishEvent(new DialogueComplete(""));
}
public function getNodeNames(?includesTag = "") {
var nodeNames = [];
for (nodeName in dialogue.allNodes) {
if (includesTag == "") {
nodeNames.push(nodeName);
continue;
}
public function getNodeNames(?includesTag = "") {
var nodeNames = [];
for (nodeName in dialogue.allNodes) {
if (includesTag == "") {
nodeNames.push(nodeName);
continue;
}
var tags = dialogue.getTagsForNode(nodeName);
if (tags.contains(includesTag)) {
nodeNames.push(nodeName);
}
}
return nodeNames;
}
var tags = dialogue.getTagsForNode(nodeName);
if (tags.contains(includesTag)) {
nodeNames.push(nodeName);
}
}
return nodeNames;
}
}

View File

@ -40,6 +40,7 @@ class EventBus {
#end
return;
}
trace('Publishing event $type');
for (func in listeners.get(type))
func(event);

View File

@ -0,0 +1,125 @@
package listeners;
import Game;
import event.EventBus;
import dialogue.DialogueManager;
import dialogue.event.LineShown;
import dialogue.event.OptionsShown;
import dialogue.event.OptionSelected;
import dialogue.event.DialogueComplete;
import dialogue.event.NextLine;
import components.DialogueBoxComponent;
class DialogueBoxController {
public var curDialogue:DialogueBoxComponent;
var game:Game;
var bg:h2d.ScaleGrid;
var tf:h2d.Text;
var int:h2d.Interactive;
var eventBus:EventBus;
var parent:h2d.Object;
var style:h2d.domkit.Style;
public function new(eventBus:EventBus, parent:h2d.Object, style:h2d.domkit.Style) {
this.parent = parent;
this.style = style;
// game = Game.current;
// parent.getScene().add(this, 1);
// bg = new h2d.ScaleGrid(Res.ui.toTile(), 5, 5, this);
// bg.colorKey = 0xFF00FF;
// tf = new h2d.Text(game.font, this);
// tf.y = 5;
// tf.x = 7;
// tf.dropShadow = {
// dx: 0,
// dy: 1,
// color: 0,
// alpha: 0.3
// };
// int = new h2d.Interactive(0, 0, this);
// int.onClick = function(_) click();
eventBus.subscribe(LineShown, dialogue);
// eventBus.subscribe(OptionsShown, renderOptions);
// eventBus.subscribe(OptionSelected, onOptionSelected);
eventBus.subscribe(DialogueComplete, onDialogueComplete);
}
// override function onRemove() {
// super.onRemove();
// // if (chan != null)
// // chan.stop();
// // timer.stop();
// }
public dynamic function onClick() {}
public dynamic function onReady() {}
function dialogue(event:LineShown) {
if (curDialogue != null) {
curDialogue.remove();
}
var d = new DialogueBoxComponent(event.line(), this.parent);
style.addObject(d);
curDialogue = d;
}
// function renderOptions(event:OptionsShown) {
// for (option in event.options) {
// addOption(option.text, option.enabled, function() {
// if (option.enabled) {
// globalEventBus.publishEvent(new OptionSelected(option.index));
// }
// });
// }
// }
//
// function newPanel(w, h) {
// var g = new h2d.ScaleGrid(Res.ui.toTile(), 5, 5);
// g.width = w;
// g.height = h;
// g.colorKey = 0xFF00FF;
// root.scene.getH2dObject().getScene().add(g, 1);
// return g;
// }
//
// function addOption(o:String, enabled:Bool, callback:() -> Void) {
// var spr = newPanel(Const.W, 60);
// curDialogue.addChild(spr);
// var tf = new h2d.Text(font, spr);
// if (!enabled) {
// tf.color = new Vector4(0.5, 0.5, 0.5, 1);
// }
// tf.text = o;
// tf.x = 10;
// tf.y = 10;
// spr.x = 0;
// spr.y = 100 + options.length * 60;
// var int = new h2d.Interactive(spr.width, spr.height, spr);
// int.onClick = function(_) {
// callback();
// }
// int.cursor = Button;
// options.push(spr);
// return spr;
// }
//
// function onOptionSelected(event:OptionSelected) {
// for (o in options) {
// o.remove();
// }
// options.splice(0, options.length);
// }
function onDialogueComplete(event:DialogueComplete) {
curDialogue.remove();
}
}

View File

@ -1,5 +1,5 @@
package scene;
interface GameScene {
function getH2dObject():h2d.Object;
function getH2dObject():h2d.Object;
}

View File

@ -1,9 +1,7 @@
package scene;
import scene.WorldMapScene;
import event.ChangeSceneEvent;
import components.MenubuttonComponent;
@:uiComp("heading")
@ -41,12 +39,11 @@ class TitleScene extends h2d.Flow implements GameScene implements h2d.domkit.Obj
}
#if hl
btnQuit.onClick = function() {
Sys.exit(0);
Sys.exit(0);
}
#else
btnQuit.remove();
btnQuit.remove();
#end
}
public function getH2dObject() {

View File

@ -5,9 +5,9 @@ import event.OpenRoomEvent;
import TilemapLayer;
typedef Room = {
rect:h2d.Graphics,
area:h2d.Interactive,
isOpen:Bool
rect:h2d.Graphics,
area:h2d.Interactive,
isOpen:Bool
}
@:uiComp("world-map-scene")
@ -15,7 +15,7 @@ class WorldMapScene extends h2d.Flow implements GameScene implements h2d.domkit.
public var width:Int;
public var height:Int;
var rooms:Map<String,Room> = new Map<String,Room>();
var rooms:Map<String, Room> = new Map<String, Room>();
public function new(?parent) {
super(parent);
@ -28,9 +28,9 @@ class WorldMapScene extends h2d.Flow implements GameScene implements h2d.domkit.
Game.current.globalEventBus.subscribe(OpenRoomEvent, openRoom);
for (layer in (map.layers)) {
switch(layer.kind) {
switch (layer.kind) {
case TTileLayer:
var l = new TilemapLayer(map, layer, root);
var l = new TilemapLayer(map, layer, root);
case TObjectGroup:
for (obj in layer.objects) {
var rect = new h2d.Graphics(root);
@ -42,7 +42,6 @@ class WorldMapScene extends h2d.Flow implements GameScene implements h2d.domkit.
area.x = obj.x;
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));
@ -60,7 +59,7 @@ class WorldMapScene extends h2d.Flow implements GameScene implements h2d.domkit.
#if debug
trace('skipping intro dialogue');
Game.current.globalEventBus.publishEvent(new OpenRoomEvent("quarters"));
#else
#else
Game.current.globalEventBus.publishEvent(new StartDialogueNode("Intro"));
#end
}