4matting
This commit is contained in:
parent
fd6b9ee8dd
commit
8be7c18d4f
25
src/Game.hx
25
src/Game.hx
@ -1,23 +1,19 @@
|
|||||||
import h2d.Layers;
|
import h2d.Layers;
|
||||||
import h2d.Console;
|
import h2d.Console;
|
||||||
import h3d.Vector4;
|
import h3d.Vector4;
|
||||||
|
|
||||||
import scene.TitleScene;
|
import scene.TitleScene;
|
||||||
import scene.WorldMapScene;
|
import scene.WorldMapScene;
|
||||||
import scene.GameScene;
|
import scene.GameScene;
|
||||||
import event.EventBus;
|
import event.EventBus;
|
||||||
import event.ChangeSceneEvent;
|
import event.ChangeSceneEvent;
|
||||||
|
|
||||||
import Const;
|
import Const;
|
||||||
import dialogue.DialogueBox;
|
import dialogue.DialogueBox;
|
||||||
import dialogue.DialogueManager;
|
import dialogue.DialogueManager;
|
||||||
|
|
||||||
import dialogue.event.LineShown;
|
import dialogue.event.LineShown;
|
||||||
import dialogue.event.OptionsShown;
|
import dialogue.event.OptionsShown;
|
||||||
import dialogue.event.OptionSelected;
|
import dialogue.event.OptionSelected;
|
||||||
import dialogue.event.DialogueComplete;
|
import dialogue.event.DialogueComplete;
|
||||||
import dialogue.event.NextLine;
|
import dialogue.event.NextLine;
|
||||||
|
|
||||||
import dialogue.command.OpenRoomCommand;
|
import dialogue.command.OpenRoomCommand;
|
||||||
|
|
||||||
@:uiComp("game-container")
|
@:uiComp("game-container")
|
||||||
@ -41,11 +37,14 @@ class Game extends hxd.App {
|
|||||||
public var dialogueManager:DialogueManager;
|
public var dialogueManager:DialogueManager;
|
||||||
|
|
||||||
public var globalEventBus:EventBus;
|
public var globalEventBus:EventBus;
|
||||||
public static var current:Game; // Current Game (singleton)
|
|
||||||
|
public static var current:Game; // Current Game (singleton)
|
||||||
|
|
||||||
var layer:Layers;
|
var layer:Layers;
|
||||||
|
|
||||||
public var root:GameContainer;
|
public var root:GameContainer;
|
||||||
public var console:Console;
|
public var console:Console;
|
||||||
|
|
||||||
var style = null;
|
var style = null;
|
||||||
|
|
||||||
public static var loader = new tiled.Tiled();
|
public static var loader = new tiled.Tiled();
|
||||||
@ -86,14 +85,8 @@ class Game extends hxd.App {
|
|||||||
|
|
||||||
dialogueManager = new DialogueManager(globalEventBus);
|
dialogueManager = new DialogueManager(globalEventBus);
|
||||||
|
|
||||||
var yarnText = [
|
var yarnText = [hxd.Res.text.intro.entry.getText(), hxd.Res.text.rooms.entry.getText(),];
|
||||||
hxd.Res.text.intro.entry.getText(),
|
var yarnFileNames = [hxd.Res.text.intro.entry.name, hxd.Res.text.rooms.entry.name,];
|
||||||
hxd.Res.text.rooms.entry.getText(),
|
|
||||||
];
|
|
||||||
var yarnFileNames = [
|
|
||||||
hxd.Res.text.intro.entry.name,
|
|
||||||
hxd.Res.text.rooms.entry.name,
|
|
||||||
];
|
|
||||||
dialogueManager.load(yarnText, yarnFileNames);
|
dialogueManager.load(yarnText, yarnFileNames);
|
||||||
|
|
||||||
globalEventBus.subscribe(LineShown, dialogue);
|
globalEventBus.subscribe(LineShown, dialogue);
|
||||||
@ -155,7 +148,7 @@ class Game extends hxd.App {
|
|||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addOption(o: String, enabled : Bool, callback: () -> Void) {
|
function addOption(o:String, enabled:Bool, callback:() -> Void) {
|
||||||
var spr = newPanel(Const.W, 60);
|
var spr = newPanel(Const.W, 60);
|
||||||
curDialogue.addChild(spr);
|
curDialogue.addChild(spr);
|
||||||
var tf = new h2d.Text(font, spr);
|
var tf = new h2d.Text(font, spr);
|
||||||
@ -169,13 +162,13 @@ class Game extends hxd.App {
|
|||||||
spr.y = 100 + options.length * 60;
|
spr.y = 100 + options.length * 60;
|
||||||
var int = new h2d.Interactive(spr.width, spr.height, spr);
|
var int = new h2d.Interactive(spr.width, spr.height, spr);
|
||||||
int.onClick = function(_) {
|
int.onClick = function(_) {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
int.cursor = Button;
|
int.cursor = Button;
|
||||||
options.push(spr);
|
options.push(spr);
|
||||||
return spr;
|
return spr;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onOptionSelected(event:OptionSelected) {
|
function onOptionSelected(event:OptionSelected) {
|
||||||
for (o in options) {
|
for (o in options) {
|
||||||
o.remove();
|
o.remove();
|
||||||
|
@ -1,197 +1,229 @@
|
|||||||
import h2d.col.Point;
|
import h2d.col.Point;
|
||||||
import h2d.Object;
|
import h2d.Object;
|
||||||
import h2d.SpriteBatch;
|
import h2d.SpriteBatch;
|
||||||
|
|
||||||
import tiled.types.TmxLayer;
|
import tiled.types.TmxLayer;
|
||||||
import tiled.types.TmxMap;
|
import tiled.types.TmxMap;
|
||||||
|
|
||||||
using tiled.TiledTools;
|
using tiled.TiledTools;
|
||||||
|
|
||||||
class TilemapLayer extends h2d.TileGroup {
|
class TilemapLayer extends h2d.TileGroup {
|
||||||
|
public var map:TmxMap;
|
||||||
public var map:TmxMap;
|
public var layer:TmxLayer;
|
||||||
public var layer:TmxLayer;
|
|
||||||
|
public function new(map:TmxMap, layer:TmxLayer, ?parent:Object) {
|
||||||
public function new (map:TmxMap, layer:TmxLayer, ?parent:Object) {
|
this.map = map;
|
||||||
this.map = map;
|
this.layer = layer;
|
||||||
this.layer = layer;
|
super(parent);
|
||||||
super(parent);
|
for (c in layer.tileChunks) {
|
||||||
for (c in layer.tileChunks) {
|
addChunk(c);
|
||||||
addChunk(c);
|
}
|
||||||
}
|
// TODO: Animations
|
||||||
// TODO: Animations
|
}
|
||||||
}
|
|
||||||
|
// public function gidAt(x:Int, y:Int):Int {
|
||||||
// public function gidAt(x:Int, y:Int):Int {
|
// if (x < 0 || x >= layer.width || y < 0 || y >= layer.height) return 0;
|
||||||
// if (x < 0 || x >= layer.width || y < 0 || y >= layer.height) return 0;
|
// return layer.data.tiles[y * layer.width + x].gid;
|
||||||
// return layer.data.tiles[y * layer.width + x].gid;
|
// }
|
||||||
// }
|
public function addChunk(chunk:TileChunk) {
|
||||||
public function addChunk(chunk:TileChunk) {
|
var tw = map.tileWidth;
|
||||||
var tw = map.tileWidth;
|
var th = map.tileHeight;
|
||||||
var th = map.tileHeight;
|
var ix = 0, iy = 0;
|
||||||
var ix = 0, iy = 0;
|
var tiles = chunk.tiles, i = 0;
|
||||||
var tiles = chunk.tiles, i = 0;
|
var tsets = map.tilesets;
|
||||||
var tsets = map.tilesets;
|
switch (map.orientation) {
|
||||||
switch (map.orientation) {
|
case Orthogonal:
|
||||||
case Orthogonal:
|
var cx = chunk.x * tw + layer.offsetX;
|
||||||
var cx = chunk.x * tw + layer.offsetX;
|
var cy = chunk.y * th + layer.offsetY;
|
||||||
var cy = chunk.y * th + layer.offsetY;
|
while (i < tiles.length) {
|
||||||
while (i < tiles.length) {
|
var gid = tiles[i++];
|
||||||
var gid = tiles[i++];
|
if (gid != 0) {
|
||||||
if (gid != 0) {
|
var t = tsets.getImage(gid);
|
||||||
var t = tsets.getImage(gid);
|
var x = cx + ix * tw;
|
||||||
var x = cx + ix * tw;
|
var y = cy + iy * th + th - t.height;
|
||||||
var y = cy + iy * th + th - t.height;
|
if (gid.flippedHorizontally)
|
||||||
if (gid.flippedHorizontally) addTransform(x + t.width, y, -1, 1, 0, t);
|
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.flippedVertically)
|
||||||
else if (gid.flippedDiagonally) addTransform(x + t.width, y + t.height, -1, -1, 0, t);
|
addTransform(x, y + t.height, 1, -1, 0, t);
|
||||||
else add(x, y, t);
|
else if (gid.flippedDiagonally)
|
||||||
}
|
addTransform(x + t.width, y + t.height, -1, -1, 0, t);
|
||||||
if (++ix == chunk.width) { iy++; ix = 0; }
|
else
|
||||||
}
|
add(x, y, t);
|
||||||
case Isometric:
|
}
|
||||||
var isoW = tw >> 1;
|
if (++ix == chunk.width) {
|
||||||
var isoH = th >> 1;
|
iy++;
|
||||||
|
ix = 0;
|
||||||
var cx = (chunk.x - chunk.y) * isoW + layer.offsetX;
|
}
|
||||||
var cy = (chunk.x + chunk.y) * isoH + layer.offsetY;
|
}
|
||||||
while (i < tiles.length) {
|
case Isometric:
|
||||||
var gid = tiles[i++];
|
var isoW = tw >> 1;
|
||||||
if (gid != 0) {
|
var isoH = th >> 1;
|
||||||
var t = tsets.getImage(gid);
|
|
||||||
var x = cx + (ix - iy) * isoW;
|
var cx = (chunk.x - chunk.y) * isoW + layer.offsetX;
|
||||||
var y = cy + (ix + iy) * isoH + th - t.height;
|
var cy = (chunk.x + chunk.y) * isoH + layer.offsetY;
|
||||||
if (gid.flippedHorizontally) addTransform(x + t.width, y, -1, 1, 0, t);
|
while (i < tiles.length) {
|
||||||
else if (gid.flippedVertically) addTransform(x, y + t.height, 1, -1, 0, t);
|
var gid = tiles[i++];
|
||||||
else if (gid.flippedDiagonally) addTransform(x + t.width, y + t.height, -1, -1, 0, t);
|
if (gid != 0) {
|
||||||
else add(x, y, t);
|
var t = tsets.getImage(gid);
|
||||||
}
|
var x = cx + (ix - iy) * isoW;
|
||||||
if (++ix == chunk.width) { iy++; ix = 0; }
|
var y = cy + (ix + iy) * isoH + th - t.height;
|
||||||
}
|
if (gid.flippedHorizontally)
|
||||||
case Staggered(staggerYAxis, staggerIndexOdd):
|
addTransform(x + t.width, y, -1, 1, 0, t);
|
||||||
var staggerX = 0, staggerY = 0, stepX = tw >> 1, stepY = th >> 1;
|
else if (gid.flippedVertically)
|
||||||
var cx = chunk.x * stepX + layer.offsetX;
|
addTransform(x, y + t.height, 1, -1, 0, t);
|
||||||
var cy = chunk.y * stepY + layer.offsetY;
|
else if (gid.flippedDiagonally)
|
||||||
if (staggerYAxis) {
|
addTransform(x + t.width, y + t.height, -1, -1, 0, t);
|
||||||
if (staggerIndexOdd) {
|
else
|
||||||
staggerX = tw >> 1;
|
add(x, y, t);
|
||||||
} else {
|
}
|
||||||
staggerX = -(tw >> 1);
|
if (++ix == chunk.width) {
|
||||||
cx -= staggerX;
|
iy++;
|
||||||
}
|
ix = 0;
|
||||||
} else {
|
}
|
||||||
if (staggerIndexOdd) {
|
}
|
||||||
staggerY = th >> 1;
|
case Staggered(staggerYAxis, staggerIndexOdd):
|
||||||
} else {
|
var staggerX = 0,
|
||||||
staggerY = -(tw >> 1);
|
staggerY = 0,
|
||||||
cy -= staggerY;
|
stepX = tw >> 1,
|
||||||
}
|
stepY = th >> 1;
|
||||||
}
|
var cx = chunk.x * stepX + layer.offsetX;
|
||||||
cx += (chunk.x % 2) * staggerX;
|
var cy = chunk.y * stepY + layer.offsetY;
|
||||||
cy += (chunk.y % 2) * staggerY;
|
if (staggerYAxis) {
|
||||||
while (i < tiles.length) {
|
if (staggerIndexOdd) {
|
||||||
var gid = tiles[i++];
|
staggerX = tw >> 1;
|
||||||
if (gid != 0) {
|
} else {
|
||||||
var t = tsets.getImage(gid);
|
staggerX = -(tw >> 1);
|
||||||
var x = cx + ix * stepX + staggerX * (ix % 1);
|
cx -= staggerX;
|
||||||
var y = cy + iy * stepY + th - t.height;
|
}
|
||||||
if (gid.flippedHorizontally) addTransform(x + t.width, y, -1, 1, 0, t);
|
} else {
|
||||||
else if (gid.flippedVertically) addTransform(x, y + t.height, 1, -1, 0, t);
|
if (staggerIndexOdd) {
|
||||||
else if (gid.flippedDiagonally) addTransform(x + t.width, y + t.height, -1, -1, 0, t);
|
staggerY = th >> 1;
|
||||||
else add(x, y, t);
|
} else {
|
||||||
}
|
staggerY = -(tw >> 1);
|
||||||
if (++ix == chunk.width) { iy++; ix = 0; }
|
cy -= staggerY;
|
||||||
}
|
}
|
||||||
case Hexagonal(sideLength, staggerYAxis, staggerIndexOdd):
|
}
|
||||||
// TODO: Fix
|
cx += (chunk.x % 2) * staggerX;
|
||||||
var staggerX = 0, staggerY = 0, stepX, stepY;
|
cy += (chunk.y % 2) * staggerY;
|
||||||
var cx, cy;
|
while (i < tiles.length) {
|
||||||
if (staggerYAxis) {
|
var gid = tiles[i++];
|
||||||
stepX = tw;
|
if (gid != 0) {
|
||||||
stepY = (th + sideLength) >> 1;
|
var t = tsets.getImage(gid);
|
||||||
cx = chunk.x * stepX + layer.offsetX;
|
var x = cx + ix * stepX + staggerX * (ix % 1);
|
||||||
cy = chunk.y * stepY + layer.offsetY;
|
var y = cy + iy * stepY + th - t.height;
|
||||||
if (staggerIndexOdd) {
|
if (gid.flippedHorizontally)
|
||||||
staggerX = tw >> 1;
|
addTransform(x + t.width, y, -1, 1, 0, t);
|
||||||
} else {
|
else if (gid.flippedVertically)
|
||||||
staggerX = -(tw >> 1);
|
addTransform(x, y + t.height, 1, -1, 0, t);
|
||||||
cx -= staggerX;
|
else if (gid.flippedDiagonally)
|
||||||
}
|
addTransform(x + t.width, y + t.height, -1, -1, 0, t);
|
||||||
} else {
|
else
|
||||||
stepX = (tw + sideLength) >> 1;
|
add(x, y, t);
|
||||||
stepY = th;
|
}
|
||||||
cx = chunk.x * stepX + layer.offsetX;
|
if (++ix == chunk.width) {
|
||||||
cy = chunk.y * stepY + layer.offsetY;
|
iy++;
|
||||||
if (staggerIndexOdd) {
|
ix = 0;
|
||||||
staggerY = th >> 1;
|
}
|
||||||
} else {
|
}
|
||||||
staggerY = -(tw >> 1);
|
case Hexagonal(sideLength, staggerYAxis, staggerIndexOdd):
|
||||||
cy -= staggerY;
|
// TODO: Fix
|
||||||
}
|
var staggerX = 0, staggerY = 0, stepX, stepY;
|
||||||
}
|
var cx, cy;
|
||||||
while (i < tiles.length) {
|
if (staggerYAxis) {
|
||||||
var gid = tiles[i++];
|
stepX = tw;
|
||||||
if (gid != 0) {
|
stepY = (th + sideLength) >> 1;
|
||||||
var t = tsets.getImage(gid);
|
cx = chunk.x * stepX + layer.offsetX;
|
||||||
var x = cx + ix * stepX;
|
cy = chunk.y * stepY + layer.offsetY;
|
||||||
var y = cy + iy * stepY + th - t.height;
|
if (staggerIndexOdd) {
|
||||||
if (gid.flippedHorizontally) addTransform(x + t.width, y, -1, 1, 0, t);
|
staggerX = tw >> 1;
|
||||||
else if (gid.flippedVertically) addTransform(x, y + t.height, 1, -1, 0, t);
|
} else {
|
||||||
else if (gid.flippedDiagonally) addTransform(x + t.width, y + t.height, -1, -1, 0, t);
|
staggerX = -(tw >> 1);
|
||||||
else add(x, y, t);
|
cx -= staggerX;
|
||||||
}
|
}
|
||||||
if (++ix == chunk.width) { iy++; ix = 0; }
|
} else {
|
||||||
}
|
stepX = (tw + sideLength) >> 1;
|
||||||
}
|
stepY = th;
|
||||||
}
|
cx = chunk.x * stepX + layer.offsetX;
|
||||||
|
cy = chunk.y * stepY + layer.offsetY;
|
||||||
|
if (staggerIndexOdd) {
|
||||||
public function addTile(tx:Int, ty:Int, ox:Float, oy:Float, gid:TmxTileIndex) {
|
staggerY = th >> 1;
|
||||||
if (gid == 0) return;
|
} else {
|
||||||
var t = map.tilesets.getImage(gid);
|
staggerY = -(tw >> 1);
|
||||||
if (t != null) {
|
cy -= staggerY;
|
||||||
var x, y;
|
}
|
||||||
switch (map.orientation) {
|
}
|
||||||
case Orthogonal:
|
while (i < tiles.length) {
|
||||||
x = tx * map.tileWidth + ox;
|
var gid = tiles[i++];
|
||||||
y = ty * map.tileHeight + oy;
|
if (gid != 0) {
|
||||||
case Isometric:
|
var t = tsets.getImage(gid);
|
||||||
x = (tx - ty) * (map.tileWidth >> 1) + ox;
|
var x = cx + ix * stepX;
|
||||||
y = (tx + ty) * (map.tileHeight >> 1) + oy;
|
var y = cy + iy * stepY + th - t.height;
|
||||||
case Staggered(staggerYAxis, staggerIndexOdd):
|
if (gid.flippedHorizontally)
|
||||||
if (staggerYAxis) {
|
addTransform(x + t.width, y, -1, 1, 0, t);
|
||||||
y = ty * (map.tileHeight >> 1);
|
else if (gid.flippedVertically)
|
||||||
if (staggerIndexOdd)
|
addTransform(x, y + t.height, 1, -1, 0, t);
|
||||||
x = tx * map.tileWidth + (tx % 2) * (map.tileWidth >> 1);
|
else if (gid.flippedDiagonally)
|
||||||
else
|
addTransform(x + t.width, y + t.height, -1, -1, 0, t);
|
||||||
x = tx * map.tileWidth + ((tx + 1) % 2) * (map.tileWidth >> 1);
|
else
|
||||||
} else {
|
add(x, y, t);
|
||||||
x = tx * (map.tileWidth >> 1);
|
}
|
||||||
if (staggerIndexOdd)
|
if (++ix == chunk.width) {
|
||||||
y = ty * map.tileHeight + (tx % 2) * (map.tileHeight >> 1);
|
iy++;
|
||||||
else
|
ix = 0;
|
||||||
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)
|
public function addTile(tx:Int, ty:Int, ox:Float, oy:Float, gid:TmxTileIndex) {
|
||||||
x = tx * map.tileWidth + (tx % 2) * (map.tileWidth >> 1);
|
if (gid == 0)
|
||||||
else
|
return;
|
||||||
x = tx * map.tileWidth + ((tx + 1) % 2) * (map.tileWidth >> 1);
|
var t = map.tilesets.getImage(gid);
|
||||||
} else {
|
if (t != null) {
|
||||||
x = tx * ((map.tileWidth + sideLength) >> 1);
|
var x, y;
|
||||||
if (staggerIndexOdd)
|
switch (map.orientation) {
|
||||||
y = ty * map.tileHeight + (tx % 2) * (map.tileHeight >> 1);
|
case Orthogonal:
|
||||||
else
|
x = tx * map.tileWidth + ox;
|
||||||
y = ty * map.tileHeight + ((tx + 1) % 2) * (map.tileHeight >> 1);
|
y = ty * map.tileHeight + oy;
|
||||||
}
|
case Isometric:
|
||||||
}
|
x = (tx - ty) * (map.tileWidth >> 1) + ox;
|
||||||
if (gid.flippedHorizontally) addTransform(x + t.width, y, -1, 1, 0, t);
|
y = (tx + ty) * (map.tileHeight >> 1) + oy;
|
||||||
else if (gid.flippedVertically) addTransform(x, y + t.height, 1, -1, 0, t);
|
case Staggered(staggerYAxis, staggerIndexOdd):
|
||||||
else if (gid.flippedDiagonally) addTransform(x + t.width, y + t.height, -1, -1, 0, t);
|
if (staggerYAxis) {
|
||||||
else add(x, y, t);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import hxyarn.dialogue.OptionSet;
|
|||||||
import hxyarn.dialogue.markup.MarkupParseResult;
|
import hxyarn.dialogue.markup.MarkupParseResult;
|
||||||
import hxyarn.compiler.Compiler;
|
import hxyarn.compiler.Compiler;
|
||||||
import hxyarn.compiler.CompilationJob;
|
import hxyarn.compiler.CompilationJob;
|
||||||
|
|
||||||
import event.EventBus;
|
import event.EventBus;
|
||||||
import dialogue.command.ICommandHandler;
|
import dialogue.command.ICommandHandler;
|
||||||
import dialogue.event.LineShown;
|
import dialogue.event.LineShown;
|
||||||
@ -22,146 +21,144 @@ import dialogue.event.StartDialogueNode;
|
|||||||
import dialogue.event.DialogueComplete;
|
import dialogue.event.DialogueComplete;
|
||||||
|
|
||||||
class DialogueManager {
|
class DialogueManager {
|
||||||
public var eventBus:EventBus;
|
public var eventBus:EventBus;
|
||||||
|
|
||||||
var storage = new MemoryVariableStore();
|
var storage = new MemoryVariableStore();
|
||||||
var dialogue:Dialogue;
|
var dialogue:Dialogue;
|
||||||
var stringTable:Map<String, StringInfo>;
|
var stringTable:Map<String, StringInfo>;
|
||||||
var commandHandlers = new Map<String, ICommandHandler>();
|
var commandHandlers = new Map<String, ICommandHandler>();
|
||||||
|
|
||||||
public var waitingForOption:Bool = false;
|
public var waitingForOption:Bool = false;
|
||||||
|
|
||||||
public function new(eventBus:EventBus) {
|
public function new(eventBus:EventBus) {
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
dialogue = new Dialogue(new MemoryVariableStore());
|
dialogue = new Dialogue(new MemoryVariableStore());
|
||||||
|
|
||||||
dialogue.logDebugMessage = this.logDebugMessage;
|
dialogue.logDebugMessage = this.logDebugMessage;
|
||||||
dialogue.logErrorMessage = this.logErrorMessage;
|
dialogue.logErrorMessage = this.logErrorMessage;
|
||||||
dialogue.lineHandler = this.lineHandler;
|
dialogue.lineHandler = this.lineHandler;
|
||||||
dialogue.optionsHandler = this.optionsHandler;
|
dialogue.optionsHandler = this.optionsHandler;
|
||||||
dialogue.commandHandler = this.commandHandler;
|
dialogue.commandHandler = this.commandHandler;
|
||||||
dialogue.nodeCompleteHandler = this.nodeCompleteHandler;
|
dialogue.nodeCompleteHandler = this.nodeCompleteHandler;
|
||||||
dialogue.nodeStartHandler = this.nodeStartHandler;
|
dialogue.nodeStartHandler = this.nodeStartHandler;
|
||||||
dialogue.dialogueCompleteHandler = this.dialogueCompleteHandler;
|
dialogue.dialogueCompleteHandler = this.dialogueCompleteHandler;
|
||||||
|
|
||||||
eventBus.subscribe(NextLine, this.nextLine);
|
eventBus.subscribe(NextLine, this.nextLine);
|
||||||
eventBus.subscribe(OptionSelected, this.optionSelected);
|
eventBus.subscribe(OptionSelected, this.optionSelected);
|
||||||
eventBus.subscribe(StartDialogueNode, function(event) {
|
eventBus.subscribe(StartDialogueNode, function(event) {
|
||||||
this.runNode(event.node);
|
this.runNode(event.node);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function load(text:Array<String>, fileNames:Array<String>) {
|
public function load(text:Array<String>, fileNames:Array<String>) {
|
||||||
var job = CompilationJob.createFromStrings(text, fileNames, dialogue.library);
|
var job = CompilationJob.createFromStrings(text, fileNames, dialogue.library);
|
||||||
var compiler = Compiler.compile(job);
|
var compiler = Compiler.compile(job);
|
||||||
stringTable = compiler.stringTable;
|
stringTable = compiler.stringTable;
|
||||||
|
|
||||||
dialogue.addProgram(compiler.program);
|
dialogue.addProgram(compiler.program);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function runNode(nodeName:String) {
|
public function runNode(nodeName:String) {
|
||||||
dialogue.setNode(nodeName);
|
dialogue.setNode(nodeName);
|
||||||
dialogue.resume();
|
dialogue.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function unload() {
|
public function unload() {
|
||||||
dialogue.unloadAll();
|
dialogue.unloadAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function resume() {
|
public function resume() {
|
||||||
dialogue.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) {
|
public function nextLine(event:NextLine) {
|
||||||
if ((dialogue.isActive()) && (!waitingForOption))
|
if ((dialogue.isActive()) && (!waitingForOption))
|
||||||
dialogue.resume();
|
dialogue.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function lineHandler(line:Line):Void {
|
public function lineHandler(line:Line):Void {
|
||||||
var text = getComposedTextForLine(line);
|
var text = getComposedTextForLine(line);
|
||||||
eventBus.publishEvent(new LineShown(text));
|
eventBus.publishEvent(new LineShown(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function optionSelected(event:OptionSelected) {
|
public function optionSelected(event:OptionSelected) {
|
||||||
dialogue.setSelectedOption(event.index);
|
dialogue.setSelectedOption(event.index);
|
||||||
dialogue.resume();
|
dialogue.resume();
|
||||||
waitingForOption = false;
|
waitingForOption = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function optionsHandler(options:OptionSet) {
|
public function optionsHandler(options:OptionSet) {
|
||||||
var optionCount = options.options.length;
|
var optionCount = options.options.length;
|
||||||
var optionChoices = new Array<OptionChoice>();
|
var optionChoices = new Array<OptionChoice>();
|
||||||
|
|
||||||
for (i => option in options.options) {
|
for (i => option in options.options) {
|
||||||
var markup = getComposedTextForLine(option.line);
|
var markup = getComposedTextForLine(option.line);
|
||||||
optionChoices.push({
|
optionChoices.push({
|
||||||
text: markup.text,
|
text: markup.text,
|
||||||
index: i,
|
index: i,
|
||||||
enabled: option.enabled,
|
enabled: option.enabled,
|
||||||
markup: markup
|
markup: markup
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
eventBus.publishEvent(new OptionsShown(optionChoices));
|
eventBus.publishEvent(new OptionsShown(optionChoices));
|
||||||
|
|
||||||
waitingForOption = true;
|
waitingForOption = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getComposedTextForLine(line:Line):MarkupParseResult {
|
public function getComposedTextForLine(line:Line):MarkupParseResult {
|
||||||
var substitutedText = Dialogue.expandSubstitutions(stringTable[line.id].text, line.substitutions);
|
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();
|
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) {
|
commandHandlers.set(handler.commandName, handler);
|
||||||
if (handler.commandName == null || handler.commandName == "") {
|
|
||||||
trace("Command handler has no command name");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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() {
|
public function getNodeNames(?includesTag = "") {
|
||||||
eventBus.publishEvent(new DialogueComplete(""));
|
var nodeNames = [];
|
||||||
}
|
for (nodeName in dialogue.allNodes) {
|
||||||
|
if (includesTag == "") {
|
||||||
|
nodeNames.push(nodeName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
public function getNodeNames(?includesTag = "") {
|
var tags = dialogue.getTagsForNode(nodeName);
|
||||||
var nodeNames = [];
|
if (tags.contains(includesTag)) {
|
||||||
for (nodeName in dialogue.allNodes) {
|
nodeNames.push(nodeName);
|
||||||
if (includesTag == "") {
|
}
|
||||||
nodeNames.push(nodeName);
|
}
|
||||||
continue;
|
return nodeNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tags = dialogue.getTagsForNode(nodeName);
|
|
||||||
if (tags.contains(includesTag)) {
|
|
||||||
nodeNames.push(nodeName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nodeNames;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package scene;
|
package scene;
|
||||||
|
|
||||||
interface GameScene {
|
interface GameScene {
|
||||||
function getH2dObject():h2d.Object;
|
function getH2dObject():h2d.Object;
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package scene;
|
package scene;
|
||||||
|
|
||||||
import scene.WorldMapScene;
|
import scene.WorldMapScene;
|
||||||
|
|
||||||
import event.ChangeSceneEvent;
|
import event.ChangeSceneEvent;
|
||||||
|
|
||||||
import components.MenubuttonComponent;
|
import components.MenubuttonComponent;
|
||||||
|
|
||||||
@:uiComp("heading")
|
@:uiComp("heading")
|
||||||
@ -41,12 +39,11 @@ class TitleScene extends h2d.Flow implements GameScene implements h2d.domkit.Obj
|
|||||||
}
|
}
|
||||||
#if hl
|
#if hl
|
||||||
btnQuit.onClick = function() {
|
btnQuit.onClick = function() {
|
||||||
Sys.exit(0);
|
Sys.exit(0);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
btnQuit.remove();
|
btnQuit.remove();
|
||||||
#end
|
#end
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getH2dObject() {
|
public function getH2dObject() {
|
||||||
|
@ -5,9 +5,9 @@ import event.OpenRoomEvent;
|
|||||||
import TilemapLayer;
|
import TilemapLayer;
|
||||||
|
|
||||||
typedef Room = {
|
typedef Room = {
|
||||||
rect:h2d.Graphics,
|
rect:h2d.Graphics,
|
||||||
area:h2d.Interactive,
|
area:h2d.Interactive,
|
||||||
isOpen:Bool
|
isOpen:Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@:uiComp("world-map-scene")
|
@:uiComp("world-map-scene")
|
||||||
@ -15,7 +15,7 @@ class WorldMapScene extends h2d.Flow implements GameScene implements h2d.domkit.
|
|||||||
public var width:Int;
|
public var width:Int;
|
||||||
public var height: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) {
|
public function new(?parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
@ -28,9 +28,9 @@ class WorldMapScene extends h2d.Flow implements GameScene implements h2d.domkit.
|
|||||||
Game.current.globalEventBus.subscribe(OpenRoomEvent, openRoom);
|
Game.current.globalEventBus.subscribe(OpenRoomEvent, openRoom);
|
||||||
|
|
||||||
for (layer in (map.layers)) {
|
for (layer in (map.layers)) {
|
||||||
switch(layer.kind) {
|
switch (layer.kind) {
|
||||||
case TTileLayer:
|
case TTileLayer:
|
||||||
var l = new TilemapLayer(map, layer, root);
|
var l = new TilemapLayer(map, layer, root);
|
||||||
case TObjectGroup:
|
case TObjectGroup:
|
||||||
for (obj in layer.objects) {
|
for (obj in layer.objects) {
|
||||||
var rect = new h2d.Graphics(root);
|
var rect = new h2d.Graphics(root);
|
||||||
@ -59,7 +59,7 @@ class WorldMapScene extends h2d.Flow implements GameScene implements h2d.domkit.
|
|||||||
#if debug
|
#if debug
|
||||||
trace('skipping intro dialogue');
|
trace('skipping intro dialogue');
|
||||||
Game.current.globalEventBus.publishEvent(new OpenRoomEvent("quarters"));
|
Game.current.globalEventBus.publishEvent(new OpenRoomEvent("quarters"));
|
||||||
#else
|
#else
|
||||||
Game.current.globalEventBus.publishEvent(new StartDialogueNode("Intro"));
|
Game.current.globalEventBus.publishEvent(new StartDialogueNode("Intro"));
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ class WorldMapScene extends h2d.Flow implements GameScene implements h2d.domkit.
|
|||||||
room.isOpen = true;
|
room.isOpen = true;
|
||||||
room.rect.alpha = 0;
|
room.rect.alpha = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getH2dObject() {
|
public function getH2dObject() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user