by now i need logging and error handling
parent
857483bffa
commit
b9f254112a
@ -1,36 +1,45 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/jordanorelli/hyperstone/bit"
|
||||
)
|
||||
|
||||
type Context struct {
|
||||
Namespace
|
||||
*Namespace
|
||||
entities map[int]Entity
|
||||
}
|
||||
|
||||
func NewContext() *Context {
|
||||
return &Context{entities: make(map[int]Entity)}
|
||||
return &Context{Namespace: new(Namespace), entities: make(map[int]Entity)}
|
||||
}
|
||||
|
||||
func (c *Context) CreateEntity(id int, r bit.Reader) {
|
||||
func (c *Context) CreateEntity(id int, r bit.Reader) error {
|
||||
classId := int(c.readClassId(r))
|
||||
if len(c.Namespace.classes) == 0 {
|
||||
return fmt.Errorf("unable to create entity %d: namespace has no classes", id)
|
||||
}
|
||||
r.ReadBits(17) // ???
|
||||
classV := int(bit.ReadVarInt(r))
|
||||
className := c.classIds[classId]
|
||||
class := c.Class(className, classV)
|
||||
if class == nil {
|
||||
return fmt.Errorf("unable to create entity %d: no class found for class name %s, version %d", className, classV)
|
||||
}
|
||||
Debug.Printf("create entity id: %d classId: %d className: %v class: %v\n", id, classId, className, class)
|
||||
e := class.New()
|
||||
e.Read(r)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Context) UpdateEntity(id int, r bit.Reader) {
|
||||
|
||||
Debug.Printf("update entity id: %d\n", id)
|
||||
}
|
||||
|
||||
func (c *Context) DeleteEntity(id int) {
|
||||
|
||||
Debug.Printf("delete entity id: %d\n", id)
|
||||
}
|
||||
|
||||
func (c *Context) LeaveEntity(id int) {
|
||||
|
||||
Debug.Printf("leave entity id: %d\n", id)
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
var (
|
||||
Debug = log.New(ioutil.Discard, "DEBUG ent: ", 0)
|
||||
Info = log.New(os.Stdout, "INFO end: ", 0)
|
||||
)
|
Loading…
Reference in New Issue