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
8526d399
Commit
8526d399
authored
2 years ago
by
Paolo.Brasolin
Browse files
Options
Downloads
Patches
Plain Diff
feat: #fe correctly handle game time
parent
4f442c35
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
+26
-6
26 additions, 6 deletions
frontend/src/js/fight_scene.ts
frontend/src/js/foe.ts
+1
-0
1 addition, 0 deletions
frontend/src/js/foe.ts
frontend/src/js/typewriter.ts
+12
-1
12 additions, 1 deletion
frontend/src/js/typewriter.ts
with
39 additions
and
7 deletions
frontend/src/js/fight_scene.ts
+
26
−
6
View file @
8526d399
...
@@ -18,6 +18,8 @@ interface InputStatus {
...
@@ -18,6 +18,8 @@ interface InputStatus {
ended_at
:
string
;
ended_at
:
string
;
typed
:
string
;
typed
:
string
;
final
:
string
;
final
:
string
;
began_at_gmtm
:
number
;
ended_at_gmtm
:
number
;
}
}
export
default
class
FightScene
extends
Phaser
.
Scene
{
export
default
class
FightScene
extends
Phaser
.
Scene
{
...
@@ -30,6 +32,7 @@ export default class FightScene extends Phaser.Scene {
...
@@ -30,6 +32,7 @@ export default class FightScene extends Phaser.Scene {
score
:
number
;
score
:
number
;
health
:
number
;
health
:
number
;
hud
:
HUD
;
hud
:
HUD
;
gameTime
:
Phaser
.
Time
.
TimerEvent
;
constructor
()
{
constructor
()
{
super
(
"
fight
"
);
super
(
"
fight
"
);
...
@@ -83,6 +86,11 @@ export default class FightScene extends Phaser.Scene {
...
@@ -83,6 +86,11 @@ export default class FightScene extends Phaser.Scene {
}
}
async
create
()
{
async
create
()
{
this
.
gameTime
=
this
.
time
.
addEvent
({
delay
:
Number
.
MAX_SAFE_INTEGER
,
paused
:
true
,
});
this
.
initCluesGroup
();
this
.
initCluesGroup
();
this
.
createAnimations
();
this
.
createAnimations
();
...
@@ -123,6 +131,7 @@ export default class FightScene extends Phaser.Scene {
...
@@ -123,6 +131,7 @@ export default class FightScene extends Phaser.Scene {
await
this
.
initBeDevice
();
await
this
.
initBeDevice
();
await
this
.
initBeGame
();
await
this
.
initBeGame
();
this
.
gameTime
.
paused
=
false
;
this
.
spawnFoes
();
this
.
spawnFoes
();
}
}
...
@@ -140,6 +149,7 @@ export default class FightScene extends Phaser.Scene {
...
@@ -140,6 +149,7 @@ export default class FightScene extends Phaser.Scene {
this
.
beGame
=
(
this
.
beGame
=
(
await
backend
.
createGame
(
this
.
beDevice
.
id
,
{
await
backend
.
createGame
(
this
.
beDevice
.
id
,
{
began_at
:
new
Date
().
toISOString
(),
began_at
:
new
Date
().
toISOString
(),
began_at_gmtm
:
this
.
getGameTime
(),
})
})
).
data
;
).
data
;
}
}
...
@@ -212,11 +222,7 @@ export default class FightScene extends Phaser.Scene {
...
@@ -212,11 +222,7 @@ export default class FightScene extends Phaser.Scene {
}
}
update
(
time
:
number
,
delta
:
number
):
void
{
update
(
time
:
number
,
delta
:
number
):
void
{
// TODO: please do not parse a date every few milliseconds
this
.
hud
.
setClock
(
this
.
getGameTime
());
if
(
this
.
beGame
?.
began_at
)
this
.
hud
.
setClock
(
new
Date
().
getTime
()
-
Date
.
parse
(
this
.
beGame
.
began_at
),
);
}
}
checkAlive
()
{
checkAlive
()
{
...
@@ -228,6 +234,7 @@ export default class FightScene extends Phaser.Scene {
...
@@ -228,6 +234,7 @@ export default class FightScene extends Phaser.Scene {
this
.
beGame
=
(
this
.
beGame
=
(
await
backend
.
updateGame
(
this
.
beGame
.
id
,
{
await
backend
.
updateGame
(
this
.
beGame
.
id
,
{
ended_at
:
new
Date
().
toISOString
(),
ended_at
:
new
Date
().
toISOString
(),
ended_at_gmtm
:
this
.
getGameTime
(),
})
})
).
data
;
).
data
;
this
.
foes
.
forEach
((
foe
)
=>
foe
.
destroy
());
this
.
foes
.
forEach
((
foe
)
=>
foe
.
destroy
());
...
@@ -315,6 +322,7 @@ export default class FightScene extends Phaser.Scene {
...
@@ -315,6 +322,7 @@ export default class FightScene extends Phaser.Scene {
}
else
{
}
else
{
backend
.
updateClue
(
match
.
beClue
.
id
,
{
backend
.
updateClue
(
match
.
beClue
.
id
,
{
ended_at
:
new
Date
().
toISOString
(),
ended_at
:
new
Date
().
toISOString
(),
ended_at_gmtm
:
this
.
getGameTime
(),
});
});
this
.
updateScore
(
+
10
);
this
.
updateScore
(
+
10
);
this
.
popFoe
(
match
);
this
.
popFoe
(
match
);
...
@@ -334,9 +342,12 @@ export default class FightScene extends Phaser.Scene {
...
@@ -334,9 +342,12 @@ export default class FightScene extends Phaser.Scene {
this
.
typewriter
.
setHidden
(
false
);
this
.
typewriter
.
setHidden
(
false
);
this
.
typewriter
.
setShiftModeOneShot
();
this
.
typewriter
.
setShiftModeOneShot
();
}
}
this
.
typewriter
.
getGameTime
=
this
.
getGameTime
.
bind
(
this
);
this
.
typewriter
.
onSubmit
=
async
(
inputStatus
)
=>
{
this
.
typewriter
.
onSubmit
=
async
(
inputStatus
)
=>
{
if
(
inputStatus
.
began_at
===
null
)
return
;
if
(
inputStatus
.
began_at
===
null
)
return
;
if
(
inputStatus
.
ended_at
===
null
)
return
;
if
(
inputStatus
.
ended_at
===
null
)
return
;
if
(
inputStatus
.
began_at_gmtm
===
null
)
return
;
if
(
inputStatus
.
ended_at_gmtm
===
null
)
return
;
if
(
inputStatus
.
final
===
""
)
return
;
if
(
inputStatus
.
final
===
""
)
return
;
this
.
hud
.
setInput
(
""
);
this
.
hud
.
setInput
(
""
);
this
.
submitTranscription
({
this
.
submitTranscription
({
...
@@ -344,6 +355,8 @@ export default class FightScene extends Phaser.Scene {
...
@@ -344,6 +355,8 @@ export default class FightScene extends Phaser.Scene {
ended_at
:
inputStatus
.
ended_at
.
toISOString
(),
ended_at
:
inputStatus
.
ended_at
.
toISOString
(),
typed
:
inputStatus
.
typed
,
typed
:
inputStatus
.
typed
,
final
:
inputStatus
.
final
,
final
:
inputStatus
.
final
,
began_at_gmtm
:
inputStatus
.
began_at_gmtm
,
ended_at_gmtm
:
inputStatus
.
ended_at_gmtm
,
});
});
};
};
this
.
typewriter
.
onChange
=
(
inputStatus
)
=>
{
this
.
typewriter
.
onChange
=
(
inputStatus
)
=>
{
...
@@ -356,8 +369,9 @@ export default class FightScene extends Phaser.Scene {
...
@@ -356,8 +369,9 @@ export default class FightScene extends Phaser.Scene {
// TODO: think of a progression which makes sense
// TODO: think of a progression which makes sense
const
delay
=
Math
.
max
(
const
delay
=
Math
.
max
(
2000
,
2000
,
(
8
*
1000
*
(
60
*
1000
-
this
.
time
.
now
))
/
60
/
1000
+
2
*
1000
,
(
8
*
1000
*
(
60
*
1000
-
this
.
getGameTime
()
))
/
60
/
1000
+
2
*
1000
,
);
);
// TODO: it should be ok calling this on time instead of gameTime, but... is it?
this
.
time
.
delayedCall
(
delay
,
this
.
spawnFoes
.
bind
(
this
));
this
.
time
.
delayedCall
(
delay
,
this
.
spawnFoes
.
bind
(
this
));
}
}
...
@@ -372,4 +386,10 @@ export default class FightScene extends Phaser.Scene {
...
@@ -372,4 +386,10 @@ export default class FightScene extends Phaser.Scene {
uncoverClues
()
{
uncoverClues
()
{
this
.
foes
.
forEach
((
foe
)
=>
foe
.
clue
.
uncover
());
this
.
foes
.
forEach
((
foe
)
=>
foe
.
clue
.
uncover
());
}
}
getGameTime
()
{
// NOTE: we don't need sub-ms precision.
// NOTE: pretty please, don't access the timer directly.
return
Math
.
round
(
this
.
gameTime
.
getElapsed
());
}
}
}
This diff is collapsed.
Click to expand it.
frontend/src/js/foe.ts
+
1
−
0
View file @
8526d399
...
@@ -28,6 +28,7 @@ class Foe {
...
@@ -28,6 +28,7 @@ class Foe {
await
backend
.
createClue
(
this
.
scene
.
beGame
.
id
,
{
await
backend
.
createClue
(
this
.
scene
.
beGame
.
id
,
{
word_id
:
this
.
beWord
.
id
,
word_id
:
this
.
beWord
.
id
,
began_at
:
new
Date
().
toISOString
(),
began_at
:
new
Date
().
toISOString
(),
began_at_gmtm
:
this
.
scene
.
getGameTime
(),
})
})
).
data
;
).
data
;
...
...
This diff is collapsed.
Click to expand it.
frontend/src/js/typewriter.ts
+
12
−
1
View file @
8526d399
...
@@ -6,6 +6,8 @@ interface InputStatus {
...
@@ -6,6 +6,8 @@ interface InputStatus {
ended_at
:
Date
|
null
;
ended_at
:
Date
|
null
;
typed
:
string
;
typed
:
string
;
final
:
string
;
final
:
string
;
began_at_gmtm
:
number
|
null
;
ended_at_gmtm
:
number
|
null
;
}
}
enum
Key
{
enum
Key
{
...
@@ -114,6 +116,7 @@ class Typewriter {
...
@@ -114,6 +116,7 @@ class Typewriter {
onChange
:
(
inputStatus
:
InputStatus
)
=>
unknown
;
onChange
:
(
inputStatus
:
InputStatus
)
=>
unknown
;
onSubmit
:
(
inputStatus
:
InputStatus
)
=>
unknown
;
onSubmit
:
(
inputStatus
:
InputStatus
)
=>
unknown
;
getGameTime
:
()
=>
number
;
// NOTE: sigh.
constructor
()
{
constructor
()
{
this
.
onChange
=
()
=>
{};
this
.
onChange
=
()
=>
{};
...
@@ -124,6 +127,8 @@ class Typewriter {
...
@@ -124,6 +127,8 @@ class Typewriter {
ended_at
:
null
,
ended_at
:
null
,
typed
:
""
,
typed
:
""
,
final
:
""
,
final
:
""
,
began_at_gmtm
:
null
,
ended_at_gmtm
:
null
,
};
};
this
.
keyboard
=
new
Keyboard
({
this
.
keyboard
=
new
Keyboard
({
...
@@ -181,11 +186,15 @@ class Typewriter {
...
@@ -181,11 +186,15 @@ class Typewriter {
event
:
KeyboardEvent
|
PointerEvent
|
MouseEvent
|
TouchEvent
,
event
:
KeyboardEvent
|
PointerEvent
|
MouseEvent
|
TouchEvent
,
)
{
)
{
const
key
=
this
.
extractKeyfromEvent
(
event
);
const
key
=
this
.
extractKeyfromEvent
(
event
);
if
(
!
this
.
inputStatus
.
began_at
)
this
.
inputStatus
.
began_at
=
new
Date
();
if
(
this
.
inputStatus
.
began_at
===
null
)
this
.
inputStatus
.
began_at
=
new
Date
();
if
(
this
.
inputStatus
.
began_at_gmtm
===
null
)
this
.
inputStatus
.
began_at_gmtm
=
this
.
getGameTime
();
if
(
key
===
Key
.
Enter
)
{
if
(
key
===
Key
.
Enter
)
{
this
.
keyboard
.
clearInput
();
this
.
keyboard
.
clearInput
();
this
.
inputStatus
.
typed
+=
"
\n
"
;
this
.
inputStatus
.
typed
+=
"
\n
"
;
this
.
inputStatus
.
ended_at
=
new
Date
();
this
.
inputStatus
.
ended_at
=
new
Date
();
this
.
inputStatus
.
ended_at_gmtm
=
this
.
getGameTime
();
this
.
onSubmit
(
this
.
inputStatus
);
this
.
onSubmit
(
this
.
inputStatus
);
this
.
resetInputStatus
();
this
.
resetInputStatus
();
}
else
if
(
key
===
Key
.
Backspace
)
{
}
else
if
(
key
===
Key
.
Backspace
)
{
...
@@ -210,6 +219,8 @@ class Typewriter {
...
@@ -210,6 +219,8 @@ class Typewriter {
ended_at
:
null
,
ended_at
:
null
,
typed
:
""
,
typed
:
""
,
final
:
""
,
final
:
""
,
began_at_gmtm
:
null
,
ended_at_gmtm
:
null
,
};
};
}
}
...
...
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