diff --git a/OutlawEditor/src/main/java/org/badvision/outlaweditor/MythosEditor.java b/OutlawEditor/src/main/java/org/badvision/outlaweditor/MythosEditor.java
index 915d5814..7d4acc36 100644
--- a/OutlawEditor/src/main/java/org/badvision/outlaweditor/MythosEditor.java
+++ b/OutlawEditor/src/main/java/org/badvision/outlaweditor/MythosEditor.java
@@ -9,6 +9,8 @@ import java.util.List;
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;
@@ -23,7 +25,11 @@ import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.badvision.outlaweditor.data.xml.Block;
+import org.badvision.outlaweditor.data.xml.Mutation;
+import org.badvision.outlaweditor.data.xml.Scope;
import org.badvision.outlaweditor.data.xml.Script;
+import org.badvision.outlaweditor.data.xml.UserType;
+import org.badvision.outlaweditor.data.xml.Variable;
import org.badvision.outlaweditor.ui.ApplicationUIController;
import org.badvision.outlaweditor.ui.MythosScriptEditorController;
import org.w3c.dom.Document;
@@ -36,13 +42,15 @@ import org.xml.sax.SAXException;
*/
public class MythosEditor {
+ Scope scope;
Script script;
Stage primaryStage;
MythosScriptEditorController controller;
public static final String XML_HEADER = "\n";
- public MythosEditor(Script theScript) {
+ public MythosEditor(Script theScript, Scope theScope) {
script = theScript;
+ scope = theScope;
}
public void show() {
@@ -104,7 +112,6 @@ public class MythosEditor {
xml = xml.replaceAll("'", "'");
xml = xml.replace("?>", "?>");
xml += "";
- System.out.println("xml: " + xml);
return generateLoadScript(xml);
} catch (JAXBException ex) {
Logger.getLogger(MythosEditor.class.getName()).log(Level.SEVERE, null, ex);
@@ -134,8 +141,73 @@ public class MythosEditor {
script.setName(name);
ApplicationUIController.getController().redrawScripts();
}
+
+ public List getUserTypes() {
+ if (Application.gameData.getGlobal().getUserTypes() == null) {
+ return new ArrayList<>();
+ } else {
+ return Application.gameData.getGlobal().getUserTypes().getUserType();
+ }
+ }
+
+ public List
diff --git a/OutlawEditor/src/main/resources/mythos/mythos-editor/js/mythos_uncompressed.js b/OutlawEditor/src/main/resources/mythos/mythos-editor/js/mythos_uncompressed.js
index 97f732f4..79f14370 100644
--- a/OutlawEditor/src/main/resources/mythos/mythos-editor/js/mythos_uncompressed.js
+++ b/OutlawEditor/src/main/resources/mythos/mythos-editor/js/mythos_uncompressed.js
@@ -24,38 +24,175 @@ if (typeof Mythos === "undefined") {
return Blockly.Xml.workspaceToDom(Blockly.mainWorkspace).innerHTML;
},
helpUrl: 'https://docs.google.com/document/d/1VXbiY4G533-cokjQevZFhwvqMMCL--17ziMAoFoeJ5M/edit#heading=h.yv9dmneqjr2b',
- initCustomDefinitions: function() {
+ initCustomDefinitions: function () {
+// Mythos.editor.log("Add user defined types");
Mythos.addUserDefinedTypes();
- Mythos.addVariablesFromGlobalScope();
+// Mythos.editor.log("Add custom variables");
+ Mythos.addCustomVariables();
+// Mythos.editor.log("Add global functions");
Mythos.addFunctionsFromGlobalScope();
- Mythos.addVariablesFromLocalScope();
+// Mythos.editor.log("Add local functions");
Mythos.addFunctionsFromLocalScope();
+// Mythos.editor.log("Reinitalizing toolbox");
+ Mythos.workspace.updateToolbox(document.getElementById('toolbox'));
+// Mythos.editor.log("Done");
},
- addUserDefinedTypes: function() {
- var toolbarCategory = document.getElementById("customTypes");
- for (var userType in Mythos.editor.getUserTypes()) {
- var typeNode = document.createElement("block");
- typeNode.setAttribute("type", "new_"+userType);
- toolbarCategory.appendChild(typeNode);
- Mythos.buildCustomType(userType);
+ each: function (list, func) {
+ if (list && list instanceof Array) {
+ for (var i = 0; i < list.length; i++) {
+ func(list[i]);
+ }
+ } else if (list) {
+ for (var i = 0; i < list.size(); i++) {
+ func(list.get(i));
+ }
}
},
- buildCustomType: function(userType) {
- //Blockly.Blocks['new_']
+ addUserDefinedTypes: function () {
+ var toolbarCategory = document.getElementById("customTypes");
+ Mythos.each(Mythos.editor.getUserTypes(), function (userType) {
+ var typeNode = document.createElement("block");
+ typeNode.setAttribute("type", "userType_" + userType.getName());
+ toolbarCategory.appendChild(typeNode);
+ var getNode = document.createElement("block");
+ getNode.setAttribute("type", "get_" + userType.getName());
+ toolbarCategory.appendChild(getNode);
+ var setNode = document.createElement("block");
+ setNode.setAttribute("type", "set_" + userType.getName());
+ toolbarCategory.appendChild(setNode);
+ Mythos.buildCustomTypeBlocks(userType);
+ });
},
- addVariablesFromGlobalScope: function() {
-
+ buildCustomType: function (userType) {
+ Blockly.Blocks['userType_' + userType.getName()] = {
+ init: function () {
+ var typeConstructor = this;
+ typeConstructor.setColour(200);
+ typeConstructor.appendDummyInput()
+ .appendField("Create " + userType.getName());
+ Mythos.each(userType.getAttribute(), function (attribute) {
+ typeConstructor.appendValueInput(attribute.getName())
+ .setAlign(Blockly.ALIGN_RIGHT)
+ .setCheck(attribute.getType())
+ .appendField(attribute.getName());
+ });
+ typeConstructor.setPreviousStatement(true);
+ typeConstructor.setNextStatement(true);
+ typeConstructor.setOutput(true, userType.getName());
+ }
+ };
+ Blockly.Blocks['set_' + userType.getName()] = {
+ init: function () {
+ var typeSetter = this;
+ typeSetter.setColour(200);
+ typeSetter.appendValueInput("Set ")
+ .setAlign(Blockly.ALIGN_LEFT)
+ .setCheck(null)
+ .appendField(Mythos.getVariableDropdown(userType), "VAR")
+ .appendField(".")
+ .appendField(Mythos.getAttributeDropdown(userType), "ATTR");
+ typeSetter.setPreviousStatement(true);
+ typeSetter.setNextStatement(true);
+ typeSetter.setOutput(false);
+ }
+ };
+ Blockly.Blocks['get_' + userType.getName()] = {
+ init: function () {
+ var typeGetter = this;
+ typeGetter.setColour(200);
+ typeGetter.appendDummyInput()
+ .setAlign(Blockly.ALIGN_LEFT)
+ .setCheck(null)
+ .appendField(Mythos.getVariableDropdown(userType), "VAR")
+ .appendField(".")
+ .appendField(Mythos.getAttributeDropdown(userType), "ATTR");
+ typeGetter.setPreviousStatement(false);
+ typeGetter.setNextStatement(false);
+ typeGetter.setOutput(true, null);
+ }
+ };
},
- addFunctionsFromGlobalScope: function() {
+ getVariableDropdown: function (userType) {
+ var variables = Mythos.editor.getVariablesByType(userType.getName());
+ var options = [];
+ Mythos.each(variables, function (variable) {
+ options.push([variable.getName(), variable.getName()]);
+ });
+ return Blockly.FieldDropdown(options);
+ },
+ getAttributeDropdown: function (userType) {
+ var options = [];
+ Mythos.each(userType.getAttribute(), function (attribute) {
+ options.push([attribute.getName(), attribute.getName()]);
+ });
+ return Blockly.FieldDropdown(options);
+ },
+ 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());
},
- addVariablesFromLocalScope: function() {
-
- },
- addFunctionsFromLocalScope: function() {
+ 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);
+ Mythos.each(Mythos.editor.getVariablesByType("String"), function (variable) {
+ list.push(variable.getName());
+ });
+ Mythos.each(Mythos.editor.getVariablesByType("Number"), function (variable) {
+ list.push(variable.getName());
+ });
+ Mythos.each(Mythos.editor.getVariablesByType("Boolean"), function (variable) {
+ list.push(variable.getName());
+ });
+ return list;
+ };
},
initBlocks: function () {
Blockly.Blocks['flow_for'] = {
@@ -162,7 +299,7 @@ if (typeof Mythos === "undefined") {
}
};
Blockly.Blocks['events_move_backward'] = {
- init: function() {
+ init: function () {
this.setHelpUrl(Mythos.helpUrl);
this.setColour(54);
this.setPreviousStatement(true);
@@ -382,4 +519,4 @@ if (typeof Mythos === "undefined") {
}
};
}
-;
\ No newline at end of file
+;