Updated dialogue engine to work with external files

This commit is contained in:
magicalfeyfenny 2021-06-04 04:09:05 -04:00
parent 9ff4641278
commit dc3f3496f3
8 changed files with 184 additions and 40 deletions

24
dialogue_test.txt Normal file
View File

@ -0,0 +1,24 @@
0
3 Wriggle
2 Mystia
"So, what are you up to?"
0
3 Wriggle
2 Mystia
"on this fine day of Tuesday"
1
1 Wriggle
2 Mystia
"not much my good binch"
1
1 Wriggle
2 Mystia
"just drinking my soup"
0
1 Wriggle
5 Mystia
"cool cool"
1
2 Wriggle
1 Mystia
"btw did you hear we're files now"

View File

@ -0,0 +1,24 @@
0
3 Wriggle
2 Mystia
"So, what are you up to?"
0
3 Wriggle
2 Mystia
"on this fine day of Tuesday"
1
1 Wriggle
2 Mystia
"not much my good binch"
1
1 Wriggle
2 Mystia
"just drinking my soup"
0
1 Wriggle
5 Mystia
"cool cool"
1
2 Wriggle
1 Mystia
"btw did you hear we're files now"

View File

@ -1,11 +1,11 @@
dialogue_flag = 0; dialogue_mode = false;
dialogue_mode = true;
loopdoop = 0;
textspew = ""; textspew = "";
texttarget = ""; texttarget = "";
actor_left = ""; actor_left = "";
actor_left_emote = 0;
actor_right = ""; actor_right = "";
actor_right_emote = 0;
spewlength = 0; spewlength = 0;
last_active = 0; last_active = 0;
text_advance_ready = -1; text_advance_ready = -1;
@ -13,31 +13,42 @@ text_advance_ready = -1;
name_test = ds_queue_create(); name_test = ds_queue_create();
text_test = ds_queue_create(); text_test = ds_queue_create();
active_test = ds_queue_create(); active_test = ds_queue_create();
emote_test = ds_queue_create();
if (dialogue_flag == 0) { loopdoop = 0;
ds_queue_enqueue(name_test,
"", "", //ds_queue_enqueue(name_test,
"Wriggle", "Mystia", // "", "",
"Wriggle", "Mystia", // "Wriggle", "Mystia",
"Wriggle", "Mystia", // "Wriggle", "Mystia",
"Wriggle", "Mystia", // "Wriggle", "Mystia",
"Wriggle", "Mystia" // "Wriggle", "Mystia",
); // "Wriggle", "Mystia"
ds_queue_enqueue(text_test, // );
"", //ds_queue_enqueue(text_test,
"So, what are you up to?", // "",
"on this fine day of Tuesday", // "So, what are you up to?",
"not much my good binch", // "on this fine day of Tuesday",
"just drinking my soup", // "not much my good binch",
"cool cool" // "just drinking my soup",
); // "cool cool"
ds_queue_enqueue(active_test, // );
0, //ds_queue_enqueue(active_test,
0, // 0,
0, // 0,
1, // 0,
1, // 1,
0 // 1,
); // 0
dialogue_flag++; // );
} //
//ds_queue_enqueue(emote_test,
// 3, 2,
// 3, 2,
// 1, 2,
// 1, 2,
// 1, 2,
// 1, 5
// );
scr_dialogue_start( "dialogue_test.txt" );

View File

@ -4,20 +4,28 @@ if (dialogue_mode) {
// draw_sprite_ext( actor_left // draw_sprite_ext( actor_left
//TODO: Draw right active character, transparent if "last active" //TODO: Draw right active character, transparent if "last active"
// draw_sprite_ext( actor_right // draw_sprite_ext( actor_right
draw_text( 128, 320, actor_left_emote );
draw_text( 1000, 320, actor_right_emote );
// Draw dialogue box // Draw dialogue box
draw_self(); draw_self();
//TODO: Draw current active character's name //TODO: Draw current active character's name
draw_set_alpha(1);
if ( last_active == 0 ) { if ( last_active == 0 ) {
draw_text( 128, 640, actor_left ); draw_set_alpha(.5);
}
draw_set_halign( fa_right );
draw_text( 1080, 640, actor_right );
draw_set_halign( fa_left );
} draw_set_alpha(1);
if ( last_active == 1 ) { if ( last_active == 1 ) {
draw_set_halign( fa_right ); draw_set_alpha(.5);
draw_text( 1080, 640, actor_right );
draw_set_halign( fa_left );
} }
draw_text( 128, 640, actor_left );
draw_set_alpha(1);
//TODO: Draw current active character's text, adding one character at a time //TODO: Draw current active character's text, adding one character at a time
draw_text( 128, 480, textspew ); draw_text( 128, 480, textspew );

View File

@ -1,10 +1,12 @@
if (dialogue_mode) { if (dialogue_mode) {
if (text_advance_ready == -1 && !ds_queue_empty(name_test) && !ds_queue_empty(name_test) && !ds_queue_empty(active_test)) { if (text_advance_ready == -1 && !ds_queue_empty(name_test) && !ds_queue_empty(name_test) && !ds_queue_empty(active_test) && !ds_queue_empty(emote_test)) {
text_advance_ready = 0; text_advance_ready = 0;
actor_left = ds_queue_dequeue(name_test); actor_left = ds_queue_dequeue(name_test);
actor_left_emote = ds_queue_dequeue(emote_test);
actor_right = ""; actor_right = "";
if (!ds_queue_empty(name_test)) { if (!ds_queue_empty(name_test) && !ds_queue_empty(emote_test)) {
actor_right = ds_queue_dequeue(name_test); actor_right = ds_queue_dequeue(name_test);
actor_right_emote = ds_queue_dequeue(emote_test);
} }
texttarget = ds_queue_dequeue(text_test); texttarget = ds_queue_dequeue(text_test);
textspew = ""; textspew = "";
@ -27,7 +29,7 @@ if (dialogue_mode) {
if (text_advance_ready == 1) { if (text_advance_ready == 1) {
if (keyboard_check_pressed( ord("Z") ) ) { if (keyboard_check_pressed( ord("Z") ) ) {
text_advance_ready = -1; text_advance_ready = -1;
if (ds_queue_empty(name_test) || ds_queue_empty(text_test) || ds_queue_empty(active_test)) { if (ds_queue_empty(name_test) || ds_queue_empty(text_test) || ds_queue_empty(active_test) || ds_queue_empty(emote_test)) {
dialogue_mode = false; dialogue_mode = false;
} }
} }

View File

@ -0,0 +1,60 @@
/// @function: scr_dialogue_start( _filename );
/// @param {string} _filename The filename of the dialogue branch
// Requirements: An instance of obj_dialogue
function scr_dialogue_start( _filename ) {
if (!instance_exists(obj_dialogue) ) {
return -1;
}
//file format for dialogue:
/*
last_active {int} active_test
actor_left_emote {int} emote_test
actor_left {string} name_test
actor_right_emote {int} emote_test
actor_right {string} name_test
texttarget {string} text_test
repeat until EOF
*/
//clear all queues
ds_queue_clear( obj_dialogue.active_test );
ds_queue_clear( obj_dialogue.emote_test );
ds_queue_clear( obj_dialogue.name_test );
ds_queue_clear( obj_dialogue.text_test );
//open dialogue file matching _filename
file = file_text_open_read( _filename );
//enqueue dialogue
while (!file_text_eof(file) ) {
ds_queue_enqueue( obj_dialogue.active_test, file_text_read_real(file) );
file_text_readln(file);
ds_queue_enqueue( obj_dialogue.emote_test, file_text_read_real(file) );
ds_queue_enqueue( obj_dialogue.name_test, file_text_read_string(file) );
file_text_readln(file);
ds_queue_enqueue( obj_dialogue.emote_test, file_text_read_real(file) );
ds_queue_enqueue( obj_dialogue.name_test, file_text_read_string(file) );
file_text_readln(file);
ds_queue_enqueue( obj_dialogue.text_test, file_text_read_string(file) );
file_text_readln(file);
}
//close dialogue file
file_text_close( file );
//enter dialogue mode and set variables
obj_dialogue.dialogue_mode = true;
obj_dialogue.textspew = "";
obj_dialogue.texttarget = "";
obj_dialogue.actor_left = "";
obj_dialogue.actor_left_emote = 0;
obj_dialogue.actor_right = "";
obj_dialogue.actor_right_emote = 0;
obj_dialogue.spewlength = 0;
obj_dialogue.last_active = 0;
obj_dialogue.text_advance_ready = -1;
}

View File

@ -0,0 +1,12 @@
{
"isDnD": false,
"isCompatibility": false,
"parent": {
"name": "thpj3",
"path": "thpj3.yyp",
},
"resourceVersion": "1.0",
"name": "scr_dialogue_start",
"tags": [],
"resourceType": "GMScript",
}

View File

@ -6,6 +6,7 @@
{"id":{"name":"Sprite7","path":"sprites/Sprite7/Sprite7.yy",},"order":9,}, {"id":{"name":"Sprite7","path":"sprites/Sprite7/Sprite7.yy",},"order":9,},
{"id":{"name":"obj_title_moon","path":"objects/obj_title_moon/obj_title_moon.yy",},"order":1,}, {"id":{"name":"obj_title_moon","path":"objects/obj_title_moon/obj_title_moon.yy",},"order":1,},
{"id":{"name":"spr_title_star","path":"sprites/spr_title_star/spr_title_star.yy",},"order":8,}, {"id":{"name":"spr_title_star","path":"sprites/spr_title_star/spr_title_star.yy",},"order":8,},
{"id":{"name":"scr_dialogue_start","path":"scripts/scr_dialogue_start/scr_dialogue_start.yy",},"order":10,},
{"id":{"name":"rm_disclaimer","path":"rooms/rm_disclaimer/rm_disclaimer.yy",},"order":3,}, {"id":{"name":"rm_disclaimer","path":"rooms/rm_disclaimer/rm_disclaimer.yy",},"order":3,},
{"id":{"name":"obj_title_text","path":"objects/obj_title_text/obj_title_text.yy",},"order":4,}, {"id":{"name":"obj_title_text","path":"objects/obj_title_text/obj_title_text.yy",},"order":4,},
{"id":{"name":"spr_title_bg","path":"sprites/spr_title_bg/spr_title_bg.yy",},"order":6,}, {"id":{"name":"spr_title_bg","path":"sprites/spr_title_bg/spr_title_bg.yy",},"order":6,},
@ -49,7 +50,9 @@
"TextureGroups": [ "TextureGroups": [
{"isScaled":true,"autocrop":true,"border":2,"mipsToGenerate":0,"groupParent":null,"targets":-1,"resourceVersion":"1.3","name":"Default","resourceType":"GMTextureGroup",}, {"isScaled":true,"autocrop":true,"border":2,"mipsToGenerate":0,"groupParent":null,"targets":-1,"resourceVersion":"1.3","name":"Default","resourceType":"GMTextureGroup",},
], ],
"IncludedFiles": [], "IncludedFiles": [
{"CopyToMask":153157610357391598,"filePath":"datafiles","resourceVersion":"1.0","name":"dialogue_test.txt","resourceType":"GMIncludedFile",},
],
"MetaData": { "MetaData": {
"IDEVersion": "2.3.2.560", "IDEVersion": "2.3.2.560",
}, },