Skip to content

Commit da7eef3

Browse files
committed
Updates
1 parent 6ec76db commit da7eef3

2 files changed

Lines changed: 122 additions & 4 deletions

File tree

bundle.js

Lines changed: 113 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@
3636
var require_rfdc = __commonJS({
3737
"node_modules/.pnpm/rfdc@1.4.1/node_modules/rfdc/index.js"(exports, module) {
3838
"use strict";
39-
module.exports = rfdc4;
39+
module.exports = rfdc5;
4040
function copyBuffer(cur) {
4141
if (cur instanceof Buffer) {
4242
return Buffer.from(cur);
4343
}
4444
return new cur.constructor(cur.buffer.slice(), cur.byteOffset, cur.length);
4545
}
46-
function rfdc4(opts) {
46+
function rfdc5(opts) {
4747
opts = opts || {};
4848
if (opts.circles) return rfdcCircles(opts);
4949
const constructorHandlers = /* @__PURE__ */ new Map();
@@ -423,6 +423,9 @@
423423
}
424424
}
425425
}
426+
if (parentKey?.currentParentKey === targetKey) {
427+
should_trigger_effect = true;
428+
}
426429
if (should_trigger_effect) {
427430
effect?.(newObj);
428431
}
@@ -558,6 +561,113 @@
558561
return output;
559562
};
560563

564+
// src/fixture.ts
565+
var import_rfdc4 = __toESM(require_rfdc());
566+
if (typeof window === "undefined") {
567+
const jsonfile = require_jsonfile();
568+
const fs = __require("fs");
569+
fs.readdirSync("./input").map((fileName) => {
570+
jsonfile.readFile(`./input/${fileName}`, function(err, obj) {
571+
if (err) {
572+
console.error(fileName, err);
573+
}
574+
let output = fixFixture(obj, process.argv[2] === "--moveUpHalfDepth");
575+
console.log(fileName, " Done!");
576+
jsonfile.writeFileSync(`./output/${fileName}`, output);
577+
});
578+
});
579+
}
580+
var fixFixture = (obj, moveUpHalfDepth = false) => {
581+
let output = (0, import_rfdc4.default)()(obj);
582+
const keysNeededToMove = ["collidesWith", "allowSleep", "bullet"];
583+
const map = { "width": "x", "height": "y", "depth": "z" };
584+
["bodies"].forEach((key) => {
585+
output = modifyCertainKey(
586+
output,
587+
key,
588+
{
589+
parentKeys: [],
590+
currentParentKey: "",
591+
targetParentKey: [],
592+
insideParentKeys: [],
593+
excludeKeys: [],
594+
brotherEntries: [],
595+
parent: {}
596+
},
597+
(obj2) => {
598+
for (let [bodyKey, body] of Object.entries(obj2)) {
599+
const newFixtures = (0, import_rfdc4.default)()(body.fixtures);
600+
const newObj = {};
601+
for (let [k, v] of Object.entries(body)) {
602+
if (keysNeededToMove.includes(k)) {
603+
newFixtures.forEach((fixture, idx) => {
604+
if (!fixture.scale) {
605+
fixture.scale = {
606+
x: 1,
607+
y: 1,
608+
z: 1
609+
};
610+
}
611+
if (!fixture.offset) {
612+
fixture.offset = {
613+
x: 0,
614+
y: 0,
615+
z: 0
616+
};
617+
}
618+
if (body.fixtures[idx].size === void 0 || body.fixtures[idx].size.width === void 0) {
619+
fixture.fitRendering = true;
620+
}
621+
switch (fixture.shape.type) {
622+
case "rectangle": {
623+
if (fixture.size) {
624+
["width", "height", "depth"].forEach((key2) => {
625+
if (fixture.size[key2]) {
626+
fixture.scale[map[key2]] = Number(fixture.size[key2]);
627+
}
628+
});
629+
}
630+
break;
631+
}
632+
case "circle": {
633+
if (fixture.size) {
634+
["width", "height", "depth"].forEach((key2) => {
635+
if (fixture.size[key2]) {
636+
fixture.scale = {
637+
x: Number(Math.max(Math.max(fixture.size.width ?? 0, fixture.size.height ?? 0), fixture.size.depth ?? 0)),
638+
y: Number(Math.max(Math.max(fixture.size.width ?? 0, fixture.size.height ?? 0), fixture.size.depth ?? 0)),
639+
z: Number(Math.max(Math.max(fixture.size.width ?? 0, fixture.size.height ?? 0), fixture.size.depth ?? 0))
640+
};
641+
}
642+
});
643+
}
644+
break;
645+
}
646+
case "capsule": {
647+
break;
648+
}
649+
}
650+
["size"].forEach((key2) => {
651+
delete fixture[key2];
652+
});
653+
if (moveUpHalfDepth) {
654+
fixture.offset.z = body.fixtures[idx].size?.depth ? body.fixtures[idx].size.depth / 2 : body.depth ? body.depth / 2 : 0;
655+
}
656+
fixture[k] = v;
657+
});
658+
} else {
659+
newObj[k] = v;
660+
}
661+
}
662+
newObj.fixtures = newFixtures;
663+
obj2[bodyKey] = newObj;
664+
}
665+
}
666+
);
667+
});
668+
return output;
669+
};
670+
561671
// src/index.ts
562-
window.fixes = { fixScale, fixDebris };
672+
window.fixes = { fixScale, fixDebris, fixFixture };
563673
})();

index.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
<button onclick="handleJson('scale', {revert: false})">fix scale (use world unit)</button>
1414
<button onclick="handleJson('scale', {revert: true})">fix scale (use pixel unit)</button>
1515
<button onclick="handleJson('debris')">remove debris</button>
16+
<button onclick="handleJson('fixture', {moveUpHalfDepth: false})">fix fixtures in body settings</button>
17+
<button onclick="handleJson('fixture', {moveUpHalfDepth: true})">fix fixtures in body settings (move collider.offset.z
18+
up half depth)</button>
1619

1720
<script src="bundle.js" type="text/javascript"></script>
1821
<script>
@@ -31,7 +34,7 @@
3134
const reader = new FileReader();
3235

3336
// Read the file as text
34-
const { fixScale, fixDebris } = window.fixes;
37+
const { fixScale, fixDebris, fixFixture } = window.fixes;
3538
reader.onload = function (event) {
3639
try {
3740
// Parse the JSON content
@@ -49,6 +52,11 @@
4952
prefix = `fixed_scale${vars.revert ? '(pixel_unit)' : '(world_unit)'}`
5053
break;
5154
}
55+
case 'fixture': {
56+
fix = (obj) => { return fixFixture(obj, vars.moveUpHalfDepth) };
57+
prefix = `fixed_fixture${vars.moveUpHalfDepth ? '(moveUpHalfDepth)' : ''}`;
58+
break;
59+
}
5260
}
5361
downloadJson(fix(jsonObject), `${prefix}_${file.name}`);
5462
} catch (error) {

0 commit comments

Comments
 (0)