Compare commits
11 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
b89ed62036 | |
|
|
67c93a9048 | |
|
|
8eae7ae9a6 | |
|
|
ce32620940 | |
|
|
24f4b6b8f5 | |
|
|
440191de0f | |
|
|
d5adc596ac | |
|
|
41a39c40d0 | |
|
|
9a38033b65 | |
|
|
6a4ad5ec36 | |
|
|
c2b8ab67f2 |
|
|
@ -15,6 +15,16 @@ type (
|
|||
Players []configPlayer
|
||||
Quiet bool
|
||||
Broadcast configBroadcast
|
||||
GM configGM
|
||||
}
|
||||
|
||||
configGM struct {
|
||||
Hotwords map[string]configGMHotword
|
||||
}
|
||||
|
||||
configGMHotword struct {
|
||||
Call string
|
||||
Args []string
|
||||
}
|
||||
|
||||
configBroadcast struct {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"io"
|
||||
"log"
|
||||
"math/rand"
|
||||
"mayhem-party/src/device/input/button"
|
||||
"mayhem-party/src/device/input/wrap"
|
||||
"net/http"
|
||||
"os"
|
||||
|
|
@ -178,7 +179,7 @@ func (v01 *V01) serveGM(w http.ResponseWriter, r *http.Request) {
|
|||
case "/gm/rpc/status":
|
||||
v01.serveGMStatus(w)
|
||||
case "/gm/rpc/broadcastSomeoneSaidAlias":
|
||||
v01.serveGMSomeoneSaidAlias(w, r)
|
||||
v01.serveGMSomeoneSaid(w, r)
|
||||
case "/gm/rpc/fillNonPlayerAliases":
|
||||
v01.serveGMFillNonPlayerAliases(w, r)
|
||||
case "/gm/rpc/vote":
|
||||
|
|
@ -223,6 +224,31 @@ func (v01 *V01) serveGMStatus(w io.Writer) {
|
|||
w.Write(b)
|
||||
}
|
||||
|
||||
func (v01 *V01) serveGMSomeoneSaid(w http.ResponseWriter, r *http.Request) {
|
||||
if gmHotword, ok := v01.cfg.GM.Hotwords[r.URL.Query().Get("message")]; ok {
|
||||
v01.serveGMSomeoneSaidGMHotword(w, r, gmHotword)
|
||||
}
|
||||
v01.serveGMSomeoneSaidAlias(w, r)
|
||||
}
|
||||
|
||||
func (v01 *V01) serveGMSomeoneSaidGMHotword(w http.ResponseWriter, r *http.Request, gmHotword configGMHotword) {
|
||||
switch gmHotword.Call {
|
||||
case "tap":
|
||||
args := append([]string{}, gmHotword.Args...)
|
||||
if len(args) < 1 || len(args[0]) < 1 {
|
||||
return
|
||||
}
|
||||
btn := args[0][0]
|
||||
go func() {
|
||||
v01.alt <- []button.Button{button.Button{Down: true, Char: btn}}
|
||||
v01.alt <- []button.Button{button.Button{Down: false, Char: btn}}
|
||||
}()
|
||||
r.URL.RawQuery = ""
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
func (v01 *V01) serveGMSomeoneSaidAlias(w http.ResponseWriter, r *http.Request) {
|
||||
v01.cfg.Quiet = true
|
||||
for k, v := range v01.cfg.Users {
|
||||
|
|
|
|||
|
|
@ -96,12 +96,8 @@ func TestServeGM(t *testing.T) {
|
|||
t.Run("status", func(t *testing.T) {
|
||||
v01 := NewV01(ctx, nil)
|
||||
var result struct {
|
||||
Players int `yaml:"Players"`
|
||||
Users map[string]struct {
|
||||
Player int
|
||||
Lag string
|
||||
IdleFor string `yaml:"idle_for"`
|
||||
} `yaml:"Users"`
|
||||
Players int `yaml:"Players"`
|
||||
Users map[string]string `yaml:"Users"`
|
||||
}
|
||||
|
||||
t.Run("empty", func(t *testing.T) {
|
||||
|
|
@ -157,22 +153,46 @@ func TestServeGM(t *testing.T) {
|
|||
if len(result.Users) != 7 {
|
||||
t.Error(result.Users)
|
||||
}
|
||||
if d, err := time.ParseDuration(result.Users["bel"].Lag); err != nil {
|
||||
t.Error(err)
|
||||
} else if d != time.Second {
|
||||
t.Error(d)
|
||||
}
|
||||
if d, err := time.ParseDuration(result.Users["bel"].IdleFor); err != nil {
|
||||
t.Error(err)
|
||||
} else if d < time.Minute || d > 2*time.Minute {
|
||||
t.Error(d)
|
||||
}
|
||||
if result.Users["bel"].Player != 3 {
|
||||
t.Error(result.Users["bel"].Player)
|
||||
if result.Users["bel"] == "" || result.Users["bel"] == "..." {
|
||||
t.Error(result.Users["bel"])
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("broadcastSomeoneSaidAlias to hotword tap", func(t *testing.T) {
|
||||
v01 := NewV01(ctx, nil)
|
||||
v01.cfg.GM = configGM{
|
||||
Hotwords: map[string]configGMHotword{
|
||||
"hotword": configGMHotword{
|
||||
Call: "tap",
|
||||
Args: []string{"a"},
|
||||
},
|
||||
},
|
||||
}
|
||||
do(v01, "/gm/rpc/broadcastSomeoneSaidAlias?message=hotword", "")
|
||||
for i := 0; i < 2; i++ {
|
||||
select {
|
||||
case btn := <-v01.alt:
|
||||
if len(btn) != 1 {
|
||||
t.Error(btn)
|
||||
} else if btn[0].Down != (i == 0) {
|
||||
t.Error(btn[0])
|
||||
} else if btn[0].Char != 'a' {
|
||||
t.Error(btn[0].Char)
|
||||
}
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("nothing in alt")
|
||||
}
|
||||
}
|
||||
do(v01, "/gm/rpc/broadcastSomeoneSaidAlias?message=hotword", "")
|
||||
time.Sleep(time.Millisecond * 150)
|
||||
if got := v01.Read(); len(got) != 1 || !got[0].Down || got[0].Char != 'a' {
|
||||
t.Error(got)
|
||||
} else if got := v01.Read(); len(got) != 1 || got[0].Down || got[0].Char != 'a' {
|
||||
t.Error(got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("broadcastSomeoneSaidAlias", func(t *testing.T) {
|
||||
v01 := NewV01(ctx, nil)
|
||||
v01.cfg.Quiet = false
|
||||
|
|
|
|||
|
|
@ -18,3 +18,11 @@ players:
|
|||
quiet: false
|
||||
broadcast:
|
||||
message: hi
|
||||
gm:
|
||||
hotwords:
|
||||
coin:
|
||||
call: tap
|
||||
args: ['!']
|
||||
star:
|
||||
call: tap
|
||||
args: ['?']
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ type (
|
|||
src raw.Raw
|
||||
cfg config
|
||||
telemetryc chan message
|
||||
alt chan []button.Button
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -41,6 +42,7 @@ func NewV01(ctx context.Context, src raw.Raw) *V01 {
|
|||
src: src,
|
||||
cfg: cfg,
|
||||
telemetryc: make(chan message),
|
||||
alt: make(chan []button.Button, 2),
|
||||
}
|
||||
go result.listen()
|
||||
go result.dotelemetry()
|
||||
|
|
@ -58,6 +60,11 @@ func (v01 *V01) Close() {
|
|||
}
|
||||
|
||||
func (v01 *V01) Read() []button.Button {
|
||||
select {
|
||||
case alt := <-v01.alt:
|
||||
return alt
|
||||
default:
|
||||
}
|
||||
line := v01.src.Read()
|
||||
var msg message
|
||||
if err := json.Unmarshal(line, &msg); err != nil {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
// a key map of allowed keys
|
||||
var allowedKeys = {
|
||||
37: 'left',
|
||||
38: 'up',
|
||||
39: 'right',
|
||||
40: 'down',
|
||||
65: 'a',
|
||||
66: 'b'
|
||||
};
|
||||
|
||||
// the 'official' Konami Code sequence
|
||||
var konamiCode = ['up', 'up', 'down', 'down', 'left', 'right', 'left', 'right', 'b', 'a'];
|
||||
|
||||
// a variable to remember the 'position' the user has reached so far.
|
||||
var konamiCodePosition = 0;
|
||||
|
||||
// add keydown event listener
|
||||
document.addEventListener('keydown', function(e) {
|
||||
// get the value of the key code from the key map
|
||||
var key = allowedKeys[e.keyCode];
|
||||
// get the value of the required key from the konami code
|
||||
var requiredKey = konamiCode[konamiCodePosition];
|
||||
|
||||
// compare the key with the required key
|
||||
if (key == requiredKey) {
|
||||
|
||||
// move to the next key in the konami code sequence
|
||||
konamiCodePosition++;
|
||||
|
||||
// if the last key is reached, activate cheats
|
||||
if (konamiCodePosition == konamiCode.length) {
|
||||
showSecrets();
|
||||
konamiCodePosition = 0;
|
||||
}
|
||||
} else {
|
||||
konamiCodePosition = 0;
|
||||
}
|
||||
});
|
||||
|
||||
function showSecrets() {
|
||||
var element = document.getElementById("konami")
|
||||
element.style = "display:block"
|
||||
var e = new Event("onKonami")
|
||||
element.dispatchEvent(new Event("onKonami"))
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
function onYouTubeIframeAPIReady() {
|
||||
|
||||
var player;
|
||||
|
||||
player = new YT.Player('konami', {
|
||||
videoId: 'V4oJ62xrFZo', // 👈 video id.
|
||||
width: 560,
|
||||
height: 316,
|
||||
playerVars: {
|
||||
'autoplay': 1,
|
||||
'controls': 1,
|
||||
'showinfo': 0,
|
||||
'modestbranding': 0,
|
||||
'loop': 1,
|
||||
'fs': 0,
|
||||
'cc_load_policty': 0,
|
||||
'iv_load_policy': 3
|
||||
},
|
||||
events: {
|
||||
'onReady': function (e) {
|
||||
e.target.setVolume(33); // For max value, set value to 100.
|
||||
document.getElementById("konami").addEventListener("onKonami", () => {e.target.playVideo()})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -2,6 +2,9 @@
|
|||
<html>
|
||||
<header>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/dark.css">
|
||||
<script src="konami.js"></script>
|
||||
<script src="lowerVolume.js"></script>
|
||||
<script async src="https://www.youtube.com/iframe_api"></script>
|
||||
<script>
|
||||
function formsay(message) {
|
||||
console.log(`say '${message}'`)
|
||||
|
|
@ -33,6 +36,8 @@
|
|||
document.getElementById("ntfy").innerHTML = `<pre>${b}</pre>`
|
||||
}, null)
|
||||
}, 1500)
|
||||
|
||||
|
||||
</script>
|
||||
</header>
|
||||
<body>
|
||||
|
|
@ -74,21 +79,32 @@
|
|||
<form id="controls">
|
||||
<div style="display: flex; flex-wrap: wrap;">
|
||||
<div>
|
||||
<input type="text" maxLength=1 value="w" name="w" placeholder="up" onchange="recontrol()">
|
||||
<input type="text" maxLength=1 value="s" name="s" placeholder="down" onchange="recontrol()">
|
||||
<input type="text" maxLength=1 value="a" name="a" placeholder="left" onchange="recontrol()">
|
||||
<input type="text" maxLength=1 value="d" name="d" placeholder="right" onchange="recontrol()">
|
||||
<label for="input-up">Up</label>
|
||||
<input id="input-up" type="text" maxLength=1 value="w" name="w" placeholder="up" onchange="recontrol()">
|
||||
<label for="input-down">Down</label>
|
||||
<input id="input-down" type="text" maxLength=1 value="s" name="s" placeholder="down" onchange="recontrol()">
|
||||
<label for="input-left">Left</label>
|
||||
<input id="input-left" type="text" maxLength=1 value="a" name="a" placeholder="left" onchange="recontrol()">
|
||||
<label for="input-right">Right</label>
|
||||
<input id="input-right" type="text" maxLength=1 value="d" name="d" placeholder="right" onchange="recontrol()">
|
||||
</div>
|
||||
<div>
|
||||
<input type="text" maxLength=1 value="5" name="5" placeholder="start" onchange="recontrol()">
|
||||
<input type="text" maxLength=1 value="q" name="q" placeholder="l" onchange="recontrol()">
|
||||
<input type="text" maxLength=1 value="e" name="e" placeholder="r" onchange="recontrol()">
|
||||
<label for="input-start">Start</label>
|
||||
<input id="input-start" type="text" maxLength=1 value="5" name="5" placeholder="start" onchange="recontrol()">
|
||||
<label for="input-left-bumper">Left Bumper</label>
|
||||
<input id="input-left-bumper" type="text" maxLength=1 value="q" name="q" placeholder="l" onchange="recontrol()">
|
||||
<label for="input-right-bumper">Right Bumper</label>
|
||||
<input id="input-right-bumper" type="text" maxLength=1 value="e" name="e" placeholder="r" onchange="recontrol()">
|
||||
</div>
|
||||
<div>
|
||||
<input type="text" maxLength=1 value="1" name="1" placeholder="a" onchange="recontrol()">
|
||||
<input type="text" maxLength=1 value="2" name="2" placeholder="b" onchange="recontrol()">
|
||||
<input type="text" maxLength=1 value="3" name="3" placeholder="x" onchange="recontrol()">
|
||||
<input type="text" maxLength=1 value="4" name="4" placeholder="y" onchange="recontrol()">
|
||||
<label for="input-a">A</label>
|
||||
<input id="input-a" type="text" maxLength=1 value="1" name="1" placeholder="a" onchange="recontrol()">
|
||||
<label for="input-b">B</label>
|
||||
<input id="input-b" type="text" maxLength=1 value="2" name="2" placeholder="b" onchange="recontrol()">
|
||||
<label for="input-x">X</label>
|
||||
<input id="input-x" type="text" maxLength=1 value="3" name="3" placeholder="x" onchange="recontrol()">
|
||||
<label for="input-y">Y</label>
|
||||
<input id="input-y" type="text" maxLength=1 value="4" name="4" placeholder="y" onchange="recontrol()">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
|
@ -96,6 +112,7 @@
|
|||
</div>
|
||||
<div id="ntfy"></div>
|
||||
<div id="ws"></div>
|
||||
<div id="konami" style="display:none"></div>
|
||||
</body>
|
||||
<footer>
|
||||
<script>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package raw
|
|||
|
||||
import (
|
||||
"context"
|
||||
"embed"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"log"
|
||||
|
|
@ -9,6 +10,7 @@ import (
|
|||
"net/http/httputil"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
|
|
@ -75,16 +77,13 @@ func (ws WS) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
func (ws WS) serveHTTP(w http.ResponseWriter, r *http.Request) error {
|
||||
switch r.URL.Path {
|
||||
case "/":
|
||||
return ws.serveIndex(w, r)
|
||||
case "/api/ws":
|
||||
return ws.serveWS(w, r)
|
||||
}
|
||||
if strings.HasPrefix(r.URL.Path, "/proxy") {
|
||||
return ws.serveProxy(w, r)
|
||||
}
|
||||
http.NotFound(w, r)
|
||||
return nil
|
||||
return ws.serveStaticFile(w, r)
|
||||
}
|
||||
|
||||
func (ws WS) serveProxy(w http.ResponseWriter, r *http.Request) error {
|
||||
|
|
@ -101,16 +100,20 @@ func (ws WS) serveProxy(w http.ResponseWriter, r *http.Request) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
//go:embed public/root.html
|
||||
var rootHTML string
|
||||
//go:embed public/*
|
||||
var staticFiles embed.FS
|
||||
|
||||
func (ws WS) serveIndex(w http.ResponseWriter, r *http.Request) error {
|
||||
v := rootHTML
|
||||
func (ws WS) serveStaticFile(w http.ResponseWriter, r *http.Request) error {
|
||||
if FlagWSDebug {
|
||||
b, _ := os.ReadFile("src/device/input/raw/public/root.html")
|
||||
v = string(b)
|
||||
w.Write(b)
|
||||
return nil
|
||||
}
|
||||
w.Write([]byte(v))
|
||||
if r.URL.Path == "/" {
|
||||
r.URL.Path = "root.html"
|
||||
}
|
||||
r.URL.Path = path.Join("public", r.URL.Path)
|
||||
http.FileServer(http.FS(staticFiles)).ServeHTTP(w, r)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,8 @@ var (
|
|||
';': PSemicolon,
|
||||
'-': PMinus,
|
||||
'=': PEqual,
|
||||
'<': PageDown,
|
||||
'>': PageUp,
|
||||
}
|
||||
keyToChar = func() map[Key]byte {
|
||||
result := map[Key]byte{}
|
||||
|
|
|
|||
|
|
@ -57,4 +57,6 @@ const (
|
|||
PSemicolon = Key(keybd_event.VK_SEMICOLON)
|
||||
PMinus = Key(keybd_event.VK_MINUS)
|
||||
PEqual = Key(keybd_event.VK_EQUAL)
|
||||
PageUp = Key(keybd_event.VK_PAGEUP)
|
||||
PageDown = Key(keybd_event.VK_PAGEDOWN)
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue