// Get the savable script attached to this GO and return its seed public SeedCollection reap() { ISavable[] blades = GetComponents <ISavable> (); SeedCollection collection = new SeedCollection(gameObject, blades); collection.prefabPath = prefabPath; collection.registeredID = registeredID; //pass in this RO's parent object, ifex Transform parent = gameObject.transform.parent; if (parent != null) { RegisteredObject parentRO = parent.GetComponent <RegisteredObject> (); if (parentRO != null) { collection.parentID = parentRO.registeredID; } } else { collection.parentID = ""; } return(collection); }
private IEnumerator Dungeon_TriggerEvents(On.Dungeon.orig_TriggerEvents orig, Dungeon self, Room openingRoom, HeroMobCommon opener, bool canTriggerDungeonEvent) { SeedCollection collection = SeedCollection.GetMostCurrentSeeds(self.ShipName, self.Level); if (collection == null || !collection.Enabled || isHumanWrapper.Value) { yield return(self.StartCoroutine(orig(self, openingRoom, opener, canTriggerDungeonEvent))); yield break; } else { // Load seeds for each door from files/somewhere // Restore the seed for this room openingRoom RandomGenerator.RestoreSeed(); // Calls TriggerEvents the proper number of times. Hangs on this call. // Random deviation seems to appear while this Coroutine is running, possibly due to monster random actions? // Could fix this by storing all before/after seeds, but doesn't that seem lame? // Would like to find a way of only wrapping the Random calls with this so that there is less UnityEngine.Random.seed // noise from other sources that occur during the runtime. // The above will probably not work, so instead wrap everything EXCEPT for the wait in the Random Save/Restore // Possible error from SpawnWaves, SpawnMobs (cause they have dedicated Coroutines that run) yield return(self.StartCoroutine(orig(self, openingRoom, opener, canTriggerDungeonEvent))); // I'm going to cheat for now and SKIP the saving step - the same exact seed is ALWAYS used for RandomGenerator // When using RandomGenerator seeds. //mod.Log("Saving Seed!"); //RandomGenerator.SaveSeed(); yield break; } }
// Save the player's data at the end of a scene public void savePlayer() { if (_player != null) { playerData = _player.GetComponent <RegisteredObject> ().Reap(); } }
public void TestSeedCollectionParsing() { var seeds = SeedCollection.FromJson(System.Text.Encoding.UTF8.GetString(Resources.userevent)); Assert.IsNotNull(seeds, "Expected seeds"); Assert.AreEqual(1, seeds.Count, "Expected seeds"); Assert.AreEqual(SeedType.MixId, seeds.FirstOrDefault().Type, "Expected mix seed"); }
public static void Clear() { inputs = new Dictionary <int, List <TASInput> >(); Dungeon d = SingletonManager.Get <Dungeon>(false); SeedCollection.ReadAll(); seeds = SeedCollection.GetMostCurrentSeeds(d.ShipName, d.Level); if (seeds == null) { seeds = SeedCollection.Create(); } }
// Tells the SSM that a RO has been destroyed through gameplay private void SaveDestruction() { if (prefabPath != "") { return; } SeedCollection seed = Reap(); seed.destroyed = true; SceneStateManager.GetInstance().Store(RID, seed); }
public void OnLoad() { mod.Load(); if (mod.EnabledWrapper.Value) { // This reads all of the seeds that we have in local files into RAM so that we can use it. SeedCollection.ReadAll(); // When the level loads, need to instead load a seed from config, for example // So the only things that seem to exist in the same locations are the layouts, layout sizes, and exits // Other static/dynamic events are unknown based off of solely Seed // However... What if I used recursive logging to find all of the data i need, then use recursive reading/setting in the same order. On.InputManager.Update += InputManager_Update; } }
public Save() { saveName = gameName = currScene = ""; sceneTime = 0f; gameTime = 0.0; currScene = ""; prevScene = ""; difficulty = Difficulty.easy; playerData = null; dtUnlocks = 0; abilities = 0; }
public Save(SerializationInfo info, StreamingContext context) { saveName = info.GetString("saveName"); gameName = info.GetString("gameName"); sceneTime = info.GetSingle("sceneTime"); gameTime = info.GetDouble("gameTime"); currScene = info.GetString("currScene"); prevScene = info.GetString("prevScene"); difficulty = (Difficulty)info.GetInt32("difficulty"); playerData = (SeedCollection)info.GetValue("playerData", typeof(SeedCollection)); dtUnlocks = info.GetInt32("dtUnlocks"); abilities = info.GetInt32("abilities"); }
private void Awake() { if (instance == null) { instance = this; } else if (instance != null) { Destroy(gameObject); } DontDestroyOnLoad(gameObject); deseeder = new SeedDeserializer(); _seedCollection = deseeder.DeserializeSeeds(); this.GenerateTiles(); }
public async void VehiclesController_GetVehicleByUuid(Guid uuid) { try { var options = new DbContextOptionsBuilder <NMTFleetManagerContext>() .UseSqlite(connection) .Options; using (context = new NMTFleetManagerContext(options)) { context.Database.OpenConnection(); context.Database.EnsureCreated(); } using (context = new NMTFleetManagerContext(options)) { SeedCollection seedCollection = SeedData.Seed(); context.Vehicles.AddRange(seedCollection.Vehicles); context.SaveChanges(); } using (context = new NMTFleetManagerContext(options)) { var expected = await context.Vehicles.SingleOrDefaultAsync(v => v.Uuid == uuid); vehiclesController = new VehiclesController(context); var actionResult = await vehiclesController.GetVehicleByUuid(uuid); if (expected == null) { Assert.IsType <NotFoundResult>(actionResult.Result); } else { var okResult = actionResult.Result as OkObjectResult; var actual = okResult?.Value as Vehicle; Assert.Equal(expected, actual); } } } finally { connection.Close(); } }
private void InputManager_Update(On.InputManager.orig_Update orig, InputManager self) { orig(self); Dungeon d = SingletonManager.Get <Dungeon>(false); if (!overwriteWrapper.Value) { SeedCollection.UnLoad(); } else { if (!SeedCollection.Loaded) { mod.Log("Reinitializing SeedCollection because it isn't loaded!"); SeedCollection.ReadAll(); } } if (d == null) { return; } if (Input.GetKeyUp((KeyCode)Enum.Parse(typeof(KeyCode), saveKeyWrapper.Value))) { mod.Log("Saving SeedData to SeedCollection!"); SeedCollection best = SeedCollection.GetMostCurrentSeeds(d.ShipName, d.Level); if (best == null) { mod.Log("Creating new SeedCollection because there were no matching SeedCollections!"); best = SeedCollection.Create(); } SeedData data = new SeedData(); d.EnqueueNotification("Saved SeedData: " + data + " to: " + best.ReadFrom); best.Add(d.ShipName, d.Level, data); SeedCollection.WriteAll(); mod.Log("Wrote SeedCollection to: " + best.ReadFrom); } if (Input.GetKeyUp((KeyCode)Enum.Parse(typeof(KeyCode), createNewSeedKeyWrapper.Value))) { mod.Log("Created new SeedCollection!"); SeedCollection best = SeedCollection.Create(); SeedData data = new SeedData(); best.Add(d.ShipName, d.Level, data); SeedCollection.WriteAll(); d.EnqueueNotification("Saved SeedData: " + data + " to new: " + best.ReadFrom); mod.Log("Wrote SeedCollection to: " + best.ReadFrom); } }
// Get the reapable scripts attached to this GO and return their seeds public SeedCollection Reap() { IReapable[] blades = GetComponents <IReapable> (); if (blades.Length <= 0) { Console.println(ToString() + " has no additional values to reap", Console.Tag.info); } else { Console.println(ToString() + " reaped values.", Console.Tag.info); } SeedCollection collection = new SeedCollection(gameObject, blades); collection.ignoreReset = ignoreReset; //pass in a prefabPath so that if this RO is a prefab, it can be spawned again later collection.prefabPath = prefabPath; collection.prefabName = prefabName; if (prefabPath != "" && prefabName != "") { collection.registeredID = registeredID; } //pass in this RO's parent object, ifex Transform parent = gameObject.transform.parent; if (parent != null) { RegisteredObject parentRO = parent.GetComponent <RegisteredObject> (); if (parentRO != null) { collection.parentID = parentRO.registeredID; } else { Console.println(ToString() + " is under a non-RO. Make its parent an RO to save its data properly.", Console.Tag.error); } } else { collection.parentID = ""; } return(collection); }
// Take a seed and pass it along to the savable script attached to this GO public void sow(SeedCollection collection) { if (allowReset <= 0) { return; } ISavable[] holes = GetComponents <ISavable> (); //intercept and save prefabPath prefabPath = collection.prefabPath; if (collection.size > 0) { collection.loadSeeds(gameObject, holes); } }
// Take a seed collection and distrubute it among the reapable scripts attached to this GO public void Sow(SeedCollection collection) { IReapable[] holes = GetComponents <IReapable> (); if (holes.Length <= 0) { Console.println(ToString() + " has nowhere to sow values", Console.Tag.info); } else { Console.println(ToString() + " sowed values.", Console.Tag.info); } //intercept and save prefabPath prefabPath = collection.prefabPath; prefabName = collection.prefabName; collection.SowSeeds(gameObject, holes); }
public async void VehiclesController_GetVehicles() { // Arrange (DB schema) try { // TODO: UseModel to override OnModelCreating var options = new DbContextOptionsBuilder <NMTFleetManagerContext>() .UseSqlite(connection) .Options; using (context = new NMTFleetManagerContext(options)) { context.Database.OpenConnection(); context.Database.EnsureCreated(); } // Seed data into the context using (context = new NMTFleetManagerContext(options)) { SeedCollection seedCollection = SeedData.Seed(); context.Vehicles.AddRange(seedCollection.Vehicles); context.SaveChanges(); } // Assert using (context = new NMTFleetManagerContext(options)) { int expected = 5; vehiclesController = new VehiclesController(context); var actionResult = await vehiclesController.GetVehicles(); var okResult = actionResult.Result as OkObjectResult; var vehicles = okResult?.Value as IEnumerable <Vehicle>; var actual = vehicles.Count(); Assert.Equal(expected, actual); } } finally { connection.Close(); } }
private Save fillSave() { Save save = new Save(); save.gameName = gameName; save.saveName = saveName; save.sceneTime = sceneTime; save.gameTime = totalTime; save.currScene = currScene; save.prevScene = prevScene; save.difficulty = _difficulty; save.playerData = playerData = player.GetComponent <RegisteredObject>().Reap(); save.dtUnlocks = _damageTypeUnlocks; save.abilities = _abilities; return(save); }
public SeedCollection DeserializeSeeds() { SeedCollection seeds = null; try { using (StreamReader r = new StreamReader("Assets//Scripts//Data//SeedData.json")) { string json = r.ReadToEnd(); //Rootobject o = Newtonsoft.Json.JsonConvert.DeserializeObject<Rootobject>(json); seeds = Newtonsoft.Json.JsonConvert.DeserializeObject <SeedCollection>(json); } } catch (Exception e) { Debug.Log(e); } return(seeds); }
// Loads the values in a save into the GameManager for resuming a game public void loadGame(Save save) { saveName = save.saveName; gameName = save.gameName; sceneTime = save.sceneTime; totalTime = save.gameTime; currScene = save.currScene; prevScene = save.prevScene; _difficulty = save.difficulty; playerData = save.playerData; _damageTypeUnlocks = save.dtUnlocks; _abilities = save.abilities; loadData(saveName); playerSpawnType = SPAWN_AT_SVPNT; SceneStateManager.GetInstance().JumpTo(save.currScene); }
// Called by RegisteredObjects when their client components are destroyed in gameplay. // Places the passed seed into the current scene's dictionary public void Store(string ID, SeedCollection seed) { //get the data for the current scene. if none exists, create a container Dictionary <string, SeedCollection> currData; if (!scenes.TryGetValue(SceneManager.GetActiveScene().name, out currData)) { currData = new Dictionary <string, SeedCollection> (); scenes.Add(SceneManager.GetActiveScene().name, currData); } //add the entry to the current scene dictionary if (currData.ContainsKey(ID)) { currData.Remove(ID); } currData.Add(ID, seed); Console.println("[SSM] Created destruction entry for \"" + ID + "\"", Console.Tag.info, Console.nameToChannel("SSM")); }
public void Awake() { if (_instance == null) { _instance = this; DontDestroyOnLoad(gameObject); } else { Destroy(gameObject); } SceneStateManager.GetInstance().IgnoreCurrentScene(); paused = false; pauseLock = false; saveName = ""; gameName = ""; sceneTime = 0f; totalTime = 0.0; currScene = ""; prevScene = ""; _difficulty = Difficulty.easy; _player = null; playerData = null; playerSpawnType = 0; _damageTypeUnlocks = 0; unlockDT(DamageType.PHYSICAL); _abilities = 0; saveDirectory = Application.persistentDataPath + Path.DirectorySeparatorChar + "saves" + Path.DirectorySeparatorChar; dataDirectory = Application.persistentDataPath + Path.DirectorySeparatorChar + "data" + Path.DirectorySeparatorChar; }
public void TestSeedCollectionEqualityAndHashCodes() { var seeds1 = new SeedCollection(Seed.FromMixId(MixId)); var seeds2 = new SeedCollection(Seed.FromMixId(MixId)); var seeds3 = new SeedCollection(Seed.FromArtistId(ArtistId)); SeedCollection nullSeeds1 = null; SeedCollection nullSeeds2 = null; Assert.AreEqual(seeds1, seeds2, "Expected equality"); Assert.IsTrue(nullSeeds1 == nullSeeds2, "Expected equality"); Assert.IsTrue(seeds1 == seeds2, "Expected equality"); Assert.IsTrue(seeds1 != seeds3, "Expected inequality"); Assert.IsFalse(seeds1.Equals(null), "Expected inequality"); Assert.IsTrue(seeds1.Equals(seeds1), "Expected equality"); Assert.IsTrue(seeds1.Equals(seeds2), "Expected equality"); Assert.AreNotEqual(seeds1.GetHashCode(), 0, "Expected a hashcode"); Assert.IsNotNull(seeds1.GetEnumerator(), "Expected Enumerator"); Assert.IsNotNull((seeds1 as IEnumerable).GetEnumerator(), "Expected Enumerator"); }
public void TestBadMixJsonHandling() { SeedCollection.FromJson("{\"mix\":{\"badid\":\"123456\"}}"); }
//public Tile GrassTileExample; SeedManager() { deseeder = new SeedDeserializer(); _seedCollection = deseeder.DeserializeSeeds(); }
/// <summary> /// Creates a Mix from a JSON Object /// </summary> /// <param name="item">The item.</param> /// <param name="settings">The settings.</param> /// <returns> /// A Mix object /// </returns> internal static Mix FromJToken(JToken item, IMusicClientSettings settings) { const string PlayMeThumbUri = "http://dev.mixrad.io/assets/playme/{0}x{0}.png"; if (item == null) { return null; } bool parentalAdvisory = false; JToken parentaladvisoryToken = item["parentaladvisory"]; if (parentaladvisoryToken != null) { parentalAdvisory = item.Value<bool>("parentaladvisory"); } JToken featuredArtists = item["featuredartists"]; var featuredArtistsList = new List<Artist>(); if (featuredArtists != null) { foreach (JToken token in featuredArtists) { Artist artist = Artist.FromJToken(token, settings); featuredArtistsList.Add(artist); } } Uri square50 = null; Uri square100 = null; Uri square200 = null; Uri square320 = null; Uri square640 = null; var thumbnailsToken = item["thumbnails"]; MusicItem.ExtractThumbs(thumbnailsToken, out square50, out square100, out square200, out square320); if (thumbnailsToken != null) { square640 = Mix.ExtractThumb(thumbnailsToken, "640x640"); } var seeds = item["seeds"]; SeedCollection seedCollection = null; if (seeds != null) { seedCollection = SeedCollection.FromJson(item.ToString()); } else { var mixId = item.Value<string>("id"); if (!string.IsNullOrEmpty(mixId)) { seedCollection = new SeedCollection(Seed.FromMixId(mixId)); } } var name = item.Value<string>("name"); var description = item.Value<string>("description"); if (seedCollection != null && seedCollection.Count > 0) { if (seedCollection.Count(s => s.Type == SeedType.UserId) > 0) { if (square50 == null) { square50 = new Uri(string.Format(PlayMeThumbUri, 50)); } if (square100 == null) { square100 = new Uri(string.Format(PlayMeThumbUri, 100)); } if (square200 == null) { square200 = new Uri(string.Format(PlayMeThumbUri, 200)); } if (square320 == null) { square320 = new Uri(string.Format(PlayMeThumbUri, 320)); } if (square640 == null) { square640 = new Uri(string.Format(PlayMeThumbUri, 640)); } if (string.IsNullOrEmpty(name)) { name = "Play Me"; } } else if (seedCollection.Count(s => s.Type == SeedType.ArtistId) > 0) { var artistSeeds = seedCollection.Where(s => (s.Type == SeedType.ArtistId)).ToArray(); if (string.IsNullOrEmpty(name)) { // Derive a name var names = artistSeeds.Select(s => s.Name).Where(s => !string.IsNullOrEmpty(s)).ToArray(); name = names.Length > 0 ? string.Join(", ", names) : "Artist Mix"; } // Derive a thumbnail image var idSeed = artistSeeds.FirstOrDefault(s => !string.IsNullOrEmpty(s.Id)); if (idSeed != null && settings != null) { var builder = new ArtistImageUriWriter(settings); if (square50 == null) { square50 = builder.BuildForId(idSeed.Id, 50); } if (square100 == null) { square100 = builder.BuildForId(idSeed.Id, 100); } if (square200 == null) { square200 = builder.BuildForId(idSeed.Id, 200); } if (square320 == null) { square320 = builder.BuildForId(idSeed.Id, 320); } if (square640 == null) { square640 = builder.BuildForId(idSeed.Id, 640); } } } } return new Mix() { Name = name, TrackCount = item.Value<int>("numbertracks"), ParentalAdvisory = parentalAdvisory, Seeds = seedCollection, Thumb50Uri = square50, Thumb100Uri = square100, Thumb200Uri = square200, Thumb320Uri = square320, Thumb640Uri = square640, Description = description, FeaturedArtists = featuredArtistsList }; }
public void UnLoad() { mod.UnLoad(); On.InputManager.Update -= InputManager_Update; SeedCollection.UnLoad(); }
public async void VehiclesController_PutVehicle(Guid uuid, Vehicle vehicle) { try { var options = new DbContextOptionsBuilder <NMTFleetManagerContext>() .UseSqlite(connection) .Options; using (context = new NMTFleetManagerContext(options)) { context.Database.OpenConnection(); context.Database.EnsureCreated(); } using (context = new NMTFleetManagerContext(options)) { SeedCollection seedCollection = SeedData.Seed(); context.Vehicles.AddRange(seedCollection.Vehicles); context.SaveChanges(); } using (context = new NMTFleetManagerContext(options)) { var controller = new VehiclesController(context); var actionResult = await controller.PutVehicle(uuid, vehicle); bool validVehicle = await context.Vehicles.AnyAsync(v => v.Uuid == uuid && v.Uuid == vehicle.Uuid); if (validVehicle) { Assert.IsType <NoContentResult>(actionResult); var expected = vehicle; var actual = await context.Vehicles.SingleOrDefaultAsync(v => v.Uuid == uuid); output.WriteLine(expected.ToString()); output.WriteLine(actual.ToString()); Assert.Equal(expected, actual); } else { Assert.IsNotType <NoContentResult>(actionResult); var invalidVehicle = vehicle; var actual = await context.Vehicles.SingleOrDefaultAsync(v => v.Uuid == uuid); if (actual == null) { actual = await context.Vehicles.SingleOrDefaultAsync(v => v.Uuid == vehicle.Uuid); if (actual == null) { // since actual does not refer to any existing vehicle in the context, pass test Assert.Null(actual); return; } } // ensure that the corresponding vehicle in the context has not been updated Assert.NotEqual(invalidVehicle.Odometer, actual.Odometer); Assert.NotEqual(invalidVehicle.Registration, actual.Registration); } } } finally { connection.Close(); } }
public void TestSeedCollectionInitialisation() { var nullSeeds = new SeedCollection(); Assert.AreEqual(0, nullSeeds.Count, "Expected no seeds"); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // Create title and gameover screens introScreen = new GameScreen(this, Content.Load<Texture2D>("textures/titleScreen"), 10.0f); gameoverScreen = new GameOverGameScreen(this, Content.Load<Texture2D>("textures/gameoverScreen"), 3.0f); // Create main game related stuff world = new World(); world.Load(); // load textures playerTexture = Content.Load<Texture2D>("textures/playerTexture"); backgroundTexture = Content.Load<Texture2D>("Background/Background_1"); backgroundTexture2 = Content.Load<Texture2D>("Background/Background_2"); backgroundTexture3 = Content.Load<Texture2D>("Background/Background_3"); this.black = Content.Load<Texture2D>("black"); this.noise = Content.Load<Texture2D>("noise"); this.parallaxCollection = new ParallaxCollection(this); // create map panel mapPanel = new MapPanel(this, Content.Load<Texture2D>("textures/centerBar"), Content.Load<Texture2D>("textures/darkBar"), Content.Load<Texture2D>("textures/mapIcons")); // create players players = new List<PlayerSprite>(); players.Add(new PlayerSprite(this, 0, new Vector3(3, world.getHeigth(3), 1.0f), playerTexture) { color = new Color(0x48, 0xe6, 0xfe, 255) }); players.Add(new PlayerSprite(this, 1, new Vector3(-3, world.getHeigth(-3), 1.0f), playerTexture) { color = new Color(0xf8, 0xfe, 0x4d, 255) }); // create game screens splitScreens = new RenderTarget2D[2]; splitScreens[0] = new RenderTarget2D(GraphicsDevice, SPLIT_SCREEN_WIDTH, SPLIT_SCREEN_HEIGHT); splitScreens[1] = new RenderTarget2D(GraphicsDevice, SPLIT_SCREEN_WIDTH, SPLIT_SCREEN_HEIGHT); joinedScreen = new RenderTarget2D(GraphicsDevice, SCREEN_WIDTH, SCREEN_HEIGHT); // create cameras cameras = new GameCamera[2]; cameras[0] = new GameCamera(this, splitScreens[0].ToVector(), 0, players[0].worldPosition); cameras[0].FollowPlayer(players[0]); cameras[1] = new GameCamera(this, splitScreens[1].ToVector(), 1, players[1].worldPosition); cameras[1].FollowPlayer(players[1]); joinedCamera = new GameCamera(this, GraphicsDevice.Viewport.ToVector(), 2, new Vector3(0.0f, 0.0f, 1.0f)); // load GUI related stuff spriteFont = Content.Load<SpriteFont>("fonts/Geo"); headlineFont = Content.Load<SpriteFont>("fonts/headline"); scriptFont = Content.Load<SpriteFont>("fonts/script"); menuButtons = Content.Load<Texture2D>("textures/menuButtons"); // create tree collection treeCollection = new TreeCollection(this); treeCollection.Load(); treeCollection.Reset(); // create seed collection seedCollection = new SeedCollection(this); seedCollection.Load(); seedCollection.Reset(); CreateRandomSeeds(NUM_INITIAL_SEEDS, treeCollection.trees[0]); // create fairy collection fairyCollection = new FairyCollection(this); fairyCollection.Load(playerTexture); fairyCollection.Reset(); /* spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, null, null, null, null, GameCamera.CurrentCamera.screenTransform); foreground.Draw(this, gameTime, i); */ // reset "The Void" ResetVoids(1.0f); this.State = GameState.INTRO; }