feat: change game name
This commit is contained in:
parent
64265d97e3
commit
e2ad380c6c
@ -1,13 +1,14 @@
|
|||||||
<template>
|
<template>
|
||||||
<AdminTile title="Game">
|
<AdminTile class="admin-tile-gameinfo" title="Game">
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Name:</td>
|
<td>Name:</td>
|
||||||
<td>{{ gameinfo.name }}</td>
|
<td>{{ gameinfo.name }}</td>
|
||||||
|
<td><div class="admin-tile-gameinfo__edit-game-name" @click="editName()"></div></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td># Players:</td>
|
<td># Players:</td>
|
||||||
<td>{{ players.length }}</td>
|
<td colspan="2">{{ players.length }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</AdminTile>
|
</AdminTile>
|
||||||
@ -16,5 +17,29 @@
|
|||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
props: ['gameinfo', 'players'],
|
props: ['gameinfo', 'players'],
|
||||||
|
methods: {
|
||||||
|
async editName() {
|
||||||
|
const name = window.prompt('new game name: ')
|
||||||
|
if (name) {
|
||||||
|
const g = this.$store.state.engine.user.game
|
||||||
|
await this.$engine.setGameName({ g, name })
|
||||||
|
await this.$engine.fetchGameInfo({ g })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.admin-tile-gameinfo {
|
||||||
|
&__edit-game-name {
|
||||||
|
cursor: pointer;
|
||||||
|
&:hover {
|
||||||
|
color: #a0a0a0;
|
||||||
|
}
|
||||||
|
&::after {
|
||||||
|
content: '✎';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
<div class="page-admin">
|
<div class="page-admin">
|
||||||
<template v-if="!isGamemasterOrAdmin">
|
<template v-if="!isGamemasterOrAdmin">
|
||||||
<p>You are not a game master.</p>
|
<p>You are not a game master.</p>
|
||||||
<button @click="login">Go to login page</button>
|
|
||||||
</template>
|
</template>
|
||||||
<template v-if="isGamemasterOrAdmin">
|
<template v-if="isGamemasterOrAdmin">
|
||||||
<GameControls />
|
<GameControls />
|
||||||
@ -49,9 +48,5 @@ export default {
|
|||||||
display: flex;
|
display: flex;
|
||||||
margin: 24px;
|
margin: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
&__back-button {
|
|
||||||
margin: 16px;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -4,6 +4,7 @@ import stop from './stop'
|
|||||||
import fetchUpdate from './fetchUpdate'
|
import fetchUpdate from './fetchUpdate'
|
||||||
import fetchUserInfo from './fetchUserInfo'
|
import fetchUserInfo from './fetchUserInfo'
|
||||||
import fetchGameInfo from './fetchGameInfo'
|
import fetchGameInfo from './fetchGameInfo'
|
||||||
|
import setGameName from './setGameName'
|
||||||
import collectQuotes from './collectQuotes'
|
import collectQuotes from './collectQuotes'
|
||||||
import startGame from './startGame'
|
import startGame from './startGame'
|
||||||
import resetGame from './resetGame'
|
import resetGame from './resetGame'
|
||||||
@ -29,6 +30,7 @@ export default (context, inject) => {
|
|||||||
fetchUpdate,
|
fetchUpdate,
|
||||||
fetchUserInfo,
|
fetchUserInfo,
|
||||||
fetchGameInfo,
|
fetchGameInfo,
|
||||||
|
setGameName,
|
||||||
collectQuotes,
|
collectQuotes,
|
||||||
getMyQuotes,
|
getMyQuotes,
|
||||||
saveQuote,
|
saveQuote,
|
||||||
|
8
client/src/plugins/engine/setGameName.js
Normal file
8
client/src/plugins/engine/setGameName.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
export default async function({ g, name }) {
|
||||||
|
const { store } = this.context
|
||||||
|
|
||||||
|
await this.callApi('/api/setGameName', {
|
||||||
|
g,
|
||||||
|
name,
|
||||||
|
})
|
||||||
|
}
|
@ -23,4 +23,6 @@ func (app *Application) SaveSelection(usr *user.User, w http.ResponseWriter, r *
|
|||||||
|
|
||||||
selection := r.URL.Query().Get("selection")
|
selection := r.URL.Query().Get("selection")
|
||||||
gm.SaveSelection(usr, selection)
|
gm.SaveSelection(usr, selection)
|
||||||
|
|
||||||
|
fmt.Fprintf(w, "ok")
|
||||||
}
|
}
|
||||||
|
32
server/src/application/setGameName.go
Normal file
32
server/src/application/setGameName.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package application
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"sirlab.de/go/knyt/user"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (app *Application) SetGameName(usr *user.User, w http.ResponseWriter, r *http.Request) {
|
||||||
|
gameRef := r.URL.Query().Get("g")
|
||||||
|
gm, err := app.GetGameById(gameRef)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
fmt.Fprintf(w, "game not found")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if usr.GetGameId() != gameRef || !usr.IsGamemaster() {
|
||||||
|
w.WriteHeader(http.StatusForbidden)
|
||||||
|
fmt.Fprintf(w, "forbidden")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
name := r.URL.Query().Get("name")
|
||||||
|
if err := gm.SetGameName(name); err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
fmt.Printf("%v", err)
|
||||||
|
fmt.Fprintf(w, "server error")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Fprintf(w, "ok")
|
||||||
|
}
|
@ -19,18 +19,36 @@ func NewGameFromFile(id, fileName string) (*Game, error) {
|
|||||||
return nil, fmt.Errorf("%s: %v\n", fileName, err)
|
return nil, fmt.Errorf("%s: %v\n", fileName, err)
|
||||||
} else {
|
} else {
|
||||||
gm := Game{
|
gm := Game{
|
||||||
id: id,
|
id: id,
|
||||||
name: gmJson.Name,
|
filename: fileName,
|
||||||
eng: engine.NewEngine(),
|
name: gmJson.Name,
|
||||||
players: make(map[string]playerInfo, 0),
|
eng: engine.NewEngine(),
|
||||||
state: STATE_IDLE,
|
players: make(map[string]playerInfo, 0),
|
||||||
quotes: make(map[string]*quote.Quote, 0),
|
state: STATE_IDLE,
|
||||||
|
quotes: make(map[string]*quote.Quote, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
return &gm, nil
|
return &gm, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gm *Game) SaveGame() error {
|
||||||
|
gm.mu.Lock()
|
||||||
|
defer gm.mu.Unlock()
|
||||||
|
|
||||||
|
gmJson := GameJson{
|
||||||
|
Name: gm.name,
|
||||||
|
}
|
||||||
|
if jsonBytes, err := json.Marshal(gmJson); err != nil {
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
if err := os.WriteFile(gm.filename, jsonBytes, 0666); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (gm *Game) StartEngine() {
|
func (gm *Game) StartEngine() {
|
||||||
gm.eng.Run(gm.populateSyncDataCb)
|
gm.eng.Run(gm.populateSyncDataCb)
|
||||||
}
|
}
|
||||||
|
11
server/src/game/setGameName.go
Normal file
11
server/src/game/setGameName.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package game
|
||||||
|
|
||||||
|
import ()
|
||||||
|
|
||||||
|
func (gm *Game) SetGameName(name string) error {
|
||||||
|
gm.mu.Lock()
|
||||||
|
gm.name = name
|
||||||
|
gm.mu.Unlock()
|
||||||
|
|
||||||
|
return gm.SaveGame()
|
||||||
|
}
|
@ -55,15 +55,16 @@ type Round struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Game struct {
|
type Game struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
id string
|
id string
|
||||||
name string
|
filename string
|
||||||
players map[string]playerInfo
|
name string
|
||||||
eng *engine.Engine
|
players map[string]playerInfo
|
||||||
state string
|
eng *engine.Engine
|
||||||
phase string
|
state string
|
||||||
quotes map[string]*quote.Quote
|
phase string
|
||||||
round Round
|
quotes map[string]*quote.Quote
|
||||||
|
round Round
|
||||||
}
|
}
|
||||||
|
|
||||||
type GameJson struct {
|
type GameJson struct {
|
||||||
|
@ -23,6 +23,7 @@ func main() {
|
|||||||
mux.PublicHandleFunc("/api/logout", mux.Logout)
|
mux.PublicHandleFunc("/api/logout", mux.Logout)
|
||||||
mux.PrivateHandleFunc("/api/userinfo", mux.GetUserInfo)
|
mux.PrivateHandleFunc("/api/userinfo", mux.GetUserInfo)
|
||||||
mux.PrivateHandleFunc("/api/gameinfo", app.GetGameInfo)
|
mux.PrivateHandleFunc("/api/gameinfo", app.GetGameInfo)
|
||||||
|
mux.PrivateHandleFunc("/api/setGameName", app.SetGameName)
|
||||||
mux.PrivateHandleFunc("/api/sync", app.SyncHandler)
|
mux.PrivateHandleFunc("/api/sync", app.SyncHandler)
|
||||||
mux.PrivateHandleFunc("/api/collectQuotes", app.CollectQuotes)
|
mux.PrivateHandleFunc("/api/collectQuotes", app.CollectQuotes)
|
||||||
mux.PrivateHandleFunc("/api/startGame", app.StartGame)
|
mux.PrivateHandleFunc("/api/startGame", app.StartGame)
|
||||||
|
Loading…
Reference in New Issue
Block a user