refactor: resource types

This commit is contained in:
cha0s 2024-10-19 08:40:35 -05:00
parent a8d32e2b01
commit 6a6be49a61
38 changed files with 52 additions and 66 deletions

View File

@ -18,7 +18,7 @@ const TileLayerInternal = PixiComponent('TileLayer', {
},
applyProps: (container, {tileLayer: oldTileLayer}, props) => {
const {asset, group, renderer, tileLayer} = props;
const extless = tileLayer.source.slice('/resources/'.length, -'.json'.length);
const extless = tileLayer.source.slice('/resources/'.length, -'.sprite.json'.length);
const {textures} = asset;
if (tileLayer === oldTileLayer) {
return;

View File

@ -118,7 +118,7 @@ function Gen() {
Math.ceil(area.x / CHUNK_SIZE) * Math.ceil(area.y / CHUNK_SIZE)
).fill(0).map(() => ({})),
data: Array(area.x * area.y).fill(1),
source: '/resources/tileset.json',
source: '/resources/tileset.sprite.json',
tileSize: {x: 16, y: 16},
};
const tileGenerator = new Generator({

View File

@ -63,13 +63,13 @@ export default function createForest() {
{
area,
data: Array(w * h).fill(0),
source: '/resources/tileset.json',
source: '/resources/tileset.sprite.json',
tileSize: {x: 16, y: 16},
},
{
area,
data: Array(w * h).fill(0),
source: '/resources/tileset.json',
source: '/resources/tileset.sprite.json',
tileSize: {x: 16, y: 16},
},
],
@ -113,7 +113,7 @@ export default function createForest() {
Position: entityPosition(x, y),
Sprite: {
anchorY: 0.7,
source: '/resources/ambient/shrub.json',
source: '/resources/ambient/shrub.sprite.json',
},
VisibleAabb: {},
});
@ -123,7 +123,7 @@ export default function createForest() {
Position: entityPosition(x, y),
Sprite: {
anchorY: 0.875,
source: '/resources/ambient/tree.json',
source: '/resources/ambient/tree.sprite.json',
},
VisibleAabb: {},
});
@ -134,7 +134,7 @@ export default function createForest() {
Position: entityPosition(x, y),
Sprite: {
anchorY: 0.7,
source: '/resources/ambient/flower.json',
source: '/resources/ambient/flower.sprite.json',
},
VisibleAabb: {},
});

View File

@ -32,13 +32,13 @@ function createMaster() {
{
area,
data,
source: '/resources/tileset.json',
source: '/resources/tileset.sprite.json',
tileSize: {x: 16, y: 16},
},
{
area,
data: Array(area.x * area.y).fill(0),
source: '/resources/tileset.json',
source: '/resources/tileset.sprite.json',
tileSize: {x: 16, y: 16},
},
],
@ -67,7 +67,7 @@ function createShitShack() {
Sprite: {
anchorX: 0.5,
anchorY: 0.8,
source: '/resources/shit-shack/shit-shack.json',
source: '/resources/shit-shack/shit-shack.sprite.json',
},
Ticking: {},
VisibleAabb: {},
@ -118,19 +118,19 @@ function createChest() {
slots: {
2: {
qty: 1,
source: '/resources/watering-can/watering-can.json',
source: '/resources/watering-can/watering-can.item.json',
},
3: {
qty: 1,
source: '/resources/tomato-seeds/tomato-seeds.json',
source: '/resources/tomato-seeds/tomato-seeds.item.json',
},
4: {
qty: 1,
source: '/resources/hoe/hoe.json',
source: '/resources/hoe/hoe.item.json',
},
5: {
qty: 1,
source: '/resources/brush/brush.json',
source: '/resources/brush/brush.item.json',
},
},
},
@ -139,7 +139,7 @@ function createChest() {
Sprite: {
anchorX: 0.5,
anchorY: 0.7,
source: '/resources/chest/chest.json',
source: '/resources/chest/chest.sprite.json',
},
Ticking: {},
VisibleAabb: {},
@ -173,7 +173,7 @@ function createTomato() {
anchorY: 0.5,
scaleX: 0.333,
scaleY: 0.333,
source: '/resources/tomato/tomato-sprite.json',
source: '/resources/tomato/tomato.sprite.json',
},
Ticking: {},
VisibleAabb: {},
@ -213,7 +213,7 @@ function createTestKitten() {
...animalJson.Sprite,
anchorX: 0.5,
anchorY: 0.7,
source: '/resources/kitty/kitty.json',
source: '/resources/kitty/kitty.sprite.json',
speed: 0.115,
},
Tags: {tags: ['kittan']},
@ -253,7 +253,7 @@ function createTestCow() {
...animalJson.Sprite,
anchorX: 0.5,
anchorY: 0.8,
source: '/resources/farm/animals/cow-adult/cow-adult.json',
source: '/resources/farm/animals/cow-adult/cow-adult.sprite.json',
speed: 0.25,
},
};
@ -292,7 +292,7 @@ function createTestGoat() {
...animalJson.Sprite,
anchorX: 0.5,
anchorY: 0.8,
source: '/resources/farm/animals/goat-white/goat-white.json',
source: '/resources/farm/animals/goat-white/goat-white.sprite.json',
speed: 0.25,
},
};
@ -349,7 +349,7 @@ function createTomatoPlant() {
Sprite: {
anchorY: 0.75,
animation: 'stage/0',
source: '/resources/tomato-plant/tomato-plant.json',
source: '/resources/tomato-plant/tomato-plant.sprite.json',
zIndex: 0,
},
Ticking: {},

View File

@ -11,7 +11,7 @@ export default function createHouse(Ecs, id) {
{
area,
data: Array(area.x * area.y).fill(0).map(() => 5 + Math.floor(Math.random() * 2)),
source: '/resources/tileset.json',
source: '/resources/tileset.sprite.json',
tileSize: {x: 16, y: 16},
}
],

View File

@ -25,31 +25,31 @@ export default function createPlayer(id) {
slots: {
1: {
qty: 100,
source: '/resources/potion/potion.json',
source: '/resources/potion/potion.item.json',
},
2: {
qty: 1,
source: '/resources/magic-swords/magic-swords.json',
source: '/resources/magic-swords/magic-swords.item.json',
},
3: {
qty: 1,
source: '/resources/watering-can/watering-can.json',
source: '/resources/watering-can/watering-can.item.json',
},
4: {
qty: 1,
source: '/resources/tomato-seeds/tomato-seeds.json',
source: '/resources/tomato-seeds/tomato-seeds.item.json',
},
5: {
qty: 1,
source: '/resources/hoe/hoe.json',
source: '/resources/hoe/hoe.item.json',
},
6: {
qty: 95,
source: '/resources/potion/potion.json',
source: '/resources/potion/potion.item.json',
},
7: {
qty: 95,
source: '/resources/potion/potion.json',
source: '/resources/potion/potion.item.json',
},
},
},
@ -65,7 +65,7 @@ export default function createPlayer(id) {
anchorY: 0.9,
animation: 'moving:down',
frame: 0,
source: '/resources/dude/dude.json',
source: '/resources/dude/dude.sprite.json',
speed: 0.115,
},
Ticking: {},

View File

@ -11,13 +11,13 @@ export default function createTown() {
{
area,
data,
source: '/resources/tileset.json',
source: '/resources/tileset.sprite.json',
tileSize: {x: 16, y: 16},
},
{
area,
data: Array(area.x * area.y).fill(0),
source: '/resources/tileset.json',
source: '/resources/tileset.sprite.json',
tileSize: {x: 16, y: 16},
},
],

View File

@ -17,7 +17,7 @@ export default function*({wielder}) {
}
Inventory.give({
qty: 1,
source: '/resources/furball/furball.json',
source: '/resources/furball/furball.item.json',
});
Controlled.locked = 0;

View File

@ -2,21 +2,14 @@ import * as Math from '@/util/math.js';
import Ticker from '@/util/ticker.js';
export default function*({entity}) {
entity.Direction.direction = Math.random() * Math.TAU;
entity.Controlled.directionMove(entity.Direction.direction);
const {Controlled, Direction, Sprite} = entity;
Direction.direction = Math.random() * Math.TAU;
Controlled.directionMove(Direction.direction);
yield Ticker.wait(0.25 + Math.random() * 2.25);
entity.Controlled.stop();
entity.Sprite.isAnimating = 0;
Controlled.stop();
Sprite.isAnimating = 0;
yield Ticker.wait(1 + Math.random() * 3);
entity.Direction.direction = Math.random() * Math.TAU;
Direction.direction = Math.random() * Math.TAU;
yield Ticker.wait(0.5 + Math.random() * 2.5);
entity.Sprite.isAnimating = 1;
}
Sprite.isAnimating = 1;
}

View File

@ -2,21 +2,14 @@ import * as Math from '@/util/math.js';
import Ticker from '@/util/ticker.js';
export default function*({entity}) {
entity.Direction.direction = Math.random() * Math.TAU;
entity.Controlled.directionMove(entity.Direction.direction);
const {Controlled, Direction, Sprite} = entity;
Direction.direction = Math.random() * Math.TAU;
Controlled.directionMove(Direction.direction);
yield Ticker.wait(0.25 + Math.random() * 2.25);
entity.Controlled.stop();
entity.Sprite.isAnimating = 0;
Controlled.stop();
Sprite.isAnimating = 0;
yield Ticker.wait(1 + Math.random() * 3);
entity.Direction.direction = Math.random() * Math.TAU;
Direction.direction = Math.random() * Math.TAU;
yield Ticker.wait(0.5 + Math.random() * 2.5);
entity.Sprite.isAnimating = 1;
}
Sprite.isAnimating = 1;
}

View File

@ -42,7 +42,7 @@ function createShots(where, wielder) {
Position: {x: Position.x, y: Position.y},
Speed: {},
Sprite: {
source: '/resources/magic-swords/magic-sword-shot.json',
source: '/resources/magic-swords/magic-sword-shot.sprite.json',
},
Ticking: {},
VisibleAabb: {},

View File

@ -31,7 +31,7 @@ export default function*({ecs, subject}) {
anchorY: 0.5,
scaleX: 0.333,
scaleY: 0.333,
source: '/resources/tomato/tomato-sprite.json',
source: '/resources/tomato/tomato.sprite.json',
},
Ticking: {},
VisibleAabb: {},

View File

@ -36,7 +36,7 @@ export default function*({ecs, wielder}) {
Sprite: {
anchorY: 0.75,
animation: 'stage/0',
source: '/resources/tomato-plant/tomato-plant.json',
source: '/resources/tomato-plant/tomato-plant.sprite.json',
zIndex: 0,
},
Ticking: {},

View File

@ -2,7 +2,7 @@ export default function*({ecs, entity, other}) {
if (other.Inventory) {
other.Inventory.give({
qty: 1,
source: '/resources/tomato/tomato.json',
source: '/resources/tomato/tomato.item.json',
})
ecs.destroy(entity.id);
}