Global functions now show up!!

This commit is contained in:
Brendan Robert
2015-06-22 02:14:12 -05:00
parent 2cb2135810
commit f94e2beeb7
3 changed files with 14 additions and 8 deletions

View File

@@ -3,6 +3,7 @@ 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;
@@ -139,7 +140,7 @@ public class MythosEditor {
public List<Script> getGlobalFunctions() {
if (Application.gameData.getGlobal().getScripts() == null) {
return Collections.emptyList();
return new ArrayList<>();
} else {
List<Script> scripts = Application.gameData.getGlobal().getScripts().getScript();
List<Script> filteredList = scripts.stream().filter((Script s) -> {
@@ -151,7 +152,7 @@ public class MythosEditor {
public List<UserType> getUserTypes() {
if (Application.gameData.getGlobal().getUserTypes() == null) {
return Collections.emptyList();
return new ArrayList<>();
} else {
return Application.gameData.getGlobal().getUserTypes().getUserType();
}
@@ -159,7 +160,7 @@ public class MythosEditor {
public List<Variable> getGlobalVariables() {
if (Application.gameData.getGlobal().getVariables() == null) {
return Collections.emptyList();
return new ArrayList<>();
} else {
return Application.gameData.getGlobal().getVariables().getVariable();
}

View File

@@ -86,7 +86,7 @@
<script>
Mythos.initBlocks();
Blockly.inject(document.getElementById('blocklyDiv'),
Mythos.workspace = Blockly.inject(document.getElementById('blocklyDiv'),
{path: '../../', toolbox: document.getElementById('toolbox')});
</script>

View File

@@ -36,15 +36,18 @@ if (typeof Mythos === "undefined") {
// Mythos.editor.log("Add local functions");
Mythos.addFunctionsFromLocalScope();
// Mythos.editor.log("Reinitalizing toolbox");
Blockly.mainWorkspace.updateToolbox(document.getElementById('toolbox'));
Mythos.workspace.updateToolbox(document.getElementById('toolbox'));
// Mythos.editor.log("Done");
},
each: function (list, func) {
// Mythos.editor.log(list.toString());
if (list && list.length > 0) {
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));
}
}
},
addUserDefinedTypes: function () {
@@ -146,10 +149,11 @@ 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()] = {
Blockly.Blocks['global_' + func.getName()] = {
init: function () {
this.setColour(250);
this.appendDummyInput()
@@ -159,6 +163,7 @@ if (typeof Mythos === "undefined") {
}
};
});
Mythos.editor.log(toolbarCategory.outerHTML);
},
addVariablesFromLocalScope: function () {