Skip to content

Commit

Permalink
Merge pull request #24 from michaelchadwick/track-moves
Browse files Browse the repository at this point in the history
Track moves
  • Loading branch information
michaelchadwick authored Oct 26, 2024
2 parents ed62c54 + fd8d87b commit 165f404
Show file tree
Hide file tree
Showing 31 changed files with 606 additions and 71 deletions.
92 changes: 92 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Continuous Integration

on:
push:
branches:
- main
- master
pull_request:

concurrency:
group: ci-${{ github.head_ref || github.ref }}
cancel-in-progress: true

env:
COVERAGE: false

jobs:
lint:
name: "Lint"
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
- name: Install Dependencies
run: pnpm install
- name: Lint
run: pnpm lint

test:
name: Test
runs-on: ubuntu-latest
timeout-minutes: 15
needs: [lint]

strategy:
fail-fast: false
matrix:
node-version: [20]
workspace:
- frontend
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: pnpm
- name: Install Dependencies
run: pnpm install
- name: Cypress run
uses: cypress-io/github-action@v6
# env:
# COVERAGE: true
# - name: Store Code Coverage
# uses: actions/upload-artifact@v4
# with:
# name: coverage-${{matrix.workspace}}
# path: ./${{matrix.workspace}}/coverage
# retention-days: 1
# - uses: actions/upload-artifact@v4
# if: failure()
# with:
# name: replay-${{matrix.workspace}}-test.json
# path: ./${{matrix.workspace}}/test-execution-*.json
# retention-days: 7

# upload-coverage:
# name: Upload code coverage
# runs-on: ubuntu-latest
# needs: test
# if: ${{ always() }}
# steps:
# - uses: actions/checkout@v4
# - uses: actions/download-artifact@v4
# with:
# name: coverage
# path: coverage
# - run: ls -lh
# - run: ls -lh coverage
# - name: Publish code coverage
# uses: paambaati/[email protected]
# env:
# CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
# with:
# coverageLocations: |
# coverageLocations: ${{github.workspace}}/coverage/lcov.info:lcov
2 changes: 1 addition & 1 deletion .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pnpm test
pnpm test:coverage
8 changes: 5 additions & 3 deletions assets/css/modal/root.css
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,16 @@
}

.modal-text {
align-items: center;
display: flex;
flex-direction: column;
gap: 0.5em;
margin: 10px 0;
/* max-height: 500px; */
overflow-y: auto;
padding: 0 16px;
width: 100%;
}
.modal-text div.para {
padding: 10px;
text-align: center;
}
.modal-text div.para.highlighted {
Expand Down Expand Up @@ -269,5 +271,5 @@
color: var(--dark-color);
}
.modal-text .share {
margin: 1rem auto 0;
margin: 0 auto;
}
2 changes: 2 additions & 0 deletions assets/js/app/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const DECKDLE_DEFAULT_CONFIG = {
synthSFX: null,
}
const DECKDLE_DEFAULT_STATE = {
actions: [],
base: [],
comboMax: 0,
gameState: 'IN_PROGRESS',
Expand All @@ -38,6 +39,7 @@ const DECKDLE_DEFAULT_STATE = {
tableau: {},
}
const DECKDLE_DEFAULT_SETTINGS = {
animationDisplay: true,
comboCounter: true,
darkMode: false,
firstTime: true,
Expand Down
9 changes: 9 additions & 0 deletions assets/js/app/lib/actions/action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* lib/actions/action.js */
/* class definition for Action */
/* eslint-disable no-unused-vars */

class Action {
constructor(type) {
this.type = type
}
}
11 changes: 11 additions & 0 deletions assets/js/app/lib/actions/stock_action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* lib/actions/stock_action.js */
/* class definition for StockAction */
/* global Action */
/* eslint-disable no-unused-vars */

class StockAction extends Action {
constructor() {
super()
this.type = 'stock'
}
}
13 changes: 13 additions & 0 deletions assets/js/app/lib/actions/tableau_action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* lib/actions/tableau_action.js */
/* class definition for TableauAction */
/* global Action */
/* eslint-disable no-unused-vars */

class TableauAction extends Action {
constructor(colId, rowId) {
super()
this.type = 'tableau'
this.colId = parseInt(colId)
this.rowId = parseInt(rowId)
}
}
11 changes: 11 additions & 0 deletions assets/js/app/lib/actions/undo_action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* lib/actions/undo_action.js */
/* class definition for UndoAction */
/* global Action */
/* eslint-disable no-unused-vars */

class UndoAction extends Action {
constructor() {
super()
this.type = 'undo'
}
}
88 changes: 50 additions & 38 deletions assets/js/app/lib/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,66 @@
/* global Deckdle */

Deckdle._animateCSS = (element, animation, loop, prefix = 'animate__') => {
// We create a Promise and return it
return new Promise((resolve) => {
const animationName = `${prefix}${animation}`
const node = document.querySelector(element)

node.classList.add(`${prefix}animated`, animationName)

if (loop) {
node.classList.add(`${prefix}infinite`)
}

// When the animation ends, we clean the classes and resolve the Promise
function handleAnimationEnd(event) {
event.stopPropagation()
node.classList.remove(`${prefix}animated`, `${prefix}infinite`, animationName)
resolve('Animation ended')
}

node.addEventListener('animationend', handleAnimationEnd, { once: true })
})
if (Deckdle.settings.animationDisplay) {
// We create a Promise and return it
return new Promise((resolve) => {
const animationName = `${prefix}${animation}`
const node = document.querySelector(element)

node.classList.add(`${prefix}animated`, animationName)

if (loop) {
node.classList.add(`${prefix}infinite`)
}

// When the animation ends, we clean the classes and resolve the Promise
function handleAnimationEnd(event) {
event.stopPropagation()
node.classList.remove(`${prefix}animated`, `${prefix}infinite`, animationName)
resolve('Animation ended')
}

node.addEventListener('animationend', handleAnimationEnd, { once: true })
})
} else {
return Promise.resolve()
}
}

Deckdle._winAnimation = async (debug = false) => {
Deckdle._logStatus('[ANIM] _winAnimation started')
return new Promise((resolve) => {
Deckdle._animateCSS('#base', 'tada')
if (Deckdle.settings.animationDisplay) {
Deckdle._logStatus('[ANIM] _winAnimation started')
return new Promise((resolve) => {
Deckdle._animateCSS('#base', 'tada')

if (!debug) {
Deckdle.ui._disableUI()
}
if (!debug) {
Deckdle.ui._disableUI()
}

setTimeout(() => resolve('[ANIM] _winAnimation ended'), 1000)
})
setTimeout(() => resolve('[ANIM] _winAnimation ended'), 1000)
})
} else {
return Promise.resolve()
}
}

Deckdle._loseAnimation = async (debug = false) => {
Deckdle._logStatus('[ANIM] _loseAnimation started')
return new Promise((resolve) => {
Deckdle.ui._disableUI()
if (Deckdle.settings.animationDisplay) {
Deckdle._logStatus('[ANIM] _loseAnimation started')
return new Promise((resolve) => {
Deckdle.ui._disableUI()

setTimeout(() => {
resolve('[ANIM] _loseAnimation ended')
setTimeout(() => {
resolve('[ANIM] _loseAnimation ended')

if (debug) {
Deckdle.ui._enableUI()
}
}, 1000)
})
if (debug) {
Deckdle.ui._enableUI()
}
}, 1000)
})
} else {
return Promise.resolve()
}
}

Deckdle._resetCardsDuration = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/* lib/cards/base.js */
/* functions for base */
/* global Deckdle */
/* eslint-disable no-unused-vars */

// TODO
class Base {}

Deckdle._isBaseEmpty = () => {
return Deckdle.__getState()['base'].length == 0
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/* lib/cards/stock.js */
/* functions for stock */
/* global Deckdle */
/* global Deckdle, StockAction */
/* eslint-disable no-unused-vars */

// TODO
class Stock {}

Deckdle._stockCount = () => {
return Deckdle.__getState()['stock'].length
Expand All @@ -25,6 +29,7 @@ Deckdle._moveCardFromStockToBase = () => {

Deckdle._resetCombo()

Deckdle.__addAction(new StockAction())
Deckdle.__setState('lastPlayedTime', new Date().getTime())
Deckdle._saveGame()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/* lib/cards/tableau.js */
/* functions for tableau */
/* global Deckdle, Card */
/* global Deckdle, Card, TableauAction, UndoAction */
/* eslint-disable no-unused-vars */

// TODO
class Tableau {}

Deckdle._tableauCount = (cards = null) => {
let tableau = null
Expand Down Expand Up @@ -98,6 +102,7 @@ Deckdle._undoLastTableauMove = () => {
tableauCards[card.col][card.row].status = 1
Deckdle._removeCardFromBase(card)

Deckdle.__addAction(new UndoAction())
Deckdle.__setState('tableau', tableauCards)
Deckdle._saveGame()
}
Expand Down Expand Up @@ -126,6 +131,7 @@ Deckdle._onTableauClick = (card, colId, rowId) => {

Deckdle.ui._moveCardToBase('tableau')

Deckdle.__addAction(new TableauAction(colId.substring(colId.length - 1), rowId))
Deckdle.__setState('base', base)
Deckdle._saveGame()

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion assets/js/app/lib/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Deckdle._displayGameState = () => {
var label = k
var value = states[state][key][k]

const consoleKeys = ['base', 'stock', 'tableau']
const consoleKeys = ['actions', 'base', 'stock', 'tableau']

if (consoleKeys.includes(label)) {
html += `<dd><code>${label}:</code></dd><dt>see dev console (⌥⌘I)</dt>`
Expand Down
16 changes: 16 additions & 0 deletions assets/js/app/lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,22 @@ Deckdle.__getGameType = () => {
return Deckdle.__getState()['gameType'] ?? DECKDLE_DEFAULT_GAMETYPE
}

Deckdle.__addAction = (action) => {
const actions = Deckdle.__getState().actions
actions.push(action)
Deckdle.__setState('actions', actions)
}
Deckdle.__getActionCount = (countUndos = false) => {
if (countUndos) {
return Deckdle.__getState().actions.length
} else {
return Deckdle.__getState().actions.filter((a) => a.type != 'undo').length
}
}
Deckdle.__getUndoCount = () => {
return Deckdle.__getState().actions.filter((a) => a.type == 'undo').length
}

Deckdle.__getConfig = () => {
return Deckdle.config || undefined
}
Expand Down
Loading

0 comments on commit 165f404

Please sign in to comment.