Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor dungeon & jsdocs everywhere #200

Merged
merged 7 commits into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,28 @@ module.exports = {
browser: true,
es2021: true,
},
extends: ['eslint:recommended', 'plugin:prettier/recommended'],
plugins: ['jsdoc'],
extends: [
'eslint:recommended',
'plugin:prettier/recommended',
'plugin:jsdoc/recommended',
// 'plugin:jsdoc/recommended-typescript-flavor',
],
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
rules: {
complexity: ['warn', 14],
'jsdoc/require-property-description': 'off',
'jsdoc/require-param-description': 'off',
'jsdoc/require-returns-description': 'off',
},
settings: {
jsdoc: {
tagNamePreference: {
property: 'prop',
},
},
},
}
3 changes: 1 addition & 2 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ On `state.player` we have you, the player. This object describes the health, pow

#### Dungeon

Every game starts in a dungeon. You make your way through rooms to reach the end.

Every game evolves around and in a dungeon. A dungeon consists of a graph (think a 2d array with rows and columns, or positions and nodes, or floors and rooms).
There are different types of rooms. Like Monster and Campfire. One day there'll be more like Merchant and Treasure or a "random" room.

#### Monsters
Expand Down
7 changes: 4 additions & 3 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"compilerOptions": {
"checkJs": true,
"allowJs": true,
"checkJs": true,
"target": "esnext",
"moduleResolution": "nodenext"
},
"moduleResolution": "nodenext",
"noEmit": true
}
}
102 changes: 102 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"docco": "^0.9.1",
"eslint": "^8.45.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-jsdoc": "^46.4.4",
"eslint-plugin-prettier": "^5.0.0",
"prettier": "3.0.0",
"release-it": "^16.1.3",
Expand Down
12 changes: 8 additions & 4 deletions src/content/dungeon-encounters.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import Dungeon from '../game/dungeon.js'
import {MonsterRoom, Monster} from '../game/dungeon-rooms.js'
import {random} from '../game/utils.js'
import {MonsterRoom} from '../game/rooms.js'
import {Monster} from '../game/monster.js'
import {random} from '../utils.js'

// A dungeon encounter is the combination of a Room and Monster(s).

// Hello. With the imported functions above you can create a dungeon with different rooms and monsters.
// Should be able to support even more monsters (4-5)
// This is the dungeon currently used.

// This is the efault dungeon currently used.
export const dungeonWithMap = () => {
return Dungeon({
width: 6,
Expand All @@ -18,7 +22,7 @@ export const dungeonWithMap = () => {
// This is the dungeon used in tests. Don't change it without running tests.
export const createTestDungeon = () => {
const dungeon = Dungeon({width: 1, height: 3})
// The tests rely on the first room having a single monster, second two monsters.
// The tests rely on the first room having a single monster, second room two monsters.
const intents = [{block: 7}, {damage: 10}, {damage: 8}, {}, {damage: 14}]
dungeon.graph[1][0].room = MonsterRoom(Monster({hp: 42, intents}))
dungeon.graph[2][0].room = MonsterRoom(Monster({hp: 24, intents}), Monster({hp: 13, intents}))
Expand Down
28 changes: 20 additions & 8 deletions src/game/action-manager.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
import Queue from './queue.js'
import actions from './actions.js'
import Queue from '../utils.js'

/** @typedef {import('./actions.js').State} State */

/**
* @typedef {Object} FutureAction
* @typedef {object} FutureAction
* @prop {string} type - the name of a function in actions.js
* @prop {any} [any] - arguments are passed to the action
*/

/**
* @typedef {Object} PastAction
* @typedef {object} PastAction
* @prop {string} type - the name of a function in actions.js
* @prop {import('./actions.js').State} state
* @prop {State} state
*/

/**
* @typedef {object} ActionManager
* @prop {function(FutureAction):void} enqueue
* @prop {function(State):State} dequeue
* @prop {function():PastAction} undo
* @prop {Queue} future
* @prop {Queue} past
*/

/**
* The action manager makes use of queues to keep track of future and past actions in the game state + undo.
* @param {Object} props
* @prop {boolean} props.debug - whether to log actions to the console
* @param {object} props
* @param {boolean} props.debug - whether to log actions to the console
* @returns {ActionManager} action manager
*/
export default function ActionManager(props) {
const future = new Queue()
Expand All @@ -34,8 +46,8 @@ export default function ActionManager(props) {
/**
* Deqeueing runs the oldest action (from the `future` queue) on the state.
* The action is then moved to the `past` queue.
* @param {import('./actions.js').State} state
* @returns {import('./actions.js').State} new state
* @param {State} state
* @returns {State} new state
*/
function dequeue(state) {
// Get the oldest action
Expand Down
Loading