Compare commits

...

10 Commits

Author SHA1 Message Date
3wc cd8be645a3 Hide Quit button on web 2024-02-13 13:47:41 -03:00
3wc 17ba4ada30 Break out title screen into separate file 2024-02-13 13:47:24 -03:00
3wc aaddce255a Ensure `make` looks at all dependent files 2024-02-13 13:46:43 -03:00
3wc 4b6cd309ac Add index.html for HTML rendering 2024-02-13 03:27:22 -03:00
3wc da1f1f1e2a Working dialogue actions handling 2024-02-13 03:27:07 -03:00
3wc 1d8222a395 Make HTML5 work again 2024-02-13 00:04:25 -03:00
3wc 51d10f430f omg working yarnspinner dialogue 😍 2024-02-12 21:58:44 -03:00
3wc 96c430c3c1 Re4mat 2024-02-12 18:30:13 -03:00
3wc ea32d0356d Basic dialogue box support 2024-02-12 18:03:43 -03:00
3wc f39ece171e Add `make clean` 2024-02-12 16:47:53 -03:00
25 changed files with 2730 additions and 74 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
**/*.hl
/bin/*

View File

@ -1,7 +1,6 @@
-cp src
--macro Init.setup()
-lib heaps
-lib hlsdl
-hl rewild.hl
-lib hxyarn
-main Main
-lib domkit

5
compile-hl.hxml Normal file
View File

@ -0,0 +1,5 @@
compile-common.hxml
-D windowTitle=StoneInAGlasshouse
-lib hlsdl
-hl bin/rewild.hl

3
compile-js.hxml Normal file
View File

@ -0,0 +1,3 @@
compile-common.hxml
-js bin/rewild.js

32
index.html Normal file
View File

@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Stone In a Glasshouse</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui"
/>
<meta name="format-detection" content="telephone=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="mobile-web-app-capable" content="yes" />
<style>
body {
margin: 0;
padding: 0;
background-color: black;
width: 100%;
height: 100%;
text-align: center;
}
canvas#webgl {
width: 900px;
margin: 0 auto;
}
</style>
</head>
<body>
<canvas id="webgl"></canvas>
<script type="text/javascript" src="bin/rewild.js"></script>
</body>
</html>

View File

@ -1,7 +1,17 @@
.PHONY: watch
rewild.hl: **/*.hx
haxe compile.hxml
default: bin/rewild.hl
SOURCES := $(shell find . -name \*.hx -print)
bin/rewild.hl: $(SOURCES)
haxe compile-hl.hxml
bin/rewild.js: $(SOURCES)
haxe compile-js.hxml
clean:
rm -f bin/rewild.hl bin/rewild.js
watch:
@inotifywait --recursive --monitor --event modify,move,create,delete --include '.*.hx$$' ./ | while read changed; do echo $$changed; make; done

View File

@ -0,0 +1,195 @@
<?xml version="1.0" encoding="utf-8"?>
<Font size="6" family="Minecraftia" height="11" style="Regular">
<Char width="2" offset="0 14" rect="1 13 0 0" code=" "/>
<Char width="2" offset="0 2" rect="2 1 1 7" code="!"/>
<Char width="4" offset="0 2" rect="4 1 3 2" code="&quot;"/>
<Char width="6" offset="0 2" rect="8 1 5 7" code="#"/>
<Char width="6" offset="0 2" rect="14 1 5 7" code="$"/>
<Char width="6" offset="0 2" rect="20 1 5 7" code="%"/>
<Char width="6" offset="0 2" rect="26 1 5 7" code="&amp;"/>
<Char width="2" offset="0 2" rect="32 1 1 2" code="'"/>
<Char width="5" offset="0 2" rect="34 1 4 7" code="("/>
<Char width="5" offset="0 2" rect="39 1 4 7" code=")"/>
<Char width="5" offset="0 2" rect="44 1 4 3" code="*"/>
<Char width="6" offset="0 4" rect="49 3 5 5" code="+"/>
<Char width="2" offset="0 7" rect="55 6 1 3" code=","/>
<Char width="6" offset="0 6" rect="57 5 5 1" code="-"/>
<Char width="2" offset="0 7" rect="63 6 1 2" code="."/>
<Char width="6" offset="0 2" rect="65 1 5 7" code="/"/>
<Char width="6" offset="0 2" rect="71 1 5 7" code="0"/>
<Char width="6" offset="0 2" rect="77 1 5 7" code="1"/>
<Char width="6" offset="0 2" rect="83 1 5 7" code="2"/>
<Char width="6" offset="0 2" rect="89 1 5 7" code="3"/>
<Char width="6" offset="0 2" rect="95 1 5 7" code="4"/>
<Char width="6" offset="0 2" rect="101 1 5 7" code="5"/>
<Char width="6" offset="0 2" rect="1 14 5 7" code="6"/>
<Char width="6" offset="0 2" rect="7 14 5 7" code="7"/>
<Char width="6" offset="0 2" rect="13 14 5 7" code="8"/>
<Char width="6" offset="0 2" rect="19 14 5 7" code="9"/>
<Char width="2" offset="0 3" rect="25 15 1 6" code=":"/>
<Char width="2" offset="0 3" rect="27 15 1 7" code=";"/>
<Char width="5" offset="0 2" rect="29 14 4 7" code="&lt;"/>
<Char width="6" offset="0 4" rect="34 16 5 4" code="="/>
<Char width="5" offset="0 2" rect="40 14 4 7" code=">"/>
<Char width="6" offset="0 2" rect="45 14 5 7" code="?"/>
<Char width="7" offset="0 2" rect="51 14 6 7" code="@"/>
<Char width="6" offset="0 2" rect="58 14 5 7" code="A"/>
<Char width="6" offset="0 2" rect="64 14 5 7" code="B"/>
<Char width="6" offset="0 2" rect="70 14 5 7" code="C"/>
<Char width="6" offset="0 2" rect="76 14 5 7" code="D"/>
<Char width="6" offset="0 2" rect="82 14 5 7" code="E"/>
<Char width="6" offset="0 2" rect="88 14 5 7" code="F"/>
<Char width="6" offset="0 2" rect="94 14 5 7" code="G"/>
<Char width="6" offset="0 2" rect="100 14 5 7" code="H"/>
<Char width="4" offset="0 2" rect="1 23 3 7" code="I"/>
<Char width="6" offset="0 2" rect="5 23 5 7" code="J"/>
<Char width="6" offset="0 2" rect="11 23 5 7" code="K"/>
<Char width="6" offset="0 2" rect="17 23 5 7" code="L"/>
<Char width="6" offset="0 2" rect="23 23 5 7" code="M"/>
<Char width="6" offset="0 2" rect="29 23 5 7" code="N"/>
<Char width="6" offset="0 2" rect="35 23 5 7" code="O"/>
<Char width="6" offset="0 2" rect="41 23 5 7" code="P"/>
<Char width="6" offset="0 2" rect="47 23 5 7" code="Q"/>
<Char width="6" offset="0 2" rect="53 23 5 7" code="R"/>
<Char width="6" offset="0 2" rect="59 23 5 7" code="S"/>
<Char width="6" offset="0 2" rect="65 23 5 7" code="T"/>
<Char width="6" offset="0 2" rect="71 23 5 7" code="U"/>
<Char width="6" offset="0 2" rect="77 23 5 7" code="V"/>
<Char width="6" offset="0 2" rect="83 23 5 7" code="W"/>
<Char width="6" offset="0 2" rect="89 23 5 7" code="X"/>
<Char width="6" offset="0 2" rect="95 23 5 7" code="Y"/>
<Char width="6" offset="0 2" rect="101 23 5 7" code="Z"/>
<Char width="4" offset="0 2" rect="1 32 3 7" code="["/>
<Char width="6" offset="0 2" rect="5 32 5 7" code="\"/>
<Char width="4" offset="0 2" rect="11 32 3 7" code="]"/>
<Char width="6" offset="0 2" rect="15 32 5 3" code="^"/>
<Char width="6" offset="0 9" rect="21 39 5 1" code="_"/>
<Char width="3" offset="0 1" rect="27 31 2 2" code="`"/>
<Char width="6" offset="0 4" rect="30 34 5 5" code="a"/>
<Char width="6" offset="0 2" rect="36 32 5 7" code="b"/>
<Char width="6" offset="0 4" rect="42 34 5 5" code="c"/>
<Char width="6" offset="0 2" rect="48 32 5 7" code="d"/>
<Char width="6" offset="0 4" rect="54 34 5 5" code="e"/>
<Char width="5" offset="0 2" rect="60 32 4 7" code="f"/>
<Char width="6" offset="0 4" rect="65 34 5 6" code="g"/>
<Char width="6" offset="0 2" rect="71 32 5 7" code="h"/>
<Char width="2" offset="0 2" rect="77 32 1 7" code="i"/>
<Char width="6" offset="0 2" rect="79 32 5 8" code="j"/>
<Char width="5" offset="0 2" rect="85 32 4 7" code="k"/>
<Char width="3" offset="0 2" rect="90 32 2 7" code="l"/>
<Char width="6" offset="0 4" rect="93 34 5 5" code="m"/>
<Char width="6" offset="0 4" rect="99 34 5 5" code="n"/>
<Char width="6" offset="0 4" rect="1 43 5 5" code="o"/>
<Char width="6" offset="0 4" rect="7 43 5 6" code="p"/>
<Char width="6" offset="0 4" rect="13 43 5 6" code="q"/>
<Char width="6" offset="0 4" rect="19 43 5 5" code="r"/>
<Char width="6" offset="0 4" rect="25 43 5 5" code="s"/>
<Char width="4" offset="0 2" rect="31 41 3 7" code="t"/>
<Char width="6" offset="0 4" rect="35 43 5 5" code="u"/>
<Char width="6" offset="0 4" rect="41 43 5 5" code="v"/>
<Char width="6" offset="0 4" rect="47 43 5 5" code="w"/>
<Char width="6" offset="0 4" rect="53 43 5 5" code="x"/>
<Char width="6" offset="0 4" rect="59 43 5 6" code="y"/>
<Char width="6" offset="0 4" rect="65 43 5 5" code="z"/>
<Char width="5" offset="0 2" rect="71 41 4 7" code="{"/>
<Char width="2" offset="0 2" rect="76 41 1 8" code="|"/>
<Char width="5" offset="0 2" rect="78 41 4 7" code="}"/>
<Char width="7" offset="0 2" rect="83 41 6 2" code="~"/>
<Char width="2" offset="0 2" rect="90 41 1 7" code="¡"/>
<Char width="5" offset="0 4" rect="92 43 4 5" code="¢"/>
<Char width="6" offset="0 2" rect="97 41 5 7" code="£"/>
<Char width="6" offset="0 3" rect="103 42 5 5" code="¤"/>
<Char width="6" offset="0 2" rect="1 51 5 7" code="¥"/>
<Char width="2" offset="0 2" rect="7 51 1 7" code="¦"/>
<Char width="6" offset="0 2" rect="9 51 5 7" code="§"/>
<Char width="5" offset="1 2" rect="15 51 3 1" code="¨"/>
<Char width="8" offset="0 2" rect="19 51 7 7" code="©"/>
<Char width="4" offset="0 2" rect="27 51 3 6" code="ª"/>
<Char width="5" offset="0 5" rect="31 54 4 4" code="«"/>
<Char width="5" offset="0 4" rect="36 53 4 3" code="¬"/>
<Char width="8" offset="0 2" rect="41 51 7 7" code="®"/>
<Char width="6" offset="0 2" rect="49 51 5 1" code="¯"/>
<Char width="4" offset="0 2" rect="55 51 3 3" code="°"/>
<Char width="6" offset="0 2" rect="59 51 5 7" code="±"/>
<Char width="4" offset="0 2" rect="65 51 3 4" code="²"/>
<Char width="4" offset="0 2" rect="69 51 3 4" code="³"/>
<Char width="3" offset="0 1" rect="73 50 2 2" code="´"/>
<Char width="6" offset="0 4" rect="76 53 5 6" code="µ"/>
<Char width="6" offset="0 2" rect="82 51 5 7" code="¶"/>
<Char width="2" offset="0 6" rect="88 55 1 1" code="·"/>
<Char width="4" offset="1 9" rect="90 58 2 2" code="¸"/>
<Char width="4" offset="0 2" rect="93 51 3 4" code="¹"/>
<Char width="4" offset="0 2" rect="97 51 3 6" code="º"/>
<Char width="5" offset="0 5" rect="101 54 4 4" code="»"/>
<Char width="9" offset="0 2" rect="1 63 8 7" code="¼"/>
<Char width="9" offset="0 2" rect="10 63 8 7" code="½"/>
<Char width="9" offset="0 2" rect="19 63 8 7" code="¾"/>
<Char width="6" offset="0 2" rect="28 63 5 7" code="¿"/>
<Char width="6" offset="0 0" rect="34 61 5 9" code="À"/>
<Char width="6" offset="0 0" rect="40 61 5 9" code="Á"/>
<Char width="6" offset="0 0" rect="46 61 5 9" code="Â"/>
<Char width="6" offset="0 0" rect="52 61 5 9" code="Ã"/>
<Char width="6" offset="0 0" rect="58 61 5 9" code="Ä"/>
<Char width="6" offset="0 0" rect="64 61 5 9" code="Å"/>
<Char width="10" offset="0 2" rect="70 63 9 7" code="Æ"/>
<Char width="6" offset="0 2" rect="80 63 5 9" code="Ç"/>
<Char width="6" offset="0 0" rect="86 61 5 9" code="È"/>
<Char width="6" offset="0 0" rect="92 61 5 9" code="É"/>
<Char width="6" offset="0 0" rect="98 61 5 9" code="Ê"/>
<Char width="6" offset="0 0" rect="1 73 5 9" code="Ë"/>
<Char width="4" offset="0 0" rect="7 73 3 9" code="Ì"/>
<Char width="4" offset="0 0" rect="11 73 3 9" code="Í"/>
<Char width="4" offset="0 0" rect="15 73 3 9" code="Î"/>
<Char width="4" offset="0 0" rect="19 73 3 9" code="Ï"/>
<Char width="7" offset="0 2" rect="23 75 6 7" code="Ð"/>
<Char width="6" offset="0 0" rect="30 73 5 9" code="Ñ"/>
<Char width="6" offset="0 0" rect="36 73 5 9" code="Ò"/>
<Char width="6" offset="0 0" rect="42 73 5 9" code="Ó"/>
<Char width="6" offset="0 0" rect="48 73 5 9" code="Ô"/>
<Char width="6" offset="0 0" rect="54 73 5 9" code="Õ"/>
<Char width="6" offset="0 0" rect="60 73 5 9" code="Ö"/>
<Char width="5" offset="0 5" rect="66 78 4 4" code="×"/>
<Char width="6" offset="0 2" rect="71 75 5 7" code="Ø"/>
<Char width="6" offset="0 0" rect="77 73 5 9" code="Ù"/>
<Char width="6" offset="0 0" rect="83 73 5 9" code="Ú"/>
<Char width="6" offset="0 0" rect="89 73 5 9" code="Û"/>
<Char width="6" offset="0 0" rect="95 73 5 9" code="Ü"/>
<Char width="6" offset="0 0" rect="101 73 5 9" code="Ý"/>
<Char width="6" offset="0 2" rect="1 85 5 7" code="Þ"/>
<Char width="6" offset="0 2" rect="7 85 5 7" code="ß"/>
<Char width="6" offset="0 1" rect="13 84 5 8" code="à"/>
<Char width="6" offset="0 1" rect="19 84 5 8" code="á"/>
<Char width="6" offset="0 1" rect="25 84 5 8" code="â"/>
<Char width="6" offset="0 1" rect="31 84 5 8" code="ã"/>
<Char width="6" offset="0 2" rect="37 85 5 7" code="ä"/>
<Char width="6" offset="0 0" rect="43 83 5 9" code="å"/>
<Char width="10" offset="0 4" rect="49 87 9 5" code="æ"/>
<Char width="6" offset="0 4" rect="59 87 5 7" code="ç"/>
<Char width="6" offset="0 1" rect="65 84 5 8" code="è"/>
<Char width="6" offset="0 1" rect="71 84 5 8" code="é"/>
<Char width="6" offset="0 1" rect="77 84 5 8" code="ê"/>
<Char width="6" offset="0 2" rect="83 85 5 7" code="ë"/>
<Char width="2" offset="-1 1" rect="89 84 2 8" code="ì"/>
<Char width="3" offset="0 1" rect="92 84 2 8" code="í"/>
<Char width="3" offset="-1 1" rect="95 84 3 8" code="î"/>
<Char width="3" offset="-1 2" rect="99 85 3 7" code="ï"/>
<Char width="6" offset="0 2" rect="103 85 5 7" code="ð"/>
<Char width="6" offset="0 1" rect="1 95 5 8" code="ñ"/>
<Char width="6" offset="0 1" rect="7 95 5 8" code="ò"/>
<Char width="6" offset="0 1" rect="13 95 5 8" code="ó"/>
<Char width="6" offset="0 1" rect="19 95 5 8" code="ô"/>
<Char width="6" offset="0 1" rect="25 95 5 8" code="õ"/>
<Char width="6" offset="0 2" rect="31 96 5 7" code="ö"/>
<Char width="6" offset="0 4" rect="37 98 5 5" code="÷"/>
<Char width="6" offset="0 4" rect="43 98 5 5" code="ø"/>
<Char width="6" offset="0 1" rect="49 95 5 8" code="ù"/>
<Char width="6" offset="0 1" rect="55 95 5 8" code="ú"/>
<Char width="6" offset="0 1" rect="61 95 5 8" code="û"/>
<Char width="6" offset="0 2" rect="67 96 5 7" code="ü"/>
<Char width="6" offset="0 1" rect="73 95 5 9" code="ý"/>
<Char width="6" offset="0 2" rect="79 96 5 8" code="þ"/>
<Char width="6" offset="0 4" rect="85 98 5 6" code="ÿ"/>
<Char width="10" offset="0 2" rect="91 96 9 7" code="Œ"/>
<Char width="10" offset="0 4" rect="1 107 9 5" code="œ"/>
<Char width="6" offset="0 2" rect="11 105 5 7" code="€"/>
</Font>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

View File

@ -0,0 +1,4 @@
The FontStruction “Pixel UniCode”
(http://fontstruct.com/fontstructions/show/908795) by “ivancr72” is licensed
under a Creative Commons Attribution license
(http://creativecommons.org/licenses/by/3.0/).

View File

@ -0,0 +1,26 @@
The font file in this archive was created using Fontstruct the free, online
font-building tool.
This font was created by “ivancr72”.
This font has a homepage where this archive and other versions may be found:
http://fontstruct.com/fontstructions/show/908795
Try Fontstruct at http://fontstruct.com
Its easy and its fun.
NOTE FOR FLASH USERS: Fontstruct fonts (fontstructions) are optimized for Flash.
If the font in this archive is a pixel font, it is best displayed at a font-size
of 16.
Fontstruct is sponsored by FontShop.
Visit them at http://fontshop.com
FontShop is the original independent font retailer. Weve been around since
the dawn of digital type. Whether you need the right font or need to create the
right font from scratch, let our 23 years of experience work for you.
Fontstruct is copyright ©2013-2014 Rob Meek
LEGAL NOTICE:
In using this font you must comply with the licensing terms described in the
file “license.txt” included with this archive.
If you redistribute the font file in this archive, it must be accompanied by all
the other files from this archive, including this one.

View File

@ -7,7 +7,7 @@ view.mybox {
padding: 10;
}
container {
title-screen {
max-width: 300;
layout: vertical;
}

11
res/text/intro.yarn Normal file
View File

@ -0,0 +1,11 @@
title: Intro
---
You: It's been 3 earth-days since I woke up from cryostasis, and I still don't know what's going on.
You: Why is nobody else awake?
You: What happened to the updates from mission control?
-> Maybe I'm still asleep?
You: Surely the scriptwriting isn't *that* cliché...
-> Is this even still the same ship?
You: Best not get too philsophical just yet
You: Let's have another look around...
===

BIN
res/ui.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 B

View File

@ -1,6 +1,4 @@
class Const {
public static inline var W = 960;
public static inline var H = 640;
}

105
src/DialogueBox.hx Normal file
View File

@ -0,0 +1,105 @@
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.inst;
game.scene.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;
}
}

126
src/DialogueManager.hx Normal file
View File

@ -0,0 +1,126 @@
import hxyarn.dialogue.Dialogue;
import hxyarn.dialogue.VariableStorage.MemoryVariableStore;
import hxyarn.dialogue.StringInfo;
import hxyarn.dialogue.Line;
import hxyarn.dialogue.Command;
import hxyarn.dialogue.Option;
import hxyarn.dialogue.OptionSet;
import hxyarn.compiler.Compiler;
import hxyarn.compiler.CompilationJob;
typedef Option = {
text:String,
callback:() -> Void
};
class DialogueManager {
var storage = new MemoryVariableStore();
var dialogue:Dialogue;
var stringTable:Map<String, StringInfo>;
var dialogueCallback:(DialogueManager, String) -> Void;
var optionCallback:(DialogueManager, Array<Option>) -> Void;
public function new(_dialogueCallback:(DialogueManager, String) -> Void, _optionCallback:(DialogueManager, Array<Option>) -> Void) {
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;
dialogueCallback = _dialogueCallback;
optionCallback = _optionCallback;
}
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);
}
public function runNode(nodeName:String) {
dialogue.setNode(nodeName);
dialogue.resume();
}
public function unload() {
dialogue.unloadAll();
}
public function resume() {
dialogue.resume();
}
public function logDebugMessage(message:String):Void {
}
public function logErrorMessage(message:String):Void {
}
public function lineHandler(line:Line):HandlerExecutionType {
var text = getComposedTextForLine(line);
dialogueCallback(this, text);
return HandlerExecutionType.ContinueExecution;
}
public function optionsHandler(options:OptionSet) {
var optionCount = options.options.length;
var optionChoices = new Array<Option>();
for (i => option in options.options) {
var text = getComposedTextForLine(option.line);
optionChoices.push({
text: text,
callback: function() {
dialogue.setSelectedOption(i);
dialogue.resume();
}
});
}
optionCallback(this, optionChoices);
}
public function getComposedTextForLine(line:Line):String {
var substitutedText = Dialogue.expandSubstitutions(stringTable[line.id].text, line.substitutions);
var markup = dialogue.parseMarkup(substitutedText);
return markup.text;
}
public function commandHandler(command:Command) {
}
public function nodeCompleteHandler(nodeName:String) {}
public function nodeStartHandler(nodeName:String) {}
public function dialogueCompleteHandler() {
}
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;
}
}

View File

@ -1,17 +1,85 @@
import Const;
import DialogueBox;
import DialogueManager;
import DialogueManager.Option;
@:publicFields
class Game extends hxd.App {
public var scene : h2d.Scene;
public var font : h2d.Font;
public var world : World;
public var scene:h2d.Scene;
public var font:h2d.Font;
public var world:World;
public var curDialogue:h2d.Object;
public var actions:Array<h2d.ScaleGrid> = [];
public var dialogueManager:DialogueManager;
override function init() {
scene = s2d;
s2d.setFixedSize(Const.W, Const.H + 12);
s2d.scaleMode = Stretch(Const.W, Const.H + 12);
world = new World(Res.map, Res.tiles);
s2d.add(world.root, 0);
font = Res.font.minecraftia_regular_6.toFont();
font.resizeTo(24);
dialogueManager = new DialogueManager(dialogue, renderActions);
var yarnText = [
hxd.Res.text.intro.entry.getText(),
];
var yarnFileNames = [
hxd.Res.text.intro.entry.name,
];
dialogueManager.load(yarnText, yarnFileNames);
dialogueManager.runNode("Intro");
}
public static var inst:Game;
function dialogue(manager:DialogueManager, t:String) {
var d = new DialogueBox(Const.W, 100, t);
d.y = 0;
d.onClick = function() {
manager.resume();
};
curDialogue = d;
}
function renderActions(manager:DialogueManager, t:Array<Option>) {
for (action in t) {
addAction(action.text, action.callback);
}
}
function newPanel(w, h) {
var g = new h2d.ScaleGrid(Res.ui.toTile(), 5, 5);
g.width = w;
g.height = h;
g.colorKey = 0xFF00FF;
scene.add(g, 1);
return g;
}
function addAction(a: String, callback: () -> Void) {
var spr = newPanel(Const.W, 60);
curDialogue.addChild(spr);
var tf = new h2d.Text(font, spr);
tf.text = a;
tf.x = 10;
tf.y = 10;
spr.x = 0;
spr.y = 100 + actions.length * 60;
var int = new h2d.Interactive(spr.width, spr.height, spr);
int.onClick = function(_) {
for (action in actions) {
action.remove();
}
callback();
// removeDialog();
}
int.cursor = Button;
actions.push(spr);
return spr;
}
public static var inst : Game;
}

View File

@ -1,5 +1,5 @@
class Init {
public static function setup() {
domkit.Macros.registerComponentsPath("components.$Component");
}
public static function setup() {
domkit.Macros.registerComponentsPath("components.$Component");
}
}

View File

@ -1,36 +1,5 @@
import components.MenubuttonComponent;
import screens.TitleScreen;
@:uiComp("view")
class ViewComp extends h2d.Flow implements h2d.domkit.Object {
static var SRC = <view class="mybox" min-width="200" content-halign={align}>
<text text={"Rewild"}/>
for( i in icons )
<bitmap src={i} id="icons[]"/>
</view>;
public function new(align:h2d.Flow.FlowAlign, icons:Array<h2d.Tile>, ?parent) {
super(parent);
initComponent();
}
}
@:uiComp("container")
class ContainerComp extends h2d.Flow implements h2d.domkit.Object {
static var SRC = <container>
<view(align,[]) id="view"/>
<menubutton("New game") public id="btnNewGame"/>
<menubutton("Continue game") public id="btnContinueGame"/>
<menubutton("Credits") public id="btnCredits"/>
<menubutton("Quit") public id="btnQuit"/>
</container>;
public function new(align:h2d.Flow.FlowAlign, ?parent) {
super(parent);
initComponent();
}
}
// PARAM=-lib domkit
class Main extends hxd.App {
var center:h2d.Flow;
var style = null;
@ -39,7 +8,7 @@ class Main extends hxd.App {
center = new h2d.Flow(s2d);
center.horizontalAlign = center.verticalAlign = Middle;
onResize();
var root = new ContainerComp(Right, center);
var root = new TitleScreen(Right, center);
root.btnNewGame.onClick = function() {
Game.inst = new Game();
@ -47,9 +16,13 @@ class Main extends hxd.App {
root.btnContinueGame.onClick = function() {
root.btnContinueGame.dom.addClass("highlight");
}
#if hl
root.btnQuit.onClick = function() {
Sys.exit(0);
}
#else
root.btnQuit.remove();
#end
style = new h2d.domkit.Style();
style.load(hxd.Res.style);

View File

@ -1,14 +1,21 @@
class World {
var game:Game;
var map:hxd.res.TiledMap.TiledMapData;
var game : Game;
var map : hxd.res.TiledMap.TiledMapData;
public var root : h2d.Object;
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;
public var root:h2d.Object;
public function new( r : hxd.res.TiledMap, tiles : hxd.res.Image ) {
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;
public function new(r:hxd.res.TiledMap, tiles:hxd.res.Image) {
game = Game.inst;
root = new h2d.Object();
map = r.toMap();
@ -17,15 +24,18 @@ class World {
height = map.height;
var t = tiles.toTile();
layers = new Map();
var font : h2d.Font = hxd.res.DefaultFont.get();
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 font:h2d.Font = hxd.res.DefaultFont.get();
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,
name: ld.name,
data: ld.data,
g: new h2d.TileGroup(t, root),
alpha: ld.opacity,
}
// l.g.colorKey = 0x1D8700;
l.g.alpha = ld.opacity;
@ -34,21 +44,22 @@ class World {
}
}
function rebuildLayer( name : String ) {
function rebuildLayer(name:String) {
var l = layers.get(name);
if( l == null ) return;
if (l == null)
return;
var pos = 0;
var g = l.g;
g.clear();
while( g.numChildren > 0 )
while (g.numChildren > 0)
g.getChildAt(0).remove();
for( y in 0...height )
for( x in 0...width ) {
for (y in 0...height)
for (x in 0...width) {
var t = l.data[pos++] - 1;
if( t < 0 ) continue;
if (t < 0)
continue;
g.add(x * 32, y * 32, tiles[t]);
}
}
}

View File

@ -37,4 +37,3 @@ class MenubuttonComponent extends h2d.Flow implements h2d.domkit.Object {
public dynamic function onClick() {}
}

View File

@ -0,0 +1,33 @@
package screens;
import components.MenubuttonComponent;
@:uiComp("heading")
class HeadingComp extends h2d.Flow implements h2d.domkit.Object {
static var SRC = <heading class="mybox" min-width="200" content-halign={align}>
<text text={"Rewild"}/>
for( i in icons )
<bitmap src={i} id="icons[]"/>
</heading>;
public function new(align:h2d.Flow.FlowAlign, icons:Array<h2d.Tile>, ?parent) {
super(parent);
initComponent();
}
}
@:uiComp("title-screen")
class TitleScreen extends h2d.Flow implements h2d.domkit.Object {
static var SRC = <title-screen>
<heading(align,[]) id="view"/>
<menubutton("New game") public id="btnNewGame"/>
<menubutton("Continue game") public id="btnContinueGame"/>
<menubutton("Credits") public id="btnCredits"/>
<menubutton("Quit") public id="btnQuit"/>
</title-screen>;
public function new(align:h2d.Flow.FlowAlign, ?parent) {
super(parent);
initComponent();
}
}