Room descriptions, flashlight visibility, fix screen clearing

main
Ashelyn Dawn 4 years ago
parent f504226a87
commit 3ec1f9f9c1

@ -29,7 +29,8 @@ export default function Text({promptVisible: promptEnabled, handleCommand, showR
const printedMessages = !outputPaused ? messages : messages.slice(0, currentPause)
const promptVisible = promptEnabled && !outputPaused
const clearedIndex = printedMessages.findIndex(message => message.type === 'clear')
const currentClear = [...printedMessages].reverse().find(message => message.type === 'clear')
const clearedIndex = printedMessages.indexOf(currentClear)
const finalMessages = (clearedIndex < 0) ? printedMessages : printedMessages.slice(clearedIndex)
async function onSubmit(ev) {
@ -95,6 +96,12 @@ export default function Text({promptVisible: promptEnabled, handleCommand, showR
return () => document.removeEventListener('keydown', handleKey)
}, [currentPause, outputPaused, messages, currentMenu])
// Scroll after unpaused
useEffect(() => {
setImmediate(() => outputRef.current.scrollTop = outputRef.current.scrollHeight)
setCurrentScroll(outputRef.current.scrollHeight)
}, [currentPause])
return (
<>
<div ref={textRef} className={styles.playArea}>

@ -1,7 +1,7 @@
import { ValidCommandDetails } from "./types/ParsedCommand";
import Game from "./Game";
import { EventEmitter } from "events";
import printArea from "../utils/printArea"
import {printLocDescription, printLocItems} from "../utils/printArea"
// This class allows for hooking up "global events" for things such as checking
// victory conditions, acting when play begins, or other such things. These
@ -15,6 +15,7 @@ export default class RulesEngine extends EventEmitter{
constructor(game : Game) {
super()
this.setMaxListeners(40)
this.game = game
this.on('beforeCommand', () => {this.lastLocation = game.getState().player.location})
this.on('afterCommand', () => {
@ -23,10 +24,26 @@ export default class RulesEngine extends EventEmitter{
})
this.on('locationChange', () => {
printArea(game)
this.printArea()
})
}
printArea() : void {
try {
this.emit('beforePrintArea')
printLocDescription(this.game)
} catch (err) {
this.game.say(err.message)
}
try {
this.emit('beforePrintItems')
printLocItems(this.game)
} catch (err) {
this.game.say(err.message)
}
}
gameStart() {
this.emit('gameStart', this.game)
this.emit('locationChange')

@ -2,7 +2,6 @@ import Parser from "../Parser";
import RulesEngine from "../RulesEngine";
import Game from "../Game";
import { ValidCommandDetails } from "../types/ParsedCommand";
import printArea from "../../utils/printArea";
export default function(parser : Parser, rules : RulesEngine, game : Game) {
parser.understand('look')
@ -11,6 +10,6 @@ export default function(parser : Parser, rules : RulesEngine, game : Game) {
.as('l')
rules.onCommand('look', (command : ValidCommandDetails) => {
printArea(game)
rules.printArea()
})
}

@ -1,27 +1,116 @@
import {game} from '../engine'
import {game, rules} from '../engine'
/**
* Cabin
*/
game.addRoom('cabin', 'Crew Cabin', `
A dark and dingy room with a single bunk bed along the starboard side.
The washroom is to the aft, with the common room to port.
The washroom is to the aft, with the comms room to port.
`)
rules.on('beforePrintItems', () => {
const state = game.getState()
const playerLocation = state.player.location
const flashlightLocation = state.items.get('flashlight')?.location
if(flashlightLocation !== 'inventory' && playerLocation === 'cabin')
throw new Error('You cannot make out much more without light.')
})
rules.onAfterCommand(() => {
const state = game.getState()
const flashlightLocation = state.items.get('flashlight')?.location
const wrenchExists = state.items.has('wrench')
if(flashlightLocation === 'inventory' && !wrenchExists)
game.addItem('wrench', 'Just generally useful for repairs and adjustments to the various mechanical parts of the ship.', 'cabin')
})
/**
* Washroom
*/
game.addRoom('bathroom', 'Washroom', `
Tight, cramped, but serviceable. This ship was really only meant for a crew
Tight, cramped, but serviceable. The _Dawn_ was really only meant for a crew
of one or two, and that is no more evident than here.
A barren metal bowl sits below a cracked mirror and above a small cupboard.
The crew cabin is through the foreward door, and the little remaining space
is occupied with a sink and cabinet.
`)
const flashlight = game.addItem('flashlight', 'Metal rod with some LEDs embedded along its length', 'bathroom')
flashlight.aliases.push('flash light')
flashlight.aliases.push('light')
flashlight.aliases.push('torch')
/**
* Comms
*/
game.addRoom('comms', 'Comms Room', `
A wide room with pipes and cabling running thick through the floor.
The bridge is to the fore, the medbay to port, and the crew cabin to starboard.
There is a large storage locker on the aft wall of the room.
`)
game.addRoom('bridge', 'Bridge', `
A lone chair sits in the center of the room, surrounded with computer
consoles and flight instruments. Nowadays most aspects of spaceflight are
automated, but every pilot still needs to meet the certification to fly
manually.
The comms room is through the aft door.
`)
game.addRoom('medbay', 'Medical Bay', `
Most of the medical equipment in this room is a little past its use-by
date, although in the case of an explosion, impact, or other traumatic
event it would still save your life . . . at least you hope it would.
The stairwell is to the aft, with the comms room to starboard.
`)
// TODO: Room descriptions
game.addRoom('comms', 'Comms Room', `// TODO`)
game.addRoom('bridge', 'Bridge', `// TODO`)
game.addRoom('medbay', 'Medical Bay', `// TODO`)
game.addRoom('stairupper', 'Upper Stairwell', `// TODO`)
game.addRoom('stairlower', 'Lower Stairwell', `// TODO`)
game.addRoom('mainframe', 'Mainframe', `// TODO`)
game.addRoom('engine', 'Engine Room', `// TODO`)
game.addRoom('docking', 'Docking Bay', `// TODO`)
game.addRoom('stairupper', 'Upper Stairwell', `
A large window in the aft wall shows the view of an unknown star system
in the distance. It's almost peaceful to gaze at, if it didn't remind
you of how lost you are.
The medical bay is to the fore, with the stairs curling into
darkness beneath you.
`)
game.addRoom('stairlower', 'Lower Stairwell', `
A bit of light makes its way down through the wire stairs, helpfully
keeping you from falling on your face in the dark.
The mainframe is to the fore, and above you the stairs curl up and
out of sight.
`)
game.addRoom('mainframe', 'Mainframe', `
The mainframe fills the room with its soft humming, lights blinking
on and off in a disorderly pattern.
The stairwell is to the aft, with the engine room to starboard.
`)
game.addRoom('engine', 'Engine Room', `
The usual deep rumble of the ship's engines is missing, leaving a
disconcerting silence.
The mainframe is to port, with the docking bay to starboard.
`)
game.addRoom('docking', 'Docking Bay', `
A long and wide room for loading and unloading cargo. The
dock hatch is sealed, and you definitely shouldn't go opening
that until you get back in atmosphere.
Toward port is the engine room, and through a small hole in
the ceiling you can see light coming from the bathroom.
`)
// Regular hallways
game.setNeighbor('cabin', 'aft', 'bathroom')

@ -4,16 +4,18 @@ import './gameSetup/0-item-visibility'
import './gameSetup/1-rooms'
import './gameSetup/2-phases-and-hints'
game.addItem('block', 'A boring wooden block', 'comms')
game.saveDraft()
// Print description on game start
rules.onGameStart(() => {
game.say(`Come, join the navy they said.`)
game.say(`A loud blaring alarm slowly drags you out of your sleep. For a moment you consider rolling over and returning to your rest, but you know that's a bad idea. The ship's alarm wouldn't be going off for no reason, and most of the reasons it would be going off are deadly.`)
game.say(`You sit up, rub the sleep from your eyes and glance around. Primary lights are off, but you can make out darkened silhouettes from the emergency light in the washroom. The computer panel in the wall is also darkened, so the engine must have stopped for long enough that the ship's primary power banks are drained.`)
game.say(`Then you notice the worst part - the security doors to the comms room are shut, sealing you off from the rest of the ship.`)
game.pause()
game.clear()
game.say(`You groan.`)
game.pause()
game.say(`It'll be fun they said.`)
game.say(`Looks like this job just got a lot more complicated.`)
game.pause()
game.clear()
})

@ -1,11 +1,16 @@
import capitalize from "./capitalize"
import Game from "../engine/Game"
export default function printArea(game : Game) {
export function printLocDescription(game : Game) {
const location = game.getCurrentRoom()!
console.log('printing')
game.say(`**${capitalize(location.printableName)}**`)
game.say(location.description!)
}
export function printLocItems(game : Game) {
const location = game.getCurrentRoom()!
const items = game.findObjectsInRoom(location.name)
const doors = game.findDoorsInRoom(location.name)
@ -34,5 +39,4 @@ export default function printArea(game : Game) {
game.say(youCanSee)
}
}

@ -1,27 +1,5 @@
# Commands:
# To-do
look around
check pockets
sleep?
go through [door]
# Bugs
Command input overflows on Chrome/Edge? (saw when Almyki tried)
Look should print what directions doors are in.
Looking a direction through an open door should print what room is past it
Unlocking an already unlocked door
Prints "you cannot go to the [direction]" twice
`go up`: "you cannot go to the up"
# Note
Almyki wants me to hide a teddy bear in the game for her.
- Prevent movement through locked doors
- Prevent movement through hatch until it's been unscrewed
- Other state locks
Loading…
Cancel
Save