-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
adds basic parsers for getting the speaker, speaker data, and speech from a chatterbox's content
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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. | ||
=== |
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. |
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)"); | ||
} | ||
} |
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); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.