public void AddBackgroundSprites(SerialisableTile serialisableTile, EditorOverworldTile tile) { EditorOverworldTileBackgroundPlacer tileBackgroundPlacer = new EditorOverworldTileBackgroundPlacer(tile); foreach (SerialisableTileBackground serialisableTileBackground in serialisableTile.TileBackgrounds) { Type type = Type.GetType(serialisableTileBackground.BackgroundType); if (type.Equals(typeof(SerialisableTilePathBackground))) { SerialisableTilePathBackground serialisableTilePathBackground = (SerialisableTilePathBackground)JsonUtility.FromJson(serialisableTileBackground.SerialisedData, type); tileBackgroundPlacer.PlacePath(new OverworldDefaultPathType(), new TileConnectionScoreInfo(serialisableTilePathBackground.TileConnectionScore)); } else if (type.Equals(typeof(SerialisableTileBaseGround))) { SerialisableTileBaseGround serialisableTileBaseGround = (SerialisableTileBaseGround)JsonUtility.FromJson(serialisableTileBackground.SerialisedData, type); tileBackgroundPlacer.PlaceGround(new OverworldDefaultGroundType(), new TileConnectionScoreInfo(serialisableTileBaseGround.TileConnectionScore)); } else if (type.Equals(typeof(SerialisableTileBaseWater))) { tileBackgroundPlacer.PlaceCoveringBaseWater(); //tileBackgroundPlacer.PlaceBackground<OverworldTileBaseWater>(); } else { Logger.Error($"Unknown TileBackgroundType {serialisableTileBackground.BackgroundType}"); } } }
private void AddBackgroundSprites(SerialisableTile serialisableTile, InGameMazeTile tile) { InGameMazeTileBackgroundPlacer tileBackgroundPlacer = new InGameMazeTileBackgroundPlacer(tile); foreach (SerialisableTileBackground serialisableTileBackground in serialisableTile.TileBackgrounds) { Type type = Type.GetType(serialisableTileBackground.BackgroundType); if (type.Equals(typeof(SerialisableTilePathBackground))) { SerialisableTilePathBackground serialisableTilePathBackground = (SerialisableTilePathBackground)JsonUtility.FromJson(serialisableTileBackground.SerialisedData, type); tileBackgroundPlacer.PlacePath(new MazeLevelDefaultPathType(), new TileConnectionScoreInfo(serialisableTilePathBackground.TileConnectionScore)); } else if (type.Equals(typeof(SerialisableTileBaseGround))) { SerialisableTileBaseGround serialisableTileBaseGround = (SerialisableTileBaseGround)JsonUtility.FromJson(serialisableTileBackground.SerialisedData, type); tileBackgroundPlacer.PlaceGround(new MazeLevelDefaultGroundType(), new TileConnectionScoreInfo(serialisableTileBaseGround.TileConnectionScore)); } else if (type.Equals(typeof(SerialisableTileBaseWater))) { tileBackgroundPlacer.PlaceBackground <MazeTileBaseWater>(); } else { Logger.Error($"Unknown TileBackgroundId {serialisableTileBackground.TileBackgroundId}"); } } }
private void AddTileAreas(SerialisableTile serialisableTile, MazeTile tile) { for (int i = 0; i < serialisableTile.TileAreaIds?.Count; i++) { string tileAreaId = serialisableTile.TileAreaIds[i]; if (TileAreas.TryGetValue(tileAreaId, out TileArea tileArea)) { tile.AddTileArea(tileArea); } } }
public OverworldData(EditorOverworld overworld) { for (int i = 0; i < overworld.Tiles.Count; i++) { SerialisableTile tile = new SerialisableTile(overworld.Tiles[i]); Tiles.Add(tile); } foreach (KeyValuePair <string, TileArea> item in overworld.TileAreas) { SerialisableTileArea tileArea = new SerialisableTileArea(item.Value); TileAreas.Add(tileArea); } }
public MazeLevelData(EditorMazeLevel level) { for (int i = 0; i < level.Tiles.Count; i++) { SerialisableTile tile = new SerialisableTile(level.Tiles[i]); Tiles.Add(tile); } foreach (KeyValuePair <string, TileArea> item in level.TileAreas) { SerialisableTileArea tileArea = new SerialisableTileArea(item.Value); TileAreas.Add(tileArea); } }
private void AddCornerFillers(SerialisableTile serialisableTile, InGameMazeTile tile) { InGameMazeTileBackgroundPlacer tileBackgroundPlacer = new InGameMazeTileBackgroundPlacer(tile); // corner filler is also an IBackground foreach (SerialisableTileCornerFiller serialisableTileCornerFiller in serialisableTile.TileCornerFillers) { if (Enum.TryParse(serialisableTileCornerFiller.TileCorner, out TileCorner tileCorner)) { tileBackgroundPlacer.PlaceCornerFiler(tileCorner); } else { Logger.Error($"Could not parse the TileCorner value{serialisableTileCornerFiller.TileCorner}"); } } }
private ITileMainMaterial AddMainMaterial(SerialisableTile serialisableTile) { SerialisableTileMainMaterial serialisableMainMaterial = serialisableTile.MainMaterial; if (serialisableMainMaterial.MainMaterialType == "GroundMainMaterial") { return(new GroundMainMaterial()); } else if (serialisableMainMaterial.MainMaterialType == "WaterMainMaterial") { return(new WaterMainMaterial()); } else { Logger.Error($"Unknown SerialisableTileMainMaterial {serialisableMainMaterial.MainMaterialType}"); return(null); } }
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); } }
private GridLocation GetMazeLevelBounds(MazeLevelData mazeLevelData) { GridLocation furthestBounds = new GridLocation(0, 0); for (int i = 0; i < mazeLevelData.Tiles.Count; i++) { SerialisableTile tile = mazeLevelData.Tiles[i]; if (tile.GridLocation.X > furthestBounds.X) { furthestBounds.X = tile.GridLocation.X; } if (tile.GridLocation.Y > furthestBounds.Y) { furthestBounds.Y = tile.GridLocation.Y; } } return(furthestBounds); }
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 void AddTileAttributes(SerialisableTile serialisableTile, EditorOverworldTile tile) { EditorOverworldTileAttributePlacer tileAttributePlacer = new EditorOverworldTileAttributePlacer(tile); foreach (SerialisableTileAttribute serialisableTileAttribute in serialisableTile.TileAttributes) { Type type = Type.GetType(serialisableTileAttribute.AttributeType); //if (tileAttributeId == SerialisableTileAttribute.ObstacleAttributeCode) //{ // tileAttributePlacer.PlaceTileObstacle(ObstacleType.Bush, new TileConnectionScoreInfo(serialisableTileAttribute.ObstacleConnectionScore, serialisableTileAttribute.SpriteNumber)); //TODO, find a way to use polymorphism so we can cast as SerialisableTileObstacleAttribute instead of a general //} //else if (tileAttributeId == SerialisableTileAttribute.PlayerExitCode) //{ // tileAttributePlacer.PlacePlayerExit(ObstacleType.Bush, new TileConnectionScoreInfo(serialisableTileAttribute.ObstacleConnectionScore, serialisableTileAttribute.SpriteNumber)); //} if (type.Equals(typeof(SerialisablePlayerSpawnpointAttribute))) { tileAttributePlacer.PlacePlayerSpawnpoint(); } else if (type.Equals(typeof(SerialisableMazeLevelEntryAttribute))) { SerialisableMazeLevelEntryAttribute serialisableMazeLevelEntryAttribute = (SerialisableMazeLevelEntryAttribute)JsonUtility.FromJson(serialisableTileAttribute.SerialisedData, type); MazeLevelEntry mazeLevelEntry = tileAttributePlacer.PlaceMazeLevelEntry(serialisableMazeLevelEntryAttribute.MazeLevelName); MazeEntries.Add(mazeLevelEntry); } //else if (tileAttributeId == SerialisableTileAttribute.PlayerOnlyAttributeCode) //{ // tileAttributePlacer.PlacePlayerOnlyAttribute(PlayerOnlyType.Bush); //} //else if (tileAttributeId == SerialisableTileAttribute.EnemySpawnpointCode) //{ // tileAttributePlacer.PlaceEnemySpawnpoint(); //} else { Logger.Error($"Unknown tile attribute of the type {type}"); } } }
private void AddTileAttributes(SerialisableTile serialisableTile, InGameOverworldTile tile) { InGameOverworldTileAttributePlacer tileAttributePlacer = new InGameOverworldTileAttributePlacer(tile); foreach (SerialisableTileAttribute serialisableTileAttribute in serialisableTile.TileAttributes) { Type type = Type.GetType(serialisableTileAttribute.AttributeType); if (type.Equals(typeof(SerialisableMazeLevelEntryAttribute))) { SerialisableMazeLevelEntryAttribute serialisableMazeLevelEntryAttribute = (SerialisableMazeLevelEntryAttribute)JsonUtility.FromJson(serialisableTileAttribute.SerialisedData, type); MazeLevelEntry mazeLevelEntry = tileAttributePlacer.PlaceMazeLevelEntry(serialisableMazeLevelEntryAttribute.MazeLevelName); MazeEntries.Add(mazeLevelEntry); } else if (type.Equals(typeof(SerialisablePlayerSpawnpointAttribute))) { tileAttributePlacer.PlacePlayerSpawnpoint(); } else { Logger.Error($"Unknown tile attribute of type {type}"); } } }
public override void BuildTiles(MazeLevelData mazeLevelData) { Dictionary <InGameMazeTile, List <SerialisableGridLocation> > TileTransformationGridLocationByTile = new Dictionary <InGameMazeTile, List <SerialisableGridLocation> >(); for (int i = 0; i < mazeLevelData.Tiles.Count; i++) { SerialisableTile serialisableTile = mazeLevelData.Tiles[i]; GameObject tileGO = GameObject.Instantiate(MazeLevelGameplayManager.Instance.InGameTilePrefab, _mazeContainer.transform); InGameMazeTile tile = tileGO.GetComponent <InGameMazeTile>(); 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); AddTileAreas(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); } foreach (KeyValuePair <InGameMazeTile, List <SerialisableGridLocation> > item in TileTransformationGridLocationByTile) { List <InGameMazeTile> tilesToTransform = new List <InGameMazeTile>(); for (int i = 0; i < item.Value.Count; i++) { for (int j = 0; j < Tiles.Count; j++) { InGameMazeTile tile = Tiles[j] as InGameMazeTile; if (item.Value[i].X == tile.GridLocation.X && item.Value[i].Y == tile.GridLocation.Y) { tilesToTransform.Add(tile); break; } } } item.Key.AddTilesToTransform(tilesToTransform); } for (int k = 0; k < Tiles.Count; k++) { InGameMazeTile tile = Tiles[k] as InGameMazeTile; tile.AddNeighbours(this); } ConnectBridgeEdgesToTheirBridgePieces(); }
private void AddTileAttributes(SerialisableTile serialisableTile, InGameMazeTile tile) { InGameMazeTileAttributePlacer tileAttributePlacer = new InGameMazeTileAttributePlacer(tile); foreach (SerialisableTileAttribute serialisableTileAttribute in serialisableTile.TileAttributes) { Type type = Type.GetType(serialisableTileAttribute.AttributeType); if (type.Equals(typeof(SerialisableTileObstacleAttribute))) { SerialisableTileObstacleAttribute serialisableTileObstacleAttribute = (SerialisableTileObstacleAttribute)JsonUtility.FromJson(serialisableTileAttribute.SerialisedData, type); tileAttributePlacer.PlaceTileObstacle(ObstacleType.Bush, new TileConnectionScoreInfo(serialisableTileObstacleAttribute.ConnectionScore, serialisableTileObstacleAttribute.SpriteNumber)); } else if (type.Equals(typeof(SerialisablePlayerExitAttribute))) { SerialisablePlayerExitAttribute serialisablePlayerExitAttribute = (SerialisablePlayerExitAttribute)JsonUtility.FromJson(serialisableTileAttribute.SerialisedData, type); tileAttributePlacer.PlacePlayerExit(ObstacleType.Bush, new TileConnectionScoreInfo(serialisablePlayerExitAttribute.ConnectionScore, serialisablePlayerExitAttribute.SpriteNumber)); } else if (type.Equals(typeof(SerialisablePlayerSpawnpointAttribute))) { tileAttributePlacer.PlacePlayerSpawnpoint(); } else if (type.Equals(typeof(SerialisablePlayerOnlyAttribute))) { tileAttributePlacer.PlacePlayerOnlyAttribute(PlayerOnlyType.Bush); } else if (type.Equals(typeof(SerialisableEnemySpawnpointAttribute))) { SerialisableEnemySpawnpointAttribute serialisableEnemySpawnpointAttribute = (SerialisableEnemySpawnpointAttribute)JsonUtility.FromJson(serialisableTileAttribute.SerialisedData, type); tileAttributePlacer.PlaceEnemySpawnpoint(serialisableEnemySpawnpointAttribute.TileAreaIds, TileAreas); } else if (type.Equals(typeof(SerialisableBridgePieceAttribute))) { SerialisableBridgePieceAttribute serialisableBridgePieceAttribute = (SerialisableBridgePieceAttribute)JsonUtility.FromJson(serialisableTileAttribute.SerialisedData, type); if (Enum.TryParse(serialisableBridgePieceAttribute.BridgePieceDirection, out BridgePieceDirection bridgePieceDirection)) { tileAttributePlacer.PlaceBridgePiece(BridgeType.Wooden, bridgePieceDirection); } else { Logger.Error($"Could not parse the BridgePieceDirection value{serialisableBridgePieceAttribute.BridgePieceDirection}"); } } else if (type.Equals(typeof(SerialisableBridgeEdgeAttribute))) { SerialisableBridgeEdgeAttribute serialisableBridgeEdgeAttribute = (SerialisableBridgeEdgeAttribute)JsonUtility.FromJson(serialisableTileAttribute.SerialisedData, type); if (Enum.TryParse(serialisableBridgeEdgeAttribute.BridgeEdgeSide, out Direction bridgeEdgeSide)) { tileAttributePlacer.PlaceBridgeEdge(BridgeType.Wooden, bridgeEdgeSide); } else { Logger.Error($"Could not parse the BridgeEdgeSide value{serialisableBridgeEdgeAttribute.BridgeEdgeSide}"); } } else if (type.Equals(typeof(SerialisableMusicInstrumentCaseAttribute))) { tileAttributePlacer.PlaceMusicInstrumentCase(); } else { Logger.Error($"Unknown tile attribute of type {type}"); } } }
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); }
public override void BuildTiles(MazeLevelData mazeLevelData) { Dictionary <SerialisableGridLocation, List <EditorMazeTile> > TileTransformationTriggererByGridLocation = new Dictionary <SerialisableGridLocation, List <EditorMazeTile> >(); for (int i = 0; i < mazeLevelData.Tiles.Count; i++) { SerialisableTile serialisableTile = mazeLevelData.Tiles[i]; GameObject tileGO = GameObject.Instantiate(MazeLevelGameplayManager.Instance.EditorTilePrefab, _mazeContainer.transform); EditorMazeTile tile = tileGO.GetComponent <EditorMazeTile>(); 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); AddTileAreas(serialisableTile, tile); TilesByLocation.Add(tile.GridLocation, tile); ITileMainMaterial mainMaterial = AddMainMaterial(serialisableTile); tile.SetMainMaterial(mainMaterial); 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; } if (serialisableTile.TilesToTransform != null) { for (int j = 0; j < serialisableTile.TilesToTransform.Count; j++) { if (TileTransformationTriggererByGridLocation.ContainsKey(serialisableTile.TilesToTransform[j])) { List <EditorMazeTile> transformationTriggerers = TileTransformationTriggererByGridLocation[serialisableTile.TilesToTransform[j]]; transformationTriggerers.Add(tile); } else { List <EditorMazeTile> transformationTriggerers = new List <EditorMazeTile>(); transformationTriggerers.Add(tile); TileTransformationTriggererByGridLocation.Add(serialisableTile.TilesToTransform[j], transformationTriggerers); } } } } foreach (KeyValuePair <SerialisableGridLocation, List <EditorMazeTile> > item in TileTransformationTriggererByGridLocation) { for (int i = 0; i < Tiles.Count; i++) { EditorMazeTile tile = Tiles[i] as EditorMazeTile; if (item.Key.X == tile.GridLocation.X && item.Key.Y == tile.GridLocation.Y) { tile.BeautificationTriggerers = item.Value; } } } for (int k = 0; k < Tiles.Count; k++) { EditorMazeTile tile = Tiles[k] as EditorMazeTile; tile.AddNeighbours(this); } ConnectBridgeEdgesToTheirBridgePieces(); }