Compare commits

...

5 Commits

Author SHA1 Message Date
3wc b16b27e03d Test out some YarnSpinner format stuff 2024-02-16 02:54:58 -03:00
3wc e0d3ca8021 Add RoomOpen command / event 2024-02-16 02:38:52 -03:00
3wc c1b102860e Clickable rooms with per-room dialogue 2024-02-16 01:53:38 -03:00
3wc bb9db51560 Tidy up debugging, remove 12px padding 2024-02-15 02:08:08 -03:00
3wc 867b33aef5 Specify git version of heaps 2024-02-15 02:06:16 -03:00
17 changed files with 414 additions and 57 deletions

View File

@ -1,6 +1,7 @@
-cp src
--macro Init.setup()
-lib heaps
-lib heaps:git:https://github.com/HeapsIO/heaps.git
-lib tiledhx
-lib hxyarn
-main Main
-lib domkit

1
res/.tmp/cache.dat Normal file
View 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

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -21,6 +21,6 @@
<object id="7" name="medical" x="96" y="96" width="224" height="128"/>
<object id="8" name="generator" x="96" y="416" width="192" height="128"/>
<object id="9" name="quarters" x="320" y="416" width="288" height="128"/>
<object id="10" name="hangar" x="640" y="128" width="224" height="416"/>
<object id="10" name="hangar" x="640" y="96" width="224" height="448"/>
</objectgroup>
</map>

14
res/rewild.tiled-project Normal file
View File

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

45
res/rewild.tiled-session Normal file
View 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"
]
}

View File

@ -8,4 +8,37 @@ You: What happened to the updates from mission control?
-> Is this even still the same ship?
You: Best not get too philsophical just yet
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?
===

View File

@ -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>
@ -42,11 +44,14 @@ class Game extends hxd.App {
var layer:Layers;
public var root:GameContainer;
var console:Console;
public var console:Console;
var style = null;
public static var loader = new tiled.Tiled();
override function init() {
s2d.scaleMode = Stretch(Const.W, Const.H + 12);
s2d.scaleMode = Stretch(Const.W, Const.H);
layer = new Layers(s2d);
#if hl
hxd.res.Resource.LIVE_UPDATE = true;
@ -57,7 +62,8 @@ class Game extends hxd.App {
root = new GameContainer();
root.horizontalAlign = root.verticalAlign = Middle;
s2d.add(root);
// s2d.add(root);
layer.addChildAt(root, 1);
onResize();
style = new h2d.domkit.Style();
@ -66,7 +72,6 @@ class Game extends hxd.App {
style.addObject(root);
font = Res.font.minecraftia_regular_6.toFont();
layer = new Layers(s2d);
#if debug
console = new Console(font);
@ -92,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));
@ -166,6 +172,7 @@ class Game extends hxd.App {
for (o in options) {
o.remove();
}
options.splice(0, options.length);
}
function onDialogueComplete(event:DialogueComplete) {

197
src/TilemapLayer.hx Normal file
View File

@ -0,0 +1,197 @@
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 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);
}
}
}

View File

@ -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) {}

View File

@ -0,0 +1,6 @@
package dialogue.command;
interface ICommandHandler {
var commandName:String;
function handleCommand(args:Array<String>):Bool;
}

View 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;
}
}

View File

@ -34,7 +34,6 @@ class EventBus {
public function publishEvent<T:IEvent>(event:T) {
var type = Type.getClassName(Type.getClass(event));
trace(type);
if (!listeners.exists(type)) {
#if debug
console.log('Publishing event with no listeners: $type');

View File

@ -0,0 +1,9 @@
package event;
class OpenRoomEvent implements IEvent {
public var roomName:String;
public function new(rn:String) {
this.roomName = rn;
}
}

View File

@ -1,72 +1,77 @@
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 {
var map:hxd.res.TiledMap.TiledMapData;
var layers:Map<String, {
name:String,
data:Array<Int>,
g:h2d.TileGroup,
alpha:Float
}>;
var tiles:Array<h2d.Tile>;
public var width:Int;
public var height:Int;
var rooms:Map<String,Room> = new Map<String,Room>();
public function new(?parent) {
super(parent);
initComponent();
var root = new h2d.Object(this);
map = Res.map.toMap();
width = map.width;
height = map.height;
var t = Res.tiles.toTile();
layers = new Map();
this.tiles = [
for (y in 0...Std.int(t.height) >> 5) for (x in 0...Std.int(t.width) >> 5) t.sub(x * 32, y * 32, 32, 32)
];
for (ld in map.layers) {
if (ld.name == "hotspots")
continue;
var l = {
name: ld.name,
data: ld.data,
g: new h2d.TileGroup(t, root),
alpha: ld.opacity,
var map = Game.loader.loadTMX("map.tmx");
Game.current.globalEventBus.subscribe(OpenRoomEvent, openRoom);
for (layer in (map.layers)) {
switch(layer.kind) {
case TTileLayer:
var l = new TilemapLayer(map, layer, root);
case TObjectGroup:
for (obj in layer.objects) {
var rect = new h2d.Graphics(root);
rect.beginFill(0x333333);
rect.alpha = 0.8;
rect.drawRect(obj.x, obj.y, obj.width, obj.height);
rect.endFill();
var area = new h2d.Interactive(obj.width, obj.height, root);
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));
} else {
Game.current.globalEventBus.publishEvent(new StartDialogueNode("Room not open"));
}
};
rooms.set(obj.name, {rect: rect, area: area, isOpen: false});
}
case TImageLayer:
case TGroup:
}
l.g.alpha = ld.opacity;
layers.set(ld.name, l);
rebuildLayer(ld.name);
}
Game.current.dialogueManager.runNode("Intro");
#if debug
trace('skipping intro dialogue');
Game.current.globalEventBus.publishEvent(new OpenRoomEvent("quarters"));
#else
Game.current.globalEventBus.publishEvent(new StartDialogueNode("Intro"));
#end
}
public function openRoom(event:OpenRoomEvent) {
var room = rooms.get(event.roomName);
room.isOpen = true;
room.rect.alpha = 0;
}
public function getH2dObject() {
return this;
}
function rebuildLayer(name:String) {
var l = layers.get(name);
if (l == null)
return;
var pos = 0;
var g = l.g;
g.clear();
while (g.numChildren > 0) {
g.getChildAt(0).remove();
}
for (y in 0...height)
for (x in 0...width) {
var t = l.data[pos++] - 1;
if (t < 0)
continue;
g.add(x * 32, y * 32, tiles[t]);
}
}
}