Skip to content

Commit

Permalink
— Added "Compare alias call" condition
Browse files Browse the repository at this point in the history
— Placed all eval ACE into separate section
  • Loading branch information
valerypopoff committed Mar 19, 2018
1 parent 934f023 commit cc8bcc1
Show file tree
Hide file tree
Showing 7 changed files with 312 additions and 99 deletions.
43 changes: 25 additions & 18 deletions Construct 2/edittime.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
return {
"name": "Valerypopoff JS Plugin",
"id": "ValerypopoffJSPlugin",
"version": "0.6.0",
"description": "Work with javascript objects and functions",
"version": "0.6.2",
"description": "Use javascript functions, get and set object properties and call object methods. Keep event sheets for high-level logic. Implement game objects, and algorithms in javascript.",
"author": "Valera Popov",
"help url": "https://readymag.com/valerypopoff/valerypopoff-js-plugin/",
"category": "Data & Storage",
Expand All @@ -27,9 +27,9 @@ AddCondition(0, cf_none, "Compare Function Return value", "General", "{0} {1} fu

AddAnyTypeParam("Value", "The value to compare to.");
AddCmpParam("Comparison", "How to compare.");
AddStringParam("Javascript code", "Enter JS code to execute and compare returned completion value. Include parameters into code by their number like this: #0, #1, #2...");
AddStringParam("JS code", "JS string that will be executed with eval. You can include parameters into the string using #-entries like this: #0, #1, #2 ... #999. The string will be parsed and all #-entries will be replaced with respective parameter values.");
AddVariadicParams("Parameter {n}", "Parameter to pass to the code.");
AddCondition(1, cf_none, "Compare JS code Completion value", "General", "{0} {1} value of {2} ({...})", "Compare completion value of JS code with optional parameters (does NOT store return value).", "CompareExecReturnWithParams");
AddCondition(1, cf_none, "Compare JS code Completion value", "Eval", "{0} {1} value of {2} ({...})", "Compare completion value of JS code with optional parameters (does NOT store return value). This condition uses eval.", "CompareExecReturnWithParams");


AddCmpParam("Comparison", "How to compare.");
Expand All @@ -40,39 +40,46 @@ AddCondition(2, cf_none, "Compare Stored Return value", "General", "Stored Retur
AddCondition(3, cf_none, "All scripts loaded", "General", "All scripts loaded", "Check if all scripts are loaded.", "AllScriptsLoaded");


AddStringParam("Name", "Alias name.");
AddStringParam("Alias expression", "Alias expression to compare.");
AddCmpParam("Comparison", "How to compare.");
AddAnyTypeParam("Value", "The value to compare to.");
AddCondition(4, cf_none, "Compare alias", "Aliases", "[{0}] {1} {2}", "Compare the value behind the alias.", "CompareAliasValue");
AddCondition(4, cf_none, "Compare alias", "Aliases", "[{0}] {1} {2}", "Compare the value behind the alias expression.", "CompareAliasValue");


AddAnyTypeParam("Value", "The value to compare to.");
AddCmpParam("Comparison", "How to compare.");
AddStringParam("Alias expression", "Alias expression to call.");
AddVariadicParams("Parameter {n}", "Parameter to pass to the function.");
AddCondition(5, cf_none, "Compare alias Call", "Aliases", "{0} {1} [{2}] ({...})", "Call JS function behind the alias expression and compare its return value (does NOT store return value).", "CompareAliasCallReturnValue");



////////////////////////////////////////
// Actions

AddStringParam("JS code", "Enter JS code to execute. Include parameters into code by their number like this: #0, #1, #2...");
AddStringParam("JS code", "JS string that will be executed with eval. You can include parameters into the string using #-entries like this: #0, #1, #2 ... #999. The string will be parsed and all #-entries will be replaced with respective parameter values.");
AddVariadicParams("Parameter {n}", "Parameter to pass to the code.");
AddAction(0, af_none, "Execute JS code (stores return value)", "General", "Execute code: {0} ({...})", "Execute JS code with optional parameters and store returned completion value.", "ExecuteJSWithParams");
AddAction(0, af_none, "Execute JS code (stores return value)", "Eval", "Execute code: {0} ({...})", "Execute JS code with optional parameters and store returned completion value. This action uses eval.", "ExecuteJSWithParams");


AddStringParam("JS function name (no parentheses)", "Enter JS function name to call.");
AddVariadicParams("Parameter {n}", "Parameter to pass to the function.");
AddAction(1, af_none, "Call JS function (stores return value)", "General", "Call function: {0} ({...})", "Call JS function with optional parameters and store its return value.", "CallJSfunction");


AddStringParam("Name", "Alias name.");
AddStringParam("Alias name", "New alias name to create.");
AddStringParam("JS", "What the alias is associated with in JS.");
AddAction(2, af_none, "Init alias", "Aliases", "Init [{0}] with javascript {1}", "Init alias with javascript code.", "InitAlias");


AddStringParam("Name", "Alias name.");
AddAnyTypeParam("Value", "Value to set the alias to.");
AddAction(3, af_none, "Set alias", "Aliases", "Set [{0}] to {1}", "Set value behind alias.", "SetAlias");
AddStringParam("Alias expression", "Alias expression to set.");
AddAnyTypeParam("Value", "Value to set the alias expression to.");
AddAction(3, af_none, "Set alias", "Aliases", "Set [{0}] to {1}", "Set value behind alias expression.", "SetAlias");


AddStringParam("Name", "Alias name.");
AddStringParam("Alias expression", "Alias expression to call.");
AddVariadicParams("Parameter {n}", "Parameter to pass to the function.");
AddAction(4, af_none, "Call alias (stores return value)", "Aliases", "Call [{0}] ({...})", "Call the function behind alias and store its return value.", "CallAlias");
AddAction(4, af_none, "Call alias (stores return value)", "Aliases", "Call [{0}] ({...})", "Call the function behind alias expression and store its return value.", "CallAlias");



Expand All @@ -81,11 +88,11 @@ AddAction(4, af_none, "Call alias (stores return value)", "Aliases", "Call [{0}]
AddExpression(0, ef_return_any, "Stored Return Value", "General", "StoredReturnValue", "Get stored return value after actions");


AddStringParam("JS code", "Enter JS code to execute and optional parameters. Include parameters into code by their number like this: #0, #1, #2...");
AddExpression(1, ef_return_any | ef_variadic_parameters, "JS Code Value", "General", "JSCodeValue", "Execute JS code with optional parameters and get its completion value right away (it will NOT store this value)");
AddStringParam("JS code", "This expression uses eval. Enter JS string (it will be executed with eval) and optional parameters. If you pass parameters, include them into the string using #-entries like this: #0, #1, #2 ... #999. The string will be parsed and all #-entries will be replaced with respective parameter values.");
AddExpression(1, ef_return_any | ef_variadic_parameters, "JS Code Value", "Eval", "JSCodeValue", "Execute JS code with optional parameters and get its completion value right away (it will NOT store this value)");


AddStringParam("Alias name", "Enter alias name.");
AddStringParam("Alias expression", "Enter alias expression.");
AddExpression(2, ef_return_any | ef_variadic_parameters, "Alias value", "Aliases", "AliasValue", "Get alias value");


Expand All @@ -96,7 +103,7 @@ ACESDone();
////////////////////////////////////////

var property_list = [
new cr.Property(ept_text, 'Script files', '', 'Names of javascript files to include.'),
new cr.Property(ept_text, 'Script files', '', 'Javascript files to include to the game.'),

];

Expand Down
62 changes: 58 additions & 4 deletions Construct 2/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ cr.plugins_.ValerypopoffJSPlugin = function(runtime)
}
}
}

};

// only called if a layout object
Expand Down Expand Up @@ -182,7 +183,6 @@ cr.plugins_.ValerypopoffJSPlugin = function(runtime)

var DotStringToDotArray = function( str_ )
{
// 2 sec
// Array of indexes that will be used to dotsplit the string. Only split by dots that are not in brackets
// To determine whether the dot is in brackets, we use simple logic:
// if before the dot there's different amount of '[' and ']', the dot is in brackets
Expand Down Expand Up @@ -517,6 +517,18 @@ cr.plugins_.ValerypopoffJSPlugin = function(runtime)
return pluginProto.cnds.CompareFunctionReturnValue.call( this, funcname_, funcparams_, cmp_, value_ );
};

cnds.C2CompareAliasCallReturnValue = function (value_, cmp_, alias_exp_, funcparams_)
{
switch( cmp_ )
{
case 2: cmp_=4; break;
case 3: cmp_=5; break;
case 4: cmp_=2; break;
case 5: cmp_=3; break;
}

return pluginProto.cnds.CompareAliasCallReturnValue.call( this, alias_exp_, funcparams_, cmp_, value_ );
};

cnds.C2CompareExecReturnWithParams = function (value_, cmp_, code_, params_)
{
Expand Down Expand Up @@ -574,6 +586,24 @@ cr.plugins_.ValerypopoffJSPlugin = function(runtime)
//Double(12) > 24
};

cnds.CompareAliasCallReturnValue = function (alias_exp_, funcparams_, cmp_, value_)
{
var store_return_value_ = false;
var ret = undefined;

//Calling the CallAlias action with the flag "false" so it doesn't not store return value.
//We only want to store return value when the user explicitly calls Plugin Actions that execute JS code
ret = pluginProto.acts.CallAlias.call( this, alias_exp_, funcparams_, store_return_value_, "'Compare Alias Call return value' condition" );

if( typeof ret === "boolean" )
ret = ret ? 1 : 0;

return cr.do_cmp(ret, cmp_, value_);

//Double(12) > 24
};


cnds.CompareExecReturnWithParams = function (code_, params_, cmp_, value_)
{
var ret = undefined;
Expand Down Expand Up @@ -628,6 +658,23 @@ cr.plugins_.ValerypopoffJSPlugin = function(runtime)
//24 < Double(12)
};

cnds.CompareAliasCallReturnValue = function (value_, cmp_, alias_exp_, funcparams_)
{
var store_return_value_ = false;
var ret = undefined;

//Calling the CallAlias action with the flag "false" so it doesn't not store return value.
//We only want to store return value when the user explicitly calls Plugin Actions that execute JS code
ret = pluginProto.acts.CallAlias.call( this, alias_exp_, funcparams_, store_return_value_, "'Compare Alias Call return value' condition" );

if( typeof ret === "boolean" )
ret = ret ? 1 : 0;

return cr.do_cmp(value_, cmp_, ret);

//24 < Double(12)
};

cnds.CompareExecReturnWithParams = function (value_, cmp_, code_, params_)
{
var ret = undefined;
Expand Down Expand Up @@ -1049,10 +1096,17 @@ cr.plugins_.ValerypopoffJSPlugin = function(runtime)
}


acts.CallAlias = function (alias_exp_, funcparams_)
acts.CallAlias = function (alias_exp_, funcparams_, store_return_value_, caller_name_)
{
var store_return_value_ = true;
var caller_name_ = "'Call alias' action";
//If no store_return_value_ passed, make it true
if( store_return_value_ === undefined )
store_return_value_ = true;

//If no caller_name_ passed, make it "'Call function' action"
if( caller_name_ === undefined )
caller_name_ = "'Call alias' action";


var final = this.ParseJS(alias_exp_, true, caller_name_);


Expand Down
Loading

0 comments on commit cc8bcc1

Please sign in to comment.