Skip to content

Commit

Permalink
Add all files again with correct directory structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxwolf committed Jan 2, 2016
1 parent 1b05bcf commit 18ca89b
Show file tree
Hide file tree
Showing 39 changed files with 3,582 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SET build_path=%~dp0
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%build_path:~0%build.ps1'"
PAUSE
60 changes: 60 additions & 0 deletions build.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////

var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");

//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////

// Define directories.
var buildDir = Directory("./bin");

//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////

Task("Clean")
.Does(() =>
{
CleanDirectory(buildDir);
});

Task("Restore-NuGet-Packages")
.IsDependentOn("Clean")
.Does(() =>
{
NuGetRestore("./src/WolfCurses.sln");
});

Task("Build")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
if(IsRunningOnWindows())
{
// Use MSBuild
MSBuild("./src/WolfCurses.sln", settings =>
settings.SetConfiguration(configuration));
}
else
{
// Use XBuild
XBuild("./src/WolfCurses.sln");
}
});

//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////

Task("Default")
.IsDependentOn("Build");

//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////

RunTarget(target);
55 changes: 55 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Param(
[string]$Script = "build.cake",
[string]$Target = "Default",
[ValidateSet("Release", "Debug")]
[string]$Configuration = "Release",
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
[string]$Verbosity = "Verbose",
[switch]$Experimental,
[switch]$WhatIf
)

$TOOLS_DIR = Join-Path $PSScriptRoot "tools"
$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe"
$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe"

# Should we use experimental build of Roslyn?
$UseExperimental = "";
if($Experimental.IsPresent) {
$UseExperimental = "-experimental"
}

# Is this a dry run?
$UseDryRun = "";
if($WhatIf.IsPresent) {
$UseDryRun = "-dryrun"
}

# Try download NuGet.exe if do not exist.
if (!(Test-Path $NUGET_EXE)) {
Invoke-WebRequest -Uri http://nuget.org/nuget.exe -OutFile $NUGET_EXE
}

# Make sure NuGet exists where we expect it.
if (!(Test-Path $NUGET_EXE)) {
Throw "Could not find NuGet.exe"
}

# Restore tools from NuGet.
Push-Location
Set-Location $TOOLS_DIR
Invoke-Expression "$NUGET_EXE install -ExcludeVersion"
Pop-Location
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}

# Make sure that Cake has been installed.
if (!(Test-Path $CAKE_EXE)) {
Throw "Could not find Cake.exe"
}

# Start Cake
Invoke-Expression "$CAKE_EXE `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseDryRun $UseExperimental"
Write-Host
exit $LASTEXITCODE
63 changes: 63 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash
###############################################################
# This is the Cake bootstrapper script that is responsible for
# downloading Cake and all specified tools from NuGet.
###############################################################

# Define directories.
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
TOOLS_DIR=$SCRIPT_DIR/tools
NUGET_EXE=$TOOLS_DIR/nuget.exe
CAKE_EXE=$TOOLS_DIR/Cake/Cake.exe

# Define default arguments.
SCRIPT="build.cake"
TARGET="Default"
CONFIGURATION="Release"
VERBOSITY="verbose"
DRYRUN=false
SHOW_VERSION=false

# Parse arguments.
for i in "$@"; do
case $1 in
-s|--script) SCRIPT="$2"; shift ;;
-t|--target) TARGET="$2"; shift ;;
-c|--configuration) CONFIGURATION="$2"; shift ;;
-v|--verbosity) VERBOSITY="$2"; shift ;;
-d|--dryrun) DRYRUN=true ;;
--version) SHOW_VERSION=true ;;
esac
shift
done

# Download NuGet if it does not exist.
if [ ! -f $NUGET_EXE ]; then
echo "Downloading NuGet..."
curl -Lsfo $NUGET_EXE https://www.nuget.org/nuget.exe
if [ $? -ne 0 ]; then
echo "An error occured while downloading nuget.exe."
exit 1
fi
fi

# Restore tools from NuGet.
pushd $TOOLS_DIR >/dev/null
mono $NUGET_EXE install -ExcludeVersion
popd >/dev/null

# Make sure that Cake has been installed.
if [ ! -f $CAKE_EXE ]; then
echo "Could not find Cake.exe."
exit 1
fi

# Start Cake
if $SHOW_VERSION; then
mono $CAKE_EXE -version
elif $DRYRUN; then
mono $CAKE_EXE $SCRIPT -verbosity=$VERBOSITY -configuration=$CONFIGURATION -target=$TARGET -dryrun
else
mono $CAKE_EXE $SCRIPT -verbosity=$VERBOSITY -configuration=$CONFIGURATION -target=$TARGET
fi
exit $?
22 changes: 22 additions & 0 deletions src/WolfCurses.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WolfCurses", "WolfCurses\WolfCurses.csproj", "{DAD43FA9-4823-4C23-A9B0-EDB0FA036DB4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DAD43FA9-4823-4C23-A9B0-EDB0FA036DB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DAD43FA9-4823-4C23-A9B0-EDB0FA036DB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DAD43FA9-4823-4C23-A9B0-EDB0FA036DB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DAD43FA9-4823-4C23-A9B0-EDB0FA036DB4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
171 changes: 171 additions & 0 deletions src/WolfCurses/Core/InputManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
// Created by Ron 'Maxwolf' McDowell ([email protected])
// Timestamp 12/31/2015@2:38 PM

namespace SimUnit
{
using System.Collections.Generic;

/// <summary>
/// Deals with keep track of input to the simulation via whatever form that may end up taking. The default
/// implementation is a text user interface (TUI) which allows for the currently accepted commands to be seen and only
/// then accepted.
/// </summary>
public sealed class InputManager : Module
{
/// <summary>
/// Holds a constant representation of the string telling the user to press enter key to continue so we don't repeat
/// ourselves.
/// </summary>
public const string PRESSENTER = "Press ENTER KEY to continue";

/// <summary>
/// Reference to simulation that is controlling the input manager.
/// </summary>
private readonly SimulationApp _simUnit;

/// <summary>
/// Holds a series of commands that need to be executed in the order they come out of the collection.
/// </summary>
private Queue<string> _commandQueue;

/// <summary>
/// Initializes a new instance of the <see cref="InputManager" /> class.
/// </summary>
/// <param name="simUnit">Core simulation which is controlling the window manager.</param>
public InputManager(SimulationApp simUnit)
{
_simUnit = simUnit;
_commandQueue = new Queue<string>();
InputBuffer = string.Empty;
}

/// <summary>
/// Input buffer that we will use to hold characters until need to send them to simulation.
/// </summary>
public string InputBuffer { get; private set; }

/// <summary>
/// Fired when the simulation is closing and needs to clear out any data structures that it created so the program can
/// exit cleanly.
/// </summary>
public override void Destroy()
{
// Clear the input buffer.
InputBuffer = string.Empty;

// Clear the command queue.
_commandQueue.Clear();
_commandQueue = null;
}

/// <summary>
/// Called when the simulation is ticked by underlying operating system, game engine, or potato. Each of these system
/// ticks is called at unpredictable rates, however if not a system tick that means the simulation has processed enough
/// of them to fire off event for fixed interval that is set in the core simulation by constant in milliseconds.
/// </summary>
/// <remarks>Default is one second or 1000ms.</remarks>
/// <param name="systemTick">
/// TRUE if ticked unpredictably by underlying operating system, game engine, or potato. FALSE if
/// pulsed by game simulation at fixed interval.
/// </param>
/// <param name="skipDay">
/// Determines if the simulation has force ticked without advancing time or down the trail. Used by
/// special events that want to simulate passage of time without actually any actual time moving by.
/// </param>
public override void OnTick(bool systemTick, bool skipDay = false)
{
// Skip if there are no commands to tick.
if (_commandQueue.Count <= 0)
return;

// Dequeue the next command to send and pass along to currently active game Windows if it exists.
_simUnit.WindowManager.FocusedWindow?.SendCommand(_commandQueue.Dequeue());
}

/// <summary>
/// Clears the input buffer and submits whatever was in there to the simulation for processing. Implementation is left
/// up the game simulation itself entirely.
/// </summary>
public void SendInputBufferAsCommand()
{
// Trim the result of the input so no extra whitespace at front or end exists.
var lineBufferTrimmed = InputBuffer.Trim();

// Destroy the input buffer if we are not accepting commands but return is pressed anyway.
if (!_simUnit.WindowManager.AcceptingInput)
InputBuffer = string.Empty;

// Send trimmed line buffer to game simulation, if not accepting input we just pass along empty string.
AddCommandToQueue(lineBufferTrimmed);

// Always forcefully clear the input buffer after returning it, this makes it ready for more input.
InputBuffer = string.Empty;
}

/// <summary>
/// Fired when the simulation receives an individual character from then input system. Depending on what it is we will
/// do something, or not!
/// </summary>
/// <param name="addedKeyString">String character converted into a string representation of itself.</param>
private void OnCharacterAddedToInputBuffer(string addedKeyString)
{
// Disable passing along input buffer if the simulation is not currently accepting input from the user.
if (!_simUnit.WindowManager.AcceptingInput)
return;

// Add the character to the end of the input buffer.
InputBuffer += addedKeyString;
}

/// <summary>
/// Populates an internal input buffer for the simulation that is used to eventually return a possible command string
/// to active game Windows.
/// </summary>
/// <param name="keyChar">The key Char.</param>
public void AddCharToInputBuffer(char keyChar)
{
// Filter to prevent non-characters like delete, insert, scroll lock, etc.
if (!char.IsLetter(keyChar) && !char.IsNumber(keyChar))
return;

// Convert character to string representation if itself.
var addedKeyString = char.ToString(keyChar);
OnCharacterAddedToInputBuffer(addedKeyString);
}

/// <summary>
/// Removes the last character from input buffer if greater than zero.
/// </summary>
public void RemoveLastCharOfInputBuffer()
{
if (InputBuffer.Length > 0)
InputBuffer = InputBuffer.Remove(InputBuffer.Length - 1);
}

/// <summary>
/// Fired by messaging system or user interface that wants to interact with the simulation by sending string command
/// that should be able to be parsed into a valid command that can be run on the current game Windows.
/// </summary>
/// <param name="returnedLine">Passed in command from controller, text was trimmed but nothing more.</param>
private void AddCommandToQueue(string returnedLine)
{
// Trim the input.
var trimmedInput = returnedLine.Trim();

// Skip if we already entered the same command, simulation is state based... no need for flooding.
if (_commandQueue.Contains(trimmedInput))
return;

// Adds the command to queue to be passed to simulation when input manager is ticked.
_commandQueue.Enqueue(trimmedInput);
}

/// <summary>
/// Removes any text data from the input buffer resetting it to an empty string again.
/// </summary>
public void ClearBuffer()
{
InputBuffer = string.Empty;
}
}
}
Loading

0 comments on commit 18ca89b

Please sign in to comment.