@@ -4,26 +4,17 @@ import { EventBus } from '../EventBus'
44import { GameData } from '../../data/GameData.ts'
55import { get_hextiles } from '../../api/get_hextiles.ts'
66import { postCollect } from '../../api/post_collect.ts'
7+ import { useToast , POSITION } from 'vue-toastification'
78
8- function randomData ( scene : Phaser . Scene , x : number , y : number ) {
9- const ret = {
10- scene : scene ,
11- x : x ,
12- y : y ,
13- size : GameData . hexSize ,
14- skew : GameData . skew ,
15- type : '' ,
16- ID : ''
17- }
18- return ret
19- }
9+ const toast = useToast ( )
2010
2111export class Game extends Scene {
2212 private contentContainer ! : Phaser . GameObjects . Container
2313 private dragStartY = 0
2414 private containerStartY = 0
2515 private boothImages : string [ ]
2616 private playerCharacterImage : Phaser . GameObjects . Image | null = null ;
17+ private showAllInfo = false
2718
2819 constructor ( boothImages : string [ ] ) {
2920 super ( 'MainGame' )
@@ -176,14 +167,14 @@ export class Game extends Scene {
176167 const infoBtn = this . add . image ( GameData . screenWidth - 40 , 40 , 'no-eye' ) . setOrigin ( 0.5 ) . setScale ( 0.5 ) . setInteractive ( )
177168 infoBtn . setScrollFactor ( 0 )
178169
179- infoBtn . on ( 'pointerdown' , ( ) => {
180- this . showAllTileInfo ( true )
181- infoBtn . setTexture ( 'eye' )
182- } )
183-
184170 infoBtn . on ( 'pointerup' , ( ) => {
185- this . showAllTileInfo ( false )
186- infoBtn . setTexture ( 'no-eye' )
171+ this . showAllInfo = ! this . showAllInfo
172+ this . showAllTileInfo ( this . showAllInfo )
173+ if ( this . showAllInfo ) {
174+ infoBtn . setTexture ( 'eye' )
175+ } else {
176+ infoBtn . setTexture ( 'no-eye' )
177+ }
187178 } )
188179
189180 EventBus . emit ( 'current-scene-ready' , this )
@@ -263,30 +254,19 @@ export class Game extends Scene {
263254 xCoordinate = 0
264255 }
265256
266- try {
267- const apiResponse = await postCollect ( boothId , xCoordinate )
268- console . log ( 'API 呼叫成功,回傳資料:' , apiResponse )
269- alert ( '板塊收集成功!' )
257+ const apiResponse = await postCollect ( boothId , xCoordinate )
270258
271- const tile = new HexTile ( randomData ( this , pos . x , pos . y ) )
272- this . contentContainer . addAt ( tile , 0 )
273- GameData . path . push ( tile )
274-
275- this . tweens . add ( {
276- targets : this . contentContainer ,
277- y : Math . max ( GameData . screenHeight * 0.5 - pos . y , 0 ) ,
278- duration : 600 ,
279- ease : 'Sine.easeInOut' ,
280- onComplete : ( ) => {
281- this . addCharacterImage ( tile )
282- }
259+ if ( ! apiResponse ?. ok ) {
260+ return toast . error ( `已搜集過此板塊了` , {
261+ position : POSITION . BOTTOM_CENTER ,
262+ timeout : 3000 ,
283263 } )
284- } catch ( error ) {
285- const errorBody = ( error as any ) . body
286- if ( errorBody && errorBody . detail === 'Point already collected' ) {
287- alert ( '你已經收集過這個板塊了!' )
288- }
289264 }
265+
266+ toast . success ( `成功收集到${ apiResponse . body . booth } 的板塊` , {
267+ position : POSITION . BOTTOM_CENTER ,
268+ timeout : 3000 ,
269+ } )
290270 }
291271
292272 showAllTileInfo ( show : boolean ) {
0 commit comments