mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-04 07:37:48 -05:00
c52c6648dd
Systems now place all of their component factories into a `Components` member. This improves code readability and makes it clear when we are dealing specifically with ecs components. The concrete ComponentFactory instances now have `Add` and `Get` methods (as opposed to `AddAlpha` or `GetAlpha`). This enforces naming of component factories as to avoid collisions when embedded in a struct with other components. Also, the ComponentFactory interface is embedded directly into the concrete component factory without a name.
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package d2systems
|
|
|
|
import (
|
|
"github.com/gravestench/akara"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
|
|
)
|
|
|
|
const (
|
|
logPrefixGameObjectFactory = "Object Factory"
|
|
)
|
|
|
|
// static check that GameObjectFactory implements the System interface
|
|
var _ akara.System = &GameObjectFactory{}
|
|
|
|
// GameObjectFactory is a wrapper system for subordinate sceneSystems that
|
|
// do the actual object creation work.
|
|
type GameObjectFactory struct {
|
|
akara.BaseSystem
|
|
*d2util.Logger
|
|
Sprites *SpriteFactory
|
|
Shapes *ShapeSystem
|
|
UI *UIWidgetFactory
|
|
}
|
|
|
|
// Init will initialize the Game Object Factory by injecting all of the factory subsystems into the world
|
|
func (t *GameObjectFactory) Init(world *akara.World) {
|
|
t.World = world
|
|
|
|
t.setupLogger()
|
|
|
|
t.Debug("initializing ...")
|
|
|
|
t.injectSubSystems()
|
|
}
|
|
|
|
func (t *GameObjectFactory) setupLogger() {
|
|
t.Logger = d2util.NewLogger()
|
|
t.SetPrefix(logPrefixGameObjectFactory)
|
|
}
|
|
|
|
func (t *GameObjectFactory) injectSubSystems() {
|
|
t.Debug("creating sprite factory")
|
|
t.Sprites = NewSpriteFactory(t.BaseSystem, t.Logger)
|
|
t.Shapes = NewShapeSystem(t.BaseSystem, t.Logger)
|
|
t.UI = NewUIWidgetFactory(t.BaseSystem, t.Logger, t.Sprites, t.Shapes)
|
|
}
|
|
|
|
// Update updates all the sub-sceneSystems
|
|
func (t *GameObjectFactory) Update() {
|
|
t.Sprites.Update()
|
|
t.Shapes.Update()
|
|
t.UI.Update()
|
|
}
|