Skip to content

Commit

Permalink
add testing functions for yarn. [skip CI]
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Oct 11, 2023
1 parent 4a051eb commit ad08bc6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Assets/Script/Lib/YarnRunner.yue
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default class YarnRunner
stop: -> coroutine.yield "Stop"
...command
}
@command.<> = command.<>
@stories = {}
@visited = {}
@yarn = {
Expand Down Expand Up @@ -122,6 +123,8 @@ export default class YarnRunner
"Option", body
when "Goto"
@advance!
when "Command"
"Command", body
when "Error", "Stop"
@stories = {}
"Error", body
Expand Down
42 changes: 40 additions & 2 deletions Assets/Script/Test/Yarn.yue
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
_ENV = Dorothy!
_ENV = Dorothy builtin.ImGui
import "UI.Control.Basic.CircleButton"
import "YarnRunner"
import "UI.View.Shape.LineRect"
Expand Down Expand Up @@ -46,7 +46,11 @@ Director.entry\addChild with AlignNode isRoot: true, inUI: false
\addChild with control = AlignNode hAlign: "Center", vAlign: "Bottom"
.alignOffset = Vec2 0, 200

runner = YarnRunner "tutorial.yarn", "Start", {}, {}, true
commands = <index>: (name)=> (...)->
msg = "[command]: " .. name .. " " .. table.concat [tostring select i, ... for i = 1, select '#', ...], ", "
coroutine.yield "Command", msg

runner = YarnRunner "tutorial.yarn", "Start", {}, commands, true

menu = with Menu!
\addTo control
Expand Down Expand Up @@ -85,6 +89,9 @@ advance = (option)->
for i, op in ipairs result
texts[] = "[#{i}]: #{op.text}"
setButtons #result
when "Command"
texts[] = result
setButtons!
else
menu\removeAllChildren!
texts[] = result
Expand All @@ -94,3 +101,34 @@ advance = (option)->

advance!

testFiles = {"tutorial.yarn"}
files = {"tutorial.yarn"}
for file in *Content\getAllFiles Content.writablePath
continue if "yarn" ~= Path\getExt file
testFiles[] = Path Content.writablePath, file
files[] = Path\getFilename file

Director.entry\addChild with Node!
currentFile = 1
windowFlags =
* "NoDecoration"
* "NoSavedSettings"
* "NoFocusOnAppearing"
* "NoNav"
* "NoMove"
\schedule ->
const :width = App.visualSize
SetNextWindowPos Vec2(width - 10, 10), "Always", Vec2 1, 0
SetNextWindowSize Vec2(200, 0), "Always"
Begin "Yarn Test", windowFlags, ->
Text "Yarn Tester"
Separator!
changed, currentFile = Combo "File", currentFile, files
if changed
runner = YarnRunner testFiles[currentFile], "Start", {}, commands, true
texts = {}
advance!
Text "Variables"
Separator!
for k, v in pairs runner.state
Text "#{k}: #{v}"

0 comments on commit ad08bc6

Please sign in to comment.