Skip to content

Commit

Permalink
Merge pull request #686 from HSF/main-investigate-state-loading
Browse files Browse the repository at this point in the history
Fixes for inconsistent state loading
  • Loading branch information
EdwardMoyse authored Sep 20, 2024
2 parents 82d8d25 + 525c2b9 commit 407445a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
21 changes: 14 additions & 7 deletions packages/phoenix-event-display/src/helpers/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,31 @@ export const loadFile = (
contentType: string = 'application/json',
) => {
// Create a mock input file element and use that to read the file
let inputFile = document.createElement('input');
const inputFile = document.createElement('input');
document.body.appendChild(inputFile);
inputFile.type = 'file';
inputFile.accept = contentType;
inputFile.onchange = (e: any) => {
inputFile.onclick = (e: any) => {
e.target.value = '';
};

inputFile.addEventListener('invalid', (e) => {
console.log(JSON.stringify(e));
});

const fileSelected = (e: any) => {
const configFile = e.target?.files[0];
const reader = new FileReader();
reader.onload = (e) => {
if (e.target && e.target.result) {
onFileRead?.(e.target.result.toString());
}
inputFile.remove();
inputFile = document.createElement('input');
// For explanation, see https://stackoverflow.com/a/26221525
};
reader.readAsText(configFile);
};

inputFile.oninput = fileSelected;
inputFile.onchange = fileSelected;
inputFile.click();
setTimeout(() => {
console.log('Let us just wait a second');
}, 1000);
};
2 changes: 2 additions & 0 deletions packages/phoenix-event-display/src/managers/state-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ export class StateManager {
typeof json === 'string' ? JSON.parse(json) : json;

if (jsonData['phoenixMenu'] && this.phoenixMenuRoot) {
console.log('StateManager: Processing phoenixMenu configuration');
this.phoenixMenuRoot.loadStateFromJSON(jsonData['phoenixMenu']);
this.phoenixMenuRoot.configActive = false;
}

if (jsonData['eventDisplay']) {
console.log('StateManager: Processing eventDisplay configuration');
this.activeCamera.position.fromArray(
jsonData['eventDisplay']?.['cameraPosition'],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ export class SceneManager {
font: this.textFont,
size: 60,
curveSegments: 1,
height: 1,
depth: 1,
});

const mesh = new Mesh(
Expand Down

0 comments on commit 407445a

Please sign in to comment.