diff --git a/public/content/cards.js b/public/content/cards.js index ef838c63..312c2824 100644 --- a/public/content/cards.js +++ b/public/content/cards.js @@ -1,8 +1,6 @@ // Here you'll find all the default cards used in the game. // See game/cards.js for the details on how they work. -//put cards here, to make it easier to add more - export default [ { name: 'Strike', @@ -481,7 +479,6 @@ export default [ },*/ // {name: 'Flex', energy: 0, type: 'skill', description: 'Gain 2 Strength.'}, ] -//cards should be split into seperate card files to make editing a single card easier // 'codices.jpg' // 'alice-holds-the-white-king.jpg' diff --git a/public/game/actions.js b/public/game/actions.js index 2cab703a..a83f203e 100644 --- a/public/game/actions.js +++ b/public/game/actions.js @@ -235,11 +235,14 @@ export function useCardActions(state, {target, card}) { if (action.conditions && !conditionsAreValid(action.conditions, state)) { return newState } - // Make sure the action is called with a target. if (!action.parameter) action.parameter = {} - // Prefer the target you dropped the card on. + + // Make sure the action is called with a target, preferably the target you dropped the card on. action.parameter.target = target - action.parameter.card = card + + // We used to set the card here, which caused a circular JSON structure. Removing this line fixed that, but keeping this comment here for now, in case something breaks. + // action.parameter.card = card + // Run the action newState = allActions[action.type](newState, action.parameter) }) diff --git a/public/game/backend.js b/public/game/backend.js index 3908afae..5509b7dc 100644 --- a/public/game/backend.js +++ b/public/game/backend.js @@ -2,6 +2,15 @@ import {isDungeonCompleted} from '../game/utils-state.js' const apiUrl = 'https://api.slaytheweb.cards/api/runs' // const apiUrl = 'http://localhost:3000/api/runs' +// + +/** + * @typedef {object} Run + * @property {string} name - user inputted player name + * @property {boolean} win - whether the player won the game + * @property {object} state - the final state + * @property {Array} past - a list of past states + */ /** * Saves a "game" object into a remote database. @@ -16,13 +25,22 @@ export function postRun(game, name) { state: game.state, past: game.past.list, } + + let body + try { + body = JSON.stringify(run) + } catch (err) { + console.log(err, run) + throw new Error('Could not stringify run') + } + return fetch(apiUrl, { method: 'POST', headers: { Accept: 'application/json', 'Content-Type': 'application/json', }, - body: JSON.stringify(run), + body, }) } diff --git a/public/game/cards.js b/public/game/cards.js index 4436d433..88b25328 100644 --- a/public/game/cards.js +++ b/public/game/cards.js @@ -42,6 +42,7 @@ export const CardTargets = { * @prop {CardTargets} target - a special "target" string to specify which targets the card affects. * color = [RED, GREEN, BLUE, PURPLE, COLORLESS, CURSE] * rarity = [BASIC, SPECIAL, COMMON, UNCOMMON, RARE, CURSE] + * @prop {boolean} exhaust - whether the card will exhaust when played. * * @prop {CARDPOWERS} [powers] - Cards can apply POWERS with the `powers` object. Powers are hardcoded in the game actions, but feel free to add more. * @prop {Array} [actions] - Cards can _optionally_ define a list of `actions`. These actions will be run, in defined order, when the card is played.