Skip to content

Commit

Permalink
folder cleanup - completed samples - less debug noise
Browse files Browse the repository at this point in the history
  • Loading branch information
kkukshtel committed Feb 13, 2022
1 parent 094f987 commit 1e56d8d
Show file tree
Hide file tree
Showing 24 changed files with 5,736 additions and 23 deletions.
Binary file modified Squiggle.Test/Squiggle.dll
Binary file not shown.
14 changes: 11 additions & 3 deletions Squiggle.Unity/Assembly-CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,17 @@
<ImplicitlyExpandDesignTimeFacades>false</ImplicitlyExpandDesignTimeFacades>
</PropertyGroup>
<ItemGroup>
<Compile Include="Assets\Squiggle\Sample Scenes\ScriptableObject\ScriptableObjectSample.cs" />
<Compile Include="Assets\Squiggle\Sample Scenes\ScriptableObject\SquiggleScriptableObject.cs" />
<Compile Include="Assets\Squiggle\Sample Scenes\TextBox\SquiggleTextBoxSample.cs" />
<Compile Include="Assets\Squiggle\Common\SquiggleUnityRunner.cs" />
<Compile Include="Assets\Squiggle\Common\SquiggleUtils.cs" />
<Compile Include="Assets\Squiggle\Sample Scenes\1 - Monobehaviour\SquiggleMonobehaviourSample.cs" />
<Compile Include="Assets\Squiggle\Sample Scenes\2 -TextBox\SquiggleTextBoxSample.cs" />
<Compile Include="Assets\Squiggle\Sample Scenes\3 - ScriptableObject\ScriptableObjectSample.cs" />
<Compile Include="Assets\Squiggle\Sample Scenes\3 - ScriptableObject\SquiggleScriptableObject.cs" />
<Compile Include="Assets\Squiggle\Sample Scenes\4 - StreamingAssetsSample\SquiggleStreamingAssetsSample.cs" />
<Compile Include="Assets\Squiggle\Sample Scenes\5 - DialogProgressionSample\SquiggleDialogProgressionSample.cs" />
<Compile Include="Assets\Squiggle\Sample Scenes\6 - CustomCommand\SquiggleCustomCommandSample.cs" />
<None Include="Assets\StreamingAssets\dialogProgressionSample.txt" />
<None Include="Assets\StreamingAssets\customCommandSample.txt" />
<None Include="Assets\StreamingAssets\sampleSquiggleScript.txt" />
<Reference Include="UnityEngine">
<HintPath>C:/Program Files/Unity/Hub/Editor/2019.4.8f1/Editor/Data/Managed/UnityEngine/UnityEngine.dll</HintPath>
Expand Down
20 changes: 20 additions & 0 deletions Squiggle.Unity/Assets/Squiggle/Common/SquiggleUnityRunner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using UnityEngine;

public class SquiggleUnityRunner : MonoBehaviour
{

}
// public class Runner : MonoBehaviour
// {

// }
// public static void UnityWaitOverride(Squiggle.Commands.Wait waitCommand)
// {
// StartCoroutine(WaitMs(waitCommand));
// }

// static IEnumerator WaitMs(Squiggle.Commands.Wait waitCommand)
// {
// yield return new WaitForSeconds(waitCommand.WaitMS / 1000f);
// waitCommand.CommandExecutionComplete?.Invoke();
// }
48 changes: 48 additions & 0 deletions Squiggle.Unity/Assets/Squiggle/Common/SquiggleUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.EventSystems;
using System.IO;

namespace Squiggle.Unity
{
public static class Utils
{
public static string ReadTextFileFromStreamingAssets(string sFileName)
{
//Debug.Log("Reading " + sFileName);
//Check to see if the filename specified exists, if not try adding '.txt', otherwise fail
string sFileNameFound = "";
if (File.Exists(Application.streamingAssetsPath + "/" + sFileName))
{
//Debug.Log("Reading '" + sFileName + "'.");
sFileNameFound = Application.streamingAssetsPath + "/" + sFileName; //file found
}
else if (File.Exists(Application.streamingAssetsPath + "/" + sFileName + ".txt"))
{
sFileNameFound = Application.streamingAssetsPath + "/" + sFileName + ".txt";
}
else
{
Debug.Log("Could not find file '" + sFileName + "'.");
return null;
}

StreamReader sr;
try
{
sr = new StreamReader(sFileNameFound);
}
catch (System.Exception e)
{
Debug.LogWarning("Something went wrong with read. " + e.Message);
return null;
}

string fileContents = sr.ReadToEnd();
sr.Close();

return fileContents;
}
}
}
Binary file modified Squiggle.Unity/Assets/Squiggle/Plugins/Squiggle.dll
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using Squiggle;

public class SquiggleMonobehaviourSample : MonoBehaviour
{
public Text SpeakerName;
public Text SpeakerText;
public Button RunSquiggle;
[TextArea]
public string SquiggleCode;
void OnEnable()
{
SpeakerName.text = "";
SpeakerText.text = "";

RunSquiggle.onClick.AddListener(() => {
EventSystem.current.SetSelectedGameObject(null);
StartCoroutine(TryExecuteSquiggle());
});
}
void OnDisable()
{
RunSquiggle.onClick.RemoveAllListeners();
}

Squiggle.Runner currentRunner;
bool currentlyRunning = false;
IEnumerator TryExecuteSquiggle()
{
if(currentlyRunning)
{
yield return null;
}

currentlyRunning = true;
currentRunner = Squiggle.Core.Run( squiggleText : SquiggleCode,
runnerOptions : new Squiggle.Runner.Options(){
AutoStart = false,
Debug = true,
LogHandler = (text) => Debug.Log(text),
WaitOverride = (command) => StartCoroutine(WaitMs(command)),
DialogHandler = (command) => {
SpeakerName.text = command.Speaker;
SpeakerText.text = command.Text;
command.CommandExecutionComplete?.Invoke();
},
});

currentRunner.CompletedExecution += OnRunnerComplete;
currentRunner.Start();
yield return null;
}

IEnumerator WaitMs(Squiggle.Commands.Wait waitCommand)
{
Debug.Log("inside wait ms");
yield return new WaitForSeconds(waitCommand.WaitMS / 1000f);
waitCommand.CommandExecutionComplete?.Invoke();
}

void OnRunnerComplete()
{
currentRunner.CompletedExecution -= OnRunnerComplete;
currentRunner = null;
currentlyRunning = false;
SpeakerName.text = "";
SpeakerText.text = "";
}
}
Loading

0 comments on commit 1e56d8d

Please sign in to comment.