From da0a6fcf0a362de3edccfab29fa877bb84727a7b Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Tue, 5 Apr 2016 15:37:27 +0100 Subject: [PATCH] Use fungus helper methods as globals or under 'fungus' global. --- Assets/Fungus/Lua/Resources/Lua/fungus.txt | 11 +- Assets/Fungus/Lua/Scripts/LuaStore.cs | 6 + Assets/Fungus/Lua/Scripts/LuaUtils.cs | 37 +++-- Assets/FungusExamples/Lua/Narrative.unity | 17 ++- Assets/FungusExamples/Lua/Trigger.unity | 34 +---- Assets/Tests/Lua/FungusTests.unity | 131 ++++++++++-------- Assets/Tests/Lua/LuaEnvironmentTests.unity | 131 +++++++++--------- .../StringSubstitutionTests.unity | 40 +++--- 8 files changed, 209 insertions(+), 198 deletions(-) diff --git a/Assets/Fungus/Lua/Resources/Lua/fungus.txt b/Assets/Fungus/Lua/Resources/Lua/fungus.txt index 4e730709..9b05218d 100644 --- a/Assets/Fungus/Lua/Resources/Lua/fungus.txt +++ b/Assets/Fungus/Lua/Resources/Lua/fungus.txt @@ -110,24 +110,25 @@ end -- Integration tests -------------------- --- Assert a condition is true (requires Unity Test Tools) -function M.assert(c, reason) +-- Checks if a condition is true (requires Unity Test Tools) +-- Lua has a built in assert function, so we called this check to avoid conflicting. +function M.check(c, reason) if (not c) then -- Output a traceback to help track down source error( debug.traceback("Assert failed", 2) ) end - fungus.test.assert(c, reason) + M.test.assert(c, reason) end -- Pass an integration test (requires Unity Test Tools) function M.pass() - fungus.test.pass() + M.test.pass() end -- Fail an integration test (requires Unity Test Tools) function M.fail(reason) error( debug.traceback("Test failed", 2) ) - fungus.test.fail(reason) + M.test.fail(reason) end ------------- diff --git a/Assets/Fungus/Lua/Scripts/LuaStore.cs b/Assets/Fungus/Lua/Scripts/LuaStore.cs index a538d342..d55fe633 100644 --- a/Assets/Fungus/Lua/Scripts/LuaStore.cs +++ b/Assets/Fungus/Lua/Scripts/LuaStore.cs @@ -90,6 +90,12 @@ namespace Fungus } fungusTable["store"] = primeTable; + + // If we're using the fungus module in globals mode then add the store to globals as well. + if (globals.Get("luaenvironment") != DynValue.Nil) + { + globals["store"] = primeTable; + } } } diff --git a/Assets/Fungus/Lua/Scripts/LuaUtils.cs b/Assets/Fungus/Lua/Scripts/LuaUtils.cs index fb64e81a..b07a62ca 100644 --- a/Assets/Fungus/Lua/Scripts/LuaUtils.cs +++ b/Assets/Fungus/Lua/Scripts/LuaUtils.cs @@ -15,12 +15,19 @@ namespace Fungus public class LuaUtils : LuaEnvironment.Initializer, StringSubstituter.ISubstitutionHandler { + public enum FungusModuleOptions + { + UseGlobalVariables, // Fungus helper items will be available as global variables. + UseFungusVariable, // Fungus helper items will be available in the 'fungus' global variable. + NoFungusModule // The fungus helper module will not be loaded. + } + /// - /// Create an instance of the 'fungus' utility Lua module. - /// This module provides useful utilities that can be accessed via the 'fungus' global table. + /// Controls if the fungus utilities are accessed from globals (e.g. say) or via a fungus variable (e.g. fungus.say)" + /// You can also choose to disable loading the fungus module if it's not required by your script. /// - [Tooltip("Create an instance of the 'fungus' utility Lua module.")] - public bool useFungusModule = true; + [Tooltip("Controls if the fungus utilities are accessed from globals (e.g. say) or via a fungus variable (e.g. fungus.say)")] + public FungusModuleOptions fungusModule = FungusModuleOptions.UseGlobalVariables; /// /// Lua script file which defines the global string table used for localisation. @@ -139,7 +146,7 @@ namespace Fungus /// protected virtual void InitFungusModule() { - if (!useFungusModule) + if (fungusModule == FungusModuleOptions.NoFungusModule) { return; } @@ -178,9 +185,23 @@ namespace Fungus fungusTable["test"] = UserData.CreateStatic(testType); } - // Example of how to register an enum - // UserData.RegisterType(); - // interpreter.Globals.Set("MyEnum", UserData.CreateStatic()); + if (fungusModule == FungusModuleOptions.UseGlobalVariables) + { + // Copy all items from the Fungus table to global variables + foreach (TablePair p in fungusTable.Pairs) + { + if (interpreter.Globals.Keys.Contains(p.Key)) + { + UnityEngine.Debug.LogError("Lua globals already contains a variable " + p.Key); + } + else + { + interpreter.Globals[p.Key] = p.Value; + } + } + + // Note: We can't remove the fungus table itself because of dependencies between functions + } } /// diff --git a/Assets/FungusExamples/Lua/Narrative.unity b/Assets/FungusExamples/Lua/Narrative.unity index e4eca926..a8f5ffcd 100644 --- a/Assets/FungusExamples/Lua/Narrative.unity +++ b/Assets/FungusExamples/Lua/Narrative.unity @@ -655,13 +655,11 @@ MonoBehaviour: executeMethods: 2 luaEnvironment: {fileID: 0} luaFile: {fileID: 0} - luaScript: "fungus.setsaydialog(saydialog)\nfungus.setmenudialog(menudialog)\n\nfunction - start()\n fungus.say \"Select an option\"\n\n fungus.menu(\"Option A\", optiona)\n - \ fungus.menu(\"Option B\", optionb)\nend\n\nfunction optiona()\n fungus.say(\"You - chose option a\")\nend\n\nfunction optionb()\n fungus.say(\"You chose option - b\")\nend\n\nstart()\n" + luaScript: "setsaydialog(saydialog)\nsetmenudialog(menudialog)\n\nfunction start()\n + \ say \"Select an option\"\n\n menu(\"Option A\", optiona)\n menu(\"Option + B\", optionb)\nend\n\nfunction optiona()\n say(\"You chose option a\")\nend\n\nfunction + optionb()\n say(\"You chose option b\")\nend\n\nstart()\n" runAsCoroutine: 1 - useFungusModule: 1 --- !u!4 &519026841 Transform: m_ObjectHideFlags: 0 @@ -1434,6 +1432,10 @@ Prefab: propertyPath: m_RootOrder value: 3 objectReference: {fileID: 0} + - target: {fileID: 11486636, guid: 49031c561e16d4fcf91c12153f8e0b25, type: 2} + propertyPath: fungusModule + value: 0 + objectReference: {fileID: 0} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: 49031c561e16d4fcf91c12153f8e0b25, type: 2} m_IsPrefabParent: 0 @@ -1781,6 +1783,8 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: tableName: + registerTypes: 1 + boundTypes: [] boundObjects: - key: saydialog obj: {fileID: 1531220777} @@ -1788,7 +1792,6 @@ MonoBehaviour: - key: menudialog obj: {fileID: 1851713324} component: {fileID: 1851713325} - boundTypes: [] --- !u!4 &1265440902 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/FungusExamples/Lua/Trigger.unity b/Assets/FungusExamples/Lua/Trigger.unity index 6134575f..8b356b29 100644 --- a/Assets/FungusExamples/Lua/Trigger.unity +++ b/Assets/FungusExamples/Lua/Trigger.unity @@ -369,7 +369,6 @@ GameObject: - 114: {fileID: 913136539} - 114: {fileID: 913136541} - 114: {fileID: 913136540} - - 114: {fileID: 913136542} m_Layer: 0 m_Name: Flowchart m_TagString: Untagged @@ -401,7 +400,7 @@ MonoBehaviour: y: -340 width: 1114 height: 859 - selectedBlock: {fileID: 0} + selectedBlock: {fileID: 913136541} selectedCommands: [] variables: [] description: 'This example shows how to execute a Block in a Flowchart via a @@ -464,30 +463,6 @@ MonoBehaviour: eventHandler: {fileID: 0} commandList: - {fileID: 913136540} - - {fileID: 913136542} ---- !u!114 &913136542 -MonoBehaviour: - m_ObjectHideFlags: 2 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 913136538} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: bc30c92f7ffe3d746ac76cd528d616e5, type: 3} - m_Name: - m_EditorClassIdentifier: - itemId: 2 - errorMessage: - indentLevel: 0 - control: 4 - _audioSource: - audioSourceRef: {fileID: 0} - audioSourceVal: {fileID: 0} - startVolume: 1 - endVolume: 1 - fadeDuration: 0 - waitUntilFinished: 0 - audioSourceOLD: {fileID: 0} --- !u!4 &913136543 Transform: m_ObjectHideFlags: 0 @@ -1254,14 +1229,13 @@ MonoBehaviour: executeMethods: 8192 luaEnvironment: {fileID: 0} luaFile: {fileID: 0} - luaScript: 'fungus.runblock(flowchart, "Start") + luaScript: 'runblock(flowchart, "Start") - fungus.setsaydialog(saydialog) + setsaydialog(saydialog) - fungus.say("Block is finished");' + say("Block is finished");' runAsCoroutine: 1 - useFungusModule: 1 --- !u!1001 &1575311449 Prefab: m_ObjectHideFlags: 0 diff --git a/Assets/Tests/Lua/FungusTests.unity b/Assets/Tests/Lua/FungusTests.unity index b7ed76e0..5bbddcdb 100644 --- a/Assets/Tests/Lua/FungusTests.unity +++ b/Assets/Tests/Lua/FungusTests.unity @@ -818,10 +818,10 @@ MonoBehaviour: -- Test Flowchart variable substitution - fungus.assert("{$StringVar}" == "it worked") + check("{$StringVar}" == "it worked") - fungus.pass()' + pass()' runAsCoroutine: 1 waitUntilFinished: 1 returnVariable: {fileID: 0} @@ -879,7 +879,7 @@ MonoBehaviour: variablesScrollPos: {x: 0, y: 0} variablesExpanded: 1 blockViewHeight: 400 - zoom: 0.9199953 + zoom: 1 scrollViewRect: serializedVersion: 2 x: -343 @@ -1205,28 +1205,28 @@ MonoBehaviour: s = flowchart.GetVariable("StringVar") - fungus.assert (s.value == "a string") + check (s.value == "a string") - t = fungus.gettime() + t = gettime() -- Execute a block to change the variable b = flowchart.FindBlock("Test Block") - fungus.runwait( b.Execute() ) + runwait( b.Execute() ) - fungus.assert(fungus.gettime() - t >= 1) + check(fungus.gettime() - t >= 1) -- Check the new value of StringVar - fungus.assert (s.value == "something") + check (s.value == "something") - fungus.pass()' + pass()' runAsCoroutine: 1 --- !u!1001 &130678264 Prefab: @@ -2273,7 +2273,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: c10f0b861365b42b0928858f7b086ff3, type: 3} m_Name: m_EditorClassIdentifier: - useFungusModule: 1 + fungusModule: 0 stringTable: {fileID: 0} activeLanguage: en timeScale: -1 @@ -2683,69 +2683,69 @@ MonoBehaviour: luaFile: {fileID: 0} luaScript: '-- The "Do Test" block in the flowchart sets a bunch of flowchart variables - fungus.runblock(flowchart, "Do Test") + runblock(flowchart, "Do Test") -- Check if the variables contain the expected values local bo = flowchart.GetVariable("BoolVar") - fungus.assert(bo.value) + check(bo.value) local f = flowchart.GetVariable("FloatVar") - fungus.assert(f.value == 1.0) + check(f.value == 1.0) local i = flowchart.GetVariable("IntVar") - fungus.assert(i.value == 2) + check(i.value == 2) local s = flowchart.GetVariable("StringVar") - fungus.assert(s.value == "a string") + check(s.value == "a string") local c = flowchart.GetVariable("ColorVar") - fungus.assert(c.value.r == 1) + check(c.value.r == 1) local go = flowchart.GetVariable("GameObjectVar") - fungus.assert(go.value == testgameobject) + check(go.value == testgameobject) local m = flowchart.GetVariable("MaterialVar") - fungus.assert(m.value == testmaterial) + check(m.value == testmaterial) local o = flowchart.GetVariable("ObjectVar") - fungus.assert(o.value == testgameobject) + check(o.value == testgameobject) local sp = flowchart.GetVariable("SpriteVar") - fungus.assert(sp.value == mushroom) + check(sp.value == mushroom) local t = flowchart.GetVariable("TextureVar") - fungus.assert(t.value == mousepointer) + check(t.value == mousepointer) local v2 = flowchart.GetVariable("Vector2Var") - fungus.assert(v2.value.y == 1) + check(v2.value.y == 1) local v3 = flowchart.GetVariable("Vector3Var") - fungus.assert(v3.value.z == 1) + check(v3.value.z == 1) fungus.pass()' @@ -3064,9 +3064,8 @@ MonoBehaviour: executeMethods: 2 luaEnvironment: {fileID: 0} luaFile: {fileID: 0} - luaScript: "fungus.menuoptions.menudialog = menudialog\n\nfunction option1()\n fungus.fail()\nend\n\nfungus.menu(\"Option - 1\", option1)\n\nfungus.assert(optionbutton0.activeSelf)\nfungus.clearmenu()\nfungus.assert(not - optionbutton0.activeSelf)\n\nfungus.pass()" + luaScript: "menuoptions.menudialog = menudialog\n\nfunction option1()\n fail()\nend\n\nmenu(\"Option + 1\", option1)\n\ncheck(optionbutton0.activeSelf)\nclearmenu()\nassert(not optionbutton0.activeSelf)\n\npass()" runAsCoroutine: 1 --- !u!1 &511430244 GameObject: @@ -3117,11 +3116,10 @@ MonoBehaviour: executeMethods: 2 luaEnvironment: {fileID: 0} luaFile: {fileID: 0} - luaScript: "-- Test the Menu Timer functionality\n\nfungus.menuoptions.menudialog - = menudialog\n\n-- Called if user clicks on menu option\nfunction option1()\n - \ fungus.pass()\nend\n\n-- Called if timeout expires\nfunction timeout()\n -- - Test coroutine is ok\n fungus.wait(1)\n fungus.pass()\nend\n\n-- Display a - menu option with a timer\nfungus.menu(\"Option 1\", option1)\nfungus.menutimer(1, + luaScript: "-- Test the Menu Timer functionality\n\nmenuoptions.menudialog = menudialog\n\n-- + Called if user clicks on menu option\nfunction option1()\n pass()\nend\n\n-- + Called if timeout expires\nfunction timeout()\n -- Test coroutine is ok\n wait(1)\n + \ pass()\nend\n\n-- Display a menu option with a timer\nmenu(\"Option 1\", option1)\nmenutimer(1, timeout)\n" runAsCoroutine: 1 --- !u!1 &560555132 @@ -4398,12 +4396,11 @@ MonoBehaviour: executeMethods: 2 luaEnvironment: {fileID: 0} luaFile: {fileID: 0} - luaScript: "-- Test Say creating a SayDialog when none already exists\n\nfungus.sayoptions.waitforinput - = false\nfungus.say(\"test\")\n\ngo = fungus.luautils.find(\"SayDialog\")\nfungus.assert(go - != nil)\n\n-- Test Menu creating a MenuDialog when none already exists\nfunction - choose_a()\n fungus.pass()\nend\n\nfungus.menu(\"Option A\", choose_a)\n\nlocal - go = fungus.luautils.find(\"OptionButton0\")\nfungus.assert(go != nil)\n\nlocal - button = go.GetComponent(\"Button\")\nfungus.assert(button != nil)\n\nbutton.onClick.Invoke()" + luaScript: "-- Test Say creating a SayDialog when none already exists\n\nsayoptions.waitforinput + = false\nsay(\"test\")\n\ngo = luautils.find(\"SayDialog\")\ncheck(go != nil)\n\n-- + Test Menu creating a MenuDialog when none already exists\nfunction choose_a()\n + \ pass()\nend\n\nmenu(\"Option A\", choose_a)\n\nlocal go = luautils.find(\"OptionButton0\")\ncheck(go + != nil)\n\nlocal button = go.GetComponent(\"Button\")\ncheck(button != nil)\n\nbutton.onClick.Invoke()" runAsCoroutine: 1 --- !u!1 &851680338 GameObject: @@ -4529,25 +4526,25 @@ MonoBehaviour: flowchart.SetBooleanVariable("BoolVar", true) - fungus.assert(flowchart.GetBooleanVariable("BoolVar")) + check(flowchart.GetBooleanVariable("BoolVar")) flowchart.SetFloatVariable("FloatVar", 1) - fungus.assert(flowchart.GetFloatVariable("FloatVar") == 1) + check(flowchart.GetFloatVariable("FloatVar") == 1) flowchart.SetIntegerVariable("IntVar", 1) - fungus.assert(flowchart.GetIntegerVariable("IntVar") == 1) + check(flowchart.GetIntegerVariable("IntVar") == 1) flowchart.SetStringVariable("StringVar", "a") - fungus.assert(flowchart.GetStringVariable("StringVar") == "a") + check(flowchart.GetStringVariable("StringVar") == "a") - fungus.pass()' + pass()' runAsCoroutine: 1 --- !u!1 &863130402 GameObject: @@ -5070,7 +5067,22 @@ MonoBehaviour: m_EditorClassIdentifier: tableName: registerTypes: 1 - boundTypes: [] + boundTypes: + - UnityEngine.GameObject, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + - UnityEngine.PrimitiveType, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + - UnityEngine.Component, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + - System.Type, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + - System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + - System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + - UnityEngine.SendMessageOptions, UnityEngine, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + - UnityEngine.SceneManagement.Scene, UnityEngine, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + - UnityEngine.Object, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + - System.Single, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + - Fungus.MenuDialog, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + - Fungus.Block, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + - UnityEngine.UI.Slider, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null boundObjects: - key: menudialog obj: {fileID: 1077682782} @@ -5078,9 +5090,6 @@ MonoBehaviour: - key: optionbutton0 obj: {fileID: 1312420724} component: {fileID: 0} - - key: - obj: {fileID: 0} - component: {fileID: 0} --- !u!1 &928936324 GameObject: m_ObjectHideFlags: 0 @@ -6431,7 +6440,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!114 &1109996700 MonoBehaviour: m_ObjectHideFlags: 0 @@ -7796,10 +7805,9 @@ MonoBehaviour: executeMethods: 2 luaEnvironment: {fileID: 0} luaFile: {fileID: 0} - luaScript: "-- Test the Menu Timer functionality\n\nfungus.menuoptions.menudialog - = menudialog\n\n-- Called if user clicks on menu option\nfunction option1()\n - \ fungus.pass()\nend\n\n-- Display a menu option with a timer\nfungus.menu(\"Option - 1\", option1)\n\noptionbutton0.onClick.Invoke()\n" + luaScript: "-- Test the Menu Timer functionality\n\nmenuoptions.menudialog = menudialog\n\n-- + Called if user clicks on menu option\nfunction option1()\n pass()\nend\n\n-- + Display a menu option with a timer\nmenu(\"Option 1\", option1)\n\noptionbutton0.onClick.Invoke()\n" runAsCoroutine: 1 --- !u!1 &1667495163 GameObject: @@ -8878,29 +8886,30 @@ MonoBehaviour: -- Make say dialog active - fungus.setsaydialog(saydialog) + setsaydialog(saydialog) - fungus.sayoptions.waitforinput = false + sayoptions.waitforinput = false -- Select active character - fungus.setcharacter(john, "Mushroom") + setcharacter(john, "Mushroom") - fungus.say ("voiceover{w=3}", voiceover) + say ("voiceover{w=3}", voiceover) -- Test say command with a tag and global variable substitution - fungus.say "Alrighty{w=1} how do {$score}?" + say "Alrighty{w=1} how do {$score}?" + + check(nametext.text == "John 10") - fungus.assert(nametext.text == "John 10") + check(storytext.text == "Alrighty how do 10?") - fungus.assert(storytext.text == "Alrighty how do 10?") - fungus.pass() + pass() ' @@ -9559,9 +9568,9 @@ MonoBehaviour: go = transform.FindChild("Mushroom") - fungus.assert(go.name == "Mushroom") + check(go.name == "Mushroom") - fungus.pass()' + pass()' runAsCoroutine: 1 --- !u!1 &2087053783 GameObject: diff --git a/Assets/Tests/Lua/LuaEnvironmentTests.unity b/Assets/Tests/Lua/LuaEnvironmentTests.unity index 19c99b1a..8cc40dcc 100644 --- a/Assets/Tests/Lua/LuaEnvironmentTests.unity +++ b/Assets/Tests/Lua/LuaEnvironmentTests.unity @@ -142,7 +142,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!114 &47556548 MonoBehaviour: m_ObjectHideFlags: 0 @@ -177,7 +177,7 @@ Transform: - {fileID: 385045793} - {fileID: 1309386183} m_Father: {fileID: 0} - m_RootOrder: 1 + m_RootOrder: 3 --- !u!1 &113453955 GameObject: m_ObjectHideFlags: 0 @@ -228,17 +228,17 @@ MonoBehaviour: executeMethods: 2 luaEnvironment: {fileID: 0} luaFile: {fileID: 0} - luaScript: 'fungus.assert(dummycollection.stringList[1] == "hi") + luaScript: 'check(dummycollection.stringList[1] == "hi") - fungus.assert(dummycollection.stringList[2] == "there") + check(dummycollection.stringList[2] == "there") - fungus.assert(dummycollection.spriteList[1].name == "angry") + check(dummycollection.spriteList[1].name == "angry") - fungus.assert(dummycollection.spriteList[2].name == "annoyed") + check(dummycollection.spriteList[2].name == "annoyed") - fungus.pass() + pass() ' runAsCoroutine: 1 @@ -409,10 +409,9 @@ MonoBehaviour: luaEnvironment: {fileID: 0} luaFile: {fileID: 0} luaScript: "-- Test the timeout works in fungus.waitfor\nlocal value = false\n\nfunction - fn()\n return value\nend\n\nt = fungus.gettime()\nfungus.waitfor(fn, 1)\nfungus.assert - (fungus.gettime() - t >= 1)\n\n-- Test fungus.waitfor() exits if the function - returns true\n-- If this doesn't work the test will timeout and fail\nvalue = - true\nfungus.waitfor(fn, 1)\n\nfungus.pass()" + fn()\n return value\nend\n\nt = gettime()\nwaitfor(fn, 1)\ncheck(gettime() - + t >= 1)\n\n-- Test fungus.waitfor() exits if the function returns true\n-- If + this doesn't work the test will timeout and fail\nvalue = true\nwaitfor(fn, 1)\n\npass()" runAsCoroutine: 1 --- !u!1001 &364012152 Prefab: @@ -554,7 +553,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: c10f0b861365b42b0928858f7b086ff3, type: 3} m_Name: m_EditorClassIdentifier: - useFungusModule: 1 + fungusModule: 0 stringTable: {fileID: 0} activeLanguage: en timeScale: -1 @@ -717,20 +716,20 @@ MonoBehaviour: luaFile: {fileID: 0} luaScript: '-- Test storing persistant data - fungus.prefs.DeleteAll() + prefs.DeleteAll() - fungus.prefs.SetFloat(0, "speed", 10) + prefs.SetFloat(0, "speed", 10) - local speed = fungus.prefs.GetFloat(0, "speed") + local speed = prefs.GetFloat(0, "speed") - fungus.prefs.DeleteAll() + prefs.DeleteAll() - fungus.assert(speed == 10) + check(speed == 10) - fungus.pass() + pass() ' @@ -785,7 +784,7 @@ Transform: - {fileID: 2093904138} - {fileID: 681659774} m_Father: {fileID: 0} - m_RootOrder: 5 + m_RootOrder: 7 --- !u!1 &804588883 GameObject: m_ObjectHideFlags: 0 @@ -852,7 +851,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 6 + m_RootOrder: 1 --- !u!1001 &1073733979 Prefab: m_ObjectHideFlags: 0 @@ -966,38 +965,38 @@ MonoBehaviour: -- Should take 1 second in realtime to wait for 1 second - t = fungus.gettime() + t = gettime() - fungus.wait(1) + wait(1) - t = fungus.gettime() - t + t = gettime() - t - fungus.assert(t >= 1) + check(t >= 1) -- Wait with timeScale = 0.5 -- Should take 2 seconds in realtime to wait for 1 second - fungus.settimescale(0.5) + settimescale(0.5) - t = fungus.gettime() + t = gettime() - fungus.wait(1) + wait(1) - t = fungus.gettime() - t + t = gettime() - t - fungus.assert(t >= 1) + check(t >= 1) -- The real elapsed time should be 3 seconds - elapsed = (fungus.time.time - timer) + elapsed = (time.time - timer) - assert(elapsed >= 3) + check(elapsed >= 3) - fungus.pass()' + pass()' runAsCoroutine: 1 --- !u!4 &1167396341 stripped Transform: @@ -1153,7 +1152,9 @@ MonoBehaviour: local f = require(''fungus'') - f.pass()' + check(f.say != nil) + + pass()' runAsCoroutine: 1 --- !u!1 &1394431693 GameObject: @@ -1282,7 +1283,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: c10f0b861365b42b0928858f7b086ff3, type: 3} m_Name: m_EditorClassIdentifier: - useFungusModule: 1 + fungusModule: 0 stringTable: {fileID: 0} activeLanguage: en timeScale: -1 @@ -1366,7 +1367,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!114 &1532103953 MonoBehaviour: m_ObjectHideFlags: 0 @@ -1401,7 +1402,7 @@ Transform: - {fileID: 1855619326} - {fileID: 1738134228} m_Father: {fileID: 0} - m_RootOrder: 3 + m_RootOrder: 5 --- !u!1 &1537199680 GameObject: m_ObjectHideFlags: 0 @@ -1567,7 +1568,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 7 + m_RootOrder: 2 --- !u!1 &1738134227 GameObject: m_ObjectHideFlags: 0 @@ -1619,21 +1620,21 @@ MonoBehaviour: luaFile: {fileID: 0} luaScript: '-- Test string table localisation system - fungus.assert(fungus.stringtable != nil) + check(fungus.stringtable != nil) -- Check string table loaded ok - fungus.assert(fungus.stringtable.hello.en == "Hi there") + check(fungus.stringtable.hello.en == "Hi there") - fungus.assert(fungus.stringtable.hello.fr == "Bonjour") + check(fungus.stringtable.hello.fr == "Bonjour") -- Check getstring() local g = fungus.getstring("hello") - fungus.assert(g == "Hi there") + check(g == "Hi there") -- Test substituting a global value @@ -1642,26 +1643,26 @@ MonoBehaviour: local s = fungus.sub("should be {$t}") - fungus.assert(s == "should be 3") + check(s == "should be 3") -- Test substituting a string table value (en) s = fungus.sub("say {$hello}") - fungus.assert(s == "say Hi there") + check(s == "say Hi there") -- Test substituting a string table value (fr) - fungus.setlanguage("fr") + setlanguage("fr") - s = fungus.sub("say {$hello}") + s = sub("say {$hello}") - fungus.assert(s == "say Bonjour") + check(s == "say Bonjour") - fungus.pass()' + pass()' runAsCoroutine: 1 --- !u!1 &1818482578 GameObject: @@ -1714,9 +1715,9 @@ MonoBehaviour: luaFile: {fileID: 0} luaScript: '-- Test if object binding works - fungus.assert (dummy != nil) + assert (dummy != nil) - fungus.pass() + pass() ' runAsCoroutine: 1 @@ -1756,7 +1757,7 @@ MonoBehaviour: variablesScrollPos: {x: 0, y: 0} variablesExpanded: 1 blockViewHeight: 400 - zoom: 0.983999 + zoom: 1 scrollViewRect: serializedVersion: 2 x: -343 @@ -1791,13 +1792,13 @@ MonoBehaviour: errorMessage: indentLevel: 0 luaEnvironment: {fileID: 0} - luaScript: 'fungus.store.test = "ok" + luaScript: 'store.test = "ok" - fungus.assert(fungus.store.test == "ok") + check(store.test == "ok") - fungus.pass()' + pass()' runAsCoroutine: 1 waitUntilFinished: 1 returnVariable: {fileID: 0} @@ -1955,7 +1956,7 @@ Transform: - {fileID: 364012153} - {fileID: 1124932172} m_Father: {fileID: 0} - m_RootOrder: 4 + m_RootOrder: 6 --- !u!1 &1932132173 GameObject: m_ObjectHideFlags: 0 @@ -2009,35 +2010,35 @@ MonoBehaviour: luaScript: '-- Test GameObject methods like find, instantiate, spawn, etc. - testgo = fungus.luautils.find("TestGameObject") + testgo = luautils.find("TestGameObject") - fungus.assert(testgo != null) + check(testgo != null) - go = fungus.luautils.instantiate(testgo) + go = luautils.instantiate(testgo) - fungus.assert(go != null) + check(go != null) go.name = "fred" - fungus.assert(go.name == "fred") + check(go.name == "fred") - fungus.luautils.destroy(go) + luautils.destroy(go) -- Spawn an object from a prefab in a Resources folder - saydialog = fungus.luautils.spawn("SayDialog") + saydialog = luautils.spawn("SayDialog") - fungus.assert(saydialog != nil) + check(saydialog != nil) - fungus.luautils.destroy(saydialog) + luautils.destroy(saydialog) - fungus.pass()' + pass()' runAsCoroutine: 1 --- !u!1 &1960220030 GameObject: @@ -2091,7 +2092,7 @@ Transform: - {fileID: 2101848761} - {fileID: 1818482579} m_Father: {fileID: 0} - m_RootOrder: 2 + m_RootOrder: 4 --- !u!1001 &2076961667 Prefab: m_ObjectHideFlags: 0 diff --git a/Assets/Tests/StringSubstitution/StringSubstitutionTests.unity b/Assets/Tests/StringSubstitution/StringSubstitutionTests.unity index fbc4e530..3dd694f6 100644 --- a/Assets/Tests/StringSubstitution/StringSubstitutionTests.unity +++ b/Assets/Tests/StringSubstitution/StringSubstitutionTests.unity @@ -126,6 +126,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: c10f0b861365b42b0928858f7b086ff3, type: 3} m_Name: m_EditorClassIdentifier: + fungusModule: 0 stringTable: {fileID: 4900000, guid: 9900570d789fa4b29957e4b897af9e3b, type: 3} activeLanguage: en timeScale: -1 @@ -321,18 +322,14 @@ MonoBehaviour: -- Test localisation value subsitution - subbed = fungus.sub("{$SETTEXT.Flowchart.6}") + subbed = sub("{$SETTEXT.Flowchart.6}") - print (subbed) + check (subbed == "English text") - fungus.assert (subbed == "English text") - - - fungus.pass() + pass() ' runAsCoroutine: 1 - useFungusModule: 1 --- !u!1 &545923887 GameObject: m_ObjectHideFlags: 0 @@ -556,6 +553,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: c10f0b861365b42b0928858f7b086ff3, type: 3} m_Name: m_EditorClassIdentifier: + fungusModule: 0 stringTable: {fileID: 0} activeLanguage: en timeScale: -1 @@ -1101,6 +1099,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: c10f0b861365b42b0928858f7b086ff3, type: 3} m_Name: m_EditorClassIdentifier: + fungusModule: 0 stringTable: {fileID: 0} activeLanguage: en timeScale: -1 @@ -1174,21 +1173,20 @@ MonoBehaviour: -- Private variable should not substitute - subbed = fungus.sub("{$StringVarA}") + subbed = sub("{$StringVarA}") - fungus.assert(subbed == "{$StringVarA}") + check(subbed == "{$StringVarA}") -- Public variable should substitute - subbed = fungus.sub("{$StringVarB}") + subbed = sub("{$StringVarB}") - fungus.assert (subbed == "Ok") + check (subbed == "Ok") fungus.pass()' runAsCoroutine: 1 - useFungusModule: 1 --- !u!1 &1532141878 GameObject: m_ObjectHideFlags: 0 @@ -1313,13 +1311,11 @@ MonoBehaviour: luaEnvironment: {fileID: 0} luaFile: {fileID: 0} luaScript: "local subbed = \"\"\n\n-- Test global variable subsitution\nglobalname - = \"Fred\"\nsubbed = fungus.sub(\"{$globalname}\")\nfungus.assert (subbed == \"Fred\")\n\n-- - Test English string table entry\nsubbed = fungus.sub(\"{$hello}\")\nfungus.assert(subbed - == \"Hi there\")\n\n-- Test French string table entry\nfungus.setlanguage(\"fr\")\nsubbed - = fungus.sub(\"{$hello}\")\nfungus.assert(subbed == \"Bonjour\")\n\n-- Global - \n\nfungus.pass()\n" + = \"Fred\"\nsubbed = sub(\"{$globalname}\")\ncheck (subbed == \"Fred\")\n\n-- + Test English string table entry\nsubbed = sub(\"{$hello}\")\ncheck(subbed == \"Hi + there\")\n\n-- Test French string table entry\nsetlanguage(\"fr\")\nsubbed = sub(\"{$hello}\")\ncheck(subbed + == \"Bonjour\")\n\n-- Global \n\npass()\n" runAsCoroutine: 1 - useFungusModule: 1 --- !u!1 &1563984262 GameObject: m_ObjectHideFlags: 0 @@ -1492,6 +1488,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: c10f0b861365b42b0928858f7b086ff3, type: 3} m_Name: m_EditorClassIdentifier: + fungusModule: 0 stringTable: {fileID: 0} activeLanguage: en timeScale: -1 @@ -1648,15 +1645,14 @@ MonoBehaviour: -- Wait for the Write command to complete - fungus.wait(0.5) + wait(0.5) - fungus.assert(text.text == "ABC") + check(text.text == "ABC") - fungus.pass()' + pass()' runAsCoroutine: 1 - useFungusModule: 1 --- !u!1 &2135590527 GameObject: m_ObjectHideFlags: 0