Private
Public Access
1
0

add music, better sync, particles
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 2m18s

This commit is contained in:
Sebastian Unterschütz
2025-11-29 23:37:57 +01:00
parent 5ce097bbb7
commit 669c783a06
43 changed files with 3001 additions and 878 deletions

View File

@@ -6,6 +6,7 @@ import (
"log"
"math/rand"
"net/http"
"sort"
"strconv"
"strings"
"time"
@@ -14,9 +15,54 @@ import (
"github.com/redis/go-redis/v9"
)
func handleEditorPage(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./secure/editor.html")
}
func handleObstacleEditorPage(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./secure/obstacle_editor.html")
}
func handleAdminChunks(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodPost {
var chunk ChunkDef
if err := json.NewDecoder(r.Body).Decode(&chunk); err != nil {
http.Error(w, "Bad JSON", 400)
return
}
chunkJson, _ := json.Marshal(chunk)
rdb.SAdd(ctx, "config:chunks:list", chunk.ID)
rdb.Set(ctx, "config:chunks:data:"+chunk.ID, chunkJson, 0)
w.WriteHeader(http.StatusOK)
}
}
func handleConfig(w http.ResponseWriter, r *http.Request) {
conf := defaultConfig
chunkIDs, _ := rdb.SMembers(ctx, "config:chunks:list").Result()
sort.Strings(chunkIDs)
var loadedChunks []ChunkDef
// 3. Details laden
for _, id := range chunkIDs {
val, err := rdb.Get(ctx, "config:chunks:data:"+id).Result()
if err == nil {
var c ChunkDef
json.Unmarshal([]byte(val), &c)
c.ID = id // Sicherstellen, dass ID gesetzt ist
loadedChunks = append(loadedChunks, c)
}
}
conf.Chunks = loadedChunks
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(defaultConfig)
json.NewEncoder(w).Encode(conf)
}
func handleStart(w http.ResponseWriter, r *http.Request) {
@@ -64,9 +110,7 @@ func handleValidate(w http.ResponseWriter, r *http.Request) {
return
}
// ---> HIER RUFEN WIR JETZT DIE SIMULATION AUF <---
isDead, score, obstacles, powerUpState, serverTick, nextSpawnTick := simulateChunk(req.SessionID, req.Inputs, req.TotalTicks, vals)
isDead, score, obstacles, platforms, powerUpState, serverTick, nextSpawnTick, finalRngState := simulateChunk(req.SessionID, req.Inputs, req.TotalTicks, vals)
status := "alive"
if isDead {
status = "dead"
@@ -78,9 +122,11 @@ func handleValidate(w http.ResponseWriter, r *http.Request) {
Status: status,
VerifiedScore: score,
ServerObs: obstacles,
ServerPlats: platforms,
PowerUps: powerUpState,
ServerTick: serverTick,
NextSpawnTick: nextSpawnTick,
RngState: finalRngState,
})
}