diff --git a/Assets/Script/Lib/Dora/en/YarnRunner.d.tl b/Assets/Script/Lib/Dora/en/YarnRunner.d.tl index 85619deb6..ae7bec776 100644 --- a/Assets/Script/Lib/Dora/en/YarnRunner.d.tl +++ b/Assets/Script/Lib/Dora/en/YarnRunner.d.tl @@ -57,6 +57,9 @@ local record YarnRunner -- Optional markup for the text. marks: nil | {Markup} + + -- A flag indicating that advancing will yield an OptionResult as the next result. + optionsFollowed: nil | boolean end -- Record to define options in the narrative. @@ -70,9 +73,9 @@ local record YarnRunner -- @param choice (integer) [optional] Index of the choice if presented with options. -- @return (nil | ResultType) Returns nil if the narrative ended. Returns enum string result when YarnRunner is still running. -- @return (string | table) Depending on the narrative, it can return a type of result and the associated content: - -- "Text" and a TextResult - -- "Option" and an OptionResult - -- "Error" and a string error message + -- "Text" and a TextResult. + -- "Option" and an OptionResult. + -- "Error" and a string error message. -- nil and a string indecating the narrative ends. advance: function(self: YarnRunner, choice?: integer): nil | ResultType, string | table end diff --git a/Assets/Script/Lib/Dora/zh-Hans/YarnRunner.d.tl b/Assets/Script/Lib/Dora/zh-Hans/YarnRunner.d.tl index c7e170dbc..ab6145ef7 100644 --- a/Assets/Script/Lib/Dora/zh-Hans/YarnRunner.d.tl +++ b/Assets/Script/Lib/Dora/zh-Hans/YarnRunner.d.tl @@ -57,6 +57,9 @@ local record YarnRunner -- 文本的可选标记。 marks: nil | {Markup} + + -- 表示下一个叙事推进得到的结果将为选项的标志。 + optionsFollowed: nil | boolean end -- 在叙述中定义选项的记录。 diff --git a/Assets/Script/Test/Yarn.yue b/Assets/Script/Test/Yarn.yue index 238d8cc98..a67c93327 100644 --- a/Assets/Script/Test/Yarn.yue +++ b/Assets/Script/Test/Yarn.yue @@ -84,7 +84,10 @@ advance = (option)-> switch mark when {name: attr, attrs: {:name}} charName = "#{name}: " if attr == "char" texts[] = charName .. result.text - setButtons! + if result.optionsFollowed + advance! + else + setButtons! when "Option" for i, op in ipairs result texts[] = "[#{i}]: #{op.text}" diff --git a/Assets/Script/Test/tutorial.yarn b/Assets/Script/Test/tutorial.yarn index a5240efd7..08a94c4ac 100644 --- a/Assets/Script/Test/tutorial.yarn +++ b/Assets/Script/Test/tutorial.yarn @@ -1,6 +1,6 @@ { "header": { - "lastSavedUnix": "2023-10-10T08:10:44.630Z", + "lastSavedUnix": "2023-11-27T09:49:28.955Z", "language": "en-GB", "documentType": "yarn", "markupLanguage": "bbcode", @@ -13,7 +13,7 @@ { "title": "Start", "tags": "", - "body": "Alex, you've finally decided to join the rebellion against the Cybertech Corp. The future of humanity is at stake!\n\n-> Continue\n\nDo you want to:\n-> Infiltrate the Cybertech Corp headquarters.\n Start infiltrating...\n <>\n-> Spread propaganda against cybernetics.\n Taking action...\n <>\n", + "body": "Alex, you've finally decided to join the rebellion against the Cybertech Corp. The future of humanity is at stake!\n\n-> Continue\n\nDo you want to:\n-> Infiltrate the Cybertech Corp headquarters.\n Start infiltrating...\n <>\n-> Spread propaganda against cybernetics.\n Taking action...\n <>", "position": { "x": -80, "y": -560 @@ -23,7 +23,7 @@ { "title": "Infiltrate", "tags": "", - "body": "You've decided to infiltrate the Cybertech Corp. This is risky, but if successful, it could end their reign.\n\n<>\n\n-> Continue\n\n<>", + "body": "<>\n\nYou've decided to infiltrate the Cybertech Corp. This is risky, but if successful, it could end their reign.\n\n-> Continue\n\n<>", "position": { "x": -240, "y": -160 @@ -33,7 +33,7 @@ { "title": "Propaganda", "tags": "", - "body": "You've chosen to spread the word about the dangers of Cybertech's cybernetics. Information is power.\n\n<>\n\n-> Continue\n\n<>", + "body": "<>\n\nYou've chosen to spread the word about the dangers of Cybertech's cybernetics. Information is power.\n\n-> Continue\n\n<>", "position": { "x": 40, "y": -160 @@ -43,7 +43,7 @@ { "title": "Outcome", "tags": "", - "body": "<>\nYou sneak into the Cybertech Corp's main facility. It's eerily quiet.\n-> Attempt to hack their mainframe.\n Hacking...\n-> Search for documents.\n<>\nYou start broadcasting messages across the city, warning citizens. The resistance grows stronger every day.\n-> Organize a protest.\n-> Stay underground and plan.\n<>\n\n-> to be continued", + "body": "<>\nYou sneak into the Cybertech Corp's main facility. It's eerily quiet.\n-> Attempt to hack their mainframe.\n Hacking...\n-> Search for documents.\n Searching...\n<>\nYou start broadcasting messages across the city, warning citizens. The resistance grows stronger every day.\n-> Organize a protest.\n Actioning...\n-> Stay underground and plan.\n Planing...\n<>\n\n-> to be continued", "position": { "x": -80, "y": 240 diff --git a/Site/docs/api/Class/App.mdx b/Site/docs/api/Class/App.mdx index d62a791b3..cf3bb499b 100644 --- a/Site/docs/api/Class/App.mdx +++ b/Site/docs/api/Class/App.mdx @@ -108,6 +108,19 @@ Should be in format of "v0.0.0". const version: string ``` +## deltaTime + +**Type:** Readonly Field. + +**Description:** + +  The time in seconds since the last frame update. + +**Signature:** +```tl +const deltaTime: number +``` + ## eclapsedTime **Type:** Readonly Field. diff --git a/Site/docs/api/Class/Controller.mdx b/Site/docs/api/Class/Controller.mdx index f9dbf1147..482000f38 100644 --- a/Site/docs/api/Class/Controller.mdx +++ b/Site/docs/api/Class/Controller.mdx @@ -21,6 +21,8 @@ enum AxisName "lefty" "rightx" "righty" + "lefttrigger" + "righttrigger" end ``` @@ -44,10 +46,8 @@ enum ButtonName "dpup" "leftshoulder" "leftstick" - "lefttrigger" "rightshoulder" "rightstick" - "righttrigger" "start" "x" "y" diff --git a/Site/docs/api/Class/Director.mdx b/Site/docs/api/Class/Director.mdx index f18d66a8f..dc1b83e98 100644 --- a/Site/docs/api/Class/Director.mdx +++ b/Site/docs/api/Class/Director.mdx @@ -129,19 +129,6 @@ const postScheduler: Scheduler const currentCamera: Camera ``` -## deltaTime - -**Type:** Readonly Field. - -**Description:** - -  The time in seconds since the last frame update. - -**Signature:** -```tl -const deltaTime: number -``` - ## pushCamera **Type:** Function. diff --git a/Site/docs/api/Class/YarnRunner.mdx b/Site/docs/api/Class/YarnRunner.mdx index b9d65f81e..21c2efabf 100644 --- a/Site/docs/api/Class/YarnRunner.mdx +++ b/Site/docs/api/Class/YarnRunner.mdx @@ -92,4 +92,4 @@ advance: function(self: YarnRunner, choice?: integer): nil | ResultType, string | Return Type | Description | | --- | --- | | nil \| ResultType | Returns nil if the narrative ended. Returns enum string result when YarnRunner is still running. | -| string \| table | Depending on the narrative, it can return a type of result and the associated content:"Text" and a TextResult"Option" and an OptionResult"Error" and a string error messagenil and a string indecating the narrative ends. | \ No newline at end of file +| string \| table | Depending on the narrative, it can return a type of result and the associated content:"Text" and a TextResult."Option" and an OptionResult."Error" and a string error message.nil and a string indecating the narrative ends. | \ No newline at end of file diff --git a/Site/docs/api/Class/YarnRunner/TextResult.mdx b/Site/docs/api/Class/YarnRunner/TextResult.mdx index dcc24afc1..c593b123d 100644 --- a/Site/docs/api/Class/YarnRunner/TextResult.mdx +++ b/Site/docs/api/Class/YarnRunner/TextResult.mdx @@ -30,4 +30,17 @@ text: string **Signature:** ```tl marks: nil | {Markup} +``` + +## optionsFollowed + +**Type:** Field. + +**Description:** + +  A flag indicating that advancing will yield an OptionResult as the next result. + +**Signature:** +```tl +optionsFollowed: nil | boolean ``` \ No newline at end of file diff --git a/Site/i18n/zh-Hans/docusaurus-plugin-content-docs/current/api/Class/App.mdx b/Site/i18n/zh-Hans/docusaurus-plugin-content-docs/current/api/Class/App.mdx index d794d65b8..4fc8b3ff7 100644 --- a/Site/i18n/zh-Hans/docusaurus-plugin-content-docs/current/api/Class/App.mdx +++ b/Site/i18n/zh-Hans/docusaurus-plugin-content-docs/current/api/Class/App.mdx @@ -107,6 +107,19 @@ const platform: Platform const version: string ``` +## deltaTime + +**类型:** 只读成员变量。 + +**描述:** + +  自从上一帧游戏更新以来间隔的时间(以秒为单位)。 + +**签名:** +```tl +const deltaTime: number +``` + ## eclapsedTime **类型:** 只读成员变量。 diff --git a/Site/i18n/zh-Hans/docusaurus-plugin-content-docs/current/api/Class/Controller.mdx b/Site/i18n/zh-Hans/docusaurus-plugin-content-docs/current/api/Class/Controller.mdx index 283e50020..25326ce6a 100644 --- a/Site/i18n/zh-Hans/docusaurus-plugin-content-docs/current/api/Class/Controller.mdx +++ b/Site/i18n/zh-Hans/docusaurus-plugin-content-docs/current/api/Class/Controller.mdx @@ -21,6 +21,8 @@ enum AxisName "lefty" "rightx" "righty" + "lefttrigger" + "righttrigger" end ``` @@ -44,10 +46,8 @@ enum ButtonName "dpup" "leftshoulder" "leftstick" - "lefttrigger" "rightshoulder" "rightstick" - "righttrigger" "start" "x" "y" diff --git a/Site/i18n/zh-Hans/docusaurus-plugin-content-docs/current/api/Class/Director.mdx b/Site/i18n/zh-Hans/docusaurus-plugin-content-docs/current/api/Class/Director.mdx index e23451b21..3c9c33e08 100644 --- a/Site/i18n/zh-Hans/docusaurus-plugin-content-docs/current/api/Class/Director.mdx +++ b/Site/i18n/zh-Hans/docusaurus-plugin-content-docs/current/api/Class/Director.mdx @@ -129,19 +129,6 @@ const postScheduler: Scheduler const currentCamera: Camera ``` -## deltaTime - -**类型:** 只读成员变量。 - -**描述:** - -  自从上一帧更新以来间隔的时间(以秒为单位)。 - -**签名:** -```tl -const deltaTime: number -``` - ## pushCamera **类型:** 函数。 diff --git a/Site/i18n/zh-Hans/docusaurus-plugin-content-docs/current/api/Class/YarnRunner/TextResult.mdx b/Site/i18n/zh-Hans/docusaurus-plugin-content-docs/current/api/Class/YarnRunner/TextResult.mdx index 1249ab120..d2fd19350 100644 --- a/Site/i18n/zh-Hans/docusaurus-plugin-content-docs/current/api/Class/YarnRunner/TextResult.mdx +++ b/Site/i18n/zh-Hans/docusaurus-plugin-content-docs/current/api/Class/YarnRunner/TextResult.mdx @@ -30,4 +30,17 @@ text: string **签名:** ```tl marks: nil | {Markup} +``` + +## optionsFollowed + +**类型:** 成员变量。 + +**描述:** + +  表示下一个叙事推进得到的结果将为选项的标志。 + +**签名:** +```tl +optionsFollowed: nil | boolean ``` \ No newline at end of file diff --git a/Source/Lua/Yarn/YarnCompiler.cpp b/Source/Lua/Yarn/YarnCompiler.cpp index 077b3dc95..4b7d1f7aa 100755 --- a/Source/Lua/Yarn/YarnCompiler.cpp +++ b/Source/Lua/Yarn/YarnCompiler.cpp @@ -868,10 +868,14 @@ class YarnCompiler { return; } str_list temp; - for (auto stmt : block->statements.objects()) { + const auto& stmts = block->statements.objects(); + for (auto it = stmts.begin(); it != stmts.end(); ++it) { + auto stmt = *it; switch (stmt->get_id()) { case id(): { - transformDialog(static_cast(stmt), temp); + auto next = it; + ++next; + transformDialog(static_cast(stmt), temp, next != stmts.end() && (*next)->get_id() == id()); temp.back() = indent() + "coroutine.yield(\"Dialog\", "s + temp.back() + ')' + nl(stmt); break; } @@ -917,7 +921,7 @@ class YarnCompiler { } } - void transformDialog(Dialog_t* dialog, str_list& out) { + void transformDialog(Dialog_t* dialog, str_list& out, bool optionsFollowed) { auto x = dialog; str_list texts; std::list markups; @@ -1032,6 +1036,9 @@ class YarnCompiler { decIndentOffset(); _buf << indent() << "},"sv << nl(x); } + if (optionsFollowed) { + _buf << indent() << "optionsFollowed = true,"sv << nl(x); + } decIndentOffset(); _buf << indent() << '}'; if (ifTags.empty()) { @@ -1071,7 +1078,7 @@ class YarnCompiler { incIndentOffset(); for (auto group : group->options.objects()) { auto option = static_cast(group); - transformDialog(option->dialog, options); + transformDialog(option->dialog, options, false); options.back() = indent() + options.back() + ',' + nl(x); branches.push_back(indent() + "function()"s + nl(x)); if (option->block) {