Archive eaglerforge-builder (tool, 1.8.8, clean)
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
# EaglerForgeBuilderNew
|
||||
## [Try it here](https://eaglerforge.github.io/EaglerForgeBuilderNew/)
|
||||
|
||||
This is a complete rewrite and redesign of @OeildeLynx31's [eaglerforge builder](https://eaglerforge-builder.vercel.app/) [(repo)](https://github.com/OeildeLynx31/eaglerforge-builder), a tool that allows you to easily develop [Eaglercraft](https://git.eaglercraft.rip/eaglercraft/eaglercraft-1.8/src/branch/main/README.md) mods using the EaglerForge modding API.
|
||||
|
||||
This rewrite brings a lot of new features and changes, such as moving to a higher-level system where you add modules which you then customise. (eg: add an item and then modify it's behaviour or texture.)\
|
||||
You can use blocks to write custom event handlers, which you can select in your module.
|
||||
|
||||
### Changes
|
||||
- Now using the new [EaglerForgeInjector](https://github.com/eaglerforge/EaglerForgeInjector/) API architecture rather than [Legacy](https://github.com/eaglerforge/EaglerForge-old)
|
||||
- Mods are now no longer limited to being client-side only.
|
||||
- You can now easily add blocks, items, commands and recipes.
|
||||
- Dark mode
|
||||
- Higher-level design
|
||||
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:bx="https://boxy-svg.com" style="background-color: rgb(20,20,20);" viewBox="0 0 500 500">
|
||||
<path d="M 500 0 L 500 500 L 0 500 L 500 0 Z" style="fill: rgb(218, 218, 218); stroke: rgb(0, 0, 0);" bx:shape="triangle 0 0 500 500 1 0 1@936b7950"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 295 B |
@@ -0,0 +1,15 @@
|
||||
const BLOCK_LIBMAP = {};
|
||||
var oldDefineBlocks = Blockly.common.defineBlocks;
|
||||
Blockly.common.defineBlocks = function (blockMap) {
|
||||
var types = Object.keys(blockMap);
|
||||
types.forEach(type => {
|
||||
BLOCK_LIBMAP[type] = (blockMap[type].libs || []);
|
||||
});
|
||||
return oldDefineBlocks.apply(this, [blockMap]);
|
||||
}
|
||||
function getBlockLibs(block) {
|
||||
return BLOCK_LIBMAP[block.type] || [];
|
||||
}
|
||||
function getBlockLibsByType(blockType) {
|
||||
return BLOCK_LIBMAP[blockType] || [];
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
const enumaction = {
|
||||
init: function () {
|
||||
this.appendDummyInput('VAR')
|
||||
.appendField('[1.12] EnumAction')
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
['PASS', 'PASS'],
|
||||
['SUCCESS', 'SUCCESS'],
|
||||
['FAIL', 'FAIL']
|
||||
]), 'NAME');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, null);
|
||||
this.setTooltip('Creates an EnumAction for 1.12 handlers.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(120);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ enumaction: enumaction });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['enumaction'] = function () {
|
||||
const enumaction = this.getFieldValue('NAME');
|
||||
|
||||
|
||||
return [`(ModAPI.reflect.getClassByName("EnumActionResult").staticVariables.${enumaction})`, javascript.Order.NONE]
|
||||
}
|
||||
|
||||
|
||||
const actionresult = {
|
||||
init: function () {
|
||||
this.appendValueInput('OBJ')
|
||||
.appendField('[1.12] ActionResult of');
|
||||
this.appendDummyInput('VAR')
|
||||
.appendField('mode:')
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
['PASS', 'PASS'],
|
||||
['SUCCESS', 'SUCCESS'],
|
||||
['FAIL', 'FAIL']
|
||||
]), 'NAME');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, null);
|
||||
this.setTooltip('Checks if a global is defined.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(120);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ actionresult: actionresult });
|
||||
javascript.javascriptGenerator.forBlock['actionresult'] = function () {
|
||||
const object = generator.valueToCode(block, 'OBJ', javascript.Order.ATOMIC);
|
||||
const mode = block.getFieldValue('NAME');
|
||||
|
||||
return [`(ModAPI.reflect.getClassByName("ActionResult").constructors[0](ModAPI.reflect.getClassByName("EnumActionResult").staticVariables.${mode}, ${object}))`, javascript.Order.NONE];
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
const blockpos_getxyz = {
|
||||
init: function () {
|
||||
this.appendDummyInput('TAB')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
['x', '$x'],
|
||||
['y', '$y'],
|
||||
['z', '$z']
|
||||
]), 'TAB');
|
||||
this.appendValueInput('VALUE')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('component of BlockPos');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, "Number");
|
||||
this.setTooltip('Get a component of a block pos');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/util/BlockPos.html');
|
||||
this.setColour(270);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ blockpos_getxyz: blockpos_getxyz });
|
||||
|
||||
|
||||
|
||||
javascript.javascriptGenerator.forBlock['blockpos_getxyz'] = function () {
|
||||
const dropdown_tab = this.getFieldValue('TAB');
|
||||
const value_value = javascript.javascriptGenerator.valueToCode(this, 'VALUE', javascript.Order.ATOMIC);
|
||||
|
||||
const code = `(${value_value})["${dropdown_tab}"]`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
|
||||
const blockpos_fromxyz = {
|
||||
init: function () {
|
||||
this.appendValueInput('X')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.setCheck('Number')
|
||||
.appendField('Make BlockPos from x:');
|
||||
this.appendValueInput('Y')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.setCheck('Number')
|
||||
.appendField('y:');
|
||||
this.appendValueInput('Z')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.setCheck('Number')
|
||||
.appendField('z:');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, null);
|
||||
this.setTooltip('Create a BlockPos from components');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/util/BlockPos.html');
|
||||
this.setColour(270);
|
||||
},
|
||||
libs: ["construct_blockpos"]
|
||||
};
|
||||
Blockly.common.defineBlocks({ blockpos_fromxyz: blockpos_fromxyz });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['blockpos_fromxyz'] = function () {
|
||||
const value_x = javascript.javascriptGenerator.valueToCode(this, 'X', javascript.Order.ATOMIC);
|
||||
const value_y = javascript.javascriptGenerator.valueToCode(this, 'Y', javascript.Order.ATOMIC);
|
||||
const value_z = javascript.javascriptGenerator.valueToCode(this, 'Z', javascript.Order.ATOMIC);
|
||||
|
||||
const code = `efb2__makeBlockPos(Math.floor(${value_x}),Math.floor(${value_y}),Math.floor(${value_z}))`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
@@ -0,0 +1,312 @@
|
||||
registerHandler("BlockConstructor", "block constructor", {}, function () {
|
||||
this.setTooltip('Runs when the block type is initialised.\nNo return value expected.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(0);
|
||||
});
|
||||
|
||||
|
||||
const blocks_blockproperty = {
|
||||
init: function () {
|
||||
this.appendDummyInput('PROPERTY')
|
||||
.appendField('set block')
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
['slipperiness', 'slipperiness'],
|
||||
['light opacity', 'lightOpacity'],
|
||||
['light value', 'lightValue'],
|
||||
['blast resistance', 'blockResistance'],
|
||||
['hardness', 'blockHardness']
|
||||
]), 'PROPERTY');
|
||||
this.appendValueInput('VALUE')
|
||||
.setCheck('Number')
|
||||
.appendField('to');
|
||||
this.setInputsInline(true)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(0);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ blocks_blockproperty: blocks_blockproperty });
|
||||
javascript.javascriptGenerator.forBlock['blocks_blockproperty'] = function () {
|
||||
const dropdown_property = this.getFieldValue('PROPERTY');
|
||||
const value_value = javascript.javascriptGenerator.valueToCode(this, 'VALUE', javascript.Order.ATOMIC);
|
||||
const code = `this["$${dropdown_property}"] = ${value_value};`;
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const blocks_blockswitch = {
|
||||
init: function () {
|
||||
this.appendDummyInput('PROPERTY')
|
||||
.appendField('set block')
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
['full block', 'fullBlock'],
|
||||
['translucent', 'translucent'],
|
||||
['use neighbor brightness', 'useNeighborBrightness'],
|
||||
['needs random tick', 'needsRandomTick']
|
||||
]), 'PROPERTY');
|
||||
this.appendDummyInput('VALUE')
|
||||
.setAlign(Blockly.inputs.Align.CENTRE)
|
||||
.appendField('to')
|
||||
.appendField(new Blockly.FieldCheckbox('TRUE'), 'VALUE');
|
||||
this.setInputsInline(true)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(0);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ blocks_blockswitch: blocks_blockswitch });
|
||||
javascript.javascriptGenerator.forBlock['blocks_blockswitch'] = function () {
|
||||
const dropdown_property = this.getFieldValue('PROPERTY');
|
||||
const checkbox_value = this.getFieldValue('VALUE') ? 1 : 0;
|
||||
const code = `this["$${dropdown_property}"] = ${checkbox_value};`;
|
||||
return code;
|
||||
}
|
||||
|
||||
registerHandler("BlockBreak", "block break", {
|
||||
"WORLD": "world",
|
||||
"BLOCKPOS": "blockpos",
|
||||
"$$blockstate": null
|
||||
}, function () {
|
||||
this.setTooltip('Runs when the block is removed from the world.\nNo return value expected.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(0);
|
||||
});
|
||||
|
||||
|
||||
registerHandler("BlockAdded", "block added", {
|
||||
"WORLD": "world",
|
||||
"BLOCKPOS": "blockpos",
|
||||
"$$blockstate": null
|
||||
}, function () {
|
||||
this.setTooltip('Runs when the block is added to the world.\nNo return value expected.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(0);
|
||||
});
|
||||
|
||||
|
||||
registerHandler("BlockNeighbourChange", "block neighbor update", {
|
||||
"WORLD": "world",
|
||||
"BLOCKPOS": "blockpos",
|
||||
"$$blockstate": null
|
||||
}, function () {
|
||||
this.setTooltip('Runs when a block\'s neighbor is changed.\nNo return value expected.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(0);
|
||||
});
|
||||
|
||||
registerHandler("BlockBrokenByPlayer", "block broken by player", {
|
||||
"WORLD": "world",
|
||||
"BLOCKPOS": "blockpos",
|
||||
"$$blockstate": null
|
||||
}, function () {
|
||||
this.setTooltip('Runs when a block is broken by a player.\nNo return value expected.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(0);
|
||||
});
|
||||
|
||||
registerHandler("BlockRandomTick", "block random tick", {
|
||||
"WORLD": "world",
|
||||
"BLOCKPOS": "blockpos",
|
||||
"$$blockstate": null,
|
||||
"$$random": null
|
||||
}, function () {
|
||||
this.setTooltip('Runs when a block is ticked.\nNo return value expected.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(0);
|
||||
});
|
||||
|
||||
|
||||
const blocks_block = {
|
||||
init: function () {
|
||||
this.appendDummyInput('BLOCK')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('block')
|
||||
.appendField(new Blockly.FieldMinecraftItemInput(true, true), 'BLOCK');
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, null);
|
||||
this.setTooltip('Returns an Block instance (for comparisons)');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(0);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ blocks_block: blocks_block });
|
||||
javascript.javascriptGenerator.forBlock['blocks_block'] = function () {
|
||||
const block_primitive = this.getFieldValue('BLOCK');
|
||||
const object = {
|
||||
id: block_primitive.split("/")[1].split("@")[0]
|
||||
}
|
||||
return [`(ModAPI.blocks["${object.id}"]?.getRef() || null)`, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
const blocks_currentblock = {
|
||||
init: function () {
|
||||
this.appendDummyInput('BLOCK')
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField('current block')
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, null);
|
||||
this.setTooltip('The current Block that the handler is executing on.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(0);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ blocks_currentblock: blocks_currentblock });
|
||||
javascript.javascriptGenerator.forBlock['blocks_currentblock'] = function () {
|
||||
return [`$$nmb_AdvancedBlock`, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
const blocks_boundingbox = {
|
||||
init: function () {
|
||||
this.appendDummyInput('MIN')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('Set block bounds to min:')
|
||||
.appendField(new Blockly.FieldNumber(0), 'MINX')
|
||||
.appendField(new Blockly.FieldNumber(0), 'MINY')
|
||||
.appendField(new Blockly.FieldNumber(0), 'MINZ');
|
||||
this.appendDummyInput('MAX')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('max:')
|
||||
.appendField(new Blockly.FieldNumber(1), 'MAXX')
|
||||
.appendField(new Blockly.FieldNumber(1), 'MAXY')
|
||||
.appendField(new Blockly.FieldNumber(1), 'MAXZ');
|
||||
this.setInputsInline(false)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Sets the block\'s bounding box');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(0);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ blocks_boundingbox: blocks_boundingbox });
|
||||
javascript.javascriptGenerator.forBlock['blocks_boundingbox'] = function () {
|
||||
const number_minx = this.getFieldValue('MINX');
|
||||
const number_miny = this.getFieldValue('MINY');
|
||||
const number_minz = this.getFieldValue('MINZ');
|
||||
const number_maxx = this.getFieldValue('MAXX');
|
||||
const number_maxy = this.getFieldValue('MAXY');
|
||||
const number_maxz = this.getFieldValue('MAXZ');
|
||||
const code = `this.$setBlockBounds(${number_minx}, ${number_miny}, ${number_minz}, ${number_maxx}, ${number_maxy}, ${number_maxz});`;
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const blocks_creativetab = {
|
||||
init: function () {
|
||||
this.appendDummyInput('TAB')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('Set block creative tab to')
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
["tabBlock", "tabBlock"],
|
||||
["tabDecorations", "tabDecorations"],
|
||||
["tabRedstone", "tabRedstone"],
|
||||
["tabTransport", "tabTransport"],
|
||||
["tabMisc", "tabMisc"],
|
||||
["tabAllSearch", "tabAllSearch"],
|
||||
["tabFood", "tabFood"],
|
||||
["tabTools", "tabTools"],
|
||||
["tabCombat", "tabCombat"],
|
||||
["tabBrewing", "tabBrewing"],
|
||||
["tabMaterials", "tabMaterials"],
|
||||
["tabInventory", "tabInventory"]
|
||||
]), 'TAB');
|
||||
this.setInputsInline(false)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Set the creative tab of the block');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(0);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ blocks_creativetab: blocks_creativetab });
|
||||
javascript.javascriptGenerator.forBlock['blocks_creativetab'] = function () {
|
||||
let dropdown_tab = this.getFieldValue('TAB');
|
||||
if (flags.target === "1_12") {
|
||||
dropdown_tab = dropdown_tab.replace("tab", "").toUpperCase();
|
||||
}
|
||||
const code = `this.$setCreativeTab(ModAPI.reflect.getClassById("net.minecraft.creativetab.CreativeTabs").staticVariables.${dropdown_tab});`;
|
||||
return code;
|
||||
}
|
||||
|
||||
registerHandler("BlockEntityCollision", "block entity collision", {
|
||||
"WORLD": "world",
|
||||
"BLOCKPOS": "blockpos",
|
||||
"ENTITY": "entity",
|
||||
}, function () {
|
||||
this.setTooltip('Runs when an entity collides with the block.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(0);
|
||||
});
|
||||
|
||||
registerHandler("BlockGetDroppedItem", "block get dropped item", {
|
||||
"$$blockstate": null,
|
||||
"$$random": null,
|
||||
"FORTURE": "forture",
|
||||
}, function () {
|
||||
this.setTooltip('Runs when a block is broken to get the dropped item.\nItem return value expected.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(0);
|
||||
});
|
||||
|
||||
registerHandler("BlockQuantityDropped", "block get dropped quantity", {
|
||||
"FORTURE": "forture",
|
||||
"$$random": null,
|
||||
}, function () {
|
||||
this.setTooltip('Runs when a block is broken to get the dropped quantity.\nInteger return value expected.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(0);
|
||||
});
|
||||
|
||||
|
||||
const blocks_setsoundtype = {
|
||||
init: function () {
|
||||
this.appendDummyInput('S')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('Set block sound type to')
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
["wood", "wood"],
|
||||
["ground", "ground"],
|
||||
["plant", "plant"],
|
||||
["stone", "stone"],
|
||||
["metal", "metal"],
|
||||
["glass", "glass"],
|
||||
["cloth", "cloth"],
|
||||
["sand", "sand"],
|
||||
["snow", "snow"],
|
||||
["ladder", "ladder"],
|
||||
["anvil", "anvil"],
|
||||
["slime", "slime"]
|
||||
]), 'S');
|
||||
this.setInputsInline(false)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Set the sound type of the block');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(0);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ blocks_setsoundtype: blocks_setsoundtype });
|
||||
javascript.javascriptGenerator.forBlock['blocks_setsoundtype'] = function () {
|
||||
let dropdown_tab = this.getFieldValue('S');
|
||||
if (flags.target !== "1_12") {
|
||||
dropdown_tab = dropdown_tab.replaceAll("ground", "gravel");
|
||||
if (dropdown_tab === "slime") {
|
||||
dropdown_tab = "SLIME_SOUND";
|
||||
} else {
|
||||
dropdown_tab = dropdown_tab[0].toUpperCase() + dropdown_tab.slice(1);
|
||||
dropdown_tab = "soundType" + dropdown_tab;
|
||||
}
|
||||
} else {
|
||||
dropdown_tab = dropdown_tab.toUpperCase();
|
||||
}
|
||||
const code = flags.target === "1_12"
|
||||
? `this.$setSoundType(ModAPI.blockSounds.${dropdown_tab}.getRef());`
|
||||
: `this.$setStepSound($$blockClass.staticVariables.${dropdown_tab});`;
|
||||
return code;
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
registerHandler("CommandCalled", "command called by other", {
|
||||
"ARGS": "argument list",
|
||||
"COMMAND_SENDER": "command sender",
|
||||
}, function () {
|
||||
this.setTooltip('Runs when the command is called by a non-player.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(0);
|
||||
});
|
||||
|
||||
registerHandler("CommandCalledByPlayer", "command called by player", {
|
||||
"ARGS": "argument list",
|
||||
"player": "player",
|
||||
"COMMAND_SENDER": "command sender",
|
||||
}, function () {
|
||||
this.setTooltip('Runs when the command is called by a player.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(0);
|
||||
});
|
||||
|
||||
|
||||
const command_sendmessage = {
|
||||
libs: ["message_command_sender"],
|
||||
init: function () {
|
||||
this.appendValueInput('MESSAGE')
|
||||
.setCheck('String')
|
||||
.appendField('send message');
|
||||
this.appendValueInput('SENDER')
|
||||
.appendField('to command sender');
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Sends a message to the specified command sender.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(0);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ command_sendmessage: command_sendmessage });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['command_sendmessage'] = function () {
|
||||
const value_message = javascript.javascriptGenerator.valueToCode(this, 'MESSAGE', javascript.Order.ATOMIC);
|
||||
const value_sender = javascript.javascriptGenerator.valueToCode(this, 'SENDER', javascript.Order.ATOMIC);
|
||||
const code = `efb2__messageCommandSender(${value_sender}, ${value_message});`;
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const command_get_position = {
|
||||
init: function () {
|
||||
this.appendValueInput('CMDSENDER')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('get position of command sender');
|
||||
this.appendDummyInput('AS')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('as')
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
['BlockPos', '$getPosition'],
|
||||
['Vec3', '$getPositionVector']
|
||||
]), 'AS');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, null);
|
||||
this.setTooltip('Gets the command sender\'s position object.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(0);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ command_get_position: command_get_position });
|
||||
javascript.javascriptGenerator.forBlock['command_get_position'] = function () {
|
||||
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'CMDSENDER', javascript.Order.ATOMIC);
|
||||
const dropdown_as = this.getFieldValue('AS');
|
||||
const code = `(${value_entity})["${dropdown_as}"]()`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
|
||||
const command_get_world = {
|
||||
init: function () {
|
||||
this.appendValueInput('CMDSENDER')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('get world of command sender');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, null);
|
||||
this.setTooltip('Gets the command sender\'s world object.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(0);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ command_get_world: command_get_world });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['command_get_world'] = function () {
|
||||
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'CMDSENDER', javascript.Order.ATOMIC);
|
||||
const code = `(${value_entity}).$getEntityWorld()`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
const command_get_entity = {
|
||||
init: function () {
|
||||
this.appendValueInput('CMDSENDER')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('get command sender as entity');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, null);
|
||||
this.setTooltip('Gets the command sender as an entity. May be null.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(0);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ command_get_entity: command_get_entity });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['command_get_entity'] = function () {
|
||||
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'CMDSENDER', javascript.Order.ATOMIC);
|
||||
const code = `(${value_entity}).$getCommandSenderEntity()`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
const command_get_name = {
|
||||
init: function () {
|
||||
this.appendValueInput('CMDSENDER')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('get name of command sender');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, null);
|
||||
this.setTooltip('Gets the command sender\'s name.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(0);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ command_get_name: command_get_name });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['command_get_name'] = function () {
|
||||
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'CMDSENDER', javascript.Order.ATOMIC);
|
||||
const code = `ModAPI.util.ustr((${value_entity}).$getName())`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
registerHandler("CraftingRecipeModifyResult", "crafting recipe modify item", {
|
||||
"ITEMSTACK": "itemstack",
|
||||
}, function () {
|
||||
this.setTooltip('Runs when registering the command to modify the output item. Does not expect a return value.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(15);
|
||||
});
|
||||
@@ -0,0 +1,77 @@
|
||||
const debug_log = {
|
||||
init: function () {
|
||||
this.appendValueInput('NAME')
|
||||
.appendField('log to console');
|
||||
this.setInputsInline(true)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Logs the string/object provided to the console. ');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(270);
|
||||
},
|
||||
libs: ["java_logger"]
|
||||
};
|
||||
Blockly.common.defineBlocks({ debug_log: debug_log });
|
||||
javascript.javascriptGenerator.forBlock['debug_log'] = function () {
|
||||
const log = javascript.javascriptGenerator.valueToCode(this, 'NAME', javascript.Order.ATOMIC);
|
||||
const code = `efb2__jlog(${log});`;
|
||||
return code;
|
||||
}
|
||||
|
||||
const debug_warn = {
|
||||
init: function () {
|
||||
this.appendValueInput('NAME')
|
||||
.appendField('warn to console');
|
||||
this.setInputsInline(true)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Logs the string/object provided to the console as a warning. ');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(270);
|
||||
},
|
||||
libs: ["java_logger"]
|
||||
};
|
||||
Blockly.common.defineBlocks({ debug_warn: debug_warn });
|
||||
javascript.javascriptGenerator.forBlock['debug_warn'] = function () {
|
||||
const log = javascript.javascriptGenerator.valueToCode(this, 'NAME', javascript.Order.ATOMIC);
|
||||
const code = `efb2__jwarn(${log});`;
|
||||
return code;
|
||||
}
|
||||
|
||||
const debug_err = {
|
||||
init: function () {
|
||||
this.appendValueInput('NAME')
|
||||
.appendField('error to console');
|
||||
this.setInputsInline(true)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Logs the string/object provided to the console as an error. ');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(270);
|
||||
},
|
||||
libs: ["java_logger"]
|
||||
};
|
||||
Blockly.common.defineBlocks({ debug_err: debug_err });
|
||||
javascript.javascriptGenerator.forBlock['debug_err'] = function () {
|
||||
const log = javascript.javascriptGenerator.valueToCode(this, 'NAME', javascript.Order.ATOMIC);
|
||||
const code = `efb2__jerr(${log});`;
|
||||
return code;
|
||||
}
|
||||
|
||||
const debug_debugger = {
|
||||
init: function () {
|
||||
this.appendDummyInput('NAME')
|
||||
.appendField('debugger');
|
||||
this.setInputsInline(true)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('If devtools is open, pauses code execution at this position.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(270);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ debug_debugger: debug_debugger });
|
||||
javascript.javascriptGenerator.forBlock['debug_debugger'] = function () {
|
||||
const code = `debugger;`;
|
||||
return code;
|
||||
}
|
||||
@@ -0,0 +1,407 @@
|
||||
const ENTITY_NUMERICAL_PROPS = [
|
||||
['x', '$posX'],
|
||||
['y', '$posY'],
|
||||
['z', '$posZ'],
|
||||
['x velocity', '$motionX'],
|
||||
['y velocity', '$motionY'],
|
||||
['z velocity', '$motionZ'],
|
||||
['yaw', '$rotationYaw'],
|
||||
['pitch', '$rotationPitch'],
|
||||
['fallDistance', '$fallDistance'],
|
||||
['stepHeight', '$stepHeight'],
|
||||
['age (ticks)', '$ticksExisted'],
|
||||
['fire time (ticks)', '$fire'],
|
||||
['chunk x', '$chunkCoordX'],
|
||||
['chunk y', '$chunkCoordY'],
|
||||
['chunk z', '$chunkCoordZ'],
|
||||
['dimension', '$dimension'],
|
||||
['collision reduction', "$entityCollisionReduction"]
|
||||
];
|
||||
const ENTITY_BOOLEAN_PROPS = [
|
||||
['on ground', '$onGround'],
|
||||
['collided horizontally', '$isCollidedHorizontally'],
|
||||
['collided vertically', '$isCollidedVertically'],
|
||||
['collided', '$isCollided'],
|
||||
['is in web', '$isInWeb'],
|
||||
['is outside border', '$isOutsideBorder'],
|
||||
['is dead', '$isDead'],
|
||||
['no clip', '$noClip'],
|
||||
['in water', '$inWater'],
|
||||
['is immune to fire', '$isImmuneToFire'],
|
||||
['in portal', '$inPortal'],
|
||||
['invulnerable', '$invulnerable']
|
||||
];
|
||||
|
||||
|
||||
const entity_set_position = {
|
||||
init: function () {
|
||||
this.appendValueInput('ENTITY')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('set position of entity');
|
||||
this.appendValueInput('POS')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('to Vec3');
|
||||
this.setInputsInline(true)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Sets the position of the entity to a vector, and sends a packet.');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/entity/Entity.html');
|
||||
this.setColour(30);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ entity_set_position: entity_set_position });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['entity_set_position'] = function () {
|
||||
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'ENTITY', javascript.Order.ATOMIC);
|
||||
const value_pos = javascript.javascriptGenerator.valueToCode(this, 'POS', javascript.Order.ATOMIC);
|
||||
const code = `var $$efb_vec3pos = ${value_pos};(${value_entity}).$setPositionAndUpdate($$efb_vec3pos.$xCoord,$$efb_vec3pos.$yCoord,$$efb_vec3pos.$zCoord)`;
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
const entity_set_position_xyz = {
|
||||
init: function () {
|
||||
this.appendValueInput('ENTITY')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('set position of entity');
|
||||
this.appendValueInput('X')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('to X:');
|
||||
this.appendValueInput('Y')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('Y:');
|
||||
this.appendValueInput('Z')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('Z:');
|
||||
this.setInputsInline(true)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Sets the position of the entity to a vector, and sends a packet.');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/entity/Entity.html');
|
||||
this.setColour(30);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ entity_set_position_xyz: entity_set_position_xyz });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['entity_set_position_xyz'] = function () {
|
||||
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'ENTITY', javascript.Order.ATOMIC);
|
||||
const value_X = javascript.javascriptGenerator.valueToCode(this, 'X', javascript.Order.ATOMIC);
|
||||
const value_Y = javascript.javascriptGenerator.valueToCode(this, 'Y', javascript.Order.ATOMIC);
|
||||
const value_Z = javascript.javascriptGenerator.valueToCode(this, 'Z', javascript.Order.ATOMIC);
|
||||
const code = `(${value_entity}).$setPositionAndUpdate(${value_X},${value_Y},${value_Z})`;
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const entity_get_prop = {
|
||||
init: function () {
|
||||
this.appendDummyInput('PROP')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(new Blockly.FieldDropdown(ENTITY_NUMERICAL_PROPS), 'PROP');
|
||||
this.appendValueInput('ENTITY')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('of entity');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, "Number");
|
||||
this.setTooltip('Gets a property of the entity. yaw and pitch are in radians, not degrees.');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/entity/Entity.html');
|
||||
this.setColour(30);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ entity_get_prop: entity_get_prop });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['entity_get_prop'] = function () {
|
||||
const dropdown_prop = this.getFieldValue('PROP');
|
||||
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'ENTITY', javascript.Order.ATOMIC);
|
||||
const code = `(${value_entity})["${dropdown_prop}"]`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
|
||||
const entity_set_prop = {
|
||||
init: function () {
|
||||
this.appendDummyInput('PROP')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('set')
|
||||
.appendField(new Blockly.FieldDropdown(ENTITY_NUMERICAL_PROPS), 'PROP');
|
||||
this.appendValueInput('ENTITY')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('of entity');
|
||||
this.appendValueInput('VALUE')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.setCheck('Number')
|
||||
.appendField('to');
|
||||
this.setInputsInline(true)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Sets a property of the entity. yaw and pitch are in radians, not degrees.');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/entity/Entity.html');
|
||||
this.setColour(30);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ entity_set_prop: entity_set_prop });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['entity_set_prop'] = function () {
|
||||
const dropdown_prop = this.getFieldValue('PROP');
|
||||
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'ENTITY', javascript.Order.ATOMIC);
|
||||
const value_value = javascript.javascriptGenerator.valueToCode(this, 'VALUE', javascript.Order.ATOMIC);
|
||||
const code = `(${value_entity})["${dropdown_prop}"] = ${value_value};`;
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
const entity_set_switch = {
|
||||
init: function () {
|
||||
this.appendDummyInput('PROP')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('set boolean')
|
||||
.appendField(new Blockly.FieldDropdown(ENTITY_BOOLEAN_PROPS), 'PROP');
|
||||
this.appendValueInput('ENTITY')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('of entity');
|
||||
this.appendValueInput('VALUE')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.setCheck('Boolean')
|
||||
.appendField('to');
|
||||
this.setInputsInline(true)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Sets a boolean property of the entity.');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/entity/Entity.html');
|
||||
this.setColour(30);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ entity_set_switch: entity_set_switch });
|
||||
javascript.javascriptGenerator.forBlock['entity_set_switch'] = function () {
|
||||
const dropdown_prop = this.getFieldValue('PROP');
|
||||
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'ENTITY', javascript.Order.ATOMIC);
|
||||
const value_value = javascript.javascriptGenerator.valueToCode(this, 'VALUE', javascript.Order.ATOMIC);
|
||||
const code = `(${value_entity})["${dropdown_prop}"] = ((${value_value}) ? 1 : 0);`;
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const entity_get_switch = {
|
||||
init: function () {
|
||||
this.appendDummyInput('PROP')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(new Blockly.FieldDropdown(ENTITY_BOOLEAN_PROPS), 'PROP');
|
||||
this.appendValueInput('ENTITY')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('of entity');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, 'Boolean');
|
||||
this.setTooltip('Sets a boolean property of the entity.');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/entity/Entity.html');
|
||||
this.setColour(30);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ entity_get_switch: entity_get_switch });
|
||||
javascript.javascriptGenerator.forBlock['entity_get_switch'] = function () {
|
||||
const dropdown_prop = this.getFieldValue('PROP');
|
||||
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'ENTITY', javascript.Order.ATOMIC);
|
||||
const code = `((${value_entity})["${dropdown_prop}"] ? true : false)`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
|
||||
const entity_get_world = {
|
||||
init: function () {
|
||||
this.appendValueInput('ENTITY')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('get world of entity');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, null);
|
||||
this.setTooltip('Gets the entity\'s world object.');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/entity/Entity.html');
|
||||
this.setColour(30);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ entity_get_world: entity_get_world });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['entity_get_world'] = function () {
|
||||
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'ENTITY', javascript.Order.ATOMIC);
|
||||
const code = `(${value_entity}).$worldObj`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
|
||||
const entity_get_position = {
|
||||
init: function () {
|
||||
this.appendValueInput('ENTITY')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('get position of entity');
|
||||
this.appendDummyInput('AS')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('as')
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
['BlockPos', '$getPosition'],
|
||||
['Vec3', '$getPositionVector']
|
||||
]), 'AS');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, null);
|
||||
this.setTooltip('Gets the entity\'s position object.');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/entity/Entity.html');
|
||||
this.setColour(30);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ entity_get_position: entity_get_position });
|
||||
javascript.javascriptGenerator.forBlock['entity_get_position'] = function () {
|
||||
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'ENTITY', javascript.Order.ATOMIC);
|
||||
const dropdown_as = this.getFieldValue('AS');
|
||||
const code = `(${value_entity})["${dropdown_as}"]()`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
|
||||
const entity_distance = {
|
||||
init: function () {
|
||||
this.appendValueInput('A')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('distance from entity');
|
||||
this.appendValueInput('B')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('to entity');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, 'Number');
|
||||
this.setTooltip('Get the distance between two entities');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/entity/Entity.html');
|
||||
this.setColour(30);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ entity_distance: entity_distance });
|
||||
javascript.javascriptGenerator.forBlock['entity_distance'] = function () {
|
||||
const value_a = javascript.javascriptGenerator.valueToCode(this, 'A', javascript.Order.ATOMIC);
|
||||
const value_b = javascript.javascriptGenerator.valueToCode(this, 'B', javascript.Order.ATOMIC);
|
||||
const code = `(${value_a}).$getDistanceToEntity(${value_b})`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
|
||||
const entity_distance_vec3 = {
|
||||
init: function () {
|
||||
this.appendValueInput('A')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('distance from entity');
|
||||
this.appendValueInput('B')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('to Vec3');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, 'Number');
|
||||
this.setTooltip('Get the distance from an entity to a Vec3 position');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/entity/Entity.html');
|
||||
this.setColour(30);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ entity_distance_vec3: entity_distance_vec3 });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['entity_distance_vec3'] = function () {
|
||||
const value_a = javascript.javascriptGenerator.valueToCode(this, 'A', javascript.Order.ATOMIC);
|
||||
const value_b = javascript.javascriptGenerator.valueToCode(this, 'B', javascript.Order.ATOMIC);
|
||||
const code = `(($$efb2_arg_a, $$efb2_arg_b)=>$$efb2_arg_a.$getDistance($$efb2_arg_b.$x,$$efb2_arg_b.$y,$$efb2_arg_b.$z))(${value_a}, ${value_b})`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
|
||||
const entity_get_lookvec = {
|
||||
init: function () {
|
||||
this.appendValueInput('ENTITY')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('get look vector of entity');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, 'Number');
|
||||
this.setTooltip('Gets an entity\'s look vector (Vec3)');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/entity/Entity.html');
|
||||
this.setColour(30);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ entity_get_lookvec: entity_get_lookvec });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['entity_get_lookvec'] = function () {
|
||||
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'ENTITY', javascript.Order.ATOMIC);
|
||||
const code = `(${value_entity}).$getLook(1)`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
|
||||
const entity_get_eye_pos = {
|
||||
init: function () {
|
||||
this.appendValueInput('ENTITY')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('get eye position vector of entity');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, 'Number');
|
||||
this.setTooltip('Gets an entity\'s eye position (Vec3)');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/entity/Entity.html');
|
||||
this.setColour(30);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ entity_get_eye_pos: entity_get_eye_pos });
|
||||
javascript.javascriptGenerator.forBlock['entity_get_eye_pos'] = function () {
|
||||
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'ENTITY', javascript.Order.ATOMIC);
|
||||
const code = `(${value_entity}).$getPositionEyes(1)`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
const entity_raytrace = {
|
||||
init: function () {
|
||||
this.appendValueInput('ENTITY')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('hit position from ray cast with entity');
|
||||
this.appendValueInput('DIST')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.setCheck('Number')
|
||||
.appendField('with max distance');
|
||||
this.setInputsInline(false)
|
||||
this.setOutput(true, 'Number');
|
||||
this.setTooltip('Cast a ray from an entity and return the hit position as a Vec3.');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/entity/Entity.html');
|
||||
this.setColour(30);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ entity_raytrace: entity_raytrace });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['entity_raytrace'] = function () {
|
||||
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'ENTITY', javascript.Order.ATOMIC);
|
||||
const value_dist = javascript.javascriptGenerator.valueToCode(this, 'DIST', javascript.Order.ATOMIC);
|
||||
const code = `(${value_entity}).$rayTrace((${value_dist}), 1).$hitVec`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
|
||||
const entity_setdead = {
|
||||
init: function () {
|
||||
this.appendValueInput('ENTITY')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('set entity to dead');
|
||||
this.setInputsInline(true)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Sets an entity\'s state to \'dead\'');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/entity/Entity.html');
|
||||
this.setColour(30);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ entity_setdead: entity_setdead });
|
||||
javascript.javascriptGenerator.forBlock['entity_setdead'] = function () {
|
||||
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'ENTITY', javascript.Order.ATOMIC);
|
||||
const code = `(${value_entity}).$setDead();`;
|
||||
return code;
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
const keyCodes = [
|
||||
["ANY", ""],
|
||||
["SPACE", "32"],
|
||||
["UP ARROW", "38"],
|
||||
["DOWN ARROW", "40"],
|
||||
["LEFT ARROW", "37"],
|
||||
["RIGHT ARROW", "39"],
|
||||
["A", "65"],
|
||||
["B", "66"],
|
||||
["C", "67"],
|
||||
["D", "68"],
|
||||
["E", "69"],
|
||||
["F", "70"],
|
||||
["G", "71"],
|
||||
["H", "72"],
|
||||
["I", "73"],
|
||||
["J", "74"],
|
||||
["K", "75"],
|
||||
["L", "76"],
|
||||
["M", "77"],
|
||||
["N", "78"],
|
||||
["O", "79"],
|
||||
["P", "80"],
|
||||
["Q", "81"],
|
||||
["R", "82"],
|
||||
["S", "83"],
|
||||
["T", "84"],
|
||||
["U", "85"],
|
||||
["V", "86"],
|
||||
["W", "87"],
|
||||
["X", "88"],
|
||||
["Y", "89"],
|
||||
["Z", "90"],
|
||||
["0", "48"],
|
||||
["1", "49"],
|
||||
["2", "50"],
|
||||
["3", "51"],
|
||||
["4", "52"],
|
||||
["5", "53"],
|
||||
["6", "54"],
|
||||
["7", "55"],
|
||||
["8", "56"],
|
||||
["9", "57"],
|
||||
["F1", "112"],
|
||||
["F2", "113"],
|
||||
["F3", "114"],
|
||||
["F4", "115"],
|
||||
["F5", "116"],
|
||||
["F6", "117"],
|
||||
["F7", "118"],
|
||||
["F8", "119"],
|
||||
["F9", "120"],
|
||||
["F10", "121"],
|
||||
["F11", "122"],
|
||||
["F12", "123"],
|
||||
];
|
||||
|
||||
const events_onModLoads = {
|
||||
init: function() {
|
||||
this.appendDummyInput()
|
||||
.appendField(new Blockly.FieldLabel('when all mods finished loading'));
|
||||
this.appendStatementInput('CODE')
|
||||
.setAlign(Blockly.inputs.Align.CENTRE)
|
||||
.appendField('do');
|
||||
this.setColour(55);
|
||||
this.setTooltip('Is executed when all mods finished loading.');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
const events_onClientTick = {
|
||||
init: function() {
|
||||
this.appendDummyInput()
|
||||
.appendField(new Blockly.FieldLabel('each client tick'));
|
||||
this.appendStatementInput('CODE')
|
||||
.setAlign(Blockly.inputs.Align.CENTRE)
|
||||
.appendField('do');
|
||||
this.setColour(55);
|
||||
this.setTooltip('Is executed on each client tick.');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
const events_onClientFrame = {
|
||||
init: function() {
|
||||
this.appendDummyInput()
|
||||
.appendField(new Blockly.FieldLabel('each client frame'));
|
||||
this.appendStatementInput('CODE')
|
||||
.setAlign(Blockly.inputs.Align.CENTRE)
|
||||
.appendField('do');
|
||||
this.setColour(55);
|
||||
this.setTooltip('Is executed on each client frame.');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
/*
|
||||
const events_onKeyPressed = {
|
||||
init: function() {
|
||||
this.appendDummyInput()
|
||||
.appendField('when')
|
||||
.appendField(new Blockly.FieldDropdown(keyCodes), 'KEYCODE')
|
||||
.appendField('key pressed');
|
||||
this.appendStatementInput('CODE')
|
||||
.setAlign(Blockly.inputs.Align.CENTRE)
|
||||
.appendField('do');
|
||||
this.setColour(55);
|
||||
this.setTooltip('Is executed when a key is pressed.');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
const events_onKeyReleased = {
|
||||
init: function() {
|
||||
this.appendDummyInput()
|
||||
.appendField('when')
|
||||
.appendField(new Blockly.FieldDropdown(keyCodes), 'KEYCODE')
|
||||
.appendField('key released');
|
||||
this.appendStatementInput('CODE')
|
||||
.setAlign(Blockly.inputs.Align.CENTRE)
|
||||
.appendField('do');
|
||||
this.setColour(55);
|
||||
this.setTooltip('Is executed when a key is released.');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
*/
|
||||
const events_onscreenRender = {
|
||||
init: function() {
|
||||
this.appendDummyInput()
|
||||
.appendField(new Blockly.FieldLabel('On Screen Render'));
|
||||
this.appendStatementInput('CODE')
|
||||
.setAlign(Blockly.inputs.Align.CENTRE)
|
||||
.appendField('do');
|
||||
this.setColour(55);
|
||||
this.setTooltip('Called each time the screen is rendering, both in the game screen and in the interface.');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
const events_onGUIScreenRender = {
|
||||
init: function() {
|
||||
this.appendDummyInput()
|
||||
.appendField(new Blockly.FieldLabel('On Gui Screen Render'));
|
||||
this.appendStatementInput('CODE')
|
||||
.setAlign(Blockly.inputs.Align.CENTRE)
|
||||
.appendField('do');
|
||||
this.setColour(55);
|
||||
this.setTooltip('Called each time the screen is rendering, but only in the interface (not in game)');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
const events_onJoinWorld = {
|
||||
init: function() {
|
||||
this.appendDummyInput()
|
||||
.appendField(new Blockly.FieldLabel('when HOST joins world'));
|
||||
this.appendStatementInput('CODE')
|
||||
.setAlign(Blockly.inputs.Align.CENTRE)
|
||||
.appendField('do');
|
||||
this.setColour(55);
|
||||
this.setTooltip('Is executed when player joins a world, runs once.');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
// Now define all blocks after the block definitions
|
||||
Blockly.common.defineBlocks({
|
||||
events_onModLoads: events_onModLoads,
|
||||
events_onClientTick: events_onClientTick,
|
||||
events_onClientFrame: events_onClientFrame,
|
||||
//events_onKeyPressed: events_onKeyPressed,
|
||||
//events_onKeyReleased: events_onKeyReleased,
|
||||
events_onJoinWorld: events_onJoinWorld
|
||||
});
|
||||
|
||||
// JavaScript generators for each event block
|
||||
javascript.javascriptGenerator.forBlock['events_onJoinWorld'] = function(block, generator) {
|
||||
const statement = generator.statementToCode(block, 'CODE');
|
||||
const code = `
|
||||
ModAPI.addEventListener("serverstart", () => {
|
||||
${statement} })`;
|
||||
return code;
|
||||
}
|
||||
|
||||
javascript.javascriptGenerator.forBlock['events_onscreenRender'] = function(block, generator) {
|
||||
const statement = generator.statementToCode(block, 'CODE');
|
||||
const code = `
|
||||
ModAPI.addEventListener("screenRender", () => {
|
||||
${statement} })`;
|
||||
return code;
|
||||
}
|
||||
|
||||
javascript.javascriptGenerator.forBlock['events_onGUIScreenRender'] = function(block, generator) {
|
||||
const statement = generator.statementToCode(block, 'CODE');
|
||||
const code = `
|
||||
ModAPI.addEventListener("GUIScreenRender", () => {
|
||||
${statement} })`;
|
||||
return code;
|
||||
}
|
||||
|
||||
javascript.javascriptGenerator.forBlock['events_oninGameScreenRender'] = function(block, generator) {
|
||||
const statement = generator.statementToCode(block, 'CODE');
|
||||
const code = `
|
||||
ModAPI.addEventListener("inGameScreenRender", () => {
|
||||
${statement} })`;
|
||||
return code;
|
||||
}
|
||||
|
||||
javascript.javascriptGenerator.forBlock['events_onscreenChange'] = function(block, generator) {
|
||||
const statement = generator.statementToCode(block, 'CODE');
|
||||
const code = `
|
||||
ModAPI.addEventListener("screenChange", () => {
|
||||
${statement} })`;
|
||||
return code;
|
||||
}
|
||||
|
||||
javascript.javascriptGenerator.forBlock['events_onopenModManager'] = function(block, generator) {
|
||||
const statement = generator.statementToCode(block, 'CODE');
|
||||
const code = `
|
||||
ModAPI.addEventListener("openModManager", () => {
|
||||
${statement} })`;
|
||||
return code;
|
||||
}
|
||||
|
||||
javascript.javascriptGenerator.forBlock['events_onopenLANSharing'] = function(block, generator) {
|
||||
const statement = generator.statementToCode(block, 'CODE');
|
||||
const code = `
|
||||
ModAPI.addEventListener("openLANSharing", () => {
|
||||
${statement} })`;
|
||||
return code;
|
||||
}
|
||||
|
||||
javascript.javascriptGenerator.forBlock['events_onModLoads'] = function(block, generator) {
|
||||
const statement = generator.statementToCode(block, 'CODE');
|
||||
const code = `
|
||||
ModAPI.addEventListener("load", () => {
|
||||
${statement} })`;
|
||||
return code;
|
||||
}
|
||||
|
||||
javascript.javascriptGenerator.forBlock['events_onClientTick'] = function(block, generator) {
|
||||
const statement = generator.statementToCode(block, 'CODE');
|
||||
const code = `
|
||||
ModAPI.addEventListener("update", () => {
|
||||
${statement} })`;
|
||||
return code;
|
||||
}
|
||||
|
||||
javascript.javascriptGenerator.forBlock['events_onClientFrame'] = function(block, generator) {
|
||||
const statement = generator.statementToCode(block, 'CODE');
|
||||
const code = `
|
||||
ModAPI.addEventListener("frame", () => {
|
||||
${statement} })`;
|
||||
return code;
|
||||
}
|
||||
|
||||
javascript.javascriptGenerator.forBlock['events_onKeyPressed'] = function(block, generator) {
|
||||
const statement = generator.statementToCode(block, 'CODE');
|
||||
const keyCode = block.getFieldValue('KEYCODE');
|
||||
const code = `
|
||||
window.addEventListener("keydown", event => {
|
||||
${keyCode !== ""?"if (event.keyCode === '"+keyCode+"') {":""}
|
||||
${statement}
|
||||
${keyCode !== ""?"}":""}`;
|
||||
return code;
|
||||
}
|
||||
|
||||
javascript.javascriptGenerator.forBlock['events_onKeyReleased'] = function(block, generator) {
|
||||
const statement = generator.statementToCode(block, 'CODE');
|
||||
const keyCode = block.getFieldValue('KEYCODE');
|
||||
const code = `
|
||||
window.addEventListener("keyup", event => {
|
||||
${keyCode !== ""?"if (event.keyCode === '"+keyCode+"') {":""}
|
||||
${statement}
|
||||
${keyCode !== ""?"}":""}`;
|
||||
return code;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,274 @@
|
||||
const itemstack_getitem = {
|
||||
init: function () {
|
||||
this.appendValueInput('ITEMSTACK')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('get itemstack item');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, null);
|
||||
this.setTooltip('Gets the Item of an ItemStack');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/item/ItemStack.html');
|
||||
this.setColour(165);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ itemstack_getitem: itemstack_getitem });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['itemstack_getitem'] = function () {
|
||||
const value_itemstack = javascript.javascriptGenerator.valueToCode(this, 'ITEMSTACK', javascript.Order.ATOMIC);
|
||||
const code = `(${value_itemstack}).$item`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
const itemstack_stacksize = {
|
||||
init: function () {
|
||||
this.appendValueInput('ITEMSTACK')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('get itemstack stack size');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, 'Number');
|
||||
this.setTooltip('Gets the stacksize of an ItemStack');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/item/ItemStack.html');
|
||||
this.setColour(165);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ itemstack_stacksize: itemstack_stacksize });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['itemstack_stacksize'] = function () {
|
||||
const value_itemstack = javascript.javascriptGenerator.valueToCode(this, 'ITEMSTACK', javascript.Order.ATOMIC);
|
||||
const code = `(${value_itemstack}).$stackSize`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
|
||||
const itemstack_setstacksize = {
|
||||
init: function () {
|
||||
this.appendValueInput('ITEMSTACK')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('set itemstack stack size');
|
||||
this.appendValueInput('VALUE')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.setCheck('Number')
|
||||
.appendField('to');
|
||||
this.setInputsInline(true)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Sets the stacksize of an ItemStack');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/item/ItemStack.html');
|
||||
this.setColour(165);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ itemstack_setstacksize: itemstack_setstacksize });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['itemstack_setstacksize'] = function () {
|
||||
const value_itemstack = javascript.javascriptGenerator.valueToCode(this, 'ITEMSTACK', javascript.Order.ATOMIC);
|
||||
const value_num = javascript.javascriptGenerator.valueToCode(this, 'VALUE', javascript.Order.ATOMIC);
|
||||
const code = `(${value_itemstack}).$stackSize = (${value_num});`;
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
const itemstack_meta = {
|
||||
init: function () {
|
||||
this.appendValueInput('ITEMSTACK')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('get itemstack metadata');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, 'Number');
|
||||
this.setTooltip('Gets the metadata integer of an ItemStack (itemDamage)');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/item/ItemStack.html');
|
||||
this.setColour(165);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ itemstack_meta: itemstack_meta });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['itemstack_meta'] = function () {
|
||||
const value_itemstack = javascript.javascriptGenerator.valueToCode(this, 'ITEMSTACK', javascript.Order.ATOMIC);
|
||||
const code = `(${value_itemstack}).$itemDamage`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
|
||||
const itemstack_setmeta = {
|
||||
init: function () {
|
||||
this.appendValueInput('ITEMSTACK')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('set itemstack metadata');
|
||||
this.appendValueInput('VALUE')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.setCheck('Number')
|
||||
.appendField('to');
|
||||
this.setInputsInline(true)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Sets the metadata of an ItemStack (itemDamage)');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/item/ItemStack.html');
|
||||
this.setColour(165);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ itemstack_setmeta: itemstack_setmeta });
|
||||
|
||||
|
||||
javascript.javascriptGenerator.forBlock['itemstack_setmeta'] = function () {
|
||||
const value_itemstack = javascript.javascriptGenerator.valueToCode(this, 'ITEMSTACK', javascript.Order.ATOMIC);
|
||||
const value_value = javascript.javascriptGenerator.valueToCode(this, 'VALUE', javascript.Order.ATOMIC);
|
||||
const code = `(${value_itemstack}).$itemDamage = (${value_value});`;
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
const itemstack_displayname = {
|
||||
init: function () {
|
||||
this.appendValueInput('ITEMSTACK')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('get itemstack display name');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, 'String');
|
||||
this.setTooltip('Gets the display name of an ItemStack');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/item/ItemStack.html');
|
||||
this.setColour(165);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ itemstack_displayname: itemstack_displayname });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['itemstack_displayname'] = function () {
|
||||
const value_itemstack = javascript.javascriptGenerator.valueToCode(this, 'ITEMSTACK', javascript.Order.ATOMIC);
|
||||
const code = `ModAPI.util.ustr((${value_itemstack}).$getDisplayName())`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
const itemstack_setdisplayname = {
|
||||
init: function () {
|
||||
this.appendValueInput('ITEMSTACK')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('set itemstack display name');
|
||||
this.appendValueInput('VALUE')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.setCheck('String')
|
||||
.appendField('to');
|
||||
this.setInputsInline(true)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Sets the display name of an ItemStack');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/item/ItemStack.html');
|
||||
this.setColour(165);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ itemstack_setdisplayname: itemstack_setdisplayname });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['itemstack_setdisplayname'] = function () {
|
||||
const value_itemstack = javascript.javascriptGenerator.valueToCode(this, 'ITEMSTACK', javascript.Order.ATOMIC);
|
||||
const value_value = javascript.javascriptGenerator.valueToCode(this, 'VALUE', javascript.Order.ATOMIC);
|
||||
const code = `(${value_itemstack}).$setStackDisplayName(ModAPI.util.str(${value_value}));`;
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
const itemstack_enchant = {
|
||||
init: function () {
|
||||
this.appendValueInput('ITEMSTACK')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('enchant itemstack');
|
||||
this.appendDummyInput('ENCHANTMENT')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('with enchantment')
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
["protection", "protection"],
|
||||
["fireProtection", "fireProtection"],
|
||||
["featherFalling", "featherFalling"],
|
||||
["blastProtection", "blastProtection"],
|
||||
["projectileProtection", "projectileProtection"],
|
||||
["respiration", "respiration"],
|
||||
["aquaAffinity", "aquaAffinity"],
|
||||
["thorns", "thorns"],
|
||||
["depthStrider", "depthStrider"],
|
||||
["sharpness", "sharpness"],
|
||||
["smite", "smite"],
|
||||
["baneOfArthropods", "baneOfArthropods"],
|
||||
["knockback", "knockback"],
|
||||
["fireAspect", "fireAspect"],
|
||||
["looting", "looting"],
|
||||
["efficiency", "efficiency"],
|
||||
["silkTouch", "silkTouch"],
|
||||
["unbreaking", "unbreaking"],
|
||||
["fortune", "fortune"],
|
||||
["power", "power"],
|
||||
["punch", "punch"],
|
||||
["flame", "flame"],
|
||||
["infinity", "infinity"],
|
||||
["luckOfTheSea", "luckOfTheSea"],
|
||||
["lure", "lure"]
|
||||
]), 'ENCHANTMENT');
|
||||
this.appendValueInput('LEVEL')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.setCheck('Number')
|
||||
.appendField('at level');
|
||||
this.setInputsInline(true)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Adds an enchantment to an ItemStack');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/item/ItemStack.html');
|
||||
this.setColour(165);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ itemstack_enchant: itemstack_enchant });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['itemstack_enchant'] = function () {
|
||||
const value_itemstack = javascript.javascriptGenerator.valueToCode(this, 'ITEMSTACK', javascript.Order.ATOMIC);
|
||||
const dropdown_enchantment = this.getFieldValue('ENCHANTMENT');
|
||||
const value_level = javascript.javascriptGenerator.valueToCode(this, 'LEVEL', javascript.Order.ATOMIC);
|
||||
const code = `(${value_itemstack}).$addEnchantment(ModAPI.enchantments["${dropdown_enchantment}"].getRef(), (${value_level}));`;
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const itemstack_repaircost = {
|
||||
init: function () {
|
||||
this.appendValueInput('ITEMSTACK')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('get itemstack repair cost');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, 'Number');
|
||||
this.setTooltip('Gets the repair cost of an ItemStack');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/item/ItemStack.html');
|
||||
this.setColour(165);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ itemstack_repaircost: itemstack_repaircost });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['itemstack_repaircost'] = function () {
|
||||
const value_itemstack = javascript.javascriptGenerator.valueToCode(this, 'ITEMSTACK', javascript.Order.ATOMIC);
|
||||
const code = `(${value_itemstack}).$getRepairCost()`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
|
||||
const itemstack_setrepaircost = {
|
||||
init: function () {
|
||||
this.appendValueInput('ITEMSTACK')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('set itemstack repair cost');
|
||||
this.appendValueInput('VALUE')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.setCheck('Number')
|
||||
.appendField('to');
|
||||
this.setInputsInline(true)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Sets the repair cost of an ItemStack');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/item/ItemStack.html');
|
||||
this.setColour(165);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ itemstack_setrepaircost: itemstack_setrepaircost });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['itemstack_setrepaircost'] = function () {
|
||||
const value_itemstack = javascript.javascriptGenerator.valueToCode(this, 'ITEMSTACK', javascript.Order.ATOMIC);
|
||||
const value_value = javascript.javascriptGenerator.valueToCode(this, 'VALUE', javascript.Order.ATOMIC);
|
||||
const code = `(${value_itemstack}).$setRepairCost(${value_value});`;
|
||||
return code;
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
const items_creativetab = {
|
||||
init: function () {
|
||||
this.appendDummyInput('TAB')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('Set item creative tab to')
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
["tabBlock", "tabBlock"],
|
||||
["tabDecorations", "tabDecorations"],
|
||||
["tabRedstone", "tabRedstone"],
|
||||
["tabTransport", "tabTransport"],
|
||||
["tabMisc", "tabMisc"],
|
||||
["tabAllSearch", "tabAllSearch"],
|
||||
["tabFood", "tabFood"],
|
||||
["tabTools", "tabTools"],
|
||||
["tabCombat", "tabCombat"],
|
||||
["tabBrewing", "tabBrewing"],
|
||||
["tabMaterials", "tabMaterials"],
|
||||
["tabInventory", "tabInventory"]
|
||||
]), 'TAB');
|
||||
this.setInputsInline(false)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Set the creative tab of the item');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/item/Item.html');
|
||||
this.setColour(225);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ items_creativetab: items_creativetab });
|
||||
javascript.javascriptGenerator.forBlock['items_creativetab'] = function () {
|
||||
let dropdown_tab = this.getFieldValue('TAB');
|
||||
if (flags.target === "1_12") {
|
||||
dropdown_tab = dropdown_tab.replace("tab", "").toUpperCase();
|
||||
}
|
||||
const code = `this.$setCreativeTab(ModAPI.reflect.getClassById("net.minecraft.creativetab.CreativeTabs").staticVariables.${dropdown_tab});`;
|
||||
return code;
|
||||
}
|
||||
|
||||
const items_item = {
|
||||
init: function () {
|
||||
this.appendDummyInput('ITEM')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('item')
|
||||
.appendField(new Blockly.FieldMinecraftItemInput(false, true), 'ITEM');
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, null);
|
||||
this.setTooltip('Returns an Item instance (for comparisons)');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/item/Item.html');
|
||||
this.setColour(225);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ items_item: items_item });
|
||||
javascript.javascriptGenerator.forBlock['items_item'] = function () {
|
||||
const item_primitive = this.getFieldValue('ITEM');
|
||||
const object = {
|
||||
type: item_primitive.split("/")[0],
|
||||
id: item_primitive.split("/")[1].split("@")[0]
|
||||
}
|
||||
if (object.type === "item") {
|
||||
return [`(ModAPI.items["${object.id}"]?.getRef() || null)`, javascript.Order.NONE]
|
||||
} else {
|
||||
return [`ModAPI.util.getItemFromBlock(ModAPI.blocks["${object.id}"]?.getRef() || null)`, javascript.Order.NONE]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
const items_setmaxstacksize = {
|
||||
init: function () {
|
||||
this.appendValueInput('SIZE')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.setCheck('Number')
|
||||
.appendField('set max stack size to');
|
||||
this.setInputsInline(true)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Sets an items max stack size.');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/item/Item.html');
|
||||
this.setColour(225);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ items_setmaxstacksize: items_setmaxstacksize });
|
||||
javascript.javascriptGenerator.forBlock['items_setmaxstacksize'] = function () {
|
||||
const value_size = javascript.javascriptGenerator.valueToCode(this, 'SIZE', javascript.Order.ATOMIC);
|
||||
const code = `this.$maxStackSize = (${value_size});`;
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
registerHandler("ItemConstructor", "item constructor", {}, function () {
|
||||
this.setTooltip('Runs when the item type is initialised.\nNo return value expected.');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/item/Item.html');
|
||||
this.setColour(225);
|
||||
});
|
||||
|
||||
|
||||
registerHandler("ItemRightClick", "item right click", {
|
||||
"ITEM_STACK": "itemstack",
|
||||
"WORLD": "world",
|
||||
"PLAYER": "player"
|
||||
}, function () {
|
||||
this.setTooltip('1.8: Runs when the item is right-clicked.\nThe itemstack argument is expected as a return value.\n\n1.12: Expects ActionResult containing the ItemStack. If \'SUCCESS\' is the mode selected, the stack size is automatically decreased. If no return value, UseItemOnRightClick determines wether or not SUCCESS or PASS is the enabled mode.');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/item/Item.html');
|
||||
this.setColour(225);
|
||||
});
|
||||
|
||||
registerHandler("ItemUsed", "item used", {
|
||||
"ITEM_STACK": "itemstack",
|
||||
"WORLD": "world",
|
||||
"PLAYER": "player"
|
||||
}, function () {
|
||||
this.setTooltip('Runs when the item is used. Not called when the player stops using the item early.\nThe itemstack argument is expected as a return value.');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/item/Item.html');
|
||||
this.setColour(225);
|
||||
});
|
||||
|
||||
registerHandler("ItemTicked", "item ticked", {
|
||||
"ITEM_STACK": "itemstack",
|
||||
"WORLD": "world",
|
||||
"PLAYER": "player",
|
||||
"SLOT_INDEX": "slot index",
|
||||
"IS_ITEM_HELD": "item held?"
|
||||
}, function () {
|
||||
this.setTooltip('Runs every tick when the item is in a player\'s inventory.\nThe itemstack argument is expected as a return value.\n`slot index` is a number representing inventory location, `is held` is a boolean.');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/item/Item.html');
|
||||
this.setColour(225);
|
||||
});
|
||||
|
||||
registerHandler("ItemBlockUse", "item block use", {
|
||||
"ITEM_STACK": "itemstack",
|
||||
"PLAYER": "player",
|
||||
"WORLD": "world",
|
||||
"BLOCKPOS": "blockpos",
|
||||
}, function () {
|
||||
this.setTooltip('1.8: Runs when the item is used on a block.\nA boolean is expected as a return value.\n\n1.12: EnumActionResult Expected as return value.');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/item/Item.html');
|
||||
this.setColour(225);
|
||||
});
|
||||
|
||||
registerHandler("ItemCrafted", "item crafted", {
|
||||
"ITEM_STACK": "itemstack",
|
||||
"WORLD": "world",
|
||||
"PLAYER": "player",
|
||||
}, function () {
|
||||
this.setTooltip('Runs when the item is crafted or smelted.\nNo return value is expected.');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/item/Item.html');
|
||||
this.setColour(225);
|
||||
});
|
||||
|
||||
registerHandler("ItemBlockBroken", "item block broken", {
|
||||
"ITEM_STACK": "itemstack",
|
||||
"WORLD": "world",
|
||||
"BLOCK": "block",
|
||||
"BLOCKPOS": "blockpos",
|
||||
"ENTITY": "entity",
|
||||
}, function () {
|
||||
this.setTooltip('Runs when a block is broken with this item.\nA boolean is expected as a return value.');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/item/Item.html');
|
||||
this.setColour(225);
|
||||
});
|
||||
|
||||
registerHandler("ItemGetAttributes", "item get attributes", { "ATTRIBUTEMAP": "attribute map" }, function () {
|
||||
this.setTooltip('Runs when an item\'s attributes are calculated.\nAn AttributeMap is expected as a return value, but is automatically returned.');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/item/Item.html');
|
||||
this.setColour(225);
|
||||
});
|
||||
|
||||
registerHandler("ItemGetEfficiency", "item get efficiency vs block", { "ITEMSTACK": "itemstack", "BLOCK": "block" }, function () {
|
||||
this.setTooltip('Runs to get the item\'s strength when breaking a block.\nA number is expected as an output. Default response is 1.0');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/item/Item.html');
|
||||
this.setColour(225);
|
||||
});
|
||||
|
||||
const items_get_applicable_blocks = {
|
||||
init: function () {
|
||||
this.appendDummyInput('GROUP')
|
||||
.appendField('get applicable blocks of')
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
['ItemAxe', 'ItemAxe'],
|
||||
['ItemPickaxe', 'ItemPickaxe'],
|
||||
['ItemSpade', 'ItemSpade']
|
||||
]), 'GROUP');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, null);
|
||||
this.setTooltip('Returns an array of blocks that the item group is effective on.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(225);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ items_get_applicable_blocks: items_get_applicable_blocks });
|
||||
javascript.javascriptGenerator.forBlock['items_get_applicable_blocks'] = function () {
|
||||
const dropdown_group = this.getFieldValue('GROUP');
|
||||
const code = `(ModAPI.reflect.getClassByName("${dropdown_group}").staticVariables.EFFECTIVE_ON?.$backingMap?.$elementData?.data?.filter(x => !!x)?.map(x => x.$key) || [])`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
const items_currentitem = {
|
||||
init: function () {
|
||||
this.appendDummyInput('ITEM')
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField('current item')
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, null);
|
||||
this.setTooltip('The current Item that the handler is executing on.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(225);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ items_currentitem: items_currentitem });
|
||||
javascript.javascriptGenerator.forBlock['items_currentitem'] = function () {
|
||||
return [`$$CustomItem`, javascript.Order.NONE];
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
const PLAYER_CAPABILITIES_BOOLEAN = [
|
||||
["can fly", "allowFlying"],
|
||||
["is flying", "isFlying"],
|
||||
["disable damage", "disableDamage"],
|
||||
["is in creative", "isCreativeMode"],
|
||||
["is in spectator", "isSpectatorMode"],
|
||||
["allow edit", "allowEdit"],
|
||||
["is invulnerable", "invulnerable"],
|
||||
];
|
||||
|
||||
const player_get_capability_boolean = {
|
||||
init: function () {
|
||||
this.appendDummyInput('CAPABILITY')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(new Blockly.FieldDropdown(PLAYER_CAPABILITIES_BOOLEAN), 'CAPABILITY');
|
||||
this.appendValueInput('PLAYER')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('capability of player');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, "Boolean");
|
||||
this.setTooltip('Gets a capability of a player.');
|
||||
this.setHelpUrl('https://eaglerforge.github.io/apidocs/globals/PlayerCapabilities.html');
|
||||
this.setColour(30);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ player_get_capability_boolean: player_get_capability_boolean });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['player_get_capability_boolean'] = function () {
|
||||
const dropdown_capability = this.getFieldValue('CAPABILITY');
|
||||
const value_player = javascript.javascriptGenerator.valueToCode(this, 'PLAYER', javascript.Order.ATOMIC);
|
||||
let code;
|
||||
if (dropdown_capability === invulnerable) {
|
||||
code = `Boolean((${value_player}).$invulnerable)`;
|
||||
} else if (dropdown_capability === isSpectatorMode) {
|
||||
code = `Boolean((${value_player}).$isSpectator()`;
|
||||
} else {
|
||||
code = `Boolean((${value_player}).$capabilities["${dropdown_capability}"])`;
|
||||
}
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
const PLAYER_CAPABILITIES_NUMBER = [
|
||||
["walk speed", "walkSpeed0"],
|
||||
["fly speed ", "flySpeed0"],
|
||||
];
|
||||
|
||||
const player_get_capability_number = {
|
||||
init: function () {
|
||||
this.appendDummyInput('CAPABILITY')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(new Blockly.FieldDropdown(PLAYER_CAPABILITIES_NUMBER), 'CAPABILITY');
|
||||
this.appendValueInput('PLAYER')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('capability of player');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, "Number");
|
||||
this.setTooltip('Gets a capability of a player.');
|
||||
this.setHelpUrl('https://eaglerforge.github.io/apidocs/globals/PlayerCapabilities.html');
|
||||
this.setColour(30);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ player_get_capability_number: player_get_capability_number });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['player_get_capability_number'] = function () {
|
||||
const dropdown_capability = this.getFieldValue('CAPABILITY');
|
||||
const value_player = javascript.javascriptGenerator.valueToCode(this, 'PLAYER', javascript.Order.ATOMIC);
|
||||
const code = `(${value_player}).$capabilities["$${dropdown_capability}"]`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
const PLAYER_FOOD_STATS = [
|
||||
["food exhaustion level", "foodExhaustionLevel"],
|
||||
["food level ", "foodLevel0"],
|
||||
["food saturation level", "foodSaturationLevel"],
|
||||
];
|
||||
|
||||
const player_get_food_stats = {
|
||||
init: function () {
|
||||
this.appendDummyInput('STAT')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField( new Blockly.FieldDropdown(PLAYER_FOOD_STATS), 'STAT');
|
||||
this.appendValueInput('PLAYER')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('of player');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, "Number");
|
||||
this.setTooltip('Gets the food stats of a player.');
|
||||
this.setHelpUrl('https://eaglerforge.github.io/apidocs/globals/FoodStatsData.html');
|
||||
this.setColour(30);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ player_get_food_stats: player_get_food_stats });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['player_get_food_stats'] = function () {
|
||||
const dropdown_stat = this.getFieldValue('STAT');
|
||||
const value_player = javascript.javascriptGenerator.valueToCode(this, 'PLAYER', javascript.Order.ATOMIC);
|
||||
const code = `(${value_player}).$foodStats["$${dropdown_stat}"]`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
const PLAYER_XP_STATS = [
|
||||
["experience", "experience"],
|
||||
["experience level", "experienceLevel"],
|
||||
["total experience", "experienceTotal"],
|
||||
["experience points", "experiencePoints"]
|
||||
];
|
||||
|
||||
const player_get_xp_stats = {
|
||||
init: function () {
|
||||
this.appendDummyInput('STAT')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField( new Blockly.FieldDropdown(PLAYER_XP_STATS), 'STAT');
|
||||
this.appendValueInput('PLAYER')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('of player');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, "Number");
|
||||
this.setTooltip('Gets the experience stats of a player.');
|
||||
this.setHelpUrl('https://eaglerforge.github.io/apidocs/globals/FoodStatsData.html');
|
||||
this.setColour(30);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ player_get_xp_stats: player_get_xp_stats });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['player_get_xp_stats'] = function () {
|
||||
const dropdown_stat = this.getFieldValue('STAT');
|
||||
const value_player = javascript.javascriptGenerator.valueToCode(this, 'PLAYER', javascript.Order.ATOMIC);
|
||||
let code;
|
||||
if (dropdown_stat === "experiencePoints") {
|
||||
code = `${value_player}.$getExperiencePoints()`;
|
||||
} else {
|
||||
code = `${value_player}.` + "$" + `${dropdown_stat}`;
|
||||
}
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
const PLAYER_ITEM_TYPE = [
|
||||
["ItemStack", "ItemStack"],
|
||||
["Item", "Item"],
|
||||
];
|
||||
|
||||
const player_get_item_hand = {
|
||||
init: function () {
|
||||
this.appendValueInput('PLAYER')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('get held item of player');
|
||||
this.appendDummyInput()
|
||||
.appendField('as');
|
||||
this.appendDummyInput('TYPE')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(new Blockly.FieldDropdown(PLAYER_ITEM_TYPE), 'TYPE');
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true);
|
||||
this.setTooltip('Gets the item in the hand of a player.');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/entity/player/EntityPlayer.html');
|
||||
this.setColour(30);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ player_get_item_hand: player_get_item_hand });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['player_get_item_hand'] = function () {
|
||||
const dropdown_item_type = this.getFieldValue('TYPE');
|
||||
const value_player = javascript.javascriptGenerator.valueToCode(this, 'PLAYER', javascript.Order.ATOMIC);
|
||||
let code;
|
||||
if (dropdown_item_type === "Item") {
|
||||
code = `(${value_player}).$getHeldItem()?(${value_player}).$getHeldItem().$item:null`;
|
||||
} else {
|
||||
code = `(${value_player}).$getHeldItem()`;
|
||||
}
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
const player_get_current_item_pos = {
|
||||
init: function () {
|
||||
this.appendValueInput('PLAYER')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('get held item index of player');
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, "Number");
|
||||
this.setTooltip('Gets the selected item index of a player.');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/entity/player/EntityPlayer.html');
|
||||
this.setColour(30);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ player_get_current_item_pos: player_get_current_item_pos });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['player_get_current_item_pos'] = function () {
|
||||
const value_player = javascript.javascriptGenerator.valueToCode(this, 'PLAYER', javascript.Order.ATOMIC);
|
||||
const code = `(${value_player}.$inventory.$currentItem+1)`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
const PLAYER_INVENTORY = [
|
||||
["get main inventory", "main"],
|
||||
["get armor inventory", "armor"],
|
||||
["get enderchest inventory", "enderchest"],
|
||||
];
|
||||
|
||||
const player_get_player_inventory = {
|
||||
init: function () {
|
||||
this.appendDummyInput('TYPE')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(new Blockly.FieldDropdown(PLAYER_INVENTORY), 'TYPE');
|
||||
this.appendValueInput('PLAYER')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('of player');
|
||||
this.appendDummyInput()
|
||||
.appendField('as list');
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true);
|
||||
this.setTooltip('Gets the inventory of a player as list.');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/entity/player/EntityPlayer.html');
|
||||
this.setColour(30);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ player_get_player_inventory: player_get_player_inventory });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['player_get_player_inventory'] = function () {
|
||||
const dropdown_inventory = this.getFieldValue('TYPE');
|
||||
const value_player = javascript.javascriptGenerator.valueToCode(this, 'PLAYER', javascript.Order.ATOMIC);
|
||||
let code;
|
||||
if (dropdown_inventory === "main") {
|
||||
code = `(${value_player}).$inventory.$mainInventory.data`;
|
||||
} else if (dropdown_inventory === "armor") {
|
||||
code = `(${value_player}).$inventory.$armorInventory.data`;
|
||||
} else {
|
||||
code = `(${value_player}).$getInventoryEnderChest().$inventoryContents.data`
|
||||
}
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
const player_is_entity_player = {
|
||||
init: function () {
|
||||
this.appendValueInput('ENTITY')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('is entity');
|
||||
this.appendDummyInput()
|
||||
.appendField('a player');
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, "Boolean");
|
||||
this.setTooltip('Checks if an entity is a player or not');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/entity/player/EntityPlayer.html');
|
||||
this.setColour(30);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ player_is_entity_player: player_is_entity_player });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['player_is_entity_player'] = function () {
|
||||
const value_entity = javascript.javascriptGenerator.valueToCode(this, 'ENTITY', javascript.Order.ATOMIC);
|
||||
const code = `Boolean(Minecraft.$thePlayer.$isPlayer())`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
const player_get_player_name = {
|
||||
init: function () {
|
||||
this.appendValueInput('PLAYER')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('get the name of player');
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, "String");
|
||||
this.setTooltip('Gets the name a player.');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/entity/player/EntityPlayer.html');
|
||||
this.setColour(30);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ player_get_player_name: player_get_player_name });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['player_get_player_name'] = function () {
|
||||
const value_player = javascript.javascriptGenerator.valueToCode(this, 'PLAYER', javascript.Order.ATOMIC);
|
||||
const code = `ModAPI.util.ustr((${value_player}).$getName())`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
const local_this = {
|
||||
init: function () {
|
||||
this.appendDummyInput('NAME')
|
||||
.appendField('this');
|
||||
this.setInputsInline(false)
|
||||
this.setOutput(true, null);
|
||||
this.setTooltip('The object the handler is running on.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(330);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ local_this: local_this });
|
||||
javascript.javascriptGenerator.forBlock['local_this'] = function () {
|
||||
return 'this';
|
||||
}
|
||||
|
||||
const proc_return = {
|
||||
init: function () {
|
||||
this.appendDummyInput('NAME')
|
||||
.appendField('return');
|
||||
this.setInputsInline(true)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(false, null);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(195);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ proc_return: proc_return });
|
||||
javascript.javascriptGenerator.forBlock['proc_return'] = function () {
|
||||
return 'return;';
|
||||
}
|
||||
|
||||
const proc_returnvalue = {
|
||||
init: function () {
|
||||
this.appendValueInput('VALUE')
|
||||
.appendField('return value');
|
||||
this.setInputsInline(false)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(false, null);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(195);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ proc_returnvalue: proc_returnvalue });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['proc_returnvalue'] = function () {
|
||||
const value = javascript.javascriptGenerator.valueToCode(this, 'VALUE', javascript.Order.ATOMIC);
|
||||
const code = 'return ' + value + ';';
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
const proc_returnbool = {
|
||||
init: function () {
|
||||
this.appendValueInput('VALUE').setCheck('Boolean')
|
||||
.appendField('return boolean');
|
||||
this.setInputsInline(false)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(false, null);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(195);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ proc_returnbool: proc_returnbool });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['proc_returnbool'] = function () {
|
||||
const value = javascript.javascriptGenerator.valueToCode(this, 'VALUE', javascript.Order.ATOMIC);
|
||||
const code = `return (${value}) ? 1 : 0;`;
|
||||
return code;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
const attributes_set = {
|
||||
libs: ["attribute_map_set"],
|
||||
init: function () {
|
||||
this.appendValueInput('MAP')
|
||||
.appendField('set attribute map');
|
||||
this.appendDummyInput('KEY')
|
||||
.appendField('value')
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
['max health', "generic.maxHealth"],
|
||||
['knockback resistance', "generic.knockbackResistance"],
|
||||
['movement speed', "generic.movementSpeed"],
|
||||
['attack damage', "generic.attackDamage"]
|
||||
]), 'KEY');
|
||||
this.appendValueInput('VALUE')
|
||||
.setCheck('Number')
|
||||
.appendField('to');
|
||||
this.setInputsInline(true)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Set an attribute\'s value on the specified map.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(225);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ attributes_set: attributes_set });
|
||||
|
||||
|
||||
javascript.javascriptGenerator.forBlock['attributes_set'] = function () {
|
||||
const value_map = javascript.javascriptGenerator.valueToCode(this, 'MAP', javascript.Order.ATOMIC);
|
||||
const dropdown_key = this.getFieldValue('KEY');
|
||||
const value_value = javascript.javascriptGenerator.valueToCode(this, 'VALUE', javascript.Order.ATOMIC);
|
||||
const code = `efb2__attrMapSet(${value_map}, "${dropdown_key}", ${value_value});`;
|
||||
return code;
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
const logic_a_or_b = {
|
||||
init: function () {
|
||||
this.appendValueInput('A')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('B')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('otherwise');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, null);
|
||||
this.setTooltip('Uses the first value if it exists, otherwise uses the second value. (JavaScript ?? operator)');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(210);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ logic_a_or_b: logic_a_or_b });
|
||||
javascript.javascriptGenerator.forBlock['logic_a_or_b'] = function () {
|
||||
const value_a = javascript.javascriptGenerator.valueToCode(this, 'A', javascript.Order.ATOMIC);
|
||||
const value_b = javascript.javascriptGenerator.valueToCode(this, 'B', javascript.Order.ATOMIC);
|
||||
const code = `((${value_a})??(${value_b}))`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
const proc_wait = {
|
||||
init: function () {
|
||||
this.appendValueInput('VALUE')
|
||||
.appendField('synchronous wait');
|
||||
this.setInputsInline(false);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Waits set amount of time. Synchronous: (no frames or otehr code can be run while this is waiting)');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(255);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ proc_wait: proc_wait });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['proc_wait'] = function () {
|
||||
const value = javascript.javascriptGenerator.valueToCode(this, 'VALUE', javascript.Order.ATOMIC);
|
||||
const code = `
|
||||
var start = Date.now();
|
||||
var current = start;
|
||||
while (current - start < (${value} * 1000)) {
|
||||
current = Date.now();
|
||||
};
|
||||
`;
|
||||
return code;
|
||||
}
|
||||
const comment = {
|
||||
init: function () {
|
||||
this.appendDummyInput('VALUE')
|
||||
.appendField('comment ')
|
||||
.appendField(new Blockly.FieldTextInput('x'), 'VALUE');
|
||||
this.setInputsInline(false);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Adds a comment');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(255);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ comment: comment });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['comment'] = function () {
|
||||
const value = this.getFieldValue('VALUE');
|
||||
const code = `
|
||||
// ${value}
|
||||
`;
|
||||
return code;
|
||||
}
|
||||
|
||||
const proc_asyncrun = {
|
||||
init: function () {
|
||||
this.appendValueInput('DELAY')
|
||||
.setCheck('Number')
|
||||
.appendField('in');
|
||||
this.appendDummyInput('NIL')
|
||||
.appendField('seconds, run:');
|
||||
this.appendStatementInput('CODE');
|
||||
this.setInputsInline(true)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Asynchronous wait. Runs code in a set amount of time. Other code can still run.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(255);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ proc_asyncrun: proc_asyncrun });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['proc_asyncrun'] = function () {
|
||||
// TODO: change Order.ATOMIC to the correct operator precedence strength
|
||||
const value_delay = javascript.javascriptGenerator.valueToCode(this, 'DELAY', javascript.Order.ATOMIC);
|
||||
|
||||
const statement_code = javascript.javascriptGenerator.statementToCode(this, 'CODE');
|
||||
|
||||
|
||||
const code = `setTimeout(()=>{
|
||||
ModAPI.promisify(()=>{
|
||||
${statement_code};
|
||||
})();
|
||||
}, ${parseFloat(value_delay) * 1000});`;
|
||||
return code;
|
||||
}
|
||||
|
||||
const list_includes = {
|
||||
init: function () {
|
||||
this.appendValueInput('LIST')
|
||||
.setCheck('Array')
|
||||
.appendField('list');
|
||||
this.appendValueInput('VALUE')
|
||||
.appendField('includes');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, 'Boolean');
|
||||
this.setTooltip('Checks if a list contains an item.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(255);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ list_includes: list_includes });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['list_includes'] = function () {
|
||||
const value_list = javascript.javascriptGenerator.valueToCode(this, 'LIST', javascript.Order.ATOMIC);
|
||||
const value_value = javascript.javascriptGenerator.valueToCode(this, 'VALUE', javascript.Order.ATOMIC);
|
||||
const code = `${value_list}.includes(${value_value})`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
const globals_set = {
|
||||
init: function () {
|
||||
this.appendDummyInput('VAR')
|
||||
.appendField('global ')
|
||||
.appendField(new Blockly.FieldTextInput('x'), 'VAR');
|
||||
this.appendValueInput('VAL')
|
||||
.appendField('=');
|
||||
this.setInputsInline(true)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Sets a global variable.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(150);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ globals_set: globals_set });
|
||||
javascript.javascriptGenerator.forBlock['globals_set'] = function () {
|
||||
const text_var = this.getFieldValue('VAR');
|
||||
const value_val = javascript.javascriptGenerator.valueToCode(this, 'VAL', javascript.Order.ATOMIC);
|
||||
const code = `$$scoped_efb_globals["${text_var}"] = ${value_val};`;
|
||||
return code;
|
||||
}
|
||||
|
||||
const globals_get = {
|
||||
init: function () {
|
||||
this.appendDummyInput('VAR')
|
||||
.appendField('global ')
|
||||
.appendField(new Blockly.FieldTextInput('x'), 'VAR');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, null);
|
||||
this.setTooltip('Gets a global variable.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(150);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ globals_get: globals_get });
|
||||
|
||||
|
||||
javascript.javascriptGenerator.forBlock['globals_get'] = function () {
|
||||
const text_var = this.getFieldValue('VAR');
|
||||
const code = `$$scoped_efb_globals["${text_var}"]`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
const globals_delete = {
|
||||
init: function () {
|
||||
this.appendDummyInput('VAR')
|
||||
.appendField('delete global')
|
||||
.appendField(new Blockly.FieldTextInput('x'), 'VAR');
|
||||
this.setInputsInline(true)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Deletes a global variable.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(150);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ globals_delete: globals_delete });
|
||||
|
||||
|
||||
javascript.javascriptGenerator.forBlock['globals_delete'] = function () {
|
||||
const text_var = this.getFieldValue('VAR');
|
||||
const code = `delete $$scoped_efb_globals["${text_var}"];`;
|
||||
return code;
|
||||
}
|
||||
|
||||
const globals_exists = {
|
||||
init: function () {
|
||||
this.appendDummyInput('VAR')
|
||||
.appendField('global exists')
|
||||
.appendField(new Blockly.FieldTextInput('x'), 'VAR');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, 'Boolean');
|
||||
this.setTooltip('Checks if a global is defined.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(150);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ globals_exists: globals_exists });
|
||||
|
||||
|
||||
javascript.javascriptGenerator.forBlock['globals_exists'] = function () {
|
||||
const text_var = this.getFieldValue('VAR');
|
||||
const code = `("${text_var}" in $$scoped_efb_globals)`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
const vec3_getxyz = {
|
||||
init: function () {
|
||||
this.appendDummyInput('TAB')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
['x', '$xCoord'],
|
||||
['y', '$yCoord'],
|
||||
['z', '$zCoord']
|
||||
]), 'TAB');
|
||||
this.appendValueInput('VALUE')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('component of Vec3');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, "Number");
|
||||
this.setTooltip('Get a component of a Vec3');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/util/Vec3.html');
|
||||
this.setColour(270);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ vec3_getxyz: vec3_getxyz });
|
||||
|
||||
|
||||
|
||||
javascript.javascriptGenerator.forBlock['vec3_getxyz'] = function () {
|
||||
const dropdown_tab = this.getFieldValue('TAB');
|
||||
const value_value = javascript.javascriptGenerator.valueToCode(this, 'VALUE', javascript.Order.ATOMIC);
|
||||
|
||||
const code = `(${value_value})["${dropdown_tab}"]`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
|
||||
const vec3_fromxyz = {
|
||||
init: function () {
|
||||
this.appendValueInput('X')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.setCheck('Number')
|
||||
.appendField('Make Vec3 from x:');
|
||||
this.appendValueInput('Y')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.setCheck('Number')
|
||||
.appendField('y:');
|
||||
this.appendValueInput('Z')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.setCheck('Number')
|
||||
.appendField('z:');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, null);
|
||||
this.setTooltip('Create a Vec3 from components');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/util/Vec3.html');
|
||||
this.setColour(270);
|
||||
},
|
||||
libs: ["construct_vec3"]
|
||||
};
|
||||
Blockly.common.defineBlocks({ vec3_fromxyz: vec3_fromxyz });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['vec3_fromxyz'] = function () {
|
||||
const value_x = javascript.javascriptGenerator.valueToCode(this, 'X', javascript.Order.ATOMIC);
|
||||
const value_y = javascript.javascriptGenerator.valueToCode(this, 'Y', javascript.Order.ATOMIC);
|
||||
const value_z = javascript.javascriptGenerator.valueToCode(this, 'Z', javascript.Order.ATOMIC);
|
||||
|
||||
const code = `efb2__makeVec3(${value_x},${value_y},${value_z})`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
const vec3_dist = {
|
||||
init: function () {
|
||||
this.appendValueInput('X')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('distance from Vec3');
|
||||
this.appendValueInput('Y')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('to Vec3');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, "Number");
|
||||
this.setTooltip('Calculates the distance between two Vec3\'s.');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/util/Vec3.html');
|
||||
this.setColour(270);
|
||||
},
|
||||
};
|
||||
Blockly.common.defineBlocks({ vec3_dist: vec3_dist });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['vec3_dist'] = function () {
|
||||
const value_x = javascript.javascriptGenerator.valueToCode(this, 'X', javascript.Order.ATOMIC);
|
||||
const value_y = javascript.javascriptGenerator.valueToCode(this, 'Y', javascript.Order.ATOMIC);
|
||||
|
||||
const code = `(${value_x}).$distanceTo(${value_y})`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
const world_explosion = {
|
||||
init: function () {
|
||||
this.appendValueInput('WORLD')
|
||||
.appendField('Spawn explosion in world:');
|
||||
this.appendValueInput('POS')
|
||||
.appendField('BlockPos:');
|
||||
this.appendValueInput('STRENGTH')
|
||||
.setCheck('Number')
|
||||
.appendField('Strength:');
|
||||
this.appendValueInput('FIRE')
|
||||
.setCheck('Boolean')
|
||||
.appendField('Fire:');
|
||||
this.appendValueInput('SMOKE')
|
||||
.setCheck('Boolean')
|
||||
.appendField('Break Blocks:');
|
||||
this.setInputsInline(false)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(195);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ world_explosion: world_explosion });
|
||||
javascript.javascriptGenerator.forBlock['world_explosion'] = function () {
|
||||
const value_world = javascript.javascriptGenerator.valueToCode(this, 'WORLD', javascript.Order.ATOMIC);
|
||||
const value_pos = javascript.javascriptGenerator.valueToCode(this, 'POS', javascript.Order.ATOMIC);
|
||||
const value_strength = javascript.javascriptGenerator.valueToCode(this, 'STRENGTH', javascript.Order.ATOMIC);
|
||||
const value_fire = javascript.javascriptGenerator.valueToCode(this, 'FIRE', javascript.Order.ATOMIC);
|
||||
const value_smoke = javascript.javascriptGenerator.valueToCode(this, 'SMOKE', javascript.Order.ATOMIC);
|
||||
const code = `${value_world}.$newExplosion(null, ${value_pos}.$x, ${value_pos}.$y, ${value_pos}.$z, ${value_strength}, (${value_fire} ? 1 : 0), (${value_smoke} ? 1 : 0));`;
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const world_command = {
|
||||
init: function () {
|
||||
this.appendValueInput('WORLD')
|
||||
.appendField('Execute command in world');
|
||||
this.appendValueInput('POS')
|
||||
.appendField('BlockPos:');
|
||||
this.appendValueInput('CMD')
|
||||
.setCheck('String')
|
||||
.appendField('Command:');
|
||||
this.appendValueInput('FEEDBACK')
|
||||
.setCheck('Boolean')
|
||||
.appendField('Feedback:');
|
||||
this.setInputsInline(false)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('NOTICE: @selectors (probably) do NOT work');
|
||||
this.setHelpUrl('https://legacy.mcstacker.net/mcstacker1.10.php');
|
||||
this.setColour(195);
|
||||
},
|
||||
libs: ["execute_command"]
|
||||
};
|
||||
Blockly.common.defineBlocks({ world_command: world_command });
|
||||
javascript.javascriptGenerator.forBlock['world_command'] = function () {
|
||||
const value_world = javascript.javascriptGenerator.valueToCode(this, 'WORLD', javascript.Order.ATOMIC);
|
||||
const value_pos = javascript.javascriptGenerator.valueToCode(this, 'POS', javascript.Order.ATOMIC);
|
||||
const value_cmd = javascript.javascriptGenerator.valueToCode(this, 'CMD', javascript.Order.ATOMIC);
|
||||
const value_feedback = javascript.javascriptGenerator.valueToCode(this, 'FEEDBACK', javascript.Order.ATOMIC);
|
||||
const code = `efb2__executeCommand(${value_world}, ${value_pos}, ${value_cmd}, ${value_feedback});`;
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const world_is_not_remote = {
|
||||
init: function () {
|
||||
this.appendValueInput('WORLD')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('world is on the server');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, 'Boolean');
|
||||
this.setTooltip('Check if the world is running on the server.');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(195);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ world_is_not_remote: world_is_not_remote });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['world_is_not_remote'] = function () {
|
||||
const value_world = javascript.javascriptGenerator.valueToCode(this, 'WORLD', javascript.Order.ATOMIC);
|
||||
const code = `!(${value_world}).$isRemote`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
|
||||
const world_get_loaded_entities = {
|
||||
init: function () {
|
||||
this.appendValueInput('WORLD')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('get list of entities in world');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, 'Array');
|
||||
this.setTooltip('Returns an array of entities in the world');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(195);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ world_get_loaded_entities: world_get_loaded_entities });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['world_get_loaded_entities'] = function () {
|
||||
const value_world = javascript.javascriptGenerator.valueToCode(this, 'WORLD', javascript.Order.ATOMIC);
|
||||
const code = `(${value_world}).$loadedEntityList.$toArray1().data`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
|
||||
const world_get_player_entities = {
|
||||
init: function () {
|
||||
this.appendValueInput('WORLD')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('get list of players in world');
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, 'Array');
|
||||
this.setTooltip('Returns an array of player entities in the world');
|
||||
this.setHelpUrl('');
|
||||
this.setColour(195);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ world_get_player_entities: world_get_player_entities });
|
||||
javascript.javascriptGenerator.forBlock['world_get_player_entities'] = function () {
|
||||
const value_world = javascript.javascriptGenerator.valueToCode(this, 'WORLD', javascript.Order.ATOMIC);
|
||||
const code = `(${value_world}).$playerEntities.$toArray1().data`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
|
||||
|
||||
|
||||
const world_execute_command_as_entity = {
|
||||
libs: ["execute_command_as"],
|
||||
init: function () {
|
||||
this.appendValueInput('MESSAGE')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.setCheck('String')
|
||||
.appendField('execute command');
|
||||
this.appendValueInput('SENDER')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('as')
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
['command sender', 'command_sender'],
|
||||
['entity', 'entity']
|
||||
]), 'TYPE');
|
||||
this.appendValueInput('FEEDBACK')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.setCheck('Boolean')
|
||||
.appendField('feedback');
|
||||
this.setInputsInline(false)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip('Executes a command as a command sender or entity.');
|
||||
this.setHelpUrl('https://legacy.mcstacker.net/mcstacker1.10.php');
|
||||
this.setColour(195);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ world_execute_command_as_entity: world_execute_command_as_entity });
|
||||
javascript.javascriptGenerator.forBlock['world_execute_command_as_entity'] = function () {
|
||||
const value_message = javascript.javascriptGenerator.valueToCode(this, 'MESSAGE', javascript.Order.ATOMIC);
|
||||
const value_sender = javascript.javascriptGenerator.valueToCode(this, 'SENDER', javascript.Order.ATOMIC);
|
||||
const value_feedback = javascript.javascriptGenerator.valueToCode(this, 'FEEDBACK', javascript.Order.ATOMIC);
|
||||
const code = `efb2__executeCommandAs(${value_sender}, ${value_message}, ${value_feedback});`;
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
const world_get_player_by_name = {
|
||||
init: function () {
|
||||
this.appendValueInput('NAME')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('get player by name')
|
||||
.setCheck('String');
|
||||
this.appendValueInput('WORLD')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('in world');
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true);
|
||||
this.setTooltip('Gets a player by his name. Can be null.');
|
||||
this.setHelpUrl('https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/entity/player/EntityPlayer.html');
|
||||
this.setColour(195);
|
||||
}
|
||||
};
|
||||
Blockly.common.defineBlocks({ world_get_player_by_name: world_get_player_by_name });
|
||||
|
||||
javascript.javascriptGenerator.forBlock['world_get_player_by_name'] = function () {
|
||||
const value_name = javascript.javascriptGenerator.valueToCode(this, 'NAME', javascript.Order.ATOMIC);
|
||||
const world = javascript.javascriptGenerator.valueToCode(this, 'WORLD', javascript.Order.ATOMIC);
|
||||
const code = `(${world}).$playerEntities.$array1.data.find((player) => player && player.$getName() && ModAPI.util.ustr(player.$getName()) === ${value_name})`;
|
||||
return [code, javascript.Order.NONE];
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
function toFunctionName(str) {
|
||||
return (/^[a-zA-Z_]/.test(str.replace(/[^a-zA-Z0-9_]/g, '')) ? '' : '_') + str.replace(/[^a-zA-Z0-9_]/g, '');
|
||||
}
|
||||
|
||||
const flags = {};
|
||||
Object.defineProperty(flags, "target", {
|
||||
get: ()=>document.querySelector("#compiler_target").value,
|
||||
set: ()=>{}
|
||||
});
|
||||
|
||||
function getCompiledCode() {
|
||||
javascript.javascriptGenerator.init(workspace);
|
||||
const watermark = `// Built in EFBN targetting ${flags.target}
|
||||
// https://github.com/eaglerforge/EaglerForgeBuilderNew
|
||||
`;
|
||||
let datablock_contents = "";
|
||||
var prereq_contents = watermark;
|
||||
let functionPrereqs = [];
|
||||
state.nodes.forEach(node => {
|
||||
delete node._deps;
|
||||
node._deps = PRIMITIVES[node.type].getDependencies.apply(node, []);
|
||||
});
|
||||
state.nodes.sort((a, b) => {
|
||||
var bDepends = b._deps.includes(a);
|
||||
var aDepends = a._deps.includes(b);
|
||||
if (bDepends && aDepends) {
|
||||
alert(`Failed to compile:\nCircular dependency between ${a.name} and ${b.name}`);
|
||||
}
|
||||
if (bDepends) {
|
||||
return -1;
|
||||
}
|
||||
if (aDepends) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
state.nodes.forEach(node => {
|
||||
functionPrereqs = functionPrereqs.concat(PRIMITIVES[node.type].uses);
|
||||
globalThis.__currentlyProcessingNode = node;
|
||||
datablock_contents += PRIMITIVES[node.type].asJavaScript.apply(node, []);
|
||||
});
|
||||
workspace.getAllBlocks().forEach(block => {
|
||||
functionPrereqs = functionPrereqs.concat(getBlockLibs(block));
|
||||
});
|
||||
// Adding event blocks compilation
|
||||
workspace.getTopBlocks(true).forEach(block => {
|
||||
if (block.type.startsWith("events_")) {
|
||||
datablock_contents += javascript.javascriptGenerator.blockToCode(block);
|
||||
}
|
||||
});
|
||||
Object.keys(javascript.javascriptGenerator.functionNames_).forEach(fn => {
|
||||
prereq_contents += javascript.javascriptGenerator.definitions_[fn];
|
||||
});
|
||||
functionPrereqs = [...new Set(functionPrereqs)]; //dedupe the list
|
||||
functionPrereqs.forEach(fn => {
|
||||
prereq_contents += getFunctionCode(FUNCTIONS[fn]);
|
||||
});
|
||||
|
||||
//let modCode = javascript.javascriptGenerator.workspaceToCode(workspace);
|
||||
|
||||
return `(function EFB2Mod() {
|
||||
const $$scoped_efb_globals = {};
|
||||
${prereq_contents}
|
||||
${datablock_contents}
|
||||
})();
|
||||
`;
|
||||
}
|
||||
|
||||
function exportMod() {
|
||||
let output = getCompiledCode()
|
||||
fileSave(output, "mod.js");
|
||||
}
|
||||
var efiBuild = null;
|
||||
function getEfiBuild() {
|
||||
return new Promise((res, rej) => {
|
||||
const fileInput = document.createElement('input');
|
||||
fileInput.type = 'file';
|
||||
fileInput.accept = ".html";
|
||||
fileInput.addEventListener('change', (event) => {
|
||||
const file = event.target.files[0];
|
||||
const reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
if (!reader.result.includes("__eaglerforgeinjector_installation_flag__")) {
|
||||
if (window.confirm("This file is not a EaglerForgeInjector build, or is too old.\nOpen the EaglerForgeInjector page?")) {
|
||||
window.open("https://eaglerforge.github.io/EaglerForgeInjector");
|
||||
}
|
||||
|
||||
return rej();
|
||||
}
|
||||
efiBuild = reader.result;
|
||||
res();
|
||||
};
|
||||
reader.readAsText(file);
|
||||
});
|
||||
fileInput.click();
|
||||
});
|
||||
}
|
||||
async function runMod() {
|
||||
var url = "data:text/javascript," + encodeURIComponent(getCompiledCode());
|
||||
if (!efiBuild) {
|
||||
await getEfiBuild();
|
||||
}
|
||||
var insp = document.querySelector("#inspector");
|
||||
insp.srcdoc = efiBuild + `<script>eaglercraftXOpts.noInitialModGui = false; eaglercraftXOpts.Mods = ["${url}"];</script>`;
|
||||
if (document.querySelector(".datablock[data-dtype=inspector]")) {
|
||||
document.querySelector(".datablock[data-dtype=inspector]").click();
|
||||
}
|
||||
}
|
||||
|
||||
document.querySelector("#export").addEventListener("click", exportMod);
|
||||
document.querySelector("#run").addEventListener("click", runMod);
|
||||
@@ -0,0 +1,236 @@
|
||||
Math.clamp = function clamp(x, min, max) {
|
||||
return Math.max(Math.min(x, max), min);
|
||||
}
|
||||
|
||||
const codeGrabberRegex = /(?<=function \(\) {)[\s\S]+(?=}$)/gm; //regex to get the contents of a stringified function
|
||||
const FUNCTIONS = {};
|
||||
|
||||
FUNCTIONS["fixup_block_ids"] = {
|
||||
//Very important that there is no name and a whitespace before and after the parantheses
|
||||
code: function () {
|
||||
function EFB2__defineFixupGlobal() {
|
||||
globalThis.efb2__fixupBlockIds = function efb2__fixupBlockIds() {
|
||||
var blockRegistry = ModAPI.util.wrap(ModAPI.reflect.getClassById("net.minecraft.block.Block").staticVariables.blockRegistry).getCorrective();
|
||||
var BLOCK_STATE_IDS = ModAPI.util.wrap(ModAPI.reflect.getClassById("net.minecraft.block.Block").staticVariables.BLOCK_STATE_IDS).getCorrective();
|
||||
blockRegistry.registryObjects.hashTableKToV.forEach(entry => {
|
||||
if (entry) {
|
||||
var block = entry.value;
|
||||
var validStates = block.getBlockState().getValidStates();
|
||||
var stateArray = validStates.array || [validStates.element];
|
||||
stateArray.forEach(iblockstate => {
|
||||
var i = blockRegistry.getIDForObject(block.getRef()) << 4 | block.getMetaFromState(iblockstate.getRef());
|
||||
BLOCK_STATE_IDS.put(iblockstate.getRef(), i);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
ModAPI.dedicatedServer.appendCode(EFB2__defineFixupGlobal);
|
||||
EFB2__defineFixupGlobal();
|
||||
},
|
||||
};
|
||||
|
||||
FUNCTIONS["execute_command"] = {
|
||||
//Very important that there is no name and a whitespace before and after the parantheses
|
||||
code: function () {
|
||||
function EFB2__defineExecCmdGlobal() {
|
||||
globalThis.efb2__executeCommand = function efb2__executeCommand($world, $blockpos, commandStr, feedback) {
|
||||
if ($world.$isRemote) {
|
||||
return;
|
||||
}
|
||||
function x() {
|
||||
ModAPI.reflect.getSuper(ModAPI.reflect.getClassByName("CommandBlockLogic"))(this);
|
||||
}
|
||||
ModAPI.reflect.prototypeStack(ModAPI.reflect.getClassByName("CommandBlockLogic"), x);
|
||||
var vector = ModAPI.reflect.getClassByName("Vec3").constructors[0]($blockpos.$x + 0.5, $blockpos.$y + 0.5, $blockpos.$z + 0.5);
|
||||
x.prototype.$getEntityWorld = () => { return $world };
|
||||
x.prototype.$getCommandSenderEntity = () => { return null };
|
||||
x.prototype.$updateCommand = () => { };
|
||||
x.prototype.$addChatMessage = (e) => { console.log(e) };
|
||||
x.prototype.$func_145757_a = () => { };
|
||||
x.prototype.$getPosition = () => { return $blockpos };
|
||||
x.prototype.$getPosition0 = () => { return $blockpos };
|
||||
x.prototype.$getPositionVector = () => { return vector };
|
||||
x.prototype.$func_145751_f = () => { return 0 };
|
||||
x.prototype.$sendCommandFeedback = () => { return feedback ? 1 : 0 }
|
||||
var cmd = new x();
|
||||
cmd.$setCommand(ModAPI.util.str(commandStr));
|
||||
|
||||
const notifyOps0 = ModAPI.hooks.methods.nmc_CommandBase_notifyOperators0;
|
||||
const notifyOps = ModAPI.hooks.methods.nmc_CommandBase_notifyOperators;
|
||||
|
||||
if (!feedback) {
|
||||
ModAPI.hooks.methods.nmc_CommandBase_notifyOperators0 = () => { };
|
||||
ModAPI.hooks.methods.nmc_CommandBase_notifyOperators = () => { };
|
||||
}
|
||||
|
||||
try {
|
||||
cmd.$trigger($world);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
if (!feedback) {
|
||||
ModAPI.hooks.methods.nmc_CommandBase_notifyOperators0 = notifyOps0;
|
||||
ModAPI.hooks.methods.nmc_CommandBase_notifyOperators = notifyOps;
|
||||
}
|
||||
}
|
||||
}
|
||||
ModAPI.dedicatedServer.appendCode(EFB2__defineExecCmdGlobal);
|
||||
EFB2__defineExecCmdGlobal();
|
||||
},
|
||||
};
|
||||
|
||||
FUNCTIONS["execute_command_as"] = {
|
||||
//Very important that there is no name and a whitespace before and after the parantheses
|
||||
code: function () {
|
||||
function EFB2__defineExecCmdAsGlobal() {
|
||||
var getServer = ModAPI.reflect.getClassById("net.minecraft.server.MinecraftServer").staticMethods.getServer?.method;
|
||||
globalThis.efb2__executeCommandAs = function efb2__executeCommandAs($commandsender, command, feedback) {
|
||||
var server = getServer ?
|
||||
getServer() : //1.8
|
||||
ModAPI.reflect.getClassById("net.minecraft.server.MinecraftServer").staticVariables.server; //1.12
|
||||
if (!server) { return };
|
||||
var commandManager = server.$commandManager;
|
||||
|
||||
//lie a bit
|
||||
var x = $commandsender.$canCommandSenderUseCommand;
|
||||
$commandsender.$canCommandSenderUseCommand = () => 1;
|
||||
|
||||
var y = $commandsender.$sendCommandFeedback;
|
||||
$commandsender.$sendCommandFeedback = feedback ? () => 1 : () => 0;
|
||||
|
||||
const notifyOps0 = ModAPI.hooks.methods.nmc_CommandBase_notifyOperators0;
|
||||
const notifyOps = ModAPI.hooks.methods.nmc_CommandBase_notifyOperators;
|
||||
const addChatMsg = $commandsender.$addChatMessage;
|
||||
|
||||
if (!feedback) {
|
||||
ModAPI.hooks.methods.nmc_CommandBase_notifyOperators0 = () => { };
|
||||
ModAPI.hooks.methods.nmc_CommandBase_notifyOperators = () => { };
|
||||
$commandsender.$addChatMessage = () => { };
|
||||
}
|
||||
|
||||
try {
|
||||
commandManager.$executeCommand($commandsender, ModAPI.util.str(command));
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
if (!feedback) {
|
||||
ModAPI.hooks.methods.nmc_CommandBase_notifyOperators0 = notifyOps0;
|
||||
ModAPI.hooks.methods.nmc_CommandBase_notifyOperators = notifyOps;
|
||||
$commandsender.$addChatMessage = addChatMsg;
|
||||
}
|
||||
|
||||
$commandsender.$canCommandSenderUseCommand = x;
|
||||
$commandsender.$sendCommandFeedback = y;
|
||||
}
|
||||
}
|
||||
ModAPI.dedicatedServer.appendCode(EFB2__defineExecCmdAsGlobal);
|
||||
EFB2__defineExecCmdAsGlobal();
|
||||
},
|
||||
};
|
||||
|
||||
FUNCTIONS["construct_vec3"] = {
|
||||
//Very important that there is no name and a whitespace before and after the parantheses
|
||||
code: function () {
|
||||
function EFB2__defineMakeVec3() {
|
||||
var mkVec3 = ModAPI.reflect.getClassById("net.minecraft.util.Vec3").constructors.find(x => x.length === 3);
|
||||
globalThis.efb2__makeVec3 = function efb2__makeVec3(x, y, z) {
|
||||
return mkVec3(x, y, z);
|
||||
}
|
||||
}
|
||||
ModAPI.dedicatedServer.appendCode(EFB2__defineMakeVec3);
|
||||
EFB2__defineMakeVec3();
|
||||
},
|
||||
};
|
||||
|
||||
FUNCTIONS["construct_blockpos"] = {
|
||||
//Very important that there is no name and a whitespace before and after the parantheses
|
||||
code: function () {
|
||||
function EFB2__defineMakeBlockPos() {
|
||||
var mkBlockPos = ModAPI.reflect.getClassById("net.minecraft.util.BlockPos").constructors.find(x => x.length === 3);
|
||||
globalThis.efb2__makeBlockPos = function efb2__makeBlockPos(x, y, z) {
|
||||
return mkBlockPos(x, y, z);
|
||||
}
|
||||
}
|
||||
ModAPI.dedicatedServer.appendCode(EFB2__defineMakeBlockPos);
|
||||
EFB2__defineMakeBlockPos();
|
||||
},
|
||||
};
|
||||
|
||||
FUNCTIONS["message_command_sender"] = {
|
||||
//Very important that there is no name and a whitespace before and after the parantheses
|
||||
code: function () {
|
||||
function EFB2__defineMessageCommandSender() {
|
||||
var chatComponentText = ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText").constructors[0];
|
||||
globalThis.efb2__messageCommandSender = function efb2__messageCommandSender(cmdSender, str) {
|
||||
return cmdSender.$addChatMessage(chatComponentText(ModAPI.util.str(str)));
|
||||
}
|
||||
}
|
||||
ModAPI.dedicatedServer.appendCode(EFB2__defineMessageCommandSender);
|
||||
EFB2__defineMessageCommandSender();
|
||||
},
|
||||
};
|
||||
|
||||
FUNCTIONS["java_logger"] = {
|
||||
//Very important that there is no name and a whitespace before and after the parantheses
|
||||
code: function () {
|
||||
function EFB2__defineJavaLogger() {
|
||||
var logger = ModAPI.reflect.getClassByName("LogManager").staticMethods.getLogger0.method();
|
||||
globalThis.efb2__jlog = function efb2__jlog(log) {
|
||||
if (typeof log === "string") {
|
||||
logger.$info(ModAPI.util.str(log));
|
||||
} else {
|
||||
console.log(log);
|
||||
}
|
||||
}
|
||||
globalThis.efb2__jwarn = function efb2__jwarn(log) {
|
||||
logger.$warn(ModAPI.util.str(log));
|
||||
}
|
||||
globalThis.efb2__jerr = function efb2__jerr(log) {
|
||||
logger.$error1(ModAPI.util.str(log));
|
||||
}
|
||||
}
|
||||
ModAPI.dedicatedServer.appendCode(EFB2__defineJavaLogger);
|
||||
EFB2__defineJavaLogger();
|
||||
},
|
||||
};
|
||||
|
||||
FUNCTIONS["str2ab"] = {
|
||||
//Very important that there is no name and a whitespace before and after the parantheses
|
||||
code: function () {
|
||||
function EFB2__defineStr2Ab() {
|
||||
globalThis.efb2__str2ab = function efb2__str2ab(str) {
|
||||
var buf = new ArrayBuffer(str.length);
|
||||
var bufView = new Uint8Array(buf);
|
||||
for (var i = 0, strLen = str.length; i < strLen; i++) {
|
||||
bufView[i] = str.charCodeAt(i);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
ModAPI.dedicatedServer.appendCode(EFB2__defineStr2Ab);
|
||||
EFB2__defineStr2Ab();
|
||||
},
|
||||
}
|
||||
|
||||
FUNCTIONS["attribute_map_set"] = {
|
||||
code: function () {
|
||||
function EFB2_defineAttrMapSet() {
|
||||
const AttributeModifier = ModAPI.reflect.getClassByName("AttributeModifier").constructors.find(x => x.length === 4);
|
||||
const secretUUID = ModAPI.reflect.getClassByName("Item").staticVariables.itemModifierUUID;
|
||||
globalThis.efb2__attrMapSet = function efb2__attrMapSet(map, key, value) {
|
||||
map.$put(ModAPI.util.str(key), AttributeModifier(secretUUID, ModAPI.util.str("Tool modifier"), value, 0));
|
||||
}
|
||||
}
|
||||
ModAPI.dedicatedServer.appendCode(EFB2_defineAttrMapSet);
|
||||
EFB2_defineAttrMapSet();
|
||||
}
|
||||
}
|
||||
|
||||
function getFunctionCode(fn) {
|
||||
if (!fn) return "";
|
||||
return fn.code.toString().match(codeGrabberRegex)?.[0]
|
||||
|| (() => { console.error("Malformed function: ", fn); return ""; })();
|
||||
}
|
||||
@@ -0,0 +1,649 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>EaglerForgeBuilderNew</title>
|
||||
<link rel="stylesheet" href="stylesheet.css" />
|
||||
|
||||
<!-- Load Blockly core -->
|
||||
<script src="./libs/blockly/blockly_compressed.js"></script>
|
||||
|
||||
<!-- Load the default blocks -->
|
||||
<script src="./libs/blockly/blocks_compressed.js"></script>
|
||||
|
||||
<!-- Load a generator -->
|
||||
<script src="./libs/blockly/javascript_compressed.js"></script>
|
||||
|
||||
<!-- Load a message file -->
|
||||
<script src="./libs/blockly/en.js"></script>
|
||||
|
||||
<!-- Load eruda console -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/eruda" onload="eruda.init()"></script>
|
||||
|
||||
<!-- Load dark mode -->
|
||||
<script src="./libs/blockly/darktheme.js"></script>
|
||||
|
||||
<!-- Load blockly dev tools -->
|
||||
<script src="./libs/blockly/blockly_dev_tools.js"></script>
|
||||
|
||||
<!-- Load handler argument patch -->
|
||||
<script src="./libs/blockly/blockly_patch.js"></script>
|
||||
|
||||
<!-- Load item and block selector patch -->
|
||||
<script src="./libs/blockly/blockly_minecraft_item_selector.js"></script>
|
||||
|
||||
<xml
|
||||
xmlns="https://developers.google.com/blockly/xml"
|
||||
id="toolbox"
|
||||
style="display: none"
|
||||
>
|
||||
<category name="Logic" colour="#5b80a5">
|
||||
<block type="controls_if"></block>
|
||||
<block type="logic_compare">
|
||||
<field name="OP">EQ</field>
|
||||
</block>
|
||||
<block type="logic_operation">
|
||||
<field name="OP">AND</field>
|
||||
</block>
|
||||
<block type="logic_negate"></block>
|
||||
<block type="logic_boolean">
|
||||
<field name="BOOL">TRUE</field>
|
||||
</block>
|
||||
<block type="logic_null"></block>
|
||||
<block type="logic_a_or_b"></block>
|
||||
<block type="logic_ternary"></block>
|
||||
</category>
|
||||
<category name="Loops" colour="#5ba55b">
|
||||
<block type="controls_repeat_ext">
|
||||
<value name="TIMES">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">10</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="controls_whileUntil">
|
||||
<field name="MODE">WHILE</field>
|
||||
</block>
|
||||
<block type="controls_for">
|
||||
<field name="VAR" id=":ajQQC^!][(eT3;33w[k">i</field>
|
||||
<value name="FROM">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">10</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="BY">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="controls_forEach">
|
||||
<field name="VAR" id="w.NtRHu,vLo5uAjge%7?">j</field>
|
||||
</block>
|
||||
<block type="controls_flow_statements">
|
||||
<field name="FLOW">BREAK</field>
|
||||
</block>
|
||||
<block type="proc_wait">
|
||||
<value name="VALUE">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="proc_asyncrun">
|
||||
<value name="DELAY">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
</category>
|
||||
<category name="Math" colour="#5b67a5">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</block>
|
||||
<block type="math_arithmetic">
|
||||
<field name="OP">ADD</field>
|
||||
<value name="A">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="B">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_single">
|
||||
<field name="OP">ROOT</field>
|
||||
<value name="NUM">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">9</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_trig">
|
||||
<field name="OP">SIN</field>
|
||||
<value name="NUM">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">45</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_constant">
|
||||
<field name="CONSTANT">PI</field>
|
||||
</block>
|
||||
<block type="math_number_property">
|
||||
<mutation divisor_input="false"></mutation>
|
||||
<field name="PROPERTY">EVEN</field>
|
||||
<value name="NUMBER_TO_CHECK">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_round">
|
||||
<field name="OP">ROUND</field>
|
||||
<value name="NUM">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">3.1</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_on_list">
|
||||
<mutation op="SUM"></mutation>
|
||||
<field name="OP">SUM</field>
|
||||
</block>
|
||||
<block type="math_modulo">
|
||||
<value name="DIVIDEND">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">64</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="DIVISOR">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">10</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_constrain">
|
||||
<value name="VALUE">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">50</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="LOW">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="HIGH">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">100</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_random_int">
|
||||
<value name="FROM">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">100</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_random_float"></block>
|
||||
</category>
|
||||
<category name="Text" colour="#5ba58c">
|
||||
<block type="text">
|
||||
<field name="TEXT"></field>
|
||||
</block>
|
||||
<block type="text_join">
|
||||
<mutation items="2"></mutation>
|
||||
</block>
|
||||
<block type="text_append">
|
||||
<field name="VAR" id="o4A872,H8svB|p9?`+~v">item</field>
|
||||
<value name="TEXT">
|
||||
<shadow type="text">
|
||||
<field name="TEXT"></field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_length">
|
||||
<value name="VALUE">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">abc</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_isEmpty">
|
||||
<value name="VALUE">
|
||||
<shadow type="text">
|
||||
<field name="TEXT"></field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_indexOf">
|
||||
<field name="END">FIRST</field>
|
||||
<value name="VALUE">
|
||||
<block type="variables_get">
|
||||
<field name="VAR" id="2M)8,;1:WvaP#5-8/k9)">text</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="FIND">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">abc</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_charAt">
|
||||
<mutation at="true"></mutation>
|
||||
<field name="WHERE">FROM_START</field>
|
||||
<value name="VALUE">
|
||||
<block type="variables_get">
|
||||
<field name="VAR" id="2M)8,;1:WvaP#5-8/k9)">text</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_getSubstring">
|
||||
<mutation at1="true" at2="true"></mutation>
|
||||
<field name="WHERE1">FROM_START</field>
|
||||
<field name="WHERE2">FROM_START</field>
|
||||
<value name="STRING">
|
||||
<block type="variables_get">
|
||||
<field name="VAR" id="2M)8,;1:WvaP#5-8/k9)">text</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_changeCase">
|
||||
<field name="CASE">UPPERCASE</field>
|
||||
<value name="TEXT">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">abc</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_trim">
|
||||
<field name="MODE">BOTH</field>
|
||||
<value name="TEXT">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">abc</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="comment">
|
||||
</block>
|
||||
<block type="text_print">
|
||||
<value name="TEXT">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">abc</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
</category>
|
||||
<category name="Lists" colour="#745ba5">
|
||||
<block type="lists_create_with">
|
||||
<mutation items="0"></mutation>
|
||||
</block>
|
||||
<block type="lists_create_with">
|
||||
<mutation items="3"></mutation>
|
||||
</block>
|
||||
<block type="lists_repeat">
|
||||
<value name="NUM">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">5</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="lists_length"></block>
|
||||
<block type="lists_isEmpty"></block>
|
||||
<block type="lists_indexOf">
|
||||
<field name="END">FIRST</field>
|
||||
<value name="VALUE">
|
||||
<block type="variables_get">
|
||||
<field name="VAR" id="k8|hQIbGNUm?zO%Na,Da">list</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="lists_getIndex">
|
||||
<mutation statement="false" at="true"></mutation>
|
||||
<field name="MODE">GET</field>
|
||||
<field name="WHERE">FROM_START</field>
|
||||
<value name="VALUE">
|
||||
<block type="variables_get">
|
||||
<field name="VAR" id="k8|hQIbGNUm?zO%Na,Da">list</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="lists_setIndex">
|
||||
<mutation at="true"></mutation>
|
||||
<field name="MODE">SET</field>
|
||||
<field name="WHERE">FROM_START</field>
|
||||
<value name="LIST">
|
||||
<block type="variables_get">
|
||||
<field name="VAR" id="k8|hQIbGNUm?zO%Na,Da">list</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="lists_getSublist">
|
||||
<mutation at1="true" at2="true"></mutation>
|
||||
<field name="WHERE1">FROM_START</field>
|
||||
<field name="WHERE2">FROM_START</field>
|
||||
<value name="LIST">
|
||||
<block type="variables_get">
|
||||
<field name="VAR" id="k8|hQIbGNUm?zO%Na,Da">list</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="lists_split">
|
||||
<mutation mode="SPLIT"></mutation>
|
||||
<field name="MODE">SPLIT</field>
|
||||
<value name="DELIM">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">,</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="list_includes">
|
||||
<value name="LIST">
|
||||
<block type="variables_get">
|
||||
<field name="VAR" id="k8|hQIbGNUm?zO%Na,Da">list</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="VALUE">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">apple</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
</category>
|
||||
<sep></sep>
|
||||
<category name="Return" colour="#008855">
|
||||
<block type="local_this"> </block>
|
||||
<block type="proc_return"> </block>
|
||||
<block type="proc_returnvalue">
|
||||
<value name="VALUE">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">0.5</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="proc_returnbool">
|
||||
<field name="VALUE"> </field>
|
||||
</block>
|
||||
</category>
|
||||
<category name="Events" colour="#a59f5b">
|
||||
<block type="events_onModLoads">
|
||||
</block>
|
||||
<block type="events_onJoinWorld">
|
||||
</block>
|
||||
<!-- <block type="events_onKeyPressed">
|
||||
</block>
|
||||
<block type="events_onKeyReleased">
|
||||
</block>
|
||||
-->
|
||||
<block type="events_onClientTick">
|
||||
</block>
|
||||
<block type="events_onClientFrame">
|
||||
</block>
|
||||
</category>
|
||||
<sep></sep>
|
||||
<category name="Variables" colour="#a55b80" custom="VARIABLE"></category>
|
||||
<category name="Globals" colour="#42f5bf">
|
||||
<block type="globals_get"></block>
|
||||
<block type="globals_set"></block>
|
||||
<block type="globals_delete"></block>
|
||||
<block type="globals_exists"></block>
|
||||
</category>
|
||||
<category name="Functions" colour="#995ba5" custom="PROCEDURE"></category>
|
||||
<sep></sep>
|
||||
<category name="Blocks (H)" colour="#dd11dd">
|
||||
<block type="handle_BlockConstructor"> </block>
|
||||
<block type="handle_BlockBreak"> </block>
|
||||
<block type="handle_BlockAdded"> </block>
|
||||
<block type="handle_BlockNeighbourChange"> </block>
|
||||
<block type="handle_BlockBrokenByPlayer"> </block>
|
||||
<block type="handle_BlockRandomTick"> </block>
|
||||
<block type="handle_BlockEntityCollision"> </block>
|
||||
<block type="handle_BlockGetDroppedItem"> </block>
|
||||
<block type="handle_BlockQuantityDropped"> </block>
|
||||
</category>
|
||||
<category name="Blocks (C)" colour="#dd11dd">
|
||||
<block type="blocks_currentblock"> </block>
|
||||
<block type="blocks_block"> </block>
|
||||
<block type="blocks_blockproperty"> </block>
|
||||
<block type="blocks_blockswitch"> </block>
|
||||
<block type="blocks_boundingbox"> </block>
|
||||
<block type="blocks_creativetab"> </block>
|
||||
<block type="blocks_setsoundtype"> </block>
|
||||
</category>
|
||||
<category name="Items (H)" colour="#0033dd">
|
||||
<block type="handle_ItemConstructor"> </block>
|
||||
<block type="handle_ItemRightClick"> </block>
|
||||
<block type="handle_ItemUsed"> </block>
|
||||
<block type="handle_ItemTicked"> </block>
|
||||
<block type="handle_ItemBlockUse"> </block>
|
||||
<block type="handle_ItemCrafted"> </block>
|
||||
<block type="handle_ItemBlockBroken"> </block>
|
||||
<block type="handle_ItemGetAttributes"> </block>
|
||||
<block type="handle_ItemGetEfficiency"> </block>
|
||||
</category>
|
||||
<category name="Items (C)" colour="#0033dd">
|
||||
<block type="items_currentitem"> </block>
|
||||
<block type="items_item"> </block>
|
||||
<block type="items_creativetab"> </block>
|
||||
<block type="items_setmaxstacksize"> </block>
|
||||
<block type="items_get_applicable_blocks"> </block>
|
||||
</category>
|
||||
<category name="ItemStack (C)" colour="#44eebb">
|
||||
<block type="itemstack_meta"> </block>
|
||||
<block type="itemstack_setmeta"> </block>
|
||||
<block type="itemstack_getitem"> </block>
|
||||
<block type="itemstack_stacksize"> </block>
|
||||
<block type="itemstack_setstacksize"> </block>
|
||||
<block type="itemstack_displayname"> </block>
|
||||
<block type="itemstack_setdisplayname"> </block>
|
||||
<sep gap="40"></sep>
|
||||
<block type="itemstack_enchant"> </block>
|
||||
<block type="itemstack_repaircost"> </block>
|
||||
<block type="itemstack_setrepaircost"> </block>
|
||||
</category>
|
||||
<category name="SharedAttributes (C)" colour="#fcba03">
|
||||
<block type="attributes_set"> </block>
|
||||
</category>
|
||||
<category name="BlockPos (C)" colour="#6633cc">
|
||||
<block type="blockpos_fromxyz"> </block>
|
||||
<block type="blockpos_getxyz"> </block>
|
||||
</category>
|
||||
<category name="ActionResult 1.12 (C)" colour="#6633cc">
|
||||
<block type="enumaction"> </block>
|
||||
<block type="actionresult"> </block>
|
||||
</category>
|
||||
<category name="Vec3 (C)" colour="#6633cc">
|
||||
<block type="vec3_fromxyz"> </block>
|
||||
<block type="vec3_getxyz"> </block>
|
||||
<block type="vec3_dist"> </block>
|
||||
</category>
|
||||
<category name="Debugger (C)" colour="#4422aa">
|
||||
<block type="debug_log"> </block>
|
||||
<block type="debug_warn"> </block>
|
||||
<block type="debug_err"> </block>
|
||||
<block type="debug_debugger"> </block>
|
||||
</category>
|
||||
<category name="World (C)" colour="#22aabb">
|
||||
<block type="world_is_not_remote"> </block>
|
||||
<block type="world_explosion"> </block>
|
||||
<block type="world_command"> </block>
|
||||
<block type="world_execute_command_as_entity"> </block>
|
||||
<block type="world_get_loaded_entities"> </block>
|
||||
<block type="world_get_player_entities"> </block>
|
||||
<block type="world_get_player_by_name"> </block>
|
||||
</category>
|
||||
<category name="Entity (C)" colour="#ff8811">
|
||||
<block type="entity_set_position"> </block>
|
||||
<block type="entity_set_position_xyz"> </block>
|
||||
<block type="entity_get_prop"> </block>
|
||||
<block type="entity_set_prop"> </block>
|
||||
<sep gap="40"></sep>
|
||||
<block type="entity_get_switch"> </block>
|
||||
<block type="entity_set_switch"> </block>
|
||||
<sep gap="40"></sep>
|
||||
<block type="entity_get_world"> </block>
|
||||
<block type="entity_get_position"> </block>
|
||||
<block type="entity_distance"> </block>
|
||||
<block type="entity_distance_vec3"> </block>
|
||||
<block type="entity_get_lookvec"> </block>
|
||||
<block type="entity_get_eye_pos"> </block>
|
||||
<block type="entity_raytrace"> </block>
|
||||
</category>
|
||||
<category name="Player (C)" colour="#ff8811">
|
||||
<button text="Help" callbackKey="playerHelpButton"></button>
|
||||
<sep gap="30"></sep>
|
||||
<block type="player_get_capability_boolean"> </block>
|
||||
<block type="player_get_capability_number"> </block>
|
||||
<block type="player_get_food_stats"> </block>
|
||||
<block type="player_get_xp_stats"> </block>
|
||||
<sep gap="40"></sep>
|
||||
<block type="player_get_player_inventory"> </block>
|
||||
<block type="player_get_item_hand"> </block>
|
||||
<block type="player_get_current_item_pos"> </block>
|
||||
<sep gap="40"></sep>
|
||||
<block type="player_get_player_name"> </block>
|
||||
<block type="player_is_entity_player"> </block>
|
||||
</category>
|
||||
<category name="Command (H)" colour="#ed120e">
|
||||
<block type="handle_CommandCalledByPlayer"> </block>
|
||||
<block type="handle_CommandCalled"> </block>
|
||||
</category>
|
||||
<category name="Command (C)" colour="#ed120e">
|
||||
<block type="command_sendmessage"> </block>
|
||||
<block type="command_get_position"> </block>
|
||||
<block type="command_get_world"> </block>
|
||||
<block type="command_get_entity"> </block>
|
||||
<block type="command_get_name"> </block>
|
||||
</category>
|
||||
<category name="Crafting Recipe (H)" colour="#8c5e4d">
|
||||
<block type="handle_CraftingRecipeModifyResult"> </block>
|
||||
</category>
|
||||
</xml>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<div id="toolbar">
|
||||
<h1>EaglerForgeBuilder Public Beta</h1>
|
||||
<button id="load">Load</button>
|
||||
<button id="save">Save</button>
|
||||
<button id="export">Export</button>
|
||||
<button id="run">Run</button>
|
||||
|
||||
<label>Compiler Target (WIP): </label>
|
||||
<select id="compiler_target">
|
||||
<option value="1_8">1.8.x</option>
|
||||
<option value="1_12">1.12.x</option>
|
||||
</select>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<div id="blockly" style="background-color: darkslategrey"></div>
|
||||
</td>
|
||||
<td id="right">
|
||||
<div id="propnav">properties of datablock</div>
|
||||
<select id="addtype"></select>
|
||||
<button style="margin-bottom: 1rem" id="newdatablock">
|
||||
New
|
||||
</button>
|
||||
<div id="datablock_container">
|
||||
<input
|
||||
id="search"
|
||||
type="search"
|
||||
value=""
|
||||
placeholder="Search for content: "
|
||||
/><br />
|
||||
<span class="datablock selected">
|
||||
<h4>Dirt Block</h4>
|
||||
<br />
|
||||
<i>Type: Block</i>
|
||||
<br /><br />
|
||||
<div class="controls">
|
||||
<button>Delete</button>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<!-- Blockly block libmap builder -->
|
||||
<script src="block_libmap.js"></script>
|
||||
<script src="libs/upatch.js"></script>
|
||||
<script src="libs/item_selector.js"></script>
|
||||
<script src="libs/handler_register.js"></script>
|
||||
|
||||
<!-- Additional blocks -->
|
||||
<script src="blocks/World.js"></script>
|
||||
<script src="blocks/Commands.js"></script>
|
||||
<script src="blocks/CraftingRecipe.js"></script>
|
||||
<script src="blocks/SharedAttributes.js"></script>
|
||||
<script src="blocks/ItemStack.js"></script>
|
||||
<script src="blocks/Blocks.js"></script>
|
||||
<script src="blocks/Items.js"></script>
|
||||
<script src="blocks/Entity.js"></script>
|
||||
<script src="blocks/Player.js"></script>
|
||||
<script src="blocks/Vec3.js"></script>
|
||||
<script src="blocks/BlockPos.js"></script>
|
||||
<script src="blocks/Debug.js"></script>
|
||||
<script src="blocks/Events.js"></script> <!-- Currently unused -->
|
||||
<script src="blocks/ReturnBlock.js"></script>
|
||||
<script src="blocks/ActionResult.js"></script>
|
||||
<script src="blocks/Utils.js"></script>
|
||||
|
||||
<!-- The datablock types -->
|
||||
<script src="types.js"></script>
|
||||
|
||||
<!-- Datablock Primitives -->
|
||||
<script src="primitives/Inspector.js"></script>
|
||||
<script src="primitives/Metadata.js"></script>
|
||||
<script src="primitives/Icon.js"></script>
|
||||
<script src="primitives/OreGeneration.js"></script>
|
||||
<script src="primitives/AdvancedBlock.js"></script>
|
||||
<script src="primitives/Item.js"></script>
|
||||
<script src="primitives/Command.js"></script>
|
||||
<script src="primitives/CraftingRecipe.js"></script>
|
||||
<script src="primitives/FurnaceRecipe.js"></script>
|
||||
|
||||
<!-- Web App GUI and Engine -->
|
||||
<script src="functions.js"></script>
|
||||
<script src="propviewer.js"></script>
|
||||
<script src="index.js"></script>
|
||||
<script src="serialise.js"></script>
|
||||
<script src="compiler.js"></script>
|
||||
|
||||
<!-- Button script -->
|
||||
<script>
|
||||
function playerHelpButton() {
|
||||
alert("Players are entities, by consequence all the blocks for entities also work for players, but not the contrary.");
|
||||
}
|
||||
Blockly.getMainWorkspace().registerButtonCallback("playerHelpButton", playerHelpButton)
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,202 @@
|
||||
var workspace = globalThis.workspace = Blockly.inject('blockly', {
|
||||
collapse: true,
|
||||
comments: true,
|
||||
css: true,
|
||||
disable: true,
|
||||
renderer: 'zelos',
|
||||
scrollbars: true,
|
||||
sounds: true,
|
||||
theme: "dark",
|
||||
trashcan: true,
|
||||
readOnly: false,
|
||||
toolbox: document.querySelector("#toolbox"),
|
||||
zoom: {
|
||||
controls: true,
|
||||
wheel: true,
|
||||
startScale: 1.0,
|
||||
maxScale: 3,
|
||||
minScale: 0.3,
|
||||
scaleSpeed: 1.2,
|
||||
pinch: true
|
||||
},
|
||||
});
|
||||
javascript.javascriptGenerator.addReservedWords("ModAPI", "PluginAPI", "window", "globalThis");
|
||||
workspace.addChangeListener(removeUnusedArgumentVariables);
|
||||
blocklyDeveloperTools();
|
||||
const oldScrub = javascript.javascriptGenerator.scrub_;
|
||||
var rippedCode = null; //Used to decompile function definitions later.
|
||||
javascript.javascriptGenerator.scrub_ = function (...args) {
|
||||
rippedCode = args[1];
|
||||
return oldScrub.apply(this, args);
|
||||
}
|
||||
var handlers = {};
|
||||
var handlerMapDict = {};
|
||||
function getHandlers(type) {
|
||||
return handlers["handle_" + type] || [];
|
||||
}
|
||||
function getHandler(type, name) {
|
||||
return handlerMapDict["handle_" + type]?.[name] || null;
|
||||
}
|
||||
function depsgraph_search(blck, enounteredFunctions, usedVariableSet, procMap) {
|
||||
const FN_PROCCODES = ["procedures_callreturn", "procedures_callnoreturn"];
|
||||
const FN_DEFCODES = ["procedures_defreturn", "procedures_defnoreturn"];
|
||||
enounteredFunctions ||= new Set();
|
||||
usedVariableSet ||= new Set();
|
||||
procMap ||= Object.fromEntries(workspace.getAllBlocks().filter(x=>FN_DEFCODES.includes(x.type)).map(x=>[x.getProcedureDef()[0], x]));
|
||||
|
||||
var descendants = blck.getDescendants(true);
|
||||
for (let i = 0; i < descendants.length; i++) {
|
||||
const descendant = descendants[i];
|
||||
if (FN_PROCCODES.includes(descendant.type) && !enounteredFunctions.has(descendant.getProcedureCall())) {
|
||||
var proccode = descendant.getProcedureCall();
|
||||
enounteredFunctions.add(proccode);
|
||||
depsgraph_search(procMap[proccode], enounteredFunctions, usedVariableSet, procMap);
|
||||
continue;
|
||||
}
|
||||
descendant.getVars().forEach(varId => {
|
||||
usedVariableSet.add(varId);
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
usedVariableSet,
|
||||
enounteredFunctions,
|
||||
procMap
|
||||
}
|
||||
}
|
||||
function getProcedureCode(name, procMap) {
|
||||
javascript.javascriptGenerator.blockToCode(procMap[name]); //for some *stupid* reason, is hardcoded to always return null.
|
||||
return rippedCode;
|
||||
}
|
||||
function getHandlerCode(type, tag, defaultArgs, targetMapper) {
|
||||
var handler = getHandler(type, tag);
|
||||
if (!handler && targetMapper) {
|
||||
return "";
|
||||
}
|
||||
if (!handler) { return { code: "", args: defaultArgs } };
|
||||
var { usedVariableSet, enounteredFunctions, procMap } = depsgraph_search(handler);
|
||||
var generatedCode = javascript.javascriptGenerator.forBlock[handler.type].apply(handler, []);
|
||||
|
||||
var variableCode = [...usedVariableSet].map(varId => { return javascript.javascriptGenerator.getVariableName(varId) }).join(",");
|
||||
variableCode = variableCode ? ("var " + variableCode + ";") : "";
|
||||
|
||||
var procedureCode = [...enounteredFunctions].map(x => getProcedureCode(x, procMap)).join(";");
|
||||
|
||||
generatedCode.code = variableCode + procedureCode + generatedCode.code;
|
||||
|
||||
if (targetMapper) {
|
||||
const mappingFunction = Object.entries(targetMapper).filter(ent=>ent[0].split(",").includes(flags.target))[0]?.[1];
|
||||
if (!mappingFunction) {
|
||||
alert("Mapping function for handler " + type + " not defined! Please contact developers.");
|
||||
throw Error("Mapping fn not defined!");
|
||||
}
|
||||
return mappingFunction.apply(globalThis.__currentlyProcessingNode, [generatedCode.args, generatedCode.code]);
|
||||
};
|
||||
return generatedCode;
|
||||
}
|
||||
const supportedEvents = [
|
||||
Blockly.Events.BlockFieldIntermediateChange,
|
||||
Blockly.Events.BlockChange,
|
||||
Blockly.Events.BlockCreate,
|
||||
Blockly.Events.BlockDelete
|
||||
];
|
||||
function updateHandlers(e) {
|
||||
if (!supportedEvents.reduce((acc, x)=>acc||(e instanceof x))) {return}
|
||||
if (workspace.isDragging()) return;
|
||||
handlers = {};
|
||||
handlerMapDict = {};
|
||||
workspace.getAllBlocks().forEach(block => {
|
||||
var id = block.getFieldValue("ID");
|
||||
if (id === "None") {
|
||||
return;
|
||||
}
|
||||
if (!handlers[block.type]) {
|
||||
handlers[block.type] = [id];
|
||||
handlerMapDict[block.type] = Object.fromEntries([[id, block]]);
|
||||
} else {
|
||||
|
||||
if (handlers[block.type].includes(id)) {
|
||||
return;
|
||||
}
|
||||
handlers[block.type].push(id);
|
||||
handlerMapDict[block.type][id] = block;
|
||||
}
|
||||
});
|
||||
document.querySelectorAll(".handler_select").forEach(x => {
|
||||
x.updateHandlerList(e instanceof Blockly.Events.BlockFieldIntermediateChange);
|
||||
});
|
||||
}
|
||||
workspace.addChangeListener(updateHandlers);
|
||||
var state = globalThis.state = {
|
||||
nodes: [
|
||||
getPrimitive("metadata"),
|
||||
getPrimitive("icon"),
|
||||
]
|
||||
};
|
||||
var inspector = getPrimitive("inspector");
|
||||
function reloadUI(sel) {
|
||||
if (!state.nodes.includes(sel)) {
|
||||
sel = document.querySelector(".datablock.selected")?.datablock;
|
||||
}
|
||||
document.querySelector("#propnav").innerHTML = "";
|
||||
document.querySelectorAll(".datablock").forEach(elem => {
|
||||
elem.remove();
|
||||
});
|
||||
document.querySelector("#search").value = "";
|
||||
var datablockContainer = document.querySelector("#datablock_container");
|
||||
state.nodes.concat(inspector).forEach((node, index) => {
|
||||
var datablock = document.createElement("span");
|
||||
datablock.datablock = node;
|
||||
datablock.classList.add("datablock");
|
||||
datablock.setAttribute("data-dtype", node.type);
|
||||
|
||||
if (node === sel) {
|
||||
datablock.classList.add("selected");
|
||||
editObject(node, datablock);
|
||||
}
|
||||
|
||||
datablock.addEventListener("click", (e) => {
|
||||
document.querySelectorAll(".datablock.selected").forEach(x => x.classList.remove("selected"));
|
||||
datablock.classList.add("selected");
|
||||
editObject(node, datablock);
|
||||
});
|
||||
|
||||
var h4 = document.createElement("h4");
|
||||
h4.innerText = node.name;
|
||||
datablock.appendChild(h4);
|
||||
|
||||
datablock.appendChild(document.createElement("br"));
|
||||
|
||||
var type = document.createElement("i");
|
||||
type.innerText = "Type: " + node.type;
|
||||
datablock.appendChild(type);
|
||||
|
||||
datablock.appendChild(document.createElement("br"));
|
||||
datablock.appendChild(document.createElement("br"));
|
||||
|
||||
var controls = document.createElement("div");
|
||||
controls.classList.add("controls");
|
||||
|
||||
var deleteButton = document.createElement("button");
|
||||
deleteButton.innerText = "Delete";
|
||||
deleteButton.addEventListener("click", (e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
state.nodes.splice(index, 1);
|
||||
updateDynamics(false);
|
||||
reloadUI();
|
||||
});
|
||||
controls.appendChild(deleteButton);
|
||||
|
||||
datablock.appendChild(controls);
|
||||
|
||||
datablockContainer.appendChild(datablock);
|
||||
});
|
||||
}
|
||||
document.querySelector("#newdatablock").addEventListener("click", (e) => {
|
||||
state.nodes.push(getPrimitive(document.querySelector("#addtype").value));
|
||||
updateDynamics(false);
|
||||
reloadUI(document.querySelector(".datablock.selected")?.datablock);
|
||||
});
|
||||
reloadUI();
|
||||
@@ -0,0 +1,229 @@
|
||||
const MoreEvents = {
|
||||
|
||||
ModAPI.events.newEvent("screenRender"); // Called each time the screen is rendering, both in the game screen and in the interface
|
||||
ModAPI.events.newEvent("GUIScreenRender"); // Called each time the screen is rendering, but only in the interface (not in game)
|
||||
ModAPI.events.newEvent("inGameScreenRender"); // Called each time the screen is rendering, but only in game (not in the interface)
|
||||
ModAPI.events.newEvent("screenChange"); // Called when the screen changes, you can use event.previousScreenName
|
||||
// For all these events, you can use event.screen to get the current screen, and event.screenName to get its name.
|
||||
|
||||
ModAPI.events.newEvent("openModManager"); // Called when the mod manager interface is opened
|
||||
ModAPI.events.newEvent("refreshModManager"); // Called when the mod manager interface is updated
|
||||
ModAPI.events.newEvent("closeModManager"); // Called when the mod manager interface is closed
|
||||
// For all these events, you can use event.modList to obtain the loaded mods list with all their metadatas
|
||||
|
||||
ModAPI.events.newEvent("openLANSharing"); // Called when the client starts sharing his world using LAN, use event.code to get the access code, event.URL to get the relay URL, and event.world to get the client-side world
|
||||
ModAPI.events.newEvent("closeLANSharing"); // Called when the client stops sharing his world using LAN
|
||||
|
||||
ModAPI.events.newEvent("crash"); // Called when the client crashes, use event.crashReport to get the crash report
|
||||
|
||||
ModAPI.events.newEvent("tick"); // Called each client world tick
|
||||
|
||||
ModAPI.events.newEvent("settingsUpdate"); // Called when the settings are updated and saved
|
||||
|
||||
ModAPI.events.newEvent("playerPosChange"); // Called when the player moves, use event.player to get the player, and event.posX posY posZ to get its position
|
||||
|
||||
ModAPI.events.newEvent("rightClick"); // Called when the right button of the mouse is clicked, only in game
|
||||
/* For these two events, you can use :
|
||||
event.heldItem to get the item in hand
|
||||
event.entity to get the pointed entity, if existing
|
||||
event.block to get the pointed block, if not there is not block it's an air block
|
||||
event.blockPos to get the pointed block position
|
||||
*/
|
||||
|
||||
ModAPI.events.newEvent("profileUpdate"); // Called when the profile is updated
|
||||
|
||||
let methodName1 = ModAPI.hooks._classMap.nmcg_GuiScreen.methods.drawScreen.methodName;
|
||||
const originalMethod1 = ModAPI.hooks.methods[methodName1];
|
||||
ModAPI.hooks.methods[methodName1] = function(...args) {
|
||||
let x = originalMethod1.apply(this, args);
|
||||
|
||||
ModAPI.events.callEvent("screenRender", {
|
||||
screen: Minecraft.$currentScreen,
|
||||
screenName: ModAPI.util.ustr(Minecraft.$currentScreen.$getClass().$getSimpleName()),
|
||||
});
|
||||
ModAPI.events.callEvent("GUIScreenRender", {
|
||||
screen: Minecraft.$currentScreen,
|
||||
screenName: ModAPI.util.ustr(Minecraft.$currentScreen.$getClass().$getSimpleName()),
|
||||
});
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
let methodName2 = ModAPI.hooks._classMap.nmcg_GuiIngame.methods.func_181551_a.methodName
|
||||
const originalMethod2 = ModAPI.hooks.methods[methodName2];
|
||||
ModAPI.hooks.methods[methodName2] = function(...args) {
|
||||
let x = originalMethod2.apply(this, args)
|
||||
|
||||
ModAPI.events.callEvent("screenRender", {
|
||||
screen: Minecraft.$ingameGUI,
|
||||
screenName: 'GuiIngame',
|
||||
});
|
||||
|
||||
ModAPI.events.callEvent("inGameScreenRender", {
|
||||
screen: Minecraft.$ingameGUI,
|
||||
screenName: 'GuiIngame',
|
||||
});
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
let previousScreenName = null;
|
||||
ModAPI.addEventListener("screenRender", (event) => {
|
||||
if (previousScreenName !== event.screenName) {
|
||||
ModAPI.events.callEvent("screenChange", {
|
||||
screen: Minecraft.$ingameGUI,
|
||||
screenName: event.screenName,
|
||||
previousScreenName: previousScreenName,
|
||||
});
|
||||
previousScreenName = event.screenName;
|
||||
}
|
||||
})
|
||||
|
||||
const originalMethod3 = modapi_displayModGui;
|
||||
let modManagerOpened = false;
|
||||
modapi_displayModGui = function(...args) {
|
||||
let x = originalMethod3.apply(this, args);
|
||||
if (modManagerOpened) { // check if the mod manager was already opened
|
||||
ModAPI.events.callEvent("refreshModManager", {
|
||||
modList: function() {
|
||||
let modList = [];
|
||||
let modIdList = Object.keys(ModAPI.meta._titleMap);
|
||||
modIdList.forEach(id => {
|
||||
modList.push({
|
||||
"title": ModAPI.meta._titleMap[id],
|
||||
"icon": ModAPI.meta._iconMap[id],
|
||||
"desciption": ModAPI.meta._descriptionMap[id],
|
||||
"developer": ModAPI.meta._developerMap[id],
|
||||
"version": ModAPI.meta._versionMap[id],
|
||||
"metaID": id,
|
||||
});
|
||||
});
|
||||
return modList;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ModAPI.events.callEvent("openModManager", {
|
||||
modList: function() {
|
||||
let modList = [];
|
||||
let modIdList = Object.keys(ModAPI.meta._titleMap);
|
||||
modIdList.forEach(id => {
|
||||
modList.push({
|
||||
"title": ModAPI.meta._titleMap[id],
|
||||
"icon": ModAPI.meta._iconMap[id],
|
||||
"desciption": ModAPI.meta._descriptionMap[id],
|
||||
"developer": ModAPI.meta._developerMap[id],
|
||||
"version": ModAPI.meta._versionMap[id],
|
||||
"metaID": id,
|
||||
});
|
||||
});
|
||||
return modList;
|
||||
}
|
||||
});
|
||||
}
|
||||
modManagerOpened = true;
|
||||
document.getElementsByClassName('_doneButton')[0].addEventListener('click', function() {
|
||||
modManagerOpened = false
|
||||
ModAPI.events.callEvent("closeModManager", {
|
||||
modList: function() {
|
||||
let modList = [];
|
||||
let modIdList = Object.keys(ModAPI.meta._titleMap);
|
||||
modIdList.forEach(id => {
|
||||
modList.push({
|
||||
"title": ModAPI.meta._titleMap[id],
|
||||
"icon": ModAPI.meta._iconMap[id],
|
||||
"desciption": ModAPI.meta._descriptionMap[id],
|
||||
"developer": ModAPI.meta._developerMap[id],
|
||||
"version": ModAPI.meta._versionMap[id],
|
||||
"metaID": id,
|
||||
});
|
||||
});
|
||||
return modList;
|
||||
}
|
||||
});
|
||||
})
|
||||
return x;
|
||||
}
|
||||
|
||||
let lastLANState = 0;
|
||||
const originalMethod4 = ModAPI.hooks.methods.nlevsl_LANServerController_isHostingLAN;
|
||||
ModAPI.hooks.methods.nlevsl_LANServerController_isHostingLAN = function(...args) {
|
||||
let x = originalMethod4.apply(this, args);
|
||||
if (lastLANState !== x) {
|
||||
if (x === 0) {
|
||||
ModAPI.events.callEvent("openLANSharing", {
|
||||
"code": ModAPI.util.ustr(ModAPI.hooks.methods.nlevsl_LANServerController_getCurrentCode()),
|
||||
"URL": ModAPI.util.ustr(ModAPI.hooks.methods.nlevsl_LANServerController_getCurrentURI()),
|
||||
"world": Minecraft.$theWorld,
|
||||
});
|
||||
} else {
|
||||
ModAPI.events.callEvent("closeLANSharing");
|
||||
}
|
||||
lastLANState = x;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
const originalMethod5 = ModAPI.hooks.methods.nmc_CrashReport_makeCrashReport;
|
||||
ModAPI.hooks.methods.nmc_CrashReport_makeCrashReport = function(...args) {
|
||||
let x = originalMethod5.apply(this, args);
|
||||
ModAPI.events.callEvent("crash", {
|
||||
"crashReport": x,
|
||||
});
|
||||
return x
|
||||
}
|
||||
|
||||
const originalMethod6 = ModAPI.hooks.methods.nmcm_WorldClient_tick;
|
||||
ModAPI.hooks.methods.nmcm_WorldClient_tick = function(...args) {
|
||||
let x = originalMethod6.apply(this, args);
|
||||
ModAPI.events.callEvent("tick");
|
||||
return x
|
||||
}
|
||||
|
||||
const originalMethod7 = ModAPI.hooks.methods.nmce_EntityPlayerSP_onUpdate;
|
||||
let lastPlayerPos = [];
|
||||
ModAPI.hooks.methods.nmce_EntityPlayerSP_onUpdate = function(...args) {
|
||||
let x = originalMethod7.apply(this, args);
|
||||
let newPlayerPos = [args[0].$posX, args[0].$posY, args[0].$posZ];
|
||||
if (newPlayerPos[0] !== lastPlayerPos[0] || newPlayerPos[1] !== lastPlayerPos[1] || newPlayerPos[2] !== lastPlayerPos[2]) {
|
||||
ModAPI.events.callEvent("playerPosChange", {
|
||||
"player": args[0],
|
||||
"posX": args[1],
|
||||
"posY": args[2],
|
||||
"posZ": args[3],
|
||||
});
|
||||
lastPlayerPos = newPlayerPos;
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
const originalMethod8 = ModAPI.hooks.methods.nmc_Minecraft_rightClickMouse;
|
||||
ModAPI.hooks.methods.nmc_Minecraft_rightClickMouse = function(...args) {
|
||||
let x = originalMethod8.apply(this, args);
|
||||
ModAPI.events.callEvent("rightClick", {
|
||||
"heldItem": Minecraft.$thePlayer.$getHeldItem(),
|
||||
"entity": Minecraft.$objectMouseOver.$entityHit,
|
||||
"block": Minecraft.$theWorld.$getBlockState(Minecraft.$objectMouseOver.$getBlockPos()).$block,
|
||||
"blockPos": Minecraft.$objectMouseOver.$getBlockPos(),
|
||||
});
|
||||
return x
|
||||
}
|
||||
|
||||
|
||||
|
||||
const originalMethod10 = ModAPI.hooks.methods.nlevp_EaglerProfile_save;
|
||||
ModAPI.hooks.methods.nlevp_EaglerProfile_save = function(...args) {
|
||||
let x = originalMethod10.apply(this, args);
|
||||
ModAPI.events.callEvent("profileUpdate", {
|
||||
name: ModAPI.util.ustr(ModAPI.hooks._classMap.nlevp_EaglerProfile.staticMethods.getName.method()),
|
||||
});
|
||||
return x
|
||||
}
|
||||
};
|
||||
|
||||
/* Example:
|
||||
|
||||
ModAPI.addEventListener("screenRender", (event) => {
|
||||
event.screen.$drawString(Minecraft.$fontRendererObj, ModAPI.util.str('You are on the screen with name: '+event.screenName), 0, 0, 16777215);
|
||||
});
|
||||
|
||||
*/
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,570 @@
|
||||
//Made by ZXMushroom63 for scratch++
|
||||
function blocklyDeveloperTools() {
|
||||
var Blockly = window.Blockly; //Blockly is usually exposed by default.
|
||||
|
||||
if (!Blockly) { //If the Blockly global is not exposed or found manually, the script cannot do anything useful.
|
||||
return "Failed to find Blockly instance!";
|
||||
}
|
||||
|
||||
var workspace = Blockly.getMainWorkspace();
|
||||
|
||||
var dom = Blockly.Xml.workspaceToDom(workspace); //Export the workspace to a DOM representing the save XML.
|
||||
workspace.addChangeListener(() => { //Every time the workspace changes, update the dom variable.
|
||||
if (!document.querySelector("g.blocklyDraggable[data-id].blocklyInsertionMarker")) { //Blockly will try to serialise insertion markers, which will cause an internal crash.
|
||||
dom = Blockly.Xml.workspaceToDom(workspace);
|
||||
}
|
||||
});
|
||||
|
||||
const observerConfig = { childList: true, characterData: false, attributes: false, subtree: true }; //Config for MutationObservers.
|
||||
|
||||
const TabManager = { //Hacky fix to get the tab key working in the XML editor.
|
||||
enableTab: function (keyEvent) { //Call with the key event and a string to insert at the text caret's position
|
||||
if (keyEvent.keyCode === 9) {
|
||||
// Insert tab at cursor position
|
||||
this.insertTab();
|
||||
|
||||
// Prevent switching focus to next element
|
||||
this.blockKeyEvent(keyEvent);
|
||||
}
|
||||
},
|
||||
insertTab: function () { //Function to insert the tab char
|
||||
if (window.getSelection) {
|
||||
const sel = window.getSelection();
|
||||
|
||||
sel.modify("extend", "backward", "paragraphboundary"); //Alter bounds of selection
|
||||
|
||||
const pos = sel.anchorOffset; //Offset of caret in anchorNode (in the editor's case, this is the current Text node)
|
||||
|
||||
if (sel.anchorNode) {
|
||||
sel.collapseToEnd();
|
||||
|
||||
const node = sel.anchorNode;
|
||||
|
||||
if (node instanceof HTMLElement) {
|
||||
//Get text before and after caret
|
||||
const preText = node.innerHTML.substring(0, pos);
|
||||
const postText = node.innerHTML.substring(pos, node.innerHTML.length);
|
||||
|
||||
node.innerHTML = preText + " " + postText; //Insert tab character
|
||||
} else if (node instanceof Node) {
|
||||
//Get text before and after caret
|
||||
const preText = node.nodeValue.substring(0, pos);
|
||||
const postText = node.nodeValue.substring(pos, node.nodeValue.length);
|
||||
|
||||
node.nodeValue = preText + "\u2003" + postText; //Insert tab character
|
||||
}
|
||||
|
||||
sel.setPosition(node, pos + 1); //Move text caret forward
|
||||
}
|
||||
}
|
||||
},
|
||||
blockKeyEvent: function (keyEvent) {
|
||||
if (keyEvent.preventDefault) {
|
||||
keyEvent.preventDefault();
|
||||
} else {
|
||||
keyEvent.returnValue = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function firefoxSpacingFix(elem) { //Fix for firefox adding a \n at the end of every text node, which makes the editor feel janky.
|
||||
elem.childNodes.forEach(element => {
|
||||
if (element instanceof Text) {
|
||||
element.nodeValue = element.nodeValue.replace(/\n/g, "");
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function makeEditorContainer() {
|
||||
var editor = document.createElement("div");
|
||||
|
||||
editor.setAttribute("data-isblocklydeveditor", "true"); //Attribute to identify element as editor
|
||||
editor.contentEditable = true; //Allow editing of content
|
||||
|
||||
//Styling
|
||||
editor.style.padding = "10px";
|
||||
editor.style.userSelect = "text";
|
||||
editor.style.cursor = "auto";
|
||||
editor.style.font = "12pt monospace";
|
||||
editor.style.boxShadow = "0px 0px 10px rgba(0,0,0,0.5)";
|
||||
editor.style.color = "yellowgreen";
|
||||
editor.style.border = "2px solid white";
|
||||
editor.style.zIndex = "998";
|
||||
editor.style.borderRadius = "0.8rem";
|
||||
editor.style.width = "max-content";
|
||||
editor.style.backgroundColor = "rgb(0,0,30)";
|
||||
editor.style.overflowX = "hidden";
|
||||
editor.style.maxHeight = "100vh";
|
||||
editor.style.overflowY = "scroll";
|
||||
editor.style.caretColor = "white";
|
||||
|
||||
//Disable spellcheck and autocomplete.
|
||||
editor.setAttribute("autocomplete", "false");
|
||||
editor.setAttribute("spellcheck", "false");
|
||||
|
||||
//Prevent events from propagating to Blockly
|
||||
editor.addEventListener("pointerdown", (event) => {
|
||||
event.stopPropagation();
|
||||
}, {
|
||||
capture: true
|
||||
});
|
||||
editor.addEventListener("wheel", (event) => {
|
||||
event.stopPropagation();
|
||||
}, {
|
||||
capture: true
|
||||
});
|
||||
editor.addEventListener("scroll", (event) => {
|
||||
event.stopPropagation();
|
||||
}, {
|
||||
capture: true
|
||||
});
|
||||
editor.addEventListener("contextmenu", (event) => {
|
||||
event.stopPropagation();
|
||||
}, {
|
||||
capture: true
|
||||
});
|
||||
editor.addEventListener("keydown", (event) => {
|
||||
TabManager.enableTab(event); //Fix for tab key
|
||||
|
||||
}, {
|
||||
capture: true
|
||||
});
|
||||
|
||||
return editor;
|
||||
}
|
||||
|
||||
var style = document.createElement("style");
|
||||
style.innerHTML = `
|
||||
/* Hide the ✏️ button on blocks that aren't top level */
|
||||
g.blocklyDraggable[data-id]:not(.blocklyInsertionMarker):not(g.blocklyBlockCanvas>g.blocklyDraggable[data-id]:not(.blocklyInsertionMarker)) [data-is-blocklydev-btn] {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
/* Hide editor buttons on blocks that aren't top level */
|
||||
g.blocklyDraggable[data-id]:not(.blocklyInsertionMarker):not(g.blocklyBlockCanvas>g.blocklyDraggable[data-id]:not(.blocklyInsertionMarker)) [data-is-blocklydev-editor-btn] {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
/* Hide the XML editor on blocks that aren't top level */
|
||||
g.blocklyDraggable[data-id]:not(.blocklyInsertionMarker):not(g.blocklyBlockCanvas>g.blocklyDraggable[data-id]:not(.blocklyInsertionMarker)) [data-isblocklydeveditor] {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
/* Hide the XML editor on blocks that aren't top level */
|
||||
g.blocklyDraggable[data-id]:not(.blocklyInsertionMarker):not(g.blocklyBlockCanvas>g.blocklyDraggable[data-id]:not(.blocklyInsertionMarker)) .blockly-dev-tools-code-preview {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
/* Hide scrollbars on the XML editor */
|
||||
div[data-isblocklydeveditor]::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
div[data-isblocklydeveditor] {
|
||||
scrollbar-width: none;
|
||||
}
|
||||
`;
|
||||
document.head.appendChild(style);
|
||||
|
||||
//CSS would normally be injected here.
|
||||
|
||||
if (!getBlocklyWorkspace()) {
|
||||
return "Failed to find Blockly SvgWorkspace!";
|
||||
}
|
||||
|
||||
function formatXml(xml, innerHTMLMode = false) { //Utility function to format XML, optionally outputting valid HTML
|
||||
var formatted = '', indent = '';
|
||||
var tab = '\t';
|
||||
xml.split(/>\s*</).forEach(function (node) {
|
||||
if (node.match(/^\/\w/)) indent = indent.substring(tab.length);
|
||||
formatted += indent + '<' + node + '>\r\n';
|
||||
if (node.match(/^<?\w[^>]*[^\/]$/)) indent += tab;
|
||||
});
|
||||
if (!innerHTMLMode) {
|
||||
return formatted.substring(1, formatted.length - 3);
|
||||
} else {
|
||||
return formatted.substring(1, formatted.length - 3)
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/\t/g, " ")
|
||||
.replace(/\n/g, "<br>")
|
||||
.replace(/ /g, " ");
|
||||
}
|
||||
}
|
||||
function getBlocklyWorkspace() { //Get the svg workspace
|
||||
return document.querySelector("svg.blocklySvg>g.blocklyWorkspace");
|
||||
}
|
||||
function getBlocklyBlockCanvas() { //get the block canvas from the workspace
|
||||
return getBlocklyWorkspace().querySelector("g.blocklyBlockCanvas");
|
||||
}
|
||||
function getSvgPathFromBlock(blockElem) { //Get the svg path from an svg block
|
||||
if (isNewBlocklyBlock(blockElem)) {
|
||||
return blockElem.querySelector("g.blocklyDraggable[data-id]:not(.blocklyInsertionMarker)>path.blocklyPath[d]");
|
||||
}
|
||||
}
|
||||
function isNewBlocklyBlock(node) { //Is node a block svg that has not yet been hooked.
|
||||
return node && node instanceof Element && node.tagName === "g" && node.classList.contains("blocklyDraggable") && !node.classList.contains("blocklyInsertionMarker") && node.hasAttribute("data-id") && !node.hasAttribute("data-blocklydev-hooked");
|
||||
}
|
||||
function makeXMLEditor(blockId, block) { //Make the XML editor for a blockId
|
||||
function getXmlFromBlockId(id, dom) { //Utility function to get the block's XML string from a Blockly serialised DOM.
|
||||
for (const element of dom.children) {
|
||||
if (element.tagName.toLowerCase() === "block" && element.getAttribute("id") === id) {
|
||||
return element.outerHTML;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getXmlFromVarId(id, dom) { //Utility function to get the block's XML string from a Blockly serialised DOM.
|
||||
var variables = dom.querySelector("variables");
|
||||
for (const element of variables.children) {
|
||||
if (element.tagName.toLowerCase() === "variable" && element.getAttribute("id") === id) {
|
||||
return element.outerHTML;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var originalXml = getXmlFromBlockId(blockId, dom); //Store the block's original, un-edited XML.
|
||||
|
||||
|
||||
var container = makeEditorContainer(); //Create the editor
|
||||
|
||||
//Set the editor's contents to the formatted original XML.
|
||||
container.innerHTML = formatXml(originalXml, true);
|
||||
firefoxSpacingFix(container);
|
||||
|
||||
var referencesVars = block.getVars(); //Array of variable ids referenced by block (directly)
|
||||
var editorVar = referencesVars[0]; //The variable to display
|
||||
var secondaryEditor = makeEditorContainer(); //Create secondary editor
|
||||
var originalVarXml = editorVar ? getXmlFromVarId(editorVar, dom) : null;
|
||||
|
||||
secondaryEditor.innerHTML = originalVarXml ? formatXml(originalVarXml, true) : "";
|
||||
secondaryEditor.style.display = originalVarXml ? "block" : "none";
|
||||
firefoxSpacingFix(container);
|
||||
|
||||
function update() { //Function called when the workspace updates
|
||||
originalXml = getXmlFromBlockId(blockId, dom); //Update original XML
|
||||
if (!originalXml) { //If it is now undefined, the block has been deleted or no longer exists, so remove listeners and exit.
|
||||
workspace.removeChangeListener(update);
|
||||
return;
|
||||
}
|
||||
referencesVars = block.getVars();
|
||||
editorVar = referencesVars[0] || false;
|
||||
originalVarXml = editorVar ? getXmlFromVarId(editorVar, dom) : null;
|
||||
if (originalVarXml) {
|
||||
secondaryEditor.innerHTML = formatXml(originalVarXml, true);
|
||||
secondaryEditor.style.display = "block";
|
||||
firefoxSpacingFix(container);
|
||||
} else {
|
||||
secondaryEditor.innerHTML = "";
|
||||
secondaryEditor.style.display = "none";
|
||||
}
|
||||
container.innerHTML = formatXml(originalXml, true); //Update contents
|
||||
firefoxSpacingFix(container);
|
||||
}
|
||||
|
||||
workspace.addChangeListener(update); //Register change listener
|
||||
|
||||
container.save = function () { //Function to save
|
||||
var xmlStr = (Blockly.Xml.domToText || Blockly.utils.xml.domToText)(dom); //Convert the dom to string
|
||||
if (!xmlStr.includes(originalXml)) { //If the domn does not contain the original block XML, it is impossible to save changes.
|
||||
throw new Error("Workspace XML does not contain block!");
|
||||
}
|
||||
xmlStr = xmlStr.replace(originalXml, container.textContent); //Replace original XML with modified XML.
|
||||
if (originalVarXml) {
|
||||
xmlStr = xmlStr.replace(originalVarXml, secondaryEditor.textContent);
|
||||
}
|
||||
//xmlStr = xmlStr.replace(/\u2003/g, "").replace(/\n/g, "");
|
||||
xmlStr = xmlStr.replace(/\u00A0/g, "\u0020"); //Replace any non-breaking spaces with normal ones.
|
||||
var tempDom = (Blockly.Xml.textToDom || Blockly.utils.xml.textToDom)(xmlStr);
|
||||
if (tempDom.querySelector("parsererror")) {
|
||||
tempDom.querySelectorAll("parsererror").forEach(err => {
|
||||
var display = document.createElement("div");
|
||||
display.innerText = err.querySelector("div").innerText;
|
||||
display.style.color = "red";
|
||||
display.style.font = "12pt monospace";
|
||||
display.style.backgroundColor = "rgb(0,0,20)";
|
||||
display.style.border = "2px solid white";
|
||||
display.style.borderRadius = "0.4rem";
|
||||
display.style.width = "max-content";
|
||||
display.style.padding = "8px";
|
||||
display.style.cursor = "auto";
|
||||
display.addEventListener("pointerdown", (event) => { event.stopPropagation(); }, { capture: true });
|
||||
display.addEventListener("contextmenu", (event) => { event.stopPropagation(); }, { capture: true });
|
||||
devWrapper.appendChild(display);
|
||||
setTimeout(() => {
|
||||
display.classList.add("blocklyDevtoolsFadeOut");
|
||||
setTimeout(() => {
|
||||
display.remove();
|
||||
}, 1000);
|
||||
}, 3000);
|
||||
});
|
||||
return;
|
||||
}
|
||||
dom = tempDom; //Update the DOM variable.
|
||||
workspace.clear(); //Clear the workspace
|
||||
Blockly.Xml.domToWorkspace(dom, workspace); //Load the DOM
|
||||
if (workspace.getToolbox() //If the blockly instance has a toolbox, it needs to be refreshed,
|
||||
) {
|
||||
workspace.getToolbox().refreshSelection();
|
||||
}
|
||||
}
|
||||
|
||||
return [container, secondaryEditor];
|
||||
}
|
||||
function processBlock(element) { //Function to hook block svg element
|
||||
if (isNewBlocklyBlock(element)) { //Check if we have not already hooked it
|
||||
var blockId = element.getAttribute("data-id"); //Get the id
|
||||
var internalBlock = workspace.getBlockById(blockId); //Get the internal block object
|
||||
if (!internalBlock) {
|
||||
return;
|
||||
}
|
||||
internalBlock.tooltip ||= internalBlock.type || "unknown"; //If the block does not have a tooltip, set it to it's opcode.
|
||||
const devWrapper = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject'); //Create a foreignObject element to allow HTML inside of SVG.
|
||||
const btnWrapper = document.createElement("div"); //Wrapper for buttons to keep them on the same row
|
||||
|
||||
btnWrapper.style.cursor = "auto"; //Fix for cursor being the grab hand
|
||||
btnWrapper.style.width = "max-content";
|
||||
|
||||
const btn = document.createElement("span"); //Create the edit button
|
||||
btn.style.cursor = "pointer";
|
||||
btn.style.zIndex = "999";
|
||||
btn.style.lineHeight = "1rem";
|
||||
btn.setAttribute("data-is-blocklydev-btn", "true");
|
||||
btn.innerText = "✏️"; //📝✏️
|
||||
|
||||
const save = document.createElement("span"); //Create the save button
|
||||
save.style.cursor = "pointer";
|
||||
save.style.zIndex = "999";
|
||||
save.setAttribute("data-is-blocklydev-editor-btn", "true");
|
||||
save.style.display = "none";
|
||||
save.innerText = "💾";
|
||||
save.style.lineHeight = "1rem";
|
||||
|
||||
const collapse = document.createElement("span"); //Create the collapse/uncollapse button
|
||||
collapse.style.cursor = "pointer";
|
||||
collapse.style.zIndex = "999";
|
||||
collapse.setAttribute("data-is-blocklydev-editor-btn", "true");
|
||||
collapse.style.display = "none";
|
||||
collapse.innerText = "⬆️";
|
||||
collapse.style.lineHeight = "1rem";
|
||||
|
||||
const viewcode = document.createElement("span"); //Create the collapse/uncollapse button
|
||||
viewcode.style.cursor = "pointer";
|
||||
viewcode.style.zIndex = "999";
|
||||
viewcode.setAttribute("data-is-blocklydev-editor-btn", "true");
|
||||
viewcode.style.display = "none";
|
||||
viewcode.innerText = "📟";
|
||||
viewcode.style.lineHeight = "1rem";
|
||||
|
||||
const bin = document.createElement("span"); //Create the force delete button
|
||||
bin.style.cursor = "pointer";
|
||||
bin.style.zIndex = "999";
|
||||
bin.setAttribute("data-is-blocklydev-btn", "true");
|
||||
bin.innerText = "🗑️";
|
||||
bin.style.lineHeight = "1rem";
|
||||
|
||||
//Get the block's hull and calculate bounding box. Used to calculate where to position elements.
|
||||
const path = getSvgPathFromBlock(element);
|
||||
var bbox = path.getBBox();
|
||||
|
||||
//Attributes and styles for the foreignObject
|
||||
//Width and height are 1 instead of 0 because firefox is won't render the element if it doesn't have a positive size.
|
||||
devWrapper.setAttributeNS(null, "width", 1);
|
||||
devWrapper.setAttributeNS(null, "height", 1);
|
||||
|
||||
devWrapper.style.overflow = "visible";
|
||||
devWrapper.style.userSelect = "none";
|
||||
|
||||
devWrapper.setAttributeNS(null, "class", "blocklyText");
|
||||
devWrapper.setAttributeNS(null, "y", "0");
|
||||
devWrapper.setAttributeNS(null, "text-anchor", "middle");
|
||||
devWrapper.setAttributeNS(null, "dominant-baseline", "middle");
|
||||
devWrapper.setAttributeNS(null, "dy", "0");
|
||||
devWrapper.setAttributeNS(null, "x", bbox.width);
|
||||
devWrapper.setAttributeNS(null, "transform", `translate(0, 0) `);
|
||||
|
||||
//Add buttons to button wrapper
|
||||
btnWrapper.appendChild(btn);
|
||||
btnWrapper.appendChild(save);
|
||||
if (globalThis?.javascript?.javascriptGenerator) {
|
||||
btnWrapper.appendChild(viewcode);
|
||||
}
|
||||
btnWrapper.appendChild(collapse);
|
||||
btnWrapper.appendChild(bin);
|
||||
|
||||
//Add button wrapper to foreignObject
|
||||
devWrapper.appendChild(btnWrapper);
|
||||
|
||||
//Add foreignObject to block SVG
|
||||
element.appendChild(devWrapper);
|
||||
|
||||
//The block has been hooked
|
||||
element.setAttribute("data-blocklydev-hooked", "true");
|
||||
|
||||
//Stop events reaching Blockly
|
||||
btnWrapper.addEventListener("pointerdown", (event) => {
|
||||
event.stopPropagation();
|
||||
});
|
||||
|
||||
//Edit button handler.
|
||||
btn.addEventListener("pointerdown", (event) => {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
if (element.hasAttribute("data-id")) {
|
||||
blockId = element.getAttribute("data-id");
|
||||
if (devWrapper.querySelector("div[data-isblocklydeveditor]")) { //If the editor exists, remove it.
|
||||
devWrapper.querySelectorAll("div[data-isblocklydeveditor]").forEach(element => {
|
||||
element.remove();
|
||||
});
|
||||
save.style.display = "none";
|
||||
viewcode.style.display = "none";
|
||||
collapse.style.display = "none";
|
||||
if (devWrapper.querySelector(".blockly-dev-tools-code-preview")) {
|
||||
devWrapper.querySelectorAll(".blockly-dev-tools-code-preview").forEach(x=>x.remove());
|
||||
}
|
||||
} else {
|
||||
//Add editor if it does not exist.
|
||||
internalBlock = workspace.getBlockById(blockId);
|
||||
makeXMLEditor(blockId, internalBlock).forEach(editorSegment => {
|
||||
devWrapper.appendChild(editorSegment);
|
||||
});
|
||||
|
||||
save.style.display = "initial";
|
||||
viewcode.style.display = "initial";
|
||||
if (internalBlock.nextConnection || internalBlock.previousConnection) {
|
||||
collapse.style.display = "initial";
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
capture: true
|
||||
});
|
||||
|
||||
collapse.addEventListener("pointerdown", (event) => { //Handler for collapse button
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
if (element.hasAttribute("data-id")) {
|
||||
blockId = element.getAttribute("data-id");
|
||||
internalBlock = workspace.getBlockById(blockId);
|
||||
|
||||
internalBlock.setCollapsed(!internalBlock.isCollapsed()); //Toggle collapsed for the current block
|
||||
|
||||
var collapsed = internalBlock.isCollapsed(); //Store collapsed as variable for efficiency
|
||||
|
||||
//Loop through all sub-blocks and set collapsed to match.
|
||||
var blocks = element.querySelectorAll("g.blocklyDraggable[data-id]:not(.blocklyInsertionMarker)");
|
||||
for (let i = 0; i < blocks.length; i++) {
|
||||
const b = blocks[i];
|
||||
var bId = b.getAttribute("data-id");
|
||||
workspace.getBlockById(bId).setCollapsed(collapsed);
|
||||
}
|
||||
if (collapsed) { //Change button
|
||||
collapse.innerText = "⬇️";
|
||||
} else {
|
||||
collapse.innerText = "⬆️";
|
||||
}
|
||||
}
|
||||
}, {
|
||||
capture: true
|
||||
});
|
||||
|
||||
save.addEventListener("pointerdown", (event) => { //Save button handler
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
if (element.hasAttribute("data-id") && devWrapper.querySelector("div[data-isblocklydeveditor]")) {
|
||||
devWrapper.querySelector("div[data-isblocklydeveditor]").save(); //Delegate saving to the editor
|
||||
}
|
||||
}, {
|
||||
capture: true
|
||||
});
|
||||
|
||||
viewcode.addEventListener("pointerdown", (event)=>{
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
if (element.hasAttribute("data-id")) {
|
||||
blockId = element.getAttribute("data-id");
|
||||
internalBlock = workspace.getBlockById(blockId);
|
||||
var code;
|
||||
try {
|
||||
code = javascript.javascriptGenerator.blockToCode(internalBlock)
|
||||
} catch (error) {
|
||||
code = "ERR: " + error;
|
||||
}
|
||||
if (devWrapper.querySelector(".blockly-dev-tools-code-preview")) {
|
||||
devWrapper.querySelectorAll(".blockly-dev-tools-code-preview").forEach(x=>x.remove());
|
||||
}
|
||||
var display = document.createElement("div");
|
||||
display.innerText = code;
|
||||
display.style.color = "lightblue";
|
||||
display.style.font = "12pt monospace";
|
||||
display.style.backgroundColor = "rgb(0,0,20)";
|
||||
display.style.border = "2px solid white";
|
||||
display.style.borderRadius = "0.4rem";
|
||||
display.style.width = "max-content";
|
||||
display.style.padding = "8px";
|
||||
display.style.cursor = "auto";
|
||||
display.classList.add("blockly-dev-tools-code-preview");
|
||||
display.addEventListener("pointerdown", (event) => { event.stopPropagation(); }, { capture: true });
|
||||
display.addEventListener("contextmenu", (event) => { event.stopPropagation(); }, { capture: true });
|
||||
devWrapper.appendChild(display);
|
||||
}
|
||||
});
|
||||
|
||||
bin.addEventListener("pointerdown", (event) => { //Force delete handler
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
if (element.hasAttribute("data-id")) {
|
||||
blockId = element.getAttribute("data-id");
|
||||
var block = workspace.getBlockById(blockId);
|
||||
block.getDescendants(false, true).forEach((block) => {
|
||||
block.dispose(true); //Healing the stack is a good idea, previously I was not doing this and it was corrupting everything yay :]
|
||||
});
|
||||
if (workspace.getToolbox() //If the blockly instance has a toolbox, it needs to be refreshed,
|
||||
) {
|
||||
workspace.getToolbox().refreshSelection();
|
||||
}
|
||||
}
|
||||
}, {
|
||||
capture: true
|
||||
});
|
||||
|
||||
var updateObserver = new MutationObserver(function () { //When this block updates
|
||||
blockId = element.getAttribute("data-id");
|
||||
bbox = path.getBBox();
|
||||
|
||||
devWrapper.setAttributeNS(null, "class", "blocklyText");
|
||||
devWrapper.setAttributeNS(null, "y", "0");
|
||||
devWrapper.setAttributeNS(null, "text-anchor", "middle");
|
||||
devWrapper.setAttributeNS(null, "dominant-baseline", "middle");
|
||||
devWrapper.setAttributeNS(null, "dy", "0");
|
||||
devWrapper.setAttributeNS(null, "x", bbox.width);
|
||||
devWrapper.setAttributeNS(null, "transform", `translate(0, 0) `);
|
||||
|
||||
updateObserver.disconnect();
|
||||
element.appendChild(devWrapper); //Move element to be last, to allow displaying on top of other blocks connected underneath. (When an element is already appended, appendChild() moves rather than appends)
|
||||
updateObserver.observe(element, observerConfig);
|
||||
});
|
||||
updateObserver.observe(element, observerConfig); //Initialise observer
|
||||
}
|
||||
}
|
||||
var observer = new MutationObserver(mutationHandler);
|
||||
|
||||
function mutationHandler(mutationRecords) { //Handler that tries to process all blocks every time the block canvas changes.
|
||||
mutationRecords.forEach(function (mutation) {
|
||||
mutation.addedNodes.forEach(function (node) {
|
||||
processBlock(node);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//Initial block processing (script runs too early in this case)
|
||||
var blocks = getBlocklyBlockCanvas().children;
|
||||
for (let i = 0; i < blocks.length; i++) {
|
||||
const block = blocks[i];
|
||||
processBlock(block);
|
||||
}
|
||||
|
||||
//Observe canvas
|
||||
observer.observe(getBlocklyBlockCanvas(), observerConfig);
|
||||
return "Blockly dev tools ran successfully.";
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
Blockly.FieldMinecraftItemInput = class FieldMinecraftItemInput extends Blockly.FieldTextInput {
|
||||
constructor(blocksOnly, noMeta) {
|
||||
super("item/air");
|
||||
this.noMeta = noMeta;
|
||||
this.blocksOnly = blocksOnly;
|
||||
this.oldValue = this.getValue();
|
||||
this.size_.width = 64 + 12;
|
||||
this.size_.height = 64;
|
||||
}
|
||||
render_() {
|
||||
const wrapperElement = this.fieldGroup_;
|
||||
if (!wrapperElement.querySelector(".itemsel_foreignobject")) {
|
||||
this.appendPicker();
|
||||
} else if (this.oldValue !== this.getValue()) {
|
||||
wrapperElement.querySelector(".itemsel_foreignobject").remove();
|
||||
this.appendPicker();
|
||||
}
|
||||
if (wrapperElement.querySelector(".blocklyFieldRect")) {
|
||||
wrapperElement.querySelector(".blocklyFieldRect").remove();
|
||||
}
|
||||
}
|
||||
appendPicker() {
|
||||
const wrapperElement = this.fieldGroup_;
|
||||
const devWrapper = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
|
||||
devWrapper.classList.add("itemsel_foreignobject");
|
||||
const self = this;
|
||||
var input = makeItemSelector(this.getValue(), this.blocksOnly, function () {
|
||||
self.setValue(input?.value || "item/air");
|
||||
},
|
||||
{
|
||||
width: "512px",
|
||||
height: "512px",
|
||||
top: "1rem",
|
||||
left: "4rem",
|
||||
noMeta: this.noMeta,
|
||||
});
|
||||
devWrapper.appendChild(input);
|
||||
devWrapper.setAttributeNS(null, "width", 1);
|
||||
devWrapper.setAttributeNS(null, "height", 1);
|
||||
devWrapper.style.overflow = "visible";
|
||||
devWrapper.style.userSelect = "none";
|
||||
wrapperElement.appendChild(devWrapper);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
function createAndDragVar(workspace, j, varId, parentBlock, inputOffset) {
|
||||
if (!parentBlock) {
|
||||
return;
|
||||
}
|
||||
var block = workspace.newBlock("variables_get");
|
||||
block.setFieldValue(varId, "VAR");
|
||||
block.initSvg();
|
||||
block.render();
|
||||
var startPos = Blockly.utils.Coordinate.sum(parentBlock.relativeCoords, inputOffset);
|
||||
block.moveTo(startPos);
|
||||
block.startDrag(startPos);
|
||||
j.preventDefault();
|
||||
j.stopImmediatePropagation();
|
||||
j.stopPropagation();
|
||||
var initialPixelsBB = block.getSvgRoot().getBoundingClientRect();
|
||||
var initialPixels = {
|
||||
x: initialPixelsBB.x + (initialPixelsBB.width / 2),
|
||||
y: initialPixelsBB.y + (initialPixelsBB.height / 2)
|
||||
}
|
||||
var moveHander = (e) => {
|
||||
e.preventDefault();
|
||||
e.stopImmediatePropagation();
|
||||
e.stopPropagation();
|
||||
var diff = Blockly.utils.Coordinate.difference(e, initialPixels);
|
||||
block.drag(Blockly.utils.Coordinate.sum(startPos, Blockly.dragging.Dragger.prototype.pixelsToWorkspaceUnits.apply({ workspace }, [diff])));
|
||||
};
|
||||
var upHandler = (e) => {
|
||||
e.preventDefault();
|
||||
e.stopImmediatePropagation();
|
||||
e.stopPropagation();
|
||||
block.endDrag();
|
||||
window.removeEventListener("pointermove", moveHander, true);
|
||||
window.removeEventListener("pointerup", upHandler, true);
|
||||
};
|
||||
window.addEventListener("pointermove", moveHander, true);
|
||||
window.addEventListener("pointerup", upHandler, true);
|
||||
return block;
|
||||
}
|
||||
|
||||
const oldGetVariablesOfType = Blockly.Workspace.prototype.getVariablesOfType;
|
||||
Blockly.Workspace.prototype.getVariablesOfType = function (type, bypass) {
|
||||
var ret = oldGetVariablesOfType.apply(this, [type]);
|
||||
if (bypass) {
|
||||
return ret;
|
||||
}
|
||||
return ret.filter(x => !x.name.startsWith("$_efb2_arg_"));
|
||||
}
|
||||
function patchVariableField(node) {
|
||||
var textOffset = parseFloat(node.querySelector(".blocklyDropdownText").getAttribute("x"));
|
||||
node.querySelectorAll("image").forEach(x => {
|
||||
if (x.hasAttribute("width")) {
|
||||
textOffset += parseFloat(x.getAttribute("width").replaceAll("px", "")) / 2 + 2;
|
||||
}
|
||||
x.remove();
|
||||
});
|
||||
node.style.cursor = "grab";
|
||||
node.querySelector(".blocklyDropdownText").setAttribute("x", textOffset);
|
||||
}
|
||||
Blockly.FieldEFB2Variable = class FieldEFB2Variable extends Blockly.FieldVariable {
|
||||
constructor(name) {
|
||||
super("$_efb2_arg_" + name)
|
||||
}
|
||||
getText() {
|
||||
return super.getText().replace("$_efb2_arg_", "");
|
||||
}
|
||||
render_() {
|
||||
super.render_();
|
||||
patchVariableField(this.fieldGroup_);
|
||||
this.fieldGroup_.addEventListener("pointerdown", (e) => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
e.stopImmediatePropagation();
|
||||
var fieldAABB = this.fieldGroup_.getBoundingClientRect();
|
||||
var blockAABB = this.fieldGroup_.closest("g.blocklyDraggable").getBoundingClientRect();
|
||||
var offset = Blockly.dragging.Dragger.prototype.pixelsToWorkspaceUnits.apply({ workspace }, [{ x: fieldAABB.x - blockAABB.x, y: fieldAABB.y - blockAABB.y }]);
|
||||
createAndDragVar(workspace, e, this.getVariable().id, workspace.getBlockById(this.fieldGroup_.closest("g.blocklyDraggable").getAttribute("data-id")), offset);
|
||||
}, true);
|
||||
this.fieldGroup_.querySelector("rect").style.fill = "rgb(153, 91, 165)";
|
||||
}
|
||||
}
|
||||
const oldGetText = Blockly.FieldVariable.prototype.getText;
|
||||
Blockly.FieldVariable.prototype.getText = function (...args) {
|
||||
return oldGetText.apply(this, args).replace("$_efb2_arg_", "");
|
||||
}
|
||||
const oldBlockRender = Blockly.BlockSvg.prototype.renderEfficiently;
|
||||
Blockly.BlockSvg.prototype.renderEfficiently = function (...args) {
|
||||
oldBlockRender.apply(this, args);
|
||||
if ((this.type === "variables_get") && (workspace.getVariableById(this.getFieldValue("VAR"))?.name?.startsWith("$_efb2_arg_"))) {
|
||||
patchVariableField(this.svgGroup);
|
||||
this.svgGroup.querySelector("path").setAttribute("fill", "rgb(153, 91, 165)");
|
||||
if (!this.svgGroup.$$patched) {
|
||||
this.svgGroup.$$patched = true;
|
||||
this.svgGroup.addEventListener("click", (e) => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
e.stopImmediatePropagation();
|
||||
document.querySelector('.blocklyDropDownDiv').style.display = "none";
|
||||
}, true);
|
||||
this.svgGroup.addEventListener("pointerdown", (e) => {
|
||||
setTimeout(() => {
|
||||
[...document.querySelectorAll('.blocklyContextMenu div[role=menuitem]')].filter(x => x.querySelector(".blocklyMenuItemContent").innerText.toLowerCase().includes("create")).forEach(x => x.remove());
|
||||
}, 0);
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
function removeUnusedArgumentVariables() {
|
||||
if (workspace.isDragging()) return;
|
||||
var variables = workspace.getVariablesOfType("", true);
|
||||
variables.forEach(variable => {
|
||||
if (variable.name.startsWith("$_efb2_arg_") && workspace.getVariableUsesById(variable.id).length < 1) {
|
||||
workspace.deleteVariableById(variable.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
//This part is your job to integrate after injecting your workspace
|
||||
//workspace.addChangeListener(removeUnusedArgumentVariables);
|
||||
@@ -0,0 +1,193 @@
|
||||
// Do not edit this file; automatically generated.
|
||||
|
||||
/* eslint-disable */
|
||||
;(function(root, factory) {
|
||||
if (typeof define === 'function' && define.amd) { // AMD
|
||||
define(["./blockly_compressed.js"], factory);
|
||||
} else if (typeof exports === 'object') { // Node.js
|
||||
module.exports = factory(require("./blockly_compressed.js"));
|
||||
} else { // Script
|
||||
root.Blockly.libraryBlocks = factory(root.Blockly);
|
||||
}
|
||||
}(this, function(__parent__) {
|
||||
var $=__parent__.__namespace__;
|
||||
var blocks$$module$build$src$blocks$variables_dynamic=$.createBlockDefinitionsFromJsonArray$$module$build$src$core$common([{type:"variables_get_dynamic",message0:"%1",args0:[{type:"field_variable",name:"VAR",variable:"%{BKY_VARIABLES_DEFAULT_NAME}"}],output:null,style:"variable_dynamic_blocks",helpUrl:"%{BKY_VARIABLES_GET_HELPURL}",tooltip:"%{BKY_VARIABLES_GET_TOOLTIP}",extensions:["contextMenu_variableDynamicSetterGetter"]},{type:"variables_set_dynamic",message0:"%{BKY_VARIABLES_SET}",args0:[{type:"field_variable",
|
||||
name:"VAR",variable:"%{BKY_VARIABLES_DEFAULT_NAME}"},{type:"input_value",name:"VALUE"}],previousStatement:null,nextStatement:null,style:"variable_dynamic_blocks",tooltip:"%{BKY_VARIABLES_SET_TOOLTIP}",helpUrl:"%{BKY_VARIABLES_SET_HELPURL}",extensions:["contextMenu_variableDynamicSetterGetter"]}]),CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN$$module$build$src$blocks$variables_dynamic={customContextMenu:function(a){if(!this.isInFlyout){if("variables_get_dynamic"===this.type){var b="variables_set_dynamic";
|
||||
var c=$.Msg$$module$build$src$core$msg.VARIABLES_GET_CREATE_SET}else b="variables_get_dynamic",c=$.Msg$$module$build$src$core$msg.VARIABLES_SET_CREATE_GET;var d=this.getField("VAR");b={type:b,fields:{VAR:d.saveState(!0)}};a.push({enabled:0<this.workspace.remainingCapacity(),text:c.replace("%1",d.getText()),callback:$.callbackFactory$$module$build$src$core$contextmenu(this,b)})}else if("variables_get_dynamic"===this.type||"variables_get_reporter_dynamic"===this.type)c={text:$.Msg$$module$build$src$core$msg.RENAME_VARIABLE,
|
||||
enabled:!0,callback:renameOptionCallbackFactory$$module$build$src$blocks$variables_dynamic(this)},d=this.getField("VAR").getText(),d={text:$.Msg$$module$build$src$core$msg.DELETE_VARIABLE.replace("%1",d),enabled:!0,callback:deleteOptionCallbackFactory$$module$build$src$blocks$variables_dynamic(this)},a.unshift(c),a.unshift(d)},onchange:function(a){a=this.getFieldValue("VAR");a=$.getVariable$$module$build$src$core$variables(this.workspace,a);"variables_get_dynamic"===this.type?this.outputConnection.setCheck(a.type):
|
||||
this.getInput("VALUE").connection.setCheck(a.type)}},renameOptionCallbackFactory$$module$build$src$blocks$variables_dynamic=function(a){return function(){const b=a.workspace,c=a.getField("VAR").getVariable();$.renameVariable$$module$build$src$core$variables(b,c)}},deleteOptionCallbackFactory$$module$build$src$blocks$variables_dynamic=function(a){return function(){const b=a.workspace,c=a.getField("VAR").getVariable();b.deleteVariableById(c.getId());b.refreshToolboxSelection()}};
|
||||
$.registerMixin$$module$build$src$core$extensions("contextMenu_variableDynamicSetterGetter",CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN$$module$build$src$blocks$variables_dynamic);$.defineBlocks$$module$build$src$core$common(blocks$$module$build$src$blocks$variables_dynamic);var module$build$src$blocks$variables_dynamic={blocks:blocks$$module$build$src$blocks$variables_dynamic};var blocks$$module$build$src$blocks$variables=$.createBlockDefinitionsFromJsonArray$$module$build$src$core$common([{type:"variables_get",message0:"%1",args0:[{type:"field_variable",name:"VAR",variable:"%{BKY_VARIABLES_DEFAULT_NAME}"}],output:null,style:"variable_blocks",helpUrl:"%{BKY_VARIABLES_GET_HELPURL}",tooltip:"%{BKY_VARIABLES_GET_TOOLTIP}",extensions:["contextMenu_variableSetterGetter"]},{type:"variables_set",message0:"%{BKY_VARIABLES_SET}",args0:[{type:"field_variable",name:"VAR",variable:"%{BKY_VARIABLES_DEFAULT_NAME}"},
|
||||
{type:"input_value",name:"VALUE"}],previousStatement:null,nextStatement:null,style:"variable_blocks",tooltip:"%{BKY_VARIABLES_SET_TOOLTIP}",helpUrl:"%{BKY_VARIABLES_SET_HELPURL}",extensions:["contextMenu_variableSetterGetter"]}]),CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN$$module$build$src$blocks$variables={customContextMenu:function(a){if(!this.isInFlyout){if("variables_get"===this.type){var b="variables_set";var c=$.Msg$$module$build$src$core$msg.VARIABLES_GET_CREATE_SET}else b="variables_get",
|
||||
c=$.Msg$$module$build$src$core$msg.VARIABLES_SET_CREATE_GET;var d=this.getField("VAR");b={type:b,fields:{VAR:d.saveState(!0)}};a.push({enabled:0<this.workspace.remainingCapacity(),text:c.replace("%1",d.getText()),callback:$.callbackFactory$$module$build$src$core$contextmenu(this,b)})}else if("variables_get"===this.type||"variables_get_reporter"===this.type)c={text:$.Msg$$module$build$src$core$msg.RENAME_VARIABLE,enabled:!0,callback:renameOptionCallbackFactory$$module$build$src$blocks$variables(this)},
|
||||
d=this.getField("VAR").getText(),d={text:$.Msg$$module$build$src$core$msg.DELETE_VARIABLE.replace("%1",d),enabled:!0,callback:deleteOptionCallbackFactory$$module$build$src$blocks$variables(this)},a.unshift(c),a.unshift(d)}},renameOptionCallbackFactory$$module$build$src$blocks$variables=function(a){return function(){const b=a.workspace,c=a.getField("VAR").getVariable();$.renameVariable$$module$build$src$core$variables(b,c)}},deleteOptionCallbackFactory$$module$build$src$blocks$variables=function(a){return function(){const b=
|
||||
a.workspace,c=a.getField("VAR").getVariable();b.deleteVariableById(c.getId());b.refreshToolboxSelection()}};$.registerMixin$$module$build$src$core$extensions("contextMenu_variableSetterGetter",CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN$$module$build$src$blocks$variables);$.defineBlocks$$module$build$src$core$common(blocks$$module$build$src$blocks$variables);var module$build$src$blocks$variables={blocks:blocks$$module$build$src$blocks$variables};var blocks$$module$build$src$blocks$text=$.createBlockDefinitionsFromJsonArray$$module$build$src$core$common([{type:"text",message0:"%1",args0:[{type:"field_input",name:"TEXT",text:""}],output:"String",style:"text_blocks",helpUrl:"%{BKY_TEXT_TEXT_HELPURL}",tooltip:"%{BKY_TEXT_TEXT_TOOLTIP}",extensions:["text_quotes","parent_tooltip_when_inline"]},{type:"text_join",message0:"",output:"String",style:"text_blocks",helpUrl:"%{BKY_TEXT_JOIN_HELPURL}",tooltip:"%{BKY_TEXT_JOIN_TOOLTIP}",mutator:"text_join_mutator"},
|
||||
{type:"text_create_join_container",message0:"%{BKY_TEXT_CREATE_JOIN_TITLE_JOIN} %1 %2",args0:[{type:"input_dummy"},{type:"input_statement",name:"STACK"}],style:"text_blocks",tooltip:"%{BKY_TEXT_CREATE_JOIN_TOOLTIP}",enableContextMenu:!1},{type:"text_create_join_item",message0:"%{BKY_TEXT_CREATE_JOIN_ITEM_TITLE_ITEM}",previousStatement:null,nextStatement:null,style:"text_blocks",tooltip:"%{BKY_TEXT_CREATE_JOIN_ITEM_TOOLTIP}",enableContextMenu:!1},{type:"text_append",message0:"%{BKY_TEXT_APPEND_TITLE}",
|
||||
args0:[{type:"field_variable",name:"VAR",variable:"%{BKY_TEXT_APPEND_VARIABLE}"},{type:"input_value",name:"TEXT"}],previousStatement:null,nextStatement:null,style:"text_blocks",extensions:["text_append_tooltip"]},{type:"text_length",message0:"%{BKY_TEXT_LENGTH_TITLE}",args0:[{type:"input_value",name:"VALUE",check:["String","Array"]}],output:"Number",style:"text_blocks",tooltip:"%{BKY_TEXT_LENGTH_TOOLTIP}",helpUrl:"%{BKY_TEXT_LENGTH_HELPURL}"},{type:"text_isEmpty",message0:"%{BKY_TEXT_ISEMPTY_TITLE}",
|
||||
args0:[{type:"input_value",name:"VALUE",check:["String","Array"]}],output:"Boolean",style:"text_blocks",tooltip:"%{BKY_TEXT_ISEMPTY_TOOLTIP}",helpUrl:"%{BKY_TEXT_ISEMPTY_HELPURL}"},{type:"text_indexOf",message0:"%{BKY_TEXT_INDEXOF_TITLE}",args0:[{type:"input_value",name:"VALUE",check:"String"},{type:"field_dropdown",name:"END",options:[["%{BKY_TEXT_INDEXOF_OPERATOR_FIRST}","FIRST"],["%{BKY_TEXT_INDEXOF_OPERATOR_LAST}","LAST"]]},{type:"input_value",name:"FIND",check:"String"}],output:"Number",style:"text_blocks",
|
||||
helpUrl:"%{BKY_TEXT_INDEXOF_HELPURL}",inputsInline:!0,extensions:["text_indexOf_tooltip"]},{type:"text_charAt",message0:"%{BKY_TEXT_CHARAT_TITLE}",args0:[{type:"input_value",name:"VALUE",check:"String"},{type:"field_dropdown",name:"WHERE",options:[["%{BKY_TEXT_CHARAT_FROM_START}","FROM_START"],["%{BKY_TEXT_CHARAT_FROM_END}","FROM_END"],["%{BKY_TEXT_CHARAT_FIRST}","FIRST"],["%{BKY_TEXT_CHARAT_LAST}","LAST"],["%{BKY_TEXT_CHARAT_RANDOM}","RANDOM"]]}],output:"String",style:"text_blocks",helpUrl:"%{BKY_TEXT_CHARAT_HELPURL}",
|
||||
inputsInline:!0,mutator:"text_charAt_mutator"}]),GET_SUBSTRING_BLOCK$$module$build$src$blocks$text={init:function(){this.WHERE_OPTIONS_1=[[$.Msg$$module$build$src$core$msg.TEXT_GET_SUBSTRING_START_FROM_START,"FROM_START"],[$.Msg$$module$build$src$core$msg.TEXT_GET_SUBSTRING_START_FROM_END,"FROM_END"],[$.Msg$$module$build$src$core$msg.TEXT_GET_SUBSTRING_START_FIRST,"FIRST"]];this.WHERE_OPTIONS_2=[[$.Msg$$module$build$src$core$msg.TEXT_GET_SUBSTRING_END_FROM_START,"FROM_START"],[$.Msg$$module$build$src$core$msg.TEXT_GET_SUBSTRING_END_FROM_END,
|
||||
"FROM_END"],[$.Msg$$module$build$src$core$msg.TEXT_GET_SUBSTRING_END_LAST,"LAST"]];this.setHelpUrl($.Msg$$module$build$src$core$msg.TEXT_GET_SUBSTRING_HELPURL);this.setStyle("text_blocks");this.appendValueInput("STRING").setCheck("String").appendField($.Msg$$module$build$src$core$msg.TEXT_GET_SUBSTRING_INPUT_IN_TEXT);this.appendDummyInput("AT1");this.appendDummyInput("AT2");$.Msg$$module$build$src$core$msg.TEXT_GET_SUBSTRING_TAIL&&this.appendDummyInput("TAIL").appendField($.Msg$$module$build$src$core$msg.TEXT_GET_SUBSTRING_TAIL);
|
||||
this.setInputsInline(!0);this.setOutput(!0,"String");this.updateAt_(1,!0);this.updateAt_(2,!0);this.setTooltip($.Msg$$module$build$src$core$msg.TEXT_GET_SUBSTRING_TOOLTIP)},mutationToDom:function(){const a=$.createElement$$module$build$src$core$utils$xml("mutation");var b=this.getInput("AT1")instanceof $.ValueInput$$module$build$src$core$inputs$value_input;a.setAttribute("at1",`${b}`);b=this.getInput("AT2")instanceof $.ValueInput$$module$build$src$core$inputs$value_input;a.setAttribute("at2",`${b}`);
|
||||
return a},domToMutation:function(a){const b="true"===a.getAttribute("at1");a="true"===a.getAttribute("at2");this.updateAt_(1,b);this.updateAt_(2,a)},updateAt_:function(a,b){this.removeInput("AT"+a);this.removeInput("ORDINAL"+a,!0);b?(this.appendValueInput("AT"+a).setCheck("Number"),$.Msg$$module$build$src$core$msg.ORDINAL_NUMBER_SUFFIX&&this.appendDummyInput("ORDINAL"+a).appendField($.Msg$$module$build$src$core$msg.ORDINAL_NUMBER_SUFFIX)):this.appendDummyInput("AT"+a);2===a&&$.Msg$$module$build$src$core$msg.TEXT_GET_SUBSTRING_TAIL&&
|
||||
(this.removeInput("TAIL",!0),this.appendDummyInput("TAIL").appendField($.Msg$$module$build$src$core$msg.TEXT_GET_SUBSTRING_TAIL));const c=$.fromJson$$module$build$src$core$field_registry({type:"field_dropdown",options:this["WHERE_OPTIONS_"+a]});c.setValidator(function(d){const e="FROM_START"===d||"FROM_END"===d;if(e!==b){const f=this.getSourceBlock();f.updateAt_(a,e);f.setFieldValue(d,"WHERE"+a);return null}});this.getInput("AT"+a).appendField(c,"WHERE"+a);1===a&&(this.moveInputBefore("AT1","AT2"),
|
||||
this.getInput("ORDINAL1")&&this.moveInputBefore("ORDINAL1","AT2"))}};blocks$$module$build$src$blocks$text.text_getSubstring=GET_SUBSTRING_BLOCK$$module$build$src$blocks$text;
|
||||
blocks$$module$build$src$blocks$text.text_changeCase={init:function(){const a=[[$.Msg$$module$build$src$core$msg.TEXT_CHANGECASE_OPERATOR_UPPERCASE,"UPPERCASE"],[$.Msg$$module$build$src$core$msg.TEXT_CHANGECASE_OPERATOR_LOWERCASE,"LOWERCASE"],[$.Msg$$module$build$src$core$msg.TEXT_CHANGECASE_OPERATOR_TITLECASE,"TITLECASE"]];this.setHelpUrl($.Msg$$module$build$src$core$msg.TEXT_CHANGECASE_HELPURL);this.setStyle("text_blocks");this.appendValueInput("TEXT").setCheck("String").appendField($.fromJson$$module$build$src$core$field_registry({type:"field_dropdown",
|
||||
options:a}),"CASE");this.setOutput(!0,"String");this.setTooltip($.Msg$$module$build$src$core$msg.TEXT_CHANGECASE_TOOLTIP)}};
|
||||
blocks$$module$build$src$blocks$text.text_trim={init:function(){const a=[[$.Msg$$module$build$src$core$msg.TEXT_TRIM_OPERATOR_BOTH,"BOTH"],[$.Msg$$module$build$src$core$msg.TEXT_TRIM_OPERATOR_LEFT,"LEFT"],[$.Msg$$module$build$src$core$msg.TEXT_TRIM_OPERATOR_RIGHT,"RIGHT"]];this.setHelpUrl($.Msg$$module$build$src$core$msg.TEXT_TRIM_HELPURL);this.setStyle("text_blocks");this.appendValueInput("TEXT").setCheck("String").appendField($.fromJson$$module$build$src$core$field_registry({type:"field_dropdown",options:a}),
|
||||
"MODE");this.setOutput(!0,"String");this.setTooltip($.Msg$$module$build$src$core$msg.TEXT_TRIM_TOOLTIP)}};blocks$$module$build$src$blocks$text.text_print={init:function(){this.jsonInit({message0:$.Msg$$module$build$src$core$msg.TEXT_PRINT_TITLE,args0:[{type:"input_value",name:"TEXT"}],previousStatement:null,nextStatement:null,style:"text_blocks",tooltip:$.Msg$$module$build$src$core$msg.TEXT_PRINT_TOOLTIP,helpUrl:$.Msg$$module$build$src$core$msg.TEXT_PRINT_HELPURL})}};
|
||||
var PROMPT_COMMON$$module$build$src$blocks$text={updateType_:function(a){this.outputConnection.setCheck("NUMBER"===a?"Number":"String")},mutationToDom:function(){const a=$.createElement$$module$build$src$core$utils$xml("mutation");a.setAttribute("type",this.getFieldValue("TYPE"));return a},domToMutation:function(a){this.updateType_(a.getAttribute("type"))}};
|
||||
blocks$$module$build$src$blocks$text.text_prompt_ext=Object.assign({},PROMPT_COMMON$$module$build$src$blocks$text,{init:function(){var a=[[$.Msg$$module$build$src$core$msg.TEXT_PROMPT_TYPE_TEXT,"TEXT"],[$.Msg$$module$build$src$core$msg.TEXT_PROMPT_TYPE_NUMBER,"NUMBER"]];this.setHelpUrl($.Msg$$module$build$src$core$msg.TEXT_PROMPT_HELPURL);this.setStyle("text_blocks");a=$.fromJson$$module$build$src$core$field_registry({type:"field_dropdown",options:a});a.setValidator(b=>{this.updateType_(b)});this.appendValueInput("TEXT").appendField(a,
|
||||
"TYPE");this.setOutput(!0,"String");this.setTooltip(()=>"TEXT"===this.getFieldValue("TYPE")?$.Msg$$module$build$src$core$msg.TEXT_PROMPT_TOOLTIP_TEXT:$.Msg$$module$build$src$core$msg.TEXT_PROMPT_TOOLTIP_NUMBER)}});
|
||||
var TEXT_PROMPT_BLOCK$$module$build$src$blocks$text=Object.assign({},PROMPT_COMMON$$module$build$src$blocks$text,{init:function(){this.mixin(QUOTE_IMAGE_MIXIN$$module$build$src$blocks$text);var a=[[$.Msg$$module$build$src$core$msg.TEXT_PROMPT_TYPE_TEXT,"TEXT"],[$.Msg$$module$build$src$core$msg.TEXT_PROMPT_TYPE_NUMBER,"NUMBER"]];this.setHelpUrl($.Msg$$module$build$src$core$msg.TEXT_PROMPT_HELPURL);this.setStyle("text_blocks");a=$.fromJson$$module$build$src$core$field_registry({type:"field_dropdown",
|
||||
options:a});a.setValidator(b=>{this.updateType_(b)});this.appendDummyInput().appendField(a,"TYPE").appendField(this.newQuote_(!0)).appendField($.fromJson$$module$build$src$core$field_registry({type:"field_input",text:""}),"TEXT").appendField(this.newQuote_(!1));this.setOutput(!0,"String");this.setTooltip(()=>"TEXT"===this.getFieldValue("TYPE")?$.Msg$$module$build$src$core$msg.TEXT_PROMPT_TOOLTIP_TEXT:$.Msg$$module$build$src$core$msg.TEXT_PROMPT_TOOLTIP_NUMBER)}});
|
||||
blocks$$module$build$src$blocks$text.text_prompt=TEXT_PROMPT_BLOCK$$module$build$src$blocks$text;blocks$$module$build$src$blocks$text.text_count={init:function(){this.jsonInit({message0:$.Msg$$module$build$src$core$msg.TEXT_COUNT_MESSAGE0,args0:[{type:"input_value",name:"SUB",check:"String"},{type:"input_value",name:"TEXT",check:"String"}],output:"Number",inputsInline:!0,style:"text_blocks",tooltip:$.Msg$$module$build$src$core$msg.TEXT_COUNT_TOOLTIP,helpUrl:$.Msg$$module$build$src$core$msg.TEXT_COUNT_HELPURL})}};
|
||||
blocks$$module$build$src$blocks$text.text_replace={init:function(){this.jsonInit({message0:$.Msg$$module$build$src$core$msg.TEXT_REPLACE_MESSAGE0,args0:[{type:"input_value",name:"FROM",check:"String"},{type:"input_value",name:"TO",check:"String"},{type:"input_value",name:"TEXT",check:"String"}],output:"String",inputsInline:!0,style:"text_blocks",tooltip:$.Msg$$module$build$src$core$msg.TEXT_REPLACE_TOOLTIP,helpUrl:$.Msg$$module$build$src$core$msg.TEXT_REPLACE_HELPURL})}};
|
||||
blocks$$module$build$src$blocks$text.text_reverse={init:function(){this.jsonInit({message0:$.Msg$$module$build$src$core$msg.TEXT_REVERSE_MESSAGE0,args0:[{type:"input_value",name:"TEXT",check:"String"}],output:"String",inputsInline:!0,style:"text_blocks",tooltip:$.Msg$$module$build$src$core$msg.TEXT_REVERSE_TOOLTIP,helpUrl:$.Msg$$module$build$src$core$msg.TEXT_REVERSE_HELPURL})}};
|
||||
var QUOTE_IMAGE_MIXIN$$module$build$src$blocks$text={QUOTE_IMAGE_LEFT_DATAURI:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAn0lEQVQI1z3OMa5BURSF4f/cQhAKjUQhuQmFNwGJEUi0RKN5rU7FHKhpjEH3TEMtkdBSCY1EIv8r7nFX9e29V7EBAOvu7RPjwmWGH/VuF8CyN9/OAdvqIXYLvtRaNjx9mMTDyo+NjAN1HNcl9ZQ5oQMM3dgDUqDo1l8DzvwmtZN7mnD+PkmLa+4mhrxVA9fRowBWmVBhFy5gYEjKMfz9AylsaRRgGzvZAAAAAElFTkSuQmCC",QUOTE_IMAGE_RIGHT_DATAURI:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAqUlEQVQI1z3KvUpCcRiA8ef9E4JNHhI0aFEacm1o0BsI0Slx8wa8gLauoDnoBhq7DcfWhggONDmJJgqCPA7neJ7p934EOOKOnM8Q7PDElo/4x4lFb2DmuUjcUzS3URnGib9qaPNbuXvBO3sGPHJDRG6fGVdMSeWDP2q99FQdFrz26Gu5Tq7dFMzUvbXy8KXeAj57cOklgA+u1B5AoslLtGIHQMaCVnwDnADZIFIrXsoXrgAAAABJRU5ErkJggg==",
|
||||
QUOTE_IMAGE_WIDTH:12,QUOTE_IMAGE_HEIGHT:12,quoteField_:function(a){for(let b=0,c;c=this.inputList[b];b++)for(let d=0,e;e=c.fieldRow[d];d++)if(a===e.name){c.insertFieldAt(d,this.newQuote_(!0));c.insertFieldAt(d+2,this.newQuote_(!1));return}console.warn('field named "'+a+'" not found in '+this.toDevString())},newQuote_:function(a){a=this.RTL?!a:a;return $.fromJson$$module$build$src$core$field_registry({type:"field_image",src:a?this.QUOTE_IMAGE_LEFT_DATAURI:this.QUOTE_IMAGE_RIGHT_DATAURI,width:this.QUOTE_IMAGE_WIDTH,
|
||||
height:this.QUOTE_IMAGE_HEIGHT,alt:a?"\u201c":"\u201d"})}},QUOTES_EXTENSION$$module$build$src$blocks$text=function(){this.mixin(QUOTE_IMAGE_MIXIN$$module$build$src$blocks$text);this.quoteField_("TEXT")},JOIN_MUTATOR_MIXIN$$module$build$src$blocks$text={itemCount_:0,mutationToDom:function(){const a=$.createElement$$module$build$src$core$utils$xml("mutation");a.setAttribute("items",`${this.itemCount_}`);return a},domToMutation:function(a){this.itemCount_=parseInt(a.getAttribute("items"),10);this.updateShape_()},
|
||||
saveExtraState:function(){return{itemCount:this.itemCount_}},loadExtraState:function(a){this.itemCount_=a.itemCount;this.updateShape_()},decompose:function(a){const b=a.newBlock("text_create_join_container");b.initSvg();let c=b.getInput("STACK").connection;for(let d=0;d<this.itemCount_;d++){const e=a.newBlock("text_create_join_item");e.initSvg();c.connect(e.previousConnection);c=e.nextConnection}return b},compose:function(a){var b=a.getInputTargetBlock("STACK");for(a=[];b;)b.isInsertionMarker()||
|
||||
a.push(b.valueConnection_),b=b.getNextBlock();for(b=0;b<this.itemCount_;b++){const c=this.getInput("ADD"+b).connection.targetConnection;c&&!a.includes(c)&&c.disconnect()}this.itemCount_=a.length;this.updateShape_();for(b=0;b<this.itemCount_;b++){let c;null==(c=a[b])||c.reconnect(this,"ADD"+b)}},saveConnections:function(a){a=a.getInputTargetBlock("STACK");let b=0;for(;a;){if(a.isInsertionMarker()){a=a.getNextBlock();continue}const c=this.getInput("ADD"+b);a.valueConnection_=c&&c.connection.targetConnection;
|
||||
a=a.getNextBlock();b++}},updateShape_:function(){this.itemCount_&&this.getInput("EMPTY")?this.removeInput("EMPTY"):this.itemCount_||this.getInput("EMPTY")||this.appendDummyInput("EMPTY").appendField(this.newQuote_(!0)).appendField(this.newQuote_(!1));for(var a=0;a<this.itemCount_;a++)if(!this.getInput("ADD"+a)){const b=this.appendValueInput("ADD"+a).setAlign($.Align$$module$build$src$core$inputs$align.RIGHT);0===a&&b.appendField($.Msg$$module$build$src$core$msg.TEXT_JOIN_TITLE_CREATEWITH)}for(a=this.itemCount_;this.getInput("ADD"+
|
||||
a);a++)this.removeInput("ADD"+a)}},JOIN_EXTENSION$$module$build$src$blocks$text=function(){this.mixin(QUOTE_IMAGE_MIXIN$$module$build$src$blocks$text);this.itemCount_=2;this.updateShape_();this.setMutator(new $.MutatorIcon$$module$build$src$core$icons$mutator_icon(["text_create_join_item"],this))};$.register$$module$build$src$core$extensions("text_append_tooltip",$.buildTooltipWithFieldText$$module$build$src$core$extensions("%{BKY_TEXT_APPEND_TOOLTIP}","VAR"));
|
||||
var INDEXOF_TOOLTIP_EXTENSION$$module$build$src$blocks$text=function(){this.setTooltip(()=>$.Msg$$module$build$src$core$msg.TEXT_INDEXOF_TOOLTIP.replace("%1",this.workspace.options.oneBasedIndex?"0":"-1"))},CHARAT_MUTATOR_MIXIN$$module$build$src$blocks$text={isAt_:!1,mutationToDom:function(){const a=$.createElement$$module$build$src$core$utils$xml("mutation");a.setAttribute("at",`${this.isAt_}`);return a},domToMutation:function(a){a="false"!==a.getAttribute("at");this.updateAt_(a)},updateAt_:function(a){this.removeInput("AT",
|
||||
!0);this.removeInput("ORDINAL",!0);a&&(this.appendValueInput("AT").setCheck("Number"),$.Msg$$module$build$src$core$msg.ORDINAL_NUMBER_SUFFIX&&this.appendDummyInput("ORDINAL").appendField($.Msg$$module$build$src$core$msg.ORDINAL_NUMBER_SUFFIX));$.Msg$$module$build$src$core$msg.TEXT_CHARAT_TAIL&&(this.removeInput("TAIL",!0),this.appendDummyInput("TAIL").appendField($.Msg$$module$build$src$core$msg.TEXT_CHARAT_TAIL));this.isAt_=a}},CHARAT_EXTENSION$$module$build$src$blocks$text=function(){this.getField("WHERE").setValidator(function(a){a=
|
||||
"FROM_START"===a||"FROM_END"===a;const b=this.getSourceBlock();a!==b.isAt_&&b.updateAt_(a)});this.updateAt_(!0);this.setTooltip(()=>{var a=this.getFieldValue("WHERE");let b=$.Msg$$module$build$src$core$msg.TEXT_CHARAT_TOOLTIP;("FROM_START"===a||"FROM_END"===a)&&(a="FROM_START"===a?$.Msg$$module$build$src$core$msg.LISTS_INDEX_FROM_START_TOOLTIP:$.Msg$$module$build$src$core$msg.LISTS_INDEX_FROM_END_TOOLTIP)&&(b+=" "+a.replace("%1",this.workspace.options.oneBasedIndex?"#1":"#0"));return b})};
|
||||
$.register$$module$build$src$core$extensions("text_indexOf_tooltip",INDEXOF_TOOLTIP_EXTENSION$$module$build$src$blocks$text);$.register$$module$build$src$core$extensions("text_quotes",QUOTES_EXTENSION$$module$build$src$blocks$text);$.registerMixin$$module$build$src$core$extensions("quote_image_mixin",QUOTE_IMAGE_MIXIN$$module$build$src$blocks$text);$.registerMutator$$module$build$src$core$extensions("text_join_mutator",JOIN_MUTATOR_MIXIN$$module$build$src$blocks$text,JOIN_EXTENSION$$module$build$src$blocks$text);
|
||||
$.registerMutator$$module$build$src$core$extensions("text_charAt_mutator",CHARAT_MUTATOR_MIXIN$$module$build$src$blocks$text,CHARAT_EXTENSION$$module$build$src$blocks$text);$.defineBlocks$$module$build$src$core$common(blocks$$module$build$src$blocks$text);var module$build$src$blocks$text={blocks:blocks$$module$build$src$blocks$text};var blocks$$module$build$src$blocks$procedures={},PROCEDURE_DEF_COMMON$$module$build$src$blocks$procedures={setStatements_:function(a){this.hasStatements_!==a&&(a?(this.appendStatementInput("STACK").appendField($.Msg$$module$build$src$core$msg.PROCEDURES_DEFNORETURN_DO),this.getInput("RETURN")&&this.moveInputBefore("STACK","RETURN")):this.removeInput("STACK",!0),this.hasStatements_=a)},updateParams_:function(){let a="";this.arguments_.length&&(a=$.Msg$$module$build$src$core$msg.PROCEDURES_BEFORE_PARAMS+
|
||||
" "+this.arguments_.join(", "));$.disable$$module$build$src$core$events$utils();try{this.setFieldValue(a,"PARAMS")}finally{$.enable$$module$build$src$core$events$utils()}},mutationToDom:function(a){const b=$.createElement$$module$build$src$core$utils$xml("mutation");a&&b.setAttribute("name",this.getFieldValue("NAME"));for(let c=0;c<this.argumentVarModels_.length;c++){const d=$.createElement$$module$build$src$core$utils$xml("arg"),e=this.argumentVarModels_[c];d.setAttribute("name",e.name);d.setAttribute("varid",
|
||||
e.getId());a&&this.paramIds_&&d.setAttribute("paramId",this.paramIds_[c]);b.appendChild(d)}this.hasStatements_||b.setAttribute("statements","false");return b},domToMutation:function(a){this.arguments_=[];this.argumentVarModels_=[];for(let c=0,d;d=a.childNodes[c];c++)if("arg"===d.nodeName.toLowerCase()){var b=d;const e=b.getAttribute("name");b=b.getAttribute("varid")||b.getAttribute("varId");this.arguments_.push(e);b=$.getOrCreateVariablePackage$$module$build$src$core$variables(this.workspace,b,e,
|
||||
"");null!==b?this.argumentVarModels_.push(b):console.log(`Failed to create a variable named "${e}", ignoring.`)}this.updateParams_();$.mutateCallers$$module$build$src$core$procedures(this);this.setStatements_("false"!==a.getAttribute("statements"))},saveExtraState:function(){if(!this.argumentVarModels_.length&&this.hasStatements_)return null;const a=Object.create(null);if(this.argumentVarModels_.length){a.params=[];for(let b=0;b<this.argumentVarModels_.length;b++)a.params.push({name:this.argumentVarModels_[b].name,
|
||||
id:this.argumentVarModels_[b].getId()})}this.hasStatements_||(a.hasStatements=!1);return a},loadExtraState:function(a){this.arguments_=[];this.argumentVarModels_=[];if(a.params)for(let c=0;c<a.params.length;c++){var b=a.params[c];b=$.getOrCreateVariablePackage$$module$build$src$core$variables(this.workspace,b.id,b.name,"");this.arguments_.push(b.name);this.argumentVarModels_.push(b)}this.updateParams_();$.mutateCallers$$module$build$src$core$procedures(this);this.setStatements_(!1===a.hasStatements?
|
||||
!1:!0)},decompose:function(a){const b=$.createElement$$module$build$src$core$utils$xml("block");b.setAttribute("type","procedures_mutatorcontainer");var c=$.createElement$$module$build$src$core$utils$xml("statement");c.setAttribute("name","STACK");b.appendChild(c);for(let e=0;e<this.arguments_.length;e++){const f=$.createElement$$module$build$src$core$utils$xml("block");f.setAttribute("type","procedures_mutatorarg");var d=$.createElement$$module$build$src$core$utils$xml("field");d.setAttribute("name",
|
||||
"NAME");const g=$.createTextNode$$module$build$src$core$utils$xml(this.arguments_[e]);d.appendChild(g);f.appendChild(d);d=$.createElement$$module$build$src$core$utils$xml("next");f.appendChild(d);c.appendChild(f);c=d}a=$.domToBlock$$module$build$src$core$xml(b,a);"procedures_defreturn"===this.type?a.setFieldValue(this.hasStatements_,"STATEMENTS"):a.removeInput("STATEMENT_INPUT");$.mutateCallers$$module$build$src$core$procedures(this);return a},compose:function(a){this.arguments_=[];this.paramIds_=
|
||||
[];this.argumentVarModels_=[];let b=a.getInputTargetBlock("STACK");for(;b&&!b.isInsertionMarker();){var c=b.getFieldValue("NAME");this.arguments_.push(c);c=this.workspace.getVariable(c,"");this.argumentVarModels_.push(c);this.paramIds_.push(b.id);b=b.nextConnection&&b.nextConnection.targetBlock()}this.updateParams_();$.mutateCallers$$module$build$src$core$procedures(this);a=a.getFieldValue("STATEMENTS");if(null!==a&&(a="TRUE"===a,this.hasStatements_!==a))if(a){this.setStatements_(!0);var d;null==
|
||||
(d=this.statementConnection_)||d.reconnect(this,"STACK");this.statementConnection_=null}else{d=this.getInput("STACK").connection;if(this.statementConnection_=d.targetConnection)d=d.targetBlock(),d.unplug(),d.bumpNeighbours();this.setStatements_(!1)}},getVars:function(){return this.arguments_},getVarModels:function(){return this.argumentVarModels_},renameVarById:function(a,b){var c=this.workspace.getVariableById(a);if(""===c.type){c=c.name;b=this.workspace.getVariableById(b);var d=!1;for(let e=0;e<
|
||||
this.argumentVarModels_.length;e++)this.argumentVarModels_[e].getId()===a&&(this.arguments_[e]=b.name,this.argumentVarModels_[e]=b,d=!0);d&&(this.displayRenamedVar_(c,b.name),$.mutateCallers$$module$build$src$core$procedures(this))}},updateVarName:function(a){const b=a.name;let c=!1,d;for(let e=0;e<this.argumentVarModels_.length;e++)this.argumentVarModels_[e].getId()===a.getId()&&(d=this.arguments_[e],this.arguments_[e]=b,c=!0);c&&(this.displayRenamedVar_(d,b),$.mutateCallers$$module$build$src$core$procedures(this))},
|
||||
displayRenamedVar_:function(a,b){this.updateParams_();var c=this.getIcon($.MutatorIcon$$module$build$src$core$icons$mutator_icon.TYPE);if(c&&c.bubbleIsVisible()){c=c.getWorkspace().getAllBlocks(!1);for(let d=0,e;e=c[d];d++)"procedures_mutatorarg"===e.type&&$.Names$$module$build$src$core$names.equals(a,e.getFieldValue("NAME"))&&e.setFieldValue(b,"NAME")}},customContextMenu:function(a){if(!this.isInFlyout){var b=this.getFieldValue("NAME"),c={type:this.callType_,extraState:{name:b,params:this.arguments_}};
|
||||
a.push({enabled:!0,text:$.Msg$$module$build$src$core$msg.PROCEDURES_CREATE_DO.replace("%1",b),callback:$.callbackFactory$$module$build$src$core$contextmenu(this,c)});if(!this.isCollapsed())for(b=0;b<this.argumentVarModels_.length;b++){c=this.argumentVarModels_[b];const d={type:"variables_get",fields:{VAR:{name:c.name,id:c.getId(),type:c.type}}};a.push({enabled:!0,text:$.Msg$$module$build$src$core$msg.VARIABLES_SET_CREATE_GET.replace("%1",c.name),callback:$.callbackFactory$$module$build$src$core$contextmenu(this,
|
||||
d)})}}}};
|
||||
blocks$$module$build$src$blocks$procedures.procedures_defnoreturn=Object.assign({},PROCEDURE_DEF_COMMON$$module$build$src$blocks$procedures,{init:function(){var a=$.findLegalName$$module$build$src$core$procedures("",this);a=$.fromJson$$module$build$src$core$field_registry({type:"field_input",text:a});a.setValidator($.rename$$module$build$src$core$procedures);a.setSpellcheck(!1);this.appendDummyInput().appendField($.Msg$$module$build$src$core$msg.PROCEDURES_DEFNORETURN_TITLE).appendField(a,"NAME").appendField("",
|
||||
"PARAMS");this.setMutator(new $.MutatorIcon$$module$build$src$core$icons$mutator_icon(["procedures_mutatorarg"],this));(this.workspace.options.comments||this.workspace.options.parentWorkspace&&this.workspace.options.parentWorkspace.options.comments)&&$.Msg$$module$build$src$core$msg.PROCEDURES_DEFNORETURN_COMMENT&&this.setCommentText($.Msg$$module$build$src$core$msg.PROCEDURES_DEFNORETURN_COMMENT);this.setStyle("procedure_blocks");this.setTooltip($.Msg$$module$build$src$core$msg.PROCEDURES_DEFNORETURN_TOOLTIP);
|
||||
this.setHelpUrl($.Msg$$module$build$src$core$msg.PROCEDURES_DEFNORETURN_HELPURL);this.arguments_=[];this.argumentVarModels_=[];this.setStatements_(!0);this.statementConnection_=null},getProcedureDef:function(){return[this.getFieldValue("NAME"),this.arguments_,!1]},callType_:"procedures_callnoreturn"});
|
||||
blocks$$module$build$src$blocks$procedures.procedures_defreturn=Object.assign({},PROCEDURE_DEF_COMMON$$module$build$src$blocks$procedures,{init:function(){var a=$.findLegalName$$module$build$src$core$procedures("",this);a=$.fromJson$$module$build$src$core$field_registry({type:"field_input",text:a});a.setValidator($.rename$$module$build$src$core$procedures);a.setSpellcheck(!1);this.appendDummyInput().appendField($.Msg$$module$build$src$core$msg.PROCEDURES_DEFRETURN_TITLE).appendField(a,"NAME").appendField("",
|
||||
"PARAMS");this.appendValueInput("RETURN").setAlign($.Align$$module$build$src$core$inputs$align.RIGHT).appendField($.Msg$$module$build$src$core$msg.PROCEDURES_DEFRETURN_RETURN);this.setMutator(new $.MutatorIcon$$module$build$src$core$icons$mutator_icon(["procedures_mutatorarg"],this));(this.workspace.options.comments||this.workspace.options.parentWorkspace&&this.workspace.options.parentWorkspace.options.comments)&&$.Msg$$module$build$src$core$msg.PROCEDURES_DEFRETURN_COMMENT&&this.setCommentText($.Msg$$module$build$src$core$msg.PROCEDURES_DEFRETURN_COMMENT);
|
||||
this.setStyle("procedure_blocks");this.setTooltip($.Msg$$module$build$src$core$msg.PROCEDURES_DEFRETURN_TOOLTIP);this.setHelpUrl($.Msg$$module$build$src$core$msg.PROCEDURES_DEFRETURN_HELPURL);this.arguments_=[];this.argumentVarModels_=[];this.setStatements_(!0);this.statementConnection_=null},getProcedureDef:function(){return[this.getFieldValue("NAME"),this.arguments_,!0]},callType_:"procedures_callreturn"});
|
||||
var PROCEDURES_MUTATORCONTAINER$$module$build$src$blocks$procedures={init:function(){this.appendDummyInput().appendField($.Msg$$module$build$src$core$msg.PROCEDURES_MUTATORCONTAINER_TITLE);this.appendStatementInput("STACK");this.appendDummyInput("STATEMENT_INPUT").appendField($.Msg$$module$build$src$core$msg.PROCEDURES_ALLOW_STATEMENTS).appendField($.fromJson$$module$build$src$core$field_registry({type:"field_checkbox",checked:!0}),"STATEMENTS");this.setStyle("procedure_blocks");this.setTooltip($.Msg$$module$build$src$core$msg.PROCEDURES_MUTATORCONTAINER_TOOLTIP);
|
||||
this.contextMenu=!1}};blocks$$module$build$src$blocks$procedures.procedures_mutatorcontainer=PROCEDURES_MUTATORCONTAINER$$module$build$src$blocks$procedures;
|
||||
var PROCEDURES_MUTATORARGUMENT$$module$build$src$blocks$procedures={init:function(){const a=$.fromJson$$module$build$src$core$field_registry({type:"field_input",text:$.DEFAULT_ARG$$module$build$src$core$procedures});a.setValidator(this.validator_);a.oldShowEditorFn_=a.showEditor_;a.showEditor_=function(){this.createdVariables_=[];this.oldShowEditorFn_()};this.appendDummyInput().appendField($.Msg$$module$build$src$core$msg.PROCEDURES_MUTATORARG_TITLE).appendField(a,"NAME");this.setPreviousStatement(!0);
|
||||
this.setNextStatement(!0);this.setStyle("procedure_blocks");this.setTooltip($.Msg$$module$build$src$core$msg.PROCEDURES_MUTATORARG_TOOLTIP);this.contextMenu=!1;a.onFinishEditing_=this.deleteIntermediateVars_;a.createdVariables_=[];a.onFinishEditing_("x")},validator_:function(a){var b=this.getSourceBlock();const c=b.workspace.getRootWorkspace();a=a.replace(/[\s\xa0]+/g," ").replace(/^ | $/g,"");if(!a)return null;const d=(b.workspace.targetWorkspace||b.workspace).getAllBlocks(!1),e=a.toLowerCase();
|
||||
for(let f=0;f<d.length;f++){if(d[f].id===this.getSourceBlock().id)continue;const g=d[f].getFieldValue("NAME");if(g&&g.toLowerCase()===e)return null}if(b.isInFlyout)return a;(b=c.getVariable(a,""))&&b.name!==a&&c.renameVariableById(b.getId(),a);b||(b=c.createVariable(a,""))&&this.createdVariables_&&this.createdVariables_.push(b);return a},deleteIntermediateVars_:function(a){const b=this.getSourceBlock().workspace.getRootWorkspace();if(b)for(let c=0;c<this.createdVariables_.length;c++){const d=this.createdVariables_[c];
|
||||
d.name!==a&&b.deleteVariableById(d.getId())}}};blocks$$module$build$src$blocks$procedures.procedures_mutatorarg=PROCEDURES_MUTATORARGUMENT$$module$build$src$blocks$procedures;
|
||||
var DISABLED_PROCEDURE_DEFINITION_DISABLED_REASON$$module$build$src$blocks$procedures="DISABLED_PROCEDURE_DEFINITION",PROCEDURE_CALL_COMMON$$module$build$src$blocks$procedures={getProcedureCall:function(){return this.getFieldValue("NAME")},renameProcedure:function(a,b){$.Names$$module$build$src$core$names.equals(a,this.getProcedureCall())&&(this.setFieldValue(b,"NAME"),this.setTooltip((this.outputConnection?$.Msg$$module$build$src$core$msg.PROCEDURES_CALLRETURN_TOOLTIP:$.Msg$$module$build$src$core$msg.PROCEDURES_CALLNORETURN_TOOLTIP).replace("%1",
|
||||
b)))},setProcedureParameters_:function(a,b){var c=$.getDefinition$$module$build$src$core$procedures(this.getProcedureCall(),this.workspace);(c=(c=c&&c.getIcon($.MutatorIcon$$module$build$src$core$icons$mutator_icon.TYPE))&&c.bubbleIsVisible())?this.setCollapsed(!1):(this.quarkConnections_={},this.quarkIds_=null);if(a.join("\n")===this.arguments_.join("\n"))this.quarkIds_=b;else{if(b.length!==a.length)throw RangeError("paramNames and paramIds must be the same length.");this.quarkIds_||(this.quarkConnections_=
|
||||
{},this.quarkIds_=[]);for(let e=0;e<this.arguments_.length;e++){var d=this.getInput("ARG"+e);d&&(d=d.connection.targetConnection,this.quarkConnections_[this.quarkIds_[e]]=d,c&&d&&!b.includes(this.quarkIds_[e])&&(d.disconnect(),d.getSourceBlock().bumpNeighbours()))}this.arguments_=[].concat(a);this.argumentVarModels_=[];for(a=0;a<this.arguments_.length;a++)c=$.getOrCreateVariablePackage$$module$build$src$core$variables(this.workspace,null,this.arguments_[a],""),this.argumentVarModels_.push(c);this.updateShape_();
|
||||
if(this.quarkIds_=b)for(b=0;b<this.arguments_.length;b++)if(a=this.quarkIds_[b],a in this.quarkConnections_){let e;(null==(e=this.quarkConnections_[a])?0:e.reconnect(this,"ARG"+b))||delete this.quarkConnections_[a]}}},updateShape_:function(){for(var a=0;a<this.arguments_.length;a++){var b=this.getField("ARGNAME"+a);if(b){$.disable$$module$build$src$core$events$utils();try{b.setValue(this.arguments_[a])}finally{$.enable$$module$build$src$core$events$utils()}}else b=$.fromJson$$module$build$src$core$field_registry({type:"field_label",
|
||||
text:this.arguments_[a]}),this.appendValueInput("ARG"+a).setAlign($.Align$$module$build$src$core$inputs$align.RIGHT).appendField(b,"ARGNAME"+a)}for(a=this.arguments_.length;this.getInput("ARG"+a);a++)this.removeInput("ARG"+a);(a=this.getInput("TOPROW"))&&(this.arguments_.length?this.getField("WITH")||a.appendField($.Msg$$module$build$src$core$msg.PROCEDURES_CALL_BEFORE_PARAMS,"WITH"):this.getField("WITH")&&a.removeField("WITH"))},mutationToDom:function(){const a=$.createElement$$module$build$src$core$utils$xml("mutation");
|
||||
a.setAttribute("name",this.getProcedureCall());for(let b=0;b<this.arguments_.length;b++){const c=$.createElement$$module$build$src$core$utils$xml("arg");c.setAttribute("name",this.arguments_[b]);a.appendChild(c)}return a},domToMutation:function(a){var b=a.getAttribute("name");this.renameProcedure(this.getProcedureCall(),b);b=[];const c=[];for(let d=0,e;e=a.childNodes[d];d++)"arg"===e.nodeName.toLowerCase()&&(b.push(e.getAttribute("name")),c.push(e.getAttribute("paramId")));this.setProcedureParameters_(b,
|
||||
c)},saveExtraState:function(){const a=Object.create(null);a.name=this.getProcedureCall();this.arguments_.length&&(a.params=this.arguments_);return a},loadExtraState:function(a){this.renameProcedure(this.getProcedureCall(),a.name);if(a=a.params){const b=[];b.length=a.length;b.fill(null);this.setProcedureParameters_(a,b)}},getVars:function(){return this.arguments_},getVarModels:function(){return this.argumentVarModels_},onchange:function(a){if(this.workspace&&!this.workspace.isFlyout&&a.recordUndo)if(a.type===
|
||||
$.CREATE$$module$build$src$core$events$utils&&a.ids.includes(this.id)){var b=this.getProcedureCall();b=$.getDefinition$$module$build$src$core$procedures(b,this.workspace);!b||b.type===this.defType_&&JSON.stringify(b.getVars())===JSON.stringify(this.arguments_)||(b=null);if(!b){$.setGroup$$module$build$src$core$events$utils(a.group);a=$.createElement$$module$build$src$core$utils$xml("xml");b=$.createElement$$module$build$src$core$utils$xml("block");b.setAttribute("type",this.defType_);var c=this.getRelativeToSurfaceXY(),
|
||||
d=c.y+2*$.config$$module$build$src$core$config.snapRadius;b.setAttribute("x",`${c.x+$.config$$module$build$src$core$config.snapRadius*(this.RTL?-1:1)}`);b.setAttribute("y",`${d}`);c=this.mutationToDom();b.appendChild(c);c=$.createElement$$module$build$src$core$utils$xml("field");c.setAttribute("name","NAME");d=this.getProcedureCall();const e=$.findLegalName$$module$build$src$core$procedures(d,this);d!==e&&this.renameProcedure(d,e);c.appendChild($.createTextNode$$module$build$src$core$utils$xml(d));
|
||||
b.appendChild(c);a.appendChild(b);$.domToWorkspace$$module$build$src$core$xml(a,this.workspace);$.setGroup$$module$build$src$core$events$utils(!1)}}else a.type===$.DELETE$$module$build$src$core$events$utils?(b=this.getProcedureCall(),$.getDefinition$$module$build$src$core$procedures(b,this.workspace)||($.setGroup$$module$build$src$core$events$utils(a.group),this.dispose(!0),$.setGroup$$module$build$src$core$events$utils(!1))):a.type===$.CHANGE$$module$build$src$core$events$utils&&"disabled"===a.element&&
|
||||
(b=this.getProcedureCall(),(d=$.getDefinition$$module$build$src$core$procedures(b,this.workspace))&&d.id===a.blockId&&((c=$.getGroup$$module$build$src$core$events$utils())&&console.log("Saw an existing group while responding to a definition change"),$.setGroup$$module$build$src$core$events$utils(a.group),a=d.isEnabled(),this.setDisabledReason(!a,DISABLED_PROCEDURE_DEFINITION_DISABLED_REASON$$module$build$src$blocks$procedures),this.setWarningText(a?null:$.Msg$$module$build$src$core$msg.PROCEDURES_CALL_DISABLED_DEF_WARNING.replace("%1",
|
||||
b)),$.setGroup$$module$build$src$core$events$utils(c)))},customContextMenu:function(a){if(this.workspace.isMovable()){var b=this.getProcedureCall(),c=this.workspace;a.push({enabled:!0,text:$.Msg$$module$build$src$core$msg.PROCEDURES_HIGHLIGHT_DEF,callback:function(){const d=$.getDefinition$$module$build$src$core$procedures(b,c);d&&(c.centerOnBlock(d.id),$.setSelected$$module$build$src$core$common(d))}})}}};
|
||||
blocks$$module$build$src$blocks$procedures.procedures_callnoreturn=Object.assign({},PROCEDURE_CALL_COMMON$$module$build$src$blocks$procedures,{init:function(){this.appendDummyInput("TOPROW").appendField("","NAME");this.setPreviousStatement(!0);this.setNextStatement(!0);this.setStyle("procedure_blocks");this.setHelpUrl($.Msg$$module$build$src$core$msg.PROCEDURES_CALLNORETURN_HELPURL);this.arguments_=[];this.argumentVarModels_=[];this.quarkConnections_={};this.quarkIds_=null},defType_:"procedures_defnoreturn"});
|
||||
blocks$$module$build$src$blocks$procedures.procedures_callreturn=Object.assign({},PROCEDURE_CALL_COMMON$$module$build$src$blocks$procedures,{init:function(){this.appendDummyInput("TOPROW").appendField("","NAME");this.setOutput(!0);this.setStyle("procedure_blocks");this.setHelpUrl($.Msg$$module$build$src$core$msg.PROCEDURES_CALLRETURN_HELPURL);this.arguments_=[];this.argumentVarModels_=[];this.quarkConnections_={};this.quarkIds_=null},defType_:"procedures_defreturn"});
|
||||
var UNPARENTED_IFRETURN_DISABLED_REASON$$module$build$src$blocks$procedures="UNPARENTED_IFRETURN",PROCEDURES_IFRETURN$$module$build$src$blocks$procedures={init:function(){this.appendValueInput("CONDITION").setCheck("Boolean").appendField($.Msg$$module$build$src$core$msg.CONTROLS_IF_MSG_IF);this.appendValueInput("VALUE").appendField($.Msg$$module$build$src$core$msg.PROCEDURES_DEFRETURN_RETURN);this.setInputsInline(!0);this.setPreviousStatement(!0);this.setNextStatement(!0);this.setStyle("procedure_blocks");
|
||||
this.setTooltip($.Msg$$module$build$src$core$msg.PROCEDURES_IFRETURN_TOOLTIP);this.setHelpUrl($.Msg$$module$build$src$core$msg.PROCEDURES_IFRETURN_HELPURL);this.hasReturnValue_=!0},mutationToDom:function(){const a=$.createElement$$module$build$src$core$utils$xml("mutation");a.setAttribute("value",String(Number(this.hasReturnValue_)));return a},domToMutation:function(a){this.hasReturnValue_="1"===a.getAttribute("value");this.hasReturnValue_||(this.removeInput("VALUE"),this.appendDummyInput("VALUE").appendField($.Msg$$module$build$src$core$msg.PROCEDURES_DEFRETURN_RETURN))},
|
||||
onchange:function(a){if(!(this.workspace.isDragging&&this.workspace.isDragging()||a.type!==$.MOVE$$module$build$src$core$events$utils&&a.type!==$.CREATE$$module$build$src$core$events$utils)){a=!1;var b=this;do{if(this.FUNCTION_TYPES.includes(b.type)){a=!0;break}b=b.getSurroundParent()}while(b);a?("procedures_defnoreturn"===b.type&&this.hasReturnValue_?(this.removeInput("VALUE"),this.appendDummyInput("VALUE").appendField($.Msg$$module$build$src$core$msg.PROCEDURES_DEFRETURN_RETURN),this.hasReturnValue_=
|
||||
!1):"procedures_defreturn"!==b.type||this.hasReturnValue_||(this.removeInput("VALUE"),this.appendValueInput("VALUE").appendField($.Msg$$module$build$src$core$msg.PROCEDURES_DEFRETURN_RETURN),this.hasReturnValue_=!0),this.setWarningText(null)):this.setWarningText($.Msg$$module$build$src$core$msg.PROCEDURES_IFRETURN_WARNING);if(!this.isInFlyout)try{$.setRecordUndo$$module$build$src$core$events$utils(!1),this.setDisabledReason(!a,UNPARENTED_IFRETURN_DISABLED_REASON$$module$build$src$blocks$procedures)}finally{$.setRecordUndo$$module$build$src$core$events$utils(!0)}}},
|
||||
FUNCTION_TYPES:["procedures_defnoreturn","procedures_defreturn"]};blocks$$module$build$src$blocks$procedures.procedures_ifreturn=PROCEDURES_IFRETURN$$module$build$src$blocks$procedures;$.defineBlocks$$module$build$src$core$common(blocks$$module$build$src$blocks$procedures);var module$build$src$blocks$procedures={blocks:blocks$$module$build$src$blocks$procedures};var blocks$$module$build$src$blocks$math=$.createBlockDefinitionsFromJsonArray$$module$build$src$core$common([{type:"math_number",message0:"%1",args0:[{type:"field_number",name:"NUM",value:0}],output:"Number",helpUrl:"%{BKY_MATH_NUMBER_HELPURL}",style:"math_blocks",tooltip:"%{BKY_MATH_NUMBER_TOOLTIP}",extensions:["parent_tooltip_when_inline"]},{type:"math_arithmetic",message0:"%1 %2 %3",args0:[{type:"input_value",name:"A",check:"Number"},{type:"field_dropdown",name:"OP",options:[["%{BKY_MATH_ADDITION_SYMBOL}",
|
||||
"ADD"],["%{BKY_MATH_SUBTRACTION_SYMBOL}","MINUS"],["%{BKY_MATH_MULTIPLICATION_SYMBOL}","MULTIPLY"],["%{BKY_MATH_DIVISION_SYMBOL}","DIVIDE"],["%{BKY_MATH_POWER_SYMBOL}","POWER"]]},{type:"input_value",name:"B",check:"Number"}],inputsInline:!0,output:"Number",style:"math_blocks",helpUrl:"%{BKY_MATH_ARITHMETIC_HELPURL}",extensions:["math_op_tooltip"]},{type:"math_single",message0:"%1 %2",args0:[{type:"field_dropdown",name:"OP",options:[["%{BKY_MATH_SINGLE_OP_ROOT}","ROOT"],["%{BKY_MATH_SINGLE_OP_ABSOLUTE}",
|
||||
"ABS"],["-","NEG"],["ln","LN"],["log10","LOG10"],["e^","EXP"],["10^","POW10"]]},{type:"input_value",name:"NUM",check:"Number"}],output:"Number",style:"math_blocks",helpUrl:"%{BKY_MATH_SINGLE_HELPURL}",extensions:["math_op_tooltip"]},{type:"math_trig",message0:"%1 %2",args0:[{type:"field_dropdown",name:"OP",options:[["%{BKY_MATH_TRIG_SIN}","SIN"],["%{BKY_MATH_TRIG_COS}","COS"],["%{BKY_MATH_TRIG_TAN}","TAN"],["%{BKY_MATH_TRIG_ASIN}","ASIN"],["%{BKY_MATH_TRIG_ACOS}","ACOS"],["%{BKY_MATH_TRIG_ATAN}",
|
||||
"ATAN"]]},{type:"input_value",name:"NUM",check:"Number"}],output:"Number",style:"math_blocks",helpUrl:"%{BKY_MATH_TRIG_HELPURL}",extensions:["math_op_tooltip"]},{type:"math_constant",message0:"%1",args0:[{type:"field_dropdown",name:"CONSTANT",options:[["\u03c0","PI"],["e","E"],["\u03c6","GOLDEN_RATIO"],["sqrt(2)","SQRT2"],["sqrt(\u00bd)","SQRT1_2"],["\u221e","INFINITY"]]}],output:"Number",style:"math_blocks",tooltip:"%{BKY_MATH_CONSTANT_TOOLTIP}",helpUrl:"%{BKY_MATH_CONSTANT_HELPURL}"},{type:"math_number_property",
|
||||
message0:"%1 %2",args0:[{type:"input_value",name:"NUMBER_TO_CHECK",check:"Number"},{type:"field_dropdown",name:"PROPERTY",options:[["%{BKY_MATH_IS_EVEN}","EVEN"],["%{BKY_MATH_IS_ODD}","ODD"],["%{BKY_MATH_IS_PRIME}","PRIME"],["%{BKY_MATH_IS_WHOLE}","WHOLE"],["%{BKY_MATH_IS_POSITIVE}","POSITIVE"],["%{BKY_MATH_IS_NEGATIVE}","NEGATIVE"],["%{BKY_MATH_IS_DIVISIBLE_BY}","DIVISIBLE_BY"]]}],inputsInline:!0,output:"Boolean",style:"math_blocks",tooltip:"%{BKY_MATH_IS_TOOLTIP}",mutator:"math_is_divisibleby_mutator"},
|
||||
{type:"math_change",message0:"%{BKY_MATH_CHANGE_TITLE}",args0:[{type:"field_variable",name:"VAR",variable:"%{BKY_MATH_CHANGE_TITLE_ITEM}"},{type:"input_value",name:"DELTA",check:"Number"}],previousStatement:null,nextStatement:null,style:"variable_blocks",helpUrl:"%{BKY_MATH_CHANGE_HELPURL}",extensions:["math_change_tooltip"]},{type:"math_round",message0:"%1 %2",args0:[{type:"field_dropdown",name:"OP",options:[["%{BKY_MATH_ROUND_OPERATOR_ROUND}","ROUND"],["%{BKY_MATH_ROUND_OPERATOR_ROUNDUP}","ROUNDUP"],
|
||||
["%{BKY_MATH_ROUND_OPERATOR_ROUNDDOWN}","ROUNDDOWN"]]},{type:"input_value",name:"NUM",check:"Number"}],output:"Number",style:"math_blocks",helpUrl:"%{BKY_MATH_ROUND_HELPURL}",tooltip:"%{BKY_MATH_ROUND_TOOLTIP}"},{type:"math_on_list",message0:"%1 %2",args0:[{type:"field_dropdown",name:"OP",options:[["%{BKY_MATH_ONLIST_OPERATOR_SUM}","SUM"],["%{BKY_MATH_ONLIST_OPERATOR_MIN}","MIN"],["%{BKY_MATH_ONLIST_OPERATOR_MAX}","MAX"],["%{BKY_MATH_ONLIST_OPERATOR_AVERAGE}","AVERAGE"],["%{BKY_MATH_ONLIST_OPERATOR_MEDIAN}",
|
||||
"MEDIAN"],["%{BKY_MATH_ONLIST_OPERATOR_MODE}","MODE"],["%{BKY_MATH_ONLIST_OPERATOR_STD_DEV}","STD_DEV"],["%{BKY_MATH_ONLIST_OPERATOR_RANDOM}","RANDOM"]]},{type:"input_value",name:"LIST",check:"Array"}],output:"Number",style:"math_blocks",helpUrl:"%{BKY_MATH_ONLIST_HELPURL}",mutator:"math_modes_of_list_mutator",extensions:["math_op_tooltip"]},{type:"math_modulo",message0:"%{BKY_MATH_MODULO_TITLE}",args0:[{type:"input_value",name:"DIVIDEND",check:"Number"},{type:"input_value",name:"DIVISOR",check:"Number"}],
|
||||
inputsInline:!0,output:"Number",style:"math_blocks",tooltip:"%{BKY_MATH_MODULO_TOOLTIP}",helpUrl:"%{BKY_MATH_MODULO_HELPURL}"},{type:"math_constrain",message0:"%{BKY_MATH_CONSTRAIN_TITLE}",args0:[{type:"input_value",name:"VALUE",check:"Number"},{type:"input_value",name:"LOW",check:"Number"},{type:"input_value",name:"HIGH",check:"Number"}],inputsInline:!0,output:"Number",style:"math_blocks",tooltip:"%{BKY_MATH_CONSTRAIN_TOOLTIP}",helpUrl:"%{BKY_MATH_CONSTRAIN_HELPURL}"},{type:"math_random_int",message0:"%{BKY_MATH_RANDOM_INT_TITLE}",
|
||||
args0:[{type:"input_value",name:"FROM",check:"Number"},{type:"input_value",name:"TO",check:"Number"}],inputsInline:!0,output:"Number",style:"math_blocks",tooltip:"%{BKY_MATH_RANDOM_INT_TOOLTIP}",helpUrl:"%{BKY_MATH_RANDOM_INT_HELPURL}"},{type:"math_random_float",message0:"%{BKY_MATH_RANDOM_FLOAT_TITLE_RANDOM}",output:"Number",style:"math_blocks",tooltip:"%{BKY_MATH_RANDOM_FLOAT_TOOLTIP}",helpUrl:"%{BKY_MATH_RANDOM_FLOAT_HELPURL}"},{type:"math_atan2",message0:"%{BKY_MATH_ATAN2_TITLE}",args0:[{type:"input_value",
|
||||
name:"X",check:"Number"},{type:"input_value",name:"Y",check:"Number"}],inputsInline:!0,output:"Number",style:"math_blocks",tooltip:"%{BKY_MATH_ATAN2_TOOLTIP}",helpUrl:"%{BKY_MATH_ATAN2_HELPURL}"}]),TOOLTIPS_BY_OP$$module$build$src$blocks$math={ADD:"%{BKY_MATH_ARITHMETIC_TOOLTIP_ADD}",MINUS:"%{BKY_MATH_ARITHMETIC_TOOLTIP_MINUS}",MULTIPLY:"%{BKY_MATH_ARITHMETIC_TOOLTIP_MULTIPLY}",DIVIDE:"%{BKY_MATH_ARITHMETIC_TOOLTIP_DIVIDE}",POWER:"%{BKY_MATH_ARITHMETIC_TOOLTIP_POWER}",ROOT:"%{BKY_MATH_SINGLE_TOOLTIP_ROOT}",
|
||||
ABS:"%{BKY_MATH_SINGLE_TOOLTIP_ABS}",NEG:"%{BKY_MATH_SINGLE_TOOLTIP_NEG}",LN:"%{BKY_MATH_SINGLE_TOOLTIP_LN}",LOG10:"%{BKY_MATH_SINGLE_TOOLTIP_LOG10}",EXP:"%{BKY_MATH_SINGLE_TOOLTIP_EXP}",POW10:"%{BKY_MATH_SINGLE_TOOLTIP_POW10}",SIN:"%{BKY_MATH_TRIG_TOOLTIP_SIN}",COS:"%{BKY_MATH_TRIG_TOOLTIP_COS}",TAN:"%{BKY_MATH_TRIG_TOOLTIP_TAN}",ASIN:"%{BKY_MATH_TRIG_TOOLTIP_ASIN}",ACOS:"%{BKY_MATH_TRIG_TOOLTIP_ACOS}",ATAN:"%{BKY_MATH_TRIG_TOOLTIP_ATAN}",SUM:"%{BKY_MATH_ONLIST_TOOLTIP_SUM}",MIN:"%{BKY_MATH_ONLIST_TOOLTIP_MIN}",
|
||||
MAX:"%{BKY_MATH_ONLIST_TOOLTIP_MAX}",AVERAGE:"%{BKY_MATH_ONLIST_TOOLTIP_AVERAGE}",MEDIAN:"%{BKY_MATH_ONLIST_TOOLTIP_MEDIAN}",MODE:"%{BKY_MATH_ONLIST_TOOLTIP_MODE}",STD_DEV:"%{BKY_MATH_ONLIST_TOOLTIP_STD_DEV}",RANDOM:"%{BKY_MATH_ONLIST_TOOLTIP_RANDOM}"};$.register$$module$build$src$core$extensions("math_op_tooltip",$.buildTooltipForDropdown$$module$build$src$core$extensions("OP",TOOLTIPS_BY_OP$$module$build$src$blocks$math));
|
||||
var IS_DIVISIBLEBY_MUTATOR_MIXIN$$module$build$src$blocks$math={mutationToDom:function(){const a=$.createElement$$module$build$src$core$utils$xml("mutation"),b="DIVISIBLE_BY"===this.getFieldValue("PROPERTY");a.setAttribute("divisor_input",String(b));return a},domToMutation:function(a){a="true"===a.getAttribute("divisor_input");this.updateShape_(a)},updateShape_:function(a){const b=this.getInput("DIVISOR");a?b||this.appendValueInput("DIVISOR").setCheck("Number"):b&&this.removeInput("DIVISOR")}},IS_DIVISIBLE_MUTATOR_EXTENSION$$module$build$src$blocks$math=
|
||||
function(){this.getField("PROPERTY").setValidator(function(a){a="DIVISIBLE_BY"===a;this.getSourceBlock().updateShape_(a)})};$.registerMutator$$module$build$src$core$extensions("math_is_divisibleby_mutator",IS_DIVISIBLEBY_MUTATOR_MIXIN$$module$build$src$blocks$math,IS_DIVISIBLE_MUTATOR_EXTENSION$$module$build$src$blocks$math);$.register$$module$build$src$core$extensions("math_change_tooltip",$.buildTooltipWithFieldText$$module$build$src$core$extensions("%{BKY_MATH_CHANGE_TOOLTIP}","VAR"));
|
||||
var LIST_MODES_MUTATOR_MIXIN$$module$build$src$blocks$math={updateType_:function(a){"MODE"===a?this.outputConnection.setCheck("Array"):this.outputConnection.setCheck("Number")},mutationToDom:function(){const a=$.createElement$$module$build$src$core$utils$xml("mutation");a.setAttribute("op",this.getFieldValue("OP"));return a},domToMutation:function(a){a=a.getAttribute("op");if(null===a)throw new TypeError("xmlElement had no op attribute");this.updateType_(a)}},LIST_MODES_MUTATOR_EXTENSION$$module$build$src$blocks$math=
|
||||
function(){this.getField("OP").setValidator(function(a){this.updateType_(a)}.bind(this))};$.registerMutator$$module$build$src$core$extensions("math_modes_of_list_mutator",LIST_MODES_MUTATOR_MIXIN$$module$build$src$blocks$math,LIST_MODES_MUTATOR_EXTENSION$$module$build$src$blocks$math);$.defineBlocks$$module$build$src$core$common(blocks$$module$build$src$blocks$math);var module$build$src$blocks$math={blocks:blocks$$module$build$src$blocks$math};var blocks$$module$build$src$blocks$loops=$.createBlockDefinitionsFromJsonArray$$module$build$src$core$common([{type:"controls_repeat_ext",message0:"%{BKY_CONTROLS_REPEAT_TITLE}",args0:[{type:"input_value",name:"TIMES",check:"Number"}],message1:"%{BKY_CONTROLS_REPEAT_INPUT_DO} %1",args1:[{type:"input_statement",name:"DO"}],previousStatement:null,nextStatement:null,style:"loop_blocks",tooltip:"%{BKY_CONTROLS_REPEAT_TOOLTIP}",helpUrl:"%{BKY_CONTROLS_REPEAT_HELPURL}"},{type:"controls_repeat",message0:"%{BKY_CONTROLS_REPEAT_TITLE}",
|
||||
args0:[{type:"field_number",name:"TIMES",value:10,min:0,precision:1}],message1:"%{BKY_CONTROLS_REPEAT_INPUT_DO} %1",args1:[{type:"input_statement",name:"DO"}],previousStatement:null,nextStatement:null,style:"loop_blocks",tooltip:"%{BKY_CONTROLS_REPEAT_TOOLTIP}",helpUrl:"%{BKY_CONTROLS_REPEAT_HELPURL}"},{type:"controls_whileUntil",message0:"%1 %2",args0:[{type:"field_dropdown",name:"MODE",options:[["%{BKY_CONTROLS_WHILEUNTIL_OPERATOR_WHILE}","WHILE"],["%{BKY_CONTROLS_WHILEUNTIL_OPERATOR_UNTIL}","UNTIL"]]},
|
||||
{type:"input_value",name:"BOOL",check:"Boolean"}],message1:"%{BKY_CONTROLS_REPEAT_INPUT_DO} %1",args1:[{type:"input_statement",name:"DO"}],previousStatement:null,nextStatement:null,style:"loop_blocks",helpUrl:"%{BKY_CONTROLS_WHILEUNTIL_HELPURL}",extensions:["controls_whileUntil_tooltip"]},{type:"controls_for",message0:"%{BKY_CONTROLS_FOR_TITLE}",args0:[{type:"field_variable",name:"VAR",variable:null},{type:"input_value",name:"FROM",check:"Number",align:"RIGHT"},{type:"input_value",name:"TO",check:"Number",
|
||||
align:"RIGHT"},{type:"input_value",name:"BY",check:"Number",align:"RIGHT"}],message1:"%{BKY_CONTROLS_REPEAT_INPUT_DO} %1",args1:[{type:"input_statement",name:"DO"}],inputsInline:!0,previousStatement:null,nextStatement:null,style:"loop_blocks",helpUrl:"%{BKY_CONTROLS_FOR_HELPURL}",extensions:["contextMenu_newGetVariableBlock","controls_for_tooltip"]},{type:"controls_forEach",message0:"%{BKY_CONTROLS_FOREACH_TITLE}",args0:[{type:"field_variable",name:"VAR",variable:null},{type:"input_value",name:"LIST",
|
||||
check:"Array"}],message1:"%{BKY_CONTROLS_REPEAT_INPUT_DO} %1",args1:[{type:"input_statement",name:"DO"}],previousStatement:null,nextStatement:null,style:"loop_blocks",helpUrl:"%{BKY_CONTROLS_FOREACH_HELPURL}",extensions:["contextMenu_newGetVariableBlock","controls_forEach_tooltip"]},{type:"controls_flow_statements",message0:"%1",args0:[{type:"field_dropdown",name:"FLOW",options:[["%{BKY_CONTROLS_FLOW_STATEMENTS_OPERATOR_BREAK}","BREAK"],["%{BKY_CONTROLS_FLOW_STATEMENTS_OPERATOR_CONTINUE}","CONTINUE"]]}],
|
||||
previousStatement:null,style:"loop_blocks",helpUrl:"%{BKY_CONTROLS_FLOW_STATEMENTS_HELPURL}",suppressPrefixSuffix:!0,extensions:["controls_flow_tooltip","controls_flow_in_loop_check"]}]),WHILE_UNTIL_TOOLTIPS$$module$build$src$blocks$loops={WHILE:"%{BKY_CONTROLS_WHILEUNTIL_TOOLTIP_WHILE}",UNTIL:"%{BKY_CONTROLS_WHILEUNTIL_TOOLTIP_UNTIL}"};$.register$$module$build$src$core$extensions("controls_whileUntil_tooltip",$.buildTooltipForDropdown$$module$build$src$core$extensions("MODE",WHILE_UNTIL_TOOLTIPS$$module$build$src$blocks$loops));
|
||||
var BREAK_CONTINUE_TOOLTIPS$$module$build$src$blocks$loops={BREAK:"%{BKY_CONTROLS_FLOW_STATEMENTS_TOOLTIP_BREAK}",CONTINUE:"%{BKY_CONTROLS_FLOW_STATEMENTS_TOOLTIP_CONTINUE}"};$.register$$module$build$src$core$extensions("controls_flow_tooltip",$.buildTooltipForDropdown$$module$build$src$core$extensions("FLOW",BREAK_CONTINUE_TOOLTIPS$$module$build$src$blocks$loops));
|
||||
var CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN$$module$build$src$blocks$loops={customContextMenu:function(a){if(!this.isInFlyout){var b=this.getField("VAR"),c=b.getVariable().name;this.isCollapsed()||null===c||(b={type:"variables_get",fields:{VAR:b.saveState(!0)}},a.push({enabled:!0,text:$.Msg$$module$build$src$core$msg.VARIABLES_SET_CREATE_GET.replace("%1",c),callback:$.callbackFactory$$module$build$src$core$contextmenu(this,b)}))}}};
|
||||
$.registerMixin$$module$build$src$core$extensions("contextMenu_newGetVariableBlock",CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN$$module$build$src$blocks$loops);$.register$$module$build$src$core$extensions("controls_for_tooltip",$.buildTooltipWithFieldText$$module$build$src$core$extensions("%{BKY_CONTROLS_FOR_TOOLTIP}","VAR"));$.register$$module$build$src$core$extensions("controls_forEach_tooltip",$.buildTooltipWithFieldText$$module$build$src$core$extensions("%{BKY_CONTROLS_FOREACH_TOOLTIP}","VAR"));
|
||||
var loopTypes$$module$build$src$blocks$loops=new Set(["controls_repeat","controls_repeat_ext","controls_forEach","controls_for","controls_whileUntil"]),CONTROL_FLOW_NOT_IN_LOOP_DISABLED_REASON$$module$build$src$blocks$loops="CONTROL_FLOW_NOT_IN_LOOP",CONTROL_FLOW_IN_LOOP_CHECK_MIXIN$$module$build$src$blocks$loops={getSurroundLoop:function(){let a=this;do{if(loopTypes$$module$build$src$blocks$loops.has(a.type))return a;a=a.getSurroundParent()}while(a);return null},onchange:function(a){const b=this.workspace;
|
||||
if(b.isDragging&&!b.isDragging()&&(a.type===$.MOVE$$module$build$src$core$events$utils||a.type===$.CREATE$$module$build$src$core$events$utils)&&(a=!!this.getSurroundLoop(),this.setWarningText(a?null:$.Msg$$module$build$src$core$msg.CONTROLS_FLOW_STATEMENTS_WARNING),!this.isInFlyout))try{$.setRecordUndo$$module$build$src$core$events$utils(!1),this.setDisabledReason(!a,CONTROL_FLOW_NOT_IN_LOOP_DISABLED_REASON$$module$build$src$blocks$loops)}finally{$.setRecordUndo$$module$build$src$core$events$utils(!0)}}};
|
||||
$.registerMixin$$module$build$src$core$extensions("controls_flow_in_loop_check",CONTROL_FLOW_IN_LOOP_CHECK_MIXIN$$module$build$src$blocks$loops);$.defineBlocks$$module$build$src$core$common(blocks$$module$build$src$blocks$loops);var module$build$src$blocks$loops={blocks:blocks$$module$build$src$blocks$loops,loopTypes:loopTypes$$module$build$src$blocks$loops};var blocks$$module$build$src$blocks$logic=$.createBlockDefinitionsFromJsonArray$$module$build$src$core$common([{type:"logic_boolean",message0:"%1",args0:[{type:"field_dropdown",name:"BOOL",options:[["%{BKY_LOGIC_BOOLEAN_TRUE}","TRUE"],["%{BKY_LOGIC_BOOLEAN_FALSE}","FALSE"]]}],output:"Boolean",style:"logic_blocks",tooltip:"%{BKY_LOGIC_BOOLEAN_TOOLTIP}",helpUrl:"%{BKY_LOGIC_BOOLEAN_HELPURL}"},{type:"controls_if",message0:"%{BKY_CONTROLS_IF_MSG_IF} %1",args0:[{type:"input_value",name:"IF0",check:"Boolean"}],
|
||||
message1:"%{BKY_CONTROLS_IF_MSG_THEN} %1",args1:[{type:"input_statement",name:"DO0"}],previousStatement:null,nextStatement:null,style:"logic_blocks",helpUrl:"%{BKY_CONTROLS_IF_HELPURL}",suppressPrefixSuffix:!0,mutator:"controls_if_mutator",extensions:["controls_if_tooltip"]},{type:"controls_ifelse",message0:"%{BKY_CONTROLS_IF_MSG_IF} %1",args0:[{type:"input_value",name:"IF0",check:"Boolean"}],message1:"%{BKY_CONTROLS_IF_MSG_THEN} %1",args1:[{type:"input_statement",name:"DO0"}],message2:"%{BKY_CONTROLS_IF_MSG_ELSE} %1",
|
||||
args2:[{type:"input_statement",name:"ELSE"}],previousStatement:null,nextStatement:null,style:"logic_blocks",tooltip:"%{BKYCONTROLS_IF_TOOLTIP_2}",helpUrl:"%{BKY_CONTROLS_IF_HELPURL}",suppressPrefixSuffix:!0,extensions:["controls_if_tooltip"]},{type:"logic_compare",message0:"%1 %2 %3",args0:[{type:"input_value",name:"A"},{type:"field_dropdown",name:"OP",options:[["=","EQ"],["\u2260","NEQ"],["\u200f<","LT"],["\u200f\u2264","LTE"],["\u200f>","GT"],["\u200f\u2265","GTE"]]},{type:"input_value",name:"B"}],
|
||||
inputsInline:!0,output:"Boolean",style:"logic_blocks",helpUrl:"%{BKY_LOGIC_COMPARE_HELPURL}",extensions:["logic_compare","logic_op_tooltip"]},{type:"logic_operation",message0:"%1 %2 %3",args0:[{type:"input_value",name:"A",check:"Boolean"},{type:"field_dropdown",name:"OP",options:[["%{BKY_LOGIC_OPERATION_AND}","AND"],["%{BKY_LOGIC_OPERATION_OR}","OR"]]},{type:"input_value",name:"B",check:"Boolean"}],inputsInline:!0,output:"Boolean",style:"logic_blocks",helpUrl:"%{BKY_LOGIC_OPERATION_HELPURL}",extensions:["logic_op_tooltip"]},
|
||||
{type:"logic_negate",message0:"%{BKY_LOGIC_NEGATE_TITLE}",args0:[{type:"input_value",name:"BOOL",check:"Boolean"}],output:"Boolean",style:"logic_blocks",tooltip:"%{BKY_LOGIC_NEGATE_TOOLTIP}",helpUrl:"%{BKY_LOGIC_NEGATE_HELPURL}"},{type:"logic_null",message0:"%{BKY_LOGIC_NULL}",output:null,style:"logic_blocks",tooltip:"%{BKY_LOGIC_NULL_TOOLTIP}",helpUrl:"%{BKY_LOGIC_NULL_HELPURL}"},{type:"logic_ternary",message0:"%{BKY_LOGIC_TERNARY_CONDITION} %1",args0:[{type:"input_value",name:"IF",check:"Boolean"}],
|
||||
message1:"%{BKY_LOGIC_TERNARY_IF_TRUE} %1",args1:[{type:"input_value",name:"THEN"}],message2:"%{BKY_LOGIC_TERNARY_IF_FALSE} %1",args2:[{type:"input_value",name:"ELSE"}],output:null,style:"logic_blocks",tooltip:"%{BKY_LOGIC_TERNARY_TOOLTIP}",helpUrl:"%{BKY_LOGIC_TERNARY_HELPURL}",extensions:["logic_ternary"]},{type:"controls_if_if",message0:"%{BKY_CONTROLS_IF_IF_TITLE_IF}",nextStatement:null,enableContextMenu:!1,style:"logic_blocks",tooltip:"%{BKY_CONTROLS_IF_IF_TOOLTIP}"},{type:"controls_if_elseif",
|
||||
message0:"%{BKY_CONTROLS_IF_ELSEIF_TITLE_ELSEIF}",previousStatement:null,nextStatement:null,enableContextMenu:!1,style:"logic_blocks",tooltip:"%{BKY_CONTROLS_IF_ELSEIF_TOOLTIP}"},{type:"controls_if_else",message0:"%{BKY_CONTROLS_IF_ELSE_TITLE_ELSE}",previousStatement:null,enableContextMenu:!1,style:"logic_blocks",tooltip:"%{BKY_CONTROLS_IF_ELSE_TOOLTIP}"}]),TOOLTIPS_BY_OP$$module$build$src$blocks$logic={EQ:"%{BKY_LOGIC_COMPARE_TOOLTIP_EQ}",NEQ:"%{BKY_LOGIC_COMPARE_TOOLTIP_NEQ}",LT:"%{BKY_LOGIC_COMPARE_TOOLTIP_LT}",
|
||||
LTE:"%{BKY_LOGIC_COMPARE_TOOLTIP_LTE}",GT:"%{BKY_LOGIC_COMPARE_TOOLTIP_GT}",GTE:"%{BKY_LOGIC_COMPARE_TOOLTIP_GTE}",AND:"%{BKY_LOGIC_OPERATION_TOOLTIP_AND}",OR:"%{BKY_LOGIC_OPERATION_TOOLTIP_OR}"};$.register$$module$build$src$core$extensions("logic_op_tooltip",$.buildTooltipForDropdown$$module$build$src$core$extensions("OP",TOOLTIPS_BY_OP$$module$build$src$blocks$logic));
|
||||
var CONTROLS_IF_MUTATOR_MIXIN$$module$build$src$blocks$logic={elseifCount_:0,elseCount_:0,mutationToDom:function(){if(!this.elseifCount_&&!this.elseCount_)return null;const a=$.createElement$$module$build$src$core$utils$xml("mutation");this.elseifCount_&&a.setAttribute("elseif",String(this.elseifCount_));this.elseCount_&&a.setAttribute("else","1");return a},domToMutation:function(a){this.elseifCount_=parseInt(a.getAttribute("elseif"),10)||0;this.elseCount_=parseInt(a.getAttribute("else"),10)||0;this.rebuildShape_()},
|
||||
saveExtraState:function(){if(!this.elseifCount_&&!this.elseCount_)return null;const a=Object.create(null);this.elseifCount_&&(a.elseIfCount=this.elseifCount_);this.elseCount_&&(a.hasElse=!0);return a},loadExtraState:function(a){this.elseifCount_=a.elseIfCount||0;this.elseCount_=a.hasElse?1:0;this.updateShape_()},decompose:function(a){const b=a.newBlock("controls_if_if");b.initSvg();let c=b.nextConnection;for(let d=1;d<=this.elseifCount_;d++){const e=a.newBlock("controls_if_elseif");e.initSvg();c.connect(e.previousConnection);
|
||||
c=e.nextConnection}this.elseCount_&&(a=a.newBlock("controls_if_else"),a.initSvg(),c.connect(a.previousConnection));return b},compose:function(a){a=a.nextConnection.targetBlock();this.elseCount_=this.elseifCount_=0;const b=[null],c=[null];let d=null;for(;a;){if(!a.isInsertionMarker())switch(a.type){case "controls_if_elseif":this.elseifCount_++;b.push(a.valueConnection_);c.push(a.statementConnection_);break;case "controls_if_else":this.elseCount_++;d=a.statementConnection_;break;default:throw TypeError("Unknown block type: "+
|
||||
a.type);}a=a.getNextBlock()}this.updateShape_();this.reconnectChildBlocks_(b,c,d)},saveConnections:function(a){a=a.nextConnection.targetBlock();let b=1;for(;a;){if(!a.isInsertionMarker())switch(a.type){case "controls_if_elseif":var c=this.getInput("IF"+b);const d=this.getInput("DO"+b);a.valueConnection_=c&&c.connection.targetConnection;a.statementConnection_=d&&d.connection.targetConnection;b++;break;case "controls_if_else":c=this.getInput("ELSE");a.statementConnection_=c&&c.connection.targetConnection;
|
||||
break;default:throw TypeError("Unknown block type: "+a.type);}a=a.getNextBlock()}},rebuildShape_:function(){const a=[null],b=[null];let c=null;this.getInput("ELSE")&&(c=this.getInput("ELSE").connection.targetConnection);for(let d=1;this.getInput("IF"+d);d++){const e=this.getInput("IF"+d),f=this.getInput("DO"+d);a.push(e.connection.targetConnection);b.push(f.connection.targetConnection)}this.updateShape_();this.reconnectChildBlocks_(a,b,c)},updateShape_:function(){this.getInput("ELSE")&&this.removeInput("ELSE");
|
||||
for(var a=1;this.getInput("IF"+a);a++)this.removeInput("IF"+a),this.removeInput("DO"+a);for(a=1;a<=this.elseifCount_;a++)this.appendValueInput("IF"+a).setCheck("Boolean").appendField($.Msg$$module$build$src$core$msg.CONTROLS_IF_MSG_ELSEIF),this.appendStatementInput("DO"+a).appendField($.Msg$$module$build$src$core$msg.CONTROLS_IF_MSG_THEN);this.elseCount_&&this.appendStatementInput("ELSE").appendField($.Msg$$module$build$src$core$msg.CONTROLS_IF_MSG_ELSE)},reconnectChildBlocks_:function(a,b,c){for(let d=
|
||||
1;d<=this.elseifCount_;d++){let e;null==(e=a[d])||e.reconnect(this,"IF"+d);let f;null==(f=b[d])||f.reconnect(this,"DO"+d)}null==c||c.reconnect(this,"ELSE")}};$.registerMutator$$module$build$src$core$extensions("controls_if_mutator",CONTROLS_IF_MUTATOR_MIXIN$$module$build$src$blocks$logic,null,["controls_if_elseif","controls_if_else"]);
|
||||
var CONTROLS_IF_TOOLTIP_EXTENSION$$module$build$src$blocks$logic=function(){this.setTooltip(function(){if(this.elseifCount_||this.elseCount_){if(!this.elseifCount_&&this.elseCount_)return $.Msg$$module$build$src$core$msg.CONTROLS_IF_TOOLTIP_2;if(this.elseifCount_&&!this.elseCount_)return $.Msg$$module$build$src$core$msg.CONTROLS_IF_TOOLTIP_3;if(this.elseifCount_&&this.elseCount_)return $.Msg$$module$build$src$core$msg.CONTROLS_IF_TOOLTIP_4}else return $.Msg$$module$build$src$core$msg.CONTROLS_IF_TOOLTIP_1;
|
||||
return""}.bind(this))};$.register$$module$build$src$core$extensions("controls_if_tooltip",CONTROLS_IF_TOOLTIP_EXTENSION$$module$build$src$blocks$logic);
|
||||
var LOGIC_COMPARE_ONCHANGE_MIXIN$$module$build$src$blocks$logic={onchange:function(a){this.prevBlocks_||(this.prevBlocks_=[null,null]);var b=this.getInputTargetBlock("A");const c=this.getInputTargetBlock("B");b&&c&&!this.workspace.connectionChecker.doTypeChecks(b.outputConnection,c.outputConnection)&&($.setGroup$$module$build$src$core$events$utils(a.group),a=this.prevBlocks_[0],a!==b&&(b.unplug(),!a||a.isDisposed()||a.isShadow()||this.getInput("A").connection.connect(a.outputConnection)),b=this.prevBlocks_[1],
|
||||
b!==c&&(c.unplug(),!b||b.isDisposed()||b.isShadow()||this.getInput("B").connection.connect(b.outputConnection)),this.bumpNeighbours(),$.setGroup$$module$build$src$core$events$utils(!1));this.prevBlocks_[0]=this.getInputTargetBlock("A");this.prevBlocks_[1]=this.getInputTargetBlock("B")}},LOGIC_COMPARE_EXTENSION$$module$build$src$blocks$logic=function(){this.mixin(LOGIC_COMPARE_ONCHANGE_MIXIN$$module$build$src$blocks$logic)};$.register$$module$build$src$core$extensions("logic_compare",LOGIC_COMPARE_EXTENSION$$module$build$src$blocks$logic);
|
||||
var LOGIC_TERNARY_ONCHANGE_MIXIN$$module$build$src$blocks$logic={prevParentConnection_:null,onchange:function(a){const b=this.getInputTargetBlock("THEN"),c=this.getInputTargetBlock("ELSE"),d=this.outputConnection.targetConnection;if((b||c)&&d)for(let e=0;2>e;e++){const f=1===e?b:c;f&&!f.workspace.connectionChecker.doTypeChecks(f.outputConnection,d)&&($.setGroup$$module$build$src$core$events$utils(a.group),d===this.prevParentConnection_?(this.unplug(),d.getSourceBlock().bumpNeighbours()):(f.unplug(),
|
||||
f.bumpNeighbours()),$.setGroup$$module$build$src$core$events$utils(!1))}this.prevParentConnection_=d}};$.registerMixin$$module$build$src$core$extensions("logic_ternary",LOGIC_TERNARY_ONCHANGE_MIXIN$$module$build$src$blocks$logic);$.defineBlocks$$module$build$src$core$common(blocks$$module$build$src$blocks$logic);var module$build$src$blocks$logic={blocks:blocks$$module$build$src$blocks$logic};var blocks$$module$build$src$blocks$lists=$.createBlockDefinitionsFromJsonArray$$module$build$src$core$common([{type:"lists_create_empty",message0:"%{BKY_LISTS_CREATE_EMPTY_TITLE}",output:"Array",style:"list_blocks",tooltip:"%{BKY_LISTS_CREATE_EMPTY_TOOLTIP}",helpUrl:"%{BKY_LISTS_CREATE_EMPTY_HELPURL}"},{type:"lists_repeat",message0:"%{BKY_LISTS_REPEAT_TITLE}",args0:[{type:"input_value",name:"ITEM"},{type:"input_value",name:"NUM",check:"Number"}],output:"Array",style:"list_blocks",tooltip:"%{BKY_LISTS_REPEAT_TOOLTIP}",
|
||||
helpUrl:"%{BKY_LISTS_REPEAT_HELPURL}"},{type:"lists_reverse",message0:"%{BKY_LISTS_REVERSE_MESSAGE0}",args0:[{type:"input_value",name:"LIST",check:"Array"}],output:"Array",inputsInline:!0,style:"list_blocks",tooltip:"%{BKY_LISTS_REVERSE_TOOLTIP}",helpUrl:"%{BKY_LISTS_REVERSE_HELPURL}"},{type:"lists_isEmpty",message0:"%{BKY_LISTS_ISEMPTY_TITLE}",args0:[{type:"input_value",name:"VALUE",check:["String","Array"]}],output:"Boolean",style:"list_blocks",tooltip:"%{BKY_LISTS_ISEMPTY_TOOLTIP}",helpUrl:"%{BKY_LISTS_ISEMPTY_HELPURL}"},
|
||||
{type:"lists_length",message0:"%{BKY_LISTS_LENGTH_TITLE}",args0:[{type:"input_value",name:"VALUE",check:["String","Array"]}],output:"Number",style:"list_blocks",tooltip:"%{BKY_LISTS_LENGTH_TOOLTIP}",helpUrl:"%{BKY_LISTS_LENGTH_HELPURL}"}]),LISTS_CREATE_WITH$$module$build$src$blocks$lists={init:function(){this.setHelpUrl($.Msg$$module$build$src$core$msg.LISTS_CREATE_WITH_HELPURL);this.setStyle("list_blocks");this.itemCount_=3;this.updateShape_();this.setOutput(!0,"Array");this.setMutator(new $.MutatorIcon$$module$build$src$core$icons$mutator_icon(["lists_create_with_item"],
|
||||
this));this.setTooltip($.Msg$$module$build$src$core$msg.LISTS_CREATE_WITH_TOOLTIP)},mutationToDom:function(){const a=$.createElement$$module$build$src$core$utils$xml("mutation");a.setAttribute("items",String(this.itemCount_));return a},domToMutation:function(a){a=a.getAttribute("items");if(!a)throw new TypeError("element did not have items");this.itemCount_=parseInt(a,10);this.updateShape_()},saveExtraState:function(){return{itemCount:this.itemCount_}},loadExtraState:function(a){this.itemCount_=a.itemCount;
|
||||
this.updateShape_()},decompose:function(a){const b=a.newBlock("lists_create_with_container");b.initSvg();let c=b.getInput("STACK").connection;for(let d=0;d<this.itemCount_;d++){const e=a.newBlock("lists_create_with_item");e.initSvg();if(!e.previousConnection)throw Error("itemBlock has no previousConnection");c.connect(e.previousConnection);c=e.nextConnection}return b},compose:function(a){var b=a.getInputTargetBlock("STACK");for(a=[];b;)b.isInsertionMarker()||a.push(b.valueConnection_),b=b.getNextBlock();
|
||||
for(b=0;b<this.itemCount_;b++){const c=this.getInput("ADD"+b).connection.targetConnection;c&&!a.includes(c)&&c.disconnect()}this.itemCount_=a.length;this.updateShape_();for(b=0;b<this.itemCount_;b++){let c;null==(c=a[b])||c.reconnect(this,"ADD"+b)}},saveConnections:function(a){a=a.getInputTargetBlock("STACK");let b=0;for(;a;){if(a.isInsertionMarker()){a=a.getNextBlock();continue}const c=this.getInput("ADD"+b);let d;a.valueConnection_=null==(d=c)?void 0:d.connection.targetConnection;a=a.getNextBlock();
|
||||
b++}},updateShape_:function(){this.itemCount_&&this.getInput("EMPTY")?this.removeInput("EMPTY"):this.itemCount_||this.getInput("EMPTY")||this.appendDummyInput("EMPTY").appendField($.Msg$$module$build$src$core$msg.LISTS_CREATE_EMPTY_TITLE);for(var a=0;a<this.itemCount_;a++)if(!this.getInput("ADD"+a)){const b=this.appendValueInput("ADD"+a).setAlign($.Align$$module$build$src$core$inputs$align.RIGHT);0===a&&b.appendField($.Msg$$module$build$src$core$msg.LISTS_CREATE_WITH_INPUT_WITH)}for(a=this.itemCount_;this.getInput("ADD"+
|
||||
a);a++)this.removeInput("ADD"+a)}};blocks$$module$build$src$blocks$lists.lists_create_with=LISTS_CREATE_WITH$$module$build$src$blocks$lists;var LISTS_CREATE_WITH_CONTAINER$$module$build$src$blocks$lists={init:function(){this.setStyle("list_blocks");this.appendDummyInput().appendField($.Msg$$module$build$src$core$msg.LISTS_CREATE_WITH_CONTAINER_TITLE_ADD);this.appendStatementInput("STACK");this.setTooltip($.Msg$$module$build$src$core$msg.LISTS_CREATE_WITH_CONTAINER_TOOLTIP);this.contextMenu=!1}};
|
||||
blocks$$module$build$src$blocks$lists.lists_create_with_container=LISTS_CREATE_WITH_CONTAINER$$module$build$src$blocks$lists;var LISTS_CREATE_WITH_ITEM$$module$build$src$blocks$lists={init:function(){this.setStyle("list_blocks");this.appendDummyInput().appendField($.Msg$$module$build$src$core$msg.LISTS_CREATE_WITH_ITEM_TITLE);this.setPreviousStatement(!0);this.setNextStatement(!0);this.setTooltip($.Msg$$module$build$src$core$msg.LISTS_CREATE_WITH_ITEM_TOOLTIP);this.contextMenu=!1}};
|
||||
blocks$$module$build$src$blocks$lists.lists_create_with_item=LISTS_CREATE_WITH_ITEM$$module$build$src$blocks$lists;
|
||||
var LISTS_INDEXOF$$module$build$src$blocks$lists={init:function(){var a=[[$.Msg$$module$build$src$core$msg.LISTS_INDEX_OF_FIRST,"FIRST"],[$.Msg$$module$build$src$core$msg.LISTS_INDEX_OF_LAST,"LAST"]];this.setHelpUrl($.Msg$$module$build$src$core$msg.LISTS_INDEX_OF_HELPURL);this.setStyle("list_blocks");this.setOutput(!0,"Number");this.appendValueInput("VALUE").setCheck("Array").appendField($.Msg$$module$build$src$core$msg.LISTS_INDEX_OF_INPUT_IN_LIST);a=$.fromJson$$module$build$src$core$field_registry({type:"field_dropdown",
|
||||
options:a});if(!a)throw Error("field_dropdown not found");this.appendValueInput("FIND").appendField(a,"END");this.setInputsInline(!0);this.setTooltip(()=>$.Msg$$module$build$src$core$msg.LISTS_INDEX_OF_TOOLTIP.replace("%1",this.workspace.options.oneBasedIndex?"0":"-1"))}};blocks$$module$build$src$blocks$lists.lists_indexOf=LISTS_INDEXOF$$module$build$src$blocks$lists;
|
||||
var LISTS_GETINDEX$$module$build$src$blocks$lists={init:function(){var a=[[$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_GET,"GET"],[$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_GET_REMOVE,"GET_REMOVE"],[$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_REMOVE,"REMOVE"]];this.WHERE_OPTIONS=[[$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_FROM_START,"FROM_START"],[$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_FROM_END,"FROM_END"],[$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_FIRST,"FIRST"],
|
||||
[$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_LAST,"LAST"],[$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_RANDOM,"RANDOM"]];this.setHelpUrl($.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_HELPURL);this.setStyle("list_blocks");a=$.fromJson$$module$build$src$core$field_registry({type:"field_dropdown",options:a});a.setValidator(function(b){b="REMOVE"===b;this.getSourceBlock().updateStatement_(b)});this.appendValueInput("VALUE").setCheck("Array").appendField($.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_INPUT_IN_LIST);
|
||||
this.appendDummyInput().appendField(a,"MODE").appendField("","SPACE");this.appendDummyInput("AT");$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_TAIL&&this.appendDummyInput("TAIL").appendField($.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_TAIL);this.setInputsInline(!0);this.setOutput(!0);this.updateAt_(!0);this.setTooltip(()=>{const b=this.getFieldValue("MODE"),c=this.getFieldValue("WHERE");let d="";switch(b+" "+c){case "GET FROM_START":case "GET FROM_END":d=$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_TOOLTIP_GET_FROM;
|
||||
break;case "GET FIRST":d=$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_TOOLTIP_GET_FIRST;break;case "GET LAST":d=$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_TOOLTIP_GET_LAST;break;case "GET RANDOM":d=$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_TOOLTIP_GET_RANDOM;break;case "GET_REMOVE FROM_START":case "GET_REMOVE FROM_END":d=$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_TOOLTIP_GET_REMOVE_FROM;break;case "GET_REMOVE FIRST":d=$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_TOOLTIP_GET_REMOVE_FIRST;
|
||||
break;case "GET_REMOVE LAST":d=$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_TOOLTIP_GET_REMOVE_LAST;break;case "GET_REMOVE RANDOM":d=$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_TOOLTIP_GET_REMOVE_RANDOM;break;case "REMOVE FROM_START":case "REMOVE FROM_END":d=$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_TOOLTIP_REMOVE_FROM;break;case "REMOVE FIRST":d=$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_TOOLTIP_REMOVE_FIRST;break;case "REMOVE LAST":d=$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_TOOLTIP_REMOVE_LAST;
|
||||
break;case "REMOVE RANDOM":d=$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_TOOLTIP_REMOVE_RANDOM}if("FROM_START"===c||"FROM_END"===c)d+=" "+("FROM_START"===c?$.Msg$$module$build$src$core$msg.LISTS_INDEX_FROM_START_TOOLTIP:$.Msg$$module$build$src$core$msg.LISTS_INDEX_FROM_END_TOOLTIP).replace("%1",this.workspace.options.oneBasedIndex?"#1":"#0");return d})},mutationToDom:function(){const a=$.createElement$$module$build$src$core$utils$xml("mutation");a.setAttribute("statement",String(!this.outputConnection));
|
||||
const b=this.getInput("AT")instanceof $.ValueInput$$module$build$src$core$inputs$value_input;a.setAttribute("at",String(b));return a},domToMutation:function(a){const b="true"===a.getAttribute("statement");this.updateStatement_(b);a="false"!==a.getAttribute("at");this.updateAt_(a)},saveExtraState:function(){return this.outputConnection?null:{isStatement:!0}},loadExtraState:function(a){a.isStatement?this.updateStatement_(!0):"string"===typeof a&&this.domToMutation($.textToDom$$module$build$src$core$utils$xml(a))},
|
||||
updateStatement_:function(a){a!==!this.outputConnection&&(this.unplug(!0,!0),a?(this.setOutput(!1),this.setPreviousStatement(!0),this.setNextStatement(!0)):(this.setPreviousStatement(!1),this.setNextStatement(!1),this.setOutput(!0)))},updateAt_:function(a){this.removeInput("AT");this.removeInput("ORDINAL",!0);a?(this.appendValueInput("AT").setCheck("Number"),$.Msg$$module$build$src$core$msg.ORDINAL_NUMBER_SUFFIX&&this.appendDummyInput("ORDINAL").appendField($.Msg$$module$build$src$core$msg.ORDINAL_NUMBER_SUFFIX)):
|
||||
this.appendDummyInput("AT");const b=$.fromJson$$module$build$src$core$field_registry({type:"field_dropdown",options:this.WHERE_OPTIONS});b.setValidator(function(c){const d="FROM_START"===c||"FROM_END"===c;if(d!==a){const e=this.getSourceBlock();e.updateAt_(d);e.setFieldValue(c,"WHERE");return null}});this.getInput("AT").appendField(b,"WHERE");$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_TAIL&&this.moveInputBefore("TAIL",null)}};blocks$$module$build$src$blocks$lists.lists_getIndex=LISTS_GETINDEX$$module$build$src$blocks$lists;
|
||||
var LISTS_SETINDEX$$module$build$src$blocks$lists={init:function(){var a=[[$.Msg$$module$build$src$core$msg.LISTS_SET_INDEX_SET,"SET"],[$.Msg$$module$build$src$core$msg.LISTS_SET_INDEX_INSERT,"INSERT"]];this.WHERE_OPTIONS=[[$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_FROM_START,"FROM_START"],[$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_FROM_END,"FROM_END"],[$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_FIRST,"FIRST"],[$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_LAST,"LAST"],[$.Msg$$module$build$src$core$msg.LISTS_GET_INDEX_RANDOM,
|
||||
"RANDOM"]];this.setHelpUrl($.Msg$$module$build$src$core$msg.LISTS_SET_INDEX_HELPURL);this.setStyle("list_blocks");this.appendValueInput("LIST").setCheck("Array").appendField($.Msg$$module$build$src$core$msg.LISTS_SET_INDEX_INPUT_IN_LIST);a=$.fromJson$$module$build$src$core$field_registry({type:"field_dropdown",options:a});this.appendDummyInput().appendField(a,"MODE").appendField("","SPACE");this.appendDummyInput("AT");this.appendValueInput("TO").appendField($.Msg$$module$build$src$core$msg.LISTS_SET_INDEX_INPUT_TO);
|
||||
this.setInputsInline(!0);this.setPreviousStatement(!0);this.setNextStatement(!0);this.setTooltip($.Msg$$module$build$src$core$msg.LISTS_SET_INDEX_TOOLTIP);this.updateAt_(!0);this.setTooltip(()=>{const b=this.getFieldValue("MODE"),c=this.getFieldValue("WHERE");let d="";switch(b+" "+c){case "SET FROM_START":case "SET FROM_END":d=$.Msg$$module$build$src$core$msg.LISTS_SET_INDEX_TOOLTIP_SET_FROM;break;case "SET FIRST":d=$.Msg$$module$build$src$core$msg.LISTS_SET_INDEX_TOOLTIP_SET_FIRST;break;case "SET LAST":d=
|
||||
$.Msg$$module$build$src$core$msg.LISTS_SET_INDEX_TOOLTIP_SET_LAST;break;case "SET RANDOM":d=$.Msg$$module$build$src$core$msg.LISTS_SET_INDEX_TOOLTIP_SET_RANDOM;break;case "INSERT FROM_START":case "INSERT FROM_END":d=$.Msg$$module$build$src$core$msg.LISTS_SET_INDEX_TOOLTIP_INSERT_FROM;break;case "INSERT FIRST":d=$.Msg$$module$build$src$core$msg.LISTS_SET_INDEX_TOOLTIP_INSERT_FIRST;break;case "INSERT LAST":d=$.Msg$$module$build$src$core$msg.LISTS_SET_INDEX_TOOLTIP_INSERT_LAST;break;case "INSERT RANDOM":d=
|
||||
$.Msg$$module$build$src$core$msg.LISTS_SET_INDEX_TOOLTIP_INSERT_RANDOM}if("FROM_START"===c||"FROM_END"===c)d+=" "+$.Msg$$module$build$src$core$msg.LISTS_INDEX_FROM_START_TOOLTIP.replace("%1",this.workspace.options.oneBasedIndex?"#1":"#0");return d})},mutationToDom:function(){const a=$.createElement$$module$build$src$core$utils$xml("mutation"),b=this.getInput("AT")instanceof $.ValueInput$$module$build$src$core$inputs$value_input;a.setAttribute("at",String(b));return a},domToMutation:function(a){a=
|
||||
"false"!==a.getAttribute("at");this.updateAt_(a)},saveExtraState:function(){return null},loadExtraState:function(){},updateAt_:function(a){this.removeInput("AT");this.removeInput("ORDINAL",!0);a?(this.appendValueInput("AT").setCheck("Number"),$.Msg$$module$build$src$core$msg.ORDINAL_NUMBER_SUFFIX&&this.appendDummyInput("ORDINAL").appendField($.Msg$$module$build$src$core$msg.ORDINAL_NUMBER_SUFFIX)):this.appendDummyInput("AT");const b=$.fromJson$$module$build$src$core$field_registry({type:"field_dropdown",
|
||||
options:this.WHERE_OPTIONS});b.setValidator(function(c){const d="FROM_START"===c||"FROM_END"===c;if(d!==a){const e=this.getSourceBlock();e.updateAt_(d);e.setFieldValue(c,"WHERE");return null}});this.moveInputBefore("AT","TO");this.getInput("ORDINAL")&&this.moveInputBefore("ORDINAL","TO");this.getInput("AT").appendField(b,"WHERE")}};blocks$$module$build$src$blocks$lists.lists_setIndex=LISTS_SETINDEX$$module$build$src$blocks$lists;
|
||||
var LISTS_GETSUBLIST$$module$build$src$blocks$lists={init:function(){this.WHERE_OPTIONS_1=[[$.Msg$$module$build$src$core$msg.LISTS_GET_SUBLIST_START_FROM_START,"FROM_START"],[$.Msg$$module$build$src$core$msg.LISTS_GET_SUBLIST_START_FROM_END,"FROM_END"],[$.Msg$$module$build$src$core$msg.LISTS_GET_SUBLIST_START_FIRST,"FIRST"]];this.WHERE_OPTIONS_2=[[$.Msg$$module$build$src$core$msg.LISTS_GET_SUBLIST_END_FROM_START,"FROM_START"],[$.Msg$$module$build$src$core$msg.LISTS_GET_SUBLIST_END_FROM_END,"FROM_END"],
|
||||
[$.Msg$$module$build$src$core$msg.LISTS_GET_SUBLIST_END_LAST,"LAST"]];this.setHelpUrl($.Msg$$module$build$src$core$msg.LISTS_GET_SUBLIST_HELPURL);this.setStyle("list_blocks");this.appendValueInput("LIST").setCheck("Array").appendField($.Msg$$module$build$src$core$msg.LISTS_GET_SUBLIST_INPUT_IN_LIST);this.appendDummyInput("AT1");this.appendDummyInput("AT2");$.Msg$$module$build$src$core$msg.LISTS_GET_SUBLIST_TAIL&&this.appendDummyInput("TAIL").appendField($.Msg$$module$build$src$core$msg.LISTS_GET_SUBLIST_TAIL);
|
||||
this.setInputsInline(!0);this.setOutput(!0,"Array");this.updateAt_(1,!0);this.updateAt_(2,!0);this.setTooltip($.Msg$$module$build$src$core$msg.LISTS_GET_SUBLIST_TOOLTIP)},mutationToDom:function(){const a=$.createElement$$module$build$src$core$utils$xml("mutation");var b=this.getInput("AT1")instanceof $.ValueInput$$module$build$src$core$inputs$value_input;a.setAttribute("at1",String(b));b=this.getInput("AT2")instanceof $.ValueInput$$module$build$src$core$inputs$value_input;a.setAttribute("at2",String(b));
|
||||
return a},domToMutation:function(a){const b="true"===a.getAttribute("at1");a="true"===a.getAttribute("at2");this.updateAt_(1,b);this.updateAt_(2,a)},saveExtraState:function(){return null},loadExtraState:function(){},updateAt_:function(a,b){this.removeInput("AT"+a);this.removeInput("ORDINAL"+a,!0);b?(this.appendValueInput("AT"+a).setCheck("Number"),$.Msg$$module$build$src$core$msg.ORDINAL_NUMBER_SUFFIX&&this.appendDummyInput("ORDINAL"+a).appendField($.Msg$$module$build$src$core$msg.ORDINAL_NUMBER_SUFFIX)):
|
||||
this.appendDummyInput("AT"+a);const c=$.fromJson$$module$build$src$core$field_registry({type:"field_dropdown",options:this["WHERE_OPTIONS_"+a]});c.setValidator(function(d){const e="FROM_START"===d||"FROM_END"===d;if(e!==b){const f=this.getSourceBlock();f.updateAt_(a,e);f.setFieldValue(d,"WHERE"+a);return null}});this.getInput("AT"+a).appendField(c,"WHERE"+a);1===a&&(this.moveInputBefore("AT1","AT2"),this.getInput("ORDINAL1")&&this.moveInputBefore("ORDINAL1","AT2"));$.Msg$$module$build$src$core$msg.LISTS_GET_SUBLIST_TAIL&&
|
||||
this.moveInputBefore("TAIL",null)}};blocks$$module$build$src$blocks$lists.lists_getSublist=LISTS_GETSUBLIST$$module$build$src$blocks$lists;
|
||||
blocks$$module$build$src$blocks$lists.lists_sort={init:function(){this.jsonInit({message0:"%{BKY_LISTS_SORT_TITLE}",args0:[{type:"field_dropdown",name:"TYPE",options:[["%{BKY_LISTS_SORT_TYPE_NUMERIC}","NUMERIC"],["%{BKY_LISTS_SORT_TYPE_TEXT}","TEXT"],["%{BKY_LISTS_SORT_TYPE_IGNORECASE}","IGNORE_CASE"]]},{type:"field_dropdown",name:"DIRECTION",options:[["%{BKY_LISTS_SORT_ORDER_ASCENDING}","1"],["%{BKY_LISTS_SORT_ORDER_DESCENDING}","-1"]]},{type:"input_value",name:"LIST",check:"Array"}],output:"Array",
|
||||
style:"list_blocks",tooltip:"%{BKY_LISTS_SORT_TOOLTIP}",helpUrl:"%{BKY_LISTS_SORT_HELPURL}"})}};
|
||||
blocks$$module$build$src$blocks$lists.lists_split={init:function(){const a=$.fromJson$$module$build$src$core$field_registry({type:"field_dropdown",options:[[$.Msg$$module$build$src$core$msg.LISTS_SPLIT_LIST_FROM_TEXT,"SPLIT"],[$.Msg$$module$build$src$core$msg.LISTS_SPLIT_TEXT_FROM_LIST,"JOIN"]]});if(!a)throw Error("field_dropdown not found");a.setValidator(b=>{this.updateType_(b)});this.setHelpUrl($.Msg$$module$build$src$core$msg.LISTS_SPLIT_HELPURL);this.setStyle("list_blocks");this.appendValueInput("INPUT").setCheck("String").appendField(a,
|
||||
"MODE");this.appendValueInput("DELIM").setCheck("String").appendField($.Msg$$module$build$src$core$msg.LISTS_SPLIT_WITH_DELIMITER);this.setInputsInline(!0);this.setOutput(!0,"Array");this.setTooltip(()=>{const b=this.getFieldValue("MODE");if("SPLIT"===b)return $.Msg$$module$build$src$core$msg.LISTS_SPLIT_TOOLTIP_SPLIT;if("JOIN"===b)return $.Msg$$module$build$src$core$msg.LISTS_SPLIT_TOOLTIP_JOIN;throw Error("Unknown mode: "+b);})},updateType_:function(a){if(this.getFieldValue("MODE")!==a){const b=
|
||||
this.getInput("INPUT").connection;b.setShadowDom(null);const c=b.targetBlock();c&&(b.disconnect(),c.isShadow()?c.dispose(!1):this.bumpNeighbours())}"SPLIT"===a?(this.outputConnection.setCheck("Array"),this.getInput("INPUT").setCheck("String")):(this.outputConnection.setCheck("String"),this.getInput("INPUT").setCheck("Array"))},mutationToDom:function(){const a=$.createElement$$module$build$src$core$utils$xml("mutation");a.setAttribute("mode",this.getFieldValue("MODE"));return a},domToMutation:function(a){this.updateType_(a.getAttribute("mode"))},
|
||||
saveExtraState:function(){return null},loadExtraState:function(){}};$.defineBlocks$$module$build$src$core$common(blocks$$module$build$src$blocks$lists);var module$build$src$blocks$lists={blocks:blocks$$module$build$src$blocks$lists};var blocks$$module$build$src$blocks$blocks=Object.assign({},blocks$$module$build$src$blocks$lists,blocks$$module$build$src$blocks$logic,blocks$$module$build$src$blocks$loops,blocks$$module$build$src$blocks$math,blocks$$module$build$src$blocks$procedures,blocks$$module$build$src$blocks$text,blocks$$module$build$src$blocks$variables,blocks$$module$build$src$blocks$variables_dynamic),module$build$src$blocks$blocks={blocks:blocks$$module$build$src$blocks$blocks,lists:module$build$src$blocks$lists,logic:module$build$src$blocks$logic,
|
||||
loops:module$build$src$blocks$loops,math:module$build$src$blocks$math,procedures:module$build$src$blocks$procedures,texts:module$build$src$blocks$text,variables:module$build$src$blocks$variables,variablesDynamic:module$build$src$blocks$variables_dynamic};
|
||||
module$build$src$blocks$blocks.__namespace__=$;
|
||||
return module$build$src$blocks$blocks;
|
||||
}));
|
||||
|
||||
|
||||
//# sourceMappingURL=blocks_compressed.js.map
|
||||
@@ -0,0 +1,3 @@
|
||||
/*! For license information please see index.js.LICENSE.txt */
|
||||
!function(e,o){if("object"==typeof exports&&"object"==typeof module)module.exports=o(require("blockly/core"));else if("function"==typeof define&&define.amd)define(["blockly/core"],o);else{var r="object"==typeof exports?o(require("blockly/core")):o(e.Blockly);for(var t in r)("object"==typeof exports?exports:e)[t]=r[t]}}(this,(e=>(()=>{"use strict";var o={370:o=>{o.exports=e}},r={};function t(e){var l=r[e];if(void 0!==l)return l.exports;var c=r[e]={exports:{}};return o[e](c,c.exports,t),c.exports}t.n=e=>{var o=e&&e.__esModule?()=>e.default:()=>e;return t.d(o,{a:o}),o},t.d=(e,o)=>{for(var r in o)t.o(o,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:o[r]})},t.o=(e,o)=>Object.prototype.hasOwnProperty.call(e,o),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var l={};t.r(l),t.d(l,{default:()=>n});var c=t(370);const n=c.Theme.defineTheme("dark",{base:c.Themes.Classic,componentStyles:{workspaceBackgroundColour:"#1e1e1e",toolboxBackgroundColour:"blackBackground",toolboxForegroundColour:"#fff",flyoutBackgroundColour:"#252526",flyoutForegroundColour:"#ccc",flyoutOpacity:1,scrollbarColour:"#797979",insertionMarkerColour:"#fff",insertionMarkerOpacity:.3,scrollbarOpacity:.4,cursorColour:"#d0d0d0",blackBackground:"#333"}});return l})()));
|
||||
//# sourceMappingURL=index.js.map
|
||||
@@ -0,0 +1,442 @@
|
||||
/* eslint-disable */
|
||||
;(function(root, factory) {
|
||||
if (typeof define === 'function' && define.amd) { // AMD
|
||||
define([], factory);
|
||||
} else if (typeof exports === 'object') { // Node.js
|
||||
module.exports = factory();
|
||||
} else { // Browser
|
||||
var messages = factory();
|
||||
for (var key in messages) {
|
||||
root.Blockly.Msg[key] = messages[key];
|
||||
}
|
||||
}
|
||||
}(this, function() {
|
||||
// This file was automatically generated. Do not modify.
|
||||
|
||||
'use strict';
|
||||
|
||||
var Blockly = Blockly || { Msg: Object.create(null) };
|
||||
|
||||
Blockly.Msg["ADD_COMMENT"] = "Add Comment";
|
||||
Blockly.Msg["CANNOT_DELETE_VARIABLE_PROCEDURE"] = "Can't delete the variable '%1' because it's part of the definition of the function '%2'";
|
||||
Blockly.Msg["CHANGE_VALUE_TITLE"] = "Change value:";
|
||||
Blockly.Msg["CLEAN_UP"] = "Clean up Blocks";
|
||||
Blockly.Msg["COLLAPSED_WARNINGS_WARNING"] = "Collapsed blocks contain warnings.";
|
||||
Blockly.Msg["COLLAPSE_ALL"] = "Collapse Blocks";
|
||||
Blockly.Msg["COLLAPSE_BLOCK"] = "Collapse Block";
|
||||
Blockly.Msg["COLOUR_BLEND_COLOUR1"] = "colour 1";
|
||||
Blockly.Msg["COLOUR_BLEND_COLOUR2"] = "colour 2";
|
||||
Blockly.Msg["COLOUR_BLEND_HELPURL"] = "https://meyerweb.com/eric/tools/color-blend/#:::rgbp";
|
||||
Blockly.Msg["COLOUR_BLEND_RATIO"] = "ratio";
|
||||
Blockly.Msg["COLOUR_BLEND_TITLE"] = "blend";
|
||||
Blockly.Msg["COLOUR_BLEND_TOOLTIP"] = "Blends two colours together with a given ratio (0.0 - 1.0).";
|
||||
Blockly.Msg["COLOUR_PICKER_HELPURL"] = "https://en.wikipedia.org/wiki/Color";
|
||||
Blockly.Msg["COLOUR_PICKER_TOOLTIP"] = "Choose a colour from the palette.";
|
||||
Blockly.Msg["COLOUR_RANDOM_HELPURL"] = "http://randomcolour.com";
|
||||
Blockly.Msg["COLOUR_RANDOM_TITLE"] = "random colour";
|
||||
Blockly.Msg["COLOUR_RANDOM_TOOLTIP"] = "Choose a colour at random.";
|
||||
Blockly.Msg["COLOUR_RGB_BLUE"] = "blue";
|
||||
Blockly.Msg["COLOUR_RGB_GREEN"] = "green";
|
||||
Blockly.Msg["COLOUR_RGB_HELPURL"] = "https://www.december.com/html/spec/colorpercompact.html";
|
||||
Blockly.Msg["COLOUR_RGB_RED"] = "red";
|
||||
Blockly.Msg["COLOUR_RGB_TITLE"] = "colour with";
|
||||
Blockly.Msg["COLOUR_RGB_TOOLTIP"] = "Create a colour with the specified amount of red, green, and blue. All values must be between 0 and 100.";
|
||||
Blockly.Msg["CONTROLS_FLOW_STATEMENTS_HELPURL"] = "https://github.com/google/blockly/wiki/Loops#loop-termination-blocks";
|
||||
Blockly.Msg["CONTROLS_FLOW_STATEMENTS_OPERATOR_BREAK"] = "break out of loop";
|
||||
Blockly.Msg["CONTROLS_FLOW_STATEMENTS_OPERATOR_CONTINUE"] = "continue with next iteration of loop";
|
||||
Blockly.Msg["CONTROLS_FLOW_STATEMENTS_TOOLTIP_BREAK"] = "Break out of the containing loop.";
|
||||
Blockly.Msg["CONTROLS_FLOW_STATEMENTS_TOOLTIP_CONTINUE"] = "Skip the rest of this loop, and continue with the next iteration.";
|
||||
Blockly.Msg["CONTROLS_FLOW_STATEMENTS_WARNING"] = "Warning: This block may only be used within a loop.";
|
||||
Blockly.Msg["CONTROLS_FOREACH_HELPURL"] = "https://github.com/google/blockly/wiki/Loops#for-each";
|
||||
Blockly.Msg["CONTROLS_FOREACH_TITLE"] = "for each item %1 in list %2";
|
||||
Blockly.Msg["CONTROLS_FOREACH_TOOLTIP"] = "For each item in a list, set the variable '%1' to the item, and then do some statements.";
|
||||
Blockly.Msg["CONTROLS_FOR_HELPURL"] = "https://github.com/google/blockly/wiki/Loops#count-with";
|
||||
Blockly.Msg["CONTROLS_FOR_TITLE"] = "count with %1 from %2 to %3 by %4";
|
||||
Blockly.Msg["CONTROLS_FOR_TOOLTIP"] = "Have the variable '%1' take on the values from the start number to the end number, counting by the specified interval, and do the specified blocks.";
|
||||
Blockly.Msg["CONTROLS_IF_ELSEIF_TOOLTIP"] = "Add a condition to the if block.";
|
||||
Blockly.Msg["CONTROLS_IF_ELSE_TOOLTIP"] = "Add a final, catch-all condition to the if block.";
|
||||
Blockly.Msg["CONTROLS_IF_HELPURL"] = "https://github.com/google/blockly/wiki/IfElse";
|
||||
Blockly.Msg["CONTROLS_IF_IF_TOOLTIP"] = "Add, remove, or reorder sections to reconfigure this if block.";
|
||||
Blockly.Msg["CONTROLS_IF_MSG_ELSE"] = "else";
|
||||
Blockly.Msg["CONTROLS_IF_MSG_ELSEIF"] = "else if";
|
||||
Blockly.Msg["CONTROLS_IF_MSG_IF"] = "if";
|
||||
Blockly.Msg["CONTROLS_IF_TOOLTIP_1"] = "If a value is true, then do some statements.";
|
||||
Blockly.Msg["CONTROLS_IF_TOOLTIP_2"] = "If a value is true, then do the first block of statements. Otherwise, do the second block of statements.";
|
||||
Blockly.Msg["CONTROLS_IF_TOOLTIP_3"] = "If the first value is true, then do the first block of statements. Otherwise, if the second value is true, do the second block of statements.";
|
||||
Blockly.Msg["CONTROLS_IF_TOOLTIP_4"] = "If the first value is true, then do the first block of statements. Otherwise, if the second value is true, do the second block of statements. If none of the values are true, do the last block of statements.";
|
||||
Blockly.Msg["CONTROLS_REPEAT_HELPURL"] = "https://en.wikipedia.org/wiki/For_loop";
|
||||
Blockly.Msg["CONTROLS_REPEAT_INPUT_DO"] = "do";
|
||||
Blockly.Msg["CONTROLS_REPEAT_TITLE"] = "repeat %1 times";
|
||||
Blockly.Msg["CONTROLS_REPEAT_TOOLTIP"] = "Do some statements several times.";
|
||||
Blockly.Msg["CONTROLS_WHILEUNTIL_HELPURL"] = "https://github.com/google/blockly/wiki/Loops#repeat";
|
||||
Blockly.Msg["CONTROLS_WHILEUNTIL_OPERATOR_UNTIL"] = "repeat until";
|
||||
Blockly.Msg["CONTROLS_WHILEUNTIL_OPERATOR_WHILE"] = "repeat while";
|
||||
Blockly.Msg["CONTROLS_WHILEUNTIL_TOOLTIP_UNTIL"] = "While a value is false, then do some statements.";
|
||||
Blockly.Msg["CONTROLS_WHILEUNTIL_TOOLTIP_WHILE"] = "While a value is true, then do some statements.";
|
||||
Blockly.Msg["DELETE_ALL_BLOCKS"] = "Delete all %1 blocks?";
|
||||
Blockly.Msg["DELETE_BLOCK"] = "Delete Block";
|
||||
Blockly.Msg["DELETE_VARIABLE"] = "Delete the '%1' variable";
|
||||
Blockly.Msg["DELETE_VARIABLE_CONFIRMATION"] = "Delete %1 uses of the '%2' variable?";
|
||||
Blockly.Msg["DELETE_X_BLOCKS"] = "Delete %1 Blocks";
|
||||
Blockly.Msg["DIALOG_CANCEL"] = "Cancel";
|
||||
Blockly.Msg["DIALOG_OK"] = "OK";
|
||||
Blockly.Msg["DISABLE_BLOCK"] = "Disable Block";
|
||||
Blockly.Msg["DUPLICATE_BLOCK"] = "Duplicate";
|
||||
Blockly.Msg["DUPLICATE_COMMENT"] = "Duplicate Comment";
|
||||
Blockly.Msg["ENABLE_BLOCK"] = "Enable Block";
|
||||
Blockly.Msg["EXPAND_ALL"] = "Expand Blocks";
|
||||
Blockly.Msg["EXPAND_BLOCK"] = "Expand Block";
|
||||
Blockly.Msg["EXTERNAL_INPUTS"] = "External Inputs";
|
||||
Blockly.Msg["HELP"] = "Help";
|
||||
Blockly.Msg["INLINE_INPUTS"] = "Inline Inputs";
|
||||
Blockly.Msg["LISTS_CREATE_EMPTY_HELPURL"] = "https://github.com/google/blockly/wiki/Lists#create-empty-list";
|
||||
Blockly.Msg["LISTS_CREATE_EMPTY_TITLE"] = "create empty list";
|
||||
Blockly.Msg["LISTS_CREATE_EMPTY_TOOLTIP"] = "Returns a list, of length 0, containing no data records";
|
||||
Blockly.Msg["LISTS_CREATE_WITH_CONTAINER_TITLE_ADD"] = "list";
|
||||
Blockly.Msg["LISTS_CREATE_WITH_CONTAINER_TOOLTIP"] = "Add, remove, or reorder sections to reconfigure this list block.";
|
||||
Blockly.Msg["LISTS_CREATE_WITH_HELPURL"] = "https://github.com/google/blockly/wiki/Lists#create-list-with";
|
||||
Blockly.Msg["LISTS_CREATE_WITH_INPUT_WITH"] = "create list with";
|
||||
Blockly.Msg["LISTS_CREATE_WITH_ITEM_TOOLTIP"] = "Add an item to the list.";
|
||||
Blockly.Msg["LISTS_CREATE_WITH_TOOLTIP"] = "Create a list with any number of items.";
|
||||
Blockly.Msg["LISTS_GET_INDEX_FIRST"] = "first";
|
||||
Blockly.Msg["LISTS_GET_INDEX_FROM_END"] = "# from end";
|
||||
Blockly.Msg["LISTS_GET_INDEX_FROM_START"] = "#";
|
||||
Blockly.Msg["LISTS_GET_INDEX_GET"] = "get";
|
||||
Blockly.Msg["LISTS_GET_INDEX_GET_REMOVE"] = "get and remove";
|
||||
Blockly.Msg["LISTS_GET_INDEX_HELPURL"] = "https://github.com/google/blockly/wiki/Lists#getting-items-from-a-list";
|
||||
Blockly.Msg["LISTS_GET_INDEX_LAST"] = "last";
|
||||
Blockly.Msg["LISTS_GET_INDEX_RANDOM"] = "random";
|
||||
Blockly.Msg["LISTS_GET_INDEX_REMOVE"] = "remove";
|
||||
Blockly.Msg["LISTS_GET_INDEX_TAIL"] = "";
|
||||
Blockly.Msg["LISTS_GET_INDEX_TOOLTIP_GET_FIRST"] = "Returns the first item in a list.";
|
||||
Blockly.Msg["LISTS_GET_INDEX_TOOLTIP_GET_FROM"] = "Returns the item at the specified position in a list.";
|
||||
Blockly.Msg["LISTS_GET_INDEX_TOOLTIP_GET_LAST"] = "Returns the last item in a list.";
|
||||
Blockly.Msg["LISTS_GET_INDEX_TOOLTIP_GET_RANDOM"] = "Returns a random item in a list.";
|
||||
Blockly.Msg["LISTS_GET_INDEX_TOOLTIP_GET_REMOVE_FIRST"] = "Removes and returns the first item in a list.";
|
||||
Blockly.Msg["LISTS_GET_INDEX_TOOLTIP_GET_REMOVE_FROM"] = "Removes and returns the item at the specified position in a list.";
|
||||
Blockly.Msg["LISTS_GET_INDEX_TOOLTIP_GET_REMOVE_LAST"] = "Removes and returns the last item in a list.";
|
||||
Blockly.Msg["LISTS_GET_INDEX_TOOLTIP_GET_REMOVE_RANDOM"] = "Removes and returns a random item in a list.";
|
||||
Blockly.Msg["LISTS_GET_INDEX_TOOLTIP_REMOVE_FIRST"] = "Removes the first item in a list.";
|
||||
Blockly.Msg["LISTS_GET_INDEX_TOOLTIP_REMOVE_FROM"] = "Removes the item at the specified position in a list.";
|
||||
Blockly.Msg["LISTS_GET_INDEX_TOOLTIP_REMOVE_LAST"] = "Removes the last item in a list.";
|
||||
Blockly.Msg["LISTS_GET_INDEX_TOOLTIP_REMOVE_RANDOM"] = "Removes a random item in a list.";
|
||||
Blockly.Msg["LISTS_GET_SUBLIST_END_FROM_END"] = "to # from end";
|
||||
Blockly.Msg["LISTS_GET_SUBLIST_END_FROM_START"] = "to #";
|
||||
Blockly.Msg["LISTS_GET_SUBLIST_END_LAST"] = "to last";
|
||||
Blockly.Msg["LISTS_GET_SUBLIST_HELPURL"] = "https://github.com/google/blockly/wiki/Lists#getting-a-sublist";
|
||||
Blockly.Msg["LISTS_GET_SUBLIST_START_FIRST"] = "get sub-list from first";
|
||||
Blockly.Msg["LISTS_GET_SUBLIST_START_FROM_END"] = "get sub-list from # from end";
|
||||
Blockly.Msg["LISTS_GET_SUBLIST_START_FROM_START"] = "get sub-list from #";
|
||||
Blockly.Msg["LISTS_GET_SUBLIST_TAIL"] = "";
|
||||
Blockly.Msg["LISTS_GET_SUBLIST_TOOLTIP"] = "Creates a copy of the specified portion of a list.";
|
||||
Blockly.Msg["LISTS_INDEX_FROM_END_TOOLTIP"] = "%1 is the last item.";
|
||||
Blockly.Msg["LISTS_INDEX_FROM_START_TOOLTIP"] = "%1 is the first item.";
|
||||
Blockly.Msg["LISTS_INDEX_OF_FIRST"] = "find first occurrence of item";
|
||||
Blockly.Msg["LISTS_INDEX_OF_HELPURL"] = "https://github.com/google/blockly/wiki/Lists#finding-items-in-a-list";
|
||||
Blockly.Msg["LISTS_INDEX_OF_LAST"] = "find last occurrence of item";
|
||||
Blockly.Msg["LISTS_INDEX_OF_TOOLTIP"] = "Returns the index of the first/last occurrence of the item in the list. Returns %1 if item is not found.";
|
||||
Blockly.Msg["LISTS_INLIST"] = "in list";
|
||||
Blockly.Msg["LISTS_ISEMPTY_HELPURL"] = "https://github.com/google/blockly/wiki/Lists#is-empty";
|
||||
Blockly.Msg["LISTS_ISEMPTY_TITLE"] = "%1 is empty";
|
||||
Blockly.Msg["LISTS_ISEMPTY_TOOLTIP"] = "Returns true if the list is empty.";
|
||||
Blockly.Msg["LISTS_LENGTH_HELPURL"] = "https://github.com/google/blockly/wiki/Lists#length-of";
|
||||
Blockly.Msg["LISTS_LENGTH_TITLE"] = "length of %1";
|
||||
Blockly.Msg["LISTS_LENGTH_TOOLTIP"] = "Returns the length of a list.";
|
||||
Blockly.Msg["LISTS_REPEAT_HELPURL"] = "https://github.com/google/blockly/wiki/Lists#create-list-with";
|
||||
Blockly.Msg["LISTS_REPEAT_TITLE"] = "create list with item %1 repeated %2 times";
|
||||
Blockly.Msg["LISTS_REPEAT_TOOLTIP"] = "Creates a list consisting of the given value repeated the specified number of times.";
|
||||
Blockly.Msg["LISTS_REVERSE_HELPURL"] = "https://github.com/google/blockly/wiki/Lists#reversing-a-list";
|
||||
Blockly.Msg["LISTS_REVERSE_MESSAGE0"] = "reverse %1";
|
||||
Blockly.Msg["LISTS_REVERSE_TOOLTIP"] = "Reverse a copy of a list.";
|
||||
Blockly.Msg["LISTS_SET_INDEX_HELPURL"] = "https://github.com/google/blockly/wiki/Lists#in-list--set";
|
||||
Blockly.Msg["LISTS_SET_INDEX_INPUT_TO"] = "as";
|
||||
Blockly.Msg["LISTS_SET_INDEX_INSERT"] = "insert at";
|
||||
Blockly.Msg["LISTS_SET_INDEX_SET"] = "set";
|
||||
Blockly.Msg["LISTS_SET_INDEX_TOOLTIP_INSERT_FIRST"] = "Inserts the item at the start of a list.";
|
||||
Blockly.Msg["LISTS_SET_INDEX_TOOLTIP_INSERT_FROM"] = "Inserts the item at the specified position in a list.";
|
||||
Blockly.Msg["LISTS_SET_INDEX_TOOLTIP_INSERT_LAST"] = "Append the item to the end of a list.";
|
||||
Blockly.Msg["LISTS_SET_INDEX_TOOLTIP_INSERT_RANDOM"] = "Inserts the item randomly in a list.";
|
||||
Blockly.Msg["LISTS_SET_INDEX_TOOLTIP_SET_FIRST"] = "Sets the first item in a list.";
|
||||
Blockly.Msg["LISTS_SET_INDEX_TOOLTIP_SET_FROM"] = "Sets the item at the specified position in a list.";
|
||||
Blockly.Msg["LISTS_SET_INDEX_TOOLTIP_SET_LAST"] = "Sets the last item in a list.";
|
||||
Blockly.Msg["LISTS_SET_INDEX_TOOLTIP_SET_RANDOM"] = "Sets a random item in a list.";
|
||||
Blockly.Msg["LISTS_SORT_HELPURL"] = "https://github.com/google/blockly/wiki/Lists#sorting-a-list";
|
||||
Blockly.Msg["LISTS_SORT_ORDER_ASCENDING"] = "ascending";
|
||||
Blockly.Msg["LISTS_SORT_ORDER_DESCENDING"] = "descending";
|
||||
Blockly.Msg["LISTS_SORT_TITLE"] = "sort %1 %2 %3";
|
||||
Blockly.Msg["LISTS_SORT_TOOLTIP"] = "Sort a copy of a list.";
|
||||
Blockly.Msg["LISTS_SORT_TYPE_IGNORECASE"] = "alphabetic, ignore case";
|
||||
Blockly.Msg["LISTS_SORT_TYPE_NUMERIC"] = "numeric";
|
||||
Blockly.Msg["LISTS_SORT_TYPE_TEXT"] = "alphabetic";
|
||||
Blockly.Msg["LISTS_SPLIT_HELPURL"] = "https://github.com/google/blockly/wiki/Lists#splitting-strings-and-joining-lists";
|
||||
Blockly.Msg["LISTS_SPLIT_LIST_FROM_TEXT"] = "make list from text";
|
||||
Blockly.Msg["LISTS_SPLIT_TEXT_FROM_LIST"] = "make text from list";
|
||||
Blockly.Msg["LISTS_SPLIT_TOOLTIP_JOIN"] = "Join a list of texts into one text, separated by a delimiter.";
|
||||
Blockly.Msg["LISTS_SPLIT_TOOLTIP_SPLIT"] = "Split text into a list of texts, breaking at each delimiter.";
|
||||
Blockly.Msg["LISTS_SPLIT_WITH_DELIMITER"] = "with delimiter";
|
||||
Blockly.Msg["LOGIC_BOOLEAN_FALSE"] = "false";
|
||||
Blockly.Msg["LOGIC_BOOLEAN_HELPURL"] = "https://github.com/google/blockly/wiki/Logic#values";
|
||||
Blockly.Msg["LOGIC_BOOLEAN_TOOLTIP"] = "Returns either true or false.";
|
||||
Blockly.Msg["LOGIC_BOOLEAN_TRUE"] = "true";
|
||||
Blockly.Msg["LOGIC_COMPARE_HELPURL"] = "https://en.wikipedia.org/wiki/Inequality_(mathematics)";
|
||||
Blockly.Msg["LOGIC_COMPARE_TOOLTIP_EQ"] = "Return true if both inputs equal each other.";
|
||||
Blockly.Msg["LOGIC_COMPARE_TOOLTIP_GT"] = "Return true if the first input is greater than the second input.";
|
||||
Blockly.Msg["LOGIC_COMPARE_TOOLTIP_GTE"] = "Return true if the first input is greater than or equal to the second input.";
|
||||
Blockly.Msg["LOGIC_COMPARE_TOOLTIP_LT"] = "Return true if the first input is smaller than the second input.";
|
||||
Blockly.Msg["LOGIC_COMPARE_TOOLTIP_LTE"] = "Return true if the first input is smaller than or equal to the second input.";
|
||||
Blockly.Msg["LOGIC_COMPARE_TOOLTIP_NEQ"] = "Return true if both inputs are not equal to each other.";
|
||||
Blockly.Msg["LOGIC_NEGATE_HELPURL"] = "https://github.com/google/blockly/wiki/Logic#not";
|
||||
Blockly.Msg["LOGIC_NEGATE_TITLE"] = "not %1";
|
||||
Blockly.Msg["LOGIC_NEGATE_TOOLTIP"] = "Returns true if the input is false. Returns false if the input is true.";
|
||||
Blockly.Msg["LOGIC_NULL"] = "null";
|
||||
Blockly.Msg["LOGIC_NULL_HELPURL"] = "https://en.wikipedia.org/wiki/Nullable_type";
|
||||
Blockly.Msg["LOGIC_NULL_TOOLTIP"] = "Returns null.";
|
||||
Blockly.Msg["LOGIC_OPERATION_AND"] = "and";
|
||||
Blockly.Msg["LOGIC_OPERATION_HELPURL"] = "https://github.com/google/blockly/wiki/Logic#logical-operations";
|
||||
Blockly.Msg["LOGIC_OPERATION_OR"] = "or";
|
||||
Blockly.Msg["LOGIC_OPERATION_TOOLTIP_AND"] = "Return true if both inputs are true.";
|
||||
Blockly.Msg["LOGIC_OPERATION_TOOLTIP_OR"] = "Return true if at least one of the inputs is true.";
|
||||
Blockly.Msg["LOGIC_TERNARY_CONDITION"] = "test";
|
||||
Blockly.Msg["LOGIC_TERNARY_HELPURL"] = "https://en.wikipedia.org/wiki/%3F:";
|
||||
Blockly.Msg["LOGIC_TERNARY_IF_FALSE"] = "if false";
|
||||
Blockly.Msg["LOGIC_TERNARY_IF_TRUE"] = "if true";
|
||||
Blockly.Msg["LOGIC_TERNARY_TOOLTIP"] = "Check the condition in 'test'. If the condition is true, returns the 'if true' value; otherwise returns the 'if false' value.";
|
||||
Blockly.Msg["MATH_ADDITION_SYMBOL"] = "+";
|
||||
Blockly.Msg["MATH_ARITHMETIC_HELPURL"] = "https://en.wikipedia.org/wiki/Arithmetic";
|
||||
Blockly.Msg["MATH_ARITHMETIC_TOOLTIP_ADD"] = "Return the sum of the two numbers.";
|
||||
Blockly.Msg["MATH_ARITHMETIC_TOOLTIP_DIVIDE"] = "Return the quotient of the two numbers.";
|
||||
Blockly.Msg["MATH_ARITHMETIC_TOOLTIP_MINUS"] = "Return the difference of the two numbers.";
|
||||
Blockly.Msg["MATH_ARITHMETIC_TOOLTIP_MULTIPLY"] = "Return the product of the two numbers.";
|
||||
Blockly.Msg["MATH_ARITHMETIC_TOOLTIP_POWER"] = "Return the first number raised to the power of the second number.";
|
||||
Blockly.Msg["MATH_ATAN2_HELPURL"] = "https://en.wikipedia.org/wiki/Atan2";
|
||||
Blockly.Msg["MATH_ATAN2_TITLE"] = "atan2 of X:%1 Y:%2";
|
||||
Blockly.Msg["MATH_ATAN2_TOOLTIP"] = "Return the arctangent of point (X, Y) in degrees from -180 to 180.";
|
||||
Blockly.Msg["MATH_CHANGE_HELPURL"] = "https://en.wikipedia.org/wiki/Programming_idiom#Incrementing_a_counter";
|
||||
Blockly.Msg["MATH_CHANGE_TITLE"] = "change %1 by %2";
|
||||
Blockly.Msg["MATH_CHANGE_TOOLTIP"] = "Add a number to variable '%1'.";
|
||||
Blockly.Msg["MATH_CONSTANT_HELPURL"] = "https://en.wikipedia.org/wiki/Mathematical_constant";
|
||||
Blockly.Msg["MATH_CONSTANT_TOOLTIP"] = "Return one of the common constants: π (3.141…), e (2.718…), φ (1.618…), sqrt(2) (1.414…), sqrt(½) (0.707…), or ∞ (infinity).";
|
||||
Blockly.Msg["MATH_CONSTRAIN_HELPURL"] = "https://en.wikipedia.org/wiki/Clamping_(graphics)";
|
||||
Blockly.Msg["MATH_CONSTRAIN_TITLE"] = "constrain %1 low %2 high %3";
|
||||
Blockly.Msg["MATH_CONSTRAIN_TOOLTIP"] = "Constrain a number to be between the specified limits (inclusive).";
|
||||
Blockly.Msg["MATH_DIVISION_SYMBOL"] = "÷";
|
||||
Blockly.Msg["MATH_IS_DIVISIBLE_BY"] = "is divisible by";
|
||||
Blockly.Msg["MATH_IS_EVEN"] = "is even";
|
||||
Blockly.Msg["MATH_IS_NEGATIVE"] = "is negative";
|
||||
Blockly.Msg["MATH_IS_ODD"] = "is odd";
|
||||
Blockly.Msg["MATH_IS_POSITIVE"] = "is positive";
|
||||
Blockly.Msg["MATH_IS_PRIME"] = "is prime";
|
||||
Blockly.Msg["MATH_IS_TOOLTIP"] = "Check if a number is an even, odd, prime, whole, positive, negative, or if it is divisible by certain number. Returns true or false.";
|
||||
Blockly.Msg["MATH_IS_WHOLE"] = "is whole";
|
||||
Blockly.Msg["MATH_MODULO_HELPURL"] = "https://en.wikipedia.org/wiki/Modulo_operation";
|
||||
Blockly.Msg["MATH_MODULO_TITLE"] = "remainder of %1 ÷ %2";
|
||||
Blockly.Msg["MATH_MODULO_TOOLTIP"] = "Return the remainder from dividing the two numbers.";
|
||||
Blockly.Msg["MATH_MULTIPLICATION_SYMBOL"] = "×";
|
||||
Blockly.Msg["MATH_NUMBER_HELPURL"] = "https://en.wikipedia.org/wiki/Number";
|
||||
Blockly.Msg["MATH_NUMBER_TOOLTIP"] = "A number.";
|
||||
Blockly.Msg["MATH_ONLIST_HELPURL"] = "";
|
||||
Blockly.Msg["MATH_ONLIST_OPERATOR_AVERAGE"] = "average of list";
|
||||
Blockly.Msg["MATH_ONLIST_OPERATOR_MAX"] = "max of list";
|
||||
Blockly.Msg["MATH_ONLIST_OPERATOR_MEDIAN"] = "median of list";
|
||||
Blockly.Msg["MATH_ONLIST_OPERATOR_MIN"] = "min of list";
|
||||
Blockly.Msg["MATH_ONLIST_OPERATOR_MODE"] = "modes of list";
|
||||
Blockly.Msg["MATH_ONLIST_OPERATOR_RANDOM"] = "random item of list";
|
||||
Blockly.Msg["MATH_ONLIST_OPERATOR_STD_DEV"] = "standard deviation of list";
|
||||
Blockly.Msg["MATH_ONLIST_OPERATOR_SUM"] = "sum of list";
|
||||
Blockly.Msg["MATH_ONLIST_TOOLTIP_AVERAGE"] = "Return the average (arithmetic mean) of the numeric values in the list.";
|
||||
Blockly.Msg["MATH_ONLIST_TOOLTIP_MAX"] = "Return the largest number in the list.";
|
||||
Blockly.Msg["MATH_ONLIST_TOOLTIP_MEDIAN"] = "Return the median number in the list.";
|
||||
Blockly.Msg["MATH_ONLIST_TOOLTIP_MIN"] = "Return the smallest number in the list.";
|
||||
Blockly.Msg["MATH_ONLIST_TOOLTIP_MODE"] = "Return a list of the most common item(s) in the list.";
|
||||
Blockly.Msg["MATH_ONLIST_TOOLTIP_RANDOM"] = "Return a random element from the list.";
|
||||
Blockly.Msg["MATH_ONLIST_TOOLTIP_STD_DEV"] = "Return the standard deviation of the list.";
|
||||
Blockly.Msg["MATH_ONLIST_TOOLTIP_SUM"] = "Return the sum of all the numbers in the list.";
|
||||
Blockly.Msg["MATH_POWER_SYMBOL"] = "^";
|
||||
Blockly.Msg["MATH_RANDOM_FLOAT_HELPURL"] = "https://en.wikipedia.org/wiki/Random_number_generation";
|
||||
Blockly.Msg["MATH_RANDOM_FLOAT_TITLE_RANDOM"] = "random fraction";
|
||||
Blockly.Msg["MATH_RANDOM_FLOAT_TOOLTIP"] = "Return a random fraction between 0.0 (inclusive) and 1.0 (exclusive).";
|
||||
Blockly.Msg["MATH_RANDOM_INT_HELPURL"] = "https://en.wikipedia.org/wiki/Random_number_generation";
|
||||
Blockly.Msg["MATH_RANDOM_INT_TITLE"] = "random integer from %1 to %2";
|
||||
Blockly.Msg["MATH_RANDOM_INT_TOOLTIP"] = "Return a random integer between the two specified limits, inclusive.";
|
||||
Blockly.Msg["MATH_ROUND_HELPURL"] = "https://en.wikipedia.org/wiki/Rounding";
|
||||
Blockly.Msg["MATH_ROUND_OPERATOR_ROUND"] = "round";
|
||||
Blockly.Msg["MATH_ROUND_OPERATOR_ROUNDDOWN"] = "round down";
|
||||
Blockly.Msg["MATH_ROUND_OPERATOR_ROUNDUP"] = "round up";
|
||||
Blockly.Msg["MATH_ROUND_TOOLTIP"] = "Round a number up or down.";
|
||||
Blockly.Msg["MATH_SINGLE_HELPURL"] = "https://en.wikipedia.org/wiki/Square_root";
|
||||
Blockly.Msg["MATH_SINGLE_OP_ABSOLUTE"] = "absolute";
|
||||
Blockly.Msg["MATH_SINGLE_OP_ROOT"] = "square root";
|
||||
Blockly.Msg["MATH_SINGLE_TOOLTIP_ABS"] = "Return the absolute value of a number.";
|
||||
Blockly.Msg["MATH_SINGLE_TOOLTIP_EXP"] = "Return e to the power of a number.";
|
||||
Blockly.Msg["MATH_SINGLE_TOOLTIP_LN"] = "Return the natural logarithm of a number.";
|
||||
Blockly.Msg["MATH_SINGLE_TOOLTIP_LOG10"] = "Return the base 10 logarithm of a number.";
|
||||
Blockly.Msg["MATH_SINGLE_TOOLTIP_NEG"] = "Return the negation of a number.";
|
||||
Blockly.Msg["MATH_SINGLE_TOOLTIP_POW10"] = "Return 10 to the power of a number.";
|
||||
Blockly.Msg["MATH_SINGLE_TOOLTIP_ROOT"] = "Return the square root of a number.";
|
||||
Blockly.Msg["MATH_SUBTRACTION_SYMBOL"] = "-";
|
||||
Blockly.Msg["MATH_TRIG_ACOS"] = "acos";
|
||||
Blockly.Msg["MATH_TRIG_ASIN"] = "asin";
|
||||
Blockly.Msg["MATH_TRIG_ATAN"] = "atan";
|
||||
Blockly.Msg["MATH_TRIG_COS"] = "cos";
|
||||
Blockly.Msg["MATH_TRIG_HELPURL"] = "https://en.wikipedia.org/wiki/Trigonometric_functions";
|
||||
Blockly.Msg["MATH_TRIG_SIN"] = "sin";
|
||||
Blockly.Msg["MATH_TRIG_TAN"] = "tan";
|
||||
Blockly.Msg["MATH_TRIG_TOOLTIP_ACOS"] = "Return the arccosine of a number.";
|
||||
Blockly.Msg["MATH_TRIG_TOOLTIP_ASIN"] = "Return the arcsine of a number.";
|
||||
Blockly.Msg["MATH_TRIG_TOOLTIP_ATAN"] = "Return the arctangent of a number.";
|
||||
Blockly.Msg["MATH_TRIG_TOOLTIP_COS"] = "Return the cosine of a degree (not radian).";
|
||||
Blockly.Msg["MATH_TRIG_TOOLTIP_SIN"] = "Return the sine of a degree (not radian).";
|
||||
Blockly.Msg["MATH_TRIG_TOOLTIP_TAN"] = "Return the tangent of a degree (not radian).";
|
||||
Blockly.Msg["NEW_COLOUR_VARIABLE"] = "Create colour variable...";
|
||||
Blockly.Msg["NEW_NUMBER_VARIABLE"] = "Create number variable...";
|
||||
Blockly.Msg["NEW_STRING_VARIABLE"] = "Create string variable...";
|
||||
Blockly.Msg["NEW_VARIABLE"] = "Create variable...";
|
||||
Blockly.Msg["NEW_VARIABLE_TITLE"] = "New variable name:";
|
||||
Blockly.Msg["NEW_VARIABLE_TYPE_TITLE"] = "New variable type:";
|
||||
Blockly.Msg["ORDINAL_NUMBER_SUFFIX"] = "";
|
||||
Blockly.Msg["PROCEDURES_ALLOW_STATEMENTS"] = "allow statements";
|
||||
Blockly.Msg["PROCEDURES_BEFORE_PARAMS"] = "with:";
|
||||
Blockly.Msg["PROCEDURES_CALLNORETURN_HELPURL"] = "https://en.wikipedia.org/wiki/Subroutine";
|
||||
Blockly.Msg["PROCEDURES_CALLNORETURN_TOOLTIP"] = "Run the user-defined function '%1'.";
|
||||
Blockly.Msg["PROCEDURES_CALLRETURN_HELPURL"] = "https://en.wikipedia.org/wiki/Subroutine";
|
||||
Blockly.Msg["PROCEDURES_CALLRETURN_TOOLTIP"] = "Run the user-defined function '%1' and use its output.";
|
||||
Blockly.Msg["PROCEDURES_CALL_BEFORE_PARAMS"] = "with:";
|
||||
Blockly.Msg["PROCEDURES_CALL_DISABLED_DEF_WARNING"] = "Can't run the user-defined function '%1' because the definition block is disabled.";
|
||||
Blockly.Msg["PROCEDURES_CREATE_DO"] = "Create '%1'";
|
||||
Blockly.Msg["PROCEDURES_DEFNORETURN_COMMENT"] = "Describe this function...";
|
||||
Blockly.Msg["PROCEDURES_DEFNORETURN_DO"] = "";
|
||||
Blockly.Msg["PROCEDURES_DEFNORETURN_HELPURL"] = "https://en.wikipedia.org/wiki/Subroutine";
|
||||
Blockly.Msg["PROCEDURES_DEFNORETURN_PROCEDURE"] = "do something";
|
||||
Blockly.Msg["PROCEDURES_DEFNORETURN_TITLE"] = "to";
|
||||
Blockly.Msg["PROCEDURES_DEFNORETURN_TOOLTIP"] = "Creates a function with no output.";
|
||||
Blockly.Msg["PROCEDURES_DEFRETURN_HELPURL"] = "https://en.wikipedia.org/wiki/Subroutine";
|
||||
Blockly.Msg["PROCEDURES_DEFRETURN_RETURN"] = "return";
|
||||
Blockly.Msg["PROCEDURES_DEFRETURN_TOOLTIP"] = "Creates a function with an output.";
|
||||
Blockly.Msg["PROCEDURES_DEF_DUPLICATE_WARNING"] = "Warning: This function has duplicate parameters.";
|
||||
Blockly.Msg["PROCEDURES_HIGHLIGHT_DEF"] = "Highlight function definition";
|
||||
Blockly.Msg["PROCEDURES_IFRETURN_HELPURL"] = "https://c2.com/cgi/wiki?GuardClause";
|
||||
Blockly.Msg["PROCEDURES_IFRETURN_TOOLTIP"] = "If a value is true, then return a second value.";
|
||||
Blockly.Msg["PROCEDURES_IFRETURN_WARNING"] = "Warning: This block may be used only within a function definition.";
|
||||
Blockly.Msg["PROCEDURES_MUTATORARG_TITLE"] = "input name:";
|
||||
Blockly.Msg["PROCEDURES_MUTATORARG_TOOLTIP"] = "Add an input to the function.";
|
||||
Blockly.Msg["PROCEDURES_MUTATORCONTAINER_TITLE"] = "inputs";
|
||||
Blockly.Msg["PROCEDURES_MUTATORCONTAINER_TOOLTIP"] = "Add, remove, or reorder inputs to this function.";
|
||||
Blockly.Msg["REDO"] = "Redo";
|
||||
Blockly.Msg["REMOVE_COMMENT"] = "Remove Comment";
|
||||
Blockly.Msg["RENAME_VARIABLE"] = "Rename variable...";
|
||||
Blockly.Msg["RENAME_VARIABLE_TITLE"] = "Rename all '%1' variables to:";
|
||||
Blockly.Msg["TEXT_APPEND_HELPURL"] = "https://github.com/google/blockly/wiki/Text#text-modification";
|
||||
Blockly.Msg["TEXT_APPEND_TITLE"] = "to %1 append text %2";
|
||||
Blockly.Msg["TEXT_APPEND_TOOLTIP"] = "Append some text to variable '%1'.";
|
||||
Blockly.Msg["TEXT_CHANGECASE_HELPURL"] = "https://github.com/google/blockly/wiki/Text#adjusting-text-case";
|
||||
Blockly.Msg["TEXT_CHANGECASE_OPERATOR_LOWERCASE"] = "to lower case";
|
||||
Blockly.Msg["TEXT_CHANGECASE_OPERATOR_TITLECASE"] = "to Title Case";
|
||||
Blockly.Msg["TEXT_CHANGECASE_OPERATOR_UPPERCASE"] = "to UPPER CASE";
|
||||
Blockly.Msg["TEXT_CHANGECASE_TOOLTIP"] = "Return a copy of the text in a different case.";
|
||||
Blockly.Msg["TEXT_CHARAT_FIRST"] = "get first letter";
|
||||
Blockly.Msg["TEXT_CHARAT_FROM_END"] = "get letter # from end";
|
||||
Blockly.Msg["TEXT_CHARAT_FROM_START"] = "get letter #";
|
||||
Blockly.Msg["TEXT_CHARAT_HELPURL"] = "https://github.com/google/blockly/wiki/Text#extracting-text";
|
||||
Blockly.Msg["TEXT_CHARAT_LAST"] = "get last letter";
|
||||
Blockly.Msg["TEXT_CHARAT_RANDOM"] = "get random letter";
|
||||
Blockly.Msg["TEXT_CHARAT_TAIL"] = "";
|
||||
Blockly.Msg["TEXT_CHARAT_TITLE"] = "in text %1 %2";
|
||||
Blockly.Msg["TEXT_CHARAT_TOOLTIP"] = "Returns the letter at the specified position.";
|
||||
Blockly.Msg["TEXT_COUNT_HELPURL"] = "https://github.com/google/blockly/wiki/Text#counting-substrings";
|
||||
Blockly.Msg["TEXT_COUNT_MESSAGE0"] = "count %1 in %2";
|
||||
Blockly.Msg["TEXT_COUNT_TOOLTIP"] = "Count how many times some text occurs within some other text.";
|
||||
Blockly.Msg["TEXT_CREATE_JOIN_ITEM_TOOLTIP"] = "Add an item to the text.";
|
||||
Blockly.Msg["TEXT_CREATE_JOIN_TITLE_JOIN"] = "join";
|
||||
Blockly.Msg["TEXT_CREATE_JOIN_TOOLTIP"] = "Add, remove, or reorder sections to reconfigure this text block.";
|
||||
Blockly.Msg["TEXT_GET_SUBSTRING_END_FROM_END"] = "to letter # from end";
|
||||
Blockly.Msg["TEXT_GET_SUBSTRING_END_FROM_START"] = "to letter #";
|
||||
Blockly.Msg["TEXT_GET_SUBSTRING_END_LAST"] = "to last letter";
|
||||
Blockly.Msg["TEXT_GET_SUBSTRING_HELPURL"] = "https://github.com/google/blockly/wiki/Text#extracting-a-region-of-text";
|
||||
Blockly.Msg["TEXT_GET_SUBSTRING_INPUT_IN_TEXT"] = "in text";
|
||||
Blockly.Msg["TEXT_GET_SUBSTRING_START_FIRST"] = "get substring from first letter";
|
||||
Blockly.Msg["TEXT_GET_SUBSTRING_START_FROM_END"] = "get substring from letter # from end";
|
||||
Blockly.Msg["TEXT_GET_SUBSTRING_START_FROM_START"] = "get substring from letter #";
|
||||
Blockly.Msg["TEXT_GET_SUBSTRING_TAIL"] = "";
|
||||
Blockly.Msg["TEXT_GET_SUBSTRING_TOOLTIP"] = "Returns a specified portion of the text.";
|
||||
Blockly.Msg["TEXT_INDEXOF_HELPURL"] = "https://github.com/google/blockly/wiki/Text#finding-text";
|
||||
Blockly.Msg["TEXT_INDEXOF_OPERATOR_FIRST"] = "find first occurrence of text";
|
||||
Blockly.Msg["TEXT_INDEXOF_OPERATOR_LAST"] = "find last occurrence of text";
|
||||
Blockly.Msg["TEXT_INDEXOF_TITLE"] = "in text %1 %2 %3";
|
||||
Blockly.Msg["TEXT_INDEXOF_TOOLTIP"] = "Returns the index of the first/last occurrence of the first text in the second text. Returns %1 if text is not found.";
|
||||
Blockly.Msg["TEXT_ISEMPTY_HELPURL"] = "https://github.com/google/blockly/wiki/Text#checking-for-empty-text";
|
||||
Blockly.Msg["TEXT_ISEMPTY_TITLE"] = "%1 is empty";
|
||||
Blockly.Msg["TEXT_ISEMPTY_TOOLTIP"] = "Returns true if the provided text is empty.";
|
||||
Blockly.Msg["TEXT_JOIN_HELPURL"] = "https://github.com/google/blockly/wiki/Text#text-creation";
|
||||
Blockly.Msg["TEXT_JOIN_TITLE_CREATEWITH"] = "create text with";
|
||||
Blockly.Msg["TEXT_JOIN_TOOLTIP"] = "Create a piece of text by joining together any number of items.";
|
||||
Blockly.Msg["TEXT_LENGTH_HELPURL"] = "https://github.com/google/blockly/wiki/Text#text-modification";
|
||||
Blockly.Msg["TEXT_LENGTH_TITLE"] = "length of %1";
|
||||
Blockly.Msg["TEXT_LENGTH_TOOLTIP"] = "Returns the number of letters (including spaces) in the provided text.";
|
||||
Blockly.Msg["TEXT_PRINT_HELPURL"] = "https://github.com/google/blockly/wiki/Text#printing-text";
|
||||
Blockly.Msg["TEXT_PRINT_TITLE"] = "log %1";
|
||||
Blockly.Msg["TEXT_PRINT_TOOLTIP"] = "Logs a message to console.";
|
||||
Blockly.Msg["TEXT_PROMPT_HELPURL"] = "https://github.com/google/blockly/wiki/Text#getting-input-from-the-user";
|
||||
Blockly.Msg["TEXT_PROMPT_TOOLTIP_NUMBER"] = "Prompt for user for a number.";
|
||||
Blockly.Msg["TEXT_PROMPT_TOOLTIP_TEXT"] = "Prompt for user for some text.";
|
||||
Blockly.Msg["TEXT_PROMPT_TYPE_NUMBER"] = "prompt for number with message";
|
||||
Blockly.Msg["TEXT_PROMPT_TYPE_TEXT"] = "prompt for text with message";
|
||||
Blockly.Msg["TEXT_REPLACE_HELPURL"] = "https://github.com/google/blockly/wiki/Text#replacing-substrings";
|
||||
Blockly.Msg["TEXT_REPLACE_MESSAGE0"] = "replace %1 with %2 in %3";
|
||||
Blockly.Msg["TEXT_REPLACE_TOOLTIP"] = "Replace all occurances of some text within some other text.";
|
||||
Blockly.Msg["TEXT_REVERSE_HELPURL"] = "https://github.com/google/blockly/wiki/Text#reversing-text";
|
||||
Blockly.Msg["TEXT_REVERSE_MESSAGE0"] = "reverse %1";
|
||||
Blockly.Msg["TEXT_REVERSE_TOOLTIP"] = "Reverses the order of the characters in the text.";
|
||||
Blockly.Msg["TEXT_TEXT_HELPURL"] = "https://en.wikipedia.org/wiki/String_(computer_science)";
|
||||
Blockly.Msg["TEXT_TEXT_TOOLTIP"] = "A letter, word, or line of text.";
|
||||
Blockly.Msg["TEXT_TRIM_HELPURL"] = "https://github.com/google/blockly/wiki/Text#trimming-removing-spaces";
|
||||
Blockly.Msg["TEXT_TRIM_OPERATOR_BOTH"] = "trim spaces from both sides of";
|
||||
Blockly.Msg["TEXT_TRIM_OPERATOR_LEFT"] = "trim spaces from left side of";
|
||||
Blockly.Msg["TEXT_TRIM_OPERATOR_RIGHT"] = "trim spaces from right side of";
|
||||
Blockly.Msg["TEXT_TRIM_TOOLTIP"] = "Return a copy of the text with spaces removed from one or both ends.";
|
||||
Blockly.Msg["TODAY"] = "Today";
|
||||
Blockly.Msg["UNDO"] = "Undo";
|
||||
Blockly.Msg["UNNAMED_KEY"] = "unnamed";
|
||||
Blockly.Msg["VARIABLES_DEFAULT_NAME"] = "item";
|
||||
Blockly.Msg["VARIABLES_GET_CREATE_SET"] = "Create 'set %1'";
|
||||
Blockly.Msg["VARIABLES_GET_HELPURL"] = "https://github.com/google/blockly/wiki/Variables#get";
|
||||
Blockly.Msg["VARIABLES_GET_TOOLTIP"] = "Returns the value of this variable.";
|
||||
Blockly.Msg["VARIABLES_SET"] = "set %1 to %2";
|
||||
Blockly.Msg["VARIABLES_SET_CREATE_GET"] = "Create 'get %1'";
|
||||
Blockly.Msg["VARIABLES_SET_HELPURL"] = "https://github.com/google/blockly/wiki/Variables#set";
|
||||
Blockly.Msg["VARIABLES_SET_TOOLTIP"] = "Sets this variable to be equal to the input.";
|
||||
Blockly.Msg["VARIABLE_ALREADY_EXISTS"] = "A variable named '%1' already exists.";
|
||||
Blockly.Msg["VARIABLE_ALREADY_EXISTS_FOR_ANOTHER_TYPE"] = "A variable named '%1' already exists for another type: '%2'.";
|
||||
Blockly.Msg["VARIABLE_ALREADY_EXISTS_FOR_A_PARAMETER"] = "A variable named '%1' already exists as a parameter in the procedure '%2'.";
|
||||
Blockly.Msg["WORKSPACE_ARIA_LABEL"] = "Blockly Workspace";
|
||||
Blockly.Msg["WORKSPACE_COMMENT_DEFAULT_TEXT"] = "Say something...";
|
||||
Blockly.Msg["CONTROLS_FOREACH_INPUT_DO"] = Blockly.Msg["CONTROLS_REPEAT_INPUT_DO"];
|
||||
Blockly.Msg["CONTROLS_FOR_INPUT_DO"] = Blockly.Msg["CONTROLS_REPEAT_INPUT_DO"];
|
||||
Blockly.Msg["CONTROLS_IF_ELSEIF_TITLE_ELSEIF"] = Blockly.Msg["CONTROLS_IF_MSG_ELSEIF"];
|
||||
Blockly.Msg["CONTROLS_IF_ELSE_TITLE_ELSE"] = Blockly.Msg["CONTROLS_IF_MSG_ELSE"];
|
||||
Blockly.Msg["CONTROLS_IF_IF_TITLE_IF"] = Blockly.Msg["CONTROLS_IF_MSG_IF"];
|
||||
Blockly.Msg["CONTROLS_IF_MSG_THEN"] = Blockly.Msg["CONTROLS_REPEAT_INPUT_DO"];
|
||||
Blockly.Msg["CONTROLS_WHILEUNTIL_INPUT_DO"] = Blockly.Msg["CONTROLS_REPEAT_INPUT_DO"];
|
||||
Blockly.Msg["LISTS_CREATE_WITH_ITEM_TITLE"] = Blockly.Msg["VARIABLES_DEFAULT_NAME"];
|
||||
Blockly.Msg["LISTS_GET_INDEX_INPUT_IN_LIST"] = Blockly.Msg["LISTS_INLIST"];
|
||||
Blockly.Msg["LISTS_GET_SUBLIST_INPUT_IN_LIST"] = Blockly.Msg["LISTS_INLIST"];
|
||||
Blockly.Msg["LISTS_INDEX_OF_INPUT_IN_LIST"] = Blockly.Msg["LISTS_INLIST"];
|
||||
Blockly.Msg["LISTS_SET_INDEX_INPUT_IN_LIST"] = Blockly.Msg["LISTS_INLIST"];
|
||||
Blockly.Msg["MATH_CHANGE_TITLE_ITEM"] = Blockly.Msg["VARIABLES_DEFAULT_NAME"];
|
||||
Blockly.Msg["PROCEDURES_DEFRETURN_COMMENT"] = Blockly.Msg["PROCEDURES_DEFNORETURN_COMMENT"];
|
||||
Blockly.Msg["PROCEDURES_DEFRETURN_DO"] = Blockly.Msg["PROCEDURES_DEFNORETURN_DO"];
|
||||
Blockly.Msg["PROCEDURES_DEFRETURN_PROCEDURE"] = Blockly.Msg["PROCEDURES_DEFNORETURN_PROCEDURE"];
|
||||
Blockly.Msg["PROCEDURES_DEFRETURN_TITLE"] = Blockly.Msg["PROCEDURES_DEFNORETURN_TITLE"];
|
||||
Blockly.Msg["TEXT_APPEND_VARIABLE"] = Blockly.Msg["VARIABLES_DEFAULT_NAME"];
|
||||
Blockly.Msg["TEXT_CREATE_JOIN_ITEM_TITLE_ITEM"] = Blockly.Msg["VARIABLES_DEFAULT_NAME"];
|
||||
|
||||
Blockly.Msg["COLOUR_HUE"] = "20";
|
||||
Blockly.Msg["LISTS_HUE"] = "260";
|
||||
Blockly.Msg["LOGIC_HUE"] = "210";
|
||||
Blockly.Msg["LOOPS_HUE"] = "120";
|
||||
Blockly.Msg["MATH_HUE"] = "230";
|
||||
Blockly.Msg["PROCEDURES_HUE"] = "290";
|
||||
Blockly.Msg["TEXTS_HUE"] = "160";
|
||||
Blockly.Msg["VARIABLES_DYNAMIC_HUE"] = "310";
|
||||
Blockly.Msg["VARIABLES_HUE"] = "330";
|
||||
return Blockly.Msg;
|
||||
}));
|
||||
@@ -0,0 +1,264 @@
|
||||
// Do not edit this file; automatically generated.
|
||||
|
||||
/* eslint-disable */
|
||||
;(function(root, factory) {
|
||||
if (typeof define === 'function' && define.amd) { // AMD
|
||||
define(["./blockly_compressed.js"], factory);
|
||||
} else if (typeof exports === 'object') { // Node.js
|
||||
module.exports = factory(require("./blockly_compressed.js"));
|
||||
} else { // Script
|
||||
root.javascript = factory(root.Blockly);
|
||||
root.Blockly.JavaScript = root.javascript.javascriptGenerator;
|
||||
}
|
||||
}(this, function(__parent__) {
|
||||
var $=__parent__.__namespace__;
|
||||
var lists_create_empty$$module$build$src$generators$javascript$lists=function(a,b){return["[]",Order$$module$build$src$generators$javascript$javascript_generator.ATOMIC]},lists_create_with$$module$build$src$generators$javascript$lists=function(a,b){const c=Array(a.itemCount_);for(let d=0;d<a.itemCount_;d++)c[d]=b.valueToCode(a,"ADD"+d,Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"null";return["["+c.join(", ")+"]",Order$$module$build$src$generators$javascript$javascript_generator.ATOMIC]},
|
||||
lists_repeat$$module$build$src$generators$javascript$lists=function(a,b){const c=b.provideFunction_("listsRepeat",`
|
||||
function ${b.FUNCTION_NAME_PLACEHOLDER_}(value, n) {
|
||||
var array = [];
|
||||
for (var i = 0; i < n; i++) {
|
||||
array[i] = value;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
`),d=b.valueToCode(a,"ITEM",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"null";a=b.valueToCode(a,"NUM",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"0";return[c+"("+d+", "+a+")",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},lists_length$$module$build$src$generators$javascript$lists=function(a,b){return[(b.valueToCode(a,"VALUE",Order$$module$build$src$generators$javascript$javascript_generator.MEMBER)||
|
||||
"[]")+".length",Order$$module$build$src$generators$javascript$javascript_generator.MEMBER]},lists_isEmpty$$module$build$src$generators$javascript$lists=function(a,b){return["!"+(b.valueToCode(a,"VALUE",Order$$module$build$src$generators$javascript$javascript_generator.MEMBER)||"[]")+".length",Order$$module$build$src$generators$javascript$javascript_generator.LOGICAL_NOT]},lists_indexOf$$module$build$src$generators$javascript$lists=function(a,b){const c="FIRST"===a.getFieldValue("END")?"indexOf":"lastIndexOf",
|
||||
d=b.valueToCode(a,"FIND",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"''";b=(b.valueToCode(a,"VALUE",Order$$module$build$src$generators$javascript$javascript_generator.MEMBER)||"[]")+"."+c+"("+d+")";return a.workspace.options.oneBasedIndex?[b+" + 1",Order$$module$build$src$generators$javascript$javascript_generator.ADDITION]:[b,Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},lists_getIndex$$module$build$src$generators$javascript$lists=
|
||||
function(a,b){const c=a.getFieldValue("MODE")||"GET",d=a.getFieldValue("WHERE")||"FROM_START";var e=b.valueToCode(a,"VALUE","RANDOM"===d?Order$$module$build$src$generators$javascript$javascript_generator.NONE:Order$$module$build$src$generators$javascript$javascript_generator.MEMBER)||"[]";switch(d){case "FIRST":if("GET"===c)return[e+"[0]",Order$$module$build$src$generators$javascript$javascript_generator.MEMBER];if("GET_REMOVE"===c)return[e+".shift()",Order$$module$build$src$generators$javascript$javascript_generator.MEMBER];
|
||||
if("REMOVE"===c)return e+".shift();\n";break;case "LAST":if("GET"===c)return[e+".slice(-1)[0]",Order$$module$build$src$generators$javascript$javascript_generator.MEMBER];if("GET_REMOVE"===c)return[e+".pop()",Order$$module$build$src$generators$javascript$javascript_generator.MEMBER];if("REMOVE"===c)return e+".pop();\n";break;case "FROM_START":a=b.getAdjusted(a,"AT");if("GET"===c)return[e+"["+a+"]",Order$$module$build$src$generators$javascript$javascript_generator.MEMBER];if("GET_REMOVE"===c)return[e+
|
||||
".splice("+a+", 1)[0]",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL];if("REMOVE"===c)return e+".splice("+a+", 1);\n";break;case "FROM_END":a=b.getAdjusted(a,"AT",1,!0);if("GET"===c)return[e+".slice("+a+")[0]",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL];if("GET_REMOVE"===c)return[e+".splice("+a+", 1)[0]",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL];if("REMOVE"===c)return e+".splice("+a+", 1);";
|
||||
break;case "RANDOM":e=b.provideFunction_("listsGetRandomItem",`
|
||||
function ${b.FUNCTION_NAME_PLACEHOLDER_}(list, remove) {
|
||||
var x = Math.floor(Math.random() * list.length);
|
||||
if (remove) {
|
||||
return list.splice(x, 1)[0];
|
||||
} else {
|
||||
return list[x];
|
||||
}
|
||||
}
|
||||
`)+"("+e+", "+("GET"!==c)+")";if("GET"===c||"GET_REMOVE"===c)return[e,Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL];if("REMOVE"===c)return e+";\n"}throw Error("Unhandled combination (lists_getIndex).");},lists_setIndex$$module$build$src$generators$javascript$lists=function(a,b){function c(){if(d.match(/^\w+$/))return"";const h=b.nameDB_.getDistinctName("tmpList",$.NameType$$module$build$src$core$names.VARIABLE),k="var "+h+" = "+d+";\n";d=h;return k}let d=b.valueToCode(a,
|
||||
"LIST",Order$$module$build$src$generators$javascript$javascript_generator.MEMBER)||"[]";const e=a.getFieldValue("MODE")||"GET";var f=a.getFieldValue("WHERE")||"FROM_START";const g=b.valueToCode(a,"TO",Order$$module$build$src$generators$javascript$javascript_generator.ASSIGNMENT)||"null";switch(f){case "FIRST":if("SET"===e)return d+"[0] = "+g+";\n";if("INSERT"===e)return d+".unshift("+g+");\n";break;case "LAST":if("SET"===e)return c()+(d+"["+d+".length - 1] = "+g+";\n");if("INSERT"===e)return d+".push("+
|
||||
g+");\n";break;case "FROM_START":a=b.getAdjusted(a,"AT");if("SET"===e)return d+"["+a+"] = "+g+";\n";if("INSERT"===e)return d+".splice("+a+", 0, "+g+");\n";break;case "FROM_END":a=b.getAdjusted(a,"AT",1,!1,Order$$module$build$src$generators$javascript$javascript_generator.SUBTRACTION);f=c();if("SET"===e)return f+(d+"["+d+".length - "+a+"] = "+g+";\n");if("INSERT"===e)return f+(d+".splice("+d+".length - "+a+", 0, "+g+");\n");break;case "RANDOM":a=c();f=b.nameDB_.getDistinctName("tmpX",$.NameType$$module$build$src$core$names.VARIABLE);
|
||||
a+="var "+f+" = Math.floor(Math.random() * "+d+".length);\n";if("SET"===e)return a+(d+"["+f+"] = "+g+";\n");if("INSERT"===e)return a+(d+".splice("+f+", 0, "+g+");\n")}throw Error("Unhandled combination (lists_setIndex).");},lists_getSublist$$module$build$src$generators$javascript$lists=function(a,b){var c={FIRST:"First",LAST:"Last",FROM_START:"FromStart",FROM_END:"FromEnd"},d=b.valueToCode(a,"LIST",Order$$module$build$src$generators$javascript$javascript_generator.MEMBER)||"[]";const e=a.getFieldValue("WHERE1"),
|
||||
f=a.getFieldValue("WHERE2");if("FIRST"===e&&"LAST"===f)d+=".slice(0)";else if(d.match(/^\w+$/)||"FROM_END"!==e&&"FROM_START"===f){switch(e){case "FROM_START":c=b.getAdjusted(a,"AT1");break;case "FROM_END":c=b.getAdjusted(a,"AT1",1,!1,Order$$module$build$src$generators$javascript$javascript_generator.SUBTRACTION);c=d+".length - "+c;break;case "FIRST":c="0";break;default:throw Error("Unhandled option (lists_getSublist).");}switch(f){case "FROM_START":b=b.getAdjusted(a,"AT2",1);break;case "FROM_END":b=
|
||||
b.getAdjusted(a,"AT2",0,!1,Order$$module$build$src$generators$javascript$javascript_generator.SUBTRACTION);b=d+".length - "+b;break;case "LAST":b=d+".length";break;default:throw Error("Unhandled option (lists_getSublist).");}d=d+".slice("+c+", "+b+")"}else{const g=b.getAdjusted(a,"AT1");a=b.getAdjusted(a,"AT2");d=b.provideFunction_("subsequence"+c[e]+c[f],`
|
||||
function ${b.FUNCTION_NAME_PLACEHOLDER_}(sequence${"FROM_END"===e||"FROM_START"===e?", at1":""}${"FROM_END"===f||"FROM_START"===f?", at2":""}) {
|
||||
var start = ${getSubstringIndex$$module$build$src$generators$javascript$lists("sequence",e,"at1")};
|
||||
var end = ${getSubstringIndex$$module$build$src$generators$javascript$lists("sequence",f,"at2")} + 1;
|
||||
return sequence.slice(start, end);
|
||||
}
|
||||
`)+"("+d+("FROM_END"===e||"FROM_START"===e?", "+g:"")+("FROM_END"===f||"FROM_START"===f?", "+a:"")+")"}return[d,Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},lists_sort$$module$build$src$generators$javascript$lists=function(a,b){const c=b.valueToCode(a,"LIST",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL)||"[]",d="1"===a.getFieldValue("DIRECTION")?1:-1;a=a.getFieldValue("TYPE");b=b.provideFunction_("listsGetSortCompare",`
|
||||
function ${b.FUNCTION_NAME_PLACEHOLDER_}(type, direction) {
|
||||
var compareFuncs = {
|
||||
'NUMERIC': function(a, b) {
|
||||
return Number(a) - Number(b); },
|
||||
'TEXT': function(a, b) {
|
||||
return String(a) > String(b) ? 1 : -1; },
|
||||
'IGNORE_CASE': function(a, b) {
|
||||
return String(a).toLowerCase() > String(b).toLowerCase() ? 1 : -1; },
|
||||
};
|
||||
var compare = compareFuncs[type];
|
||||
return function(a, b) { return compare(a, b) * direction; };
|
||||
}
|
||||
`);return[c+".slice().sort("+b+'("'+a+'", '+d+"))",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},lists_split$$module$build$src$generators$javascript$lists=function(a,b){let c=b.valueToCode(a,"INPUT",Order$$module$build$src$generators$javascript$javascript_generator.MEMBER);b=b.valueToCode(a,"DELIM",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"''";a=a.getFieldValue("MODE");if("SPLIT"===a)c||(c="''"),a="split";else if("JOIN"===
|
||||
a)c||(c="[]"),a="join";else throw Error("Unknown mode: "+a);return[c+"."+a+"("+b+")",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},lists_reverse$$module$build$src$generators$javascript$lists=function(a,b){return[(b.valueToCode(a,"LIST",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL)||"[]")+".slice().reverse()",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},controls_if$$module$build$src$generators$javascript$logic=
|
||||
function(a,b){var c=0;let d="";b.STATEMENT_PREFIX&&(d+=b.injectId(b.STATEMENT_PREFIX,a));do{const e=b.valueToCode(a,"IF"+c,Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"false";let f=b.statementToCode(a,"DO"+c);b.STATEMENT_SUFFIX&&(f=b.prefixLines(b.injectId(b.STATEMENT_SUFFIX,a),b.INDENT)+f);d+=(0<c?" else ":"")+"if ("+e+") {\n"+f+"}";c++}while(a.getInput("IF"+c));if(a.getInput("ELSE")||b.STATEMENT_SUFFIX)c=b.statementToCode(a,"ELSE"),b.STATEMENT_SUFFIX&&(c=b.prefixLines(b.injectId(b.STATEMENT_SUFFIX,
|
||||
a),b.INDENT)+c),d+=" else {\n"+c+"}";return d+"\n"},logic_compare$$module$build$src$generators$javascript$logic=function(a,b){const c={EQ:"==",NEQ:"!=",LT:"<",LTE:"<=",GT:">",GTE:">="}[a.getFieldValue("OP")],d="=="===c||"!="===c?Order$$module$build$src$generators$javascript$javascript_generator.EQUALITY:Order$$module$build$src$generators$javascript$javascript_generator.RELATIONAL,e=b.valueToCode(a,"A",d)||"0";a=b.valueToCode(a,"B",d)||"0";return[e+" "+c+" "+a,d]},logic_operation$$module$build$src$generators$javascript$logic=
|
||||
function(a,b){const c="AND"===a.getFieldValue("OP")?"&&":"||",d="&&"===c?Order$$module$build$src$generators$javascript$javascript_generator.LOGICAL_AND:Order$$module$build$src$generators$javascript$javascript_generator.LOGICAL_OR;let e=b.valueToCode(a,"A",d);a=b.valueToCode(a,"B",d);e||a?(b="&&"===c?"true":"false",e||(e=b),a||(a=b)):a=e="false";return[e+" "+c+" "+a,d]},logic_negate$$module$build$src$generators$javascript$logic=function(a,b){const c=Order$$module$build$src$generators$javascript$javascript_generator.LOGICAL_NOT;
|
||||
return["!"+(b.valueToCode(a,"BOOL",c)||"true"),c]},logic_boolean$$module$build$src$generators$javascript$logic=function(a,b){return["TRUE"===a.getFieldValue("BOOL")?"true":"false",Order$$module$build$src$generators$javascript$javascript_generator.ATOMIC]},logic_null$$module$build$src$generators$javascript$logic=function(a,b){return["null",Order$$module$build$src$generators$javascript$javascript_generator.ATOMIC]},logic_ternary$$module$build$src$generators$javascript$logic=function(a,b){const c=b.valueToCode(a,
|
||||
"IF",Order$$module$build$src$generators$javascript$javascript_generator.CONDITIONAL)||"false",d=b.valueToCode(a,"THEN",Order$$module$build$src$generators$javascript$javascript_generator.CONDITIONAL)||"null";a=b.valueToCode(a,"ELSE",Order$$module$build$src$generators$javascript$javascript_generator.CONDITIONAL)||"null";return[c+" ? "+d+" : "+a,Order$$module$build$src$generators$javascript$javascript_generator.CONDITIONAL]},controls_repeat_ext$$module$build$src$generators$javascript$loops=function(a,
|
||||
b){let c;c=a.getField("TIMES")?String(Number(a.getFieldValue("TIMES"))):b.valueToCode(a,"TIMES",Order$$module$build$src$generators$javascript$javascript_generator.ASSIGNMENT)||"0";let d=b.statementToCode(a,"DO");d=b.addLoopTrap(d,a);a="";const e=b.nameDB_.getDistinctName("count",$.NameType$$module$build$src$core$names.VARIABLE);let f=c;c.match(/^\w+$/)||$.isNumber$$module$build$src$core$utils$string(c)||(f=b.nameDB_.getDistinctName("repeat_end",$.NameType$$module$build$src$core$names.VARIABLE),a+=
|
||||
"var "+f+" = "+c+";\n");return a+("for (var "+e+" = 0; "+e+" < "+f+"; "+e+"++) {\n"+d+"}\n")},controls_whileUntil$$module$build$src$generators$javascript$loops=function(a,b){const c="UNTIL"===a.getFieldValue("MODE");let d=b.valueToCode(a,"BOOL",c?Order$$module$build$src$generators$javascript$javascript_generator.LOGICAL_NOT:Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"false",e=b.statementToCode(a,"DO");e=b.addLoopTrap(e,a);c&&(d="!"+d);return"while ("+d+") {\n"+e+"}\n"},
|
||||
controls_for$$module$build$src$generators$javascript$loops=function(a,b){var c=b.getVariableName(a.getFieldValue("VAR")),d=b.valueToCode(a,"FROM",Order$$module$build$src$generators$javascript$javascript_generator.ASSIGNMENT)||"0",e=b.valueToCode(a,"TO",Order$$module$build$src$generators$javascript$javascript_generator.ASSIGNMENT)||"0";const f=b.valueToCode(a,"BY",Order$$module$build$src$generators$javascript$javascript_generator.ASSIGNMENT)||"1";let g=b.statementToCode(a,"DO");g=b.addLoopTrap(g,a);
|
||||
if($.isNumber$$module$build$src$core$utils$string(d)&&$.isNumber$$module$build$src$core$utils$string(e)&&$.isNumber$$module$build$src$core$utils$string(f))b=Number(d)<=Number(e),a="for ("+c+" = "+d+"; "+c+(b?" <= ":" >= ")+e+"; "+c,c=Math.abs(Number(f)),a=1===c?a+(b?"++":"--"):a+((b?" += ":" -= ")+c),a+=") {\n"+g+"}\n";else{a="";let h=d;d.match(/^\w+$/)||$.isNumber$$module$build$src$core$utils$string(d)||(h=b.nameDB_.getDistinctName(c+"_start",$.NameType$$module$build$src$core$names.VARIABLE),a+=
|
||||
"var "+h+" = "+d+";\n");d=e;e.match(/^\w+$/)||$.isNumber$$module$build$src$core$utils$string(e)||(d=b.nameDB_.getDistinctName(c+"_end",$.NameType$$module$build$src$core$names.VARIABLE),a+="var "+d+" = "+e+";\n");e=b.nameDB_.getDistinctName(c+"_inc",$.NameType$$module$build$src$core$names.VARIABLE);a+="var "+e+" = ";a=$.isNumber$$module$build$src$core$utils$string(f)?a+(Math.abs(Number(f))+";\n"):a+("Math.abs("+f+");\n");a+="if ("+h+" > "+d+") {\n";a+=b.INDENT+e+" = -"+e+";\n";a=a+"}\nfor ("+(c+" = "+
|
||||
h+"; "+e+" >= 0 ? "+c+" <= "+d+" : "+c+" >= "+d+"; "+c+" += "+e+") {\n"+g+"}\n")}return a},controls_forEach$$module$build$src$generators$javascript$loops=function(a,b){const c=b.getVariableName(a.getFieldValue("VAR"));var d=b.valueToCode(a,"LIST",Order$$module$build$src$generators$javascript$javascript_generator.ASSIGNMENT)||"[]";let e=b.statementToCode(a,"DO");e=b.addLoopTrap(e,a);a="";let f=d;d.match(/^\w+$/)||(f=b.nameDB_.getDistinctName(c+"_list",$.NameType$$module$build$src$core$names.VARIABLE),
|
||||
a+="var "+f+" = "+d+";\n");d=b.nameDB_.getDistinctName(c+"_index",$.NameType$$module$build$src$core$names.VARIABLE);e=b.INDENT+c+" = "+f+"["+d+"];\n"+e;return a+("for (var "+d+" in "+f+") {\n"+e+"}\n")},controls_flow_statements$$module$build$src$generators$javascript$loops=function(a,b){let c="";b.STATEMENT_PREFIX&&(c+=b.injectId(b.STATEMENT_PREFIX,a));b.STATEMENT_SUFFIX&&(c+=b.injectId(b.STATEMENT_SUFFIX,a));if(b.STATEMENT_PREFIX){const d=a.getSurroundLoop();d&&!d.suppressPrefixSuffix&&(c+=b.injectId(b.STATEMENT_PREFIX,
|
||||
d))}switch(a.getFieldValue("FLOW")){case "BREAK":return c+"break;\n";case "CONTINUE":return c+"continue;\n"}throw Error("Unknown flow statement.");},math_number$$module$build$src$generators$javascript$math=function(a,b){a=Number(a.getFieldValue("NUM"));return[String(a),0<=a?Order$$module$build$src$generators$javascript$javascript_generator.ATOMIC:Order$$module$build$src$generators$javascript$javascript_generator.UNARY_NEGATION]},math_arithmetic$$module$build$src$generators$javascript$math=function(a,
|
||||
b){var c={ADD:[" + ",Order$$module$build$src$generators$javascript$javascript_generator.ADDITION],MINUS:[" - ",Order$$module$build$src$generators$javascript$javascript_generator.SUBTRACTION],MULTIPLY:[" * ",Order$$module$build$src$generators$javascript$javascript_generator.MULTIPLICATION],DIVIDE:[" / ",Order$$module$build$src$generators$javascript$javascript_generator.DIVISION],POWER:[null,Order$$module$build$src$generators$javascript$javascript_generator.NONE]}[a.getFieldValue("OP")];const d=c[0];
|
||||
c=c[1];const e=b.valueToCode(a,"A",c)||"0";a=b.valueToCode(a,"B",c)||"0";return d?[e+d+a,c]:["Math.pow("+e+", "+a+")",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},math_single$$module$build$src$generators$javascript$math=function(a,b){const c=a.getFieldValue("OP");let d;if("NEG"===c)return a=b.valueToCode(a,"NUM",Order$$module$build$src$generators$javascript$javascript_generator.UNARY_NEGATION)||"0","-"===a[0]&&(a=" "+a),["-"+a,Order$$module$build$src$generators$javascript$javascript_generator.UNARY_NEGATION];
|
||||
a="SIN"===c||"COS"===c||"TAN"===c?b.valueToCode(a,"NUM",Order$$module$build$src$generators$javascript$javascript_generator.DIVISION)||"0":b.valueToCode(a,"NUM",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"0";switch(c){case "ABS":d="Math.abs("+a+")";break;case "ROOT":d="Math.sqrt("+a+")";break;case "LN":d="Math.log("+a+")";break;case "EXP":d="Math.exp("+a+")";break;case "POW10":d="Math.pow(10,"+a+")";break;case "ROUND":d="Math.round("+a+")";break;case "ROUNDUP":d="Math.ceil("+
|
||||
a+")";break;case "ROUNDDOWN":d="Math.floor("+a+")";break;case "SIN":d="Math.sin("+a+" / 180 * Math.PI)";break;case "COS":d="Math.cos("+a+" / 180 * Math.PI)";break;case "TAN":d="Math.tan("+a+" / 180 * Math.PI)"}if(d)return[d,Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL];switch(c){case "LOG10":d="Math.log("+a+") / Math.log(10)";break;case "ASIN":d="Math.asin("+a+") / Math.PI * 180";break;case "ACOS":d="Math.acos("+a+") / Math.PI * 180";break;case "ATAN":d="Math.atan("+
|
||||
a+") / Math.PI * 180";break;default:throw Error("Unknown math operator: "+c);}return[d,Order$$module$build$src$generators$javascript$javascript_generator.DIVISION]},math_constant$$module$build$src$generators$javascript$math=function(a,b){return{PI:["Math.PI",Order$$module$build$src$generators$javascript$javascript_generator.MEMBER],E:["Math.E",Order$$module$build$src$generators$javascript$javascript_generator.MEMBER],GOLDEN_RATIO:["(1 + Math.sqrt(5)) / 2",Order$$module$build$src$generators$javascript$javascript_generator.DIVISION],
|
||||
SQRT2:["Math.SQRT2",Order$$module$build$src$generators$javascript$javascript_generator.MEMBER],SQRT1_2:["Math.SQRT1_2",Order$$module$build$src$generators$javascript$javascript_generator.MEMBER],INFINITY:["Infinity",Order$$module$build$src$generators$javascript$javascript_generator.ATOMIC]}[a.getFieldValue("CONSTANT")]},math_number_property$$module$build$src$generators$javascript$math=function(a,b){var c={EVEN:[" % 2 === 0",Order$$module$build$src$generators$javascript$javascript_generator.MODULUS,
|
||||
Order$$module$build$src$generators$javascript$javascript_generator.EQUALITY],ODD:[" % 2 === 1",Order$$module$build$src$generators$javascript$javascript_generator.MODULUS,Order$$module$build$src$generators$javascript$javascript_generator.EQUALITY],WHOLE:[" % 1 === 0",Order$$module$build$src$generators$javascript$javascript_generator.MODULUS,Order$$module$build$src$generators$javascript$javascript_generator.EQUALITY],POSITIVE:[" > 0",Order$$module$build$src$generators$javascript$javascript_generator.RELATIONAL,
|
||||
Order$$module$build$src$generators$javascript$javascript_generator.RELATIONAL],NEGATIVE:[" < 0",Order$$module$build$src$generators$javascript$javascript_generator.RELATIONAL,Order$$module$build$src$generators$javascript$javascript_generator.RELATIONAL],DIVISIBLE_BY:[null,Order$$module$build$src$generators$javascript$javascript_generator.MODULUS,Order$$module$build$src$generators$javascript$javascript_generator.EQUALITY],PRIME:[null,Order$$module$build$src$generators$javascript$javascript_generator.NONE,
|
||||
Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]};const d=a.getFieldValue("PROPERTY"),[e,f,g]=c[d];c=b.valueToCode(a,"NUMBER_TO_CHECK",f)||"0";"PRIME"===d?a=b.provideFunction_("mathIsPrime",`
|
||||
function ${b.FUNCTION_NAME_PLACEHOLDER_}(n) {
|
||||
// https://en.wikipedia.org/wiki/Primality_test#Naive_methods
|
||||
if (n == 2 || n == 3) {
|
||||
return true;
|
||||
}
|
||||
// False if n is NaN, negative, is 1, or not whole.
|
||||
// And false if n is divisible by 2 or 3.
|
||||
if (isNaN(n) || n <= 1 || n % 1 !== 0 || n % 2 === 0 || n % 3 === 0) {
|
||||
return false;
|
||||
}
|
||||
// Check all the numbers of form 6k +/- 1, up to sqrt(n).
|
||||
for (var x = 6; x <= Math.sqrt(n) + 1; x += 6) {
|
||||
if (n % (x - 1) === 0 || n % (x + 1) === 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
`)+"("+c+")":"DIVISIBLE_BY"===d?(a=b.valueToCode(a,"DIVISOR",Order$$module$build$src$generators$javascript$javascript_generator.MODULUS)||"0",a=c+" % "+a+" === 0"):a=c+e;return[a,g]},math_change$$module$build$src$generators$javascript$math=function(a,b){const c=b.valueToCode(a,"DELTA",Order$$module$build$src$generators$javascript$javascript_generator.ADDITION)||"0";a=b.getVariableName(a.getFieldValue("VAR"));return a+" = (typeof "+a+" === 'number' ? "+a+" : 0) + "+c+";\n"},math_on_list$$module$build$src$generators$javascript$math=
|
||||
function(a,b){var c=a.getFieldValue("OP");switch(c){case "SUM":a=b.valueToCode(a,"LIST",Order$$module$build$src$generators$javascript$javascript_generator.MEMBER)||"[]";a+=".reduce(function(x, y) {return x + y;}, 0)";break;case "MIN":a=b.valueToCode(a,"LIST",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"[]";a="Math.min.apply(null, "+a+")";break;case "MAX":a=b.valueToCode(a,"LIST",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"[]";a="Math.max.apply(null, "+
|
||||
a+")";break;case "AVERAGE":c=b.provideFunction_("mathMean",`
|
||||
function ${b.FUNCTION_NAME_PLACEHOLDER_}(myList) {
|
||||
return myList.reduce(function(x, y) {return x + y;}, 0) / myList.length;
|
||||
}
|
||||
`);a=b.valueToCode(a,"LIST",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"[]";a=c+"("+a+")";break;case "MEDIAN":c=b.provideFunction_("mathMedian",`
|
||||
function ${b.FUNCTION_NAME_PLACEHOLDER_}(myList) {
|
||||
var localList = myList.filter(function (x) {return typeof x === 'number';});
|
||||
if (!localList.length) return null;
|
||||
localList.sort(function(a, b) {return b - a;});
|
||||
if (localList.length % 2 === 0) {
|
||||
return (localList[localList.length / 2 - 1] + localList[localList.length / 2]) / 2;
|
||||
} else {
|
||||
return localList[(localList.length - 1) / 2];
|
||||
}
|
||||
}
|
||||
`);a=b.valueToCode(a,"LIST",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"[]";a=c+"("+a+")";break;case "MODE":c=b.provideFunction_("mathModes",`
|
||||
function ${b.FUNCTION_NAME_PLACEHOLDER_}(values) {
|
||||
var modes = [];
|
||||
var counts = [];
|
||||
var maxCount = 0;
|
||||
for (var i = 0; i < values.length; i++) {
|
||||
var value = values[i];
|
||||
var found = false;
|
||||
var thisCount;
|
||||
for (var j = 0; j < counts.length; j++) {
|
||||
if (counts[j][0] === value) {
|
||||
thisCount = ++counts[j][1];
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
counts.push([value, 1]);
|
||||
thisCount = 1;
|
||||
}
|
||||
maxCount = Math.max(thisCount, maxCount);
|
||||
}
|
||||
for (var j = 0; j < counts.length; j++) {
|
||||
if (counts[j][1] === maxCount) {
|
||||
modes.push(counts[j][0]);
|
||||
}
|
||||
}
|
||||
return modes;
|
||||
}
|
||||
`);a=b.valueToCode(a,"LIST",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"[]";a=c+"("+a+")";break;case "STD_DEV":c=b.provideFunction_("mathStandardDeviation",`
|
||||
function ${b.FUNCTION_NAME_PLACEHOLDER_}(numbers) {
|
||||
var n = numbers.length;
|
||||
if (!n) return null;
|
||||
var mean = numbers.reduce(function(x, y) {return x + y;}) / n;
|
||||
var variance = 0;
|
||||
for (var j = 0; j < n; j++) {
|
||||
variance += Math.pow(numbers[j] - mean, 2);
|
||||
}
|
||||
variance /= n;
|
||||
return Math.sqrt(variance);
|
||||
}
|
||||
`);a=b.valueToCode(a,"LIST",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"[]";a=c+"("+a+")";break;case "RANDOM":c=b.provideFunction_("mathRandomList",`
|
||||
function ${b.FUNCTION_NAME_PLACEHOLDER_}(list) {
|
||||
var x = Math.floor(Math.random() * list.length);
|
||||
return list[x];
|
||||
}
|
||||
`);a=b.valueToCode(a,"LIST",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"[]";a=c+"("+a+")";break;default:throw Error("Unknown operator: "+c);}return[a,Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},math_modulo$$module$build$src$generators$javascript$math=function(a,b){const c=b.valueToCode(a,"DIVIDEND",Order$$module$build$src$generators$javascript$javascript_generator.MODULUS)||"0";a=b.valueToCode(a,"DIVISOR",Order$$module$build$src$generators$javascript$javascript_generator.MODULUS)||
|
||||
"0";return[c+" % "+a,Order$$module$build$src$generators$javascript$javascript_generator.MODULUS]},math_constrain$$module$build$src$generators$javascript$math=function(a,b){const c=b.valueToCode(a,"VALUE",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"0",d=b.valueToCode(a,"LOW",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"0";a=b.valueToCode(a,"HIGH",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"Infinity";return["Math.min(Math.max("+
|
||||
c+", "+d+"), "+a+")",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},math_random_int$$module$build$src$generators$javascript$math=function(a,b){const c=b.valueToCode(a,"FROM",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"0";a=b.valueToCode(a,"TO",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"0";return[b.provideFunction_("mathRandomInt",`
|
||||
function ${b.FUNCTION_NAME_PLACEHOLDER_}(a, b) {
|
||||
if (a > b) {
|
||||
// Swap a and b to ensure a is smaller.
|
||||
var c = a;
|
||||
a = b;
|
||||
b = c;
|
||||
}
|
||||
return Math.floor(Math.random() * (b - a + 1) + a);
|
||||
}
|
||||
`)+"("+c+", "+a+")",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},math_random_float$$module$build$src$generators$javascript$math=function(a,b){return["Math.random()",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},math_atan2$$module$build$src$generators$javascript$math=function(a,b){const c=b.valueToCode(a,"X",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"0";return["Math.atan2("+(b.valueToCode(a,"Y",
|
||||
Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"0")+", "+c+") / Math.PI * 180",Order$$module$build$src$generators$javascript$javascript_generator.DIVISION]},procedures_defreturn$$module$build$src$generators$javascript$procedures=function(a,b){const c=b.getProcedureName(a.getFieldValue("NAME"));var d="";b.STATEMENT_PREFIX&&(d+=b.injectId(b.STATEMENT_PREFIX,a));b.STATEMENT_SUFFIX&&(d+=b.injectId(b.STATEMENT_SUFFIX,a));d&&(d=b.prefixLines(d,b.INDENT));let e="";b.INFINITE_LOOP_TRAP&&
|
||||
(e=b.prefixLines(b.injectId(b.INFINITE_LOOP_TRAP,a),b.INDENT));let f="";a.getInput("STACK")&&(f=b.statementToCode(a,"STACK"));let g="";a.getInput("RETURN")&&(g=b.valueToCode(a,"RETURN",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"");let h="";f&&g&&(h=d);g&&(g=b.INDENT+"return "+g+";\n");const k=[],l=a.getVars();for(let m=0;m<l.length;m++)k[m]=b.getVariableName(l[m]);d="function "+c+"("+k.join(", ")+") {\n"+d+e+f+h+g+"}";d=b.scrub_(a,d);b.definitions_["%"+c]=d;return null},
|
||||
procedures_callreturn$$module$build$src$generators$javascript$procedures=function(a,b){const c=b.getProcedureName(a.getFieldValue("NAME")),d=[],e=a.getVars();for(let f=0;f<e.length;f++)d[f]=b.valueToCode(a,"ARG"+f,Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"null";return[c+"("+d.join(", ")+")",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},procedures_callnoreturn$$module$build$src$generators$javascript$procedures=function(a,b){return b.forBlock.procedures_callreturn(a,
|
||||
b)[0]+";\n"},procedures_ifreturn$$module$build$src$generators$javascript$procedures=function(a,b){let c="if ("+(b.valueToCode(a,"CONDITION",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"false")+") {\n";b.STATEMENT_SUFFIX&&(c+=b.prefixLines(b.injectId(b.STATEMENT_SUFFIX,a),b.INDENT));a.hasReturnValue_?(a=b.valueToCode(a,"VALUE",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"null",c+=b.INDENT+"return "+a+";\n"):c+=b.INDENT+"return;\n";return c+
|
||||
"}\n"},text$$module$build$src$generators$javascript$text=function(a,b){return[b.quote_(a.getFieldValue("TEXT")),Order$$module$build$src$generators$javascript$javascript_generator.ATOMIC]},text_join$$module$build$src$generators$javascript$text=function(a,b){switch(a.itemCount_){case 0:return["''",Order$$module$build$src$generators$javascript$javascript_generator.ATOMIC];case 1:return a=b.valueToCode(a,"ADD0",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"''",forceString$$module$build$src$generators$javascript$text(a);
|
||||
case 2:var c=b.valueToCode(a,"ADD0",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"''";a=b.valueToCode(a,"ADD1",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"''";return[forceString$$module$build$src$generators$javascript$text(c)[0]+" + "+forceString$$module$build$src$generators$javascript$text(a)[0],Order$$module$build$src$generators$javascript$javascript_generator.ADDITION];default:c=Array(a.itemCount_);for(let d=0;d<a.itemCount_;d++)c[d]=
|
||||
b.valueToCode(a,"ADD"+d,Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"''";return["["+c.join(",")+"].join('')",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]}},text_append$$module$build$src$generators$javascript$text=function(a,b){const c=b.getVariableName(a.getFieldValue("VAR"));a=b.valueToCode(a,"TEXT",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"''";return c+" += "+forceString$$module$build$src$generators$javascript$text(a)[0]+
|
||||
";\n"},text_length$$module$build$src$generators$javascript$text=function(a,b){return[(b.valueToCode(a,"VALUE",Order$$module$build$src$generators$javascript$javascript_generator.MEMBER)||"''")+".length",Order$$module$build$src$generators$javascript$javascript_generator.MEMBER]},text_isEmpty$$module$build$src$generators$javascript$text=function(a,b){return["!"+(b.valueToCode(a,"VALUE",Order$$module$build$src$generators$javascript$javascript_generator.MEMBER)||"''")+".length",Order$$module$build$src$generators$javascript$javascript_generator.LOGICAL_NOT]},
|
||||
text_indexOf$$module$build$src$generators$javascript$text=function(a,b){const c="FIRST"===a.getFieldValue("END")?"indexOf":"lastIndexOf",d=b.valueToCode(a,"FIND",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"''";b=(b.valueToCode(a,"VALUE",Order$$module$build$src$generators$javascript$javascript_generator.MEMBER)||"''")+"."+c+"("+d+")";return a.workspace.options.oneBasedIndex?[b+" + 1",Order$$module$build$src$generators$javascript$javascript_generator.ADDITION]:[b,Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},
|
||||
text_charAt$$module$build$src$generators$javascript$text=function(a,b){const c=a.getFieldValue("WHERE")||"FROM_START",d=b.valueToCode(a,"VALUE","RANDOM"===c?Order$$module$build$src$generators$javascript$javascript_generator.NONE:Order$$module$build$src$generators$javascript$javascript_generator.MEMBER)||"''";switch(c){case "FIRST":return[d+".charAt(0)",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL];case "LAST":return[d+".slice(-1)",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL];
|
||||
case "FROM_START":return a=b.getAdjusted(a,"AT"),[d+".charAt("+a+")",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL];case "FROM_END":return a=b.getAdjusted(a,"AT",1,!0),[d+".slice("+a+").charAt(0)",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL];case "RANDOM":return[b.provideFunction_("textRandomLetter",`
|
||||
function ${b.FUNCTION_NAME_PLACEHOLDER_}(text) {
|
||||
var x = Math.floor(Math.random() * text.length);
|
||||
return text[x];
|
||||
}
|
||||
`)+"("+d+")",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]}throw Error("Unhandled option (text_charAt).");},text_getSubstring$$module$build$src$generators$javascript$text=function(a,b){var c={FIRST:"First",LAST:"Last",FROM_START:"FromStart",FROM_END:"FromEnd"};const d=a.getFieldValue("WHERE1"),e=a.getFieldValue("WHERE2");var f="FROM_END"!==d&&"LAST"!==d&&"FROM_END"!==e&&"LAST"!==e,g=b.valueToCode(a,"STRING",f?Order$$module$build$src$generators$javascript$javascript_generator.MEMBER:
|
||||
Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"''";if("FIRST"===d&&"LAST"===e)return[g,Order$$module$build$src$generators$javascript$javascript_generator.NONE];if(g.match(/^'?\w+'?$/)||f){switch(d){case "FROM_START":c=b.getAdjusted(a,"AT1");break;case "FROM_END":c=b.getAdjusted(a,"AT1",1,!1,Order$$module$build$src$generators$javascript$javascript_generator.SUBTRACTION);c=g+".length - "+c;break;case "FIRST":c="0";break;default:throw Error("Unhandled option (text_getSubstring).");
|
||||
}switch(e){case "FROM_START":b=b.getAdjusted(a,"AT2",1);break;case "FROM_END":b=b.getAdjusted(a,"AT2",0,!1,Order$$module$build$src$generators$javascript$javascript_generator.SUBTRACTION);b=g+".length - "+b;break;case "LAST":b=g+".length";break;default:throw Error("Unhandled option (text_getSubstring).");}g=g+".slice("+c+", "+b+")"}else f=b.getAdjusted(a,"AT1"),a=b.getAdjusted(a,"AT2"),g=b.provideFunction_("subsequence"+c[d]+c[e],`
|
||||
function ${b.FUNCTION_NAME_PLACEHOLDER_}(sequence${"FROM_END"===d||"FROM_START"===d?", at1":""}${"FROM_END"===e||"FROM_START"===e?", at2":""}) {
|
||||
var start = ${getSubstringIndex$$module$build$src$generators$javascript$text("sequence",d,"at1")};
|
||||
var end = ${getSubstringIndex$$module$build$src$generators$javascript$text("sequence",e,"at2")} + 1;
|
||||
return sequence.slice(start, end);
|
||||
}
|
||||
`)+"("+g+("FROM_END"===d||"FROM_START"===d?", "+f:"")+("FROM_END"===e||"FROM_START"===e?", "+a:"")+")";return[g,Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},text_changeCase$$module$build$src$generators$javascript$text=function(a,b){const c={UPPERCASE:".toUpperCase()",LOWERCASE:".toLowerCase()",TITLECASE:null}[a.getFieldValue("CASE")];a=b.valueToCode(a,"TEXT",c?Order$$module$build$src$generators$javascript$javascript_generator.MEMBER:Order$$module$build$src$generators$javascript$javascript_generator.NONE)||
|
||||
"''";return[c?a+c:b.provideFunction_("textToTitleCase",`
|
||||
function ${b.FUNCTION_NAME_PLACEHOLDER_}(str) {
|
||||
return str.replace(/\\S+/g,
|
||||
function(txt) {return txt[0].toUpperCase() + txt.substring(1).toLowerCase();});
|
||||
}
|
||||
`)+"("+a+")",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},text_trim$$module$build$src$generators$javascript$text=function(a,b){const c={LEFT:".replace(/^[\\s\\xa0]+/, '')",RIGHT:".replace(/[\\s\\xa0]+$/, '')",BOTH:".trim()"}[a.getFieldValue("MODE")];return[(b.valueToCode(a,"TEXT",Order$$module$build$src$generators$javascript$javascript_generator.MEMBER)||"''")+c,Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},text_print$$module$build$src$generators$javascript$text=
|
||||
function(a,b){return"console.log("+(b.valueToCode(a,"TEXT",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"''")+");\n"},text_prompt_ext$$module$build$src$generators$javascript$text=function(a,b){b="window.prompt("+(a.getField("TEXT")?b.quote_(a.getFieldValue("TEXT")):b.valueToCode(a,"TEXT",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"''")+")";"NUMBER"===a.getFieldValue("TYPE")&&(b="Number("+b+")");return[b,Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},
|
||||
text_count$$module$build$src$generators$javascript$text=function(a,b){const c=b.valueToCode(a,"TEXT",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"''";a=b.valueToCode(a,"SUB",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"''";return[b.provideFunction_("textCount",`
|
||||
function ${b.FUNCTION_NAME_PLACEHOLDER_}(haystack, needle) {
|
||||
if (needle.length === 0) {
|
||||
return haystack.length + 1;
|
||||
} else {
|
||||
return haystack.split(needle).length - 1;
|
||||
}
|
||||
}
|
||||
`)+"("+c+", "+a+")",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},text_replace$$module$build$src$generators$javascript$text=function(a,b){const c=b.valueToCode(a,"TEXT",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"''",d=b.valueToCode(a,"FROM",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"''";a=b.valueToCode(a,"TO",Order$$module$build$src$generators$javascript$javascript_generator.NONE)||"''";return[b.provideFunction_("textReplace",
|
||||
`
|
||||
function ${b.FUNCTION_NAME_PLACEHOLDER_}(haystack, needle, replacement) {
|
||||
needle = needle.replace(/([-()\\[\\]{}+?*.$\\^|,:#<!\\\\])/g, '\\\\$1')
|
||||
.replace(/\\x08/g, '\\\\x08');
|
||||
return haystack.replace(new RegExp(needle, 'g'), replacement);
|
||||
}
|
||||
`)+"("+c+", "+d+", "+a+")",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},text_reverse$$module$build$src$generators$javascript$text=function(a,b){return[(b.valueToCode(a,"TEXT",Order$$module$build$src$generators$javascript$javascript_generator.MEMBER)||"''")+".split('').reverse().join('')",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},variables_get$$module$build$src$generators$javascript$variables=function(a,b){return[b.getVariableName(a.getFieldValue("VAR")),
|
||||
Order$$module$build$src$generators$javascript$javascript_generator.ATOMIC]},variables_set$$module$build$src$generators$javascript$variables=function(a,b){const c=b.valueToCode(a,"VALUE",Order$$module$build$src$generators$javascript$javascript_generator.ASSIGNMENT)||"0";return b.getVariableName(a.getFieldValue("VAR"))+" = "+c+";\n"},Order$$module$build$src$generators$javascript$javascript_generator;
|
||||
(function(a){a[a.ATOMIC=0]="ATOMIC";a[a.NEW=1.1]="NEW";a[a.MEMBER=1.2]="MEMBER";a[a.FUNCTION_CALL=2]="FUNCTION_CALL";a[a.INCREMENT=3]="INCREMENT";a[a.DECREMENT=3]="DECREMENT";a[a.BITWISE_NOT=4.1]="BITWISE_NOT";a[a.UNARY_PLUS=4.2]="UNARY_PLUS";a[a.UNARY_NEGATION=4.3]="UNARY_NEGATION";a[a.LOGICAL_NOT=4.4]="LOGICAL_NOT";a[a.TYPEOF=4.5]="TYPEOF";a[a.VOID=4.6]="VOID";a[a.DELETE=4.7]="DELETE";a[a.AWAIT=4.8]="AWAIT";a[a.EXPONENTIATION=5]="EXPONENTIATION";a[a.MULTIPLICATION=5.1]="MULTIPLICATION";a[a.DIVISION=
|
||||
5.2]="DIVISION";a[a.MODULUS=5.3]="MODULUS";a[a.SUBTRACTION=6.1]="SUBTRACTION";a[a.ADDITION=6.2]="ADDITION";a[a.BITWISE_SHIFT=7]="BITWISE_SHIFT";a[a.RELATIONAL=8]="RELATIONAL";a[a.IN=8]="IN";a[a.INSTANCEOF=8]="INSTANCEOF";a[a.EQUALITY=9]="EQUALITY";a[a.BITWISE_AND=10]="BITWISE_AND";a[a.BITWISE_XOR=11]="BITWISE_XOR";a[a.BITWISE_OR=12]="BITWISE_OR";a[a.LOGICAL_AND=13]="LOGICAL_AND";a[a.LOGICAL_OR=14]="LOGICAL_OR";a[a.CONDITIONAL=15]="CONDITIONAL";a[a.ASSIGNMENT=16]="ASSIGNMENT";a[a.YIELD=17]="YIELD";
|
||||
a[a.COMMA=18]="COMMA";a[a.NONE=99]="NONE"})(Order$$module$build$src$generators$javascript$javascript_generator||(Order$$module$build$src$generators$javascript$javascript_generator={}));
|
||||
var JavascriptGenerator$$module$build$src$generators$javascript$javascript_generator=class extends $.CodeGenerator$$module$build$src$core$generator{constructor(a="JavaScript"){super(a);this.ORDER_OVERRIDES=[[Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL,Order$$module$build$src$generators$javascript$javascript_generator.MEMBER],[Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL,Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL],
|
||||
[Order$$module$build$src$generators$javascript$javascript_generator.MEMBER,Order$$module$build$src$generators$javascript$javascript_generator.MEMBER],[Order$$module$build$src$generators$javascript$javascript_generator.MEMBER,Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL],[Order$$module$build$src$generators$javascript$javascript_generator.LOGICAL_NOT,Order$$module$build$src$generators$javascript$javascript_generator.LOGICAL_NOT],[Order$$module$build$src$generators$javascript$javascript_generator.MULTIPLICATION,
|
||||
Order$$module$build$src$generators$javascript$javascript_generator.MULTIPLICATION],[Order$$module$build$src$generators$javascript$javascript_generator.ADDITION,Order$$module$build$src$generators$javascript$javascript_generator.ADDITION],[Order$$module$build$src$generators$javascript$javascript_generator.LOGICAL_AND,Order$$module$build$src$generators$javascript$javascript_generator.LOGICAL_AND],[Order$$module$build$src$generators$javascript$javascript_generator.LOGICAL_OR,Order$$module$build$src$generators$javascript$javascript_generator.LOGICAL_OR]];
|
||||
this.isInitialized=!1;for(const b in Order$$module$build$src$generators$javascript$javascript_generator)a=Order$$module$build$src$generators$javascript$javascript_generator[b],"string"!==typeof a&&(this["ORDER_"+b]=a);this.addReservedWords("break,case,catch,class,const,continue,debugger,default,delete,do,else,export,extends,finally,for,function,if,import,in,instanceof,new,return,super,switch,this,throw,try,typeof,var,void,while,with,yield,enum,implements,interface,let,package,private,protected,public,static,await,null,true,false,arguments,"+
|
||||
Object.getOwnPropertyNames(globalThis).join(","))}init(a){super.init(a);this.nameDB_?this.nameDB_.reset():this.nameDB_=new $.Names$$module$build$src$core$names(this.RESERVED_WORDS_);this.nameDB_.setVariableMap(a.getVariableMap());this.nameDB_.populateVariables(a);this.nameDB_.populateProcedures(a);const b=[];var c=$.allDeveloperVariables$$module$build$src$core$variables(a);for(let d=0;d<c.length;d++)b.push(this.nameDB_.getName(c[d],$.NameType$$module$build$src$core$names.DEVELOPER_VARIABLE));a=$.allUsedVarModels$$module$build$src$core$variables(a);
|
||||
for(c=0;c<a.length;c++)b.push(this.nameDB_.getName(a[c].getId(),$.NameType$$module$build$src$core$names.VARIABLE));b.length&&(this.definitions_.variables="var "+b.join(", ")+";");this.isInitialized=!0}finish(a){const b=Object.values(this.definitions_);super.finish(a);this.isInitialized=!1;this.nameDB_.reset();return b.join("\n\n")+"\n\n\n"+a}scrubNakedValue(a){return a+";\n"}quote_(a){a=a.replace(/\\/g,"\\\\").replace(/\n/g,"\\\n").replace(/'/g,"\\'");return"'"+a+"'"}multiline_quote_(a){return a.split(/\n/g).map(this.quote_).join(" + '\\n' +\n")}scrub_(a,
|
||||
b,c=!1){let d="";if(!a.outputConnection||!a.outputConnection.targetConnection){var e=a.getCommentText();e&&(e=$.wrap$$module$build$src$core$utils$string(e,this.COMMENT_WRAP-3),d+=this.prefixLines(e+"\n","// "));for(let f=0;f<a.inputList.length;f++)a.inputList[f].type===$.inputTypes$$module$build$src$core$inputs$input_types.VALUE&&(e=a.inputList[f].connection.targetBlock())&&(e=this.allNestedComments(e))&&(d+=this.prefixLines(e,"// "))}a=a.nextConnection&&a.nextConnection.targetBlock();c=c?"":this.blockToCode(a);
|
||||
return d+b+c}getAdjusted(a,b,c=0,d=!1,e=Order$$module$build$src$generators$javascript$javascript_generator.NONE){a.workspace.options.oneBasedIndex&&c--;const f=a.workspace.options.oneBasedIndex?"1":"0";let g=e;0<c?g=Order$$module$build$src$generators$javascript$javascript_generator.ADDITION:0>c?g=Order$$module$build$src$generators$javascript$javascript_generator.SUBTRACTION:d&&(g=Order$$module$build$src$generators$javascript$javascript_generator.UNARY_NEGATION);a=this.valueToCode(a,b,g)||f;if(0===
|
||||
c&&!d)return a;if($.isNumber$$module$build$src$core$utils$string(a))return a=String(Number(a)+c),d&&(a=String(-Number(a))),a;0<c?a=`${a} + ${c}`:0>c&&(a=`${a} - ${-c}`);d&&(a=c?`-(${a})`:`-${a}`);Math.floor(e)>=Math.floor(g)&&(a=`(${a})`);return a}},module$build$src$generators$javascript$javascript_generator={};module$build$src$generators$javascript$javascript_generator.JavascriptGenerator=JavascriptGenerator$$module$build$src$generators$javascript$javascript_generator;
|
||||
module$build$src$generators$javascript$javascript_generator.Order=Order$$module$build$src$generators$javascript$javascript_generator;var getSubstringIndex$$module$build$src$generators$javascript$lists=function(a,b,c){return"FIRST"===b?"0":"FROM_END"===b?a+".length - 1 - "+c:"LAST"===b?a+".length - 1":c},module$build$src$generators$javascript$lists={};module$build$src$generators$javascript$lists.lists_create_empty=lists_create_empty$$module$build$src$generators$javascript$lists;module$build$src$generators$javascript$lists.lists_create_with=lists_create_with$$module$build$src$generators$javascript$lists;
|
||||
module$build$src$generators$javascript$lists.lists_getIndex=lists_getIndex$$module$build$src$generators$javascript$lists;module$build$src$generators$javascript$lists.lists_getSublist=lists_getSublist$$module$build$src$generators$javascript$lists;module$build$src$generators$javascript$lists.lists_indexOf=lists_indexOf$$module$build$src$generators$javascript$lists;module$build$src$generators$javascript$lists.lists_isEmpty=lists_isEmpty$$module$build$src$generators$javascript$lists;
|
||||
module$build$src$generators$javascript$lists.lists_length=lists_length$$module$build$src$generators$javascript$lists;module$build$src$generators$javascript$lists.lists_repeat=lists_repeat$$module$build$src$generators$javascript$lists;module$build$src$generators$javascript$lists.lists_reverse=lists_reverse$$module$build$src$generators$javascript$lists;module$build$src$generators$javascript$lists.lists_setIndex=lists_setIndex$$module$build$src$generators$javascript$lists;
|
||||
module$build$src$generators$javascript$lists.lists_sort=lists_sort$$module$build$src$generators$javascript$lists;module$build$src$generators$javascript$lists.lists_split=lists_split$$module$build$src$generators$javascript$lists;var controls_ifelse$$module$build$src$generators$javascript$logic=controls_if$$module$build$src$generators$javascript$logic,module$build$src$generators$javascript$logic={};module$build$src$generators$javascript$logic.controls_if=controls_if$$module$build$src$generators$javascript$logic;module$build$src$generators$javascript$logic.controls_ifelse=controls_if$$module$build$src$generators$javascript$logic;module$build$src$generators$javascript$logic.logic_boolean=logic_boolean$$module$build$src$generators$javascript$logic;
|
||||
module$build$src$generators$javascript$logic.logic_compare=logic_compare$$module$build$src$generators$javascript$logic;module$build$src$generators$javascript$logic.logic_negate=logic_negate$$module$build$src$generators$javascript$logic;module$build$src$generators$javascript$logic.logic_null=logic_null$$module$build$src$generators$javascript$logic;module$build$src$generators$javascript$logic.logic_operation=logic_operation$$module$build$src$generators$javascript$logic;
|
||||
module$build$src$generators$javascript$logic.logic_ternary=logic_ternary$$module$build$src$generators$javascript$logic;var controls_repeat$$module$build$src$generators$javascript$loops=controls_repeat_ext$$module$build$src$generators$javascript$loops,module$build$src$generators$javascript$loops={};module$build$src$generators$javascript$loops.controls_flow_statements=controls_flow_statements$$module$build$src$generators$javascript$loops;module$build$src$generators$javascript$loops.controls_for=controls_for$$module$build$src$generators$javascript$loops;module$build$src$generators$javascript$loops.controls_forEach=controls_forEach$$module$build$src$generators$javascript$loops;
|
||||
module$build$src$generators$javascript$loops.controls_repeat=controls_repeat_ext$$module$build$src$generators$javascript$loops;module$build$src$generators$javascript$loops.controls_repeat_ext=controls_repeat_ext$$module$build$src$generators$javascript$loops;module$build$src$generators$javascript$loops.controls_whileUntil=controls_whileUntil$$module$build$src$generators$javascript$loops;var math_round$$module$build$src$generators$javascript$math=math_single$$module$build$src$generators$javascript$math,math_trig$$module$build$src$generators$javascript$math=math_single$$module$build$src$generators$javascript$math,module$build$src$generators$javascript$math={};module$build$src$generators$javascript$math.math_arithmetic=math_arithmetic$$module$build$src$generators$javascript$math;module$build$src$generators$javascript$math.math_atan2=math_atan2$$module$build$src$generators$javascript$math;
|
||||
module$build$src$generators$javascript$math.math_change=math_change$$module$build$src$generators$javascript$math;module$build$src$generators$javascript$math.math_constant=math_constant$$module$build$src$generators$javascript$math;module$build$src$generators$javascript$math.math_constrain=math_constrain$$module$build$src$generators$javascript$math;module$build$src$generators$javascript$math.math_modulo=math_modulo$$module$build$src$generators$javascript$math;
|
||||
module$build$src$generators$javascript$math.math_number=math_number$$module$build$src$generators$javascript$math;module$build$src$generators$javascript$math.math_number_property=math_number_property$$module$build$src$generators$javascript$math;module$build$src$generators$javascript$math.math_on_list=math_on_list$$module$build$src$generators$javascript$math;module$build$src$generators$javascript$math.math_random_float=math_random_float$$module$build$src$generators$javascript$math;
|
||||
module$build$src$generators$javascript$math.math_random_int=math_random_int$$module$build$src$generators$javascript$math;module$build$src$generators$javascript$math.math_round=math_single$$module$build$src$generators$javascript$math;module$build$src$generators$javascript$math.math_single=math_single$$module$build$src$generators$javascript$math;module$build$src$generators$javascript$math.math_trig=math_single$$module$build$src$generators$javascript$math;var procedures_defnoreturn$$module$build$src$generators$javascript$procedures=procedures_defreturn$$module$build$src$generators$javascript$procedures,module$build$src$generators$javascript$procedures={};module$build$src$generators$javascript$procedures.procedures_callnoreturn=procedures_callnoreturn$$module$build$src$generators$javascript$procedures;module$build$src$generators$javascript$procedures.procedures_callreturn=procedures_callreturn$$module$build$src$generators$javascript$procedures;
|
||||
module$build$src$generators$javascript$procedures.procedures_defnoreturn=procedures_defreturn$$module$build$src$generators$javascript$procedures;module$build$src$generators$javascript$procedures.procedures_defreturn=procedures_defreturn$$module$build$src$generators$javascript$procedures;module$build$src$generators$javascript$procedures.procedures_ifreturn=procedures_ifreturn$$module$build$src$generators$javascript$procedures;var strRegExp$$module$build$src$generators$javascript$text=/^\s*'([^']|\\')*'\s*$/,forceString$$module$build$src$generators$javascript$text=function(a){return strRegExp$$module$build$src$generators$javascript$text.test(a)?[a,Order$$module$build$src$generators$javascript$javascript_generator.ATOMIC]:["String("+a+")",Order$$module$build$src$generators$javascript$javascript_generator.FUNCTION_CALL]},getSubstringIndex$$module$build$src$generators$javascript$text=function(a,b,c){return"FIRST"===b?"0":
|
||||
"FROM_END"===b?a+".length - 1 - "+c:"LAST"===b?a+".length - 1":c},text_prompt$$module$build$src$generators$javascript$text=text_prompt_ext$$module$build$src$generators$javascript$text,module$build$src$generators$javascript$text={};module$build$src$generators$javascript$text.text=text$$module$build$src$generators$javascript$text;module$build$src$generators$javascript$text.text_append=text_append$$module$build$src$generators$javascript$text;
|
||||
module$build$src$generators$javascript$text.text_changeCase=text_changeCase$$module$build$src$generators$javascript$text;module$build$src$generators$javascript$text.text_charAt=text_charAt$$module$build$src$generators$javascript$text;module$build$src$generators$javascript$text.text_count=text_count$$module$build$src$generators$javascript$text;module$build$src$generators$javascript$text.text_getSubstring=text_getSubstring$$module$build$src$generators$javascript$text;
|
||||
module$build$src$generators$javascript$text.text_indexOf=text_indexOf$$module$build$src$generators$javascript$text;module$build$src$generators$javascript$text.text_isEmpty=text_isEmpty$$module$build$src$generators$javascript$text;module$build$src$generators$javascript$text.text_join=text_join$$module$build$src$generators$javascript$text;module$build$src$generators$javascript$text.text_length=text_length$$module$build$src$generators$javascript$text;
|
||||
module$build$src$generators$javascript$text.text_print=text_print$$module$build$src$generators$javascript$text;module$build$src$generators$javascript$text.text_prompt=text_prompt_ext$$module$build$src$generators$javascript$text;module$build$src$generators$javascript$text.text_prompt_ext=text_prompt_ext$$module$build$src$generators$javascript$text;module$build$src$generators$javascript$text.text_replace=text_replace$$module$build$src$generators$javascript$text;
|
||||
module$build$src$generators$javascript$text.text_reverse=text_reverse$$module$build$src$generators$javascript$text;module$build$src$generators$javascript$text.text_trim=text_trim$$module$build$src$generators$javascript$text;var module$build$src$generators$javascript$variables={};module$build$src$generators$javascript$variables.variables_get=variables_get$$module$build$src$generators$javascript$variables;module$build$src$generators$javascript$variables.variables_set=variables_set$$module$build$src$generators$javascript$variables;var module$build$src$generators$javascript$variables_dynamic={};module$build$src$generators$javascript$variables_dynamic.variables_get_dynamic=variables_get$$module$build$src$generators$javascript$variables;module$build$src$generators$javascript$variables_dynamic.variables_set_dynamic=variables_set$$module$build$src$generators$javascript$variables;var javascriptGenerator$$module$build$src$generators$javascript=new JavascriptGenerator$$module$build$src$generators$javascript$javascript_generator,generators$$module$build$src$generators$javascript=Object.assign({},module$build$src$generators$javascript$lists,module$build$src$generators$javascript$logic,module$build$src$generators$javascript$loops,module$build$src$generators$javascript$math,module$build$src$generators$javascript$procedures,module$build$src$generators$javascript$text,module$build$src$generators$javascript$variables,
|
||||
module$build$src$generators$javascript$variables_dynamic);for(const a in generators$$module$build$src$generators$javascript)javascriptGenerator$$module$build$src$generators$javascript.forBlock[a]=generators$$module$build$src$generators$javascript[a];var module$build$src$generators$javascript={};module$build$src$generators$javascript.JavascriptGenerator=JavascriptGenerator$$module$build$src$generators$javascript$javascript_generator;module$build$src$generators$javascript.Order=Order$$module$build$src$generators$javascript$javascript_generator;
|
||||
module$build$src$generators$javascript.javascriptGenerator=javascriptGenerator$$module$build$src$generators$javascript;
|
||||
module$build$src$generators$javascript.__namespace__=$;
|
||||
return module$build$src$generators$javascript;
|
||||
}));
|
||||
|
||||
|
||||
//# sourceMappingURL=javascript_compressed.js.map
|
||||
@@ -0,0 +1,25 @@
|
||||
var arrayList = ModAPI.reflect.getClassByName("ArrayList").constructors[0]();
|
||||
var vs = Object.values(ModAPI.blocks);
|
||||
var vsRaw = Object.values(ModAPI.blocks).map(x=>x.getRef());
|
||||
var ks = Object.keys(ModAPI.blocks);
|
||||
vs.forEach(x=>{
|
||||
var itemblock = ModAPI.util.getItemFromBlock(x.getRef());
|
||||
x.getSubBlocks(itemblock, null, arrayList);
|
||||
});
|
||||
|
||||
arrayList = ModAPI.util.wrap(arrayList).getCorrective();
|
||||
var out = [];
|
||||
arrayList.array.forEach((x)=>{
|
||||
try{
|
||||
var l10n = ModAPI.util.ustr(x?.getUnlocalizedName()?.getRef() ?? ModAPI.util.str("")).slice("5").split(".");
|
||||
out.push({
|
||||
name: l10n[l10n.length - 1],
|
||||
meta: x.itemDamage,
|
||||
id: ks[vsRaw.indexOf(ModAPI.util.getBlockFromItem(x.item.getRef()))],
|
||||
type: "block"
|
||||
});
|
||||
} catch(e) {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
@@ -0,0 +1,4 @@
|
||||
var out = [{"id": "air", "type": "item"}].concat(Object.keys(ModAPI.items).map(x=>{return {
|
||||
id: x,
|
||||
type: "item"
|
||||
}}));
|
||||
@@ -0,0 +1,38 @@
|
||||
function toTitleCase(str) {
|
||||
return str.replace(
|
||||
/\w\S*/g,
|
||||
text => text.charAt(0).toUpperCase() + text.substring(1).toLowerCase()
|
||||
);
|
||||
}
|
||||
function registerHandler(id, l10n, map, post) {
|
||||
var key = "handle_" + id;
|
||||
const handler = {
|
||||
init: function () {
|
||||
this.appendDummyInput('ID')
|
||||
.appendField('Handler ID:')
|
||||
.appendField(new Blockly.FieldTextInput(l10n.toLowerCase().trim() + ' 1'), 'ID');
|
||||
var dummy = this.appendDummyInput('')
|
||||
.appendField(toTitleCase(l10n.trim()) + ' Handler' + ((Object.keys(map).length === 0) ? "" : " with:"));
|
||||
|
||||
Object.keys(map).forEach(x=>{
|
||||
if (map[x] === null) {
|
||||
return;
|
||||
}
|
||||
dummy.appendField(new Blockly.FieldEFB2Variable(map[x]), x)
|
||||
});
|
||||
|
||||
this.appendStatementInput('CODE');
|
||||
this.setInputsInline(false)
|
||||
post.apply(this, []);
|
||||
}
|
||||
};
|
||||
const data = {};
|
||||
data[key] = handler;
|
||||
Blockly.common.defineBlocks(data);
|
||||
|
||||
javascript.javascriptGenerator.forBlock[key] = function () {
|
||||
const variables = Object.keys(map).map(k => (map[k] === null) ? k : javascript.javascriptGenerator.getVariableName(this.getFieldValue(k)));
|
||||
const statement = javascript.javascriptGenerator.statementToCode(this, 'CODE');
|
||||
return { code: statement, args: variables };
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
function $$str2ab(str) {
|
||||
var buf = new ArrayBuffer(str.length * 2);
|
||||
var bufView = new Uint16Array(buf);
|
||||
for (var i = 0, strLen = str.length; i < strLen; i++) {
|
||||
bufView[i] = str.charCodeAt(i);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
Array.prototype.bake = function () {
|
||||
this.originalState = structuredClone(this);
|
||||
this.modifiers = [];
|
||||
this.useDynamic = true;
|
||||
return this;
|
||||
}
|
||||
Array.prototype.calculate = function () {
|
||||
this.splice(0, this.length, ...this.originalState);
|
||||
this.modifiers.forEach(x=>x.apply(this, []));
|
||||
return this;
|
||||
}
|
||||
Array.prototype.dynamicConcat = function (datablockType, propname, interim) {
|
||||
interim ||= (x)=>x;
|
||||
this.modifiers.push(function () {
|
||||
this.push(...state.nodes.filter(x=>x.type === datablockType).map(x=>interim(x.tags[propname])));
|
||||
});
|
||||
return this;
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
//TODO: quantityDropped, onBlockDestroyedByExplosion, onBlockActivated
|
||||
PRIMITIVES["block_advanced"] = {
|
||||
name: "Advanced Block",
|
||||
uses: ["fixup_block_ids", "str2ab"],
|
||||
type: "block_advanced",
|
||||
tags: {
|
||||
id: "advanced_block",
|
||||
name: "Advanced Block",
|
||||
texture: VALUE_ENUMS.IMG,
|
||||
animatedSpritesheetTexture: false, // https://sheeptester.github.io/words-go-here/misc/animated-painting-maker.html
|
||||
animatedTextureFrameDuration: 1,
|
||||
animatedTextureInterpolate: false,
|
||||
tickRatio: 10,
|
||||
material: ['rock', 'air', 'grass', 'ground', 'wood', 'iron', 'anvil', 'water', 'lava', 'leaves', 'plants', 'vine', 'sponge', 'cloth', 'fire', 'sand', 'circuits', 'carpet', 'glass', 'redstoneLight', 'tnt', 'coral', 'ice', 'packedIce', 'snow', 'craftedSnow', 'cactus', 'clay', 'gourd', 'dragonEgg', 'portal', 'cake', 'web', 'piston', 'barrier'],
|
||||
Constructor: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockConstructor",
|
||||
Break: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockBreak",
|
||||
Added: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockAdded",
|
||||
NeighborChange: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockNeighbourChange",
|
||||
Break: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockBreak",
|
||||
BrokenByPlayer: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockBrokenByPlayer",
|
||||
RandomTick: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockRandomTick",
|
||||
EntityCollided: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockEntityCollision",
|
||||
GetDroppedItem: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockGetDroppedItem",
|
||||
QuantityDropped: VALUE_ENUMS.ABSTRACT_HANDLER + "BlockQuantityDropped",
|
||||
},
|
||||
getDependencies: function () {
|
||||
return [];
|
||||
},
|
||||
asJavaScript: function () {
|
||||
var constructorHandler = getHandlerCode("BlockConstructor", this.tags.Constructor, []);
|
||||
var breakHandler = getHandlerCode("BlockBreak", this.tags.Break, ["$$world", "$$blockpos", "$$blockstate"]);
|
||||
var addedHandler = getHandlerCode("BlockAdded", this.tags.Added, ["$$world", "$$blockpos", "$$blockstate"]);
|
||||
var neighborHandler = getHandlerCode("BlockNeighbourChange", this.tags.NeighborChange, ["$$world", "$$blockpos", "$$blockstate"], {
|
||||
"1_8": function (args, code) {
|
||||
return `
|
||||
var $$onNeighborBlockChangeMethod = $$blockClass.methods.onNeighborBlockChange.method;
|
||||
$$nmb_AdvancedBlock.prototype.$onNeighborBlockChange = function (${args.join(", ")}) {
|
||||
${code};
|
||||
return $$onNeighborBlockChangeMethod(this, ${args.join(", ")});
|
||||
}
|
||||
`
|
||||
},
|
||||
"1_12": function (args, code) {
|
||||
const copy = [...args];
|
||||
copy[0] = args[1];
|
||||
copy[1] = args[2];
|
||||
copy[2] = args[0];
|
||||
return `
|
||||
var $$onNeighborBlockChangeMethod = $$blockClass.methods.neighborChanged.method;
|
||||
$$nmb_AdvancedBlock.prototype.$neighborChanged = function (${copy.join(", ")}) {
|
||||
${code};
|
||||
return $$onNeighborBlockChangeMethod(this, ${copy.join(", ")});
|
||||
}
|
||||
`
|
||||
}
|
||||
});
|
||||
var brokenByPlayerHandler = getHandlerCode("BlockBrokenByPlayer", this.tags.BrokenByPlayer, ["$$world", "$$blockpos", "$$blockstate"]);
|
||||
var randomTickHandler = getHandlerCode("BlockRandomTick", this.tags.RandomTick, ["$$world", "$$blockpos", "$$blockstate", "$$random"]);
|
||||
var entityCollisionHandler = getHandlerCode("BlockEntityCollision", this.tags.EntityCollided, ["$$world", "$$blockpos", "$$entity"], {
|
||||
"1_8": function (args, code) {
|
||||
return `
|
||||
var $$entityCollisionMethod = $$blockClass.methods.onEntityCollidedWithBlock.method;
|
||||
$$nmb_AdvancedBlock.prototype.$onEntityCollidedWithBlock = function (${args.join(", ")}) {
|
||||
${code};
|
||||
return $$entityCollisionMethod(this, ${args.join(", ")});
|
||||
}`;
|
||||
},
|
||||
"1_12": function (args, code) {
|
||||
const argList = `${args.slice(0,2).join(", ")},$$blockstate,${args[2]}`;
|
||||
return `
|
||||
var $$entityCollisionMethod = $$blockClass.methods.onEntityCollidedWithBlock.method;
|
||||
$$nmb_AdvancedBlock.prototype.$onEntityCollidedWithBlock = function (${argList}) {
|
||||
${code};
|
||||
return $$entityCollisionMethod(this, ${argList});
|
||||
}`;
|
||||
}
|
||||
});
|
||||
var getDroppedItemHandler = getHandlerCode("BlockGetDroppedItem", this.tags.GetDroppedItem, ["$$blockstate", "$$random", "$$forture"]);
|
||||
var quantityDroppedHandler = getHandlerCode("BlockQuantityDropped", this.tags.QuantityDropped, ["$$random", "$$fortune"]);
|
||||
|
||||
var animationCode = `
|
||||
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/textures/blocks/${this.tags.id}.png.mcmeta", efb2__str2ab(
|
||||
\`{
|
||||
"animation": {
|
||||
"frametime": ${Math.max(1, Math.round(this.tags.animatedTextureFrameDuration)) || 1},
|
||||
"interpolate": ${this.tags.animatedTextureInterpolate}
|
||||
}
|
||||
}\`));
|
||||
`;
|
||||
|
||||
return `(function AdvancedBlockDatablock() {
|
||||
const $$blockTexture = "${this.tags.texture}";
|
||||
|
||||
function $$ServersideBlocks() {
|
||||
const $$scoped_efb_globals = {};
|
||||
var $$itemClass = ModAPI.reflect.getClassById("net.minecraft.item.Item");
|
||||
var $$blockClass = ModAPI.reflect.getClassById("net.minecraft.block.Block");
|
||||
var $$iproperty = ModAPI.reflect.getClassById("net.minecraft.block.properties.IProperty").class;
|
||||
var $$makeBlockState = ModAPI.reflect.getClassById("${flags.target === "1_12" ? "net.minecraft.block.state.BlockStateContainer" : "net.minecraft.block.state.BlockState"}").constructors.find(x => x.length === 2);
|
||||
var $$blockSuper = ModAPI.reflect.getSuper($$blockClass, (x) => x.length === 2);
|
||||
|
||||
var $$breakBlockMethod = $$blockClass.methods.breakBlock.method;
|
||||
var $$onBlockAddedMethod = $$blockClass.methods.onBlockAdded.method;
|
||||
var $$onBlockDestroyedByPlayerMethod = $$blockClass.methods.onBlockDestroyedByPlayer.method;
|
||||
var $$randomTickMethod = $$blockClass.methods.randomTick.method;
|
||||
|
||||
var $$getDroppedItem = $$blockClass.methods.getItemDropped.method;
|
||||
var $$quantityDropped = $$blockClass.methods.quantityDropped.method;
|
||||
|
||||
var $$nmb_AdvancedBlock = function $$nmb_AdvancedBlock() {
|
||||
$$blockSuper(this, ModAPI.materials.${this.tags.material}.getRef());
|
||||
${flags.target === "1_12" ? "//" : ""}this.$defaultBlockState = this.$blockState.$getBaseState();
|
||||
${constructorHandler.code};
|
||||
}
|
||||
ModAPI.reflect.prototypeStack($$blockClass, $$nmb_AdvancedBlock);
|
||||
$$nmb_AdvancedBlock.prototype.$isOpaqueCube = function () {
|
||||
return 1;
|
||||
}
|
||||
$$nmb_AdvancedBlock.prototype.$createBlockState = function () {
|
||||
return $$makeBlockState(this, ModAPI.array.object($$iproperty, 0));
|
||||
}
|
||||
$$nmb_AdvancedBlock.prototype.$breakBlock = function (${breakHandler.args.join(", ")}) {
|
||||
${breakHandler.code};
|
||||
return $$breakBlockMethod(this, ${breakHandler.args.join(", ")});
|
||||
}
|
||||
$$nmb_AdvancedBlock.prototype.$onBlockAdded = function (${addedHandler.args.join(", ")}) {
|
||||
${addedHandler.code};
|
||||
return $$onBlockAddedMethod(this, ${addedHandler.args.join(", ")});
|
||||
}
|
||||
|
||||
${neighborHandler}
|
||||
|
||||
$$nmb_AdvancedBlock.prototype.$onBlockDestroyedByPlayer = function (${brokenByPlayerHandler.args.join(", ")}) {
|
||||
${brokenByPlayerHandler.code};
|
||||
return $$onBlockDestroyedByPlayerMethod(this, ${brokenByPlayerHandler.args.join(", ")});
|
||||
}
|
||||
$$nmb_AdvancedBlock.prototype.$randomTick = function (${randomTickHandler.args.join(", ")}) {
|
||||
${randomTickHandler.code};
|
||||
return $$randomTickMethod(this, ${randomTickHandler.args.join(", ")});
|
||||
}
|
||||
$$nmb_AdvancedBlock.prototype.$tickRate = function () {
|
||||
return ${Math.max(1, Math.floor(this.tags.tickRatio || 10))};
|
||||
}
|
||||
|
||||
${entityCollisionHandler}
|
||||
|
||||
$$nmb_AdvancedBlock.prototype.$getItemDropped = function (${getDroppedItemHandler.args.join(", ")}) {
|
||||
${getDroppedItemHandler.code};
|
||||
return $$getDroppedItem(this, ${getDroppedItemHandler.args.join(", ")});
|
||||
}
|
||||
$$nmb_AdvancedBlock.prototype.$quantityDropped = function (${quantityDroppedHandler.args.join(", ")}) {
|
||||
${quantityDroppedHandler.code};
|
||||
return $$quantityDropped(this, ${quantityDroppedHandler.args.join(", ")});
|
||||
}
|
||||
$$nmb_AdvancedBlock.prototype.$quantityDroppedWithBonus = function (${quantityDroppedHandler.args.reverse().join(", ")}) {
|
||||
${quantityDroppedHandler.code};
|
||||
return $$quantityDropped(this, ${quantityDroppedHandler.args.reverse().join(", ")});
|
||||
}
|
||||
|
||||
function $$internal_reg() {
|
||||
var $$cblock = (new $$nmb_AdvancedBlock()).$setUnlocalizedName(
|
||||
ModAPI.util.str("${this.tags.id}")
|
||||
);
|
||||
$$blockClass.staticMethods.registerBlock0.method(
|
||||
ModAPI.keygen.block("${this.tags.id}"),
|
||||
ModAPI.util.str("${this.tags.id}"),
|
||||
$$cblock
|
||||
);
|
||||
$$itemClass.staticMethods.registerItemBlock0.method($$cblock);
|
||||
efb2__fixupBlockIds();
|
||||
ModAPI.blocks["${this.tags.id}"] = $$cblock;
|
||||
|
||||
return $$cblock;
|
||||
}
|
||||
|
||||
if (ModAPI.materials) {
|
||||
return $$internal_reg();
|
||||
} else {
|
||||
ModAPI.addEventListener("bootstrap", $$internal_reg);
|
||||
}
|
||||
}
|
||||
ModAPI.dedicatedServer.appendCode($$ServersideBlocks);
|
||||
var $$cblock = $$ServersideBlocks();
|
||||
ModAPI.addEventListener("lib:asyncsink", async () => {
|
||||
ModAPI.addEventListener("lib:asyncsink:registeritems", ($$renderItem)=>{
|
||||
$$renderItem.registerBlock($$cblock, ModAPI.util.str("${this.tags.id}"));
|
||||
});
|
||||
AsyncSink.L10N.set("tile.${this.tags.id}.name", "${this.tags.name}");
|
||||
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/models/block/${this.tags.id}.json", JSON.stringify(
|
||||
{
|
||||
"parent": "block/cube_all",
|
||||
"textures": {
|
||||
"all": "blocks/${this.tags.id}"
|
||||
}
|
||||
}
|
||||
));
|
||||
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/models/item/${this.tags.id}.json", JSON.stringify(
|
||||
{
|
||||
"parent": "block/${this.tags.id}",
|
||||
"display": {
|
||||
"thirdperson": {
|
||||
"rotation": [10, -45, 170],
|
||||
"translation": [0, 1.5, -2.75],
|
||||
"scale": [0.375, 0.375, 0.375]
|
||||
}
|
||||
}
|
||||
}
|
||||
));
|
||||
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/blockstates/${this.tags.id}.json", JSON.stringify(
|
||||
{
|
||||
"variants": {
|
||||
"normal": [
|
||||
{ "model": "${this.tags.id}" },
|
||||
]
|
||||
}
|
||||
}
|
||||
));
|
||||
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/textures/blocks/${this.tags.id}.png", await (await fetch(
|
||||
$$blockTexture
|
||||
)).arrayBuffer());
|
||||
${this.tags.animatedSpritesheetTexture ? animationCode : ""}
|
||||
});
|
||||
})();`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
PRIMITIVES["command"] = {
|
||||
name: "Command",
|
||||
uses: [],
|
||||
type: "command",
|
||||
tags: {
|
||||
command: "/example_command",
|
||||
caseSensitive: false,
|
||||
playersOnly: true,
|
||||
CalledByPlayer: VALUE_ENUMS.ABSTRACT_HANDLER + "CommandCalledByPlayer",
|
||||
CalledByOther: VALUE_ENUMS.ABSTRACT_HANDLER + "CommandCalled",
|
||||
},
|
||||
getDependencies: function () {
|
||||
return [];
|
||||
},
|
||||
asJavaScript: function () {
|
||||
var escaped = this.tags.command.replaceAll("\"", "\\\"");
|
||||
var len = this.tags.command.length;
|
||||
var callHandler = getHandlerCode("CommandCalled", this.tags.CalledByOther, ["$$args", "$$sender"]);
|
||||
var callPlayerHandler = getHandlerCode("CommandCalledByPlayer", this.tags.CalledByPlayer, ["$$args", "$$sender", "$$player"]);
|
||||
return `
|
||||
(function CommandDatablock() {
|
||||
PluginAPI.dedicatedServer.appendCode(function () {
|
||||
const $$scoped_efb_globals = {};
|
||||
PluginAPI.addEventListener("processcommand", ($$event) => {
|
||||
if ($$event.command${this.tags.caseSensitive ? "" : ".toLowerCase()"}.startsWith("${escaped}")) {
|
||||
var $$arguments = $$event.command.substring(${len + 1}).trim().split(" ").filter(x=>!!x);
|
||||
var $$isPlayer = ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP").instanceOf($$event.sender.getRef());
|
||||
if (
|
||||
$$isPlayer
|
||||
) {
|
||||
(function (${callPlayerHandler.args.join(",")}) {${callPlayerHandler.code}})($$arguments, $$event.sender.getRef(), $$event.sender.getRef());
|
||||
}${this.tags.playersOnly ? "" : ` else {
|
||||
(function (${callHandler.args.join(",")}) {${callHandler.code}})($$arguments, $$event.sender.getRef());
|
||||
}`}
|
||||
$$event.preventDefault = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
})();`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
//TODO: quantityDropped, onBlockDestroyedByExplosion, onBlockActivated
|
||||
PRIMITIVES["recipe"] = {
|
||||
name: "Crafting Recipe",
|
||||
uses: [],
|
||||
type: "recipe",
|
||||
tags: {
|
||||
slot0: VALUE_ENUMS.ABSTRACT_ITEM,
|
||||
slot1: VALUE_ENUMS.ABSTRACT_ITEM,
|
||||
slot2: VALUE_ENUMS.ABSTRACT_ITEM,
|
||||
lf0: VALUE_ENUMS.NEWLINE,
|
||||
slot3: VALUE_ENUMS.ABSTRACT_ITEM,
|
||||
slot4: VALUE_ENUMS.ABSTRACT_ITEM,
|
||||
slot5: VALUE_ENUMS.ABSTRACT_ITEM,
|
||||
lf1: VALUE_ENUMS.NEWLINE,
|
||||
slot6: VALUE_ENUMS.ABSTRACT_ITEM,
|
||||
slot7: VALUE_ENUMS.ABSTRACT_ITEM,
|
||||
slot8: VALUE_ENUMS.ABSTRACT_ITEM,
|
||||
lf2: VALUE_ENUMS.NEWLINE,
|
||||
lf3: VALUE_ENUMS.NEWLINE,
|
||||
resultQuantity: 1,
|
||||
result: VALUE_ENUMS.ABSTRACT_ITEM,
|
||||
lf4: VALUE_ENUMS.NEWLINE,
|
||||
ModifyResult: VALUE_ENUMS.ABSTRACT_HANDLER + "CraftingRecipeModifyResult",
|
||||
},
|
||||
getDependencies: function () {
|
||||
const matchesList = new Set([].bake().dynamicConcat("block_advanced", "id", (x) => {
|
||||
return "block/" + x + "@0"
|
||||
}).dynamicConcat("item", "id", (x) => {
|
||||
return "item/" + x
|
||||
}).calculate());
|
||||
const possibleDepsList = new Set([
|
||||
this.tags.slot0,
|
||||
this.tags.slot1,
|
||||
this.tags.slot2,
|
||||
this.tags.slot3,
|
||||
this.tags.slot4,
|
||||
this.tags.slot5,
|
||||
this.tags.slot6,
|
||||
this.tags.slot7,
|
||||
this.tags.slot8,
|
||||
this.tags.result
|
||||
]);
|
||||
const deps = [...matchesList.intersection(possibleDepsList)].map(x => {
|
||||
if (x.startsWith("block/")) {
|
||||
x = x.replace("block/", "").split("@");
|
||||
x = x[0];
|
||||
return state.nodes.find(y => (y.type === "block_advanced") && (y.tags.id === x))
|
||||
} else {
|
||||
x = x.replace("item/", "");
|
||||
return state.nodes.find(y => (y.type === "item") && (y.tags.id === x))
|
||||
}
|
||||
});
|
||||
return deps;
|
||||
},
|
||||
asJavaScript: function () {
|
||||
Object.keys(this.tags).forEach(k => {
|
||||
this.tags[k] = (this.tags[k] === VALUE_ENUMS.ABSTRACT_ITEM) ? "item/air" : this.tags[k];
|
||||
});
|
||||
const grid = [
|
||||
[this.tags.slot0, this.tags.slot1, this.tags.slot2],
|
||||
[this.tags.slot3, this.tags.slot4, this.tags.slot5],
|
||||
[this.tags.slot6, this.tags.slot7, this.tags.slot8]
|
||||
];
|
||||
var minX = 2;
|
||||
var minY = 2;
|
||||
var maxX = 0;
|
||||
var maxY = 0;
|
||||
for (let y = 0; y < grid.length; y++) {
|
||||
const row = grid[y];
|
||||
for (let x = 0; x < row.length; x++) {
|
||||
const cell = row[x];
|
||||
if (cell === "item/air") {
|
||||
continue;
|
||||
}
|
||||
minX = Math.min(minX, x);
|
||||
minY = Math.min(minY, y);
|
||||
maxX = Math.max(maxX, x);
|
||||
maxY = Math.max(maxY, y);
|
||||
}
|
||||
}
|
||||
minX = Math.min(minX, maxX);
|
||||
minY = Math.min(minY, maxY);
|
||||
maxX = Math.max(maxX, minX);
|
||||
maxY = Math.max(maxY, minY);
|
||||
const newGrid = (new Array((maxY + 1) - minY)).fill([]).map(() => (new Array((maxX + 1) - minX)).fill("item/air"));
|
||||
for (let x = minX; x < (maxX + 1); x++) {
|
||||
for (let y = minY; y < (maxY + 1); y++) {
|
||||
newGrid[y - minY][x - minX] = grid[y][x];
|
||||
}
|
||||
}
|
||||
const uniqueTypesMap = Object.fromEntries([...new Set(newGrid.flat())].filter(x => x !== "item/air").map((x, i) => {
|
||||
return [x, String.fromCharCode(65 + i)];
|
||||
}));
|
||||
const uniqueTypesMapReverse = Object.fromEntries([...new Set(newGrid.flat())].filter(x => x !== "item/air").map((x, i) => {
|
||||
return [String.fromCharCode(65 + i), x];
|
||||
}));
|
||||
var legendStr = "";
|
||||
const ks = Object.keys(uniqueTypesMapReverse);
|
||||
ks.forEach((k, i) => {
|
||||
if (flags.target === "1_12") {
|
||||
legendStr += `"${k}": {
|
||||
item: "minecraft:${uniqueTypesMapReverse[k].split("/")[1].split("@")[0]}",
|
||||
${uniqueTypesMapReverse[k].includes("@") ? `data: ${parseInt(uniqueTypesMapReverse[k].split("/")[1].split("@")[1]) || 0}` : ""}
|
||||
}${ks.length === (i+1) ? "" : ","}`
|
||||
} else {
|
||||
legendStr += `"${k}": {
|
||||
type: "${uniqueTypesMapReverse[k].split("/")[0]}",
|
||||
id: "${uniqueTypesMapReverse[k].split("/")[1].split("@")[0]}",
|
||||
${uniqueTypesMapReverse[k].includes("@") ? `meta: ${parseInt(uniqueTypesMapReverse[k].split("/")[1].split("@")[1]) || 0}` : ""}
|
||||
}${ks.length === (i+1) ? "" : ","}`
|
||||
}
|
||||
});
|
||||
var $$recipePattern = "";
|
||||
for (let y = 0; y < newGrid.length; y++) {
|
||||
const row = newGrid[y];
|
||||
$$recipePattern += '"';
|
||||
for (let x = 0; x < row.length; x++) {
|
||||
const cell = row[x];
|
||||
$$recipePattern += `${cell === "item/air" ? " " : uniqueTypesMap[cell]}`
|
||||
}
|
||||
$$recipePattern += '"';
|
||||
$$recipePattern += ",";
|
||||
}
|
||||
var modifyResultHandler = getHandlerCode("CraftingRecipeModifyResult", this.tags.ModifyResult, ["$$itemstack"]);
|
||||
if (flags.target === "1_12") {
|
||||
return `(function CraftingRecipeDatablock112() {
|
||||
|
||||
async function registerRecipe(isServer) {
|
||||
if (isServer) {
|
||||
await new Promise((res, rej) => {
|
||||
ModAPI.addEventListener("bootstrap", res);
|
||||
});
|
||||
}
|
||||
const parseJson = ModAPI.reflect.getClassByName("JSONObject").constructors.findLast(x => x.length === 1);
|
||||
const CraftingManager = ModAPI.reflect.getClassByName("CraftingManager");
|
||||
const CraftingManagerMethods = CraftingManager.staticMethods;
|
||||
const jsonData = parseJson(ModAPI.util.str(\`{
|
||||
"type": "crafting_shaped", ${/*/or crafting_shapeless/*/""}
|
||||
"pattern": [
|
||||
${$$recipePattern}
|
||||
],
|
||||
"key": {
|
||||
${legendStr}
|
||||
},
|
||||
"result": {
|
||||
"item": "minecraft:${this.tags.result.split("/")[1].split("@")[0]}",
|
||||
"data": ${this.tags.result.split("/")[1].split("@")[1] || "0"},
|
||||
"count": ${this.tags.resultQuantity}
|
||||
}
|
||||
}\`.trim()));
|
||||
const recipeObj = CraftingManagerMethods.func_193376_a.method(jsonData); //convert json to an IRecipe
|
||||
CraftingManagerMethods.func_193379_a.method(ModAPI.util.str("coolrecipeid"), recipeObj); //register recipe under resource location
|
||||
}
|
||||
|
||||
ModAPI.dedicatedServer.appendCode(registerRecipe);
|
||||
registerRecipe(false);
|
||||
})();
|
||||
`;
|
||||
} else {
|
||||
return `(function CraftingRecipeDatablock() {
|
||||
function $$registerRecipe() {
|
||||
function $$internalRegister() {
|
||||
const $$scoped_efb_globals = {};
|
||||
var $$ObjectClass = ModAPI.reflect.getClassById("java.lang.Object").class;
|
||||
function $$ToChar(char) {
|
||||
return ModAPI.reflect.getClassById("java.lang.Character").staticMethods.valueOf.method(char[0].charCodeAt(0));
|
||||
}
|
||||
var $$resultItemArg = "${this.tags.result.replace("item/air", "block/air")}";
|
||||
var $$recipeLegend = {
|
||||
${legendStr}
|
||||
};
|
||||
var $$recipePattern = [
|
||||
${$$recipePattern}
|
||||
];
|
||||
var $$itemStackFromBlockWithMeta = ModAPI.reflect.getClassById("net.minecraft.item.ItemStack").constructors[2];
|
||||
var $$itemStackFromItem = ModAPI.reflect.getClassById("net.minecraft.item.ItemStack").constructors[4];
|
||||
var $$recipeInternal = [];
|
||||
Object.keys($$recipeLegend).forEach(($$key) => {
|
||||
$$recipeInternal.push($$ToChar($$key));
|
||||
var $$ingredient = ($$recipeLegend[$$key].type === "block" ? $$itemStackFromBlockWithMeta(ModAPI.blocks[$$recipeLegend[$$key].id].getRef(),1,$$recipeLegend[$$key].meta) : ModAPI.items[$$recipeLegend[$$key].id].getRef());
|
||||
$$recipeInternal.push($$ingredient);
|
||||
});
|
||||
|
||||
var $$recipeContents = $$recipePattern.map(row => ModAPI.util.str(row));
|
||||
var $$recipe = ModAPI.util.makeArray($$ObjectClass, $$recipeContents.concat($$recipeInternal));
|
||||
|
||||
var $$resultItem = $$resultItemArg.startsWith("block/") ?
|
||||
($$itemStackFromBlockWithMeta(ModAPI.blocks[$$resultItemArg.replace("block/", "").split("@")[0]].getRef(),${this.tags.resultQuantity},$$resultItemArg.replace("block/", "").split("@")[1] || 0))
|
||||
: ($$itemStackFromItem(ModAPI.items[$$resultItemArg.replace("item/", "")].getRef(), ${this.tags.resultQuantity}));
|
||||
|
||||
(function (${modifyResultHandler.args.join(",")}) {${modifyResultHandler.code}})($$resultItem);
|
||||
|
||||
var $$craftingManager = ModAPI.reflect.getClassById("net.minecraft.item.crafting.CraftingManager").staticMethods.getInstance.method();
|
||||
ModAPI.hooks.methods.nmic_CraftingManager_addRecipe($$craftingManager, $$resultItem, $$recipe);
|
||||
|
||||
}
|
||||
|
||||
if (ModAPI.items) {
|
||||
$$internalRegister();
|
||||
} else {
|
||||
ModAPI.addEventListener("bootstrap", $$internalRegister);
|
||||
}
|
||||
}
|
||||
ModAPI.dedicatedServer.appendCode($$registerRecipe);
|
||||
$$registerRecipe();
|
||||
})();`;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
PRIMITIVES["furnace_recipe"] = {
|
||||
name: "Furnace Recipe",
|
||||
uses: [],
|
||||
type: "furnace_recipe",
|
||||
tags: {
|
||||
input: VALUE_ENUMS.ABSTRACT_ITEM, // item/block to smelt
|
||||
lf0: VALUE_ENUMS.NEWLINE,
|
||||
lf1: VALUE_ENUMS.NEWLINE,
|
||||
resultQuantity: 1, // output count
|
||||
result: VALUE_ENUMS.ABSTRACT_ITEM, // smelt result
|
||||
lf3: VALUE_ENUMS.NEWLINE,
|
||||
experience: 0.1, // xp gained
|
||||
},
|
||||
getDependencies: function () {
|
||||
const deps = [];
|
||||
[this.tags.input, this.tags.result].forEach(entry => {
|
||||
if (!entry || entry === "item/air") return;
|
||||
if (entry.startsWith("block/")) {
|
||||
let id = entry.replace("block/", "").split("@")[0];
|
||||
const dep = state.nodes.find(y => y.type === "block_advanced" && y.tags.id === id);
|
||||
if (dep) deps.push(dep);
|
||||
} else if (entry.startsWith("item/")) {
|
||||
let id = entry.replace("item/", "").split("@")[0];
|
||||
const dep = state.nodes.find(y => y.type === "item" && y.tags.id === id);
|
||||
if (dep) deps.push(dep);
|
||||
}
|
||||
});
|
||||
return deps;
|
||||
},
|
||||
asJavaScript: function () {
|
||||
// Create a copy of tags to avoid modifying the original
|
||||
const tags = { ...this.tags };
|
||||
Object.keys(tags).forEach(k => {
|
||||
tags[k] = (tags[k] === VALUE_ENUMS.ABSTRACT_ITEM) ? "item/air" : tags[k];
|
||||
});
|
||||
|
||||
return `(function FurnaceRecipeDatablock() {
|
||||
async function $$registerFurnaceRecipe(isServer) {
|
||||
await new Promise((res, rej) => {
|
||||
if (!isServer) {
|
||||
res();
|
||||
} else {
|
||||
ModAPI.addEventListener("bootstrap", res);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
const FurnaceRecipesInstance = ModAPI.util.wrap(ModAPI.reflect.getClassByName("FurnaceRecipes").staticVariables.smeltingBase);
|
||||
|
||||
function parseEntry(entry) {
|
||||
if (!entry || entry === "item/air") return null;
|
||||
|
||||
var type, id, meta = 0;
|
||||
if (entry.includes("@")) {
|
||||
const parts = entry.split("@");
|
||||
id = parts[0];
|
||||
meta = parseInt(parts[1], 10) || 0;
|
||||
} else {
|
||||
id = entry;
|
||||
}
|
||||
|
||||
if (id.startsWith("block/")) {
|
||||
type = "block";
|
||||
id = id.replace("block/", "");
|
||||
} else if (id.startsWith("item/")) {
|
||||
type = "item";
|
||||
id = id.replace("item/", "");
|
||||
} else {
|
||||
if (ModAPI.blocks && ModAPI.blocks[id]) type = "block";
|
||||
else if (ModAPI.items && ModAPI.items[id]) type = "item";
|
||||
else {
|
||||
console.warn("Unknown item/block id: " + entry);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return { type, id, meta };
|
||||
}
|
||||
|
||||
var input = parseEntry("${tags.input}");
|
||||
var output = parseEntry("${tags.result}");
|
||||
|
||||
if (!input || !output) {
|
||||
console.warn("Invalid furnace recipe: missing input or output");
|
||||
return;
|
||||
}
|
||||
|
||||
var $$outputStack;
|
||||
if (output.type === "block") {
|
||||
if (!ModAPI.blocks[output.id]) {
|
||||
console.warn("Block not found: " + output.id);
|
||||
return;
|
||||
}
|
||||
$$outputStack = ModAPI.reflect.getClassById("net.minecraft.item.ItemStack").constructors[1](ModAPI.blocks[output.id].getRef(), ${tags.resultQuantity});
|
||||
} else {
|
||||
if (!ModAPI.items[output.id]) {
|
||||
console.warn("Item not found: " + output.id);
|
||||
return;
|
||||
}
|
||||
$$outputStack = ModAPI.reflect.getClassById("net.minecraft.item.ItemStack").constructors[4](ModAPI.items[output.id].getRef(), ${tags.resultQuantity});
|
||||
}
|
||||
|
||||
if (input.type === "block") {
|
||||
if (!ModAPI.blocks[input.id]) {
|
||||
console.warn("Input block not found: " + input.id);
|
||||
return;
|
||||
}
|
||||
FurnaceRecipesInstance.addSmeltingRecipeForBlock(ModAPI.blocks[input.id].getRef(), $$outputStack, ${tags.experience});
|
||||
} else {
|
||||
if (!ModAPI.items[input.id]) {
|
||||
console.warn("Input item not found: " + input.id);
|
||||
return;
|
||||
}
|
||||
FurnaceRecipesInstance.addSmelting(ModAPI.items[input.id].getRef(), $$outputStack, ${tags.experience});
|
||||
}
|
||||
|
||||
console.log("Registered furnace recipe: " + "${tags.input}" + " -> " + "${tags.result}");
|
||||
} catch (e) {
|
||||
console.error("Error registering furnace recipe:", e);
|
||||
}
|
||||
}
|
||||
|
||||
$$registerFurnaceRecipe();
|
||||
if (ModAPI.dedicatedServer && ModAPI.dedicatedServer.appendCode) {
|
||||
ModAPI.dedicatedServer.appendCode($$registerFurnaceRecipe);
|
||||
}
|
||||
})();`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
PRIMITIVES["icon"] = {
|
||||
name: "Icon",
|
||||
uses: [],
|
||||
type: "icon",
|
||||
tags: {
|
||||
Icon: VALUE_ENUMS.IMG,
|
||||
},
|
||||
getDependencies: function () {
|
||||
return [];
|
||||
},
|
||||
asJavaScript: function () {
|
||||
if (!this.tags.Icon || this.tags.Icon === VALUE_ENUMS.IMG) {
|
||||
return "";
|
||||
}
|
||||
return `
|
||||
(function IconDatablock() {
|
||||
ModAPI.meta.icon("${this.tags.Icon}");
|
||||
})();`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
PRIMITIVES["inspector"] = {
|
||||
name: "Inspector",
|
||||
uses: [],
|
||||
type: "inspector",
|
||||
hidden: true,
|
||||
tags: {
|
||||
},
|
||||
getDependencies: function () {
|
||||
return [];
|
||||
},
|
||||
asJavaScript: function () {
|
||||
return ``;
|
||||
}
|
||||
}
|
||||
|
||||
var inspectorFrame = document.createElement("iframe");
|
||||
inspectorFrame.id = "inspector";
|
||||
inspectorFrame.style.position = "fixed";
|
||||
inspectorFrame.style.border = "0";
|
||||
inspectorFrame.style.display = "none";
|
||||
inspectorFrame.style.pointerEvents = "none";
|
||||
inspectorFrame.style.backgroundColor = "white";
|
||||
inspectorFrame.allowFullscreen = true;
|
||||
inspectorFrame.tabIndex = 0;
|
||||
inspectorFrame.srcdoc = "<h3>Use the 'Run' button and select an EaglerForge build.</h3>";
|
||||
inspectorFrame.addEventListener("mouseover", ()=>{
|
||||
inspectorFrame.focus();
|
||||
});
|
||||
var propnav = document.querySelector("#propnav");
|
||||
function positionInspectorFrame() {
|
||||
var aabb = propnav.getBoundingClientRect();
|
||||
inspectorFrame.style.top = aabb.top + "px";
|
||||
inspectorFrame.style.left = aabb.left + "px";
|
||||
inspectorFrame.style.width = aabb.width + "px";
|
||||
inspectorFrame.style.height = aabb.height + "px";
|
||||
}
|
||||
positionInspectorFrame();
|
||||
var inspectorFrameReposTimer = null;
|
||||
document.body.appendChild(inspectorFrame);
|
||||
@@ -0,0 +1,210 @@
|
||||
PRIMITIVES["item"] = {
|
||||
name: "Item",
|
||||
uses: [],
|
||||
type: "item",
|
||||
tags: {
|
||||
id: "custom_item",
|
||||
name: "Custom Item",
|
||||
texture: VALUE_ENUMS.IMG,
|
||||
firstPersonScale: 1.7,
|
||||
thirdPersonScale: 0.55,
|
||||
useDurationTicks: 32,
|
||||
useItemOnRightClick: true,
|
||||
itemUseAnimation: ["NONE", "EAT", "DRINK", "BLOCK", "BOW"],
|
||||
Constructor: VALUE_ENUMS.ABSTRACT_HANDLER + "ItemConstructor",
|
||||
RightClick: VALUE_ENUMS.ABSTRACT_HANDLER + "ItemRightClick",
|
||||
Used: VALUE_ENUMS.ABSTRACT_HANDLER + "ItemUsed",
|
||||
Tick: VALUE_ENUMS.ABSTRACT_HANDLER + "ItemTicked",
|
||||
UsedOnBlock: VALUE_ENUMS.ABSTRACT_HANDLER + "ItemBlockUse",
|
||||
Crafted: VALUE_ENUMS.ABSTRACT_HANDLER + "ItemCrafted",
|
||||
BlockBroken: VALUE_ENUMS.ABSTRACT_HANDLER + "ItemBlockBroken",
|
||||
GetAttributes: VALUE_ENUMS.ABSTRACT_HANDLER + "ItemGetAttributes",
|
||||
GetEfficiency: VALUE_ENUMS.ABSTRACT_HANDLER + "ItemGetEfficiency",
|
||||
},
|
||||
getDependencies: function () {
|
||||
return [];
|
||||
},
|
||||
asJavaScript: function () {
|
||||
const firstPersonScale = this.tags.firstPersonScale / (flags.target === "1_12" ? 1.7 : 1);
|
||||
const thirdPersonScale = this.tags.thirdPersonScale / (flags.target === "1_12" ? 0.55 : 1);
|
||||
var constructorHandler = getHandlerCode("ItemConstructor", this.tags.Constructor, []);
|
||||
var rightClickHandler = getHandlerCode("ItemRightClick", this.tags.RightClick, ["$$itemstack", "$$world", "$$player"], {
|
||||
"1_8": function (argNames, code) {
|
||||
return `
|
||||
$$CustomItem.prototype.$onItemRightClick = function (${argNames.join(", ")}) {
|
||||
${this.tags.useItemOnRightClick ?
|
||||
`(${argNames[2]}).$setItemInUse(${argNames[0]},${this.tags.useDurationTicks});`
|
||||
: ""}
|
||||
${code};
|
||||
return (${argNames[0]});
|
||||
}
|
||||
`
|
||||
},
|
||||
"1_12": function (argNames, code) {
|
||||
return `
|
||||
var $$ResultEnum = ModAPI.reflect.getClassByName("EnumActionResult").staticVariables;
|
||||
var $$ActionResult = ModAPI.reflect.getClassByName("ActionResult").constructors[0];
|
||||
$$CustomItem.prototype.$onItemRightClick = function (${argNames.slice(1, 3).join(", ")},$handEnum,$unused) {
|
||||
var ${argNames[0]} = (${argNames[2]}).$getHeldItem($handEnum);
|
||||
${this.tags.useItemOnRightClick ?
|
||||
`
|
||||
(${argNames[2]}).$setActiveHand($handEnum);
|
||||
`
|
||||
: ""}
|
||||
${code};
|
||||
return ($$ActionResult(${this.tags.useItemOnRightClick ? "$$ResultEnum.SUCCESS" : "$$ResultEnum.PASS"}, ${argNames[0]}));
|
||||
}
|
||||
`
|
||||
}
|
||||
});
|
||||
var blockUseHandler = getHandlerCode("ItemBlockUse", this.tags.UsedOnBlock, ["$$itemstack", "$$player", "$$world", "$$blockpos"], {
|
||||
"1_8": function (args, code) {
|
||||
return `
|
||||
$$CustomItem.prototype.$onItemUse0 = function (${args.join(", ")}) {
|
||||
${code};
|
||||
return 0;
|
||||
}
|
||||
`
|
||||
},
|
||||
"1_12": function (args, code) {
|
||||
return `
|
||||
var $$ResultEnum = ModAPI.reflect.getClassByName("EnumActionResult").staticVariables;
|
||||
$$CustomItem.prototype.$onItemUse = function (${args.join(", ")}) {
|
||||
${code};
|
||||
return $$ResultEnum.PASS;
|
||||
}
|
||||
`
|
||||
}
|
||||
});
|
||||
var usedHandler = getHandlerCode("ItemUsed", this.tags.Used, ["$$itemstack", "$$world", "$$player"]);
|
||||
var tickedHandler = getHandlerCode("ItemTicked", this.tags.Tick, ["$$itemstack", "$$world", "$$player", "$$hotbar_slot", "$$is_held"]);
|
||||
var craftedHandler = getHandlerCode("ItemCrafted", this.tags.Crafted, ["$$itemstack", "$$world", "$$player"]);
|
||||
var blockBrokenHandler = getHandlerCode("ItemBlockBroken", this.tags.BlockBroken, ["$$itemstack", "$$world", "$$block", "$$blockpos", "$$entity"]);
|
||||
var getAttributes = getHandlerCode("ItemGetAttributes", this.tags.GetAttributes, ["$$attributemap"]);
|
||||
var getEfficiency = getHandlerCode("ItemGetEfficiency", this.tags.GetEfficiency, ["$$itemstack", "$$block"]);
|
||||
|
||||
const transforms = flags.target === "1_12"
|
||||
? {
|
||||
"thirdperson_righthand": {
|
||||
"rotation": [0, -90, 55],
|
||||
"translation": [0, 4.0, 0.5],
|
||||
"scale": [0.85 * thirdPersonScale, 0.85 * thirdPersonScale, 0.85 * thirdPersonScale]
|
||||
},
|
||||
"thirdperson_lefthand": {
|
||||
"rotation": [0, 90, -55],
|
||||
"translation": [0, 4.0, 0.5],
|
||||
"scale": [0.85 * thirdPersonScale, 0.85 * thirdPersonScale, 0.85 * thirdPersonScale]
|
||||
},
|
||||
"firstperson_righthand": {
|
||||
"rotation": [0, -90, 25],
|
||||
"translation": [1.13, 3.2, 1.13],
|
||||
"scale": [0.68 * firstPersonScale, 0.68 * firstPersonScale, 0.68 * firstPersonScale]
|
||||
},
|
||||
"firstperson_lefthand": {
|
||||
"rotation": [0, 90, -25],
|
||||
"translation": [1.13, 3.2, 1.13],
|
||||
"scale": [0.68 * firstPersonScale, 0.68 * firstPersonScale, 0.68 * firstPersonScale]
|
||||
}
|
||||
}
|
||||
: {
|
||||
"thirdperson": {
|
||||
"rotation": [-90, 0, 0],
|
||||
"translation": [0, 1, -3],
|
||||
"scale": [thirdPersonScale, thirdPersonScale, thirdPersonScale]
|
||||
},
|
||||
"firstperson": {
|
||||
"rotation": [0, -135, 25],
|
||||
"translation": [0, 4, 2],
|
||||
"scale": [firstPersonScale, firstPersonScale, firstPersonScale]
|
||||
}
|
||||
};
|
||||
|
||||
return `(function ItemDatablock() {
|
||||
const $$itemTexture = "${this.tags.texture}";
|
||||
|
||||
function $$ServersideItem() {
|
||||
const $$scoped_efb_globals = {};
|
||||
var $$itemClass = ModAPI.reflect.getClassById("net.minecraft.item.Item");
|
||||
var $$itemSuper = ModAPI.reflect.getSuper($$itemClass, (x) => x.length === 1);
|
||||
var $$itemUseAnimation = ModAPI.reflect.getClassById("net.minecraft.item.EnumAction").staticVariables["${this.tags.itemUseAnimation}"];
|
||||
var $$itemGetAttributes = ModAPI.reflect.getClassById("net.minecraft.item.Item").methods.getItemAttributeModifiers.method;
|
||||
|
||||
function $$CustomItem() {
|
||||
$$itemSuper(this);
|
||||
${constructorHandler.code};
|
||||
}
|
||||
ModAPI.reflect.prototypeStack($$itemClass, $$CustomItem);
|
||||
${rightClickHandler}
|
||||
$$CustomItem.prototype.$getMaxItemUseDuration = function () { //1.12 works
|
||||
return ${this.tags.useDurationTicks};
|
||||
}
|
||||
$$CustomItem.prototype.$getItemUseAction = function () { //1.12 works
|
||||
return $$itemUseAnimation;
|
||||
}
|
||||
$$CustomItem.prototype.$onItemUseFinish = function (${usedHandler.args.join(", ")}) { //1.12 works
|
||||
${usedHandler.code};
|
||||
return (${usedHandler.args[0]});
|
||||
}
|
||||
$$CustomItem.prototype.$onUpdate = function (${tickedHandler.args.join(", ")}) { //1.12 works
|
||||
${tickedHandler.args[4]} = (${tickedHandler.args[4]}) ? true : false;
|
||||
${tickedHandler.code};
|
||||
return (${tickedHandler.args[0]});
|
||||
}
|
||||
|
||||
${blockUseHandler}
|
||||
|
||||
$$CustomItem.prototype.$onCreated = function (${craftedHandler.args.join(", ")}) { //1.12 works
|
||||
${craftedHandler.code};
|
||||
}
|
||||
$$CustomItem.prototype.$onBlockDestroyed = function (${blockBrokenHandler.args.join(", ")}) {
|
||||
${blockBrokenHandler.code};
|
||||
return 0;
|
||||
}
|
||||
$$CustomItem.prototype.$getItemAttributeModifiers = function () { //1.12 works i think
|
||||
var ${getAttributes.args[0]} = $$itemGetAttributes.apply(this, []);
|
||||
${getAttributes.code};
|
||||
return ${getAttributes.args[0]};
|
||||
}
|
||||
$$CustomItem.prototype.$getStrVsBlock = function (${getEfficiency.args.join(", ")}) {
|
||||
${getEfficiency.code};
|
||||
return 1.0;
|
||||
}
|
||||
function $$internal_reg() {
|
||||
var $$custom_item = (new $$CustomItem()).$setUnlocalizedName(
|
||||
ModAPI.util.str("${this.tags.id}")
|
||||
);
|
||||
$$itemClass.staticMethods.registerItem.method(ModAPI.keygen.item("${this.tags.id}"), ModAPI.util.str("${this.tags.id}"), $$custom_item);
|
||||
ModAPI.items["${this.tags.id}"] = $$custom_item;
|
||||
return $$custom_item;
|
||||
}
|
||||
if (ModAPI.items) {
|
||||
return $$internal_reg();
|
||||
} else {
|
||||
ModAPI.addEventListener("bootstrap", $$internal_reg);
|
||||
}
|
||||
}
|
||||
|
||||
ModAPI.dedicatedServer.appendCode($$ServersideItem);
|
||||
var $$custom_item = $$ServersideItem();
|
||||
|
||||
ModAPI.addEventListener("lib:asyncsink", async () => {
|
||||
ModAPI.addEventListener("lib:asyncsink:registeritems", ($$renderItem)=>{
|
||||
$$renderItem.registerItem($$custom_item, ModAPI.util.str("${this.tags.id}"));
|
||||
});
|
||||
AsyncSink.L10N.set("item.${this.tags.id}.name", "${this.tags.name}");
|
||||
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/models/item/${this.tags.id}.json", JSON.stringify(
|
||||
{
|
||||
"parent": "builtin/generated",
|
||||
"textures": {
|
||||
"layer0": "items/${this.tags.id}"
|
||||
},
|
||||
"display": ${JSON.stringify(transforms)}
|
||||
}
|
||||
));
|
||||
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/textures/items/${this.tags.id}.png", await (await fetch(
|
||||
$$itemTexture
|
||||
)).arrayBuffer());
|
||||
});
|
||||
})();`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
PRIMITIVES["metadata"] = {
|
||||
name: "Metadata",
|
||||
uses: [],
|
||||
type: "metadata",
|
||||
tags: {
|
||||
Title: "My Awesome Mod",
|
||||
Version: "v1.0",
|
||||
Description: "Does literally nothing",
|
||||
Credits: "By <author>"
|
||||
},
|
||||
getDependencies: function () {
|
||||
return [];
|
||||
},
|
||||
asJavaScript: function () {
|
||||
return `
|
||||
(function MetadataDatablock() {
|
||||
ModAPI.meta.title("${this.tags.Title.replaceAll('"', '')}");
|
||||
ModAPI.meta.version("${this.tags.Version.replaceAll('"', '')}");
|
||||
ModAPI.meta.description("${this.tags.Description.replaceAll('"', '')}");
|
||||
ModAPI.meta.credits("${this.tags.Credits.replaceAll('"', '')}");
|
||||
})();`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
//TODO: quantityDropped, onBlockDestroyedByExplosion, onBlockActivated
|
||||
PRIMITIVES["ore_generation"] = {
|
||||
name: "Ore Generation",
|
||||
type: "ore_generation",
|
||||
tags: {
|
||||
oreBlock: VALUE_ENUMS.ABSTRACT_BLOCK,
|
||||
lf0: VALUE_ENUMS.NEWLINE,
|
||||
veinSize: 4,
|
||||
veinCount: 105,
|
||||
minGenerationHeight: 0,
|
||||
maxGenerationHeight: 256
|
||||
},
|
||||
getDependencies: function () {
|
||||
const matchesList = new Set([].bake().dynamicConcat("block_advanced", "id", (x) => {
|
||||
return "block/" + x + "@0"
|
||||
}).calculate());
|
||||
const possibleDepsList = new Set([
|
||||
this.tags.oreBlock
|
||||
]);
|
||||
const deps = [...matchesList.intersection(possibleDepsList)].map(x => {
|
||||
x = x.replace("block/", "").split("@");
|
||||
x = x[0];
|
||||
return state.nodes.find(y => (y.type === "block_advanced") && (y.tags.id === x))
|
||||
});
|
||||
return deps;
|
||||
},
|
||||
asJavaScript: function () {
|
||||
var blockId = this.tags.oreBlock.replaceAll("block/", "").split("@")[0];
|
||||
var blockMeta = parseInt(this.tags.oreBlock.replaceAll("block/", "").split("@")[0]) || 0;
|
||||
var salt = "XXXXXX".split("").map(x => Math.floor(Math.random() * 10)).join("");
|
||||
return `(function OreGenerationDatablock() {
|
||||
ModAPI.dedicatedServer.appendCode(()=>{
|
||||
const WorldGenMineable = ModAPI.reflect.getClassById("net.minecraft.world.gen.feature.WorldGenMinable").constructors.find(x=>x.length===2);
|
||||
|
||||
const BiomeDecorator_decorate = ModAPI.util.getMethodFromPackage("net.minecraft.world.biome.BiomeDecorator", "decorate");
|
||||
const oldDecorate = ModAPI.hooks.methods[BiomeDecorator_decorate];
|
||||
ModAPI.hooks.methods[BiomeDecorator_decorate] = function ($this, $world, $random, $biomeGenBase, $blockpos) {
|
||||
if (!$this.$currentWorld) {
|
||||
$this[\`$efb2__${blockId + blockMeta}_${salt}_BlockGen\`] = WorldGenMineable(ModAPI.blocks[\`${blockId}\`].getStateFromMeta(${blockMeta}).getRef(), ${this.tags.veinSize});
|
||||
}
|
||||
return oldDecorate.apply(this, [$this, $world, $random, $biomeGenBase, $blockpos]);
|
||||
}
|
||||
|
||||
const BiomeDecorator_generateOres = ModAPI.util.getMethodFromPackage("net.minecraft.world.biome.BiomeDecorator", "generateOres");
|
||||
const oldGenerateOres = ModAPI.hooks.methods[BiomeDecorator_generateOres];
|
||||
ModAPI.hooks.methods[BiomeDecorator_generateOres] = function ($this) {
|
||||
$this.$genStandardOre1(${this.tags.veinCount}, $this[\`$efb2__${blockId + blockMeta}_${salt}_BlockGen\`] || null, ${this.tags.minGenerationHeight}, ${this.tags.maxGenerationHeight});
|
||||
return oldGenerateOres.apply(this, [$this]);
|
||||
}
|
||||
});
|
||||
})();`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
const InlineValues = [
|
||||
VALUE_ENUMS.ABSTRACT_BLOCK,
|
||||
VALUE_ENUMS.ABSTRACT_ITEM
|
||||
];
|
||||
function editObject(obj, datablock) {
|
||||
if (obj.type === "inspector") {
|
||||
inspectorFrame.style.display = "block";
|
||||
inspectorFrame.style.pointerEvents = "all";
|
||||
inspectorFrameReposTimer = setInterval(positionInspectorFrame, 1000 / 15);
|
||||
} else {
|
||||
inspectorFrame.style.display = "none";
|
||||
inspectorFrame.style.pointerEvents = "none";
|
||||
if (inspectorFrameReposTimer === null) {
|
||||
inspectorFrameReposTimer = null;
|
||||
clearInterval(inspectorFrameReposTimer);
|
||||
}
|
||||
}
|
||||
var propnav = document.querySelector("#propnav");
|
||||
propnav.innerHTML = "";
|
||||
|
||||
var nameField = document.createElement("input");
|
||||
nameField.placeholder = "Datablock Name";
|
||||
nameField.type = "text";
|
||||
nameField.value = obj.name;
|
||||
nameField.addEventListener("input", () => {
|
||||
obj.name = nameField.value || "No name";
|
||||
datablock.querySelector("h4").innerText = obj.name;
|
||||
});
|
||||
propnav.appendChild(nameField);
|
||||
|
||||
propnav.appendChild(document.createElement("br"));
|
||||
propnav.appendChild(document.createElement("br"));
|
||||
|
||||
var keys = Object.keys(obj.tags);
|
||||
keys.forEach(k => {
|
||||
const parentValue = PRIMITIVES[obj.type].tags[k];
|
||||
const isInline = InlineValues.includes(parentValue);
|
||||
|
||||
if (parentValue === VALUE_ENUMS.NEWLINE) {
|
||||
return propnav.appendChild(document.createElement("br"));;
|
||||
}
|
||||
|
||||
if (!isInline) {
|
||||
var label = document.createElement("label");
|
||||
label.innerText = k + ": ";
|
||||
propnav.appendChild(label);
|
||||
}
|
||||
|
||||
var input = document.createElement("input");
|
||||
var val = obj.tags[k];
|
||||
if (typeof val === "number") {
|
||||
input.type = "number";
|
||||
}
|
||||
if (typeof val === "string") {
|
||||
input.type = "text";
|
||||
}
|
||||
|
||||
input.value = val;
|
||||
|
||||
if (typeof val === "boolean") {
|
||||
input.type = "checkbox";
|
||||
input.checked = val;
|
||||
}
|
||||
|
||||
if (val === VALUE_ENUMS.FILE) {
|
||||
input.type = "file";
|
||||
}
|
||||
|
||||
if (val === VALUE_ENUMS.IMG) {
|
||||
input.type = "file";
|
||||
input.accept = "image/png";
|
||||
}
|
||||
if (parentValue === VALUE_ENUMS.ABSTRACT_ITEM) {
|
||||
input = makeItemSelector(val, false, function () {
|
||||
obj.tags[k] = input.value;
|
||||
});
|
||||
}
|
||||
if (parentValue === VALUE_ENUMS.ABSTRACT_BLOCK) {
|
||||
input = makeItemSelector(val, true, function () {
|
||||
obj.tags[k] = input.value;
|
||||
});
|
||||
}
|
||||
if ((typeof parentValue === "string") && parentValue.startsWith(VALUE_ENUMS.ABSTRACT_HANDLER)) {
|
||||
input = document.createElement("select");
|
||||
var handlers = ["None"].concat(getHandlers(parentValue.replace(VALUE_ENUMS.ABSTRACT_HANDLER, '')));
|
||||
handlers.forEach(opt => {
|
||||
var option = document.createElement("option");
|
||||
option.value = opt;
|
||||
option.innerText = opt;
|
||||
if (opt === obj.tags[k]) {
|
||||
option.selected = true;
|
||||
}
|
||||
input.appendChild(option);
|
||||
});
|
||||
input.classList.add("handler_select");
|
||||
input.updateHandlerList = function (useIndexMethod) {
|
||||
var selectedIdx = input.selectedIndex;
|
||||
var val = input.value;
|
||||
input.innerHTML = "";
|
||||
var handlers = ["None"].concat(getHandlers(parentValue.replace(VALUE_ENUMS.ABSTRACT_HANDLER, '')));
|
||||
handlers.forEach((opt, i) => {
|
||||
var option = document.createElement("option");
|
||||
option.value = opt;
|
||||
option.innerText = opt;
|
||||
if (useIndexMethod ? (i === selectedIdx) : (opt === val)) {
|
||||
option.selected = true;
|
||||
}
|
||||
input.appendChild(option);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof parentValue === "string" && ["efb::val__file", "efb::val__img"].includes(parentValue)) {
|
||||
var resetBtn = document.createElement("button");
|
||||
resetBtn.innerText = "Reset";
|
||||
resetBtn.addEventListener("click", ()=>{
|
||||
obj.tags[k] = parentValue;
|
||||
editObject(obj, datablock);
|
||||
});
|
||||
}
|
||||
|
||||
if (Array.isArray(parentValue)) {
|
||||
input = document.createElement("select");
|
||||
var handlers = parentValue;
|
||||
if (handlers.useDynamic) {
|
||||
input.classList.add("dynamic_select");
|
||||
}
|
||||
handlers.forEach(opt => {
|
||||
var option = document.createElement("option");
|
||||
option.value = opt;
|
||||
option.innerText = opt;
|
||||
if (opt === obj.tags[k]) {
|
||||
option.selected = true;
|
||||
}
|
||||
input.appendChild(option);
|
||||
});
|
||||
input.dynamicUpdate = function (useIndexMethod) {
|
||||
var selectedIdx = input.selectedIndex;
|
||||
var val = input.value;
|
||||
input.innerHTML = "";
|
||||
|
||||
var handlers = parentValue.calculate();
|
||||
handlers.forEach((opt, i) => {
|
||||
var option = document.createElement("option");
|
||||
option.value = opt;
|
||||
option.innerText = opt;
|
||||
if (useIndexMethod ? (i === selectedIdx) : (opt === val)) {
|
||||
option.selected = true;
|
||||
}
|
||||
input.appendChild(option);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
input.addEventListener("input", () => {
|
||||
if (input.type === "file" && input.files[0]) {
|
||||
const reader = new FileReader();
|
||||
reader.onload = function (e) {
|
||||
obj.tags[k] = e.target.result;
|
||||
editObject(obj, datablock);
|
||||
};
|
||||
reader.readAsDataURL(input.files[0]);
|
||||
} else {
|
||||
obj.tags[k] = (input.type === "checkbox") ? input.checked : input.value;
|
||||
}
|
||||
updateDynamics(true);
|
||||
});
|
||||
|
||||
propnav.appendChild(input);
|
||||
|
||||
if (resetBtn) {
|
||||
propnav.appendChild(resetBtn);
|
||||
}
|
||||
|
||||
if (!isInline) {
|
||||
propnav.appendChild(document.createElement("br"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function updateDynamics(r) {
|
||||
document.querySelectorAll(".dynamic_select").forEach(x => x.dynamicUpdate(r));
|
||||
state.nodes.forEach(x => {
|
||||
var parent = PRIMITIVES[x.type];
|
||||
Object.keys(x.tags).forEach(tag => {
|
||||
if (parent.tags[tag].useDynamic) {
|
||||
var val = x.tags[tag];
|
||||
var selectedIdx = parent.tags[tag].indexOf(val);
|
||||
parent.tags[tag].calculate();
|
||||
x.tags[tag] = r ? parent.tags[tag][selectedIdx] : val;
|
||||
}
|
||||
});
|
||||
});
|
||||
document.querySelectorAll(".dynamic_itemsel").forEach(x => x.recalculateList());
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
function serialise() {
|
||||
return JSON.stringify(
|
||||
Object.assign(state,
|
||||
{
|
||||
blockly: Blockly.serialization.workspaces.save(workspace)
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
function deserialise(data) {
|
||||
var data = JSON.parse(data);
|
||||
try {
|
||||
Blockly.serialization.workspaces.load(data.blockly || {}, workspace);
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
globalThis.state = data;
|
||||
data.nodes.forEach(node => {
|
||||
var prim = getPrimitive(node.type);
|
||||
node.tags = Object.assign(prim.tags, node.tags); //load new tags
|
||||
});
|
||||
reloadUI();
|
||||
}
|
||||
function fileRead(handler) {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'file';
|
||||
input.accept = '.efb2';
|
||||
input.onchange = event => {
|
||||
const file = event.target.files[0];
|
||||
const reader = new FileReader();
|
||||
|
||||
reader.onload = () => {
|
||||
handler(reader.result);
|
||||
};
|
||||
|
||||
reader.readAsText(file);
|
||||
};
|
||||
|
||||
input.click();
|
||||
}
|
||||
function fileSave(text, fname) {
|
||||
const blob = new Blob([text], { type: 'text/plain' });
|
||||
const a = document.createElement('a');
|
||||
a.href = URL.createObjectURL(blob);
|
||||
a.download = fname || 'mod.efb2';
|
||||
a.click();
|
||||
URL.revokeObjectURL(a.href);
|
||||
}
|
||||
window.addEventListener("load", ()=>{
|
||||
document.querySelector("#load").addEventListener("click", ()=>{fileRead(deserialise)});
|
||||
document.querySelector("#save").addEventListener("click", ()=>{fileSave(serialise())});
|
||||
});
|
||||
@@ -0,0 +1,177 @@
|
||||
:root {
|
||||
--background: rgba(20, 20, 20);
|
||||
--col: rgb(179, 179, 179);
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-family: sans-serif;
|
||||
background-color: var(--background);
|
||||
color: var(--col);
|
||||
text-shadow: 0px 0px 5px rgba(0, 0, 0, 0.5);
|
||||
overflow: hidden;
|
||||
}
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6 {
|
||||
display: inline;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
#toolbar {
|
||||
width: calc(100vw - 0.5rem);
|
||||
padding-left: 0.5rem;
|
||||
padding-top: 0.2rem;
|
||||
padding-bottom: 0.2rem;
|
||||
font-size: 1rem;
|
||||
line-height: 1.5rem;
|
||||
border-bottom: 2px solid var(--col);
|
||||
}
|
||||
#blockly {
|
||||
width: 60vw;
|
||||
height: calc(100vh - 2.9rem - 2px);
|
||||
}
|
||||
table,
|
||||
tr,
|
||||
td {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
border: 0;
|
||||
outline: 0;
|
||||
position: relative;
|
||||
}
|
||||
button {
|
||||
background-color: rgba(255, 255, 255, 0.1);
|
||||
color: white;
|
||||
border: 0;
|
||||
font-size: 1rem;
|
||||
line-height: 1rem;
|
||||
border-radius: 0.2rem;
|
||||
cursor: pointer;
|
||||
transition: 0.4s;
|
||||
}
|
||||
button:active {
|
||||
background-color: rgba(255, 255, 255, 0.2) !important;
|
||||
transition: 0.1s;
|
||||
}
|
||||
button:hover {
|
||||
background-color: rgba(255, 255, 255, 0.13);
|
||||
}
|
||||
.datablock {
|
||||
position: relative;
|
||||
width: 8rem;
|
||||
height: 8rem;
|
||||
display: inline-block;
|
||||
border: 1px solid white;
|
||||
border-radius: 0.5rem;
|
||||
padding: 0.5rem;
|
||||
margin-left: 0.5rem;
|
||||
margin-top: 0.3rem;
|
||||
overflow: hidden;
|
||||
transition: 0.3s;
|
||||
}
|
||||
.datablock h4 {
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
}
|
||||
.datablock .controls {
|
||||
position: absolute;
|
||||
left: 4px;
|
||||
justify-self: end;
|
||||
}
|
||||
td {
|
||||
vertical-align: top;
|
||||
}
|
||||
#right {
|
||||
text-align: left;
|
||||
justify-content: start;
|
||||
align-items: start;
|
||||
width: calc(40vw - 8px);
|
||||
height: calc(100vh - 2.9rem);
|
||||
overflow-y: auto;
|
||||
display: inline-block;
|
||||
}
|
||||
#right input[type="search"] {
|
||||
display: block;
|
||||
width: 100%;
|
||||
margin-bottom: 0.15rem;
|
||||
outline: 0;
|
||||
}
|
||||
#propnav {
|
||||
width: 100%;
|
||||
min-height: 5rem;
|
||||
height: 16rem;
|
||||
max-height: 80vh;
|
||||
margin-bottom: 1rem;
|
||||
overflow-y: scroll;
|
||||
border-bottom: 1px solid white;
|
||||
resize: vertical;
|
||||
overflow-x: visible;
|
||||
}
|
||||
.datablock.selected {
|
||||
outline: 4px solid rgba(255, 255, 255, 0.4);
|
||||
background-color: rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
.datablock.selected h4 {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
padding-top: 0.5rem;
|
||||
padding-left: 0.5rem;
|
||||
color: var(--background);
|
||||
background-color: var(--col);
|
||||
}
|
||||
.hidden {
|
||||
display: none !important;
|
||||
}
|
||||
select {
|
||||
background-color: rgba(255, 255, 255, 0.05);
|
||||
color: white;
|
||||
outline: 0 !important;
|
||||
border: 1px solid white;
|
||||
border-radius: 0.3rem;
|
||||
}
|
||||
select option {
|
||||
color: white;
|
||||
background-color: black;
|
||||
}
|
||||
#addtype {
|
||||
margin-right: 0.1rem;
|
||||
}
|
||||
::-webkit-scrollbar {
|
||||
width: 10px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-track {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 6px;
|
||||
transition: 0.3s;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
|
||||
::-webkit-resizer {
|
||||
background-image: url('assets/resize.svg');
|
||||
}
|
||||
|
||||
.blocklyMenu, .blocklyEditableText > .blocklyText:not(.blocklyDropdownText) {
|
||||
text-shadow: none;
|
||||
}
|
||||
|
||||
.selectSearch {
|
||||
border: 2px solid purple !important;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
const VALUE_ENUMS = {
|
||||
FILE: "efb::val__file",
|
||||
IMG: "efb::val__img",
|
||||
ABSTRACT_HANDLER: "efb::handler/",
|
||||
ABSTRACT_ITEM: "efb::val__item",
|
||||
ABSTRACT_BLOCK: "efb::val__block",
|
||||
NEWLINE: "efb::lf"
|
||||
}
|
||||
|
||||
|
||||
const PRIMITIVES = {};
|
||||
|
||||
|
||||
function getPrimitive(type) {
|
||||
var cloned = Object.assign({}, PRIMITIVES[type]);
|
||||
var tags = Object.assign({}, cloned.tags);
|
||||
cloned.tags = tags;
|
||||
Object.keys(cloned.tags).forEach(key => {
|
||||
if (Array.isArray(cloned.tags[key])) {
|
||||
cloned.tags[key] = cloned.tags[key][0];
|
||||
}
|
||||
});
|
||||
delete cloned.asJavaScript;
|
||||
delete cloned.getDependencies;
|
||||
cloned = structuredClone(cloned);
|
||||
return cloned;
|
||||
}
|
||||
|
||||
window.addEventListener("load", ()=>{
|
||||
var addtype = document.querySelector("#addtype");
|
||||
Object.keys(PRIMITIVES).filter(x=>!PRIMITIVES[x].hidden).forEach(type => {
|
||||
var option = document.createElement("option");
|
||||
option.value = type;
|
||||
option.innerText = PRIMITIVES[type].name;
|
||||
addtype.appendChild(option);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user