Skip to content
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
7 changes: 7 additions & 0 deletions composables/actions/win.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { CardsCollectionItem } from '@nuxt/content'
import type { BoardCard } from '~/types/Board'
import type { Action } from '~/types/Action'

export const win: Action = (_action: CardsCollectionItem['interactions'][0]['actions'][0], _baseCard: BoardCard, _interactingCard: BoardCard) => {
navigateTo('/win', { external: true })
}
2 changes: 2 additions & 0 deletions composables/useAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { travel } from './actions/travel'
import { destroyAll } from './actions/destroyAll'
import { destroyRandom } from './actions/destroyRandom'
import { random } from './actions/random'
import { win } from './actions/win'
import type { BoardCard } from '~/types/Board'
import type { Action } from '~/types/Action'
import { reveal } from '~/composables/actions/reveal'
Expand All @@ -33,6 +34,7 @@ const allActions: { [key: string]: Action } = {
destroyRandom,
random,
reveal,
win,
}

export const useAction = () => {
Expand Down
8 changes: 8 additions & 0 deletions composables/useCardTimer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ export const useCardTimer = () => {
}, 10)
}

const reset = (card: BoardCard) => {
if (card.timerTimeoutId) clearTimeout(card.timerTimeoutId)
if (card.timerIntervalId) clearInterval(card.timerIntervalId)

card.timerStartAt = card.timerFinishAt = card.timerProgress = card.timerTimeoutId = card.timerIntervalId = undefined
}

return {
init,
reset,
}
}
5 changes: 5 additions & 0 deletions composables/useInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const useInteraction = (draggingCard: BoardCard) => {
const boardStore = useBoardStore()
const { runActions } = useAction()
const { startCooldown } = useCardCooldown()
const { reset } = useCardTimer()

const getAvailableInteractions = (boardCard: BoardCard): string[] => {
return (boardCard.card.interactions ?? []).map(interaction => interaction.card)
Expand Down Expand Up @@ -43,6 +44,10 @@ export const useInteraction = (draggingCard: BoardCard) => {
}

boardCard.currentInteraction = interaction
if (boardCard.card.timer?.resetWhenCardIsStacked) {
reset(boardCard)
}

if ((interaction.time ?? 0) <= 0) {
runInteractionActions(boardCard)
return
Expand Down
1 change: 1 addition & 0 deletions content.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default defineContentConfig({
onSpawn: actionsType,
timer: z.object({
time: z.number().positive().default(0),
resetWhenCardIsStacked: z.boolean().default(false),
actions: actionsType,
}).optional(),
}),
Expand Down
6 changes: 4 additions & 2 deletions content/cards/hyperdrive.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"time": 3,
"actions": [
{
"type": "travel"
"type": "travel",
"amount": 10
},
{
"type": "destroy"
Expand All @@ -36,7 +37,8 @@
"time": 3,
"actions": [
{
"type": "travel"
"type": "travel",
"amount": 10
},
{
"type": "destroy"
Expand Down
14 changes: 13 additions & 1 deletion content/cards/pirate.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,17 @@
}
]
}
]
],
"timer": {
"time": 12,
"resetWhenCardIsStacked": true,
"actions": [
{
"type": "destroy"
},
{
"type": "destroyRandom"
}
]
}
}
24 changes: 24 additions & 0 deletions content/cards/rocket.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@
"amount": 5
}
]
},
{
"card": "helmsman",
"time": 5,
"infinite": true,
"consumeContainer": true,
"actions": [
{
"type": "travel",
"amount": 7
}
]
},
{
"card": "helmsman-instructor",
"time": 5,
"infinite": true,
"consumeContainer": true,
"actions": [
{
"type": "travel",
"amount": 7
}
]
}
]
}
6 changes: 5 additions & 1 deletion content/events/win.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
"icon": "material-symbols:flag",
"type": "positive",
"hidden": true,
"actions": []
"actions": [
{
"type": "win"
}
]
}
10 changes: 4 additions & 6 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ watchOnce(container, () => {
addPercentage('soldier', 10, 75)

addPercentage('rocket', 50, 50)
addPercentage('trade-link-broken', 90, 75)
addPercentage('trade-link', 90, 50)

addPercentage('fuel', 35, 25, 3)
addPercentage('fuel', 45, 25, 3)
addPercentage('money', 50, 25, 400)
addPercentage('metal', 50, 25, 5)
addPercentage('metal', 55, 25, 5)

addPercentage('flux-generator', 55, 80)
addPercentage('radar', 40, 100)
addPercentage('radar', 40, 100)
addPercentage('flux-generator', 50, 80)
})
</script>

Expand Down
19 changes: 19 additions & 0 deletions pages/win.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<template>
<div class="!mt-20 container !mx-auto text-center text-green-200">
<h1 class="!text-8xl !font-bold">
You won!
</h1>

<p class="text-2xl !mt-4">
But unfortunately, you are lost in the depth of space. Well, someone is probably sad about that 😰. Anyway, thanks for playing!
</p>

<UButton
class="!mt-8 !bg-neutral-300 !py-4 !px-10 cursor-pointer !rounded-md !text-neutral-900"
color="neutral"
@click="navigateTo('/', { external: true })"
>
Retry
</UButton>
</div>
</template>
4 changes: 4 additions & 0 deletions stores/BoardStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ export const useBoardStore = defineStore('board', () => {
card.parentCard.interactionTimeoutId = undefined
card.parentCard.interactionFinishAt = undefined
card.parentCard.currentInteraction = undefined

if (card.parentCard.card.timer?.resetWhenCardIsStacked) {
init(card.parentCard)
}
}

function unstackCard(card: BoardCard, position: { x: number, y: number }) {
Expand Down