Skip to content

Commit

Permalink
basic speech parsers
Browse files Browse the repository at this point in the history
adds basic parsers for getting the speaker, speaker data, and speech from a chatterbox's content
  • Loading branch information
Pokeizel committed Apr 7, 2022
1 parent 334998b commit cc3cbf8
Show file tree
Hide file tree
Showing 16 changed files with 236 additions and 11 deletions.
16 changes: 10 additions & 6 deletions chatterbox.yyp

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

9 changes: 9 additions & 0 deletions datafiles/testcase_parsers.yarn
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#__PrivCrochet_version:1
__PrivCrochet_colorID: 0
__PrivCrochet_position: -80,0
__PrivCrochet_tags:
title: Start
---
Chatterbox[0]: I have been parsed. My identity, my values, my thoughts... they've all been parsed.
Chatterbox[1]: Nobody can understand how this feels.
===
9 changes: 9 additions & 0 deletions objects/oTestCaseParsers/Create_0.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ChatterboxLoadFromFile("testcase_parsers.yarn");
box = ChatterboxCreate();
ChatterboxJump(box, "Start");

speaker = "";
speech = "";
color = c_white; //This will be changed by the speaker's data, if any has been set.
//This can be used in a variety of ways that go beyond colors,
//like image indexes, enum values, array positions, and more.
47 changes: 47 additions & 0 deletions objects/oTestCaseParsers/Draw_0.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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))
{
//Split parts of the content with parsers
speaker = ChatterboxGetSpeaker(box, _i);
speech = ChatterboxGetSpeech(box, _i);
switch (ChatterboxGetSpeakerData(box, _i, 0))
{
case 0: color = c_yellow; break;
case 1: color = c_red; break;
}

//Draw Speaker and apply data
var c = color;
draw_text_color(_x, _y, speaker, c,c,c,c,1);
_y += string_height(speaker);

//Draw Speech
var c = c_white;
draw_text_color(_x, _y, speech, c,c,c,c,1);
_y += string_height(speech);
++_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)");
}
}
4 changes: 4 additions & 0 deletions objects/oTestCaseParsers/Step_0.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if (ChatterboxIsWaiting(box))
{
if (keyboard_check_released(vk_space)) ChatterboxContinue(box);
}
35 changes: 35 additions & 0 deletions objects/oTestCaseParsers/oTestCaseParsers.yy

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

8 changes: 7 additions & 1 deletion options/main/options_main.yy

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

4 changes: 2 additions & 2 deletions rooms/rmMain/rmMain.yy

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

4 changes: 2 additions & 2 deletions rooms/rmTest/rmTest.yy

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

23 changes: 23 additions & 0 deletions scripts/ChatterboxGetSpeaker/ChatterboxGetSpeaker.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// Returns the string behind the first colon in a line of dialogue, excluding the speaker data if there's any.
///
/// @param chatterbox
/// @param contentIndex

function ChatterboxGetSpeaker(_chatterbox, _index)
{
var _str = ChatterboxGetContent(_chatterbox, _index);
if (_str != undefined)
{
var _colon = string_pos(":", _str);
var _name = string_copy(_str, 1, _colon-1);
var _c1 = CHATTERBOX_SPEAKERDATA_TAG_OPEN;
var _c2 = CHATTERBOX_SPEAKERDATA_TAG_CLOSE;
var _char_l = string_pos(_c1, _str);
var _char_r = string_pos(_c2, _str);
if (_char_l and _char_r < _colon)
{
var _name = string_delete(_name, _char_l, _char_r-_char_l+1);
}
return _name;
} else return undefined;
}
12 changes: 12 additions & 0 deletions scripts/ChatterboxGetSpeaker/ChatterboxGetSpeaker.yy

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

25 changes: 25 additions & 0 deletions scripts/ChatterboxGetSpeakerData/ChatterboxGetSpeakerData.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/// Returns the value between special characters
/// (CHATTERBOX_SPEAKERDATA_TAG_...) after the speaker and before the speech.
///
/// @param chatterbox
/// @param contentIndex
/// @param [default]

function ChatterboxGetSpeakerData(_chatterbox, _index, _default = undefined)
{
var _str = ChatterboxGetContent(_chatterbox, _index);
if (_str != undefined)
{
var _colon = string_pos(":", _str);
var _c1 = CHATTERBOX_SPEAKERDATA_TAG_OPEN;
var _c2 = CHATTERBOX_SPEAKERDATA_TAG_CLOSE;
var _char_l = string_pos(_c1, _str);
var _char_r = string_pos(_c2, _str);
if (_char_l and _char_r < _colon)
{
var _data = string_copy(_str, _char_l+1, _char_r-_char_l-1);
return _data;
}
return _default;
} else return undefined;
}
12 changes: 12 additions & 0 deletions scripts/ChatterboxGetSpeakerData/ChatterboxGetSpeakerData.yy

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

24 changes: 24 additions & 0 deletions scripts/ChatterboxGetSpeech/ChatterboxGetSpeech.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// Returns the string after the first colon in a Chatterbox's content.
///
/// @param chatterbox
/// @param contentIndex

function ChatterboxGetSpeech(_chatterbox, _index)
{
var _str = ChatterboxGetContent(_chatterbox, _index);
if (_str != undefined)
{
var _colon = string_pos(":", _str);
var _space;
if (string_pos(" ", _str) == _colon+1)
{
_space = 2;
}
else
{
_space = 1;
}
var _speech = string_copy(_str, _colon+_space, string_length(_str)-_colon);
return _speech;
} else return undefined;
}
12 changes: 12 additions & 0 deletions scripts/ChatterboxGetSpeech/ChatterboxGetSpeech.yy

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

3 changes: 3 additions & 0 deletions scripts/__ChatterboxConfig/__ChatterboxConfig.gml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

#macro CHATTERBOX_INCLUDED_FILES_SUBDIRECTORY ""

#macro CHATTERBOX_SPEAKERDATA_TAG_OPEN "[" //
#macro CHATTERBOX_SPEAKERDATA_TAG_CLOSE "]" //The characters that hold speaker data between them. It can be, for example, an image index.

#region Advanced

#macro CHATTERBOX_INDENT_TAB_SIZE 4 //Space size of a tab character
Expand Down

0 comments on commit cc3cbf8

Please sign in to comment.