Skip to content

Commit 187e80e

Browse files
committed
fix: player can click on screen after destroyed
1 parent 60f889f commit 187e80e

4 files changed

Lines changed: 17 additions & 6 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
.env
3+
data
34
types

src/player/menu.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { destroy_inventory, display_menu, Menus } from '../player_menu.js'
1+
import { destroy_menu, display_menu, Menus } from '../player_menu.js'
22
import freeze_player from '../freeze_player.js'
33
import { SCREENS } from '../settings.js'
44
import { Context } from '../events.js'
@@ -31,7 +31,7 @@ export default {
3131
})
3232

3333
events.on(Context.SCREEN_INTERRACT, payload => {
34-
const { x, y } = payload
34+
const { x, y, screen_id } = payload
3535

3636
const click_position = {
3737
x,
@@ -50,6 +50,7 @@ export default {
5050
}
5151

5252
console.log('position:', click_position)
53+
console.log('screen:', screen_id)
5354

5455
if (is_inside(interactables.stats, click_position)) {
5556
display_menu({
@@ -77,7 +78,7 @@ export default {
7778
const screenids = [SCREENS.player_screen, SCREENS.clone_background]
7879
client.on('steer_vehicle', ({ jump }) => {
7980
if (jump === 0x2) {
80-
destroy_inventory(client, world, entityids, screenids)
81+
destroy_menu(client, world, entityids, screenids)
8182
}
8283
})
8384

src/player/screen.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ const mcData = minecraftData(VERSION)
1414
const { nearestMatch } = mapcolors
1515
const { createCanvas } = canvas
1616

17+
const SPAWNED_SCREENS = {
18+
screens: [],
19+
}
20+
1721
export function register_screen({ id, size: { width, height } }) {
1822
return world => ({
1923
...world,
@@ -106,6 +110,8 @@ export function spawn_screen(
106110
})
107111
}
108112
}
113+
114+
SPAWNED_SCREENS.screens[SPAWNED_SCREENS.screens.length] = screen_id
109115
}
110116

111117
export function update_screen(
@@ -154,12 +160,15 @@ export function update_screen(
154160

155161
export function destroy_screen({ client, world }, { screen_id }) {
156162
const { size, start_id } = world.screens[screen_id]
157-
158163
client.write('entity_destroy', {
159164
entityIds: Array.from({
160165
length: size.width * size.height,
161166
}).map((v, index) => start_id + index),
162167
})
168+
169+
SPAWNED_SCREENS.screens = SPAWNED_SCREENS.screens.filter(
170+
id => id !== screen_id
171+
)
163172
}
164173

165174
export function copy_canvas(old_canvas) {
@@ -214,7 +223,7 @@ export default {
214223
const { position } = state
215224
for (const [screen_id, screen] of Object.entries(world.screens)) {
216225
const intersect = screen_ray_intersection(screen, position)
217-
if (intersect) {
226+
if (intersect && SPAWNED_SCREENS.screens.includes(screen_id)) {
218227
const { x, y } = intersect
219228
events.emit(Context.SCREEN_INTERRACT, {
220229
x,

src/player_menu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export async function display_menu({
111111
}
112112
}
113113

114-
export function destroy_inventory(client, world, entityIds, screenIds) {
114+
export function destroy_menu(client, world, entityIds, screenIds) {
115115
client.write('entity_destroy', {
116116
entityIds,
117117
})

0 commit comments

Comments
 (0)