Skip to content

Commit

Permalink
fix(build): highlight/show unknown types in red & allow edit/delete
Browse files Browse the repository at this point in the history
  • Loading branch information
mwfarb committed Jul 31, 2024
1 parent 7184ea8 commit 5287340
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
9 changes: 6 additions & 3 deletions build/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ window.addEventListener('onauth', async (e) => {
const updateobj = getARENAObject(obj, action);

const schemaType = updateobj.type === 'object' ? updateobj.data.object_type : updateobj.type;
const schemaFile = objSchemas[schemaType].file;
let schemaFile = objSchemas.entity.file; // use default in case schema type is undefined
if (objSchemas[schemaType]) {
schemaFile = objSchemas[schemaType].file;
}
const data = await fetch(schemaFile);
schema = await data.json();
selectSchema.value = schemaFile;
Expand All @@ -202,8 +205,8 @@ window.addEventListener('onauth', async (e) => {
window.location.hash = 'edit_section';

Alert.fire({
icon: 'info',
title: 'Loaded.',
icon: objSchemas[schemaType] ? 'info' : 'error',
title: objSchemas[schemaType] ? 'Loaded.' : `Unknown "${schemaType}" loaded as "entity".`,
html: 'Loaded&nbspinto&nbsp<b>Add/Edit&nbspObject</b>&nbspform. <br/> Press "<b>A</b>dd/Update Object" button when done.',
timer: 10000,
});
Expand Down
20 changes: 14 additions & 6 deletions build/persist-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,26 +257,28 @@ export async function populateObjectList(scene, filter, objTypeFilter, focusObje

// save obj json so we can use later in selected object actions (delete/copy)
li.setAttribute('data-obj', JSON.stringify(sceneObjs[i]));
let inputValue = '';
let typeDisplay = '';

if (sceneObjs[i].attributes === undefined) continue;
if (objTypeFilter[sceneObjs[i].type] === false) continue;
if (re.test(sceneObjs[i].object_id) === false) continue;

if (sceneObjs[i].type === 'object') {
inputValue = `${sceneObjs[i].object_id} ( ${sceneObjs[i].attributes.object_type} )`;
typeDisplay = sceneObjs[i].attributes.object_type;
img.src = 'assets/3dobj-icon.png';
if (objTypeFilter[sceneObjs[i].attributes.object_type] === false) continue;
} else if (sceneObjs[i].type === 'program') {
const ptype = sceneObjs[i].attributes.filetype === 'WA' ? 'WASM program' : 'python program';
inputValue = `${sceneObjs[i].object_id} ( ${ptype}: ${sceneObjs[i].attributes.filename} )`;
typeDisplay = `${ptype}: ${sceneObjs[i].attributes.filename}`;
img.src = 'assets/program-icon.png';
} else if (sceneObjs[i].type === 'scene-options') {
inputValue = `${sceneObjs[i].object_id} ( scene options )`;
typeDisplay = 'scene options';
img.src = 'assets/options-icon.png';
} else if (sceneObjs[i].type === 'landmarks') {
inputValue = `${sceneObjs[i].object_id} ( landmarks )`;
typeDisplay = 'landmarks';
img.src = 'assets/map-icon.png';
} else {
typeDisplay = sceneObjs[i].type; // display unknown type
}

const r = sceneObjs[i].attributes.rotation;
Expand All @@ -299,7 +301,7 @@ export async function populateObjectList(scene, filter, objTypeFilter, focusObje
}
}

const t = document.createTextNode(inputValue);
const t = document.createTextNode(`${sceneObjs[i].object_id} ( ${typeDisplay} )`);
li.appendChild(t);

// add image
Expand Down Expand Up @@ -363,6 +365,12 @@ export async function populateObjectList(scene, filter, objTypeFilter, focusObje
persist.visObjHandler(sceneObjs[i], visible);
};

// highlight object type errors
const schemaType = sceneObjs[i].type === 'object' ? sceneObjs[i].attributes.object_type : sceneObjs[i].type;
if (!objTypeFilter[schemaType]) {
li.style.color = 'red';
}

persist.objList.appendChild(li);
}
persist.addEditSection.style = 'display:block';
Expand Down

0 comments on commit 5287340

Please sign in to comment.