Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
JujuAdams committed Jul 31, 2022
2 parents 485eb62 + d56872a commit 24fa4b4
Show file tree
Hide file tree
Showing 14 changed files with 243 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p align="center"><img src="https://raw.githubusercontent.com/JujuAdams/Chatterbox/master/LOGO.png" style="display:block; margin:auto; width:400px"></p>
<h1 align="center">2.6.1</h1>
<h1 align="center">2.7.0</h1>

<p align="center">Narrative engine for GameMaker by <b>@jujuadams</b></p>

Expand Down
7 changes: 4 additions & 3 deletions chatterbox.yyp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions datafiles/testcase_hop.yarn
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
title: Start
---
This is a test of the "hop" and "hopback" features.
<<hop Choice>>
You are back at the start node.
===

title: Choice
---
Please choose a node to hop to:
-> A
<<hop A>>
-> B
<<hop B>>
-> Back
<<hopback>>
You are back at the choice node.
===

title: A
---
Node A. Please choose a node to hop to:
-> A
<<hop A>>
-> B
<<hop B>>
-> Back
<<hopback>>
You are back at node A.
===

title: B
---
Node B. Please choose a node to hop to:
-> A
<<hop A>>
-> B
<<hop B>>
-> Back
<<hopback>>
You are back at node B.
===
8 changes: 8 additions & 0 deletions objects/oTestCaseHop/Create_0.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
if (!CHATTERBOX_END_OF_NODE_HOPBACK)
{
__ChatterboxError("CHATTERBOX_END_OF_NODE_HOPBACK must be set to <true> for this test case");
}

ChatterboxLoadFromFile("testcase_hop.yarn");
box = ChatterboxCreate();
ChatterboxJump(box, "Start");
55 changes: 55 additions & 0 deletions objects/oTestCaseHop/Draw_0.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
draw_set_font(fntDefault);

//Iterate over all text and draw it
var _x = 10;
var _y = 10;

if (ChatterboxIsStopped(box))
{
//If we're stopped then show that
draw_text(_x, _y, "(Chatterbox stopped)");
}
else
{
//All the spoken text
var _i = 0;
repeat(ChatterboxGetContentCount(box))
{
var _string = ChatterboxGetContent(box, _i);
draw_text(_x, _y, _string);
_y += string_height(_string);
++_i;
}

//Bit of spacing...
_y += 30;

if (ChatterboxIsWaiting(box))
{
//If we're in a "waiting" state then prompt the user for basic input
draw_text(_x, _y, "(Press Space)");
}
else
{
//All the options
var _i = 0;
repeat(ChatterboxGetOptionCount(box))
{
var _string = ChatterboxGetOption(box, _i);

if (ChatterboxGetOptionConditionBool(box, _i))
{
draw_text(_x, _y, string(_i+1) + ") " + _string);
}
else
{
draw_set_colour(c_grey);
draw_text(_x, _y, string(_i+1) + ") " + _string);
draw_set_colour(c_white);
}

_y += string_height(_string);
++_i;
}
}
}
24 changes: 24 additions & 0 deletions objects/oTestCaseHop/Step_0.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
if (ChatterboxIsStopped(box))
{
//Do nothing!
}
else if (ChatterboxIsWaiting(box))
{
if (keyboard_check_released(vk_space))
{
ChatterboxContinue(box);
}
else if (keyboard_check_released(ord("F")))
{
ChatterboxFastForward(box);
}
}
else
{
var _index = undefined;
if (keyboard_check_released(ord("1"))) _index = 0;
if (keyboard_check_released(ord("2"))) _index = 1;
if (keyboard_check_released(ord("3"))) _index = 2;
if (keyboard_check_released(ord("4"))) _index = 3;
if (_index != undefined) ChatterboxSelect(box, _index);
}
35 changes: 35 additions & 0 deletions objects/oTestCaseHop/oTestCaseHop.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion options/windows/options_windows.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions scripts/ChatterboxAddFunction/ChatterboxAddFunction.gml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ function ChatterboxAddFunction(_name, _in_function)
case "stop":
case "wait":
case "forcewait":
case "hop":
case "hopback":
case "visited":
__ChatterboxError("Function name \"", _name, "\" is reserved for internal Chatterbox use.\nPlease choose another action name.");
return false;
Expand Down
4 changes: 3 additions & 1 deletion scripts/ChatterboxCreate/ChatterboxCreate.gml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ function __ChatterboxClass(_filename, _singleton, _local_scope) constructor
optionInstruction = [];
optionStructArray = [];

hopStack = [];

current_node = undefined;
current_instruction = undefined;
stopped = true;
Expand Down Expand Up @@ -366,4 +368,4 @@ function __ChatterboxClass(_filename, _singleton, _local_scope) constructor

return loaded;
}
}
}
10 changes: 8 additions & 2 deletions scripts/__ChatterboxClassNode/__ChatterboxClassNode.gml
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function __ChatterboxSplitBody(_body)

buffer_delete(_body_buffer);

array_push(_in_substring_array, ["stop", "command", _line, 0]);
array_push(_in_substring_array, [CHATTERBOX_END_OF_NODE_HOPBACK? "hopback" : "stop", "command", _line, 0]);
return _in_substring_array;
}

Expand Down Expand Up @@ -285,6 +285,11 @@ function __ChatterboxCompile(_in_substring_array, _root_instruction)
_instruction.destination = __ChatterboxCompilerRemoveWhitespace(_remainder, all);
break;

case "hop":
var _instruction = new __ChatterboxClassInstruction("hop", _line, _indent);
_instruction.destination = __ChatterboxCompilerRemoveWhitespace(_remainder, all);
break;

case "if":
if (_previous_instruction.line == _line)
{
Expand Down Expand Up @@ -347,11 +352,12 @@ function __ChatterboxCompile(_in_substring_array, _root_instruction)

case "wait":
case "forcewait":
case "hopback":
case "stop":
_remainder = __ChatterboxCompilerRemoveWhitespace(_remainder, true);
if (_remainder != "")
{
__ChatterboxError("Cannot use arguments with <<wait>>, <<forcewait>>, or <<stop>>\n\Action was \"<<", _string, ">>\"");
__ChatterboxError("Cannot use arguments with <<wait>>, <<forcewait>>, <<hopback>>, or <<stop>>\n\Action was \"<<", _string, ">>\"");
}
else
{
Expand Down
4 changes: 4 additions & 0 deletions scripts/__ChatterboxConfig/__ChatterboxConfig.gml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#macro CHATTERBOX_SHOW_REJECTED_OPTIONS true
#macro CHATTERBOX_DECLARE_ON_COMPILE true //Whether to declare variables when Chatterbox script is compiled. Set to <false> for legacy (2.1 and earlier) behaviour

// Whether nodes without an explicit <<stop>> or <<hopback>> instruct at the end should default
// to <<hopback>>. Legacy behaviour (pre-2.7) is to set this to <false>
#macro CHATTERBOX_END_OF_NODE_HOPBACK true

// Direction mode controls how <<directions>> are processed by Chatterbox
// There are three possible values:
//
Expand Down
4 changes: 2 additions & 2 deletions scripts/__ChatterboxSystem/__ChatterboxSystem.gml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#region Internal Macro Definitions

#macro __CHATTERBOX_VERSION "2.6.1"
#macro __CHATTERBOX_DATE "2022-07-22"
#macro __CHATTERBOX_VERSION "2.7.0"
#macro __CHATTERBOX_DATE "2022-07-31"

#macro CHATTERBOX_CURRENT global.__chatterboxCurrent

Expand Down
64 changes: 53 additions & 11 deletions scripts/__ChatterboxVM/__ChatterboxVM.gml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ function __ChatterboxVM()
if (current_instruction.type == "stop")
{
stopped = true;
if (__CHATTERBOX_DEBUG_VM) __ChatterboxTrace("STOP");
if (__CHATTERBOX_DEBUG_VM) __ChatterboxTrace("STOP (<<stop>>)");
return undefined;
}

if ((current_instruction.type == "hopback") && (array_length(hopStack) <= 0))
{
stopped = true;
if (__CHATTERBOX_DEBUG_VM) __ChatterboxTrace("STOP (<<hopback>>)");
return undefined;
}

Expand Down Expand Up @@ -114,7 +121,8 @@ function __ChatterboxVMInner(_instruction)
if (((_next.type != "option") || CHATTERBOX_SINGLETON_WAIT_BEFORE_OPTION)
&& (_next.type != "wait")
&& (_next.type != "forcewait")
&& (_next.type != "stop"))
&& (_next.type != "stop")
&& !((_next.type == "hopback") && (array_length(hopStack) <= 0)))
{
waiting = true;
wait_instruction = _next;
Expand All @@ -136,7 +144,21 @@ function __ChatterboxVMInner(_instruction)
break;

case "jump":
if (__CHATTERBOX_DEBUG_VM) __ChatterboxTrace(__ChatterboxGenerateIndent(_instruction.indent), "[goto ", _instruction.destination, "]");
case "hop":
if (__CHATTERBOX_DEBUG_VM)
{
switch(_instruction.type)
{
case "jump": __ChatterboxTrace(__ChatterboxGenerateIndent(_instruction.indent), "[jump ", _instruction.destination, "]"); break;
case "hop": __ChatterboxTrace(__ChatterboxGenerateIndent(_instruction.indent), "[hop ", _instruction.destination, "]"); break;
}
}

if (_instruction.type == "hop")
{
if (__CHATTERBOX_DEBUG_VM) __ChatterboxTrace(__ChatterboxGenerateIndent(_instruction.indent), "Pushed \"", _next, "\" to hop stack");
array_push(hopStack, _next);
}

try
{
Expand Down Expand Up @@ -179,19 +201,39 @@ function __ChatterboxVMInner(_instruction)
break;

case "stop":
if (CHATTERBOX_WAIT_BEFORE_STOP && (array_length(content) > 0) && (array_length(option) <= 0))
case "hopback":
if ((_instruction.type == "stop") || (array_length(hopStack) <= 0))
{
waiting = true;
forced_waiting = true;
wait_instruction = _instruction;
//If there's nothing left in the hop stack, execute <<stop>> behaviour

if (CHATTERBOX_WAIT_BEFORE_STOP && (array_length(content) > 0) && (array_length(option) <= 0))
{
waiting = true;
forced_waiting = true;
wait_instruction = _instruction;
}
else
{
stopped = true;
}

_do_next = false;
if (__CHATTERBOX_DEBUG_VM)
{
switch(_instruction.type)
{
case "stop": __ChatterboxTrace(__ChatterboxGenerateIndent(_instruction.indent), "<<stop>>"); break;
case "hopback": __ChatterboxTrace(__ChatterboxGenerateIndent(_instruction.indent), "<<hopback>> (hop stack empty)"); break;
}
}
}
else
{
stopped = true;
//Otherwise pop a node off of our stack and go to it
_next = hopStack[array_length(hopStack)-1];
array_pop(hopStack);
if (__CHATTERBOX_DEBUG_VM) __ChatterboxTrace(__ChatterboxGenerateIndent(_instruction.indent), "<<hopback>> --> ", _next);
}

_do_next = false;
if (__CHATTERBOX_DEBUG_VM) __ChatterboxTrace(__ChatterboxGenerateIndent(_instruction.indent), "<<stop>>");
break;

case "option end":
Expand Down

0 comments on commit 24fa4b4

Please sign in to comment.