Skip to content

Commit

Permalink
Add upgraders
Browse files Browse the repository at this point in the history
  • Loading branch information
BeksOmega committed Jul 30, 2020
1 parent 5076f70 commit d0a6d78
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ private static void upgradeComponentProperties(Map<String, JSONValue> componentP
srcCompVersion = upgradeFeatureCollection(componentProperties, srcCompVersion);
} else if (componentType.equals("YandexTranslate")) {
srcCompVersion = upgradeYandexTranslateProperties(componentProperties, srcCompVersion);
} else if (componentType.equals("NxtDirectCommands")) {
srcCompVersion = upgradeNxtDirectCommandsProperties(componentProperties, srcCompVersion);
}

if (srcCompVersion < sysCompVersion) {
Expand Down Expand Up @@ -1765,6 +1767,17 @@ private static int upgradeYandexTranslateProperties(Map<String, JSONValue> compo
return srcCompVersion;
}

private static int upgradeNxtDirectCommandsProperties(
Map<String, JSONValue> componentProperties,
int srcCompVersion
) {
if (srcCompVersion < 2) {
// Adds dropdown blocks.
srcCompVersion = 2;
}
return srcCompVersion;
}

private static void handlePropertyRename(Map<String, JSONValue> componentProperties,
String oldPropName, String newPropName) {
if (componentProperties.containsKey(oldPropName)) {
Expand Down
37 changes: 36 additions & 1 deletion appinventor/blocklyeditor/src/versioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,7 @@ Blockly.Versioning.getOptionListValueMap = function(workspace, key) {
var optionList = db.getOptionList(key);
for (var i = 0, option; option = optionList.options[i]; i++) {
map[option.value] = option.name;
map[option.value.toLowerCase()] = option.name;
}
return map;
}
Expand Down Expand Up @@ -2140,7 +2141,41 @@ Blockly.Versioning.AllUpgradeMaps =
"NxtDirectCommands": {

//This is initial version. Placeholder for future upgrades
1: "noUpgrade"
1: "noUpgrade",

// Add dropdown blocks.
2: [Blockly.Versioning.makeMethodUseDropdown(
'NxtDirectCommands', 'SetOutputState', 0, 'NxtMotorPort'),
Blockly.Versioning.makeMethodUseDropdown(
'NxtDirectCommands', 'SetOutputState', 2, 'NxtMotorMode'),
Blockly.Versioning.makeMethodUseDropdown(
'NxtDirectCommands', 'SetOutputState', 3, 'NxtRegulationMode'),
Blockly.Versioning.makeMethodUseDropdown(
'NxtDirectCommands', 'SetOutputState', 5, 'NxtRunState'),
Blockly.Versioning.makeMethodUseDropdown(
'NxtDirectCommands', 'SetInputMode', 0, 'NxtSensorPort'),
Blockly.Versioning.makeMethodUseDropdown(
'NxtDirectCommands', 'SetInputMode', 1, 'NxtSensorType'),
Blockly.Versioning.makeMethodUseDropdown(
'NxtDirectCommands', 'SetInputMode', 2, 'NxtSensorMode'),
Blockly.Versioning.makeMethodUseDropdown(
'NxtDirectCommands', 'GetOutputState', 0, 'NxtMotorPort'),
Blockly.Versioning.makeMethodUseDropdown(
'NxtDirectCommands', 'GetInputValues', 0, 'NxtSensorPort'),
Blockly.Versioning.makeMethodUseDropdown(
'NxtDirectCommands', 'ResetInputScaledValue', 0, 'NxtSensorPort'),
Blockly.Versioning.makeMethodUseDropdown(
'NxtDirectCommands', 'ResetMotorPosition', 0, 'NxtMotorPort'),
Blockly.Versioning.makeMethodUseDropdown(
'NxtDirectCommands', 'LsGetStatus', 0, 'NxtSensorPort'),
Blockly.Versioning.makeMethodUseDropdown(
'NxtDirectCommands', 'LsWrite', 0, 'NxtSensorPort'),
Blockly.Versioning.makeMethodUseDropdown(
'NxtDirectCommands', 'LsRead', 0, 'NxtSensorPort'),
Blockly.Versioning.makeMethodUseDropdown(
'NxtDirectCommands', 'MessageRead', 0, 'NxtMailbox'),
Blockly.Versioning.makeMethodUseDropdown(
'NxtDirectCommands', 'MessageWrite', 0, 'NxtMailbox')]

}, // End NxtDirectCommands upgraders

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,9 @@ private YaVersion() {

public static final int NXT_COLORSENSOR_COMPONENT_VERSION = 1;

public static final int NXT_DIRECT_COMMANDS_COMPONENT_VERSION = 1;
// For NXT_DIRECT_COMMANDS_COMPONENT_VERSION 2:
// - Adds dropdown blocks.
public static final int NXT_DIRECT_COMMANDS_COMPONENT_VERSION = 2;

public static final int NXT_DRIVE_COMPONENT_VERSION = 1;

Expand Down

0 comments on commit d0a6d78

Please sign in to comment.