//go:build wasm
// +build wasm

package main

import (
	_ "embed"
	"encoding/json"
	"log"

	"git.zb-server.de/ZB-Server/EscapeFromTeacher/pkg/game"
)

//go:embed web/assets/chunks/start.json
var chunkStartData []byte

//go:embed web/assets/chunks/chunk_01.json
var chunk01Data []byte

//go:embed web/assets/chunks/chunk_02.json
var chunk02Data []byte

//go:embed web/assets/chunks/chunk_03.json
var chunk03Data []byte

//go:embed web/assets/chunks/chunk_04.json
var chunk04Data []byte

// loadChunks lädt alle Chunks aus eingebetteten Daten (WebAssembly)
func (g *Game) loadChunks() {
	chunkDataMap := map[string][]byte{
		"start":    chunkStartData,
		"chunk_01": chunk01Data,
		"chunk_02": chunk02Data,
		"chunk_03": chunk03Data,
		"chunk_04": chunk04Data,
	}

	count := 0
	for id, data := range chunkDataMap {
		var c game.Chunk
		if err := json.Unmarshal(data, &c); err == nil {
			if c.ID == "" {
				c.ID = id
			}
			g.world.ChunkLibrary[c.ID] = c
			count++
			log.Printf("📦 Chunk geladen: %s (Width=%d, Objects=%d)", c.ID, c.Width, len(c.Objects))
		} else {
			log.Printf("⚠️  Fehler beim Laden von Chunk %s: %v", id, err)
		}
	}

	log.Printf("✅ %d Chunks für WASM geladen", count)
}
