mirror of
https://github.com/badvision/lawless-legends.git
synced 2025-02-20 05:29:09 +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.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
@ -141,18 +142,6 @@ public class MythosEditor {
|
||||
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() {
|
||||
if (Application.gameData.getGlobal().getUserTypes() == null) {
|
||||
return new ArrayList<>();
|
||||
@ -161,16 +150,44 @@ public class MythosEditor {
|
||||
}
|
||||
}
|
||||
|
||||
public List<Variable> getGlobalVariables() {
|
||||
if (Application.gameData.getGlobal().getVariables() == null) {
|
||||
public List<Script> getGlobalFunctions() {
|
||||
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<>();
|
||||
} 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) {
|
||||
return getGlobalVariables().stream().filter(
|
||||
Stream<Variable> allGlobals = getGlobalVariables().stream();
|
||||
Stream<Variable> allLocals = getLocalVariables().stream();
|
||||
return Stream.concat(allGlobals, allLocals).filter(
|
||||
(Variable v) -> {
|
||||
return v.getType().equals(type);
|
||||
}).collect(Collectors.toList());
|
||||
@ -178,6 +195,7 @@ public class MythosEditor {
|
||||
|
||||
public List<String> getParametersForScript(Script script) {
|
||||
List<String> allArgs = new ArrayList();
|
||||
if (script.getBlock() != null && script.getBlock().getFieldOrMutationOrStatement() != null) {
|
||||
script.getBlock().getFieldOrMutationOrStatement()
|
||||
.stream().filter((o) -> (o instanceof Mutation))
|
||||
.map((o) -> (Mutation) o).findFirst().ifPresent((m) -> {
|
||||
@ -185,6 +203,7 @@ public class MythosEditor {
|
||||
allArgs.add(a.getName());
|
||||
});
|
||||
});
|
||||
}
|
||||
return allArgs;
|
||||
}
|
||||
|
||||
|
@ -27,12 +27,10 @@ if (typeof Mythos === "undefined") {
|
||||
initCustomDefinitions: function () {
|
||||
// Mythos.editor.log("Add user defined types");
|
||||
Mythos.addUserDefinedTypes();
|
||||
// Mythos.editor.log("Add global variables");
|
||||
Mythos.addVariablesFromGlobalScope();
|
||||
// Mythos.editor.log("Add custom variables");
|
||||
Mythos.addCustomVariables();
|
||||
// Mythos.editor.log("Add global functions");
|
||||
Mythos.addFunctionsFromGlobalScope();
|
||||
// Mythos.editor.log("Add local variables");
|
||||
Mythos.addVariablesFromLocalScope();
|
||||
// Mythos.editor.log("Add local functions");
|
||||
Mythos.addFunctionsFromLocalScope();
|
||||
// Mythos.editor.log("Reinitalizing toolbox");
|
||||
@ -92,7 +90,7 @@ if (typeof Mythos === "undefined") {
|
||||
.setCheck(null)
|
||||
.appendField(Mythos.getVariableDropdown(userType), "VAR")
|
||||
.appendField(".")
|
||||
.appendField(Mythos.getAttributeDropdoen(userType), "ATTR");
|
||||
.appendField(Mythos.getAttributeDropdown(userType), "ATTR");
|
||||
typeSetter.setPreviousStatement(true);
|
||||
typeSetter.setNextStatement(true);
|
||||
typeSetter.setOutput(false);
|
||||
@ -107,7 +105,7 @@ if (typeof Mythos === "undefined") {
|
||||
.setCheck(null)
|
||||
.appendField(Mythos.getVariableDropdown(userType), "VAR")
|
||||
.appendField(".")
|
||||
.appendField(Mythos.getAttributeDropdoen(userType), "ATTR");
|
||||
.appendField(Mythos.getAttributeDropdown(userType), "ATTR");
|
||||
typeGetter.setPreviousStatement(false);
|
||||
typeGetter.setNextStatement(false);
|
||||
typeGetter.setOutput(true, null);
|
||||
@ -129,7 +127,58 @@ if (typeof Mythos === "undefined") {
|
||||
});
|
||||
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 = function (workspace) {
|
||||
var list = Blockly.Variables.allVariables_old(workspace);
|
||||
@ -145,57 +194,6 @@ if (typeof Mythos === "undefined") {
|
||||
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 () {
|
||||
Blockly.Blocks['flow_for'] = {
|
||||
init: function () {
|
||||
|
Loading…
x
Reference in New Issue
Block a user