mirror of
https://github.com/badvision/lawless-legends.git
synced 2025-01-13 18:30:38 +00:00
Global functions now have proper return and non-return variant calls and full parameter support!
This commit is contained in:
parent
f94e2beeb7
commit
e41e515014
@ -11,6 +11,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;
|
||||
@ -24,9 +25,11 @@ import javax.xml.namespace.QName;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import org.badvision.outlaweditor.data.xml.Arg;
|
||||
import org.badvision.outlaweditor.data.xml.Block;
|
||||
import org.badvision.outlaweditor.data.xml.Global.UserTypes.UserType;
|
||||
import org.badvision.outlaweditor.data.xml.Global.Variables.Variable;
|
||||
import org.badvision.outlaweditor.data.xml.Mutation;
|
||||
import org.badvision.outlaweditor.data.xml.Script;
|
||||
import org.badvision.outlaweditor.ui.ApplicationUIController;
|
||||
import org.badvision.outlaweditor.ui.MythosScriptEditorController;
|
||||
@ -138,13 +141,13 @@ public class MythosEditor {
|
||||
ApplicationUIController.getController().redrawScripts();
|
||||
}
|
||||
|
||||
public List<Script> getGlobalFunctions() {
|
||||
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 && !s.equals(script);
|
||||
return s.getName() != null;
|
||||
}).collect(Collectors.toList());
|
||||
return filteredList;
|
||||
}
|
||||
@ -172,9 +175,20 @@ public class MythosEditor {
|
||||
return v.getType().equals(type);
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
public List<String> getParametersForScript(Script script) {
|
||||
List<String> allArgs = new ArrayList();
|
||||
script.getBlock().getFieldOrMutationOrStatement()
|
||||
.stream().filter((o) -> (o instanceof Mutation))
|
||||
.map((o) -> (Mutation) o).findFirst().ifPresent((m) -> {
|
||||
m.getArg().stream().forEach((a) -> {
|
||||
allArgs.add(a.getName());
|
||||
});
|
||||
});
|
||||
return allArgs;
|
||||
}
|
||||
|
||||
public void log(String message) {
|
||||
System.out.println(message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ if (typeof Mythos === "undefined") {
|
||||
func(list[i]);
|
||||
}
|
||||
} else if (list) {
|
||||
for (var i=0; i < list.size(); i++) {
|
||||
for (var i = 0; i < list.size(); i++) {
|
||||
func(list.get(i));
|
||||
}
|
||||
}
|
||||
@ -133,7 +133,6 @@ if (typeof Mythos === "undefined") {
|
||||
Blockly.Variables.allVariables_old = Blockly.Variables.allVariables;
|
||||
Blockly.Variables.allVariables = function (workspace) {
|
||||
var list = Blockly.Variables.allVariables_old(workspace);
|
||||
var variable;
|
||||
Mythos.each(Mythos.editor.getVariablesByType("String"), function (variable) {
|
||||
list.push(variable.getName());
|
||||
});
|
||||
@ -149,21 +148,46 @@ if (typeof Mythos === "undefined") {
|
||||
addFunctionsFromGlobalScope: function () {
|
||||
var toolbarCategory = document.getElementById("globalFunctions");
|
||||
Mythos.each(Mythos.editor.getGlobalFunctions(), function (func) {
|
||||
Mythos.editor.log("Adding "+func.getName());
|
||||
var scriptNode = document.createElement("block");
|
||||
scriptNode.setAttribute("type", "global_" + func.getName());
|
||||
toolbarCategory.appendChild(scriptNode);
|
||||
Blockly.Blocks['global_' + func.getName()] = {
|
||||
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());
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
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);
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
Mythos.editor.log(toolbarCategory.outerHTML);
|
||||
},
|
||||
addVariablesFromLocalScope: function () {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user