Skip to content

Commit 1db8461

Browse files
committed
Updates
1 parent 1b6d376 commit 1db8461

1 file changed

Lines changed: 62 additions & 26 deletions

File tree

index.html

Lines changed: 62 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,68 +10,104 @@
1010
<body>
1111
<!-- File Upload Button -->
1212
<input type="file" id="uploadJson" accept=".json" />
13-
<label>
14-
<input type="checkbox" id="fixScaleCheckbox" />
15-
fix scale (use world unit)
16-
</label>
17-
<button onclick="handleCombined()">make g</button>
13+
14+
<div style="margin: 1em 0;">
15+
<label>
16+
<input type="checkbox" id="fixScaleWorld" checked>
17+
fix scale (use world unit)
18+
</label>
19+
<br>
20+
<label>
21+
<input type="checkbox" id="fixScalePixel" checked>
22+
fix scale (use pixel unit)
23+
</label>
24+
<br>
25+
<label>
26+
<input type="checkbox" id="fixFixture" checked>
27+
fix fixtures in body settings
28+
</label>
29+
<br>
30+
<label>
31+
<input type="checkbox" id="moveUpHalfDepth" checked>
32+
move collider.offset.z up half depth (in fixture fix)
33+
</label>
34+
</div>
35+
36+
<button onclick="handleJson()">remove deprecated properties</button>
1837

1938
<script src="bundle.js" type="text/javascript"></script>
2039
<script>
2140
let jsonObject = null;
2241

23-
// Combined handler for "make g" button, applies fixScale if checkbox is checked, then removeUnwantedProperties
24-
function handleCombined() {
42+
// Function to handle the uploaded JSON file and apply selected fixes
43+
function handleJson() {
2544
const fileInput = document.getElementById('uploadJson');
2645
const file = fileInput.files[0];
27-
const fixScaleChecked = document.getElementById('fixScaleCheckbox').checked;
2846

2947
if (!file) {
3048
alert('Please select a JSON file first!');
3149
return;
3250
}
3351

52+
const fixScaleWorld = document.getElementById('fixScaleWorld').checked;
53+
const fixScalePixel = document.getElementById('fixScalePixel').checked;
54+
const fixFixture = document.getElementById('fixFixture').checked;
55+
const moveUpHalfDepth = document.getElementById('moveUpHalfDepth').checked;
56+
3457
const reader = new FileReader();
35-
const { fixScale, removeUnwantedProperties } = window.fixes;
58+
59+
const { fixScale, removeUnwantedProperties, fixFixture: fixFixtureFn } = window.fixes;
3660

3761
reader.onload = function (event) {
3862
try {
3963
jsonObject = JSON.parse(event.target.result);
40-
let processed = jsonObject;
41-
let prefix = '';
64+
let obj = JSON.parse(JSON.stringify(jsonObject)); // deep clone
65+
66+
let prefixParts = [];
4267

43-
if (fixScaleChecked) {
44-
processed = fixScale(processed, false);
45-
prefix += 'fixed_scale(world_unit)_';
68+
// Apply scale fixes if checked
69+
if (fixScaleWorld) {
70+
obj = fixScale(obj, false);
71+
prefixParts.push('fixed_scale(world_unit)');
72+
}
73+
if (fixScalePixel) {
74+
obj = fixScale(obj, true);
75+
prefixParts.push('fixed_scale(pixel_unit)');
76+
}
77+
78+
// Apply fixture fix if checked
79+
if (fixFixture) {
80+
obj = fixFixtureFn(obj, moveUpHalfDepth);
81+
prefixParts.push('fixed_fixture' + (moveUpHalfDepth ? '(moveUpHalfDepth)' : ''));
4682
}
4783

48-
processed = removeUnwantedProperties(processed);
49-
prefix += 'remove_unwanted_properties_';
84+
// Always remove unwanted properties
85+
obj = removeUnwantedProperties(obj);
86+
prefixParts.push('remove_unwanted_properties');
5087

51-
downloadJson(processed, `${prefix}${file.name}`);
88+
const prefix = prefixParts.join('_');
89+
downloadJson(obj, `${prefix}_${file.name}`);
5290
} catch (error) {
5391
console.error('Error parsing JSON:', error);
5492
alert('Invalid JSON file!');
5593
}
5694
};
57-
5895
reader.readAsText(file);
5996
}
6097

6198
// Function to download the JSON object as a file
6299
function downloadJson(jsonObj, name) {
63-
const jsonString = JSON.stringify(jsonObj, null, 2); // Convert JSON object to string
64-
const blob = new Blob([jsonString], { type: 'application/json' }); // Create a Blob
65-
const url = URL.createObjectURL(blob); // Create a URL for the Blob
100+
const jsonString = JSON.stringify(jsonObj, null, 2);
101+
const blob = new Blob([jsonString], { type: 'application/json' });
102+
const url = URL.createObjectURL(blob);
66103

67-
// Create a temporary anchor element to trigger the download
68104
const a = document.createElement('a');
69105
a.href = url;
70-
a.download = `${name}`; // Set the filename with the fixed prefix
106+
a.download = `${name}`;
71107
document.body.appendChild(a);
72-
a.click(); // Trigger the download
73-
document.body.removeChild(a); // Clean up the DOM
74-
URL.revokeObjectURL(url); // Revoke the Blob URL
108+
a.click();
109+
document.body.removeChild(a);
110+
URL.revokeObjectURL(url);
75111
}
76112
</script>
77113
</body>

0 commit comments

Comments
 (0)