reflection goes out of the window

This commit is contained in:
2019-11-10 01:24:45 +03:00
parent bc00262ead
commit f442dc6921
16 changed files with 87 additions and 63 deletions

View File

@ -1,8 +1,8 @@
package mob
import (
"lab.zaar.be/thefish/alchemyst-go/engine/ecs"
"lab.zaar.be/thefish/alchemyst-go/engine/types"
"reflect"
)
type Mob struct {
@ -15,6 +15,6 @@ func (m *Mob) Render() {
}
func (mob Mob) TypeOf() reflect.Type {
return reflect.TypeOf(mob)
func (mob Mob) Type() string {
return ecs.MobComponent
}

View File

@ -5,7 +5,6 @@ import (
"lab.zaar.be/thefish/alchemyst-go/engine/gamemap"
"lab.zaar.be/thefish/alchemyst-go/engine/mob"
"lab.zaar.be/thefish/alchemyst-go/engine/types"
"reflect"
)
type Moveable struct {
@ -13,6 +12,9 @@ type Moveable struct {
Level *gamemap.Level
}
func (mov Moveable) Type() string {
return ecs.MoveableComponent
}
func (mov Moveable) Walk() {
@ -23,9 +25,9 @@ func (mov Moveable) IsBlocked(c types.Coords) bool {
if mov.Level.GetTile(c).BlocksPass == true {
return true
}
list := mov.Controller.GetEntitiesWithComponent(mob.Mob{}.TypeOf())
list := mov.Controller.GetEntitiesWithComponent(ecs.MobComponent)
for idx, _ := range list {
coords := mov.Controller.GetComponent(list[idx], types.Coords{}.TypeOf())
coords := mov.Controller.GetComponent(list[idx], ecs.CoordsComponent)
if coords == nil {
continue
}
@ -33,7 +35,7 @@ func (mov Moveable) IsBlocked(c types.Coords) bool {
if coords != c {
continue
}
m := mov.Controller.GetComponent(list[idx], mob.Mob{}.TypeOf())
m := mov.Controller.GetComponent(list[idx], ecs.MobComponent)
if m == nil {
continue
}
@ -43,7 +45,3 @@ func (mov Moveable) IsBlocked(c types.Coords) bool {
}
return false
}
func (mov Moveable) TypeOf() reflect.Type {
return reflect.TypeOf(mov)
}