Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
KSZK
Schönherz Mátrix
games
Aggregator Backend
Commits
a0ca97c3
Commit
a0ca97c3
authored
Oct 03, 2021
by
Miklós Tóth
🤷
Browse files
Add point feedback
parent
d4bc9a0e
Pipeline
#8887
passed with stages
in 1 minute and 9 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
static/index.html
View file @
a0ca97c3
...
...
@@ -8,7 +8,7 @@
.container
{
margin-top
:
30px
;
}
#teamName
{
#teamName
,
#score
{
transition
:
opacity
0.4s
;
}
.btn
{
...
...
@@ -77,6 +77,11 @@
font-size
:
6pt
;
}
.jumbotron
>
table
td
{
padding-right
:
1em
;
vertical-align
:
bottom
;
}
</style>
<link
rel=
"icon"
type=
"image/png"
href=
"/favicon.png"
/>
</head>
...
...
@@ -84,7 +89,7 @@
<body>
<main
role=
"main"
class=
"container"
>
<div
class=
"jumbotron"
>
<h1
id=
"teamName"
>
Connecting...
</h1>
<table><tr><td>
<h1
id=
"teamName"
>
Connecting...
</h1>
</td><td><h3
id=
"score"
></h3></td></tr></table>
<p
class=
"lead"
>
Tippeld meg, hogy melyik ablak villant fel!
</p>
<div
class=
"cnt"
>
<img
class=
"wrapped"
src=
"/sch.jpg"
alt=
"sch"
/>
...
...
static/main.js
View file @
a0ca97c3
...
...
@@ -52,6 +52,17 @@ const changeTeamName = (() => {
}
})()
const
changeScore
=
(()
=>
{
const
score
=
document
.
getElementById
(
"
score
"
)
return
(
pt
,
round
)
=>
{
score
.
style
.
opacity
=
"
0
"
setTimeout
(()
=>
{
score
.
innerText
=
`
${
pt
}
p (
${
round
}
. kör)`
score
.
style
.
opacity
=
"
1
"
},
400
)
}
})()
function
join
(
data
){
localStorage
.
setItem
(
"
teamId
"
,
window
.
location
.
hash
.
substring
(
2
));
localStorage
.
setItem
(
"
userId
"
,
data
.
id
);
...
...
@@ -119,6 +130,9 @@ function handleResponse(action, response){
if
(
lastSent
)
lastSent
.
style
.
background
=
"
#660
"
break
;
case
"
score
"
:
changeScore
(
response
.
Score
,
response
.
Round
)
break
;
default
:
alert
(
"
unknown cmd
"
);
}
...
...
web/msgTypes.go
View file @
a0ca97c3
...
...
@@ -16,3 +16,11 @@ type JoinMsg struct {
type
VoteMsg
struct
{
Tip
*
logic
.
Coords
`json:"tip"`
}
type
TeamScores
struct
{
Round
int
`binding:"required"`
Groups
[]
struct
{
Id
string
`binding:"required"`
Score
int
`binding:"required"`
}
`binding:"required"`
}
web/out.go
View file @
a0ca97c3
...
...
@@ -56,3 +56,20 @@ func humanTeams(c *gin.Context) {
}
c
.
HTML
(
200
,
"teams.html"
,
teams
)
}
func
scoreSender
(
c
*
gin
.
Context
)
{
var
scores
TeamScores
if
e
:=
c
.
ShouldBindJSON
(
&
scores
);
e
!=
nil
{
c
.
String
(
400
,
"%s"
,
"Lacko pls"
,
e
.
Error
())
return
}
for
_
,
g
:=
range
scores
.
Groups
{
s
,
ok
:=
socketsByTeams
[
g
.
Id
]
if
!
ok
{
continue
}
for
_
,
s
:=
range
s
{
_
=
sendScore
(
s
,
scores
.
Round
,
g
.
Score
)
}
}
}
web/router.go
View file @
a0ca97c3
...
...
@@ -25,6 +25,7 @@ func init() {
AdminRouter
.
GET
(
"/data"
,
sumHandler
)
AdminRouter
.
POST
(
"/stop"
,
stopHandler
)
AdminRouter
.
POST
(
"/start"
,
startHandler
)
AdminRouter
.
POST
(
"/report"
,
scoreSender
)
AdminRouter
.
GET
(
"/teams"
,
teamHandler
)
AdminRouter
.
GET
(
"/teams/human"
,
humanTeams
)
}
web/socket.go
View file @
a0ca97c3
...
...
@@ -27,6 +27,8 @@ func broadcast(start bool) {
}
}
var
socketsByTeams
=
make
(
map
[
string
][]
sockjs
.
Session
)
func
socketHandler
(
session
sockjs
.
Session
)
{
connectedSockets
=
append
(
connectedSockets
,
session
)
...
...
@@ -60,6 +62,10 @@ func socketHandler(session sockjs.Session) {
case
"user"
:
joinUser
(
cmd
.
JoinMsg
.
Id
,
session
,
&
userId
,
&
teamId
)
}
if
teamId
!=
""
{
socketsByTeams
[
teamId
]
=
append
(
socketsByTeams
[
teamId
],
session
)
}
}
_
=
sendStatus
(
session
,
logic
.
GetRunning
())
...
...
web/socketHelpers.go
View file @
a0ca97c3
...
...
@@ -61,3 +61,19 @@ func init() {
broadcast
(
state
)
})
}
type
score
struct
{
Round
int
Score
int
}
func
sendScore
(
s
sockjs
.
Session
,
r
,
sc
int
)
error
{
return
sendMsg
(
s
,
&
resp
{
Code
:
200
,
Msg
:
score
{
Round
:
r
,
Score
:
sc
,
},
Cmd
:
"score"
,
})
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment