public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { solver.m_solverSubSteps = (int)solverSubSteps; parameters.m_numIterations = (int)numOfIterations; if (m_FlexParticleLocker.picked) { //TODO: check if the labeled behavior already contains a behavior and append to that behavior if (m_createBehavior.labeledBehavior.Count == 0) { print("No behaviors in Serilazable Map"); tempIVD = new SerializableMap <int, Vector3>(); tempIVD.Add(m_FlexParticleLocker.pMouseParticleID, m_FlexParticleLocker.pMouseParticlePos); m_createBehavior.labeledBehavior.Add(m_behaviorName.text, tempIVD); } else { print("There are behaviors"); foreach (var index in m_createBehavior.labeledBehavior) { if (m_behaviorName.text == index.Key) { foreach (var behavior in m_createBehavior.labeledBehavior.Values) { print(behavior.Keys); behavior.Add(m_FlexParticleLocker.pMouseParticleID, m_FlexParticleLocker.pMouseParticlePos); //m_createBehavior.labeledBehavior.Add(m_behaviorName.text, behavior); } } } } //this.GetComponent<CreateBehavior>().labeledBehavior.Add(this.GetComponent<CreateBehavior>().behaviorName.text, tempIVD); m_FlexParticleLocker.picked = false; } }
public World(ContentManager Content, Game1 game, Player player, string filename) { this.game = game; this.Content = Content; this.scripts = new Queue <ScriptChain>(); this.ui = new UiSystem(Content); lua = new Lua(); lua.LoadCLRPackage(); this.player = player; this.player.setWorld(this); lua["l"] = new LuaAPI(game, this, ui, this.player, Content); lua["player"] = this.player; lua.DoString(@" import ('Lakeside2', 'Lakeside2') import ('Lakeside2', 'Lakeside2.UI') import ('Lakeside2', 'Lakeside2.Scripting')"); camera = new TilemapCamera(null); TileMap map; if (filename == null) { map = new TileMap(Content, 20, 10); } else { map = SerializableMap.Load(Content, filename); } setMap(map); camera.setCenteringEntity(this.player); }
public void goToWorld(Player p, string filename, bool resetLocation = true) { if (states.Peek() is World) { startFade(() => { World w = (World)states.Peek(); if (resetLocation) { w.setMap(SerializableMap.Load(Content, filename)); } else { w.setMap(SerializableMap.Load(Content, filename), p.getTileLocation()); } }, false); } else { startFade(() => { Vector2 oldLocation = p.getTileLocation(); setState(new World(Content, this, p, filename)); if (!resetLocation) { p.setTileLocation(oldLocation); } }, states.Peek() is TitleScreen); } }
public void RestoreMemento(SerializableMap memento) { _pvcAllocateWait = memento.pvcAllocateWait; _lastPvcSector = memento.lastPvcSector; for (int i = 0; i < Sectors.Length; i++) { Sectors[i].RestoreMemento(memento.sectors[i]); } }
public override void SaveToMap(SerializableMap map) { ForEachMember(m => m.SaveToMap(map)); if (IsSaveable) { map.Groups.Add(ToSerializableGroup()); } }
void Start() { tempIVD = new SerializableMap <int, Vector3>(); m_FlexParticleLocker = FindObjectOfType <MyFlexMouseDrag>(); m_contextBehavior = FindObjectOfType <ContextBehavior>(); m_createBehavior = FindObjectOfType <CreateBehavior>(); m_Dropdown = FindObjectOfType <Dropdown>().GetComponent <Dropdown>(); m_Dropdown.onValueChanged.AddListener(delegate { m_contextBehavior.DeformCharacter(m_Dropdown); }); //m_Deform.AddListener(delegate { deformParticle(flexCont, pInd, pVect); }); //m_Dropdown.onValueChanged.AddListener(delegate { assignDeform = true; PostContainerUpdate(flexSolver, flexCont, flexParams); }); }
public void changeMap(string filename, Vector2 location) { TileMap newMap = SerializableMap.Load(Content, filename); if (newMap != null) { pushUiElement(new UiScreenFade(() => { world.setMap(newMap, location); }), 0, 0); } }
public static void TestWrite() { SerializableMap map = new SerializableMap() { CurrentMap = Utilites.u.CurrentMap, Collisions = Utilites.u.Collisions }; map.Players = new List <Player>(); map.Enemys = new List <Enemy>(); map.Doors = new List <Door>(); map.FakeWalls = new List <FakeWall>(); map.ItemConteiners = new List <ItemConteiner>(); map.Leavers = new List <Leaver>(); map.Characters = new List <Character>(); foreach (var item in Renderer.Characters) { if (item is Player p) { map.Players.Add(p); } else if (item is Enemy e) { map.Enemys.Add(e); } else if (item is Door d) { map.Doors.Add(d); } else if (item is FakeWall f) { map.FakeWalls.Add(f); } else if (item is ItemConteiner i) { map.ItemConteiners.Add(i); } else if (item is Leaver l) { map.Leavers.Add(l); } else { map.Characters.Add(item); } } using (StreamWriter file = File.CreateText(@"Example.json")) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, map); } }
private void SaveMap() { const string mapFilePath = "scripts/MapEditor/maps/test.map"; var serializableMap = new SerializableMap { MapName = $"{Game.Player.Name}'s Map", AuthorName = Game.Player.Name, MapObjects = _spawnedObjects.Select(mapObject => new SerializableMapObject(mapObject)), }; _mapPersistenceManager.SaveMap(mapFilePath, serializableMap); NativeUtility.UserFriendlyPrint($"Map saved to {mapFilePath}"); }
static void Load(string fileName) { SerializableMap map = new SerializableMap(); try { JsonSerializer serializer = new JsonSerializer(); using (StreamReader file = File.OpenText(fileName)) { using (JsonReader reader = new JsonTextReader(file)) { map = serializer.Deserialize <SerializableMap>(reader); } } } catch (Exception) { Console.WriteLine("can't load map"); } Utilites.u.CurrentMap = map.CurrentMap; Utilites.u.Collisions = map.Collisions; foreach (var item in map.Players) { Renderer.AddChar(item); } foreach (var item in map.Enemys) { Renderer.AddChar(item); } foreach (var item in map.Doors) { Renderer.AddChar(item); } foreach (var item in map.FakeWalls) { Renderer.AddChar(item); } foreach (var item in map.ItemConteiners) { Renderer.AddChar(item); } foreach (var item in map.Leavers) { Renderer.AddChar(item); } foreach (var item in map.Characters) { Renderer.AddChar(item); } }
public abstract void SaveToMap(SerializableMap map);
public void LoadMapData(int mapNumber) { ClearMapTiles(); mapSpawner.ClearMapRoot(); mapSpawner.DrawMapRoot(); int mapCount = LoadedMapcount; if(mapNumber > mapCount) { Debug.Log("Map index out of range"); return; } LoadedMapFileIndex = mapNumber; Debug.Log("Load Map #" + LoadedMapFileIndex); SerializableMap loadedData = new SerializableMap(); loadedData = FileManager.LoadMapData(LoadedMapFileIndex); Debug.Log("Load Named: " + loadedData.MapName); mapNameInput.text = loadedData.MapName; for (int i = 0; i < loadedData.HexTiles.Count; i++) { HexMapTile tempTile = mapSpawner.SpawnNewTile(); tempTile.SetTileCoords(new Vector3(loadedData.HexTiles[i].TileCoordX, loadedData.HexTiles[i].TileCoordY, loadedData.HexTiles[i].TileCoordZ)); tempTile.SetTileType(loadedData.HexTiles[i].TileType); AddTile(tempTile); } MapData = hexMap; mapSpawner.RefreshMapTiles(); }
public void onInput(InputHandler input) { bool interactingWithUi = ui.onInput(input); if (interactingWithUi) { return; } cursor.onInput(input); if (input.isKeyPressed(Keys.F2)) // Save { UiElement filename = new UiTextInput("Save Filename: ").addCallback(element => { UiTextInput input = (UiTextInput)element; if (input.text != "") { SerializableMap.Save(Content, map, input.text); } }); ui.pushElement(filename, Vector2.One); } else if (input.isKeyPressed(Keys.F3)) // Load { UiElement filename = new UiTextInput("Load Filename: ").addCallback(element => { UiTextInput input = (UiTextInput)element; if (input.text != "") { TileMap newMap = SerializableMap.Load(Content, input.text); if (newMap != null) { this.world.setMap(newMap); cursor.setLocation(Vector2.Zero); } } }); ui.pushElement(filename, Vector2.One); } else if (input.isKeyPressed(Keys.E)) // Edit tile properties { Tile selected = map.getTile(cursor.getTileLocation()); NPC npc = map.getNPC(cursor.getTileLocation()); LuaScript script = map.getScript(cursor.getTileLocation()); if (selected != null) { ui.pushElement(new UiTileEditor(Content, selected, npc, script).addCallback(element => { UiTileEditor editor = (UiTileEditor)element; map.setTile(cursor.getTileLocation(), editor.tile); map.setNPC(cursor.getTileLocation(), editor.npc); map.setScript(cursor.getTileLocation(), editor.script); lastEditedTile = editor.tile; lastEditedScript = editor.script; }), new Vector2(160, 0)); } } else if (input.isKeyHeld(Keys.P)) // Tile painter { if (lastEditedTile != null) { map.setTile(cursor.getTileLocation(), new Tile(lastEditedTile)); if (lastEditedScript != null) { map.setScript(cursor.getTileLocation(), new LuaScript(lastEditedScript.filename)); } } } else if (input.isKeyPressed(Keys.M)) // Edit map meta info { ui.pushElement(new UiMapMetaEditor(Content, map), new Vector2(160, 0)); } }
public TestConfigData() { Properties = new SerializableMap <string, object>(10); this.Version = "1.1.0"; this.Name = ""; }
public ModuleConfigData() { Properties = new SerializableMap <string, object>(50); }
public override void SaveToMap(SerializableMap map) { map.Rectangles.Add(GetSerializableRectangle()); }
public static void SaveNew(SerializableMap mapData) { FileManager.savedMaps.Add(mapData); WriteSaveFile(); }
public static void SaveAtIndex(int index, SerializableMap mapData) { savedMaps[index] = mapData; WriteSaveFile(); }
public void SaveMapData() { Debug.Log("Save"); SerializableMap saveFile = new SerializableMap(); saveFile.MapName = mapNameInput.text; int savedTileCount = 0; for (int i = 0; i < hexMap.HexTiles.Count; i++) { HexMapTile currTile = hexMap.HexTiles[i]; TileData tempData = new TileData(); tempData.TileType = currTile.HexTileData.TileType; tempData.TileCoordX = currTile.TileCoords.x; tempData.TileCoordY = currTile.TileCoords.y; tempData.TileCoordZ = currTile.TileCoords.z; saveFile.HexTiles.Add(tempData); savedTileCount++; } if(loadedMapFileIndex < 0) { FileManager.SaveNew(saveFile); } else { FileManager.SaveAtIndex(loadedMapFileIndex, saveFile); } Debug.Log("Saved " + savedTileCount + " total tiles"); }
public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { //Note: might need to use a Coroutine instead! //Stop flex animation first then track particle positions for this object; if (m_UIController.turnOffAnim) { flyCamEnable = true; //List<Vector3> templist = null; //Vector3 temp; this.GetComponent <FlexAnimation>().enabled = false; //might have to move this to start to optimize flyCam.enabled = true; playerController.enabled = false; //StartCoroutine(MoveParticle()); //int x = this.GetComponent<FlexMouseDrag>().m_mouseParticle; if (m_UIController.doneMoving) { m_UIController.turnOffAnim = false; m_UIController.doneMoving = false; //print(reset.position); playerController.enabled = true; } } if (m_UIController.turnOnAnim) { //Note: need to save the behavior as an asset possibly or JSON?, need to ask stefan. //string jsonData = JSONSerializer.ToJson<Dictionary<int, Vector3>>(behavior); //File.WriteAllText(Application.persistentDataPath + "/test.json", jsonData); // test C# way of serializing: XmlSerializer xmlserializer = new XmlSerializer(labeledBehavior.GetType()); //FileStream file = File.Open( "C:/Users/siciit/AppData/LocalLow/DefaultCompany/Nvidia_softAnim_trials/labbehaviorTrial2.xml", FileMode.Open, FileAccess.Write); //FileStream file = File.Open(Application.persistentDataPath + "/labbehaviorTrial2.xml", FileMode.Open, FileAccess.Read); if (!System.IO.File.Exists(Application.persistentDataPath + "/labbehaviorTrial3.xml")) { /* FileStream*/ file = File.Open(Application.persistentDataPath + "/labbehaviorTrial3.xml", FileMode.OpenOrCreate, FileAccess.Write); } else { /*FileStream */ file = File.Open(Application.persistentDataPath + "/labbehaviorTrial3.xml", FileMode.Open, FileAccess.Write); } xmlserializer.Serialize(file, labeledBehavior); file.Flush(); file.Close(); flyCamEnable = false; //JSONSerializer.Save<Dictionary<int, Vector3>>("test", behavior); //if (behaviorName != null) // { // print(behaviorName.text); // } this.GetComponent <FlexAnimation>().enabled = true; m_UIController.turnOnAnim = false; } if (m_UIController.showAnim) { m_UIController.showAnim = false; XmlSerializer readSerialize = new XmlSerializer(typeof(SerializableMap <string, SerializableMap <int, Vector3> >)); //FileStream file = new FileStream(Application.persistentDataPath + "/labbehaviorTrial2.xml", FileMode.Open); ///*FileStream */file = File.Open("C:/Users/siciit/AppData/LocalLow/DefaultCompany/Nvidia_softAnim_trials/labbehaviorTrial2.xml", FileMode.Open, FileAccess.Read); /*FileStream*/ file = File.Open(Application.persistentDataPath + "/labbehaviorTrial3.xml", FileMode.Open, FileAccess.Read); print(file.Name); container = readSerialize.Deserialize(file) as SerializableMap <string, SerializableMap <int, Vector3> >; foreach (var var in container) { print(var.Key); print(var.Value); } //this.GetComponent<GetBehaviors>().localContainer = container; //this.GetComponent<GetBehaviors>().gotXML = true; getBehaviors.localContainer = container; getBehaviors.gotXML = true; //FindObjectOfType<GetBehaviors> ().localContainer = container; //FindObjectOfType<GetBehaviors>().gotXML = true; file.Flush(); file.Close(); } //store list ofvectors that have changed positions; }