Skip to content

Commit

Permalink
rev to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Jan 6, 2024
1 parent 4427499 commit bd7f6c5
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 69 deletions.
89 changes: 58 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"license": "BSD-2-Clause",
"dependencies": {
"@excaliburjs/dev-tools": "0.28.0",
"@excaliburjs/plugin-tiled": "0.28.0",
"excalibur": "0.28.1"
"@excaliburjs/plugin-tiled": "0.29.0-alpha.1",
"excalibur": "0.28.5"
},
"devDependencies": {
"typescript": "5.2.2",
Expand Down
5 changes: 3 additions & 2 deletions res/first-level.tmx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.1" orientation="orthogonal" renderorder="right-down" width="10" height="10" tilewidth="16" tileheight="16" infinite="0" nextlayerid="4" nextobjectid="5">
<map version="1.10" tiledversion="1.10.2" orientation="orthogonal" renderorder="right-down" width="10" height="10" tilewidth="16" tileheight="16" infinite="0" nextlayerid="4" nextobjectid="5">
<tileset firstgid="1" source="tileset.tsx"/>
<layer id="1" name="Ground" width="10" height="10">
<data encoding="csv">
Expand Down Expand Up @@ -43,11 +43,12 @@
</object>
<object id="2" name="Camera" type="Camera" x="80.0299" y="72.2658">
<properties>
<property name="camera" type="bool" value="true"/>
<property name="zoom" type="float" value="4"/>
</properties>
<point/>
</object>
<object id="3" name="Player" x="37.0287" y="27.4729">
<object id="3" name="Player" type="player" x="37.0287" y="27.4729">
<point/>
</object>
</objectgroup>
Expand Down
15 changes: 1 addition & 14 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,5 @@ const game = new ex.Engine({
});

game.start(loader).then(() => {
const objects = Resources.TiledMap.data.getObjectLayerByName("Objects");
const camera = objects.getObjectByName("Camera");
if (camera) {
game.currentScene.camera.pos = ex.vec(camera.x, camera.y);
game.currentScene.camera.zoom = camera.getProperty<number>('zoom')?.value ?? 1.0;
}

const player = objects.getObjectByName("Player");
if (player) {
const playerActor = new Player(ex.vec(player.x, player.y));
game.currentScene.add(playerActor);
playerActor.z = 100;
}
Resources.TiledMap.addTiledMapToScene(game.currentScene);
Resources.TiledMap.addToScene(game.currentScene);
});
38 changes: 18 additions & 20 deletions src/resources.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
import { ImageFiltering, ImageSource, Loadable, Loader, Resource, TileMap } from "excalibur";
import { TiledMapResource } from '@excaliburjs/plugin-tiled';
import { TiledResource } from '@excaliburjs/plugin-tiled';

// Import paths to work with Vite
// Note the ?url suffix
import heroPath from '../img/Solaria Demo Pack Update 03/Solaria Demo Pack Update 03/16x16/Sprites/Hero 01.png?url';
import tilesetPath from '../img/Solaria Demo Pack Update 03/Solaria Demo Pack Update 03/16x16/Tilesets/Solaria Demo Update 01.png?url';
import tmxPath from '../res/first-level.tmx?url';
import tsxPath from '../res/tileset.tsx?url';
import tssxPath from '../res/tileset.tssx?url';
import { Player } from "./player";

export const Resources = {
HeroSpriteSheetPng: new ImageSource(heroPath, false, ImageFiltering.Pixel),
TiledMap: new TiledMapResource(tmxPath),
TsxResource: new Resource(tsxPath, 'text'),
TssxResource: new Resource(tssxPath, 'text')
}

// Patch @excalibur/plugin-tile path resolution to work around Vite
const convertPath = Resources.TiledMap.convertPath;
Resources.TiledMap.convertPath = (originalPath, relativePath) => {
if (relativePath.includes('.tmx')) {
return tmxPath;
}
if (relativePath.includes('.tsx')) {
return tsxPath;
}
if (relativePath.includes('.png')) {
return tilesetPath;
}
return convertPath(originalPath, relativePath);
TiledMap: new TiledResource(tmxPath, {
entityClassNameFactories: {
player: (props) => {
const player = new Player(props.worldPos);
player.z = 100;
return player;
}
},
// Path map intercepts and redirects to work around vite's static bundling
pathMap: [
{ path: 'first-level.tmx', output: tmxPath },
{ path: 'Solaria Demo Update 01.png', output: tilesetPath },
{ path: 'tileset.tsx', output: tsxPath }
]
}),
TsxResource: new Resource(tsxPath, 'text')
}

export const loader = new Loader();
Expand Down

0 comments on commit bd7f6c5

Please sign in to comment.