From dc3f3496f30e50b80b5ebfcf043dfe07a00c6436 Mon Sep 17 00:00:00 2001 From: magicalfeyfenny Date: Fri, 4 Jun 2021 04:09:05 -0400 Subject: [PATCH] Updated dialogue engine to work with external files --- dialogue_test.txt | 24 +++++++ thpj3/datafiles/dialogue_test.txt | 24 +++++++ thpj3/objects/obj_dialogue/Create_0.gml | 71 +++++++++++-------- thpj3/objects/obj_dialogue/Draw_0.gml | 20 ++++-- thpj3/objects/obj_dialogue/Step_0.gml | 8 ++- .../scr_dialogue_start/scr_dialogue_start.gml | 60 ++++++++++++++++ .../scr_dialogue_start/scr_dialogue_start.yy | 12 ++++ thpj3/thpj3.yyp | 5 +- 8 files changed, 184 insertions(+), 40 deletions(-) create mode 100644 dialogue_test.txt create mode 100644 thpj3/datafiles/dialogue_test.txt create mode 100644 thpj3/scripts/scr_dialogue_start/scr_dialogue_start.gml create mode 100644 thpj3/scripts/scr_dialogue_start/scr_dialogue_start.yy diff --git a/dialogue_test.txt b/dialogue_test.txt new file mode 100644 index 0000000..585f72b --- /dev/null +++ b/dialogue_test.txt @@ -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" diff --git a/thpj3/datafiles/dialogue_test.txt b/thpj3/datafiles/dialogue_test.txt new file mode 100644 index 0000000..585f72b --- /dev/null +++ b/thpj3/datafiles/dialogue_test.txt @@ -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" diff --git a/thpj3/objects/obj_dialogue/Create_0.gml b/thpj3/objects/obj_dialogue/Create_0.gml index 29ebd6a..e44e839 100644 --- a/thpj3/objects/obj_dialogue/Create_0.gml +++ b/thpj3/objects/obj_dialogue/Create_0.gml @@ -1,11 +1,11 @@ -dialogue_flag = 0; -dialogue_mode = true; -loopdoop = 0; +dialogue_mode = false; textspew = ""; texttarget = ""; actor_left = ""; +actor_left_emote = 0; actor_right = ""; +actor_right_emote = 0; spewlength = 0; last_active = 0; text_advance_ready = -1; @@ -13,31 +13,42 @@ text_advance_ready = -1; name_test = ds_queue_create(); text_test = ds_queue_create(); active_test = ds_queue_create(); +emote_test = ds_queue_create(); -if (dialogue_flag == 0) { - ds_queue_enqueue(name_test, - "", "", - "Wriggle", "Mystia", - "Wriggle", "Mystia", - "Wriggle", "Mystia", - "Wriggle", "Mystia", - "Wriggle", "Mystia" - ); - ds_queue_enqueue(text_test, - "", - "So, what are you up to?", - "on this fine day of Tuesday", - "not much my good binch", - "just drinking my soup", - "cool cool" - ); - ds_queue_enqueue(active_test, - 0, - 0, - 0, - 1, - 1, - 0 - ); - dialogue_flag++; -} \ No newline at end of file +loopdoop = 0; + +//ds_queue_enqueue(name_test, +// "", "", +// "Wriggle", "Mystia", +// "Wriggle", "Mystia", +// "Wriggle", "Mystia", +// "Wriggle", "Mystia", +// "Wriggle", "Mystia" +// ); +//ds_queue_enqueue(text_test, +// "", +// "So, what are you up to?", +// "on this fine day of Tuesday", +// "not much my good binch", +// "just drinking my soup", +// "cool cool" +// ); +//ds_queue_enqueue(active_test, +// 0, +// 0, +// 0, +// 1, +// 1, +// 0 +// ); +// +//ds_queue_enqueue(emote_test, +// 3, 2, +// 3, 2, +// 1, 2, +// 1, 2, +// 1, 2, +// 1, 5 +// ); + +scr_dialogue_start( "dialogue_test.txt" ); \ No newline at end of file diff --git a/thpj3/objects/obj_dialogue/Draw_0.gml b/thpj3/objects/obj_dialogue/Draw_0.gml index ab7155c..d7836a2 100644 --- a/thpj3/objects/obj_dialogue/Draw_0.gml +++ b/thpj3/objects/obj_dialogue/Draw_0.gml @@ -4,20 +4,28 @@ if (dialogue_mode) { // draw_sprite_ext( actor_left //TODO: Draw right active character, transparent if "last active" // draw_sprite_ext( actor_right - + draw_text( 128, 320, actor_left_emote ); + draw_text( 1000, 320, actor_right_emote ); + // Draw dialogue box draw_self(); //TODO: Draw current active character's name + draw_set_alpha(1); 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 ) { - draw_set_halign( fa_right ); - draw_text( 1080, 640, actor_right ); - draw_set_halign( fa_left ); + draw_set_alpha(.5); } + draw_text( 128, 640, actor_left ); + + draw_set_alpha(1); //TODO: Draw current active character's text, adding one character at a time draw_text( 128, 480, textspew ); diff --git a/thpj3/objects/obj_dialogue/Step_0.gml b/thpj3/objects/obj_dialogue/Step_0.gml index 92c786a..1355903 100644 --- a/thpj3/objects/obj_dialogue/Step_0.gml +++ b/thpj3/objects/obj_dialogue/Step_0.gml @@ -1,10 +1,12 @@ 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; actor_left = ds_queue_dequeue(name_test); + actor_left_emote = ds_queue_dequeue(emote_test); 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_emote = ds_queue_dequeue(emote_test); } texttarget = ds_queue_dequeue(text_test); textspew = ""; @@ -27,7 +29,7 @@ if (dialogue_mode) { if (text_advance_ready == 1) { if (keyboard_check_pressed( ord("Z") ) ) { 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; } } diff --git a/thpj3/scripts/scr_dialogue_start/scr_dialogue_start.gml b/thpj3/scripts/scr_dialogue_start/scr_dialogue_start.gml new file mode 100644 index 0000000..33c5c83 --- /dev/null +++ b/thpj3/scripts/scr_dialogue_start/scr_dialogue_start.gml @@ -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; +} \ No newline at end of file diff --git a/thpj3/scripts/scr_dialogue_start/scr_dialogue_start.yy b/thpj3/scripts/scr_dialogue_start/scr_dialogue_start.yy new file mode 100644 index 0000000..a374fdd --- /dev/null +++ b/thpj3/scripts/scr_dialogue_start/scr_dialogue_start.yy @@ -0,0 +1,12 @@ +{ + "isDnD": false, + "isCompatibility": false, + "parent": { + "name": "thpj3", + "path": "thpj3.yyp", + }, + "resourceVersion": "1.0", + "name": "scr_dialogue_start", + "tags": [], + "resourceType": "GMScript", +} \ No newline at end of file diff --git a/thpj3/thpj3.yyp b/thpj3/thpj3.yyp index 09d9059..21c3928 100644 --- a/thpj3/thpj3.yyp +++ b/thpj3/thpj3.yyp @@ -6,6 +6,7 @@ {"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":"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":"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,}, @@ -49,7 +50,9 @@ "TextureGroups": [ {"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": { "IDEVersion": "2.3.2.560", },