Skip to content

Commit

Permalink
add freak games
Browse files Browse the repository at this point in the history
  • Loading branch information
crashmax-dev committed Oct 15, 2024
1 parent 65db1fa commit 145e3cc
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 14 deletions.
7 changes: 7 additions & 0 deletions apps/frontend/src/assets/recipes.json
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,13 @@
"description": "Млекопитающее, наиболее близкое к человеку по строению тела.",
"recipes": [["human", "wool"]]
},
{
"id": "freak_games",
"name": "Freak Games",
"description": "Причудливые игры.",
"recipes": [["monkey", "hamster"]],
"ended": true
},
{
"id": "dung",
"name": "Навоз",
Expand Down
2 changes: 2 additions & 0 deletions apps/frontend/src/assets/sprites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ import forest from './sprites/forest.webp'
import fossil from './sprites/fossil.webp'
import france from './sprites/france.webp'
import frankenstein from './sprites/frankenstein.webp'
import freak_games from './sprites/freak_games.webp'
import french_fries from './sprites/french_fries.webp'
import frog from './sprites/frog.webp'
import fruit from './sprites/fruit.webp'
Expand Down Expand Up @@ -658,6 +659,7 @@ export const sprites: Record<string, string> = {
fossil,
france,
frankenstein,
freak_games,
french_fries,
frog,
fruit,
Expand Down
Binary file added apps/frontend/src/assets/sprites/freak_games.webp
Binary file not shown.
28 changes: 16 additions & 12 deletions apps/frontend/src/components/alchemy-board.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import { useElementBounding, useEventListener } from '@vueuse/core'
import { useBoard } from '@/stores/use-board.js'
import { useGame } from '@/stores/use-game.js'
import { useOpenedElements } from '@/stores/use-opened-elements.js'
import { API_URL } from '@/constants.js'
import recipes from '@/assets/recipes.json'
import { useSounds } from '@/stores/use-sounds'
import type { AlchemyElement, AlchemyElementOnBoard, Position } from '@/types.js'
const game = useGame()
const openedElements = useOpenedElements()
const sounds = useSounds()
const board = useBoard()
const boardRef = ref<HTMLDivElement>()
const boardBounding = useElementBounding(boardRef)
Expand Down Expand Up @@ -41,20 +42,23 @@ function checkCollision(boardElement: AlchemyElementOnBoard): void {
boardElement.position.y < boardItem.position.y + board.elementSize.height &&
boardElement.position.y + board.elementSize.height > boardItem.position.y
) {
checkRecipe([boardElement.id, boardItem.id])
.then((element) => {
if (!element) return
removeElement([boardItem, boardElement])
сreateElement(boardItem, element)
openedElements.addElement(element)
})
const element = checkRecipe([boardElement.id, boardItem.id])
if (!element) return
if (element.id === 'freak_games') {
sounds.freakGamesAudio.play()
}
removeElement([boardItem, boardElement])
createElement(boardItem, element)
openedElements.addElement(element)
}
}
}
async function checkRecipe(
function checkRecipe(
recipe: [string, string]
): Promise<AlchemyElementOnBoard | undefined> {
): AlchemyElementOnBoard | undefined {
for (const element of recipes) {
if (element.recipes.length === 0) continue
for (const elementRecipe of element.recipes) {
Expand Down Expand Up @@ -83,7 +87,7 @@ function removeElement(boardElement: AlchemyElementOnBoard[]): void {
})
}
function сreateElement(
function createElement(
boardElement: AlchemyElementOnBoard,
newElement: AlchemyElement,
isCopy = false
Expand Down Expand Up @@ -121,7 +125,7 @@ useEventListener(boardRef, 'dblclick', (event) => {
v-bind:alchemy-element="boardElement"
v-bind:board-bounding="boardBounding"
v-on:position="updatePosition(boardElement, $event)"
v-on:update:clone-element="сreateElement(boardElement, $event, true)"
v-on:update:clone-element="createElement(boardElement, $event, true)"
v-on:update:remove-element="removeElement([$event, boardElement])"
/>
</div>
Expand Down
5 changes: 5 additions & 0 deletions apps/frontend/src/stores/use-sounds.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { defineStore } from 'pinia'
import { sounds } from '@/assets/sounds'
import freakGames from '@/assets/freak-games.mp3'

export const useSounds = defineStore('sounds', () => {
const freakGamesAudio = new Audio(freakGames)
freakGamesAudio.volume = 1

const createAudio = new Audio(sounds.create)
createAudio.volume = 0.5

Expand All @@ -12,6 +16,7 @@ export const useSounds = defineStore('sounds', () => {
takingAudio.volume = 0.7

return {
freakGamesAudio,
createAudio,
createNewAudio,
takingAudio
Expand Down
1 change: 0 additions & 1 deletion apps/frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ const configurationByType: Record<ProxyLogType, (proxy: HttpProxy.Server) => voi

export default defineConfig({
server: {
port: 3001,
proxy: {
'/api': {
target: 'http://127.0.0.1:3000/api',
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "pnpm --filter=./apps/* run dev",
"dev": "pnpm --filter=./apps/frontend run dev",
"_dev": "pnpm --filter=./apps/* run dev",
"build": "pnpm --filter=./apps/* run build",
"build:frontend": "pnpm --filter=./apps/frontend run build",
"lint": "pnpm --filter=./apps/* run lint"
Expand Down

0 comments on commit 145e3cc

Please sign in to comment.