Skip to content

Commit

Permalink
Merge branch 'disallow-cross-stitch-temps'
Browse files Browse the repository at this point in the history
  • Loading branch information
joethephish committed Apr 18, 2018
2 parents ea67520 + 3826d90 commit 38c1730
Show file tree
Hide file tree
Showing 99 changed files with 1,926 additions and 1,082 deletions.
285 changes: 285 additions & 0 deletions InkTestBed/InkTestBed.cs
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> ();
}

58 changes: 58 additions & 0 deletions InkTestBed/InkTestBed.csproj
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>
26 changes: 26 additions & 0 deletions InkTestBed/Properties/AssemblyInfo.cs
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("")]
1 change: 1 addition & 0 deletions InkTestBed/test.ink
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.
4 changes: 3 additions & 1 deletion build_for_inky.command
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export CC="cc -arch i386 -framework CoreFoundation -lobjc -liconv"
# "Bundles in addition support a –static flag. The –static flag causes mkbundle to generate a static executable that statically links the Mono runtime. Be advised that this option will trigger the LGPL requirement that you still distribute the independent pieces to your user so he can manually upgrade his Mono runtime if he chooses to do so. Alternatively, you can obtain a proprietary license of Mono by contacting Xamarin."
# http://www.mono-project.com/archived/guiderunning_mono_applications/
cd ./inklecate/bin/Debug/
mkbundle --static --sdk /Library/Frameworks/Mono.framework/Versions/Current --deps inklecate.exe ink-engine-runtime.dll -o inklecate_mac
mkbundle --static --sdk /Library/Frameworks/Mono.framework/Versions/Current --deps inklecate.exe ink-engine-runtime.dll ink_compiler.dll -o inklecate_mac

# TODO: See if you can whittle down the dependencies a bit instead of using the --deps option above?
# It mentions all of the dependencies below, but I'm not convinced they're all necessary?
Expand All @@ -45,3 +45,5 @@ cp inklecate.exe ../../../BuildForInky/inklecate_win.exe
cp inklecate.exe.mdb ../../../BuildForInky
cp ink-engine-runtime.dll ../../../BuildForInky
cp ink-engine-runtime.dll.mdb ../../../BuildForInky
cp ink_compiler.dll ../../../BuildForInky
cp ink_compiler.dll.mdb ../../../BuildForInky
Loading

0 comments on commit 38c1730

Please sign in to comment.