Skip to content

Commit 78a3b6c

Browse files
authored
Merge pull request #223 from oskarrough/fix/dragdroptargets
Fix stuck cards after being dropped
2 parents d40de53 + 10d21fb commit 78a3b6c

File tree

8 files changed

+21
-12
lines changed

8 files changed

+21
-12
lines changed

src/game/actions.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import {produce} from 'immer'
1+
import {produce, enableMapSet} from 'immer'
22
import {clamp, shuffle} from '../utils.js'
33
import {isDungeonCompleted, getTargets, getCurrRoom} from './utils-state.js'
44
import powers from './powers.js'
55
import {conditionsAreValid} from './conditions.js'
66
import {createCard, CardTargets} from './cards.js'
77
import {dungeonWithMap} from '../content/dungeon-encounters.js'
88

9+
// Enable support for Map and Set. See https://immerjs.github.io/immer/installation/
10+
enableMapSet()
11+
912
/** @typedef {import('./dungeon.js').Dungeon} Dungeon */
1013
/** @typedef {import('./cards.js').CARD} CARD */
1114
/** @typedef {import('./rooms.js').Room} Room */

src/game/utils-state.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,24 @@ export function getCurrRoom(state) {
4242
/**
4343
* Returns an array of targets (player or monsters) in the current room.
4444
* @param {State} state
45-
* @param {CardTargets} targetQuery
45+
* @param {CardTargets} targetQuery - like player, enemy0, enemy1
4646
* @returns {Array<MONSTER>}
4747
*/
4848
export function getTargets(state, targetQuery) {
49-
if (!targetQuery || typeof targetQuery !== 'string') {
50-
throw new Error('Bad query string')
51-
}
52-
if (targetQuery === CardTargets.player) return [state.player]
49+
if (!targetQuery || typeof targetQuery !== 'string') throw new Error('Bad query string')
5350
const room = getCurrRoom(state)
51+
52+
// Player
53+
if (targetQuery.includes(CardTargets.player)) return [state.player]
54+
// All enemies
5455
if (targetQuery === CardTargets.allEnemies) return room.monsters
56+
// Single enemy
5557
if (targetQuery.startsWith(CardTargets.enemy)) {
5658
const index = Number(targetQuery.split('enemy')[1])
5759
const monster = room.monsters[index]
5860
if (monster) return [monster]
5961
}
62+
6063
throw new Error(`Could not find target "${targetQuery}" on ${state.dungeon.y}/${state.dungeon.x}`)
6164
}
6265

src/ui/components/map.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default function map({dungeon, onMove}) {
1313
<div class="MapContainer">
1414
<${SlayMap} dungeon=${dungeon} x=${x} y=${y} scatter=${20} onSelect=${onMove}><//>
1515
16-
<footer class="MapFooter">
16+
<footer hidden class="MapFooter">
1717
<h2>History</h2>
1818
<p>Current:. Floor ${y}. Node ${x}</p>
1919
<ul>

src/ui/components/start-room.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default class StartRoom extends Component {
88
<br/>
99
<div class="Box">
1010
<ul class="Options">
11-
<li><button onClick=${() => this.props.onContinue()}>View the map</button></li>
11+
<li><button onClick=${() => this.props.onContinue()}>Open the map</button></li>
1212
</ul>
1313
</div>
1414
<p center>

src/ui/dragdrop.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import {cardHasValidTarget} from '../game/utils-state.js'
33
import gsap from './animations.js'
44
import sounds from './sounds.js'
55

6-
// Class to add to the element we are dragging over.
6+
/** Class to add to the element we are dragging over */
77
const overClass = 'is-dragOver'
88

9-
// Makes the card fly back into the hand.
9+
/** Makes the card fly back into the hand */
1010
function animateCardToHand(draggable) {
1111
return gsap.to(draggable.target, {x: draggable.startX, y: draggable.startY, zIndex: 0})
1212
}

src/ui/styles/app.css

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ html {
1818
background-position: 50%;
1919
background-size: cover;
2020
background-repeat: no-repeat;
21-
overflow-x: hidden;
22-
overflow-y: scroll;
2321
}
2422

2523
/* Minimum font size */
@@ -46,6 +44,9 @@ input {
4644

4745
body {
4846
margin: 0;
47+
overflow: hidden;
48+
/* overflow-x: hidden; */
49+
/* overflow-y: scroll; */
4950
}
5051

5152
[inverse] {

src/ui/styles/overlay.css

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
bottom: 0;
4949
left: 0;
5050
width: 100%;
51+
overflow-x: hidden;
5152
overflow-y: auto;
5253
transform: translate3d(0, 4rem, 0);
5354
display: block;

tests/actions.js

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ test('getTargets utility works', (t) => {
113113
t.deepEqual(getTargets(state, 'enemy1')[0], room.monsters[1])
114114
t.throws(() => getTargets(state, 'doesntexist'))
115115
t.deepEqual(getTargets(state, 'player')[0], state.player)
116+
t.deepEqual(getTargets(state, 'player0')[0], state.player)
116117
})
117118

118119
test('can manipulate player hp', (t) => {

0 commit comments

Comments
 (0)