Skip to content

Commit

Permalink
Fix bugs for importing modules
Browse files Browse the repository at this point in the history
  • Loading branch information
ricktu288 committed Jun 2, 2024
1 parent 6d0196d commit 4d9b093
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 17 deletions.
19 changes: 19 additions & 0 deletions simulator/js/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,25 @@ class Scene {
return JSON.stringify(jsonData, null, 2);
}

/**
* Add a module definition.
* @param {string} moduleName
* @param {ModuleDef} moduleDef
* @returns {boolean} Whether the module is successfully added.
*/
addModule(moduleName, moduleDef) {
this.modules[moduleName] = moduleDef;

// Update all module objects.
for (let i in this.objs) {
if (this.objs[i].constructor.type === "ModuleObj") {
this.objs[i] = new objTypes.ModuleObj(this, this.objs[i].serialize());
}
}

return true;
}

/**
* Remove a given module and demodulize all corresponding module objects.
* @param {string} moduleName
Expand Down
4 changes: 2 additions & 2 deletions simulator/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,13 +729,13 @@ function importModule(name) {
for (let moduleName in moduleJSON.modules) {
if (moduleJSON.modules.hasOwnProperty(moduleName)) {
let newModuleName = moduleName;
if (scene.modules[moduleName]) {
if (scene.modules[moduleName] && JSON.stringify(scene.modules[moduleName]) != JSON.stringify(moduleJSON.modules[moduleName])){
newModuleName = prompt(getMsg('module_conflict'), moduleName);
if (!newModuleName) {
continue;
}
}
scene.modules[newModuleName] = moduleJSON.modules[moduleName];
scene.addModule(newModuleName, moduleJSON.modules[moduleName]);
}
}
} catch (e) {
Expand Down
7 changes: 6 additions & 1 deletion simulator/js/objs/special/ModuleObj.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ objTypes['ModuleObj'] = class extends BaseSceneObj {
populateObjBar(objBar) {
objBar.createNote('<span style="font-family: monospace; padding-right:2px">' + this.module + '</span>');

if (this.notDone) return;

try {
for (let param of this.moduleDef.params) {
const parsed = this.parseVariableRange(param, {});
Expand Down Expand Up @@ -142,7 +144,9 @@ objTypes['ModuleObj'] = class extends BaseSceneObj {
if (this.moduleDef.numPoints > 0) {
this.points.push({ x: mousePos.x, y: mousePos.y });
}
}

onConstructMouseUp(mouse, ctrl, shift) {
if (this.points.length === this.moduleDef.numPoints) {
// All control points have been added.
this.notDone = false;
Expand All @@ -151,7 +155,8 @@ objTypes['ModuleObj'] = class extends BaseSceneObj {
this.expandObjs();

return {
isDone: true
isDone: true,
requiresObjBarUpdate: true
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion simulator/locales/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,6 @@ locales["de"] = {
},
"module_conflict": {
"incomplete": true,
"message": "A module with the same name already exists in the current scene. You may enter a new name, or leave it the same to overwrite the existing module."
"message": "A different module with the same name already exists in the current scene. You may enter a new name, or leave it the same to overwrite the existing module."
}
}
2 changes: 1 addition & 1 deletion simulator/locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,6 @@ locales["en"] = {
"message": "Remove module"
},
"module_conflict": {
"message": "A module with the same name already exists in the current scene. You may enter a new name, or leave it the same to overwrite the existing module."
"message": "A different module with the same name already exists in the current scene. You may enter a new name, or leave it the same to overwrite the existing module."
}
}
2 changes: 1 addition & 1 deletion simulator/locales/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,6 @@ locales["es"] = {
},
"module_conflict": {
"incomplete": true,
"message": "A module with the same name already exists in the current scene. You may enter a new name, or leave it the same to overwrite the existing module."
"message": "A different module with the same name already exists in the current scene. You may enter a new name, or leave it the same to overwrite the existing module."
}
}
2 changes: 1 addition & 1 deletion simulator/locales/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,6 @@ locales["fr"] = {
},
"module_conflict": {
"incomplete": true,
"message": "A module with the same name already exists in the current scene. You may enter a new name, or leave it the same to overwrite the existing module."
"message": "A different module with the same name already exists in the current scene. You may enter a new name, or leave it the same to overwrite the existing module."
}
}
2 changes: 1 addition & 1 deletion simulator/locales/ja.js
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,6 @@ locales["ja"] = {
},
"module_conflict": {
"incomplete": true,
"message": "A module with the same name already exists in the current scene. You may enter a new name, or leave it the same to overwrite the existing module."
"message": "A different module with the same name already exists in the current scene. You may enter a new name, or leave it the same to overwrite the existing module."
}
}
2 changes: 1 addition & 1 deletion simulator/locales/ko.js
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,6 @@ locales["ko"] = {
},
"module_conflict": {
"incomplete": true,
"message": "A module with the same name already exists in the current scene. You may enter a new name, or leave it the same to overwrite the existing module."
"message": "A different module with the same name already exists in the current scene. You may enter a new name, or leave it the same to overwrite the existing module."
}
}
2 changes: 1 addition & 1 deletion simulator/locales/nl.js
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,6 @@ locales["nl"] = {
},
"module_conflict": {
"incomplete": true,
"message": "A module with the same name already exists in the current scene. You may enter a new name, or leave it the same to overwrite the existing module."
"message": "A different module with the same name already exists in the current scene. You may enter a new name, or leave it the same to overwrite the existing module."
}
}
2 changes: 1 addition & 1 deletion simulator/locales/pl.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,6 @@ locales["pl"] = {
},
"module_conflict": {
"incomplete": true,
"message": "A module with the same name already exists in the current scene. You may enter a new name, or leave it the same to overwrite the existing module."
"message": "A different module with the same name already exists in the current scene. You may enter a new name, or leave it the same to overwrite the existing module."
}
}
2 changes: 1 addition & 1 deletion simulator/locales/pt_BR.js
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,6 @@ locales["pt-BR"] = {
},
"module_conflict": {
"incomplete": true,
"message": "A module with the same name already exists in the current scene. You may enter a new name, or leave it the same to overwrite the existing module."
"message": "A different module with the same name already exists in the current scene. You may enter a new name, or leave it the same to overwrite the existing module."
}
}
2 changes: 1 addition & 1 deletion simulator/locales/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,6 @@ locales["ru"] = {
},
"module_conflict": {
"incomplete": true,
"message": "A module with the same name already exists in the current scene. You may enter a new name, or leave it the same to overwrite the existing module."
"message": "A different module with the same name already exists in the current scene. You may enter a new name, or leave it the same to overwrite the existing module."
}
}
2 changes: 1 addition & 1 deletion simulator/locales/si.js
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,6 @@ locales["si"] = {
},
"module_conflict": {
"incomplete": true,
"message": "A module with the same name already exists in the current scene. You may enter a new name, or leave it the same to overwrite the existing module."
"message": "A different module with the same name already exists in the current scene. You may enter a new name, or leave it the same to overwrite the existing module."
}
}
2 changes: 1 addition & 1 deletion simulator/locales/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,6 @@ locales["LOCALE_ID"] = {
},
"module_conflict": {
"incomplete": true,
"message": "A module with the same name already exists in the current scene. You may enter a new name, or leave it the same to overwrite the existing module."
"message": "A different module with the same name already exists in the current scene. You may enter a new name, or leave it the same to overwrite the existing module."
}
}
2 changes: 1 addition & 1 deletion simulator/locales/zh_CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,6 @@ locales["zh-CN"] = {
"message": "移除模块"
},
"module_conflict": {
"message": "场景中已有一个同名的模块。您可以指定新的名称,或保留相同名称以取代原模块。"
"message": "场景中已有一个同名但不相同的模块。您可以指定新的名称,或保留相同名称以取代原模块。"
}
}
2 changes: 1 addition & 1 deletion simulator/locales/zh_TW.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,6 @@ locales["zh-TW"] = {
"message": "移除模組"
},
"module_conflict": {
"message": "場景中已有一個同名的模組。您可以指定新的名稱,或保留相同名稱以取代原模組。"
"message": "場景中已有一個同名但不相同的模組。您可以指定新的名稱,或保留相同名稱以取代原模組。"
}
}

0 comments on commit 4d9b093

Please sign in to comment.