Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
oetzit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
commul
oetzit
Commits
8e77a921
Commit
8e77a921
authored
2 years ago
by
Paolo Brasolin
Browse files
Options
Downloads
Patches
Plain Diff
refactor: #fe bubble device id handling up to Game
parent
32e186cc
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
frontend/src/js/fight_scene.ts
+4
-15
4 additions, 15 deletions
frontend/src/js/fight_scene.ts
frontend/src/js/game.ts
+28
-0
28 additions, 0 deletions
frontend/src/js/game.ts
frontend/src/js/leaderboard_scene.ts
+5
-8
5 additions, 8 deletions
frontend/src/js/leaderboard_scene.ts
with
37 additions
and
23 deletions
frontend/src/js/fight_scene.ts
+
4
−
15
View file @
8e77a921
import
MainScene
,
{
InputStatus
}
from
"
./main_scene
"
;
import
Foe
from
"
./foe
"
;
import
Game
from
"
./game
"
;
import
Spear
from
"
./spear
"
;
import
backend
from
"
./backend
"
;
import
BackgroundScene
from
"
./background_scene
"
;
...
...
@@ -13,13 +14,11 @@ import {
sawtoothRamp
,
}
from
"
./utils
"
;
const
DEVICE_KEY
=
"
OETZIT/DEVICE_ID
"
;
export
default
class
FightScene
extends
MainScene
{
game
!
:
Game
;
tapoutEnabled
=
true
;
typewriterEnabled
=
true
;
beDevice
:
Types
.
Device
;
beGame
:
Types
.
Game
;
spawner
:
Phaser
.
Time
.
TimerEvent
;
...
...
@@ -32,7 +31,6 @@ export default class FightScene extends MainScene {
this
.
planMusicChanges
();
this
.
planWaveAnnouncements
();
await
this
.
initBeDevice
();
await
this
.
initBeGame
();
this
.
spawnFoes
();
...
...
@@ -105,19 +103,10 @@ export default class FightScene extends MainScene {
//=[ BE initialization ]======================================================
async
initBeDevice
()
{
const
deviceId
=
sessionStorage
.
getItem
(
DEVICE_KEY
);
if
(
deviceId
===
null
)
{
this
.
beDevice
=
(
await
backend
.
createDevice
()).
data
;
}
else
{
this
.
beDevice
=
(
await
backend
.
getDevice
(
deviceId
)).
data
;
}
sessionStorage
.
setItem
(
DEVICE_KEY
,
this
.
beDevice
.
id
);
}
async
initBeGame
()
{
const
deviceId
=
this
.
game
.
getDeviceId
();
this
.
beGame
=
(
await
backend
.
createGame
(
this
.
beD
evice
.
i
d
,
{
await
backend
.
createGame
(
d
evice
I
d
,
{
began_at
:
new
Date
().
toISOString
(),
began_at_gmtm
:
this
.
getGameTime
(),
})
...
...
This diff is collapsed.
Click to expand it.
frontend/src/js/game.ts
+
28
−
0
View file @
8e77a921
...
...
@@ -9,6 +9,11 @@ import PauseScene from "./pause_scene";
import
TutorialScene
from
"
./tutorial_scene
"
;
import
LeaderboardScene
from
"
./leaderboard_scene
"
;
import
*
as
Types
from
"
../../../backend/src/types
"
;
import
backend
from
"
./backend
"
;
const
DEVICE_ID_KEY
=
"
OETZIT/DEVICE_ID
"
;
export
const
GRAVITY_Y
=
200
;
const
CONFIG
=
{
...
...
@@ -37,9 +42,32 @@ const CONFIG = {
};
export
default
class
Game
extends
Phaser
.
Game
{
beDevice
!
:
Types
.
Device
;
constructor
()
{
super
(
CONFIG
);
this
.
bindFocusEvents
();
this
.
events
.
on
(
Phaser
.
Core
.
Events
.
READY
,
this
.
initBeDevice
.
bind
(
this
));
}
async
initBeDevice
()
{
const
deviceId
=
this
.
getDeviceId
();
if
(
deviceId
===
null
)
{
this
.
beDevice
=
(
await
backend
.
createDevice
()).
data
;
}
else
{
this
.
beDevice
=
(
await
backend
.
getDevice
(
deviceId
)).
data
;
}
this
.
setDeviceId
(
this
.
beDevice
.
id
);
}
setDeviceId
(
deviceId
:
string
)
{
sessionStorage
.
setItem
(
DEVICE_ID_KEY
,
deviceId
);
}
getDeviceId
():
string
{
const
deviceId
=
sessionStorage
.
getItem
(
DEVICE_ID_KEY
);
if
(
deviceId
!==
null
)
return
deviceId
;
throw
new
Error
(
"
getDeviceId was called before initBeDevice
"
);
}
bindFocusEvents
()
{
...
...
This diff is collapsed.
Click to expand it.
frontend/src/js/leaderboard_scene.ts
+
5
−
8
View file @
8e77a921
...
...
@@ -4,9 +4,9 @@ import { FONTS } from "./assets";
import
{
uniqueNamesGenerator
,
names
}
from
"
unique-names-generator
"
;
import
backend
from
"
./backend
"
;
import
{
LeaderboardItem
,
LeaderboardView
}
from
"
../../../backend/src/types
"
;
import
Game
from
"
./game
"
;
const
MEDALS
=
[
"
🥇
"
,
"
🥈
"
,
"
🥉
"
];
const
DEVICE_KEY
=
"
OETZIT/DEVICE_ID
"
;
const
BUTTON_HIGHLIGHT_COLOR
=
"
darkorange
"
;
...
...
@@ -42,6 +42,7 @@ const TEXT_STYLE: {
};
export
default
class
LeaderboardScene
extends
Phaser
.
Scene
{
game
!
:
Game
;
music
!
:
Phaser
.
Sound
.
BaseSound
;
rankings
!
:
Phaser
.
GameObjects
.
Text
;
message
!
:
Phaser
.
GameObjects
.
Text
;
...
...
@@ -68,20 +69,16 @@ export default class LeaderboardScene extends Phaser.Scene {
async
fetchLeaderboardView
()
{
return
(
await
backend
.
createLeaderboardView
({
device_id
:
this
.
getDevice
UUID
()
??
undefined
,
device_id
:
this
.
game
.
getDevice
Id
()
??
undefined
,
})
).
data
;
}
calculateCurrentDeviceIndex
()
{
const
uuid
=
this
.
getDevice
UUID
();
const
uuid
=
this
.
game
.
getDevice
Id
();
return
this
.
leaderboardView
.
findIndex
(({
device_id
})
=>
device_id
==
uuid
);
}
getDeviceUUID
()
{
return
sessionStorage
.
getItem
(
DEVICE_KEY
);
}
async
createRankings
()
{
const
renderedRankings
=
this
.
renderRankings
(
this
.
leaderboardView
);
...
...
@@ -109,7 +106,7 @@ export default class LeaderboardScene extends Phaser.Scene {
// Find and mark current device
const
myIndex
=
leaderboardItems
.
findIndex
(
({
device_id
})
=>
device_id
==
this
.
getDevice
UUID
(),
({
device_id
})
=>
device_id
==
this
.
game
.
getDevice
Id
(),
);
if
(
myIndex
>
-
1
)
output
[
myIndex
][
1
]
=
"
> YOU <
"
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment