create-mud 2.0.0-alpha.1.21 → 2.0.0-alpha.1.210
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cli.js +1 -1
- package/dist/templates/{minimal/packages/client → phaser}/.eslintrc +1 -3
- package/dist/templates/phaser/package.json +28 -0
- package/dist/templates/phaser/packages/art/.gitignore +0 -0
- package/dist/templates/phaser/packages/art/README.md +33 -0
- package/dist/templates/phaser/packages/art/config-sprites.json +21 -0
- package/dist/templates/phaser/packages/art/package.json +27 -0
- package/dist/templates/phaser/packages/art/scripts/cli.mjs +190 -0
- package/dist/templates/phaser/packages/art/scripts/export-tiled-types.ts +292 -0
- package/dist/templates/phaser/packages/art/sprites/golem/attack/0.png +0 -0
- package/dist/templates/phaser/packages/art/sprites/golem/attack/1.png +0 -0
- package/dist/templates/phaser/packages/art/sprites/golem/attack/2.png +0 -0
- package/dist/templates/phaser/packages/art/sprites/golem/attack/3.png +0 -0
- package/dist/templates/phaser/packages/art/sprites/golem/attack/4.png +0 -0
- package/dist/templates/phaser/packages/art/sprites/golem/attack/5.png +0 -0
- package/dist/templates/phaser/packages/art/sprites/golem/death/0.png +0 -0
- package/dist/templates/phaser/packages/art/sprites/golem/death/1.png +0 -0
- package/dist/templates/phaser/packages/art/sprites/golem/death/2.png +0 -0
- package/dist/templates/phaser/packages/art/sprites/golem/idle/0.png +0 -0
- package/dist/templates/phaser/packages/art/sprites/golem/idle/1.png +0 -0
- package/dist/templates/phaser/packages/art/sprites/golem/idle/2.png +0 -0
- package/dist/templates/phaser/packages/art/sprites/golem/idle/3.png +0 -0
- package/dist/templates/phaser/packages/art/tilesets/images/world.png +0 -0
- package/dist/templates/phaser/packages/art/tilesets/world.tsx +19 -0
- package/dist/templates/phaser/packages/client/.env +1 -0
- package/dist/templates/phaser/packages/client/.eslintrc +7 -0
- package/dist/templates/phaser/packages/client/index.html +39 -0
- package/dist/templates/phaser/packages/client/package.json +48 -0
- package/dist/templates/phaser/packages/client/public/assets/atlases/atlas.json +292 -0
- package/dist/templates/phaser/packages/client/public/assets/atlases/atlas.png +0 -0
- package/dist/templates/phaser/packages/client/public/assets/tilesets/world.png +0 -0
- package/dist/templates/phaser/packages/client/src/artTypes/world.ts +9 -0
- package/dist/templates/phaser/packages/client/src/index.tsx +11 -0
- package/dist/templates/phaser/packages/client/src/layers/network/createNetworkLayer.ts +24 -0
- package/dist/templates/phaser/packages/client/src/layers/phaser/configurePhaser.ts +91 -0
- package/dist/templates/phaser/packages/client/src/layers/phaser/constants.ts +22 -0
- package/dist/templates/phaser/packages/client/src/layers/phaser/createPhaserLayer.ts +33 -0
- package/dist/templates/phaser/packages/client/src/layers/phaser/systems/createCamera.ts +13 -0
- package/dist/templates/phaser/packages/client/src/layers/phaser/systems/createMapSystem.ts +32 -0
- package/dist/templates/phaser/packages/client/src/layers/phaser/systems/index.ts +1 -0
- package/dist/templates/phaser/packages/client/src/layers/phaser/systems/registerSystems.ts +8 -0
- package/dist/templates/phaser/packages/client/src/mud/contractComponents.ts +24 -0
- package/dist/templates/phaser/packages/client/src/mud/createClientComponents.ts +10 -0
- package/dist/templates/phaser/packages/client/src/mud/createSystemCalls.ts +21 -0
- package/dist/templates/phaser/packages/client/src/mud/getNetworkConfig.ts +53 -0
- package/dist/templates/phaser/packages/client/src/mud/setup.ts +16 -0
- package/dist/templates/phaser/packages/client/src/mud/setupNetwork.ts +102 -0
- package/dist/templates/phaser/packages/client/src/mud/supportedChains.ts +5 -0
- package/dist/templates/phaser/packages/client/src/mud/world.ts +3 -0
- package/dist/templates/phaser/packages/client/src/store.ts +38 -0
- package/dist/templates/phaser/packages/client/src/ui/App.tsx +23 -0
- package/dist/templates/phaser/packages/client/src/ui/LoadingScreen/BootScreen.tsx +42 -0
- package/dist/templates/phaser/packages/client/src/ui/LoadingScreen/LoadingBar.tsx +21 -0
- package/dist/templates/phaser/packages/client/src/ui/LoadingScreen/LoadingScreen.tsx +52 -0
- package/dist/templates/phaser/packages/client/src/ui/LoadingScreen/index.ts +1 -0
- package/dist/templates/phaser/packages/client/src/ui/PhaserLayer.tsx +20 -0
- package/dist/templates/phaser/packages/client/src/ui/UIRoot.tsx +20 -0
- package/dist/templates/phaser/packages/client/src/ui/Wrapper.tsx +5 -0
- package/dist/templates/phaser/packages/client/src/ui/hooks/useNetworkLayer.tsx +17 -0
- package/dist/templates/phaser/packages/client/src/ui/hooks/usePhaserLayer.tsx +87 -0
- package/dist/templates/phaser/packages/client/src/ui/hooks/usePromiseValue.ts +24 -0
- package/dist/templates/phaser/packages/client/src/ui/theme/ClickWrapper.tsx +18 -0
- package/dist/templates/phaser/packages/client/src/ui/theme/SpriteImage.tsx +52 -0
- package/dist/templates/{minimal → phaser}/packages/client/tsconfig.json +3 -4
- package/dist/templates/phaser/packages/client/vite.config.ts +15 -0
- package/dist/templates/phaser/packages/contracts/.env +8 -0
- package/dist/templates/{minimal → phaser}/packages/contracts/.gitignore +3 -2
- package/dist/templates/{minimal → phaser}/packages/contracts/.solhint.json +2 -1
- package/dist/templates/phaser/packages/contracts/foundry.toml +22 -0
- package/dist/templates/phaser/packages/contracts/mud.config.ts +10 -0
- package/dist/templates/phaser/packages/contracts/package.json +45 -0
- package/dist/templates/phaser/packages/contracts/remappings.txt +3 -0
- package/dist/templates/phaser/packages/contracts/script/PostDeploy.s.sol +17 -0
- package/dist/templates/phaser/packages/contracts/src/codegen/Tables.sol +6 -0
- package/dist/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol +120 -0
- package/dist/templates/phaser/packages/contracts/src/codegen/world/IIncrementSystem.sol +8 -0
- package/dist/templates/phaser/packages/contracts/src/codegen/world/IWorld.sol +16 -0
- package/dist/templates/phaser/packages/contracts/src/systems/IncrementSystem.sol +14 -0
- package/dist/templates/phaser/packages/contracts/test/CounterTest.t.sol +38 -0
- package/dist/templates/phaser/packages/contracts/tsconfig.json +13 -0
- package/dist/templates/phaser/packages/contracts/worlds.json +5 -0
- package/dist/templates/react/.eslintrc +10 -0
- package/dist/templates/react/package.json +13 -3
- package/dist/templates/react/packages/client/.env +1 -0
- package/dist/templates/react/packages/client/.eslintrc +2 -12
- package/dist/templates/react/packages/client/package.json +18 -21
- package/dist/templates/react/packages/client/src/App.tsx +11 -13
- package/dist/templates/react/packages/client/src/MUDContext.tsx +21 -0
- package/dist/templates/react/packages/client/src/index.tsx +12 -31
- package/dist/templates/react/packages/client/src/mud/contractComponents.ts +24 -0
- package/dist/templates/react/packages/client/src/mud/createClientComponents.ts +10 -0
- package/dist/templates/react/packages/client/src/mud/createSystemCalls.ts +21 -0
- package/dist/templates/react/packages/client/src/mud/getNetworkConfig.ts +53 -0
- package/dist/templates/react/packages/client/src/mud/setup.ts +16 -0
- package/dist/templates/react/packages/client/src/mud/setupNetwork.ts +102 -0
- package/dist/templates/react/packages/client/src/mud/supportedChains.ts +5 -0
- package/dist/templates/react/packages/client/src/mud/world.ts +3 -0
- package/dist/templates/react/packages/client/tsconfig.json +0 -3
- package/dist/templates/react/packages/client/vite.config.ts +3 -0
- package/dist/templates/react/packages/contracts/.env +8 -0
- package/dist/templates/react/packages/contracts/.gitignore +3 -2
- package/dist/templates/react/packages/contracts/.solhint.json +2 -1
- package/dist/templates/react/packages/contracts/foundry.toml +13 -2
- package/dist/templates/react/packages/contracts/mud.config.ts +10 -0
- package/dist/templates/react/packages/contracts/package.json +25 -20
- package/dist/templates/react/packages/contracts/remappings.txt +3 -9
- package/dist/templates/react/packages/contracts/script/PostDeploy.s.sol +24 -0
- package/dist/templates/react/packages/contracts/src/codegen/Tables.sol +6 -0
- package/dist/templates/react/packages/contracts/src/codegen/tables/Counter.sol +120 -0
- package/dist/templates/react/packages/contracts/src/codegen/world/IIncrementSystem.sol +8 -0
- package/dist/templates/react/packages/contracts/src/codegen/world/IWorld.sol +16 -0
- package/dist/templates/react/packages/contracts/src/systems/IncrementSystem.sol +7 -15
- package/dist/templates/react/packages/contracts/test/CounterTest.t.sol +38 -0
- package/dist/templates/react/packages/contracts/tsconfig.json +9 -8
- package/dist/templates/react/packages/contracts/worlds.json +5 -0
- package/dist/templates/threejs/.eslintrc +10 -0
- package/dist/templates/threejs/.gitignore +1 -0
- package/dist/templates/threejs/.vscode/extensions.json +3 -0
- package/dist/templates/threejs/.vscode/settings.json +3 -0
- package/dist/templates/threejs/package.json +28 -0
- package/dist/templates/threejs/packages/client/.env +1 -0
- package/dist/templates/threejs/packages/client/.eslintrc +7 -0
- package/dist/templates/threejs/packages/client/.gitignore +3 -0
- package/dist/templates/threejs/packages/client/index.html +12 -0
- package/dist/templates/threejs/packages/client/package.json +41 -0
- package/dist/templates/threejs/packages/client/src/App.tsx +81 -0
- package/dist/templates/threejs/packages/client/src/MUDContext.tsx +21 -0
- package/dist/templates/threejs/packages/client/src/index.tsx +19 -0
- package/dist/templates/threejs/packages/client/src/mud/contractComponents.ts +26 -0
- package/dist/templates/threejs/packages/client/src/mud/createClientComponents.ts +10 -0
- package/dist/templates/threejs/packages/client/src/mud/createSystemCalls.ts +15 -0
- package/dist/templates/threejs/packages/client/src/mud/getNetworkConfig.ts +53 -0
- package/dist/templates/threejs/packages/client/src/mud/setup.ts +16 -0
- package/dist/templates/threejs/packages/client/src/mud/setupNetwork.ts +102 -0
- package/dist/templates/threejs/packages/client/src/mud/supportedChains.ts +5 -0
- package/dist/templates/threejs/packages/client/src/mud/world.ts +3 -0
- package/dist/templates/threejs/packages/client/src/useKeyboardMovement.ts +60 -0
- package/dist/templates/threejs/packages/client/tsconfig.json +19 -0
- package/dist/templates/threejs/packages/client/vite.config.ts +15 -0
- package/dist/templates/threejs/packages/contracts/.env +8 -0
- package/dist/templates/threejs/packages/contracts/.gitignore +11 -0
- package/dist/templates/threejs/packages/contracts/.prettierrc +8 -0
- package/dist/templates/threejs/packages/contracts/.solhint.json +12 -0
- package/dist/templates/threejs/packages/contracts/foundry.toml +22 -0
- package/dist/templates/threejs/packages/contracts/mud.config.ts +13 -0
- package/dist/templates/threejs/packages/contracts/package.json +45 -0
- package/dist/templates/threejs/packages/contracts/remappings.txt +3 -0
- package/dist/templates/threejs/packages/contracts/src/codegen/Tables.sol +6 -0
- package/dist/templates/threejs/packages/contracts/src/codegen/tables/Position.sol +263 -0
- package/dist/templates/threejs/packages/contracts/src/codegen/world/IMoveSystem.sol +8 -0
- package/dist/templates/threejs/packages/contracts/src/codegen/world/IWorld.sol +16 -0
- package/dist/templates/threejs/packages/contracts/src/systems/MoveSystem.sol +25 -0
- package/dist/templates/threejs/packages/contracts/tsconfig.json +13 -0
- package/dist/templates/threejs/packages/contracts/worlds.json +5 -0
- package/dist/templates/threejs/pnpm-workspace.yaml +2 -0
- package/dist/templates/vanilla/.eslintrc +10 -0
- package/dist/templates/vanilla/.gitignore +1 -0
- package/dist/templates/vanilla/.vscode/extensions.json +3 -0
- package/dist/templates/vanilla/.vscode/settings.json +3 -0
- package/dist/templates/vanilla/package.json +28 -0
- package/dist/templates/vanilla/packages/client/.env +1 -0
- package/dist/templates/vanilla/packages/client/.gitignore +3 -0
- package/dist/templates/vanilla/packages/client/package.json +32 -0
- package/dist/templates/vanilla/packages/client/src/index.ts +22 -0
- package/dist/templates/vanilla/packages/client/src/mud/contractComponents.ts +24 -0
- package/dist/templates/vanilla/packages/client/src/mud/createClientComponents.ts +10 -0
- package/dist/templates/vanilla/packages/client/src/mud/createSystemCalls.ts +21 -0
- package/dist/templates/vanilla/packages/client/src/mud/getNetworkConfig.ts +53 -0
- package/dist/templates/vanilla/packages/client/src/mud/setup.ts +16 -0
- package/dist/templates/vanilla/packages/client/src/mud/setupNetwork.ts +102 -0
- package/dist/templates/vanilla/packages/client/src/mud/supportedChains.ts +5 -0
- package/dist/templates/vanilla/packages/client/src/mud/world.ts +3 -0
- package/dist/templates/vanilla/packages/client/tsconfig.json +18 -0
- package/dist/templates/{minimal → vanilla}/packages/client/vite.config.ts +3 -0
- package/dist/templates/vanilla/packages/contracts/.env +8 -0
- package/dist/templates/vanilla/packages/contracts/.gitignore +11 -0
- package/dist/templates/vanilla/packages/contracts/.prettierrc +8 -0
- package/dist/templates/vanilla/packages/contracts/.solhint.json +12 -0
- package/dist/templates/vanilla/packages/contracts/foundry.toml +22 -0
- package/dist/templates/vanilla/packages/contracts/mud.config.ts +10 -0
- package/dist/templates/vanilla/packages/contracts/package.json +45 -0
- package/dist/templates/vanilla/packages/contracts/remappings.txt +3 -0
- package/dist/templates/vanilla/packages/contracts/script/PostDeploy.s.sol +24 -0
- package/dist/templates/vanilla/packages/contracts/src/codegen/Tables.sol +6 -0
- package/dist/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol +120 -0
- package/dist/templates/vanilla/packages/contracts/src/codegen/world/IIncrementSystem.sol +8 -0
- package/dist/templates/vanilla/packages/contracts/src/codegen/world/IWorld.sol +16 -0
- package/dist/templates/vanilla/packages/contracts/src/systems/IncrementSystem.sol +14 -0
- package/dist/templates/vanilla/packages/contracts/test/CounterTest.t.sol +38 -0
- package/dist/templates/vanilla/packages/contracts/tsconfig.json +13 -0
- package/dist/templates/vanilla/packages/contracts/worlds.json +5 -0
- package/dist/templates/vanilla/pnpm-workspace.yaml +2 -0
- package/package.json +14 -11
- package/dist/templates/minimal/package.json +0 -18
- package/dist/templates/minimal/packages/client/package.json +0 -37
- package/dist/templates/minimal/packages/client/src/config.ts +0 -22
- package/dist/templates/minimal/packages/client/src/index.ts +0 -37
- package/dist/templates/minimal/packages/contracts/chainSpec.json +0 -5
- package/dist/templates/minimal/packages/contracts/deploy.json +0 -4
- package/dist/templates/minimal/packages/contracts/exports.sh +0 -22
- package/dist/templates/minimal/packages/contracts/foundry.toml +0 -11
- package/dist/templates/minimal/packages/contracts/package.json +0 -40
- package/dist/templates/minimal/packages/contracts/remappings.txt +0 -9
- package/dist/templates/minimal/packages/contracts/src/components/CounterComponent.sol +0 -9
- package/dist/templates/minimal/packages/contracts/src/libraries/LibMath.sol +0 -10
- package/dist/templates/minimal/packages/contracts/src/systems/IncrementSystem.sol +0 -22
- package/dist/templates/minimal/packages/contracts/src/systems/README.md +0 -7
- package/dist/templates/minimal/packages/contracts/src/test/Deploy.sol +0 -19
- package/dist/templates/minimal/packages/contracts/src/test/Deploy.t.sol +0 -14
- package/dist/templates/minimal/packages/contracts/src/test/LibDeploy.sol +0 -22
- package/dist/templates/minimal/packages/contracts/tsconfig.json +0 -12
- package/dist/templates/react/packages/client/src/config.ts +0 -22
- package/dist/templates/react/packages/contracts/chainSpec.json +0 -5
- package/dist/templates/react/packages/contracts/deploy.json +0 -4
- package/dist/templates/react/packages/contracts/exports.sh +0 -22
- package/dist/templates/react/packages/contracts/src/components/CounterComponent.sol +0 -9
- package/dist/templates/react/packages/contracts/src/libraries/LibMath.sol +0 -10
- package/dist/templates/react/packages/contracts/src/systems/README.md +0 -7
- package/dist/templates/react/packages/contracts/src/test/Deploy.sol +0 -19
- package/dist/templates/react/packages/contracts/src/test/Deploy.t.sol +0 -14
- package/dist/templates/react/packages/contracts/src/test/LibDeploy.sol +0 -22
- /package/dist/templates/{minimal → phaser}/.gitignore +0 -0
- /package/dist/templates/{minimal → phaser}/.vscode/extensions.json +0 -0
- /package/dist/templates/{minimal → phaser}/.vscode/settings.json +0 -0
- /package/dist/templates/{minimal → phaser}/packages/client/.gitignore +0 -0
- /package/dist/templates/{minimal → phaser}/packages/contracts/.prettierrc +0 -0
- /package/dist/templates/{minimal → phaser}/pnpm-workspace.yaml +0 -0
- /package/dist/templates/{minimal → vanilla}/packages/client/index.html +0 -0
package/README.md
CHANGED
package/dist/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var t=require("create-create-app"),a=require("path");var e={name:"create-mud",version:"2.0.0-alpha.1.
|
|
2
|
+
"use strict";var t=require("create-create-app"),a=require("path");var e={name:"create-mud",version:"2.0.0-alpha.1.210+69c126a9",description:"Create a new MUD project",license:"MIT",author:"Lattice <mud@lattice.xyz>",bin:"dist/cli.js",files:["dist"],scripts:{build:"pnpm run build:js","build:js":"tsup && ./scripts/copy-templates.sh",clean:"pnpm run clean:js","clean:js":"rimraf dist",dev:"tsup --watch",prepublishOnly:"npm run clean && npm run build",test:"pnpm run test:vanilla && pnpm run test:react && pnpm run test:phaser && pnpm run test:threejs","test:phaser":"dist/cli.js test-project --template phaser && rimraf test-project","test:react":"dist/cli.js test-project --template react && rimraf test-project","test:threejs":"dist/cli.js test-project --template threejs && rimraf test-project","test:vanilla":"dist/cli.js test-project --template vanilla && rimraf test-project"},dependencies:{"create-create-app":"git+https://github.com/holic/create-create-app#74376c59b48a04aabbe94d9cacfe9cb1cecccd63"},devDependencies:{"@types/node":"^18.15.11",tsup:"^6.7.0",typescript:"^4.9.5"},publishConfig:{access:"public",registry:"https://registry.npmjs.org"},gitHead:"69c126a9e3d95a451b88d36c50e30279cc628a9d"};var c=(0,a.resolve)(__dirname,"..","dist","templates");(0,t.create)("create-mud",{templateRoot:c,defaultTemplate:"vanilla",defaultPackageManager:"pnpm",promptForDescription:!1,promptForAuthor:!1,promptForEmail:!1,promptForLicense:!1,promptForTemplate:!0,caveat:({answers:r,packageManager:s})=>`Done! Play in the MUD with \`cd ${r.name}\` and \`${s} run dev\``,extra:{"mud-version":{type:"input",describe:"The version of MUD packages to use, defaults to latest",default:e.version}}});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mud-template-phaser",
|
|
3
|
+
"private": true,
|
|
4
|
+
"scripts": {
|
|
5
|
+
"build": "pnpm recursive run build",
|
|
6
|
+
"dev": "concurrently -n contracts,client -c cyan,magenta \"cd packages/contracts && pnpm run dev\" \"cd packages/client && pnpm run dev\"",
|
|
7
|
+
"dev:client": "pnpm --filter 'client' run dev",
|
|
8
|
+
"dev:contracts": "pnpm --filter 'contracts' dev",
|
|
9
|
+
"foundry:up": "curl -L https://foundry.paradigm.xyz | bash && bash $HOME/.foundry/bin/foundryup",
|
|
10
|
+
"initialize": "pnpm recursive run initialize",
|
|
11
|
+
"mud:up": "pnpm recursive exec mud set-version -v canary && pnpm install",
|
|
12
|
+
"prepare": "(forge --version || pnpm foundry:up)",
|
|
13
|
+
"test": "pnpm recursive run test"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@latticexyz/cli": "{{mud-version}}",
|
|
17
|
+
"@typescript-eslint/eslint-plugin": "5.46.1",
|
|
18
|
+
"@typescript-eslint/parser": "5.46.1",
|
|
19
|
+
"concurrently": "^8.0.1",
|
|
20
|
+
"eslint": "8.29.0",
|
|
21
|
+
"rimraf": "^3.0.2",
|
|
22
|
+
"typescript": "^4.9.5"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": "18.x",
|
|
26
|
+
"pnpm": "8.x"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Art Tooling
|
|
2
|
+
|
|
3
|
+
This package provides a set of tools for working with sprite sheets and tilesets.
|
|
4
|
+
|
|
5
|
+
## Sprites
|
|
6
|
+
|
|
7
|
+
To create a new Sprite animation you need to define a new folder structure inside of the `sprites` folder. Inside of that folder, create a series of images defining the frames of the animation. The name of the folder will be the name of the animation. The names of the images should be the frame number.
|
|
8
|
+
|
|
9
|
+
Example:
|
|
10
|
+
```
|
|
11
|
+
sprites/
|
|
12
|
+
player/
|
|
13
|
+
walk/
|
|
14
|
+
0.png
|
|
15
|
+
1.png
|
|
16
|
+
2.png
|
|
17
|
+
3.png
|
|
18
|
+
4.png
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Tilesets
|
|
22
|
+
|
|
23
|
+
Tilesets are generated using the (Tiled Map Editor)[https://www.mapeditor.org/]. An example is provided in `tilesets/world.tsx`.
|
|
24
|
+
|
|
25
|
+
## Exporting
|
|
26
|
+
|
|
27
|
+
Export does a few things:
|
|
28
|
+
1. Creates a single image sprite atlas for all of your animations
|
|
29
|
+
2. Creates an atlas manifest json file that maps the animation names to the frames in the atlas
|
|
30
|
+
3. Creates Typescript types for your Tilesets
|
|
31
|
+
4. Moves all created files into your game client package
|
|
32
|
+
|
|
33
|
+
To export, run `pnpm export` from the root of this project.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"savePath": "../client/public/assets/atlases",
|
|
3
|
+
"folders": ["sprites"],
|
|
4
|
+
"images": [],
|
|
5
|
+
"packOptions": {
|
|
6
|
+
"allowTrim": false,
|
|
7
|
+
"textureName": "atlas",
|
|
8
|
+
"width": 2048,
|
|
9
|
+
"height": 2048,
|
|
10
|
+
"fixedSize": true,
|
|
11
|
+
"powerOfTwo": true,
|
|
12
|
+
"padding": 0,
|
|
13
|
+
"allowRotation": false,
|
|
14
|
+
"detectIdentical": true,
|
|
15
|
+
"exporter": "Phaser3",
|
|
16
|
+
"removeFileExtension": false,
|
|
17
|
+
"prependFolderName": true,
|
|
18
|
+
"packer": "MaxRectsPacker",
|
|
19
|
+
"method": "Smart"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "art",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"types": "./types",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"compile-extensions": "tsc ./tiled/extensions/*.ts --outDir ./tiled/extensions/",
|
|
8
|
+
"export": "yarn generate-multiatlas-sprites && yarn export-tiled-types",
|
|
9
|
+
"export-tiled-types": "ts-node ./scripts/export-tiled-types.ts && cp tilesets/images/* ../client/public/assets/tilesets/",
|
|
10
|
+
"generate-multiatlas-sprites": "node ./scripts/cli.mjs --project ./config-sprites.json"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@mapeditor/tiled-api": "^1.8.2",
|
|
14
|
+
"@types/ejs": "^3.1.1",
|
|
15
|
+
"@types/glob": "^7.2.0",
|
|
16
|
+
"@types/node": "^18.0.3",
|
|
17
|
+
"ejs": "^3.1.8",
|
|
18
|
+
"ethers": "^5.7.0",
|
|
19
|
+
"free-tex-packer-cli": "^0.3.0",
|
|
20
|
+
"free-tex-packer-core": "^0.3.4",
|
|
21
|
+
"glob": "^8.0.3",
|
|
22
|
+
"optimist": "^0.6.1",
|
|
23
|
+
"ts-node": "^10.8.2",
|
|
24
|
+
"typescript": "^4.7.4",
|
|
25
|
+
"xml-js": "^1.6.11"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { existsSync, statSync, readdirSync, readFileSync, readFile, writeFileSync } from "fs";
|
|
2
|
+
import { resolve, dirname } from "path";
|
|
3
|
+
import optimist from "optimist";
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
const { yellowBright, redBright, white, magentaBright, greenBright } = chalk;
|
|
6
|
+
import texturePacker from "free-tex-packer-core";
|
|
7
|
+
|
|
8
|
+
import appInfo from "../package.json" assert { type: "json" };
|
|
9
|
+
|
|
10
|
+
function isExists(path) {
|
|
11
|
+
return existsSync(path);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function fixPath(path) {
|
|
15
|
+
return path.trim().split("\\").join("/");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function getNameFromPath(path) {
|
|
19
|
+
return path.trim().split("/").pop();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function isNumeric(str) {
|
|
23
|
+
if (typeof str != "string") return false; // we only process strings!
|
|
24
|
+
return (
|
|
25
|
+
!isNaN(str) && // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)...
|
|
26
|
+
!isNaN(parseFloat(str))
|
|
27
|
+
); // ...and ensure strings of whitespace fail
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function isFolder(path) {
|
|
31
|
+
if (isExists(path)) {
|
|
32
|
+
return statSync(path).isDirectory();
|
|
33
|
+
} else {
|
|
34
|
+
path = fixPath(path);
|
|
35
|
+
let name = getNameFromPath(path);
|
|
36
|
+
let parts = name.split(".");
|
|
37
|
+
return parts.length === 1;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function getFolderFilesList(dir, base = "", list = []) {
|
|
42
|
+
let files = readdirSync(dir);
|
|
43
|
+
for (let file of files) {
|
|
44
|
+
let p = resolve(dir, file);
|
|
45
|
+
if (isFolder(p) && p.toUpperCase().indexOf("__MACOSX") < 0) {
|
|
46
|
+
list = getFolderFilesList(p, base + file + "/", list);
|
|
47
|
+
} else {
|
|
48
|
+
list.push({
|
|
49
|
+
name: (base ? base : "") + file,
|
|
50
|
+
path: p,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return list;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function loadImages(images, files) {
|
|
59
|
+
for (let image of images) {
|
|
60
|
+
try {
|
|
61
|
+
files.push({ path: image.name, contents: readFileSync(image.path) });
|
|
62
|
+
} catch (e) {}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// console.log(yellowBright("Free Texture Packer CLI v" + _version));
|
|
67
|
+
const argv = optimist.argv;
|
|
68
|
+
|
|
69
|
+
let projectPath = argv.project;
|
|
70
|
+
if (!projectPath) {
|
|
71
|
+
console.log(redBright("Choose project, using --project argument"));
|
|
72
|
+
process.exit();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
readFile(projectPath, (err, content) => {
|
|
76
|
+
if (err) {
|
|
77
|
+
console.error(err.toString());
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
content = content.toString();
|
|
82
|
+
let project = null;
|
|
83
|
+
try {
|
|
84
|
+
project = JSON.parse(content);
|
|
85
|
+
} catch (e) {
|
|
86
|
+
console.log(redBright("Unsupported project format " + projectPath));
|
|
87
|
+
process.exit();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
let outputPath = argv.output;
|
|
91
|
+
|
|
92
|
+
if (!outputPath) {
|
|
93
|
+
outputPath = project.savePath;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (!outputPath) {
|
|
97
|
+
outputPath = dirname(projectPath);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let files = [];
|
|
101
|
+
|
|
102
|
+
loadImages(project.images, files);
|
|
103
|
+
|
|
104
|
+
for (let folder of project.folders) {
|
|
105
|
+
if (isExists(folder)) {
|
|
106
|
+
let list = getFolderFilesList(folder, getNameFromPath(folder) + "/");
|
|
107
|
+
loadImages(list, files);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
let options = project.packOptions;
|
|
112
|
+
|
|
113
|
+
//Map exporters to core format
|
|
114
|
+
if (options.exporter === "JSON (hash)") options.exporter = "JsonHash";
|
|
115
|
+
if (options.exporter === "JSON (array)") options.exporter = "JsonArray";
|
|
116
|
+
if (options.exporter === "XML") options.exporter = "XML";
|
|
117
|
+
if (options.exporter === "css (modern)") options.exporter = "Css";
|
|
118
|
+
if (options.exporter === "css (old)") options.exporter = "OldCss";
|
|
119
|
+
if (options.exporter === "pixi.js") options.exporter = "Pixi";
|
|
120
|
+
if (options.exporter === "Phaser (hash)") options.exporter = "PhaserHash";
|
|
121
|
+
if (options.exporter === "Phaser (array)") options.exporter = "PhaserArray";
|
|
122
|
+
if (options.exporter === "Phaser 3") options.exporter = "Phaser3";
|
|
123
|
+
if (options.exporter === "Spine") options.exporter = "Spine";
|
|
124
|
+
if (options.exporter === "cocos2d") options.exporter = "Cocos2d";
|
|
125
|
+
if (options.exporter === "UnrealEngine") options.exporter = "Unreal";
|
|
126
|
+
if (options.exporter === "Starling") options.exporter = "Starling";
|
|
127
|
+
if (options.exporter === "Unity3D") options.exporter = "Unity3D";
|
|
128
|
+
if (options.exporter === "Godot (atlas)") options.exporter = "GodotAtlas";
|
|
129
|
+
if (options.exporter === "Godot (tileset)") options.exporter = "GodotTileset";
|
|
130
|
+
|
|
131
|
+
if (options.exporter === "custom") {
|
|
132
|
+
console.log(redBright("CLI does not support a custom exporter"));
|
|
133
|
+
process.exit();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
options.appInfo = appInfo;
|
|
137
|
+
|
|
138
|
+
console.log(white("Start packing ") + magentaBright(projectPath));
|
|
139
|
+
|
|
140
|
+
texturePacker(files, options, (f, error) => {
|
|
141
|
+
if (error) {
|
|
142
|
+
console.log(redBright(error));
|
|
143
|
+
process.exit();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
let outputJson = {
|
|
147
|
+
meta: {
|
|
148
|
+
app: "",
|
|
149
|
+
version: "1.0.0",
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
const textures = [];
|
|
153
|
+
let lastImageName;
|
|
154
|
+
for (const file of f) {
|
|
155
|
+
if (file.name.includes(".json")) {
|
|
156
|
+
const outJson = file.buffer.toString("utf-8", 0, file.buffer.length);
|
|
157
|
+
const out = JSON.parse(outJson);
|
|
158
|
+
textures.push(out.textures[0]);
|
|
159
|
+
console.log(
|
|
160
|
+
white("Adding to output json ") + greenBright(file.name)
|
|
161
|
+
);
|
|
162
|
+
} else {
|
|
163
|
+
lastImageName = file.name;
|
|
164
|
+
let out = resolve(outputPath, file.name);
|
|
165
|
+
console.log(white("Writing ") + greenBright(out));
|
|
166
|
+
writeFileSync(out, file.buffer);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const fileName = lastImageName.split(".")[0];
|
|
170
|
+
let jsonFileName;
|
|
171
|
+
if (isNumeric(fileName[fileName.length - 1])) {
|
|
172
|
+
console.log("multipart detected!!");
|
|
173
|
+
jsonFileName = fileName.split("-")[0] + ".json";
|
|
174
|
+
} else {
|
|
175
|
+
jsonFileName = fileName + ".json";
|
|
176
|
+
}
|
|
177
|
+
const atlasJsonOut = resolve(outputPath, jsonFileName);
|
|
178
|
+
// sort textures
|
|
179
|
+
textures.sort((a, b) => a.image.localeCompare(b.image));
|
|
180
|
+
outputJson.textures = textures;
|
|
181
|
+
// add timestamp to atlas image to avoid browser cache
|
|
182
|
+
outputJson.textures[0].image = "atlas.png?timestamp=" + Date.now();
|
|
183
|
+
writeFileSync(
|
|
184
|
+
atlasJsonOut,
|
|
185
|
+
Buffer.from(JSON.stringify(outputJson, null, 4), "utf-8")
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
console.log(yellowBright("Done"));
|
|
189
|
+
});
|
|
190
|
+
});
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import xlmJs from "xml-js";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import glob from "glob";
|
|
4
|
+
import ejs from "ejs";
|
|
5
|
+
import path from "path";
|
|
6
|
+
|
|
7
|
+
const tilemaps = glob.sync("./tilesets/*.tsx");
|
|
8
|
+
enum PropertyName {
|
|
9
|
+
Name = "name",
|
|
10
|
+
Frame = "frame",
|
|
11
|
+
}
|
|
12
|
+
interface Tile {
|
|
13
|
+
index: number;
|
|
14
|
+
name: string;
|
|
15
|
+
frameNumber?: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface WangTile {
|
|
19
|
+
index: number;
|
|
20
|
+
wangId: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface WangSet {
|
|
24
|
+
name: string;
|
|
25
|
+
wangTiles: WangTile[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface AnimatedTile {
|
|
29
|
+
name: string;
|
|
30
|
+
frames: number[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface Tilemap {
|
|
34
|
+
name: string;
|
|
35
|
+
tiles?: Tile[];
|
|
36
|
+
animatedTiles?: AnimatedTile[];
|
|
37
|
+
wangSets?: WangSet[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const dumpObjectAsError = (obj: any) =>
|
|
41
|
+
console.error(JSON.stringify(obj, null, 2));
|
|
42
|
+
|
|
43
|
+
const readTilemap = (filename: string) => {
|
|
44
|
+
const content = fs.readFileSync(filename, { encoding: "utf-8" });
|
|
45
|
+
const tilemapParsed = xlmJs.xml2js(content, { compact: true });
|
|
46
|
+
return tilemapParsed;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const capitalize = (s: string) => {
|
|
50
|
+
return `${s[0].toUpperCase()}${s.slice(1)}`;
|
|
51
|
+
};
|
|
52
|
+
interface WithName {
|
|
53
|
+
name: string;
|
|
54
|
+
}
|
|
55
|
+
function removeDuplicate<A extends WithName>(v: A, i: number, a: A[]) {
|
|
56
|
+
return a.findIndex((v2) => v2.name === v.name) === i;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const kebabToCamel = (kebab: string) => {
|
|
60
|
+
const parts = kebab.split("-");
|
|
61
|
+
let s = parts[0];
|
|
62
|
+
for (const p of parts.slice(1)) {
|
|
63
|
+
s = s + capitalize(p);
|
|
64
|
+
}
|
|
65
|
+
return s;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const processTilemap = (filename: string) => {
|
|
69
|
+
const name = kebabToCamel(filename.split(path.sep).at(-1)!.split(".")[0]);
|
|
70
|
+
console.log(`Processing ${name}`);
|
|
71
|
+
const tilemap = readTilemap(filename);
|
|
72
|
+
const elements = parseTilemap(name, tilemap);
|
|
73
|
+
return elements;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const parseTilemap = (name: string, tilemap: xlmJs.ElementCompact): Tilemap => {
|
|
77
|
+
const tileset = tilemap.tileset;
|
|
78
|
+
const tiles = tileset.tile;
|
|
79
|
+
const wangsets = tileset.wangsets?.wangset;
|
|
80
|
+
let tileObjects;
|
|
81
|
+
let animatedTiles;
|
|
82
|
+
let wangsetObjects;
|
|
83
|
+
if (tiles) {
|
|
84
|
+
if (Array.isArray(tiles)) {
|
|
85
|
+
console.log(`Parsing ${tiles.length} tiles`);
|
|
86
|
+
tileObjects = tiles.filter(checkTile).map(parseTile);
|
|
87
|
+
animatedTiles = buildAnimatedTileList(tileObjects);
|
|
88
|
+
console.log(`Found ${animatedTiles.length} animated tiles`);
|
|
89
|
+
tileObjects = tileObjects.filter((t: Tile) => !t.frameNumber);
|
|
90
|
+
console.log(`Found ${tileObjects.length} tiles`);
|
|
91
|
+
} else {
|
|
92
|
+
console.log(`Parsing 1 tile`);
|
|
93
|
+
tileObjects = [tiles].filter(checkTile).map(parseTile);
|
|
94
|
+
animatedTiles = buildAnimatedTileList(tileObjects);
|
|
95
|
+
console.log(`Found ${animatedTiles.length} animated tiles`);
|
|
96
|
+
tileObjects = tileObjects.filter((t: Tile) => !t.frameNumber);
|
|
97
|
+
console.log(`Found ${tileObjects.length} tiles`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (wangsets) {
|
|
101
|
+
if (Array.isArray(wangsets)) {
|
|
102
|
+
console.log(`Parsing ${wangsets.length} wangsets`);
|
|
103
|
+
wangsetObjects = wangsets.map(parseWangset);
|
|
104
|
+
} else {
|
|
105
|
+
console.log(`Parsing 1 wangset`);
|
|
106
|
+
wangsetObjects = [parseWangset(wangsets)];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
name,
|
|
111
|
+
tiles: tileObjects?.filter(removeDuplicate),
|
|
112
|
+
animatedTiles: animatedTiles?.filter(removeDuplicate),
|
|
113
|
+
wangSets: wangsetObjects?.filter(removeDuplicate),
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const findProperty = (element: xlmJs.ElementCompact, name: string) => {
|
|
118
|
+
const properties: any = element.properties;
|
|
119
|
+
const property = properties.property;
|
|
120
|
+
if (Array.isArray(property)) {
|
|
121
|
+
for (const p of property) {
|
|
122
|
+
const n = p._attributes.name;
|
|
123
|
+
if (n === name) {
|
|
124
|
+
return p._attributes.value;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
const n = property._attributes.name;
|
|
129
|
+
if (n === name) {
|
|
130
|
+
return property._attributes.value;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const checkTile = (tile: xlmJs.ElementCompact): boolean => {
|
|
136
|
+
const indexUnparsed = tile._attributes!.id!;
|
|
137
|
+
const index =
|
|
138
|
+
indexUnparsed != undefined && typeof indexUnparsed === "string"
|
|
139
|
+
? parseInt(indexUnparsed)
|
|
140
|
+
: undefined;
|
|
141
|
+
if (index == undefined) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
const name: string | undefined = findProperty(tile, PropertyName.Name);
|
|
145
|
+
if (!name) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
return true;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const parseTile = (tile: xlmJs.ElementCompact) => {
|
|
152
|
+
const indexUnparsed = tile._attributes!.id!;
|
|
153
|
+
const index =
|
|
154
|
+
indexUnparsed && typeof indexUnparsed === "string"
|
|
155
|
+
? parseInt(indexUnparsed)
|
|
156
|
+
: undefined;
|
|
157
|
+
if (index == undefined) {
|
|
158
|
+
dumpObjectAsError(tile);
|
|
159
|
+
throw new Error("Tile has no index!");
|
|
160
|
+
}
|
|
161
|
+
const name: string | undefined = findProperty(tile, PropertyName.Name);
|
|
162
|
+
if (!name) {
|
|
163
|
+
dumpObjectAsError(tile);
|
|
164
|
+
throw new Error("Tile has no name!");
|
|
165
|
+
}
|
|
166
|
+
const frameNumberUnparsed = findProperty(tile, PropertyName.Frame);
|
|
167
|
+
const frameNumber = frameNumberUnparsed != undefined
|
|
168
|
+
? parseInt(frameNumberUnparsed)
|
|
169
|
+
: undefined;
|
|
170
|
+
const tileObject: Tile = {
|
|
171
|
+
index,
|
|
172
|
+
name,
|
|
173
|
+
frameNumber,
|
|
174
|
+
};
|
|
175
|
+
return tileObject;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const parseWangtile = (wangtile: xlmJs.ElementCompact): WangTile => {
|
|
179
|
+
const indexUnparsed = wangtile._attributes!.tileid!;
|
|
180
|
+
const index =
|
|
181
|
+
indexUnparsed !== undefined && typeof indexUnparsed === "string"
|
|
182
|
+
? parseInt(indexUnparsed)
|
|
183
|
+
: undefined;
|
|
184
|
+
if (index == undefined) {
|
|
185
|
+
dumpObjectAsError(wangtile);
|
|
186
|
+
throw new Error("Wangtile has no tileid!");
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const wangIdUnparsed = wangtile._attributes!.wangid!;
|
|
190
|
+
if ((wangIdUnparsed == undefined) || typeof wangIdUnparsed !== "string") {
|
|
191
|
+
dumpObjectAsError(wangtile);
|
|
192
|
+
throw new Error("Wangtile has no tileid!");
|
|
193
|
+
}
|
|
194
|
+
const binaryString = wangIdUnparsed.split(",").reverse().join("");
|
|
195
|
+
const wangId = parseInt(binaryString, 2);
|
|
196
|
+
return {
|
|
197
|
+
index,
|
|
198
|
+
wangId,
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const parseWangset = (wangset: xlmJs.ElementCompact): WangSet => {
|
|
203
|
+
const name = wangset._attributes!.name!;
|
|
204
|
+
if (!name || typeof name !== "string") {
|
|
205
|
+
dumpObjectAsError(wangset);
|
|
206
|
+
throw new Error("Wangset has no name!");
|
|
207
|
+
}
|
|
208
|
+
const wangtiles = wangset.wangtile;
|
|
209
|
+
const wangtileObjects = wangtiles.map(parseWangtile);
|
|
210
|
+
return {
|
|
211
|
+
name,
|
|
212
|
+
wangTiles: wangtileObjects,
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
const buildAnimatedTileList = (tileObjects: Tile[]) => {
|
|
217
|
+
const animatedTiles: AnimatedTile[] = [];
|
|
218
|
+
const tilesWithSameNameAndFrameNumber: { [key: string]: Tile[] } = {};
|
|
219
|
+
for (const tile of tileObjects) {
|
|
220
|
+
if (tile.name && tile.frameNumber !== undefined) {
|
|
221
|
+
if (tilesWithSameNameAndFrameNumber[tile.name]) {
|
|
222
|
+
tilesWithSameNameAndFrameNumber[tile.name].push(tile);
|
|
223
|
+
} else {
|
|
224
|
+
tilesWithSameNameAndFrameNumber[tile.name] = [tile];
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
for (const [k, v] of Object.entries(tilesWithSameNameAndFrameNumber)) {
|
|
229
|
+
animatedTiles.push({
|
|
230
|
+
frames: v
|
|
231
|
+
.sort((a, b) => a.frameNumber! - b.frameNumber!)
|
|
232
|
+
.map((t) => t.index),
|
|
233
|
+
name: k,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
return animatedTiles;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const tilemapObjects = tilemaps.map(processTilemap);
|
|
240
|
+
|
|
241
|
+
const TILEMAP_TYPE_TEMPLATE = `// GENERATED CODE - DO NOT MODIFY BY HAND
|
|
242
|
+
|
|
243
|
+
<% if(tiles){ -%>
|
|
244
|
+
export enum Tileset {
|
|
245
|
+
<% tiles.forEach(tile => { -%>
|
|
246
|
+
<%= tile.name %> = <%= tile.index %>,
|
|
247
|
+
<% }) -%>
|
|
248
|
+
}
|
|
249
|
+
<% } -%>
|
|
250
|
+
<% if(animatedTiles){ -%>
|
|
251
|
+
export enum TileAnimationKey {
|
|
252
|
+
<% animatedTiles.forEach(animatedTile => { -%>
|
|
253
|
+
<%= animatedTile.name %> = "<%= animatedTile.name %>",
|
|
254
|
+
<% }) -%>
|
|
255
|
+
}
|
|
256
|
+
export const TileAnimations: { [key in TileAnimationKey]: number[] } = {
|
|
257
|
+
<% animatedTiles.forEach(animatedTile => { -%>
|
|
258
|
+
[TileAnimationKey.<%= animatedTile.name %>]: [<%= animatedTile.frames.join(", ") %>],
|
|
259
|
+
<% }) -%>
|
|
260
|
+
};
|
|
261
|
+
<% } -%>
|
|
262
|
+
<% if(wangSets){ -%>
|
|
263
|
+
export enum WangSetKey {
|
|
264
|
+
<% wangSets.forEach(wangSet => { -%>
|
|
265
|
+
<%= wangSet.name %> = "<%= wangSet.name %>",
|
|
266
|
+
<% }) -%>
|
|
267
|
+
}
|
|
268
|
+
export const WangSets: { [key in WangSetKey]: { [key: number]: number } } = {
|
|
269
|
+
<% wangSets.forEach(wangSet => { -%>
|
|
270
|
+
[WangSetKey.<%= wangSet.name %>]: {
|
|
271
|
+
<% wangSet.wangTiles.forEach(wangTile => { -%>
|
|
272
|
+
<%= wangTile.wangId %>: <%= wangTile.index %>,
|
|
273
|
+
<% }) -%>
|
|
274
|
+
},
|
|
275
|
+
<% }) -%>
|
|
276
|
+
};
|
|
277
|
+
<% } -%>`;
|
|
278
|
+
|
|
279
|
+
const renderTilemapTypes = (tilemap: Tilemap) => {
|
|
280
|
+
return ejs.render(TILEMAP_TYPE_TEMPLATE, tilemap);
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
const tilemapTypes = tilemapObjects.map((t) => ({
|
|
284
|
+
type: renderTilemapTypes(t),
|
|
285
|
+
name: t.name,
|
|
286
|
+
}));
|
|
287
|
+
for (const tilemapType of tilemapTypes) {
|
|
288
|
+
fs.writeFileSync(
|
|
289
|
+
path.join(__dirname, "..", "..", "client", "src", "artTypes", `${tilemapType.name}.ts`),
|
|
290
|
+
tilemapType.type
|
|
291
|
+
);
|
|
292
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<tileset version="1.9" tiledversion="1.9.0" name="world" tilewidth="32" tileheight="32" tilecount="3" columns="3">
|
|
3
|
+
<image source="images/world.png" width="96" height="32"/>
|
|
4
|
+
<tile id="0">
|
|
5
|
+
<properties>
|
|
6
|
+
<property name="name" value="Grass"/>
|
|
7
|
+
</properties>
|
|
8
|
+
</tile>
|
|
9
|
+
<tile id="1">
|
|
10
|
+
<properties>
|
|
11
|
+
<property name="name" value="Mountain"/>
|
|
12
|
+
</properties>
|
|
13
|
+
</tile>
|
|
14
|
+
<tile id="2">
|
|
15
|
+
<properties>
|
|
16
|
+
<property name="name" value="Forest"/>
|
|
17
|
+
</properties>
|
|
18
|
+
</tile>
|
|
19
|
+
</tileset>
|