| @@ -49,6 +49,10 @@ const availableEntities = { | |||||
| } | } | ||||
| const availableEntitiesByName = { | |||||
| } | |||||
| const entities = { | const entities = { | ||||
| } | } | ||||
| @@ -886,6 +890,8 @@ function prepareEntities() { | |||||
| option.value = i; | option.value = i; | ||||
| option.innerText = entity.name; | option.innerText = entity.name; | ||||
| select.appendChild(option); | select.appendChild(option); | ||||
| availableEntitiesByName[entity.name] = entity; | |||||
| }; | }; | ||||
| const button = document.createElement("button"); | const button = document.createElement("button"); | ||||
| @@ -1089,26 +1095,13 @@ function copyScene() { | |||||
| // probably just have a way to do lookups directly | // probably just have a way to do lookups directly | ||||
| function findEntity(name) { | function findEntity(name) { | ||||
| const groups = Object.values(availableEntities); | |||||
| for (let i = 0; i < groups.length; i++) { | |||||
| const entityGroup = groups[i]; | |||||
| for (let j = 0; j < entityGroup.length; j++) { | |||||
| const candidate = entityGroup[j]; | |||||
| if (candidate.name === name) { | |||||
| return candidate; | |||||
| } | |||||
| } | |||||
| } | |||||
| return null; | |||||
| return availableEntitiesByName[name]; | |||||
| } | } | ||||
| function importScene(data) { | function importScene(data) { | ||||
| removeAllEntities(); | removeAllEntities(); | ||||
| data.entities.forEach(entityInfo => { | data.entities.forEach(entityInfo => { | ||||
| console.log(findEntity(entityInfo.name)) | |||||
| const entity = findEntity(entityInfo.name).constructor(); | const entity = findEntity(entityInfo.name).constructor(); | ||||
| entity.scale = entityInfo.scale | entity.scale = entityInfo.scale | ||||
| displayEntity(entity, entityInfo.view, entityInfo.x, entityInfo.y); | displayEntity(entity, entityInfo.view, entityInfo.x, entityInfo.y); | ||||