Skip to content

Commit

Permalink
reload
Browse files Browse the repository at this point in the history
  • Loading branch information
eguneys committed Dec 28, 2023
1 parent d77e3ce commit 823947d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/solitaire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,11 @@ export class SolitairePlay extends Play {
let title = this.make(SolitaireGameTitle, Vec2.make(640, 16), {})
let scoreboard = this.make(ScoreBoard, Vec2.make(16, 860), {})

make_solitaire_back(game).then(back_res => {
const on_score = (_: number) => {
scoreboard.score = _
}

make_solitaire_back(game, on_score).then(back_res => {
game.back_res = back_res
game._collect_pov()
Sound.music('main')
Expand Down
13 changes: 11 additions & 2 deletions src/solitaire_back.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SolitaireGame } from './solitaire_game'
import { Settings, Cards, Solitaire, SolitairePov, Game as OSolitaireGame, GamePov, IMoveType } from 'lsolitaire'
import { Settings, Cards, Solitaire, SolitairePov, Game as OSolitaireGame, GamePov, IMoveType, TableuToTableu } from 'lsolitaire'
import { SolitaireStore } from './store'
import { arr_random } from './util'

Expand All @@ -11,7 +11,7 @@ export type BackRes = {
}


export const make_solitaire_back = async (game: SolitaireGame, on_score: (_: number) => void, on_settings: (_: Settings) => void): Promise<BackRes> => {
export const make_solitaire_back = async (game: SolitaireGame, on_score: (_: number) => void): Promise<BackRes> => {

let back = solitaire_back
let game_pov = await back.get_pov()
Expand All @@ -28,6 +28,10 @@ export const make_solitaire_back = async (game: SolitaireGame, on_score: (_: num
game.cant(cmd, data)
} else {
game.apply(res)

game_pov.finalize_apply_pov(res)

back.get_pov().then(_ => on_score(_.score))
}
})
} else {
Expand All @@ -37,12 +41,15 @@ export const make_solitaire_back = async (game: SolitaireGame, on_score: (_: num
undo() {
if (game_pov.can_undo) {
game_pov.undo_pov()

back.undo().then(res => {
if (!res) {
game.cant_undo()
} else {
game_pov.undo(res)
game.undo(res)

back.get_pov().then(_ => on_score(_.score))
}
})
} else {
Expand All @@ -55,6 +62,8 @@ export const make_solitaire_back = async (game: SolitaireGame, on_score: (_: num
game_pov = await solitaire_back.get_pov()

game.new_game()

back.get_pov().then(_ => on_score(_.score))
}
}

Expand Down
18 changes: 16 additions & 2 deletions src/solitaire_game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class Stock extends Play {
}

add_waste_hidden(cards: Array<Card>) {
cards.forEach(_ => _.flip_back())
this.waste_hidden.add_cards(cards)
}

Expand Down Expand Up @@ -534,9 +535,16 @@ export class SolitaireGame extends Play {
foundation.release_all().forEach(_ => this.cards.release(_))
})

this.recycle_view.visible = pov.can_recycle
this._refresh_recycle()
//this.recycle_view.visible = pov.can_recycle

stock.add_waste_hidden(pov.stock.hidden.cards.map(card => this.cards.borrow()))
stock.add_stocks(pov.stock.stock.cards.map(card => this.cards.borrow()))
stock.add_waste(pov.stock.waste.cards.map(card => {
let _ = this.cards.borrow()
_.card = card
return _
}))

n_seven.map(i => {

Expand Down Expand Up @@ -692,7 +700,13 @@ export class SolitaireGame extends Play {


cant(cmd: IMoveType<SolitairePov, Solitaire>, data: any) {
if (cmd === TableuToFoundation) {
if (cmd === WasteToTableu) {
this._release_cancel_drag()
} else if (cmd === WasteToFoundation) {
this._release_cancel_drag()
} else if (cmd === TableuToTableu) {
this._release_cancel_drag()
} else if (cmd === TableuToFoundation) {
this._release_cancel_drag()
} else if (cmd === WasteToFoundation) {
this._release_cancel_drag()
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"target": "ESNext",
"useDefineForClassFields": true,
"module": "ESNext",
Expand Down

0 comments on commit 823947d

Please sign in to comment.