More optimizations

This commit is contained in:
2025-11-25 11:59:59 -07:00
parent c84ba37353
commit fb034b9b93
4 changed files with 148 additions and 52 deletions

56
internal/maps/manager.go Normal file
View File

@@ -0,0 +1,56 @@
package maps
import (
"fmt"
"github.com/atridad/LilGuy/internal/portal"
)
type Manager struct {
maps map[string]*Map
currentMap *Map
}
func NewManager() *Manager {
return &Manager{
maps: make(map[string]*Map),
}
}
func (m *Manager) RegisterMap(mp *Map) {
m.maps[mp.ID] = mp
}
func (m *Manager) GetMap(id string) *Map {
return m.maps[id]
}
func (m *Manager) SetCurrentMap(id string) error {
mp, ok := m.maps[id]
if !ok {
return fmt.Errorf("map not found: %s", id)
}
m.currentMap = mp
return nil
}
func (m *Manager) CurrentMap() *Map {
return m.currentMap
}
func (m *Manager) ResolveTransition(event portal.TransitionEvent) (*Map, *portal.Portal) {
destMap := m.GetMap(event.DestinationMap)
if destMap == nil {
return nil, nil
}
destPortal := destMap.GetPortalByID(event.DestinationPortal)
return destMap, destPortal
}
func (m *Manager) Reset() {
for _, mp := range m.maps {
mp.Reset()
}
// Reset to default map if needed, or let the caller do it
}