mirror of
https://github.com/badvision/lawless-legends.git
synced 2025-02-22 03:29:01 +00:00
Global and Local functions are now working! All underlying functionality for global/local variables is also in place but untested until variable UI is hooked up
This commit is contained in:
parent
050613781d
commit
314102bba7
@ -10,6 +10,7 @@ import java.util.Map;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
@ -141,18 +142,6 @@ public class MythosEditor {
|
|||||||
ApplicationUIController.getController().redrawScripts();
|
ApplicationUIController.getController().redrawScripts();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Script> getGlobalFunctions() {
|
|
||||||
if (Application.gameData.getGlobal().getScripts() == null) {
|
|
||||||
return new ArrayList<>();
|
|
||||||
} else {
|
|
||||||
List<Script> scripts = Application.gameData.getGlobal().getScripts().getScript();
|
|
||||||
List<Script> filteredList = scripts.stream().filter((Script s) -> {
|
|
||||||
return s.getName() != null;
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
return filteredList;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<UserType> getUserTypes() {
|
public List<UserType> getUserTypes() {
|
||||||
if (Application.gameData.getGlobal().getUserTypes() == null) {
|
if (Application.gameData.getGlobal().getUserTypes() == null) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
@ -161,16 +150,44 @@ public class MythosEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Variable> getGlobalVariables() {
|
public List<Script> getGlobalFunctions() {
|
||||||
if (Application.gameData.getGlobal().getVariables() == null) {
|
return getFunctions(Application.gameData.getGlobal());
|
||||||
|
}
|
||||||
|
public List<Script> getLocalFunctions() {
|
||||||
|
return getFunctions(scope);
|
||||||
|
}
|
||||||
|
private List<Script> getFunctions(Scope scriptScope) {
|
||||||
|
if (scriptScope.getScripts() == null) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
} else {
|
} else {
|
||||||
return Application.gameData.getGlobal().getVariables().getVariable();
|
List<Script> scripts = scriptScope.getScripts().getScript();
|
||||||
|
List<Script> filteredList = scripts.stream().filter((Script s) -> {
|
||||||
|
return s.getName() != null;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
return filteredList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Variable> getGlobalVariables() {
|
||||||
|
return getVariables(Application.gameData.getGlobal());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Variable> getLocalVariables() {
|
||||||
|
return getVariables(scope);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Variable> getVariables(Scope scriptScope) {
|
||||||
|
if (scriptScope.getVariables() == null) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
} else {
|
||||||
|
return scriptScope.getVariables().getVariable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Variable> getVariablesByType(String type) {
|
public List<Variable> getVariablesByType(String type) {
|
||||||
return getGlobalVariables().stream().filter(
|
Stream<Variable> allGlobals = getGlobalVariables().stream();
|
||||||
|
Stream<Variable> allLocals = getLocalVariables().stream();
|
||||||
|
return Stream.concat(allGlobals, allLocals).filter(
|
||||||
(Variable v) -> {
|
(Variable v) -> {
|
||||||
return v.getType().equals(type);
|
return v.getType().equals(type);
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
@ -178,6 +195,7 @@ public class MythosEditor {
|
|||||||
|
|
||||||
public List<String> getParametersForScript(Script script) {
|
public List<String> getParametersForScript(Script script) {
|
||||||
List<String> allArgs = new ArrayList();
|
List<String> allArgs = new ArrayList();
|
||||||
|
if (script.getBlock() != null && script.getBlock().getFieldOrMutationOrStatement() != null) {
|
||||||
script.getBlock().getFieldOrMutationOrStatement()
|
script.getBlock().getFieldOrMutationOrStatement()
|
||||||
.stream().filter((o) -> (o instanceof Mutation))
|
.stream().filter((o) -> (o instanceof Mutation))
|
||||||
.map((o) -> (Mutation) o).findFirst().ifPresent((m) -> {
|
.map((o) -> (Mutation) o).findFirst().ifPresent((m) -> {
|
||||||
@ -185,6 +203,7 @@ public class MythosEditor {
|
|||||||
allArgs.add(a.getName());
|
allArgs.add(a.getName());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
return allArgs;
|
return allArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,12 +27,10 @@ if (typeof Mythos === "undefined") {
|
|||||||
initCustomDefinitions: function () {
|
initCustomDefinitions: function () {
|
||||||
// Mythos.editor.log("Add user defined types");
|
// Mythos.editor.log("Add user defined types");
|
||||||
Mythos.addUserDefinedTypes();
|
Mythos.addUserDefinedTypes();
|
||||||
// Mythos.editor.log("Add global variables");
|
// Mythos.editor.log("Add custom variables");
|
||||||
Mythos.addVariablesFromGlobalScope();
|
Mythos.addCustomVariables();
|
||||||
// Mythos.editor.log("Add global functions");
|
// Mythos.editor.log("Add global functions");
|
||||||
Mythos.addFunctionsFromGlobalScope();
|
Mythos.addFunctionsFromGlobalScope();
|
||||||
// Mythos.editor.log("Add local variables");
|
|
||||||
Mythos.addVariablesFromLocalScope();
|
|
||||||
// Mythos.editor.log("Add local functions");
|
// Mythos.editor.log("Add local functions");
|
||||||
Mythos.addFunctionsFromLocalScope();
|
Mythos.addFunctionsFromLocalScope();
|
||||||
// Mythos.editor.log("Reinitalizing toolbox");
|
// Mythos.editor.log("Reinitalizing toolbox");
|
||||||
@ -92,7 +90,7 @@ if (typeof Mythos === "undefined") {
|
|||||||
.setCheck(null)
|
.setCheck(null)
|
||||||
.appendField(Mythos.getVariableDropdown(userType), "VAR")
|
.appendField(Mythos.getVariableDropdown(userType), "VAR")
|
||||||
.appendField(".")
|
.appendField(".")
|
||||||
.appendField(Mythos.getAttributeDropdoen(userType), "ATTR");
|
.appendField(Mythos.getAttributeDropdown(userType), "ATTR");
|
||||||
typeSetter.setPreviousStatement(true);
|
typeSetter.setPreviousStatement(true);
|
||||||
typeSetter.setNextStatement(true);
|
typeSetter.setNextStatement(true);
|
||||||
typeSetter.setOutput(false);
|
typeSetter.setOutput(false);
|
||||||
@ -107,7 +105,7 @@ if (typeof Mythos === "undefined") {
|
|||||||
.setCheck(null)
|
.setCheck(null)
|
||||||
.appendField(Mythos.getVariableDropdown(userType), "VAR")
|
.appendField(Mythos.getVariableDropdown(userType), "VAR")
|
||||||
.appendField(".")
|
.appendField(".")
|
||||||
.appendField(Mythos.getAttributeDropdoen(userType), "ATTR");
|
.appendField(Mythos.getAttributeDropdown(userType), "ATTR");
|
||||||
typeGetter.setPreviousStatement(false);
|
typeGetter.setPreviousStatement(false);
|
||||||
typeGetter.setNextStatement(false);
|
typeGetter.setNextStatement(false);
|
||||||
typeGetter.setOutput(true, null);
|
typeGetter.setOutput(true, null);
|
||||||
@ -129,7 +127,58 @@ if (typeof Mythos === "undefined") {
|
|||||||
});
|
});
|
||||||
return Blockly.FieldDropdown(options);
|
return Blockly.FieldDropdown(options);
|
||||||
},
|
},
|
||||||
addVariablesFromGlobalScope: function () {
|
addFunctionsFromScope: function(target, prefix, functions) {
|
||||||
|
Mythos.each(functions, function (func) {
|
||||||
|
var scriptNode = document.createElement("block");
|
||||||
|
scriptNode.setAttribute("type", prefix + "_" + func.getName());
|
||||||
|
target.appendChild(scriptNode);
|
||||||
|
scriptNode = document.createElement("block");
|
||||||
|
scriptNode.setAttribute("type", prefix + "ignore_" + func.getName());
|
||||||
|
target.appendChild(scriptNode);
|
||||||
|
Blockly.Blocks[prefix + 'ignore_' + func.getName()] = {
|
||||||
|
init: function () {
|
||||||
|
this.setPreviousStatement(true);
|
||||||
|
this.setNextStatement(true);
|
||||||
|
this.setColour(250);
|
||||||
|
this.appendDummyInput()
|
||||||
|
.appendField(prefix + " " + func.getName());
|
||||||
|
var functionBlock = this;
|
||||||
|
Mythos.each(Mythos.editor.getParametersForScript(func), function (argName) {
|
||||||
|
functionBlock.appendValueInput(argName)
|
||||||
|
.setAlign(Blockly.ALIGN_RIGHT)
|
||||||
|
.setCheck(null)
|
||||||
|
.appendField(argName);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Blockly.Blocks[prefix + '_' + func.getName()] = {
|
||||||
|
init: function () {
|
||||||
|
this.setColour(250);
|
||||||
|
this.setPreviousStatement(false);
|
||||||
|
this.setNextStatement(false);
|
||||||
|
this.setOutput(true, null);
|
||||||
|
this.appendDummyInput()
|
||||||
|
.appendField(prefix + " " + func.getName());
|
||||||
|
var functionBlock = this;
|
||||||
|
Mythos.each(Mythos.editor.getParametersForScript(func), function (argName) {
|
||||||
|
functionBlock.appendValueInput(argName)
|
||||||
|
.setAlign(Blockly.ALIGN_RIGHT)
|
||||||
|
.setCheck(null)
|
||||||
|
.appendField(argName);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
},
|
||||||
|
addFunctionsFromGlobalScope: function () {
|
||||||
|
var toolbarCategory = document.getElementById("globalFunctions");
|
||||||
|
Mythos.addFunctionsFromScope(toolbarCategory, "Global", Mythos.editor.getGlobalFunctions());
|
||||||
|
},
|
||||||
|
addFunctionsFromLocalScope: function () {
|
||||||
|
var toolbarCategory = document.getElementById("localFunctions");
|
||||||
|
Mythos.addFunctionsFromScope(toolbarCategory, "Local", Mythos.editor.getLocalFunctions());
|
||||||
|
},
|
||||||
|
addCustomVariables: function () {
|
||||||
Blockly.Variables.allVariables_old = Blockly.Variables.allVariables;
|
Blockly.Variables.allVariables_old = Blockly.Variables.allVariables;
|
||||||
Blockly.Variables.allVariables = function (workspace) {
|
Blockly.Variables.allVariables = function (workspace) {
|
||||||
var list = Blockly.Variables.allVariables_old(workspace);
|
var list = Blockly.Variables.allVariables_old(workspace);
|
||||||
@ -145,57 +194,6 @@ if (typeof Mythos === "undefined") {
|
|||||||
return list;
|
return list;
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
addFunctionsFromGlobalScope: function () {
|
|
||||||
var toolbarCategory = document.getElementById("globalFunctions");
|
|
||||||
Mythos.each(Mythos.editor.getGlobalFunctions(), function (func) {
|
|
||||||
var scriptNode = document.createElement("block");
|
|
||||||
scriptNode.setAttribute("type", "global_" + func.getName());
|
|
||||||
toolbarCategory.appendChild(scriptNode);
|
|
||||||
scriptNode = document.createElement("block");
|
|
||||||
scriptNode.setAttribute("type", "globalignore_" + func.getName());
|
|
||||||
toolbarCategory.appendChild(scriptNode);
|
|
||||||
Blockly.Blocks['globalignore_' + func.getName()] = {
|
|
||||||
init: function () {
|
|
||||||
this.setPreviousStatement(true);
|
|
||||||
this.setNextStatement(true);
|
|
||||||
this.setColour(250);
|
|
||||||
this.appendDummyInput()
|
|
||||||
.appendField("Global " + func.getName());
|
|
||||||
var functionBlock = this;
|
|
||||||
Mythos.each(Mythos.editor.getParametersForScript(func), function (argName) {
|
|
||||||
functionBlock.appendValueInput(argName)
|
|
||||||
.setAlign(Blockly.ALIGN_RIGHT)
|
|
||||||
.setCheck(null)
|
|
||||||
.appendField(argName);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Blockly.Blocks['global_' + func.getName()] = {
|
|
||||||
init: function () {
|
|
||||||
this.setColour(250);
|
|
||||||
this.setPreviousStatement(false);
|
|
||||||
this.setNextStatement(false);
|
|
||||||
this.setOutput(true, null);
|
|
||||||
this.appendDummyInput()
|
|
||||||
.appendField("Global " + func.getName());
|
|
||||||
var functionBlock = this;
|
|
||||||
Mythos.each(Mythos.editor.getParametersForScript(func), function (argName) {
|
|
||||||
functionBlock.appendValueInput(argName)
|
|
||||||
.setAlign(Blockly.ALIGN_RIGHT)
|
|
||||||
.setCheck(null)
|
|
||||||
.appendField(argName);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
},
|
|
||||||
addVariablesFromLocalScope: function () {
|
|
||||||
|
|
||||||
},
|
|
||||||
addFunctionsFromLocalScope: function () {
|
|
||||||
// var toolbarCategory = document.getElementById("localFunctions");
|
|
||||||
|
|
||||||
},
|
|
||||||
initBlocks: function () {
|
initBlocks: function () {
|
||||||
Blockly.Blocks['flow_for'] = {
|
Blockly.Blocks['flow_for'] = {
|
||||||
init: function () {
|
init: function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user