-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'disallow-cross-stitch-temps'
- Loading branch information
Showing
99 changed files
with
1,926 additions
and
1,082 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,285 @@ | ||
using System; | ||
using System.IO; | ||
using System.Collections.Generic; | ||
using Ink; | ||
|
||
|
||
class InkTestBed : IFileHandler | ||
{ | ||
// --------------------------------------------------------------- | ||
// Main area to test stuff! | ||
// --------------------------------------------------------------- | ||
|
||
void Run () | ||
{ | ||
Play (); | ||
} | ||
|
||
// --------------------------------------------------------------- | ||
// Useful functions when testing | ||
// --------------------------------------------------------------- | ||
|
||
// Full play loop | ||
void Play () | ||
{ | ||
if (story == null) CompileFile ("test.ink"); | ||
|
||
// Errors to the extent that story couldn't be constructed? | ||
if (story == null) return; | ||
|
||
while (story.canContinue || story.currentChoices.Count > 0) { | ||
if (story.canContinue) | ||
ContinueMaximally (); | ||
|
||
PrintAllMessages (); | ||
|
||
if (story.currentChoices.Count > 0) | ||
PlayerChoice (); | ||
} | ||
} | ||
|
||
void Continue () | ||
{ | ||
Console.WriteLine(story.Continue ()); | ||
PrintChoicesIfNecessary (); | ||
PrintAllMessages (); // errors etc | ||
} | ||
|
||
void ContinueMaximally () | ||
{ | ||
Console.WriteLine (story.ContinueMaximally ()); | ||
PrintChoicesIfNecessary (); | ||
PrintAllMessages (); // errors etc | ||
} | ||
|
||
void Choose (int choiceIdx) | ||
{ | ||
story.ChooseChoiceIndex (choiceIdx); | ||
} | ||
|
||
void PlayerChoice () | ||
{ | ||
bool hasValidChoice = false; | ||
int choiceIndex = -1; | ||
|
||
while (!hasValidChoice) { | ||
Console.Write (">>> "); | ||
|
||
string userInput = Console.ReadLine (); | ||
|
||
if (userInput == null) | ||
throw new System.Exception ("<User input stream closed.>"); | ||
|
||
int choiceNum; | ||
if (int.TryParse (userInput, out choiceNum)) { | ||
choiceIndex = choiceNum - 1; | ||
|
||
if (choiceIndex >= 0 && choiceIndex < story.currentChoices.Count) { | ||
hasValidChoice = true; | ||
} else { | ||
Console.WriteLine ("Choice out of range"); | ||
} | ||
} else { | ||
Console.WriteLine ("Not a number"); | ||
} | ||
} | ||
|
||
story.ChooseChoiceIndex (choiceIndex); | ||
} | ||
|
||
Ink.Runtime.Story Compile (string inkSource) | ||
{ | ||
var compiler = new Compiler (inkSource, new Compiler.Options { | ||
countAllVisits = true, | ||
errorHandler = OnError, | ||
fileHandler = this | ||
}); | ||
|
||
story = compiler.Compile (); | ||
|
||
PrintAllMessages (); | ||
|
||
return story; | ||
} | ||
|
||
|
||
Ink.Runtime.Story CompileFile (string filename = null) | ||
{ | ||
if (filename == null) filename = "test.ink"; | ||
var inkSource = File.ReadAllText (filename); | ||
|
||
var compiler = new Compiler (inkSource, new Compiler.Options { | ||
sourceFilename = filename, | ||
countAllVisits = true, | ||
errorHandler = OnError, | ||
fileHandler = this | ||
}); | ||
|
||
story = compiler.Compile (); | ||
|
||
PrintAllMessages (); | ||
|
||
return story; | ||
} | ||
|
||
void JsonRoundtrip () | ||
{ | ||
var jsonStr = story.ToJsonString (); | ||
Console.WriteLine (jsonStr); | ||
|
||
Console.WriteLine ("---------------------------------------------------"); | ||
|
||
var reloadedStory = new Ink.Runtime.Story (jsonStr); | ||
var newJsonStr = reloadedStory.ToJsonString (); | ||
Console.WriteLine (newJsonStr); | ||
|
||
story = reloadedStory; | ||
} | ||
|
||
// e.g.: | ||
// | ||
// Hello world | ||
// + choice | ||
// done! | ||
// -> END | ||
// | ||
// ------ SECOND INK VERSION ------ | ||
// | ||
// Hello world | ||
// + choice | ||
// done! | ||
// -> END | ||
// | ||
void SplitFile (string filename, out string ink1, out string ink2) | ||
{ | ||
const string splitStr = "------ SECOND INK VERSION ------"; | ||
|
||
var fullSource = File.ReadAllText (filename); | ||
|
||
var idx = fullSource.IndexOf (splitStr, StringComparison.InvariantCulture); | ||
if (idx == -1) | ||
throw new System.Exception ("Split point not found in " + filename); | ||
|
||
ink1 = fullSource.Substring (0, idx); | ||
ink2 = fullSource.Substring (idx + splitStr.Length); | ||
} | ||
|
||
// e.g.: | ||
// | ||
// InkChangingTest (() => { | ||
// ContinueMaximally (); | ||
// story.ChooseChoiceIndex (0); | ||
// }, () => { | ||
// ContinueMaximally (); | ||
// }); | ||
// | ||
void InkChangingTest (Action test1, Action test2) | ||
{ | ||
string ink1, ink2; | ||
|
||
SplitFile ("test.ink", out ink1, out ink2); | ||
|
||
var story1 = Compile (ink1); | ||
|
||
test1 (); | ||
|
||
var saveState = story1.state.ToJson (); | ||
|
||
Console.WriteLine ("------ SECOND INK VERSION ------"); | ||
|
||
var story2 = Compile (ink2); | ||
|
||
story2.state.LoadJson (saveState); | ||
|
||
test2 (); | ||
} | ||
|
||
// --------------------- | ||
|
||
public Ink.Runtime.Story story; | ||
|
||
public InkTestBed () { } | ||
|
||
public static void Main (string [] args) | ||
{ | ||
new InkTestBed ().Run (); | ||
|
||
Console.WriteLine (">>> TEST BED ENDED <<<"); | ||
} | ||
|
||
void PrintMessages (List<string> messageList, ConsoleColor colour) | ||
{ | ||
Console.ForegroundColor = colour; | ||
|
||
foreach (string msg in messageList) { | ||
Console.WriteLine (msg); | ||
} | ||
|
||
Console.ResetColor (); | ||
} | ||
|
||
void PrintAllMessages () | ||
{ | ||
PrintMessages (_authorMessages, ConsoleColor.Green); | ||
PrintMessages (_warnings, ConsoleColor.Blue); | ||
PrintMessages (_errors, ConsoleColor.Red); | ||
|
||
_authorMessages.Clear (); | ||
_warnings.Clear (); | ||
_errors.Clear (); | ||
|
||
if (story != null) { | ||
if( story.hasError ) | ||
PrintMessages (story.currentErrors, ConsoleColor.Red); | ||
if( story.hasWarning ) | ||
PrintMessages (story.currentWarnings, ConsoleColor.Blue); | ||
story.ResetErrors (); | ||
} | ||
} | ||
|
||
void PrintChoicesIfNecessary () | ||
{ | ||
if (!story.canContinue && story.currentChoices != null) { | ||
|
||
int number = 1; | ||
foreach (var c in story.currentChoices) { | ||
Console.WriteLine (" {0}) {1}", number, c.text); | ||
number++; | ||
} | ||
} | ||
} | ||
|
||
void OnError (string message, Ink.ErrorType errorType) | ||
{ | ||
switch (errorType) { | ||
case ErrorType.Author: | ||
_authorMessages.Add (message); | ||
break; | ||
|
||
case ErrorType.Warning: | ||
_warnings.Add (message); | ||
break; | ||
|
||
case ErrorType.Error: | ||
_errors.Add (message); | ||
break; | ||
} | ||
} | ||
|
||
public string ResolveInkFilename (string includeName) | ||
{ | ||
var workingDir = Directory.GetCurrentDirectory (); | ||
var fullRootInkPath = Path.Combine (workingDir, includeName); | ||
return fullRootInkPath; | ||
} | ||
|
||
public string LoadInkFileContents (string fullFilename) | ||
{ | ||
return File.ReadAllText (fullFilename); | ||
} | ||
|
||
List<string> _errors = new List<string> (); | ||
List<string> _warnings = new List<string> (); | ||
List<string> _authorMessages = new List<string> (); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{714B52DE-576A-4760-BA2E-F8483DD2CAAA}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>InkTestBed</RootNamespace> | ||
<AssemblyName>InkTestBed</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug</OutputPath> | ||
<DefineConstants>DEBUG;</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<ExternalConsole>true</ExternalConsole> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release</OutputPath> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<ExternalConsole>true</ExternalConsole> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="InkTestBed.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\compiler\ink_compiler.csproj"> | ||
<Project>{52E3F3D0-2702-44E5-82F5-783B82647CA5}</Project> | ||
<Name>ink_compiler</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\ink-engine-runtime\ink-engine-runtime.csproj"> | ||
<Project>{F68D0EE2-1831-4A06-8FFA-CBD0315EFD0E}</Project> | ||
<Name>ink-engine-runtime</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="test.ink"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Include="test_included_file.ink"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Include="test_included_file2.ink"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
|
||
// Information about this assembly is defined by the following attributes. | ||
// Change them to the values specific to your project. | ||
|
||
[assembly: AssemblyTitle ("InkTestBed")] | ||
[assembly: AssemblyDescription ("")] | ||
[assembly: AssemblyConfiguration ("")] | ||
[assembly: AssemblyCompany ("")] | ||
[assembly: AssemblyProduct ("")] | ||
[assembly: AssemblyCopyright ("phish")] | ||
[assembly: AssemblyTrademark ("")] | ||
[assembly: AssemblyCulture ("")] | ||
|
||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". | ||
// The form "{Major}.{Minor}.*" will automatically update the build and revision, | ||
// and "{Major}.{Minor}.{Build}.*" will update just the revision. | ||
|
||
[assembly: AssemblyVersion ("1.0.*")] | ||
|
||
// The following attributes are used to specify the signing key for the assembly, | ||
// if desired. See the Mono documentation for more information about signing. | ||
|
||
//[assembly: AssemblyDelaySign(false)] | ||
//[assembly: AssemblyKeyFile("")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is a convenience test file for InkTestBed. |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.