private void SaveOverworldData() { OverworldData overworldData = new OverworldData(OverworldGameplayManager.Instance.EditorOverworld).WithName(_overworldName); JsonOverworldFileWriter fileWriter = new JsonOverworldFileWriter(); fileWriter.SerialiseData(overworldData); }
public OverworldData LoadData() { OverworldData data = new OverworldData(); data.actorsData = LoadActors(); data.itemsData = LoadItems(); return(data); }
//############################################################################ //# Rendering and Unrendering Entities # //# An entity should be in the rendered or unrendered form, but not both. # //############################################################################ public void Save() { OverworldData data = new OverworldData(this); AdventureDb db = new AdventureDb(saveFile); db.SaveData(data); }
public void SerialiseData <T>(T overworldData) { Directory.CreateDirectory(Path.Combine(Application.dataPath, "StreamingAssets", "overworld")); _overworldData = overworldData as OverworldData; _path = Path.Combine(Application.dataPath, "StreamingAssets", "overworld/", _overworldData.Name + ".json"); string jsonDataString = JsonUtility.ToJson(_overworldData, true).ToString(); File.WriteAllText(_path, jsonDataString); }
public void SetupOverworld(OverworldData overworldData) { Overworld = InGameOverworld.Create(overworldData); InitialiseTileAttributes(); Logger.Log("Start scan..."); IEnumerator coroutine = ScanCoroutine(); StartCoroutine(coroutine); }
public void SetupOverworldForEditor(OverworldData overworldData) { EditorOverworld = EditorOverworld.Create(overworldData); InitialiseEditorTileBackgrounds(); InitialiseEditorTileAttributes(); MainScreenOverlayCanvas.Instance.ResetBlackOutSquares(); CameraManager.Instance.ResetCameras(); CameraManager.Instance.SetPanLimits(EditorOverworld.LevelBounds); }
/* Save overworld data to current file. */ public void SaveData(OverworldData dat) { /* Tear down existing database. */ conn.Close(); System.IO.File.Delete(filePath); /* Set up new database for this save. */ conn = new SqliteConnection("URI=file:" + filePath); cmd = conn.CreateCommand(); conn.Open(); CreateFile(filePath); CreateTables(); string output = "Saving overworld data for " + dat.saveFile + "\n"; output += "\tnextActorId: " + dat.nextActorId + "\n"; output += "\tnextItemId: " + dat.nextItemId + "\n"; output += "\titems: " + dat.itemsData.Count + "\n"; output += "\tactors: " + dat.actorsData.Count + "\n"; output += "\tcells: " + dat.cellsData.Count + "\n"; GD.Print(output); var trans = conn.BeginTransaction(); foreach (int id in dat.actorsData.Keys) { GD.Print("Saving actor " + id); SaveActor(dat.actorsData[id]); } foreach (int id in dat.itemsData.Keys) { GD.Print("Saving item " + id); SaveItem(dat.itemsData[id]); } foreach (int id in dat.cellsData.Keys) { SaveCell(dat.cellsData[id]); } trans.Commit(); conn.Close(); }
public NewOverworldFile(GraphicsDevice device, Overworld.MapData[,] map, string name, float seaLevel) { var worldFilePath = name + System.IO.Path.DirectorySeparatorChar + "world.png"; var metaFilePath = name + System.IO.Path.DirectorySeparatorChar + "meta.txt"; if (File.Exists(worldFilePath) && File.Exists(metaFilePath)) { // Do nothing since overworlds should be saved precisely once. return; } Data = new OverworldData(device, map, name, seaLevel); Width = map.GetLength(0); Height = map.GetLength(1); }
public static void LoadOverworld(OverworldData overworldData) { //If we are in the editor, first close the editor mode before loading an overworld through the consule if (EditorManager.InEditor) { EditorManager.CloseEditor(); } if (PersistentGameManager.CurrentSceneType == SceneType.Maze) { Logger.Warning("We are currently in the maze scene. Do not load overworld but return."); return; } // Make checks such as if there are starting locations for the players OverworldGameplayManager.Instance.UnloadOverworld(); OverworldGameplayManager.Instance.SetupOverworld(overworldData); // sets new Overworld in OverworldManager }
public InGameOverworld(OverworldData overworldData) { Name = overworldData.Name; GameManager.Instance.CurrentGameLevel = this; if (TilesContainer.Instance != null) { GameObject.Destroy(TilesContainer.Instance.gameObject); TilesContainer.Instance = null; } _overworldContainer = new GameObject(Name); _overworldContainer.transform.SetParent(GameManager.Instance.GridGO.transform); _overworldContainer.transform.position = new Vector3(0, 0, 0); _overworldContainer.AddComponent <TilesContainer>(); _overworldContainer.SetActive(true); BuildTiles(overworldData); }
// Opens the mission panel UI public void SelectLevel() { ableToLaunch = true; levelPanel.SetActive(true); // Creates a new instance of the mission panel constructor OverworldData selectionPanel = new OverworldData(data.mapPreview, data.levelName, data.description, data.launchButton, data.cancelButton); // Switches the UI information depending on which level is selected switch (level) { // If it's level 1, set all UI elements to the first item in each array pool case Level.Level1: selectionPanel.mapPreview.sprite = mapImages[0]; selectionPanel.levelName.text = levelNames[0]; selectionPanel.description.text = descriptions[0]; selectionPanel.launchButton.interactable = true; break; // If it's level 2, set all UI elements to the second item in each array pool case Level.Level2: selectionPanel.mapPreview.sprite = mapImages[1]; selectionPanel.levelName.text = levelNames[1]; selectionPanel.description.text = descriptions[1]; selectionPanel.launchButton.interactable = true; break; // If it's level 3, set all UI elements to the third item in each array pool case Level.Level3: selectionPanel.mapPreview.sprite = mapImages[2]; selectionPanel.levelName.text = levelNames[2]; selectionPanel.description.text = descriptions[2]; selectionPanel.launchButton.interactable = true; break; // If it's level 4, set all UI elements to the fourth item in each array pool case Level.Level4: selectionPanel.mapPreview.sprite = mapImages[3]; selectionPanel.levelName.text = levelNames[3]; selectionPanel.description.text = descriptions[3]; selectionPanel.launchButton.interactable = true; break; } }
public void BuildTiles(OverworldData overworldData) { Dictionary <InGameOverworldTile, List <SerialisableGridLocation> > TileTransformationGridLocationByTile = new Dictionary <InGameOverworldTile, List <SerialisableGridLocation> >(); for (int i = 0; i < overworldData.Tiles.Count; i++) { SerialisableTile serialisableTile = overworldData.Tiles[i]; GameObject tileGO = GameObject.Instantiate(OverworldGameplayManager.Instance.InGameTilePrefab, _overworldContainer.transform); InGameOverworldTile tile = tileGO.GetComponent <InGameOverworldTile>(); tile.SetGridLocation(serialisableTile.GridLocation.X, serialisableTile.GridLocation.Y); tile.SetId(serialisableTile.Id); tileGO.name = "Tile" + tile.GridLocation.X + ", " + tile.GridLocation.Y; tileGO.transform.position = GridLocation.GridToVector(tile.GridLocation); Tiles.Add(tile); AddBackgroundSprites(serialisableTile, tile); AddTileAttributes(serialisableTile, tile); AddCornerFillers(serialisableTile, tile); TilesByLocation.Add(tile.GridLocation, tile); GridLocation furthestBounds = LevelBounds; if (tile.GridLocation.X > furthestBounds.X) { _levelBounds.X = tile.GridLocation.X; } if (tile.GridLocation.Y > furthestBounds.Y) { _levelBounds.Y = tile.GridLocation.Y; } TileTransformationGridLocationByTile.Add(tile, serialisableTile.TilesToTransform); } for (int k = 0; k < Tiles.Count; k++) { InGameOverworldTile tile = Tiles[k] as InGameOverworldTile; tile.AddNeighbours(this); } }
public void BuildTiles(OverworldData overworldData) { for (int i = 0; i < overworldData.Tiles.Count; i++) { SerialisableTile serialisableTile = overworldData.Tiles[i]; GameObject tileGO = GameObject.Instantiate(OverworldGameplayManager.Instance.EditorTilePrefab, _overworldContainer.transform); EditorOverworldTile tile = tileGO.GetComponent <EditorOverworldTile>(); tile.SetGridLocation(serialisableTile.GridLocation.X, serialisableTile.GridLocation.Y); tile.SetId(serialisableTile.Id); tileGO.name = "Tile" + tile.GridLocation.X + ", " + tile.GridLocation.Y; tileGO.transform.position = GridLocation.GridToVector(tile.GridLocation); Tiles.Add(tile); AddTileAttributes(serialisableTile, tile); AddBackgroundSprites(serialisableTile, tile); AddCornerFillers(serialisableTile, tile); ITileMainMaterial mainMaterial = AddMainMaterial(serialisableTile); tile.SetMainMaterial(mainMaterial); TilesByLocation.Add(tile.GridLocation, tile); GridLocation furthestBounds = LevelBounds; if (tile.GridLocation.X > furthestBounds.X) { _levelBounds.X = tile.GridLocation.X; } if (tile.GridLocation.Y > furthestBounds.Y) { _levelBounds.Y = tile.GridLocation.Y; } } for (int k = 0; k < Tiles.Count; k++) { EditorOverworldTile tile = Tiles[k] as EditorOverworldTile; tile.AddNeighbours(this); } }
public bool ReadFile(string filePath) { var worldFilePath = filePath + System.IO.Path.DirectorySeparatorChar + "world.png"; var metaFilePath = filePath + System.IO.Path.DirectorySeparatorChar + "meta.txt"; Data = FileUtils.LoadJson <OverworldData>(metaFilePath, false); var worldTexture = TextureManager.LoadInstanceTexture(worldFilePath, false); if (worldTexture != null) { Data.LoadFromTexture(worldTexture); } else { Console.Out.WriteLine("Failed to load overworld texture."); return(false); } return(true); }
/* Asks the cartographer to make a new world */ public void InitWorld() { if (Session.session.adventureSettings != null && Session.session.adventureSettings.load) { AdventureDb db = new AdventureDb(saveFile); OverworldData dat = db.LoadData(); actorsData = dat.actorsData; itemsData = dat.itemsData; return; } Cartographer cart = new Cartographer(); cart.GenerateWorld(this); cellsData = cart.cells; itemsData = cart.items; actorsData = cart.actors; }
public EditorOverworld(OverworldData overworldData) { GameManager.Instance.CurrentEditorLevel = this; Name = overworldData.Name; if (TilesContainer.Instance != null) { GameObject.Destroy(TilesContainer.Instance.gameObject); TilesContainer.Instance = null; } _overworldContainer = new GameObject(Name); _overworldContainer.transform.SetParent(GameManager.Instance.GridGO.transform); _overworldContainer.transform.position = new Vector3(0, 0, 0); _overworldContainer.AddComponent <TilesContainer>(); _overworldContainer.SetActive(true); BuildTiles(overworldData); MazeLevelNames = MazeLevelLoader.GetAllPlayableLevelNames(); }
public void LoadOverworld() { Logger.Log("Load overworld (in editor)"); if (string.IsNullOrWhiteSpace(_overworldName)) { Logger.Warning(Logger.Datawriting, "In order to save the overworld, please fill in an overworld name"); return; } bool overworldNameExists = OverworldLoader.OverworldExists(_overworldName); if (overworldNameExists) { OverworldData overworldData = OverworldLoader.LoadOverworldData(_overworldName); OverworldLoader.LoadOverworldForEditor(overworldData); } EditorSelectedOverworldTileModifierContainer selectedTileModifierContainer = EditorCanvasUI.Instance.SelectedTileModifierContainer as EditorSelectedOverworldTileModifierContainer; selectedTileModifierContainer?.SetInitialModifierValues(); EditorOverworldTileModificationPanel.Instance?.Reset(); EditorOverworldTileModificationPanel.Instance?.DestroyModifierActions(); }
public void CopyFrom(OverworldFile file) { Data = file.Data; }
public OverworldFile(Overworld.MapData[,] map, string name) { Data = new OverworldData(map, name); }
public OverworldFile(GraphicsDevice device, Overworld.MapData[,] map, string name, float seaLevel) { Data = new OverworldData(device, map, name, seaLevel); }
public void Start() { switch (PersistentGameManager.CurrentSceneType) { case SceneType.Overworld: Logger.Log("instantiate overworld sprites, tiles and characters"); if (PersistentGameManager.SceneLoadOrigin == SceneLoadOrigin.Gameplay) { if (PersistentGameManager.OverworldName == "") { PersistentGameManager.SetOverworldName("overworld"); } string overworldName = PersistentGameManager.OverworldName; Logger.Log($"We will load the maze '{overworldName}'"); OverworldData startUpOverworldData = OverworldLoader.LoadOverworldData(overworldName); if (startUpOverworldData == null) { Logger.Error("Could not find the default overworld for startup"); } OverworldLoader.LoadOverworld(startUpOverworldData); if (OverworldGameplayManager.Instance.Overworld == null) { Logger.Log(Logger.Initialisation, "No overworld loaded on startup. Returning"); return; } } // We loaded a overworld scene through the editor. Set up an empty grid for in the editor else { Logger.Log("create empty grid"); EditorCanvasUI.Instance.OverworldModificationPanel.GenerateTiles(); } break; case SceneType.Maze: // We loaded a maze scene through the game. Set up the maze level if (PersistentGameManager.SceneLoadOrigin == SceneLoadOrigin.Gameplay) { if (PersistentGameManager.CurrentSceneName == "") { PersistentGameManager.SetCurrentSceneName("default"); } string mazeName = PersistentGameManager.CurrentSceneName; PersistentGameManager.SetLastMazeLevelName(mazeName); Logger.Log($"We will load the maze '{mazeName}'"); MazeLevelData startUpMazeLevelData = MazeLevelLoader.LoadMazeLevelData(mazeName); if (startUpMazeLevelData == null) { Logger.Error($"Could not find the level {mazeName} for startup. Will load defult level instead."); mazeName = "default"; startUpMazeLevelData = MazeLevelLoader.LoadMazeLevelData(mazeName); } MazeLevelLoader.LoadMazeLevel(startUpMazeLevelData); if (CurrentGameLevel == null) { Logger.Log(Logger.Initialisation, "No level loaded on startup. Returning"); return; } if (CurrentGameLevel.PlayerCharacterSpawnpoints.Count == 0) { return; } PlayableLevelNames = MazeLevelLoader.GetAllPlayableLevelNames(); } // We loaded a maze scene through the editor. Set up an empty grid for in the editor else { Logger.Log("create empty grid"); EditorCanvasUI.Instance.MazeModificationPanel.GenerateTiles(); } break; default: Logger.Error($"Scenetype {PersistentGameManager.CurrentSceneType} is not implemented yet"); break; } }
public static void LoadOverworldForEditor(OverworldData overworldData) { OverworldGameplayManager.Instance.UnloadOverworld(); OverworldGameplayManager.Instance.SetupOverworldForEditor(overworldData); // sets up the level without instantiating characters etc. }
public static InGameOverworld Create(OverworldData overworldData) { Logger.Log(Logger.Initialisation, $"Set up new Maze Level '<color={ConsoleConfiguration.HighlightColour}>{overworldData.Name}</color>'"); return(new InGameOverworld(overworldData)); }
public void GenerateTiles() { if (_gridWidth < 3) { Logger.Warning(Logger.Level, "Cannot generate a tile grid with a width of {0}. The minimum generatable grid width is 3", _gridWidth); return; } if (_gridWidth > 25) { Logger.Warning(Logger.Level, "Cannot generate a tile grid with a width of {0}. The maximum generatable grid width is 20", _gridWidth); return; } if (_gridHeight < 3) { Logger.Warning(Logger.Level, "Cannot generate a tile grid with a height of {0}. The minimum generatable grid height is 3", _gridHeight); return; } if (_gridHeight > 25) { Logger.Warning(Logger.Level, "Cannot generate a tile grid with a height of {0}. The maximum generatable grid height is 20", _gridHeight); return; } Logger.Log("Generate tile grid with a width of {0} and a height of {1}", _gridWidth, _gridHeight); // remove everything from the currently loaded level OverworldGameplayManager.Instance.UnloadOverworld(); // Create a new level from scratch with a obstacle ring at the edges List <SerialisableTile> tiles = new List <SerialisableTile>(); for (int i = 0; i < _gridWidth; i++) { for (int j = 0; j < _gridHeight; j++) { string tileId = Guid.NewGuid().ToString(); GridLocation gridLocation = new GridLocation(i, j); SerialisableTileMainMaterial mainMaterial = new SerialisableTileMainMaterial("GroundMainMaterial", new SerialisableLandMaterial()); List <SerialisableTileAttribute> tileAttributes = new List <SerialisableTileAttribute>(); List <SerialisableTileBackground> tileBackgrounds = new List <SerialisableTileBackground>(); List <SerialisableTileCornerFiller> tileCornerFillers = new List <SerialisableTileCornerFiller>(); SerialisableTileBaseGround baseBackground = TryAddBaseBackgroundForNewOverworld(tileBackgrounds, tileAttributes); if (baseBackground != null) { tileBackgrounds.Add(new SerialisableTileBackground(baseBackground.GetType().ToString(), baseBackground)); } SerialisableTile tile = new SerialisableTile(tileId, mainMaterial, tileAttributes, tileBackgrounds, tileCornerFillers, gridLocation.X, gridLocation.Y); tiles.Add(tile); } } OverworldData newOverworldData = new OverworldData(); newOverworldData.Tiles = tiles; OverworldLoader.LoadOverworldForEditor(newOverworldData); }