import { genItems, loadMap, getMap } from "../map.js"; import { updatePlayers } from "./players.js" import { updateUI } from "./ui.js" import { updateMovement } from "./movement.js" import { updateItems } from "./items.js" import { GameState, Input } from "../types.js"; export const InitialState: GameState = { started: false, input: {}, players: [], items: {}, mapId: undefined } export const onLogic = ( pastData: GameState = InitialState, input: Input = { players: {} }, _frame: number ) => { let data = structuredClone(pastData) let startPressed = updatePlayers(data, input); if (data.started) { updateMovement(data) updateItems(data) } else { updateUI(data) } if (startPressed && !data.started) { initMap(data) data.started = true; } return data } const initMap = (data: GameState) => { document.getElementById("lobby").style.display = "none" data.mapId = 0 if (getMap(0)) return let width = 21 let height = 21 let m_data = [ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1, 1,0,1,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1,0,1, 1,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,1, 1,0,1,0,1,1,1,1,1,0,1,0,1,1,1,1,1,0,1,0,1, 1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,1, 1,0,1,1,1,0,1,0,1,1,1,1,1,0,1,0,1,1,1,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,1,1,0,1,0,1,0,1,1,1,1,1,0,1,0,1,0,1,1,1, 1,0,0,0,0,0,1,0,1,2,2,2,1,0,1,0,0,0,0,0,1, 1,0,1,1,1,0,1,0,1,2,2,2,1,0,1,0,1,1,1,0,1, 1,0,0,0,0,0,1,0,1,2,2,2,1,0,1,0,0,0,0,0,1, 1,1,1,0,1,0,1,0,1,1,2,1,1,0,1,0,1,0,1,1,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,1,1,1,0,1,0,1,1,1,1,1,0,1,0,1,1,1,0,1, 1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,1, 1,0,1,0,1,1,1,1,1,0,1,0,1,1,1,1,1,0,1,0,1, 1,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,1, 1,0,1,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1,0,1, 1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 ] loadMap(width, height, m_data) // cursed temp thing data.items = genItems(getMap(0)) }