Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions flixel/system/debug/completion/CompletionHandler.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using flixel.util.FlxArrayUtil;
using flixel.util.FlxStringUtil;
using StringTools;

#if hscript
#if (polymod || hscript)
import flixel.system.debug.console.ConsoleUtil;
#end

Expand Down Expand Up @@ -72,7 +72,7 @@ class CompletionHandler

function invokeCompletion(path:String, isPeriod:Bool)
{
#if hscript
#if (polymod || hscript)
var items:Array<String> = null;

try
Expand Down Expand Up @@ -104,7 +104,7 @@ class CompletionHandler

function getGlobals():Array<String>
{
#if hscript
#if (polymod || hscript)
return ConsoleUtil.interp.getGlobals().sortAlphabetically();
#else
return [];
Expand Down Expand Up @@ -135,7 +135,7 @@ class CompletionHandler

function selectionChanged(selectedItem:String)
{
#if hscript
#if (polymod || hscript)
try
{
var lastWord = getLastWord(input.text);
Expand Down
22 changes: 11 additions & 11 deletions flixel/system/debug/console/Console.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import openfl.text.TextFormat;
#if sys
import openfl.events.MouseEvent;
#end
#if hscript
#if (polymod || hscript)
import openfl.events.FocusEvent;
import openfl.events.KeyboardEvent;
import openfl.text.TextFieldType;
Expand All @@ -30,7 +30,7 @@ class Console extends Window
/**
* The text that is displayed in the console's input field by default.
*/
static inline var DEFAULT_TEXT:String = #if hscript "(Click here / press [Tab] to enter command. Type 'help' for help.)" #else "Using the console requires hscript - please run 'haxelib install hscript'." #end;
static inline var DEFAULT_TEXT:String = #if (polymod || hscript) "(Click here / press [Tab] to enter command. Type 'help' for help.)" #else "Using the console requires hscript." #end;

/**
* Map containing all registered Objects. You can use registerObject() or add them directly to this map.
Expand Down Expand Up @@ -75,7 +75,7 @@ class Console extends Window
this.completionList = completionList;
completionList.setY(y + Window.HEADER_HEIGHT);

#if hscript
#if (polymod || hscript)
ConsoleUtil.init();
#end

Expand Down Expand Up @@ -106,7 +106,7 @@ class Console extends Window

function registerEventListeners()
{
#if hscript
#if (polymod || hscript)
input.type = TextFieldType.INPUT;
input.addEventListener(FocusEvent.FOCUS_IN, onFocus);
input.addEventListener(FocusEvent.FOCUS_OUT, onFocusLost);
Expand Down Expand Up @@ -194,7 +194,7 @@ class Console extends Window
FlxG.game.debugger.onMouseFocusLost();
}

#if hscript
#if (polymod || hscript)
function onKeyDown(e:KeyboardEvent)
{
if (completionList.visible)
Expand Down Expand Up @@ -302,7 +302,7 @@ class Console extends Window
public function registerFunction(alias:String, func:Dynamic, ?helpText:String)
{
registeredFunctions.set(alias, func);
#if hscript
#if (polymod || hscript)
ConsoleUtil.registerFunction(alias, func);
#end

Expand All @@ -319,7 +319,7 @@ class Console extends Window
public function registerObject(alias:String, object:Dynamic)
{
registeredObjects.set(alias, object);
#if hscript
#if (polymod || hscript)
ConsoleUtil.registerObject(alias, object);
#end
}
Expand All @@ -334,7 +334,7 @@ class Console extends Window
{
registeredObjects.remove(alias);
registeredFunctions.remove(alias);
#if hscript
#if (polymod || hscript)
ConsoleUtil.removeByAlias(alias);
#end
}
Expand All @@ -354,7 +354,7 @@ class Console extends Window
if (registeredObjects[alias] == object)
{
registeredObjects.remove(alias);
#if hscript
#if (polymod || hscript)
ConsoleUtil.removeByAlias(alias);
#end
break;
Expand All @@ -377,7 +377,7 @@ class Console extends Window
if (registeredFunctions[alias] == func)
{
registeredFunctions.remove(alias);
#if hscript
#if (polymod || hscript)
ConsoleUtil.removeByAlias(alias);
#end
break;
Expand Down Expand Up @@ -432,7 +432,7 @@ class Console extends Window
{
super.destroy();

#if hscript
#if (polymod || hscript)
input.removeEventListener(FocusEvent.FOCUS_IN, onFocus);
input.removeEventListener(FocusEvent.FOCUS_OUT, onFocusLost);
input.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
Expand Down
24 changes: 16 additions & 8 deletions flixel/system/debug/console/ConsoleUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@ using flixel.util.FlxStringUtil;
using flixel.util.FlxArrayUtil;
using StringTools;

#if hscript
#if polymod
import polymod.hscript._internal.Expr;
import polymod.hscript._internal.Parser;
import polymod.hscript._internal.Interp as HScriptInterp;
#elseif hscript
import hscript.Expr;
import hscript.Parser;
import hscript.Interp as HScriptInterp;
#end

/**
* A set of helper functions used by the console.
*/
class ConsoleUtil
{
#if hscript
#if (polymod || hscript)
/**
* The hscript parser to make strings into haxe code.
*/
Expand All @@ -37,7 +42,11 @@ class ConsoleUtil
parser.allowJSON = true;
parser.allowTypes = true;

#if (polymod)
interp = new Interp(null, null);
#else
interp = new Interp();
#end
}

/**
Expand Down Expand Up @@ -172,11 +181,8 @@ class ConsoleUtil
}
}

/**
* hscript doesn't use property access by default... have to make our own.
*/
#if hscript
private class Interp extends hscript.Interp
#if (polymod || hscript)
private class Interp extends HScriptInterp
{
public function getGlobals():Array<String>
{
Expand All @@ -191,6 +197,7 @@ private class Interp extends hscript.Interp
return array;
}

#if (hscript && !polymod)
override function get(o:Dynamic, f:String):Dynamic
{
if (o == null)
Expand All @@ -205,5 +212,6 @@ private class Interp extends hscript.Interp
Reflect.setProperty(o, f, v);
return v;
}
#end
}
#end
#end
4 changes: 2 additions & 2 deletions flixel/system/debug/watch/WatchEntry.hx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import openfl.text.TextFormat;

using flixel.util.FlxStringUtil;

#if hscript
#if (polymod || hscript)
import flixel.system.debug.console.ConsoleUtil;
#end

Expand Down Expand Up @@ -120,7 +120,7 @@ class WatchEntry extends Sprite implements IFlxDestroyable
case FIELD(object, field):
Reflect.getProperty(object, field);
case EXPRESSION(_, parsedExpr):
#if hscript
#if (polymod || hscript)
ConsoleUtil.runExpr(parsedExpr);
#else
"hscript is not installed";
Expand Down
6 changes: 4 additions & 2 deletions flixel/system/debug/watch/WatchEntryData.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package flixel.system.debug.watch;

#if hscript
#if polymod
import polymod.hscript._internal.Expr;
#elseif hscript
import hscript.Expr;
#end

Expand All @@ -19,7 +21,7 @@ enum WatchEntryData
/**
* Haxe expression evaluated with hscript.
*/
EXPRESSION(expression:String, parsedExpr:#if hscript Expr #else String #end);
EXPRESSION(expression:String, parsedExpr:#if (polymod || hscript) Expr #else String #end);

/**
* A function that returns the value to display.
Expand Down
4 changes: 2 additions & 2 deletions flixel/system/frontEnds/WatchFrontEnd.hx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package flixel.system.frontEnds;

import flixel.FlxG;
#if hscript
#if (polymod || hscript)
import flixel.system.debug.console.ConsoleUtil;
#end

Expand Down Expand Up @@ -84,7 +84,7 @@ class WatchFrontEnd
{
#if FLX_DEBUG
var parsedExpr = null;
#if hscript
#if (polymod || hscript)
parsedExpr = ConsoleUtil.parseCommand(expression);
#end
window.add(displayName == null ? expression : displayName, EXPRESSION(expression, parsedExpr));
Expand Down