mirror of
https://github.com/badvision/lawless-legends.git
synced 2024-06-26 00:29:30 +00:00
Big step forward in supporting user-defined types, global functions and global variables (still in progress). This has all the new XML/bean support and most of the Blockly glue to make things work.
This commit is contained in:
parent
f4e7586c13
commit
2cb2135810
|
@ -3,12 +3,13 @@ package org.badvision.outlaweditor;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
|
@ -23,6 +24,8 @@ 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.Global.UserTypes.UserType;
|
||||
import org.badvision.outlaweditor.data.xml.Global.Variables.Variable;
|
||||
import org.badvision.outlaweditor.data.xml.Script;
|
||||
import org.badvision.outlaweditor.ui.ApplicationUIController;
|
||||
import org.badvision.outlaweditor.ui.MythosScriptEditorController;
|
||||
|
@ -104,7 +107,6 @@ public class MythosEditor {
|
|||
xml = xml.replaceAll("'", "'");
|
||||
xml = xml.replace("?>", "?><xml>");
|
||||
xml += "</xml>";
|
||||
System.out.println("xml: " + xml);
|
||||
return generateLoadScript(xml);
|
||||
} catch (JAXBException ex) {
|
||||
Logger.getLogger(MythosEditor.class.getName()).log(Level.SEVERE, null, ex);
|
||||
|
@ -134,8 +136,44 @@ public class MythosEditor {
|
|||
script.setName(name);
|
||||
ApplicationUIController.getController().redrawScripts();
|
||||
}
|
||||
|
||||
public List getUserTypes() {
|
||||
return new ArrayList();
|
||||
|
||||
public List<Script> getGlobalFunctions() {
|
||||
if (Application.gameData.getGlobal().getScripts() == null) {
|
||||
return Collections.emptyList();
|
||||
} else {
|
||||
List<Script> scripts = Application.gameData.getGlobal().getScripts().getScript();
|
||||
List<Script> filteredList = scripts.stream().filter((Script s) -> {
|
||||
return s.getName() != null && !s.equals(script);
|
||||
}).collect(Collectors.toList());
|
||||
return filteredList;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<UserType> getUserTypes() {
|
||||
if (Application.gameData.getGlobal().getUserTypes() == null) {
|
||||
return Collections.emptyList();
|
||||
} else {
|
||||
return Application.gameData.getGlobal().getUserTypes().getUserType();
|
||||
}
|
||||
}
|
||||
|
||||
public List<Variable> getGlobalVariables() {
|
||||
if (Application.gameData.getGlobal().getVariables() == null) {
|
||||
return Collections.emptyList();
|
||||
} else {
|
||||
return Application.gameData.getGlobal().getVariables().getVariable();
|
||||
}
|
||||
}
|
||||
|
||||
public List<Variable> getVariablesByType(String type) {
|
||||
return getGlobalVariables().stream().filter(
|
||||
(Variable v) -> {
|
||||
return v.getType().equals(type);
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void log(String message) {
|
||||
System.out.println(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,11 +3,8 @@ package org.badvision.outlaweditor.ui;
|
|||
import java.net.URL;
|
||||
import java.util.ListResourceBundle;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.concurrent.Worker.State;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
|
@ -107,7 +104,7 @@ public class MythosScriptEditorController
|
|||
editorView.getEngine().executeScript(loadScript);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
editorView.getEngine().setPromptHandler((PromptData prompt) -> {
|
||||
TextInputDialog dialog = new TextInputDialog(prompt.getDefaultValue());
|
||||
dialog.setTitle("MythosScript Editor");
|
||||
|
|
|
@ -74,6 +74,40 @@
|
|||
<xs:complexType name="global">
|
||||
<xs:sequence>
|
||||
<xs:element name="scripts" type="tns:scripts"/>
|
||||
<xs:element name="userTypes" minOccurs="0" maxOccurs="1">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="userType" minOccurs="0" maxOccurs="unbounded">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="attribute" minOccurs="1" maxOccurs="unbounded">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="name" use="required" type="xs:NCName"/>
|
||||
<xs:attribute name="type" use="required" type="xs:NMTOKEN"/>
|
||||
<xs:attribute name="comment" type="xs:string"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="name" use="required" type="xs:NCName"/>
|
||||
<xs:attribute name="comment" use="required" type="xs:string"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="variables">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="variable" minOccurs="0" maxOccurs="unbounded">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="name" use="required" type="xs:NCName"/>
|
||||
<xs:attribute name="type" use="required" type="xs:NMTOKEN"/>
|
||||
<xs:attribute name="comment" type="xs:string"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="scripts">
|
||||
|
|
|
@ -24,38 +24,148 @@ 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.editor.log("Add global variables");
|
||||
Mythos.addVariablesFromGlobalScope();
|
||||
// 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");
|
||||
Blockly.mainWorkspace.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) {
|
||||
// Mythos.editor.log(list.toString());
|
||||
if (list && list.length > 0) {
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
func(list[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.getAttributeDropdoen(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.getAttributeDropdoen(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);
|
||||
},
|
||||
addVariablesFromGlobalScope: function () {
|
||||
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());
|
||||
});
|
||||
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;
|
||||
};
|
||||
},
|
||||
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);
|
||||
Blockly.blocks['global_' + func.getName()] = {
|
||||
init: function () {
|
||||
this.setColour(250);
|
||||
this.appendDummyInput()
|
||||
.appendField("Global " + func.getName());
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
});
|
||||
},
|
||||
addVariablesFromLocalScope: function() {
|
||||
|
||||
addVariablesFromLocalScope: function () {
|
||||
|
||||
},
|
||||
addFunctionsFromLocalScope: function() {
|
||||
var toolbarCategory = document.getElementById("localFunctions");
|
||||
|
||||
addFunctionsFromLocalScope: function () {
|
||||
// var toolbarCategory = document.getElementById("localFunctions");
|
||||
|
||||
},
|
||||
initBlocks: function () {
|
||||
Blockly.Blocks['flow_for'] = {
|
||||
|
@ -162,7 +272,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 +492,4 @@ if (typeof Mythos === "undefined") {
|
|||
}
|
||||
};
|
||||
}
|
||||
;
|
||||
;
|
||||
|
|
Loading…
Reference in New Issue
Block a user