This commit is contained in:
Dennis Postma 2024-07-01 18:05:43 +02:00
parent cb24433582
commit fc72c83f8d
2 changed files with 16 additions and 26 deletions

View File

@ -55,23 +55,22 @@ let tilesetImages: Tileset[] = [];
/** /**
* Walk through tiles and add them to the zone as tilesetImages * Walk through tiles and add them to the zone as tilesetImages
*/ */
let tileCount = 1;
toRaw(assetStore.assets).forEach((asset) => { toRaw(assetStore.assets).forEach((asset) => {
if (asset.group !== 'tiles') { if (asset.group !== 'tiles') return
return tilesetImages.push(zone.addTilesetImage(asset.key, asset.key, config.tile_size.x, config.tile_size.y, 0, 0, tileCount++) as Tileset)
}
console.log(asset)
// tilesetImages.push(zone.addTilesetImage(asset.key) as Tileset)
}) })
/** const tiles = zone.createBlankLayer('tiles', tilesetImages, 0, config.tile_size.y) as TilemapLayer
* @TODO BUG : in the map. somehow always the latest tileset is used instead of the correct one. const exampleTilesArray = Array.from({ length: zoneEditorStore.width }, () => Array.from({ length: zoneEditorStore.height }, () => 0))
*/
const t1 = zone.addTilesetImage('tile_1.png') as Tileset
const t2 = zone.addTilesetImage('tile_2.png') as Tileset
const t3 = zone.addTilesetImage('tile_3.png') as Tileset
const tiles = zone.createBlankLayer('tiles', [t1,t2,t3], 0, config.tile_size.y) as TilemapLayer function placeTile(layer: TilemapLayer, x: number, y: number, tileName: string) {
const exampleTilesArray = Array.from({ length: zoneEditorStore.width }, () => Array.from({ length: zoneEditorStore.height }, () => 'tile_0.png')) let tileImg = zone.getTileset(tileName) as Tileset;
if (!tileImg) return
layer.putTileAt(tileImg.firstgid, x, y);
}
placeTile(tiles, 0, 0, 'tile_0.png')
onMounted(() => {}) onMounted(() => {})
const pos = tileToWorldXY(tiles, 1, 1) const pos = tileToWorldXY(tiles, 1, 1)
@ -79,15 +78,6 @@ const pos2 = tileToWorldXY(tiles, 1, 2)
const pos3 = tileToWorldXY(tiles, 2, 1) const pos3 = tileToWorldXY(tiles, 2, 1)
console.log(pos) console.log(pos)
function placeTile(layer: TilemapLayer, x: number, y: number, tileType: string) {
let tilesett = zone.getTileset(tileType) as Tileset;
if (!tilesett) return
console.log(tilesett)
layer.putTileAt(tilesett.firstgid, x, y);
}
placeTile(tiles, 0, 0, 'tile_1.png')
// Watch for changes in the zoneStore and update the layer // Watch for changes in the zoneStore and update the layer
// watch( // watch(
// () => zoneEditorStore.tiles, // () => zoneEditorStore.tiles,
@ -107,7 +97,7 @@ placeTile(tiles, 0, 0, 'tile_1.png')
function eraser(tile: Phaser.Tilemaps.Tile) { function eraser(tile: Phaser.Tilemaps.Tile) {
if (zoneEditorStore.drawMode === 'tile') { if (zoneEditorStore.drawMode === 'tile') {
tiles.putTileAt(0, tile.x, tile.y) placeTile(tiles, tile.x, tile.y, 'tile_0.png')
zoneEditorStore.updateTile(tile.x, tile.y, 0) zoneEditorStore.updateTile(tile.x, tile.y, 0)
} }
@ -120,8 +110,8 @@ function eraser(tile: Phaser.Tilemaps.Tile) {
function pencil(tile: Phaser.Tilemaps.Tile) { function pencil(tile: Phaser.Tilemaps.Tile) {
if (zoneEditorStore.drawMode === 'tile') { if (zoneEditorStore.drawMode === 'tile') {
if (zoneEditorStore.selectedTile === null) return if (zoneEditorStore.selectedTile === null) return
tiles.putTileAt(zoneEditorStore.selectedTile, tile.x, tile.y) placeTile(tiles, tile.x, tile.y, zoneEditorStore.selectedTile)
zoneEditorStore.setTiles(tile.x, tile.y, zoneEditorStore.selectedTile) // zoneEditorStore.setTiles(tile.x, tile.y, zoneEditorStore.selectedTile)
} }
if (zoneEditorStore.drawMode === 'wall') { if (zoneEditorStore.drawMode === 'wall') {

View File

@ -50,7 +50,7 @@ onMounted(async () => {
/** /**
* Fetch assets from the server * Fetch assets from the server
*/ */
assetStore.fetchAssets(); await assetStore.fetchAssets();
const response = await login('ethereal', 'kanker123') const response = await login('ethereal', 'kanker123')