refactor: entity json

This commit is contained in:
cha0s 2024-10-19 10:56:57 -05:00
parent 2fe09d3cb2
commit 6e8f74b369
2 changed files with 51 additions and 33 deletions

View File

@ -0,0 +1,47 @@
{
"Behaving": {
"routines": {
"initial": "/resources/magic-swords/initial.js"
}
},
"Collider": {
"bodies": [
{
"group": -1,
"points": [
{
"x": -2.5,
"y": -2.5
},
{
"x": 14,
"y": -2.5
},
{
"x": 14,
"y": 2.5
},
{
"x": -2.5,
"y": 2.5
}
],
"unstoppable": 1
}
]
},
"Controlled": {},
"Forces": {},
"Harmful": {
"harmScript": "/resources/magic-swords/harm.js"
},
"Light": {
"brightness": 0
},
"Speed": {},
"Sprite": {
"source": "/resources/magic-swords/magic-sword-shot.sprite.json"
},
"Ticking": {},
"VisibleAabb": {}
}

View File

@ -3,56 +3,27 @@ import Ticker from '@/util/ticker.js';
const SHOTS = 14;
function createShots(where, wielder) {
function createShots(ecs, where, wielder) {
const offset = Math.random() * Math.TAU;
const {Player, Position} = wielder;
const json = ecs.readJson('/resources/magic-swords/shot.entity.json');
const shots = [];
for (let i = 0; i < SHOTS; ++i) {
shots.push({
...json,
Arbitrary: {
blob: JSON.stringify({where}),
},
Behaving: {
routines: {
initial: '/resources/magic-swords/initial.js',
},
},
Collider: {
bodies: [
{
group: -1,
points: [
{x: -2.5, y: -2.5},
{x: 14, y: -2.5},
{x: 14, y: 2.5},
{x: -2.5, y: 2.5},
],
unstoppable: 1,
},
],
},
Controlled: {},
Direction: {direction: offset + Math.TAU * (i / SHOTS)},
Forces: {},
Harmful: {
harmScript: '/resources/magic-swords/harm.js',
},
Light: {brightness: 0},
Owned: {owner: Player ? Player.id : 0},
Position: {x: Position.x, y: Position.y},
Speed: {},
Sprite: {
source: '/resources/magic-swords/magic-sword-shot.sprite.json',
},
Ticking: {},
VisibleAabb: {},
});
}
return shots;
}
export default function*({ecs, where, wielder}) {
const shots = createShots(where, wielder);
const shots = createShots(ecs, where, wielder);
do {
ecs.create(shots.shift());
yield Ticker.wait(0.03);