package systems import ( "fmt" "log/slog" "math/rand" "github.com/EngoEngine/ecs" "code.ndumas.com/ndumas/muddy/components" ) type Exit struct { *components.ID *components.Observable To, From uint64 } type Room struct { *components.ID *components.Location *components.Observable *components.Inventory } type RoomSystem struct { L *slog.Logger // replace this with cache fronted db access later Rooms map[uint64]*Room } func (rs *RoomSystem) New(w *ecs.World) { rs.L.Debug("initializing room system") z := 0 for i := range 10 { for j := range 10 { rs.Rooms[uint64(z)] = &Room{ ID: &components.ID{ ID: uint64(z), }, Location: &components.Location{ X: int64(i), Y: int64(j), Exits: make([]uint64, 0), }, Observable: &components.Observable{ Name: fmt.Sprintf("Room (%d,%d)", i, j), Description: fmt.Sprintf("%s", "A non-descript room."), }, Inventory: &components.Inventory{}, } rs.L.With( slog.Int("X", i), slog.Int("Y", j), slog.Int("ID", z), ).Debug("loaded room") z++ } } } func (rs *RoomSystem) Update(dt float32) { rs.L.Debug("tick") weather := []string{ "The sky is clear and birds sing.", "It's dark and rainy.", "It's raining men, hallelujah!", } if rand.Intn(2000) > 1990 { fmt.Println(weather[rand.Intn(len(weather))]) } // flush changes to persistent storage } func (rs *RoomSystem) Remove(e ecs.BasicEntity) {}