mirror of
https://github.com/bloeys/nmage.git
synced 2025-12-29 13:28:20 +00:00
Add BaseComp
This commit is contained in:
@ -1,9 +1,25 @@
|
|||||||
package entity
|
package entity
|
||||||
|
|
||||||
type Comp interface {
|
type Comp interface {
|
||||||
|
// This ensures that implementors of the Comp interface
|
||||||
|
// always embed BaseComp
|
||||||
|
base()
|
||||||
|
|
||||||
Name() string
|
Name() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ Comp = &BaseComp{}
|
||||||
|
|
||||||
|
type BaseComp struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BaseComp) base() {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BaseComp) Name() string {
|
||||||
|
return "Base Component"
|
||||||
|
}
|
||||||
|
|
||||||
func AddComp(e *Entity, c Comp) {
|
func AddComp(e *Entity, c Comp) {
|
||||||
e.Comps = append(e.Comps, c)
|
e.Comps = append(e.Comps, c)
|
||||||
}
|
}
|
||||||
|
|||||||
4
main.go
4
main.go
@ -71,12 +71,14 @@ type OurGame struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TransformComp struct {
|
type TransformComp struct {
|
||||||
|
entity.BaseComp
|
||||||
|
|
||||||
Pos *gglm.Vec3
|
Pos *gglm.Vec3
|
||||||
Rot *gglm.Quat
|
Rot *gglm.Quat
|
||||||
Scale *gglm.Vec3
|
Scale *gglm.Vec3
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t TransformComp) Name() string {
|
func (t *TransformComp) Name() string {
|
||||||
return "Transform Component"
|
return "Transform Component"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user