fix: improve endgame clock and gameplay stability
This commit is contained in:
1 parent
ce6aabfc55
commit
658298ee86
46 files changed
+1915
-99
No files matched your search
@@ -0,0 +1,68 @@
|
||||
package sdkserver
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSceneCommandsPreserveImportedSave(t *testing.T) {
|
||||
chdirRepoRootSDK(t)
|
||||
before, err := os.ReadFile("freesr-data.json")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
run := func(command string) bool {
|
||||
body, _ := json.Marshal(map[string]string{"command": command})
|
||||
w := httptest.NewRecorder()
|
||||
apiCommand(w, httptest.NewRequest(http.MethodPost, "/api/command", strings.NewReader(string(body))))
|
||||
var result struct {
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &result); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return result.Success
|
||||
}
|
||||
persistentBefore, err := os.ReadFile("persistent")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, invalid := range []string{"/teleport invalid", "/scene 0", "/teleport 123 bad", "/teleport 123 456 extra", "/clear lineup"} {
|
||||
if run(invalid) {
|
||||
t.Fatalf("accepted %s", invalid)
|
||||
}
|
||||
after, _ := os.ReadFile("persistent")
|
||||
if string(after) != string(persistentBefore) {
|
||||
t.Fatalf("invalid command %s wrote persistent", invalid)
|
||||
}
|
||||
}
|
||||
for _, command := range []string{"/teleport 123 456"} {
|
||||
if !run(command) {
|
||||
t.Fatalf("command failed: %s", command)
|
||||
}
|
||||
after, err := os.ReadFile("freesr-data.json")
|
||||
if err != nil || string(after) != string(before) {
|
||||
t.Fatalf("%s changed imported save", command)
|
||||
}
|
||||
}
|
||||
raw, err := os.ReadFile("persistent")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var saved struct {
|
||||
Scene struct {
|
||||
PlaneID uint32 `json:"plane_id"`
|
||||
FloorID uint32 `json:"floor_id"`
|
||||
} `json:"scene"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &saved); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if saved.Scene.PlaneID != 123 || saved.Scene.FloorID != 456 {
|
||||
t.Fatalf("persistent changes missing: %+v", saved)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user