public static BirdPersonality readPersonality(this IPersistableReader r) { var ply = new BirdPersonality(); ply.A = r.ReadFloat(); ply.S = r.ReadFloat(); return(ply); }
public static BodyData readBody(this IPersistableReader r) { var bodyData = new BodyData(); bodyData.pos = r.ReadVec2(); bodyData.velocity = r.ReadVec2(); bodyData.angle = r.ReadFloat(); bodyData.angularVelocity = r.ReadFloat(); return(bodyData); }
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 float[] ReadFloatArray(this IPersistableReader self) { var cnt = self.ReadInt(); var arr = new float[cnt]; for (var i = 0; i < cnt; i++) { arr[i] = self.ReadFloat(); } return(arr); }
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 static void ReadFloatListInto(this IPersistableReader self, List <float> list, bool clearList = true) { if (clearList) { list.Clear(); } var cnt = self.ReadInt(); for (var i = 0; i < cnt; i++) { list.Add(self.ReadFloat()); } }
public void Recover(IPersistableReader rd) { Global.log.info($"{nameof(PlayPersistable)}::recover called"); // verify save file version var readVersion = rd.ReadInt(); if (version != readVersion) { Global.log.err($"save file version mismatch (got {readVersion}, expected {version})"); } setup.rehydrated = true; // indicate that this play context is rehydrated // load game time Time.TotalTime = rd.ReadFloat() + SAVE_TIME_ADVANCE; // load map seed setup.state.mapgenSeed = rd.ReadInt(); Global.log.trace($"loaded mapgen seed: {setup.state.mapgenSeed}"); // read player var playerWd = rd.readWing(); var playerBodyData = rd.readBody(); var player = setup.createPlayer(Vector2.Zero); player.uid = playerWd.uid; player.core.energy = playerWd.energy; player.mind.soul.ply = playerWd.ply; playerBodyData.copyTo(player.body); player.changeClass(playerWd.wingClass); if (playerWd.armed) { player.AddComponent <Shooter>(); } // load all wings var wingCount = rd.ReadInt(); for (var i = 0; i < wingCount; i++) { var wd = rd.readWing(); var wing = setup.createNpcWing(wd.name, Vector2.Zero, wd.ply); wing.uid = wd.uid; if (wd.armed) { wing.AddComponent <Shooter>(); } var bd = rd.readBody(); // rd.readWingMemory(wing.mind); bd.copyTo(wing.body); wing.changeClass(wd.wingClass); Global.log.trace( $"rehydrated wing {wing.name}, pos{wing.body.pos.RoundToPoint()}, ply{wing.mind.soul.ply}"); } // load world things var thingCount = rd.ReadInt(); var thingHelper = new ThingLoader(this); var loadedThings = new List <ThingLoader.LoadedThing>(); for (var i = 0; i < thingCount; i++) { // load and inflate thing var load = thingHelper.loadThing(rd); if (load != null) { loadedThings.Add(load); } else { Global.log.err("attempted to load thing, but it was NULL"); } } // now resolve all things var resolvedThings = thingHelper.resolveThings(loadedThings); foreach (var thing in resolvedThings) { // add to context setup.addThing(thing); } }
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); }