Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ehasa-frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
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
WIMMA Lab 2019
Overflow
ehasa-frontend
Commits
975c5689
Commit
975c5689
authored
5 years ago
by
Joni Laukka
Browse files
Options
Downloads
Patches
Plain Diff
Game state buttons wip
parent
0d908724
No related branches found
Branches containing commit
No related tags found
2 merge requests
!31
Development
,
!28
Routing
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/GameStateButtons.js
+76
-0
76 additions, 0 deletions
src/components/GameStateButtons.js
src/components/GameView.js
+4
-1
4 additions, 1 deletion
src/components/GameView.js
with
80 additions
and
1 deletion
src/components/GameStateButtons.js
0 → 100644
+
76
−
0
View file @
975c5689
import
React
,
{
Fragment
}
from
"
react
"
;
export
default
class
GameStateButtons
extends
React
.
Component
{
state
=
{
gameState
:
this
.
props
.
gameState
// CREATED,STARTED,PAUSED,ENDED,ONGOING
};
handleStart
=
e
=>
{
let
token
=
sessionStorage
.
getItem
(
"
token
"
);
fetch
(
`
${
process
.
env
.
REACT_APP_API_URL
}
/game/edit-state/
${
this
.
props
.
gameId
}
`
,
{
method
:
"
PUT
"
,
headers
:
{
Authorization
:
"
Bearer
"
+
token
,
Accept
:
"
application/json
"
,
"
Content-Type
"
:
"
application/json
"
},
body
:
JSON
.
stringify
({
id
:
this
.
props
.
gameId
,
state
:
"
STARTED
"
})
}
)
.
then
(
res
=>
{
if
(
res
.
ok
)
{
return
res
.
json
();
}
else
{
throw
Error
(
res
.
statusText
);
}
})
.
then
(
res
=>
{
alert
(
`Game state changed to "STARTED"`
);
this
.
setState
({
gameState
:
"
STARTED
"
});
})
.
catch
(
error
=>
console
.
log
(
error
));
};
handlePause
=
e
=>
{
this
.
setState
({
gameState
:
"
PAUSED
"
});
};
handleStop
=
e
=>
{
this
.
setState
({
gameState
:
"
STOPPED
"
});
};
render
()
{
if
(
this
.
state
.
gameState
===
"
CREATED
"
)
{
return
<
button
onClick
=
{
this
.
handleStart
}
>
Start
<
/button>
;
}
if
(
this
.
state
.
gameState
===
"
STARTED
"
)
{
return
(
<
Fragment
>
<
button
onClick
=
{
this
.
handlePause
}
>
Pause
<
/button
>
<
button
onClick
=
{
this
.
handleStop
}
>
Stop
<
/button
>
<
/Fragment
>
);
}
if
(
this
.
state
.
gameState
===
"
PAUSED
"
)
{
return
(
<
Fragment
>
<
button
onClick
=
{
this
.
handleStart
}
>
Continue
<
/button
>
<
button
onClick
=
{
this
.
handleStop
}
>
Stop
<
/button
>
<
/Fragment
>
);
}
if
(
this
.
state
.
gameState
===
"
STOPPED
"
)
{
return
"
The game has ended
"
;
}
return
false
;
}
}
This diff is collapsed.
Click to expand it.
src/components/GameView.js
+
4
−
1
View file @
975c5689
...
...
@@ -6,6 +6,7 @@ import EditGameForm from "./EditGameForm";
import
JoinGameForm
from
"
./JoinGameForm
"
;
import
PlayerlistView
from
"
./PlayerlistView
"
;
import
NotificationView
from
"
./NotificationView
"
;
import
GameStateButtons
from
"
./GameStateButtons
"
;
export
default
class
GameView
extends
React
.
Component
{
state
=
{
...
...
@@ -22,7 +23,6 @@ export default class GameView extends React.Component {
let
gameId
=
new
URL
(
window
.
location
.
href
).
searchParams
.
get
(
"
id
"
);
let
token
=
sessionStorage
.
getItem
(
"
token
"
);
console
.
log
(
gameId
);
fetch
(
`
${
process
.
env
.
REACT_APP_API_URL
}
/game/
${
gameId
}
`
)
.
then
(
res
=>
{
if
(
!
res
.
ok
)
{
...
...
@@ -142,6 +142,9 @@ export default class GameView extends React.Component {
Leave Faction
</button>
)}
{this.state.role === "admin" && (
<GameStateButtons gameState={this.state.gameInfo.state} />
)}
<UserMap
position={initialPosition}
zoom={this.state.zoom}
...
...
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