public static WingData readWing(this IPersistableReader r) { var wd = new WingData(); wd.uid = r.ReadLong(); wd.name = r.ReadString(); wd.wingClass = (Wing.WingClass)r.ReadInt(); wd.energy = r.ReadFloat(); wd.ply = r.readPersonality(); wd.armed = r.ReadBool(); return(wd); }
public LoadedThing loadThing(IPersistableReader rd) { var kind = (ThingKind)rd.ReadInt(); var res = default(Thing); var uid = rd.ReadLong(); var senderUid = default(long); var creatorUid = default(long); switch (kind) { case ThingKind.Capsule: { var nt = new Entity("cap"); var cap = nt.AddComponent(new Capsule()); cap.acquired = rd.ReadBool(); // read body var bodyData = rd.readBody(); bodyData.copyTo(cap.body); // read other capsule info cap.energy = rd.ReadFloat(); cap.firstAvailableAt = rd.ReadFloat(); cap.despawnAt = rd.ReadFloat(); senderUid = rd.ReadLong(); creatorUid = rd.ReadLong(); // if acquired then throw away if (cap.acquired) { cap = null; // ick } res = cap; break; } case ThingKind.Tree: { var nt = new Entity("tree"); var tree = nt.AddComponent(new Tree()); // load tree tree.Entity.Position = rd.ReadVec2(); tree.stage = rd.ReadInt(); tree.harvest = rd.ReadInt(); tree.uid = uid; tree.updateStage(); res = tree; break; } default: // unrecognized thing Global.log.err($"unrecognized thing kind: {kind}"); res = null; break; } if (res != null) { Global.log.trace($"rehydrated entity {res.GetType().Name}, pos{res.Entity.Position.RoundToPoint()}"); var loadedThing = new LoadedThing(res) { interactorUid = senderUid, creatorUid = creatorUid }; return(loadedThing); // yee } return(null); }