From 54293c23714514dd8e3cb82cf0ef6155f7aff79d Mon Sep 17 00:00:00 2001 From: Otto Sichert Date: Tue, 28 Nov 2023 16:41:23 +1000 Subject: [PATCH] Simplify map templating --- src/engine/generate.tsx | 12 +++++-- src/engine/utils.tsx | 4 +++ src/engine/worlds.tsx | 71 ++++++++++++++++++++++------------------- 3 files changed, 52 insertions(+), 35 deletions(-) diff --git a/src/engine/generate.tsx b/src/engine/generate.tsx index 643c312..6f53706 100644 --- a/src/engine/generate.tsx +++ b/src/engine/generate.tsx @@ -3,11 +3,12 @@ import { MapCell } from 'worldmap-generator'; import { creatureSpawns, creatureStats, getRandomDistribution } from './balancing'; import { World, world } from './biomes'; -import { Player, Cell, SingleCategories, MultipleCategories, Entity, Rock, Flower, Tree, Bush, grounds, containers, Spell, Armor, Terrain, Sand, Water, Skin, CharacterSelect, Interaction, Lily, Apple, Blossom } from "./entities"; +import { Player, Cell, SingleCategories, MultipleCategories, Entity, Rock, Flower, Tree, Bush, grounds, containers, Spell, Armor, Terrain, Sand, Water, Skin, CharacterSelect, Interaction, Lily, Apple, Blossom, Equipment } from "./entities"; import { generateFog } from './fog'; import { createMatrix, generateWhiteNoise, valueNoise } from './noise'; import { corners, createCreature, createEquipment, createInteraction, createParticle, getDeterministicRandomInt, orientations, Processor, sum, TerminalState, updateCell, wrapCoordinates } from "./utils"; import { rural } from './worlds'; +import { collectEquipment } from './equipments'; const getSingleElements = (world: World, cells: MapCell[], category: SingleCategories) => cells.map(cell => world.tileCells[cell.name][category]); const getMultipleElements = (world: World, cells: MapCell[], category: MultipleCategories) => cells.reduce[]>((cellTypes, cell) => [ @@ -250,7 +251,8 @@ function generateLevel(state: TerminalState): TerminalState { }); }); - // load world + /* + // load character select let characterSelect: Processor; [state, characterSelect] = createInteraction(state, { x: 0, y: 0 }, CharacterSelect, { quest: 'characterSelect', equipments: [] }); @@ -259,6 +261,12 @@ function generateLevel(state: TerminalState): TerminalState { const [targetX] = wrapCoordinates(state, (index - 10) * 3, 0); state = createEquipment(state, { x: targetX, y: 0, parent: { container: 'interactions', id: characterSelect.id } }, Skin, { amount: 0, maximum: 0, level: skin.charCodeAt(0), particles: [], material: 'gold' })[0]; }) + */ + + // apply default skin + let skin: Processor; + [state, skin] = createEquipment(state, { x: 0, y: 0 }, Skin, { amount: 0, maximum: 0, level: '\u010b'.charCodeAt(0), particles: [], material: 'gold' }); + state = collectEquipment(state, skin.id); // spawn equipment for development purposes diff --git a/src/engine/utils.tsx b/src/engine/utils.tsx index 446cf4f..119a2ef 100644 --- a/src/engine/utils.tsx +++ b/src/engine/utils.tsx @@ -48,9 +48,13 @@ export type Orientation = typeof orientations[number]; export const keyToOrientation: Record = { ArrowUp: 'up', + w: 'up', ArrowRight: 'right', + d: 'right', ArrowDown: 'down', + s: 'down', ArrowLeft: 'left', + a: 'left', }; // x, y diff --git a/src/engine/worlds.tsx b/src/engine/worlds.tsx index 47f3bf9..492bb31 100644 --- a/src/engine/worlds.tsx +++ b/src/engine/worlds.tsx @@ -51,30 +51,33 @@ Boss */ -const air: LayoutCell = {}; -const tree: LayoutCell = { terrain: }; -const tre2: LayoutCell = { terrain: }; -const bush: LayoutCell = { sprite: }; -const seed: LayoutCell = { sprite: , item: }; -const flwr: LayoutCell = { sprite: }; -const herb: LayoutCell = { sprite: , item: }; -const chst: LayoutCell = { creature: [Chest, { amount: 8, maximum: 8, orientation: 'up', equipments: [], particles: [] }] }; -const cmps: LayoutCell = { equipment: [Compass, { material: 'iron', amount: 0, maximum: 0, level: 0 }] }; - const getBlockedProps = (direction: Direction): EquipmentProps => ( { amount: 0, maximum: 0, level: 0, material: 'wood', mode: 'equipped', particle: [ Wave, { direction, material: 'plant' } ] } ); -const pluu: LayoutCell = { equipment: [Blocked, getBlockedProps('up') ] }; -const plur: LayoutCell = { equipment: [Blocked, getBlockedProps('upRight') ], sprite: }; -const plrr: LayoutCell = { equipment: [Blocked, getBlockedProps('right') ] }; -const plrd: LayoutCell = { equipment: [Blocked, getBlockedProps('rightDown') ] }; -const pldd: LayoutCell = { equipment: [Blocked, getBlockedProps('down') ] }; -const pldl: LayoutCell = { equipment: [Blocked, getBlockedProps('downLeft') ] }; -const plll: LayoutCell = { equipment: [Blocked, getBlockedProps('left') ] }; -const pllu: LayoutCell = { equipment: [Blocked, getBlockedProps('leftUp') ], sprite: }; +const cellMap: Record = { + '0': null, + ' ': {}, + '#': { terrain: }, + 'Θ': { terrain: }, + 'τ': { sprite: }, + 'T': { sprite: , item: }, + ',': { sprite: }, + ';': { sprite: , item: }, + '+': { creature: [Chest, { amount: 8, maximum: 8, orientation: 'up', equipments: [], particles: [] }] }, + '^': { equipment: [Compass, { material: 'iron', amount: 0, maximum: 0, level: 0 }] }, + '─': { equipment: [Blocked, getBlockedProps('up') ] }, + '│': { equipment: [Blocked, getBlockedProps('right') ] }, + '┌': { equipment: [Blocked, getBlockedProps('leftUp') ], sprite: }, + '┐': { equipment: [Blocked, getBlockedProps('upRight') ], sprite: }, + '┘': { equipment: [Blocked, getBlockedProps('rightDown') ] }, + '└': { equipment: [Blocked, getBlockedProps('downLeft') ] }, +}; + +const mapToCells = (map: string) => map.split('\n').map(row => row.split('').map(cell => cellMap[cell])); + export type EquipmentProps = Omit, 'id' | 'particles'> & { particle?: [Particle, Omit, 'id'>], @@ -95,25 +98,27 @@ export type World = { rooms: Record, }; +const ruralMap = `\ +00000 00000 +000 Θ#Θ#Θ#Θ 000 +00 Θ#ττ┌─┐ττ#Θ 00 +0 #ττ,,│ │,,ττ# 0 + Θτ,, └─┘ ,,τΘ + #τ, , ; ,τ# + Θτ, ,+, ,T; ,τΘ + #τ, , ; ,τ# + Θτ,, ^ ,,τΘ +0 #ττ,, ,,ττ# 0 +00 Θ#ττ, ,ττ#Θ 00 +000 Θ#Θ Θ#Θ 000 +00000 00000\ +`; + export const rural: World = { rooms: { spawn: { // 19x13 - layout: [ - [null,null,null,null,null,air, air, air, air, air, air, air, air, air, null,null,null,null,null], - [null,null,null,air, air, air, tre2,tree,tre2,tree,tre2,tree,tre2,air, air, air, null,null,null], - [null,null,air, air, tre2,tree,bush,bush,pllu,pluu,plur,bush,bush,tree,tre2,air, air, null,null], - [null,air, air, tree,bush,bush,flwr,flwr,plll,null,plrr,flwr,flwr,bush,bush,tree,air, air, null], - [air, air, tre2,bush,flwr,flwr,null,null,pldl,pldd,plrd,null,null,flwr,flwr,bush,tre2,air, air ], - [air, tree,bush,flwr,null,null,flwr,null,null,null,null,null,herb,null,null,flwr,bush,tree,air ], - [air, tre2,bush,flwr,null,flwr,chst,flwr,null,null,null,flwr,seed,herb,null,flwr,bush,tre2,air ], - [air, tree,bush,flwr,null,null,flwr,null,null,null,null,null,herb,null,null,flwr,bush,tree,air ], - [air, air, tre2,bush,flwr,flwr,null,null,null,cmps,null,null,null,flwr,flwr,bush,tre2,air, air ], - [null,air, air, tree,bush,bush,flwr,flwr,null,null,null,flwr,flwr,bush,bush,tree,air, air, null], - [null,null,air, air, tre2,tree,bush,bush,flwr,air, flwr,bush,bush,tree,tre2,air, air, null,null], - [null,null,null,air, air, air, tre2,tree,tre2,air ,tre2,tree,tre2,air, air, air, null,null,null], - [null,null,null,null,null,air, air, air, air, air, air, air, air, air, null,null,null,null,null], - ] + layout: mapToCells(ruralMap), } } } \ No newline at end of file