Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
WorkAdventure Dialogs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FS Info TU Dortmund
Events
WorkAdventure Dialogs
Commits
c40ae709
Commit
c40ae709
authored
4 years ago
by
Jonas Zohren
Browse files
Options
Downloads
Patches
Plain Diff
WIP: Saving game State
parent
45d48597
Branches
Branches containing commit
No related tags found
Loading
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/App.svelte
+3
-2
3 additions, 2 deletions
src/App.svelte
src/SavingComponent.svelte
+24
-26
24 additions, 26 deletions
src/SavingComponent.svelte
src/gameStateServerSyncService.ts
+23
-0
23 additions, 0 deletions
src/gameStateServerSyncService.ts
src/utils.ts
+1
-1
1 addition, 1 deletion
src/utils.ts
with
51 additions
and
29 deletions
src/App.svelte
+
3
−
2
View file @
c40ae709
...
...
@@ -4,6 +4,7 @@
import
Debugger
from
"
./Debugger.svelte
"
;
import
type
{
Dialog
}
from
"
./types
"
;
import
SavingComponent
from
"
./SavingComponent.svelte
"
;
import
{
hasContext
}
from
"
svelte
"
;
const
gameStateServerBaseUrl
=
"
http://localhost:4000/
"
;
...
...
@@ -13,11 +14,11 @@
<main>
{
#await
dialogSetPromise
then
dialogSet
}
<SavingComponent
{
gameStateServerBaseUrl
}
/>
<br
/>
<DialogSetComponent
bind:currentDialog
{...
dialogSet
}
/>
<br
/>
<Debugger
{
dialogSet
}
bind:currentDialog />
<SavingComponent
{
gameStateServerBaseUrl
}
/>
{
:catch
_error
}
<h3>
Oh no :(
</h3>
<p>
...
...
This diff is collapsed.
Click to expand it.
src/SavingComponent.svelte
+
24
−
26
View file @
c40ae709
<script
lang=
"ts"
>
import
{
identity
}
from
"
svelte/internal
"
;
import
{
gameFactsStore
}
from
"
./gameFacts
"
;
import
{
finishedSyncSetup
,
gameStateId
}
from
"
./gameStateServerSyncService
"
;
import
{
GameStateServerClient
}
from
"
./gameStateServerClient
"
;
import
type
{
GameState
}
from
"
./types
"
;
export
let
gameStateServerBaseUrl
:
string
;
$
:
gameStateServerClient
=
new
GameStateServerClient
(
gameStateServerBaseUrl
);
let
pretixOrderCode
:
string
=
"
XXXYYY
"
;
async
function
handleSaveGameState
():
Promise
<
void
>
{
const
gameState
:
GameState
=
{
gameFacts
:
$gameFactsStore
,
};
gameStateServerClient
.
saveState
(
pretixOrderCode
,
gameState
);
}
async
function
handleLoadGameState
():
Promise
<
void
>
{
const
newGameState
=
await
gameStateServerClient
.
loadState
(
pretixOrderCode
);
$gameFactsStore
=
newGameState
.
gameFacts
;
async
function
handleSyncState
():
Promise
<
void
>
{
$finishedSyncSetup
=
true
;
}
</script>
<div>
<input
type=
"text"
placeholder=
"Your Pretix order code"
maxlength=
"5"
minlength=
"5"
bind:value=
{
pretixOrderCode
}
/>
<button
style=
"width: 10rem;"
on:click
|
preventDefault=
{
handleSaveGameState
}
>
💾 Save game
</button>
<button
style=
"width: 10rem;"
on:click
|
preventDefault=
{
handleLoadGameState
}
>
▶️ Load game
</button>
</div>
{
#if
!
$finishedSyncSetup
}
<div>
<p>
Dein Spielstand wird aktuell noch nicht synchronisiert, d.h. wenn du den
Browser schließt, kann es sein, dass du von vorne anfängst. Zum Speichern
gib bitte deinen "Order Code" ein. Deinen Order Code findest du in den
E-Mails, die wir dir zur O-Phase gesendet haben.
</p>
<br
/>
<input
type=
"text"
placeholder=
"Bsp: A1B2C3"
maxlength=
"5"
minlength=
"5"
bind:value=
{
$gameStateId
}
/>
<button
style=
"width: 20rem;"
on:click
|
preventDefault=
{
handleSyncState
}
>
Spielstand synchronisieren
</button>
</div>
{
/if
}
<style>
div
{
...
...
This diff is collapsed.
Click to expand it.
src/gameStateServerSyncService.ts
0 → 100644
+
23
−
0
View file @
c40ae709
import
{
gameFactsStore
}
from
"
./gameFacts
"
;
import
{
GameStateServerClient
}
from
"
./gameStateServerClient
"
;
import
type
{
GameState
}
from
"
./types
"
;
import
{
writable
}
from
"
svelte/store
"
;
import
type
{
Writable
}
from
"
svelte/store
"
;
export
const
finishedSyncSetup
:
Writable
<
boolean
>
=
writable
(
false
);
export
const
gameStateId
:
Writable
<
string
>
=
writable
(
""
);
export
class
SyncService
{
_client
:
GameStateServerClient
;
_id
:
string
;
constructor
(
stateServerBaseUrl
:
string
,
id
:
string
)
{
this
.
_id
=
id
;
this
.
_client
=
new
GameStateServerClient
(
stateServerBaseUrl
);
gameFactsStore
.
subscribe
(
async
(
gameFacts
:
string
[])
=>
{
const
newGameState
:
GameState
=
{
gameFacts
:
gameFacts
,
};
await
this
.
_client
.
saveState
(
this
.
_id
,
newGameState
);
});
}
}
This diff is collapsed.
Click to expand it.
src/utils.ts
+
1
−
1
View file @
c40ae709
...
...
@@ -18,7 +18,7 @@ function isValidDialogSetName(input: unknown) {
return
!
/
[^
a-zA-Z0-9
\-\_]
/i
.
test
(
input
);
}
function
getParamValue
(
paramName
:
string
):
string
|
null
{
export
function
getParamValue
(
paramName
:
string
):
string
|
null
{
return
new
URLSearchParams
(
window
.
location
.
search
).
get
(
paramName
);
}
...
...
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