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
370f88b7
Commit
370f88b7
authored
3 years ago
by
Paolo.Brasolin
Browse files
Options
Downloads
Patches
Plain Diff
feat: #fe track timing in input
parent
903a3bd2
No related branches found
No related tags found
No related merge requests found
Pipeline
#23570
passed with warnings
3 years ago
Stage: setup
Stage: check
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/src/js/fight_scene.ts
+59
-30
59 additions, 30 deletions
frontend/src/js/fight_scene.ts
with
59 additions
and
30 deletions
frontend/src/js/fight_scene.ts
+
59
−
30
View file @
370f88b7
...
@@ -9,12 +9,20 @@ import levenshtein from "damerau-levenshtein";
...
@@ -9,12 +9,20 @@ import levenshtein from "damerau-levenshtein";
import
*
as
Types
from
"
../../../backend/src/types
"
;
import
*
as
Types
from
"
../../../backend/src/types
"
;
import
Foe
from
"
./foe
"
;
import
Foe
from
"
./foe
"
;
interface
InputStatus
{
began_at
:
string
|
null
;
ended_at
:
string
|
null
;
typed
:
string
;
final
:
string
;
}
export
default
class
FightScene
extends
Phaser
.
Scene
{
export
default
class
FightScene
extends
Phaser
.
Scene
{
foes
:
Array
<
Foe
>
;
foes
:
Array
<
Foe
>
;
ground
:
Phaser
.
Types
.
Physics
.
Arcade
.
ImageWithStaticBody
;
ground
:
Phaser
.
Types
.
Physics
.
Arcade
.
ImageWithStaticBody
;
player
:
Phaser
.
Types
.
Physics
.
Arcade
.
SpriteWithDynamicBody
;
player
:
Phaser
.
Types
.
Physics
.
Arcade
.
SpriteWithDynamicBody
;
cluesGroup
:
Phaser
.
Physics
.
Arcade
.
Group
;
cluesGroup
:
Phaser
.
Physics
.
Arcade
.
Group
;
beGame
:
Types
.
Game
;
beGame
:
Types
.
Game
;
inputStatus
:
InputStatus
;
constructor
()
{
constructor
()
{
super
(
"
fight
"
);
super
(
"
fight
"
);
...
@@ -78,6 +86,10 @@ export default class FightScene extends Phaser.Scene {
...
@@ -78,6 +86,10 @@ export default class FightScene extends Phaser.Scene {
}
}
async
create
()
{
async
create
()
{
this
.
inputStatus
=
{
typed
:
""
,
final
:
""
,
};
this
.
initCluesGroup
();
this
.
initCluesGroup
();
// Draw background forest
// Draw background forest
[
"
b0
"
,
"
b1
"
,
"
b2
"
,
"
b3
"
,
"
b4
"
,
"
b5
"
,
"
b6
"
,
"
b7
"
,
"
b8
"
,
"
b9
"
,
"
b10
"
].
forEach
(
[
"
b0
"
,
"
b1
"
,
"
b2
"
,
"
b3
"
,
"
b4
"
,
"
b5
"
,
"
b6
"
,
"
b7
"
,
"
b8
"
,
"
b9
"
,
"
b10
"
].
forEach
(
...
@@ -162,7 +174,7 @@ export default class FightScene extends Phaser.Scene {
...
@@ -162,7 +174,7 @@ export default class FightScene extends Phaser.Scene {
this
.
cameras
.
main
.
width
/
this
.
cameras
.
main
.
height
,
this
.
cameras
.
main
.
width
/
this
.
cameras
.
main
.
height
,
);
);
this
.
scale
.
refresh
();
this
.
scale
.
refresh
();
initAndBindGuessPreview
(
this
);
this
.
initAndBindGuessPreview
();
this
.
beGame
=
(
await
backend
.
createGame
()).
data
;
this
.
beGame
=
(
await
backend
.
createGame
()).
data
;
this
.
beGame
=
(
this
.
beGame
=
(
...
@@ -240,8 +252,8 @@ export default class FightScene extends Phaser.Scene {
...
@@ -240,8 +252,8 @@ export default class FightScene extends Phaser.Scene {
return
result
;
return
result
;
}
}
submitTranscription
(
transcription
:
string
)
{
submitTranscription
(
inputStatus
:
InputStatus
)
{
const
{
score
,
match
}
=
this
.
findMatchingFoe
(
transcription
);
const
{
score
,
match
}
=
this
.
findMatchingFoe
(
inputStatus
.
final
);
// TODO: visual near misses based on score
// TODO: visual near misses based on score
if
(
match
===
null
)
{
if
(
match
===
null
)
{
// NOOP
// NOOP
...
@@ -256,6 +268,50 @@ export default class FightScene extends Phaser.Scene {
...
@@ -256,6 +268,50 @@ export default class FightScene extends Phaser.Scene {
new
Spear
(
this
,
this
.
player
,
match
.
critter
);
new
Spear
(
this
,
this
.
player
,
match
.
critter
);
}
}
}
}
initAndBindGuessPreview
()
{
const
textEntry
=
this
.
add
.
text
(
100
,
this
.
cameras
.
main
.
height
/
2
,
""
,
{
font
:
"
bold 64px Courier
"
,
color
:
"
#ffffff
"
,
});
this
.
input
.
keyboard
.
on
(
Phaser
.
Input
.
Keyboard
.
Events
.
ANY_KEY_DOWN
,
(
event
:
any
)
=>
{
if
(
this
.
inputStatus
.
final
===
""
)
{
this
.
inputStatus
.
began_at
=
new
Date
().
toISOString
();
}
if
(
LETTERS_KEYCODES
.
has
(
event
.
keyCode
))
{
this
.
inputStatus
.
typed
+=
event
.
key
;
this
.
inputStatus
.
final
+=
event
.
key
;
textEntry
.
text
=
this
.
inputStatus
.
final
;
}
else
if
(
event
.
keyCode
===
Phaser
.
Input
.
Keyboard
.
KeyCodes
.
BACKSPACE
&&
this
.
inputStatus
.
final
.
length
>
0
)
{
this
.
inputStatus
.
typed
+=
"
\
b
"
;
this
.
inputStatus
.
final
=
this
.
inputStatus
.
final
.
substr
(
0
,
this
.
inputStatus
.
final
.
length
-
1
,
);
textEntry
.
text
=
this
.
inputStatus
.
final
;
}
else
if
(
event
.
keyCode
===
Phaser
.
Input
.
Keyboard
.
KeyCodes
.
ENTER
&&
this
.
inputStatus
.
final
.
length
>
0
)
{
this
.
inputStatus
.
typed
+=
"
\n
"
;
this
.
inputStatus
.
ended_at
=
new
Date
().
toISOString
();
this
.
submitTranscription
(
this
.
inputStatus
);
this
.
inputStatus
=
{
began_at
:
null
,
ended_at
:
null
,
typed
:
""
,
final
:
""
,
};
textEntry
.
text
=
this
.
inputStatus
.
final
;
}
},
);
}
}
}
// TODO: remove any
// TODO: remove any
...
@@ -309,33 +365,6 @@ const LETTERS_KEYCODES = new Set([
...
@@ -309,33 +365,6 @@ const LETTERS_KEYCODES = new Set([
222
,
// ä
222
,
// ä
]);
]);
function
initAndBindGuessPreview
(
scene
:
FightScene
)
{
const
textEntry
=
scene
.
add
.
text
(
100
,
scene
.
cameras
.
main
.
height
/
2
,
""
,
{
font
:
"
bold 64px Courier
"
,
color
:
"
#ffffff
"
,
});
scene
.
input
.
keyboard
.
on
(
Phaser
.
Input
.
Keyboard
.
Events
.
ANY_KEY_DOWN
,
function
(
event
:
any
)
{
// TODO: what's the correct type?
if
(
LETTERS_KEYCODES
.
has
(
event
.
keyCode
))
{
textEntry
.
text
+=
event
.
key
;
}
else
if
(
event
.
keyCode
===
Phaser
.
Input
.
Keyboard
.
KeyCodes
.
BACKSPACE
&&
textEntry
.
text
.
length
>
0
)
{
textEntry
.
text
=
textEntry
.
text
.
substr
(
0
,
textEntry
.
text
.
length
-
1
);
}
else
if
(
event
.
keyCode
===
Phaser
.
Input
.
Keyboard
.
KeyCodes
.
ENTER
&&
textEntry
.
text
.
length
>
0
)
{
scene
.
submitTranscription
(
textEntry
.
text
);
textEntry
.
text
=
textEntry
.
text
.
substr
(
0
,
0
);
}
},
);
}
function
gameStart
(
scene
:
any
)
{
function
gameStart
(
scene
:
any
)
{
spawn
(
scene
);
spawn
(
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