-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ support custom online game names, add menu system, config persistence
- Loading branch information
Showing
15 changed files
with
458 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,3 +104,5 @@ dist | |
.tern-port | ||
|
||
.DS_Store | ||
|
||
netrisse.config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
const fs = require('node:fs'); | ||
|
||
class Config { | ||
// can't use private properties with proxies 😿 | ||
_customServer; | ||
_gameName; | ||
_playerName = 'The Unknown Netrisser'; | ||
_speed = 0.5 * 1000; | ||
|
||
get customServer() { | ||
return this._customServer; | ||
} | ||
|
||
set customServer(customServer) { | ||
this._customServer = customServer; | ||
} | ||
|
||
get gameName() { | ||
return this._gameName; | ||
} | ||
|
||
set gameName(gameName) { | ||
if (!gameName) { | ||
throw new Error('game name is required'); | ||
} | ||
this._gameName = gameName; | ||
} | ||
|
||
get playerName() { | ||
return this._playerName; | ||
} | ||
|
||
set playerName(playerName) { | ||
if (playerName) { | ||
this._playerName = playerName; | ||
} | ||
} | ||
|
||
get speed() { | ||
return this._speed; | ||
} | ||
|
||
set speed(speed) { | ||
this._speed = speed; | ||
} | ||
|
||
save() { | ||
try { | ||
fs.writeFileSync(configFile, JSON.stringify(this)); | ||
} | ||
catch (error) { // eslint-disable-line no-unused-vars | ||
// debug(error) | ||
} | ||
} | ||
}; | ||
|
||
const configFile = 'netrisse.config'; | ||
const config = new Config(); | ||
|
||
try { | ||
const savedConfig = JSON.parse(fs.readFileSync(configFile)); | ||
Object.assign(config, savedConfig); | ||
} | ||
catch (error) { // eslint-disable-line no-unused-vars | ||
// debug(error) | ||
} | ||
|
||
const handler = { | ||
set(target, property, value) { | ||
target[property] = value; | ||
target.save(); | ||
return true; | ||
}, | ||
}; | ||
|
||
module.exports = new Proxy(config, handler); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const config = require('./config'); | ||
const start = require('./start'); | ||
const quit = require('./quit'); | ||
const multiplayer = require('./multiplayer'); | ||
|
||
module.exports = function intro(screen, seed) { | ||
const mainBoardPosition = { top: 2, right: 21, bottom: 23, left: 0 }; | ||
|
||
let cursorY = 3; | ||
|
||
screen.clear(); | ||
screen.d(2, cursorY, '✨ Welcome to Netrisse! 🎉', { color: 'green' }); | ||
screen.d(5, cursorY += 3, '1) Single player 🧍', { color: 'amber' }); | ||
screen.d(5, cursorY += 2, '2) Multiplayer 🧑🤝🧑', { color: 'amber' }); | ||
screen.d(5, cursorY += 2, '3) Options 🔧', { color: 'amber' }); | ||
screen.d(5, cursorY += 2, 'Q) Quit 🚪', { color: 'brightred' }); | ||
screen.render(); | ||
|
||
const keyHandler = name => { | ||
switch (name) { | ||
case '1': | ||
screen.term.removeListener('key', keyHandler); | ||
start(seed, screen, mainBoardPosition, config.speed, null); | ||
break; | ||
case '2': | ||
screen.term.removeListener('key', keyHandler); | ||
multiplayer(screen, seed, intro, mainBoardPosition); | ||
break; | ||
case 'CTRL_C': case 'ESCAPE': case 'Q': case 'q': | ||
quit(screen, mainBoardPosition); | ||
break; | ||
} | ||
}; | ||
|
||
screen.term.on('key', keyHandler); | ||
}; |
Oops, something went wrong.