public static bool?ReadOptionalBool(this IPersistableReader self) { var hasValue = self.ReadBool(); if (!hasValue) { return(null); } return(self.ReadBool()); }
void IPersistable.Recover(IPersistableReader reader) { DeleteAll(); var cnt = reader.ReadInt(); for (var i = 0; i < cnt; i++) { var key = reader.ReadString(); _boolDict[key] = reader.ReadBool(); } cnt = reader.ReadInt(); for (var i = 0; i < cnt; i++) { var key = reader.ReadString(); _intDict[key] = reader.ReadInt(); } cnt = reader.ReadInt(); for (var i = 0; i < cnt; i++) { var key = reader.ReadString(); _floatDict[key] = reader.ReadFloat(); } cnt = reader.ReadInt(); for (var i = 0; i < cnt; i++) { var key = reader.ReadString(); _stringDict[key] = reader.ReadString(); } }
void ReadPrimitives(IPersistableReader reader) { Assert.AreEqual(reader.ReadString(), TestValues.aString); Assert.AreEqual(reader.ReadInt(), TestValues.aInt); Assert.AreEqual(reader.ReadUInt(), TestValues.aUint); Assert.AreEqual(reader.ReadFloat(), TestValues.aFloat); Assert.AreEqual(reader.ReadDouble(), TestValues.aDouble); Assert.AreEqual(reader.ReadBool(), TestValues.aBool); }
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); }