refactor: use defaults

This commit is contained in:
cha0s 2022-03-22 17:46:23 -05:00
parent d8035a391d
commit 2af3829860
2 changed files with 5 additions and 220 deletions

View File

@ -1,153 +1,9 @@
const defaultJson = (name) => ({
traits: {
Alive: {
state: {
life: 200,
maxLife: 200,
},
},
Animated: {
params: {
animations: {
idle: {
offset: [0, -12],
extends: '/player/idle.animation.json',
},
moving: {
offset: [0, -12],
extends: '/player/moving.animation.json',
},
},
},
},
Collider: {
params: {
activeCollision: true,
},
},
Controllable: {
params: {
actions: {
HotbarSlot0: [
{type: 'key', index: '1'},
],
HotbarSlot1: [
{type: 'key', index: '2'},
],
HotbarSlot2: [
{type: 'key', index: '3'},
],
HotbarSlot3: [
{type: 'key', index: '4'},
],
HotbarSlot4: [
{type: 'key', index: '5'},
],
HotbarSlot5: [
{type: 'key', index: '6'},
],
HotbarSlot6: [
{type: 'key', index: '7'},
],
HotbarSlot7: [
{type: 'key', index: '8'},
],
HotbarSlot8: [
{type: 'key', index: '9'},
],
HotbarSlot9: [
{type: 'key', index: '0'},
],
HotbarSlotNext: [
{type: 'button', index: 7},
{type: 'wheel', index: 'down'},
],
HotbarSlotPrevious: [
{type: 'button', index: 6},
{type: 'wheel', index: 'up'},
],
MoveUp: [
{type: 'joystick', index: 1, axis: -1},
{type: 'joystick', index: 7, axis: -1},
{type: 'key', index: 'w'},
],
MoveLeft: [
{type: 'joystick', index: 0, axis: -1},
{type: 'joystick', index: 6, axis: -1},
{type: 'key', index: 'a'},
],
MoveDown: [
{type: 'joystick', index: 1, axis: 1},
{type: 'joystick', index: 7, axis: 1},
{type: 'key', index: 's'},
],
MoveRight: [
{type: 'joystick', index: 0, axis: 1},
{type: 'joystick', index: 6, axis: 1},
{type: 'key', index: 'd'},
],
UseItem: [
{type: 'joystick', index: 4, axis: 1},
{type: 'button', index: 0},
{type: 'key', index: 'ArrowLeft'},
],
Interact: [
{type: 'button', index: 1},
{type: 'key', index: 'ArrowDown'},
],
},
},
},
Directional: {
params: {
directionCount: 4,
},
},
Informed: {},
Magnetic: {
params: {
isAttractor: true,
},
state: {
attraction: 20,
},
},
Mobile: {
state: {
speed: 85,
},
},
Named: {
state: {
name,
},
},
Physical: {},
Positioned: {},
Receptacle: {},
Shaped: {
params: {
shape: {
type: 'circle',
radius: 4,
},
},
},
Universed: {},
Vulnerable: {
params: {
harmedAs: [
'good',
],
},
},
Wielder: {},
},
});
const createPlayerEntity = async (flecks, name) => {
const {Entity} = flecks.get('$avocado/resource.resources');
const entity = await Entity.load(defaultJson(name));
const entity = await Entity.load({
extends: '/player/index.entity.json',
traits: {Named: {state: {name}}},
});
flecks.invoke('@humus/universe.player.entity', entity);
return entity;
};

View File

@ -1,77 +1,6 @@
const defaultJson = () => ({
entities: [
{
extends: '/npc/legit-dude.entity.json',
traits: {
Positioned: {
state: {
x: 49,
y: 37,
},
},
Named: {
state: {
name: 'Sups',
},
},
},
},
{
extends: '/npc/legit-dude.entity.json',
traits: {
Positioned: {
state: {
x: 134,
y: 142,
},
},
Directional: {
params: {
directionCount: 4,
trackMovement: true,
},
state: {
direction: 2,
},
},
},
},
],
evaporation: 64,
size: [
384,
384,
],
tiles: [
{
data: 'eNpjY2AbhaNwFI7CAYEAc8INgQ==',
area: [
24,
24,
],
tileImageUri: '/tileset.png',
tileSize: [
16,
16,
],
},
{
area: [
24,
24,
],
tileImageUri: '/tileset.png',
tileSize: [
16,
16,
],
},
],
});
const createPlayerRoom = async (flecks) => {
const {Room} = flecks.get('$avocado/resource.resources');
const room = await Room.load(defaultJson());
const room = await Room.load({extends: '/player/index.room.json'});
flecks.invoke('@humus/universe.player.room', room);
return room;
};