Skip to content

Commit

Permalink
update YarnRunner and doc. [skip CI]
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Nov 27, 2023
1 parent 262aaae commit dd10236
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 44 deletions.
9 changes: 6 additions & 3 deletions Assets/Script/Lib/Dora/en/YarnRunner.d.tl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Assets/Script/Lib/Dora/zh-Hans/YarnRunner.d.tl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ local record YarnRunner

-- 文本的可选标记。
marks: nil | {Markup}

-- 表示下一个叙事推进得到的结果将为选项的标志。
optionsFollowed: nil | boolean
end

-- 在叙述中定义选项的记录。
Expand Down
5 changes: 4 additions & 1 deletion Assets/Script/Test/Yarn.yue
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
10 changes: 5 additions & 5 deletions Assets/Script/Test/tutorial.yarn
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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 <<jump Infiltrate>>\n-> Spread propaganda against cybernetics.\n Taking action...\n <<jump Propaganda>>\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 <<jump Infiltrate>>\n-> Spread propaganda against cybernetics.\n Taking action...\n <<jump Propaganda>>",
"position": {
"x": -80,
"y": -560
Expand All @@ -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<<set $infiltrate = true>>\n\n-> Continue\n\n<<jump Outcome>>",
"body": "<<set $infiltrate = true>>\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<<jump Outcome>>",
"position": {
"x": -240,
"y": -160
Expand All @@ -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<<set $infiltrate = false>>\n\n-> Continue\n\n<<jump Outcome>>",
"body": "<<set $infiltrate = false>>\n\nYou've chosen to spread the word about the dangers of Cybertech's cybernetics. Information is power.\n\n-> Continue\n\n<<jump Outcome>>",
"position": {
"x": 40,
"y": -160
Expand All @@ -43,7 +43,7 @@
{
"title": "Outcome",
"tags": "",
"body": "<<if $infiltrate>>\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<<else>>\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<<endif>>\n\n-> to be continued",
"body": "<<if $infiltrate>>\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<<else>>\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<<endif>>\n\n-> to be continued",
"position": {
"x": -80,
"y": 240
Expand Down
13 changes: 13 additions & 0 deletions Site/docs/api/Class/App.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@ Should be in format of "v0.0.0".
const version: string
```

## deltaTime

**Type:** Readonly Field.

**Description:**

&emsp;&emsp;The time in seconds since the last frame update.

**Signature:**
```tl
const deltaTime: number
```

## eclapsedTime

**Type:** Readonly Field.
Expand Down
4 changes: 2 additions & 2 deletions Site/docs/api/Class/Controller.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ enum AxisName
"lefty"
"rightx"
"righty"
"lefttrigger"
"righttrigger"
end
```

Expand All @@ -44,10 +46,8 @@ enum ButtonName
"dpup"
"leftshoulder"
"leftstick"
"lefttrigger"
"rightshoulder"
"rightstick"
"righttrigger"
"start"
"x"
"y"
Expand Down
13 changes: 0 additions & 13 deletions Site/docs/api/Class/Director.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,6 @@ const postScheduler: Scheduler
const currentCamera: Camera
```

## deltaTime

**Type:** Readonly Field.

**Description:**

&emsp;&emsp;The time in seconds since the last frame update.

**Signature:**
```tl
const deltaTime: number
```

## pushCamera

**Type:** Function.
Expand Down
2 changes: 1 addition & 1 deletion Site/docs/api/Class/YarnRunner.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
| 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. |
13 changes: 13 additions & 0 deletions Site/docs/api/Class/YarnRunner/TextResult.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,17 @@ text: string
**Signature:**
```tl
marks: nil | {Markup}
```

## optionsFollowed

**Type:** Field.

**Description:**

&emsp;&emsp;A flag indicating that advancing will yield an OptionResult as the next result.

**Signature:**
```tl
optionsFollowed: nil | boolean
```
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ const platform: Platform
const version: string
```

## deltaTime

**类型:** 只读成员变量。

**描述:**

&emsp;&emsp;自从上一帧游戏更新以来间隔的时间(以秒为单位)。

**签名:**
```tl
const deltaTime: number
```

## eclapsedTime

**类型:** 只读成员变量。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ enum AxisName
"lefty"
"rightx"
"righty"
"lefttrigger"
"righttrigger"
end
```

Expand All @@ -44,10 +46,8 @@ enum ButtonName
"dpup"
"leftshoulder"
"leftstick"
"lefttrigger"
"rightshoulder"
"rightstick"
"righttrigger"
"start"
"x"
"y"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,6 @@ const postScheduler: Scheduler
const currentCamera: Camera
```

## deltaTime

**类型:** 只读成员变量。

**描述:**

&emsp;&emsp;自从上一帧更新以来间隔的时间(以秒为单位)。

**签名:**
```tl
const deltaTime: number
```

## pushCamera

**类型:** 函数。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,17 @@ text: string
**签名:**
```tl
marks: nil | {Markup}
```

## optionsFollowed

**类型:** 成员变量。

**描述:**

&emsp;&emsp;表示下一个叙事推进得到的结果将为选项的标志。

**签名:**
```tl
optionsFollowed: nil | boolean
```
15 changes: 11 additions & 4 deletions Source/Lua/Yarn/YarnCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Dialog_t>(): {
transformDialog(static_cast<Dialog_t*>(stmt), temp);
auto next = it;
++next;
transformDialog(static_cast<Dialog_t*>(stmt), temp, next != stmts.end() && (*next)->get_id() == id<OptionGroup_t>());
temp.back() = indent() + "coroutine.yield(\"Dialog\", "s + temp.back() + ')' + nl(stmt);
break;
}
Expand Down Expand Up @@ -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<MarkupItem> markups;
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -1071,7 +1078,7 @@ class YarnCompiler {
incIndentOffset();
for (auto group : group->options.objects()) {
auto option = static_cast<Option_t*>(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) {
Expand Down

0 comments on commit dd10236

Please sign in to comment.