From f72a1af20091240f299a7f8ff1d1235caae21168 Mon Sep 17 00:00:00 2001 From: HexaField Date: Sat, 17 Aug 2024 11:48:51 +1000 Subject: [PATCH] non-3d-page-load-optimizations --- src/old examples/matchmaking.tsx | 21 +++++++++++---------- src/old examples/matchmaking2.tsx | 7 ++++--- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/old examples/matchmaking.tsx b/src/old examples/matchmaking.tsx index 4d1a3c5..5be856c 100644 --- a/src/old examples/matchmaking.tsx +++ b/src/old examples/matchmaking.tsx @@ -8,17 +8,18 @@ import { Engine } from '@etherealengine/ecs/src/Engine' import { MatchmakingTicketAssignment, OpenMatchTicket } from '@etherealengine/matchmaking/src/interfaces' import { matchTicketAssignmentPath } from '@etherealengine/matchmaking/src/match-ticket-assignment.schema' import { matchTicketPath } from '@etherealengine/matchmaking/src/match-ticket.schema' +import { API } from '@etherealengine/common' const gameModes = ['ctf', 'tournament'] async function findCurrentTicketData() { - const { data } = await Engine.instance.api.service(matchUserPath).find() + const { data } = await API.instance.service(matchUserPath).find() if (data.length) { const matchUser = data[0] - const ticket = await Engine.instance.api.service(matchTicketPath).get(matchUser.ticketId) + const ticket = await API.instance.service(matchTicketPath).get(matchUser.ticketId) if (!ticket) { // ticket is outdated - delete match-user row - await Engine.instance.api.service(matchUserPath).remove(matchUser.id) + await API.instance.service(matchUserPath).remove(matchUser.id) } else { const gamemode = ticket.search_fields.tags[0] return { id: ticket.id, gamemode } @@ -84,15 +85,15 @@ const Page = () => { setIsUpdating(true) let serverTicket: OpenMatchTicket try { - serverTicket = await Engine.instance.api.service(matchTicketPath).create({ gamemode }) + serverTicket = await API.instance.service(matchTicketPath).create({ gamemode }) } catch (e) { - const matchUser = (await Engine.instance.api.service(matchUserPath).find()).data[0] - serverTicket = await Engine.instance.api.service(matchTicketPath).get(matchUser.ticketId) + const matchUser = (await API.instance.service(matchUserPath).find()).data[0] + serverTicket = await API.instance.service(matchTicketPath).get(matchUser.ticketId) if (!serverTicket) { // cleanup - await Engine.instance.api.service(matchUserPath).remove(matchUser.id) + await API.instance.service(matchUserPath).remove(matchUser.id) // create new - serverTicket = await Engine.instance.api.service(matchTicketPath).create({ gamemode }) + serverTicket = await API.instance.service(matchTicketPath).create({ gamemode }) } } @@ -114,14 +115,14 @@ const Page = () => { if (!ticketId) { return } - await Engine.instance.api.service(matchTicketPath).remove(ticketId) + await API.instance.service(matchTicketPath).remove(ticketId) setTicketData(undefined) // setStatus('') } function getAssignment(ticketId: string): Promise { return ( - Engine.instance.api.service(matchTicketAssignmentPath).get(ticketId) as Promise + API.instance.service(matchTicketAssignmentPath).get(ticketId) as Promise ).then((assignment) => { console.log('assignment', ticketId, assignment) return assignment diff --git a/src/old examples/matchmaking2.tsx b/src/old examples/matchmaking2.tsx index faf910c..2ae5424 100644 --- a/src/old examples/matchmaking2.tsx +++ b/src/old examples/matchmaking2.tsx @@ -8,6 +8,7 @@ import { Engine } from '@etherealengine/ecs/src/Engine' import { OpenMatchTicketAssignment } from '@etherealengine/matchmaking/src/interfaces' import { matchTicketAssignmentPath } from '@etherealengine/matchmaking/src/match-ticket-assignment.schema' import { matchTicketPath } from '@etherealengine/matchmaking/src/match-ticket.schema' +import { API } from '@etherealengine/common' const Page = () => { const [renderTrigger, updRenderTrigger] = useState() @@ -23,10 +24,10 @@ const Page = () => { async function newTicket() { let ticket try { - ticket = await Engine.instance.api.service(matchTicketPath).create({ gamemode: 'mode.demo' }) + ticket = await API.instance.service(matchTicketPath).create({ gamemode: 'mode.demo' }) } catch (e) { alert('You already searching for game') - const matchUser = (await Engine.instance.api.service(matchUserPath).find()).data[0] + const matchUser = (await API.instance.service(matchUserPath).find()).data[0] console.log('matchUser', matchUser) ticket = { id: matchUser.ticketId } } @@ -49,7 +50,7 @@ const Page = () => { function getAssignment(ticketId: string): Promise { return ( - Engine.instance.api.service(matchTicketAssignmentPath).get(ticketId) as Promise + API.instance.service(matchTicketAssignmentPath).get(ticketId) as Promise ).then((assignment) => { console.log('assignment', ticketId, assignment) connections.current[ticketId] = assignment.connection