Skip to content

Commit

Permalink
Tables and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgangmeyers committed Mar 17, 2022
1 parent e95b9a4 commit adbff7a
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 2 deletions.
89 changes: 87 additions & 2 deletions app/public/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ Blockly.Lua['humanoid_set_attribute'] = function (block) {
return code;
};

// data
Blockly.Blocks['vector3_new'] = {
init: function () {
this.appendDummyInput()
Expand Down Expand Up @@ -676,6 +677,90 @@ Blockly.Lua['vector3_new'] = function (block) {
return [code, Blockly.Lua.ORDER_ATOMIC];
};

Blockly.Blocks['nil'] = {
init: function () {
this.appendDummyInput()
.appendField("nil");
this.setOutput(true, null);
this.setColour(230);
this.setTooltip("");
this.setHelpUrl("");
}
};

Blockly.Lua['nil'] = function (block) {
var code = 'nil';
return [code, Blockly.Lua.ORDER_NONE];
};

Blockly.Blocks['table_new'] = {
init: function () {
this.appendDummyInput()
.appendField("new table");
this.setOutput(true, null);
this.setColour(230);
this.setTooltip("");
this.setHelpUrl("");
}
};

Blockly.Lua['table_new'] = function (block) {
var code = '{}';
return [code, Blockly.Lua.ORDER_ATOMIC];
};

Blockly.Blocks['table_get_attribute'] = {
init: function () {
this.appendValueInput("ATTRIBUTE")
.setCheck(null)
.appendField("get");
this.appendDummyInput()
.appendField("of")
.appendField(new Blockly.FieldVariable("table"), "TABLE");
this.setInputsInline(true);
this.setOutput(true, null);
this.setColour(230);
this.setTooltip("");
this.setHelpUrl("");
}
};

Blockly.Lua['table_get_attribute'] = function (block) {
var value_attribute = Blockly.Lua.valueToCode(block, 'ATTRIBUTE', Blockly.Lua.ORDER_ATOMIC);
var variable_table = Blockly.Lua.nameDB_.getName(block.getFieldValue('TABLE'), Blockly.Variables.CATEGORY_NAME);
var code = `${variable_table}[${value_attribute}]`;
return [code, Blockly.Lua.ORDER_NONE];
};

Blockly.Blocks['table_set_attribute'] = {
init: function () {
this.appendValueInput("ATTRIBUTE")
.setCheck(null)
.appendField("set");
this.appendValueInput("VALUE")
.setCheck(null)
.appendField("of")
.appendField(new Blockly.FieldVariable("table"), "TABLE")
.appendField("to");
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(230);
this.setTooltip("");
this.setHelpUrl("");
}
};

Blockly.Lua['table_set_attribute'] = function (block) {
var value_attribute = Blockly.Lua.valueToCode(block, 'ATTRIBUTE', Blockly.Lua.ORDER_ATOMIC);
var variable_table = Blockly.Lua.nameDB_.getName(block.getFieldValue('TABLE'), Blockly.Variables.CATEGORY_NAME);
var value_value = Blockly.Lua.valueToCode(block, 'VALUE', Blockly.Lua.ORDER_ATOMIC);
var code = `${variable_table}[${value_attribute}] = ${value_value}\n`;
return code;
};

// players

Blockly.Blocks['players_player_added'] = {
init: function () {
this.appendDummyInput()
Expand Down Expand Up @@ -1197,7 +1282,7 @@ Blockly.Lua['marketplace_game_pass_purchased'] = function (block) {
var variable_gamepass = Blockly.Lua.nameDB_.getName(block.getFieldValue('GAMEPASS'), Blockly.Variables.CATEGORY_NAME);
var variable_player = Blockly.Lua.nameDB_.getName(block.getFieldValue('PLAYER'), Blockly.Variables.CATEGORY_NAME);
var statements_handler = Blockly.Lua.statementToCode(block, 'HANDLER');
var code = `game:GetService("MarketplaceService"):PromptGamePassPurchaseFinished:Connect(function(${variable_player}, ${variable_gamepass}, purchaseSuccess)
var code = `game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(${variable_player}, ${variable_gamepass}, purchaseSuccess)
if purchaseSuccess == true then
${statements_handler}
end
Expand All @@ -1224,7 +1309,7 @@ Blockly.Lua['marketplace_player_owns_gamepass'] = function (block) {
var code = `(function()
local hasPass = false
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(${variable_player}.UserId, ${value_name})
hasPass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(${variable_player}.UserId, ${value_name})
end)
if not success then
warn("Error while checking if player has pass: " .. tostring(message))
Expand Down
58 changes: 58 additions & 0 deletions app/public/toolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,24 @@ var bloxcode_toolbox = {
"NUM": 123,
}
},
{
"kind": "block",
"type": "nil",
},
{
"kind": "block",
"type": "logic_boolean",
"fields": {
"BOOL": "TRUE"
}
},
{
"kind": "block",
"type": "text",
"fields": {
"TEXT": "Hello",
}
},
{
"kind": "block",
"type": "vector3_new",
Expand Down Expand Up @@ -261,6 +279,46 @@ var bloxcode_toolbox = {
},
}
},
{
"kind": "block",
"type": "table_new",
},
{
"kind": "block",
"type": "table_get_attribute",
"inputs": {
"ATTRIBUTE": {
"block": {
"type": "text",
"fields": {
"TEXT": "attribute",
},
},
},
},
},
{
"kind": "block",
"type": "table_set_attribute",
"inputs": {
"ATTRIBUTE": {
"block": {
"type": "text",
"fields": {
"TEXT": "attribute",
},
},
},
"VALUE": {
"block": {
"type": "text",
"fields": {
"TEXT": "value",
},
},
},
},
},
]
},
{
Expand Down

0 comments on commit adbff7a

Please sign in to comment.