2020-11-18 21:33:22 -05:00
|
|
|
package d2systems
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gravestench/akara"
|
2020-11-22 04:37:55 -05:00
|
|
|
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
|
2020-11-18 21:33:22 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
logPrefixGameObjectFactory = "Object Factory"
|
|
|
|
)
|
|
|
|
|
|
|
|
// static check that GameObjectFactory implements the System interface
|
|
|
|
var _ akara.System = &GameObjectFactory{}
|
|
|
|
|
2020-12-06 02:16:16 -05:00
|
|
|
// GameObjectFactory is a wrapper system for subordinate sceneSystems that
|
2020-11-22 04:37:55 -05:00
|
|
|
// do the actual object creation work.
|
2020-11-18 21:33:22 -05:00
|
|
|
type GameObjectFactory struct {
|
2020-11-28 00:45:58 -05:00
|
|
|
akara.BaseSystem
|
2020-11-18 21:33:22 -05:00
|
|
|
*d2util.Logger
|
2020-12-08 16:38:46 -05:00
|
|
|
Sprites *SpriteFactory
|
|
|
|
Shapes *ShapeSystem
|
|
|
|
UI *UIWidgetFactory
|
2020-11-18 21:33:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Init will initialize the Game Object Factory by injecting all of the factory subsystems into the world
|
|
|
|
func (t *GameObjectFactory) Init(world *akara.World) {
|
2020-11-28 00:45:58 -05:00
|
|
|
t.World = world
|
|
|
|
|
|
|
|
t.setupLogger()
|
|
|
|
|
2020-12-08 13:42:19 -05:00
|
|
|
t.Debug("initializing ...")
|
2020-11-28 00:45:58 -05:00
|
|
|
|
2020-11-18 21:33:22 -05:00
|
|
|
t.injectSubSystems()
|
|
|
|
}
|
|
|
|
|
2020-11-28 00:45:58 -05:00
|
|
|
func (t *GameObjectFactory) setupLogger() {
|
|
|
|
t.Logger = d2util.NewLogger()
|
|
|
|
t.SetPrefix(logPrefixGameObjectFactory)
|
|
|
|
}
|
|
|
|
|
2020-11-18 21:33:22 -05:00
|
|
|
func (t *GameObjectFactory) injectSubSystems() {
|
2020-12-08 13:42:19 -05:00
|
|
|
t.Debug("creating sprite factory")
|
2020-12-08 16:38:46 -05:00
|
|
|
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)
|
2020-11-18 21:33:22 -05:00
|
|
|
}
|
|
|
|
|
2020-12-06 02:16:16 -05:00
|
|
|
// Update updates all the sub-sceneSystems
|
2020-11-18 21:33:22 -05:00
|
|
|
func (t *GameObjectFactory) Update() {
|
2020-12-08 16:38:46 -05:00
|
|
|
t.Sprites.Update()
|
|
|
|
t.Shapes.Update()
|
|
|
|
t.UI.Update()
|
2020-11-18 21:33:22 -05:00
|
|
|
}
|