Skip to content

Commit 20e0dba

Browse files
authored
Merge pull request #16 from COSCUP/dev
Final version
2 parents e77caae + 6e46c62 commit 20e0dba

File tree

8 files changed

+51
-63
lines changed

8 files changed

+51
-63
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"qrcode.vue": "^3.6.0",
3636
"vue": "3.5.13",
3737
"vue-qrcode-reader": "^5.7.3",
38-
"vue-router": "4"
38+
"vue-router": "4",
39+
"vue-toastification": "2.0.0-rc.5"
3940
},
4041
"devDependencies": {
4142
"@antfu/eslint-config": "^4.14.1",

pnpm-lock.yaml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api/get_booths.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export async function get_booths_images() {
2121
const res = await fetch(`${API_BASE_URL}/booths`)
2222
if (!res.ok) throw new Error(`HTTP error! status: ${res.status}`)
2323
const data = await res.json()
24-
const boothsImages = data.reduce((acc: Record<string, string>, booth: { name: string, logo: string }) => {
24+
const boothsImages = data.reduce((acc: Record<string, string>, booth: any) => {
25+
if (booth.type !== 'BOOTHS') return acc
26+
2527
if (booth.name && booth.logo) {
2628
acc[booth.name] = booth.logo
2729
}

src/api/post_collect.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,15 @@ export async function postCollect(boothId: string, xCoordinate: number) {
2424
body: JSON.stringify(requestBody),
2525
});
2626

27-
if (!response.ok) {
28-
let errorBody = {};
29-
try {
30-
errorBody = await response.json();
31-
} catch (e) {
32-
errorBody = { message: await response.text() };
33-
}
34-
const error = new Error(`HTTP error! Status: ${response.status}`);
35-
(error as any).body = errorBody;
36-
throw error;
37-
}
38-
39-
const data = await response.json();
40-
return data;
27+
const body = await response.json();
28+
29+
return {
30+
ok: response.ok,
31+
status: response.status,
32+
body: body
33+
};
34+
4135
} catch (error) {
4236
console.error('Failed to post collect data:', error);
43-
if ((error as any).body) {
44-
console.error('Error body:', (error as any).body);
45-
}
46-
throw error;
4737
}
4838
}

src/components/MyProfile.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,8 @@ const closeAvatarModal = () => {
291291
}
292292
293293
.display-score {
294-
font-size: 15px;
295-
font-family: 'Zen Maru Gothic', sans-serif;
294+
font-size: 20px;
295+
font-family: 'M PLUS Rounded 1c', sans-serif;
296296
font-weight: bold;
297297
color: #4a4a4a;
298298
text-align: center;

src/components/PhaserGame.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ watch([showPopup, popupData], async ([isOpen, data]) => {
167167
<div v-for="comment in comments" :key="comment.msg_id" class="comment-item">
168168
<div class="comment-content">
169169
<div class="comment-header">
170-
<span class="comment-user">{{ comment.user.name + "." + comment.user.title }}</span>
170+
<span class="comment-user">{{ comment.user.name + "." + (comment.user.title || "新手小啄") }}</span>
171171
<span class="comment-time">{{ formatTime(comment.created_at) }}</span>
172172
</div>
173173
<p class="comment-message">{{ comment.content }}</p>

src/game/scenes/Game.ts

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,17 @@ import { EventBus } from '../EventBus'
44
import { GameData } from '../../data/GameData.ts'
55
import { get_hextiles } from '../../api/get_hextiles.ts'
66
import { 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

2111
export 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) {

src/main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { createApp } from 'vue'
22
import App from './App.vue'
33
import router from './config'
4+
import Toast from 'vue-toastification'
5+
import 'vue-toastification/dist/index.css';
46

57
const app = createApp(App)
68
app.use(router)
9+
app.use(Toast)
710
app.mount('#app')

0 commit comments

Comments
 (0)