diff --git a/src/multiplayer/mDNS.ts b/src/multiplayer/mDNS.ts index 884cb30..b3352c2 100644 --- a/src/multiplayer/mDNS.ts +++ b/src/multiplayer/mDNS.ts @@ -30,7 +30,7 @@ export type GiftMessage = { export default network; -export async function ready(name, onThing?) { +export async function ready(name) { const port = await getPort({port: getPort.makeRange(52300, 52399)}); mdns.publish({ type: 'dfi', @@ -73,4 +73,6 @@ mdns.find({ p.port = service.port; log.info('Found player', p); devices.push(p); -}); \ No newline at end of file +}).on("down", (service) => { + // TODO remove player from MP +}) \ No newline at end of file diff --git a/src/ui/Menu.ts b/src/ui/Menu.ts index 4a5cb4a..5312b86 100644 --- a/src/ui/Menu.ts +++ b/src/ui/Menu.ts @@ -59,19 +59,7 @@ export class Menu implements Renderable { Game.current.pawns.push(new Pawn()); } else if (key.full === 'x') { Game.current.board.clear(); - } - - // if(this.view === View.PAWNS) { - // if (key.full === 'delete') { - // Game.current.removePawn(Game.current.selected); - // } else if (key.full === 'up') { - // Game.current.advanceSelection(-1); - // } else if (key.full === 'down') { - // Game.current.advanceSelection(1); - // } else if (key.full === 'enter') { - // new PawnDetails(Game.current.selected); - // } - // } + } else this.view.keypress(key); // if(this.view === View.MULTIPLAYER) { // if (key.full === 'enter') { @@ -84,6 +72,8 @@ export class Menu implements Renderable { // } // } + // TODO add colortest debug screen! + Game.current.sync(); }); } @@ -93,61 +83,19 @@ export class Menu implements Renderable { return ` ${Game.current.clock.render()}{|}${getTheme().normal(`Idle: ${idlers.length}`)} `; } - renderPawns() { - return `${ - Game.current.pawns.map(pawn => `${(function() { - const selected = pawn === Game.current.selected; - let str = ''; - if(selected) { - str += ` ${getTheme().selected(` ❯ ${pawn.toString()}`)}{|}${pawn.status} \n`; - str += ` ${getTheme().normal('Energy')}{|}${progressbar(pawn.energy / 100, (menuPanel.width - 4) / 2)} \n`; - } else { - str += ` ${getTheme().normal(pawn.toString())}{|}${pawn.status} `; - } - return str; - })()}`).join('\n') - }`; - } - renderView() { const colSpace = ((menuPanel.width - 2) / 2); - return `${ - // ' '.repeat(colSpace - 20) - '{center}' - }${(() => { - return Object.values(View).map(view => { - if(view === this.view) { - return getTheme().tab.selected(` ${view} `); + return `{center}${(() => { + return Object.values(this.views).map((view, idx) => { + if(idx === this.viewIndex) { + return getTheme().tab.selected(` ${view.name} `); } else { - return getTheme().tab.normal(` ${view} `); + return getTheme().tab.normal(` ${view.name} `); } }).join(''); - })()}{/center}\n\n${(() => { - this.view.render(); - })()}` - } - - multiplayerSelected = 0; - - renderMultiplayer() { - if(mdns.players.length === 0) return `{center}${getTheme().normal('No friends online')}{/center}`; - return mdns.players.map((player, i) => { - if(i === this.multiplayerSelected) return ' ' + getTheme().selected(' ❯ ' + player.toString()); - else return ' ' + getTheme().normal(player.toString()); - }).join('\n'); - } - - renderInv() { - return Game.current.inv.render(); - } - - renderTreesSubMenu() { - return [ - `{center}Chop Trees`, - `{left} ${getTheme().hotkey('-=_+')}: ${this.trees}`, - `{left} ${getTheme().hotkey('enter')}: Create Task`, - `{left} ${getTheme().hotkey('escape')}: Cancel` - ].join('\n'); + })()}{/center}\n\n${ + this.view.render() + }`; } render() { diff --git a/src/ui/Popup.ts b/src/ui/Popup.ts index ba2867b..8cdbfa5 100644 --- a/src/ui/Popup.ts +++ b/src/ui/Popup.ts @@ -21,8 +21,22 @@ export class Popup { tags: true, ...boxStyle(), }); - let stuff = ''; - for(let i = 16; i < 232; i ++) stuff += chalk.bgAnsi256(i).black(` ${i.toString().padStart(3, ' ')} ${(i-15)%18===0?'\n':''}`) + let stuff = ' '; + for(let i = 16; i < 34; i ++) stuff += chalk.bgAnsi256(i).black(` ${i.toString().padStart(3, ' ')} ${(i-15)%6===0?chalk.reset(' '):''}`); stuff += '\n '; + for(let i = 52; i < 70; i ++) stuff += chalk.bgAnsi256(i).black(` ${i.toString().padStart(3, ' ')} ${(i-15)%6===0?chalk.reset(' '):''}`); stuff += '\n '; + for(let i = 88; i < 106; i ++) stuff += chalk.bgAnsi256(i).black(` ${i.toString().padStart(3, ' ')} ${(i-15)%6===0?chalk.reset(' '):''}`); stuff += '\n '; + for(let i = 124; i < 142; i ++) stuff += chalk.bgAnsi256(i).black(` ${i.toString().padStart(3, ' ')} ${(i-15)%6===0?chalk.reset(' '):''}`); stuff += '\n '; + for(let i = 160; i < 178; i ++) stuff += chalk.bgAnsi256(i).black(` ${i.toString().padStart(3, ' ')} ${(i-15)%6===0?chalk.reset(' '):''}`); stuff += '\n '; + for(let i = 196; i < 214; i ++) stuff += chalk.bgAnsi256(i).black(` ${i.toString().padStart(3, ' ')} ${(i-15)%6===0?chalk.reset(' '):''}`); stuff += '\n '; + stuff += '\n '; + for(let i = 34; i < 52; i ++) stuff += chalk.bgAnsi256(i).black(` ${i.toString().padStart(3, ' ')} ${(i-15)%6===0?chalk.reset(' '):''}`); stuff += '\n '; + for(let i = 70; i < 88; i ++) stuff += chalk.bgAnsi256(i).black(` ${i.toString().padStart(3, ' ')} ${(i-15)%6===0?chalk.reset(' '):''}`); stuff += '\n '; + for(let i = 106; i < 124; i ++) stuff += chalk.bgAnsi256(i).black(` ${i.toString().padStart(3, ' ')} ${(i-15)%6===0?chalk.reset(' '):''}`); stuff += '\n '; + for(let i = 142; i < 160; i ++) stuff += chalk.bgAnsi256(i).black(` ${i.toString().padStart(3, ' ')} ${(i-15)%6===0?chalk.reset(' '):''}`); stuff += '\n '; + for(let i = 178; i < 196; i ++) stuff += chalk.bgAnsi256(i).black(` ${i.toString().padStart(3, ' ')} ${(i-15)%6===0?chalk.reset(' '):''}`); stuff += '\n '; + for(let i = 214; i < 232; i ++) stuff += chalk.bgAnsi256(i).black(` ${i.toString().padStart(3, ' ')} ${(i-15)%6===0?chalk.reset(' '):''}`); stuff += '\n '; + stuff += '\n'; + for(let i = 232; i < 256; i ++) stuff += chalk.bgAnsi256(i).black(` ${i.toString().padStart(3, ' ')} ${(i-15)%18===0?'\n':''}`) this.box.setContent(stuff) this.box.on('keypress', (evt, key) => { if(key.full === 'escape' || key.full === 'enter') { diff --git a/src/ui/view/InventoryView.ts b/src/ui/view/InventoryView.ts index 77d2fe4..d58f6b4 100644 --- a/src/ui/view/InventoryView.ts +++ b/src/ui/view/InventoryView.ts @@ -1,3 +1,4 @@ +import { Game } from "../../Game.js"; import { View } from "../View.js"; export default class InventoryView extends View { @@ -5,6 +6,9 @@ export default class InventoryView extends View { super(); this.name = 'Inventory'; } - keypress: (key: { full: string; }) => void; - render() { void 0 }; + keypress(key: { full: string; }) {} + + render() { + return Game.current.inv.render(); + }; } \ No newline at end of file diff --git a/src/ui/view/MultiplayerView.ts b/src/ui/view/MultiplayerView.ts index 30b1929..7d770a5 100644 --- a/src/ui/view/MultiplayerView.ts +++ b/src/ui/view/MultiplayerView.ts @@ -1,10 +1,32 @@ -import { View } from "../View.js"; +import { GiftPopup } from "../GiftPopup.js"; +import { View } from "../View.js" +import mdns from '../../multiplayer/mDNS.js'; +import { getTheme } from "@theme"; export default class MultiplayerView extends View { + + selected: number = 0; + constructor() { super(); this.name = 'Multiplayer'; } - keypress: (key: { full: string; }) => void; - render() { void 0 }; + + keypress(key: { full: string; }) { + if (key.full === 'enter') { + new GiftPopup(mdns.players[this.selected]); + } else if (key.full === 'up') { + this.selected --; + } else if (key.full === 'down') { + this.selected ++; + } + } + + render() { + if(mdns.players.length === 0) return `{center}${getTheme().normal('No friends online')}{/center}`; + return mdns.players.map((player, i) => { + if(i === this.selected) return ' ' + getTheme().selected(' ❯ ' + player.toString()); + else return ' ' + getTheme().normal(player.toString()); + }).join('\n'); + }; } \ No newline at end of file diff --git a/src/ui/view/PawnsView.ts b/src/ui/view/PawnsView.ts index b46f8c8..118010b 100644 --- a/src/ui/view/PawnsView.ts +++ b/src/ui/view/PawnsView.ts @@ -1,3 +1,8 @@ +import { getTheme } from "@theme"; +import { Game } from "../../Game.js"; +import { progressbar } from "../../Progressbar.js"; +import { PawnDetails } from "../PawnDetails.js"; +import { menuPanel } from "../UI.js"; import { View } from "../View.js"; export default class PawnsView extends View { @@ -5,6 +10,32 @@ export default class PawnsView extends View { super(); this.name = 'Pawns'; } - keypress: (key: { full: string; }) => void; - render() { void 0 }; + + keypress(key: { full: string; }) { + if (key.full === 'delete') { + Game.current.removePawn(Game.current.selected); + } else if (key.full === 'up') { + Game.current.advanceSelection(-1); + } else if (key.full === 'down') { + Game.current.advanceSelection(1); + } else if (key.full === 'enter') { + new PawnDetails(Game.current.selected); + } + } + + render() { + return `${ + Game.current.pawns.map(pawn => `${(function() { + const selected = pawn === Game.current.selected; + let str = ''; + if(selected) { + str += ` ${getTheme().selected(` ❯ ${pawn.toString()}`)}{|}${pawn.status} \n`; + str += ` ${getTheme().normal('Energy')}{|}${progressbar(pawn.energy / 100, (menuPanel.width - 4) / 2)} \n`; + } else { + str += ` ${getTheme().normal(pawn.toString())}{|}${pawn.status} `; + } + return str; + })()}`).join('\n') + }`; + } } \ No newline at end of file