From ffa391fcefb882135b346c986bd22abb1c2363aa Mon Sep 17 00:00:00 2001 From: cha0s Date: Sat, 28 Sep 2024 07:56:12 -0500 Subject: [PATCH] refactor: creation --- app/server/create/homestead.js | 437 +++++++++++++++++++++------------ app/server/create/player.js | 12 + 2 files changed, 289 insertions(+), 160 deletions(-) diff --git a/app/server/create/homestead.js b/app/server/create/homestead.js index 28befba..7a6a24d 100644 --- a/app/server/create/homestead.js +++ b/app/server/create/homestead.js @@ -22,10 +22,9 @@ function animal() { }; } -export default async function createHomestead(id) { +function createMaster() { const area = {x: 100, y: 60}; - const entities = []; - entities.push({ + return { AreaSize: {x: area.x * 16, y: area.y * 16}, Ticking: {}, TileLayers: { @@ -46,8 +45,11 @@ export default async function createHomestead(id) { }, Time: {}, Water: {water: {}}, - }); - entities.push({ + }; +} + +function createShitShack(id) { + return { Collider: { bodies: [ { @@ -72,8 +74,11 @@ export default async function createHomestead(id) { }, Ticking: {}, VisibleAabb: {}, - }); - entities.push({ + }; +} + +function createHouseTeleport(id) { + return { Collider: { bodies: [ { @@ -102,8 +107,11 @@ export default async function createHomestead(id) { }, Position: {x: 71, y: 113}, Ticking: {}, - }); - entities.push({ + }; +} + +function createChest() { + return { Collider: { bodies: [ { @@ -160,162 +168,212 @@ export default async function createHomestead(id) { }, Ticking: {}, VisibleAabb: {}, - }); + }; +} + +function createTomato() { + return { + Collider: { + bodies: [ + { + points: [ + {x: -4, y: -4}, + {x: 3, y: -4}, + {x: 3, y: 3}, + {x: -4, y: 3}, + ], + }, + ], + collisionStartScript: [ + 'if (other.Inventory) {', + ' other.Inventory.give({', + ' qty: 1,', + " source: '/resources/tomato/tomato.json',", + ' })', + ' ecs.destroy(entity.id)', + ' undefined;', + '}', + ].join('\n'), + }, + Forces: {}, + Magnetic: {}, + Position: { + x: 168 + Math.random() * 30, + y: 448 + Math.random() * 30, + }, + Sprite: { + anchorX: 0.5, + anchorY: 0.5, + scaleX: 0.333, + scaleY: 0.333, + source: '/resources/tomato/tomato-sprite.json', + }, + Ticking: {}, + VisibleAabb: {}, + }; +} + +function createTestKitten() { const animalJson = animal(); - for (let i = 0; i < 10; ++i) { - entities.push({ - ...animalJson, - Behaving: { - routines: { - initial: '/resources/kitty/initial.js', + return { + ...animalJson, + Behaving: { + routines: { + initial: '/resources/kitty/initial.js', + }, + }, + Collider: { + bodies: [ + { + points: [ + {x: -3.5, y: -3.5}, + {x: 3.5, y: -3.5}, + {x: 3.5, y: 3.5}, + {x: -3.5, y: 3.5}, + ], }, + ], + }, + Interactive: { + interacting: 1, + interactScript: ` + const lines = [ + 'mrowwr', + 'prrrowwwww', + 'mew mew!', + 'mewwwww', + '\\\\*purrrrr\\\\*', + ]; + const line = lines[Math.floor(Math.random() * lines.length)]; + subject.Interlocutor.dialogue({ + body: line, + linger: 2, + offset: {x: 0, y: -16}, + origin: 'track', + position: 'track', + }) + `, + }, + Position: { + x: 250 + (Math.random() - 0.5) * 300, + y: 250 + (Math.random() - 0.5) * 300, + }, + Sprite: { + ...animalJson.Sprite, + anchorX: 0.5, + anchorY: 0.7, + source: '/resources/kitty/kitty.json', + speed: 0.115, + }, + Tags: {tags: ['kittan']}, + }; +} + +function createTestCow() { + const animalJson = animal(); + return { + ...animalJson, + Behaving: { + routines: { + initial: '/resources/farm/animals/cow-adult/initial.js', }, - Collider: { - bodies: [ - { - points: [ - {x: -3.5, y: -3.5}, - {x: 3.5, y: -3.5}, - {x: 3.5, y: 3.5}, - {x: -3.5, y: 3.5}, - ], - }, - ], - }, - Interactive: { - interacting: 1, - interactScript: ` - const lines = [ - 'mrowwr', - 'prrrowwwww', - 'mew mew!', - 'mewwwww', - '\\\\*purrrrr\\\\*', - ]; - const line = lines[Math.floor(Math.random() * lines.length)]; - subject.Interlocutor.dialogue({ - body: line, - linger: 2, - offset: {x: 0, y: -16}, - origin: 'track', - position: 'track', - }) - `, - }, - Position: { - x: 250 + (Math.random() - 0.5) * 300, - y: 250 + (Math.random() - 0.5) * 300, - }, - Sprite: { - ...animalJson.Sprite, - anchorX: 0.5, - anchorY: 0.7, - source: '/resources/kitty/kitty.json', - speed: 0.115, - }, - Tags: {tags: ['kittan']}, - }); - } - for (let i = 0; i < 10; ++i) { - entities.push({ - ...animalJson, - Behaving: { - routines: { - initial: '/resources/farm/animals/cow-adult/initial.js', + }, + Collider: { + bodies: [ + { + points: [ + {x: -3.5, y: -3.5}, + {x: 3.5, y: -3.5}, + {x: 3.5, y: 3.5}, + {x: -3.5, y: 3.5}, + ], }, + ], + }, + Interactive: { + interacting: 1, + interactScript: ` + const lines = [ + 'snorrt', + 'mooooooooooo', + ]; + const line = lines[Math.floor(Math.random() * lines.length)]; + subject.Interlocutor.dialogue({ + body: line, + linger: 2, + offset: {x: 0, y: -16}, + origin: 'track', + position: 'track', + }) + `, + }, + Position: { + x: 350 + (Math.random() - 0.5) * 300, + y: 350 + (Math.random() - 0.5) * 300, + }, + Sprite: { + ...animalJson.Sprite, + anchorX: 0.5, + anchorY: 0.8, + source: '/resources/farm/animals/cow-adult/cow-adult.json', + speed: 0.25, + }, + }; +} + +function createTestGoat() { + const animalJson = animal(); + return { + ...animalJson, + Behaving: { + routines: { + initial: '/resources/farm/animals/goat-white/initial.js', }, - Collider: { - bodies: [ - { - points: [ - {x: -3.5, y: -3.5}, - {x: 3.5, y: -3.5}, - {x: 3.5, y: 3.5}, - {x: -3.5, y: 3.5}, - ], - }, - ], - }, - Interactive: { - interacting: 1, - interactScript: ` - const lines = [ - 'snorrt', - 'mooooooooooo', - ]; - const line = lines[Math.floor(Math.random() * lines.length)]; - subject.Interlocutor.dialogue({ - body: line, - linger: 2, - offset: {x: 0, y: -16}, - origin: 'track', - position: 'track', - }) - `, - }, - Position: { - x: 350 + (Math.random() - 0.5) * 300, - y: 350 + (Math.random() - 0.5) * 300, - }, - Sprite: { - ...animalJson.Sprite, - anchorX: 0.5, - anchorY: 0.8, - source: '/resources/farm/animals/cow-adult/cow-adult.json', - speed: 0.25, - }, - }); - } - for (let i = 0; i < 10; ++i) { - entities.push({ - ...animalJson, - Behaving: { - routines: { - initial: '/resources/farm/animals/goat-white/initial.js', + }, + Collider: { + bodies: [ + { + points: [ + {x: -7, y: -3.5}, + {x: 7, y: -3.5}, + {x: 7, y: 3.5}, + {x: -7, y: 3.5}, + ], }, - }, - Collider: { - bodies: [ - { - points: [ - {x: -7, y: -3.5}, - {x: 7, y: -3.5}, - {x: 7, y: 3.5}, - {x: -7, y: 3.5}, - ], - }, - ], - }, - Interactive: { - interacting: 1, - interactScript: ` - const lines = [ - 'Mind your own business, buddy.\\n\\ner, I mean, MEEHHHHHH', - ]; - const line = lines[Math.floor(Math.random() * lines.length)]; - subject.Interlocutor.dialogue({ - body: line, - linger: 2, - offset: {x: 0, y: -16}, - origin: 'track', - position: 'track', - }) - `, - }, - Position: { - x: 350 + (Math.random() - 0.5) * 300, - y: 150 + (Math.random() - 0.5) * 300, - }, - Sprite: { - ...animalJson.Sprite, - anchorX: 0.5, - anchorY: 0.8, - source: '/resources/farm/animals/goat-white/goat-white.json', - speed: 0.25, - }, - }); - } - entities.push({ + ], + }, + Interactive: { + interacting: 1, + interactScript: ` + const lines = [ + 'Mind your own business, buddy.\\n\\ner, I mean, MEEHHHHHH', + ]; + const line = lines[Math.floor(Math.random() * lines.length)]; + subject.Interlocutor.dialogue({ + body: line, + linger: 2, + offset: {x: 0, y: -16}, + origin: 'track', + position: 'track', + }) + `, + }, + Position: { + x: 350 + (Math.random() - 0.5) * 300, + y: 150 + (Math.random() - 0.5) * 300, + }, + Sprite: { + ...animalJson.Sprite, + anchorX: 0.5, + anchorY: 0.8, + source: '/resources/farm/animals/goat-white/goat-white.json', + speed: 0.25, + }, + }; +} + +function createTownTeleport() { + return { Collider: { bodies: [ { @@ -345,6 +403,65 @@ export default async function createHomestead(id) { Position: {x: 8, y: 432}, Ticking: {}, - }); + }; +} + +function createTomatoPlant() { + return { + Collider: { + bodies: [ + { + points: [ + {x: -8, y: -8}, + {x: 7, y: -8}, + {x: -8, y: 7}, + {x: 7, y: 7}, + ], + }, + ], + }, + Interactive: { + interactScript: '/resources/tomato-plant/interact.js', + }, + Plant: { + growScript: '/resources/tomato-plant/grow.js', + growthFactor: Math.floor(Math.random() * 256), + mayGrowScript: '/resources/tomato-plant/may-grow.js', + stages: [0.5, 0.5, 0.5, 0.5, 0.5], + }, + Position: { + x: 168, + y: 440, + }, + Sprite: { + anchorY: 0.75, + animation: 'stage/0', + source: '/resources/tomato-plant/tomato-plant.json', + }, + Ticking: {}, + VisibleAabb: {}, + }; +} + +export default async function createHomestead(id) { + const entities = []; + entities.push(createMaster()); + entities.push(createShitShack(id)); + entities.push(createHouseTeleport(id)); + entities.push(createChest()); + // for (let i = 0; i < 200; ++i) { + // entities.push(createTomato()); + // } + entities.push(createTomatoPlant()); + // for (let i = 0; i < 10; ++i) { + // entities.push(createTestKitten()); + // } + // for (let i = 0; i < 10; ++i) { + // entities.push(createTestCow()); + // } + // for (let i = 0; i < 10; ++i) { + // entities.push(createTestGoat()); + // } + entities.push(createTownTeleport()); return entities; } diff --git a/app/server/create/player.js b/app/server/create/player.js index 536d3f7..8df1752 100644 --- a/app/server/create/player.js +++ b/app/server/create/player.js @@ -30,6 +30,18 @@ export default async function createPlayer(id) { qty: 1, source: '/resources/magic-swords/magic-swords.json', }, + 3: { + qty: 1, + source: '/resources/watering-can/watering-can.json', + }, + 4: { + qty: 1, + source: '/resources/tomato-seeds/tomato-seeds.json', + }, + 5: { + qty: 1, + source: '/resources/hoe/hoe.json', + }, }, }, Health: {health: 100},