|
36 | 36 | var require_rfdc = __commonJS({ |
37 | 37 | "node_modules/.pnpm/rfdc@1.4.1/node_modules/rfdc/index.js"(exports, module) { |
38 | 38 | "use strict"; |
39 | | - module.exports = rfdc4; |
| 39 | + module.exports = rfdc5; |
40 | 40 | function copyBuffer(cur) { |
41 | 41 | if (cur instanceof Buffer) { |
42 | 42 | return Buffer.from(cur); |
43 | 43 | } |
44 | 44 | return new cur.constructor(cur.buffer.slice(), cur.byteOffset, cur.length); |
45 | 45 | } |
46 | | - function rfdc4(opts) { |
| 46 | + function rfdc5(opts) { |
47 | 47 | opts = opts || {}; |
48 | 48 | if (opts.circles) return rfdcCircles(opts); |
49 | 49 | const constructorHandlers = /* @__PURE__ */ new Map(); |
|
423 | 423 | } |
424 | 424 | } |
425 | 425 | } |
| 426 | + if (parentKey?.currentParentKey === targetKey) { |
| 427 | + should_trigger_effect = true; |
| 428 | + } |
426 | 429 | if (should_trigger_effect) { |
427 | 430 | effect?.(newObj); |
428 | 431 | } |
|
558 | 561 | return output; |
559 | 562 | }; |
560 | 563 |
|
| 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 | + |
561 | 671 | // src/index.ts |
562 | | - window.fixes = { fixScale, fixDebris }; |
| 672 | + window.fixes = { fixScale, fixDebris, fixFixture }; |
563 | 673 | })(); |
0 commit comments