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
c29359f7
Commit
c29359f7
authored
2 years ago
by
Paolo.Brasolin
Browse files
Options
Downloads
Patches
Plain Diff
feat: #be #fe fully track game events
parent
0fc59b98
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
backend/src/api.ts
+1
-1
1 addition, 1 deletion
backend/src/api.ts
backend/src/schemas.ts
+12
-3
12 additions, 3 deletions
backend/src/schemas.ts
frontend/src/js/fight_scene.ts
+16
-10
16 additions, 10 deletions
frontend/src/js/fight_scene.ts
frontend/src/js/foe.ts
+6
-11
6 additions, 11 deletions
frontend/src/js/foe.ts
with
35 additions
and
25 deletions
backend/src/api.ts
+
1
−
1
View file @
c29359f7
...
...
@@ -177,7 +177,7 @@ const apiPlugin: FastifyPluginCallback = (fastify, options, next) => {
handler
:
async
(
request
,
reply
)
=>
{
const
shots
=
await
connection
.
table
(
"
shots
"
)
.
insert
(
request
.
body
)
.
insert
(
{
game_id
:
request
.
params
.
id
,
...
request
.
body
}
)
.
returning
<
Types
.
Shot
[]
>
(
"
*
"
);
reply
.
code
(
200
).
send
(
shots
[
0
]);
...
...
This diff is collapsed.
Click to expand it.
backend/src/schemas.ts
+
12
−
3
View file @
c29359f7
...
...
@@ -35,7 +35,16 @@ export const Shot = Type.Object({
final
:
Type
.
String
(),
});
export
const
GameUpdate
=
Type
.
Omit
(
Game
,
[
"
id
"
]);
export
const
ClueCreate
=
Type
.
Pick
(
Clue
,
[
"
word_id
"
]);
export
const
ClueUpdate
=
Type
.
Pick
(
Clue
,
[
"
began_at
"
,
"
ended_at
"
]);
export
const
GameUpdate
=
Type
.
Partial
(
Type
.
Pick
(
Game
,
[
"
began_at
"
,
"
ended_at
"
]),
);
export
const
ClueUpdate
=
Type
.
Partial
(
Type
.
Pick
(
Clue
,
[
"
began_at
"
,
"
ended_at
"
]),
);
export
const
ClueCreate
=
Type
.
Intersect
([
Type
.
Pick
(
Clue
,
[
"
word_id
"
]),
ClueUpdate
,
]);
export
const
ShotCreate
=
Type
.
Omit
(
Shot
,
[
"
id
"
,
"
game_id
"
]);
This diff is collapsed.
Click to expand it.
frontend/src/js/fight_scene.ts
+
16
−
10
View file @
c29359f7
...
...
@@ -122,7 +122,6 @@ export default class FightScene extends Phaser.Scene {
this
.
beGame
=
(
await
backend
.
updateGame
(
this
.
beGame
.
id
,
{
began_at
:
new
Date
().
toISOString
(),
ended_at
:
null
,
})
).
data
;
...
...
@@ -230,7 +229,6 @@ export default class FightScene extends Phaser.Scene {
async
endGame
()
{
this
.
beGame
=
(
await
backend
.
updateGame
(
this
.
beGame
.
id
,
{
began_at
:
this
.
beGame
.
began_at
,
// TODO: make this optional in the type
ended_at
:
new
Date
().
toISOString
(),
})
).
data
;
...
...
@@ -238,11 +236,11 @@ export default class FightScene extends Phaser.Scene {
this
.
scene
.
start
(
"
game_over
"
);
}
showSubmitFeedback
(
color
:
string
)
{
showSubmitFeedback
(
color
:
string
,
input
:
string
)
{
const
text
=
this
.
add
.
text
(
this
.
cameras
.
main
.
width
/
2
,
this
.
cameras
.
main
.
height
/
2
,
this
.
hud
.
input
.
tex
t
,
inpu
t
,
{
font
:
"
bold 64px Courier
"
,
color
:
color
,
...
...
@@ -300,21 +298,29 @@ export default class FightScene extends Phaser.Scene {
}
submitTranscription
(
inputStatus
:
InputStatus
)
{
// NOTE: this ain't async to avoid any UX delay
const
{
score
,
match
}
=
this
.
findMatchingFoe
(
inputStatus
.
final
);
// TODO: visual near misses based on score
backend
.
createShot
(
this
.
beGame
.
id
,
{
clue_id
:
match
?.
beClue
?.
id
||
null
,
...
inputStatus
,
});
if
(
match
===
null
)
{
// NOOP
this
.
showSubmitFeedback
(
"
#FFFFFF
"
);
this
.
showSubmitFeedback
(
"
#FFFFFF
"
,
inputStatus
.
final
);
}
else
if
(
score
<
0.9
)
{
// TODO: visual near misses based on score
this
.
updateScore
(
-
1
);
match
.
handleFailure
();
this
.
showSubmitFeedback
(
"
#FF0000
"
);
this
.
showSubmitFeedback
(
"
#FF0000
"
,
inputStatus
.
final
);
new
Spear
(
this
,
this
.
player
,
undefined
);
}
else
{
backend
.
updateClue
(
match
.
beClue
.
id
,
{
ended_at
:
new
Date
().
toISOString
(),
});
this
.
updateScore
(
+
10
);
this
.
popFoe
(
match
);
match
.
handleSuccess
();
this
.
showSubmitFeedback
(
"
#00FF00
"
);
this
.
showSubmitFeedback
(
"
#00FF00
"
,
inputStatus
.
final
);
new
Spear
(
this
,
this
.
player
,
match
.
critter
);
// TODO: increase score
}
...
...
@@ -323,17 +329,17 @@ export default class FightScene extends Phaser.Scene {
createAndBindTypewriter
()
{
this
.
typewriter
??=
new
Typewriter
();
this
.
typewriter
.
setHidden
(
this
.
game
.
device
.
os
.
desktop
);
this
.
typewriter
.
onSubmit
=
(
inputStatus
)
=>
{
this
.
typewriter
.
onSubmit
=
async
(
inputStatus
)
=>
{
if
(
inputStatus
.
began_at
===
null
)
return
;
if
(
inputStatus
.
ended_at
===
null
)
return
;
if
(
inputStatus
.
final
===
""
)
return
;
this
.
hud
.
input
.
text
=
""
;
this
.
submitTranscription
({
began_at
:
inputStatus
.
began_at
.
toISOString
(),
ended_at
:
inputStatus
.
ended_at
.
toISOString
(),
typed
:
inputStatus
.
typed
,
final
:
inputStatus
.
final
,
});
this
.
hud
.
input
.
text
=
""
;
};
this
.
typewriter
.
onChange
=
(
inputStatus
)
=>
{
this
.
hud
.
input
.
text
=
inputStatus
.
final
;
...
...
This diff is collapsed.
Click to expand it.
frontend/src/js/foe.ts
+
6
−
11
View file @
c29359f7
...
...
@@ -21,17 +21,12 @@ class Foe {
async
initialize
()
{
this
.
beWord
=
(
await
backend
.
getWord
()).
data
;
if
(
!
this
.
scene
.
scene
.
isActive
())
return
;
// this.beClue = (
// await backend.createClue(this.scene.beGame.id, {
// word_id: this.beWord.id,
// })
// ).data;
// this.beClue = (
// await backend.updateClue(this.beClue.id, {
// began_at: new Date().toISOString(),
// ended_at: null,
// })
// ).data;
this
.
beClue
=
(
await
backend
.
createClue
(
this
.
scene
.
beGame
.
id
,
{
word_id
:
this
.
beWord
.
id
,
began_at
:
new
Date
().
toISOString
(),
})
).
data
;
this
.
clue
=
new
Clue
(
this
.
scene
,
this
.
beWord
);
this
.
critter
=
new
Critter
(
this
.
scene
);
...
...
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