From 6d7e67b2bfb2dcd2ef5f0c0500b7c22f366d41e9 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sat, 24 Sep 2016 08:41:40 -0400 Subject: [PATCH] handle --- ent/handle.go | 23 +++++++++++++++++++++++ ent/type.go | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 ent/handle.go diff --git a/ent/handle.go b/ent/handle.go new file mode 100644 index 0000000..19cef53 --- /dev/null +++ b/ent/handle.go @@ -0,0 +1,23 @@ +package ent + +import ( + "github.com/jordanorelli/hyperstone/bit" + "github.com/jordanorelli/hyperstone/dota" +) + +func handleType(flat *dota.ProtoFlattenedSerializerFieldT, env *Env) tÿpe { + if env.symbol(int(flat.GetVarTypeSym())) != "CGameSceneNodeHandle" { + return nil + } + return handle_t{} +} + +// a handle represents a soft pointer to an entity. handles are represented by +// IDs and can cross the client-server divide. +type handle int + +type handle_t struct{} + +func (t handle_t) read(r bit.Reader) (value, error) { + return handle(bit.ReadVarInt(r)), nil +} diff --git a/ent/type.go b/ent/type.go index 6806b2c..d73f43c 100644 --- a/ent/type.go +++ b/ent/type.go @@ -26,7 +26,7 @@ func parseType(flat *dota.ProtoFlattenedSerializerFieldT, env *Env) tÿpe { } return nil } - return coalesce(atomType, qFloatType) + return coalesce(atomType, qFloatType, handleType) } // a type error is both an error and a type. It represents a type that we were