Skip to content

Commit 22d595a

Browse files
authored
Make inspector load the book (#4)
* Add inspector QR code, fix inspector to load borrowed book * Make target optional, don't handle pointer and scroll events in the inspector * Update spacecraft.js --------- Co-authored-by: Max Carlson <>
1 parent 52c78ce commit 22d595a

File tree

4 files changed

+28
-20
lines changed

4 files changed

+28
-20
lines changed

Unity/SpaceCraft/Assets/StreamingAssets/SpaceCraft/spacecraft.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class SpaceCraftSim {
178178
id: "inspector-qr",
179179
targetHtml: "StreamingAssets/SpaceCraft/inspector.html",
180180
label: "Inspector",
181-
position: "bottom-left" // Or another suitable position
181+
position: "bottom-left"
182182
},
183183
];
184184

WebSites/spacetime/StreamingAssets/SpaceCraft/controller.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,17 @@ window.BaseController = class BaseController {
447447
/**
448448
* Initialize controller
449449
*/
450-
initialize(targetElement) {
451-
this.targetElement = targetElement;
452-
453-
// Set up event handlers
454-
this.setupPageEventHandlers();
450+
initialize(skipPageHandlers) {
451+
if (! skipPageHandlers) {
452+
const targetElement = document.getElementById("target");
453+
if (!targetElement) {
454+
console.error('Target element not found');
455+
return;
456+
}
457+
this.targetElement = targetElement;
458+
// Set up event handlers
459+
this.setupPageEventHandlers();
460+
}
455461

456462
// Set up UI buttons
457463
this.setupButtons();
@@ -2390,13 +2396,6 @@ window.SelectorController = class SelectorController extends BaseController {
23902396

23912397
// Simple initialization on DOM ready - directly instantiates the right controller
23922398
document.addEventListener('DOMContentLoaded', function() {
2393-
2394-
const targetElement = document.getElementById("target");
2395-
if (!targetElement) {
2396-
console.error('Target element not found');
2397-
return;
2398-
}
2399-
24002399
// Get controller type from meta tag
24012400
const metaTag = document.querySelector('meta[name="controller-type"]');
24022401
if (!metaTag) {
@@ -2410,19 +2409,18 @@ document.addEventListener('DOMContentLoaded', function() {
24102409
let controller;
24112410
if (controllerType === 'navigator') {
24122411
controller = new NavigatorController();
2412+
controller.initialize();
24132413
} else if (controllerType === 'selector') {
24142414
controller = new SelectorController();
2415+
controller.initialize();
24152416
} else if (controllerType === 'inspector') { // ADD THIS BLOCK
24162417
controller = new InspectorController();
2418+
controller.initialize(true);
24172419
} else {
24182420
console.error('Invalid controller type: ' + controllerType);
24192421
return;
24202422
}
24212423

2422-
// Initialize it directly - this sets everything up
2423-
// including event handling and motion tracking
2424-
controller.initialize(targetElement);
2425-
24262424
// Make controller globally accessible
24272425
window.controller = controller;
24282426
});
@@ -2431,11 +2429,13 @@ window.InspectorController = class InspectorController extends BaseController {
24312429
constructor() {
24322430
super('inspector'); // Client type
24332431
this.jsonOutputElement = null;
2432+
this.iFrameElement = null;
24342433
}
24352434

24362435
setupControllerSpecificUI() {
24372436
this.logEvent('Init', 'Setting up Inspector-specific UI');
24382437
this.jsonOutputElement = document.getElementById('inspector-json-output');
2438+
this.iFrameElement = document.getElementById('inspector-iframe');
24392439
if (!this.jsonOutputElement) {
24402440
this.logEvent('Error', 'Inspector JSON output element not found!');
24412441
}
@@ -2444,9 +2444,11 @@ window.InspectorController = class InspectorController extends BaseController {
24442444
// This method will be called when the selected item data changes
24452445
selectedItemChanged(selectedItemJSON) {
24462446
this.logEvent('Inspector', 'Received new selected item JSON:', selectedItemJSON);
2447-
if (this.jsonOutputElement) {
2447+
if (this.iFrameElement) {
24482448
if (selectedItemJSON) {
2449-
this.jsonOutputElement.textContent = JSON.stringify(selectedItemJSON, null, 2);
2449+
// this.jsonOutputElement.innerHTML = JSON.stringify(selectedItemJSON)
2450+
this.iFrameElement.src = `https://archive.org/details/${selectedItemJSON['id']}`;
2451+
this.jsonOutputElement.textContent = JSON.stringify(selectedItemJSON);
24502452
} else {
24512453
this.jsonOutputElement.textContent = 'No item currently selected.';
24522454
}

WebSites/spacetime/StreamingAssets/SpaceCraft/inspector.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
<script src="controller.js"></script>
2020
</head>
2121
<body>
22+
<iframe id="inspector-iframe" width="100%" height="100%"></iframe>
2223
<div class="container selector-container">
2324
<h1 class="page-title">Inspector</h1>
2425
<div id="status" class="status">Connecting...</div>
25-
<div id="target"></div>
2626
</div>
2727
<div id="inspector-json-output"></div>
2828
</body>

WebSites/spacetime/StreamingAssets/SpaceCraft/spacecraft.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ class SpaceCraftSim {
174174
label: "Selector",
175175
position: "top-right"
176176
},
177+
{
178+
id: "inspector-qr",
179+
targetHtml: "StreamingAssets/SpaceCraft/inspector.html",
180+
label: "Inspector",
181+
position: "bottom-left"
182+
},
177183
];
178184

179185
// Initialize content promise

0 commit comments

Comments
 (0)