Ejemplo n.º 1
0
 public override bool Finalize()
 {
     if (ID == -1)
     {
         return(Error("Please specify a map ID using the '--id' parameter."));
     }
     Game.Map Map = Game.Data.Maps[ID];
     Console.WriteLine($"Map #{Utilities.Digits(Map.ID, 3)}");
     Console.WriteLine($"Development Name: {Map.DevName}");
     Console.WriteLine($"Display Name: {Map.DisplayName}");
     Console.WriteLine($"Size: {Map.Width}x{Map.Height}");
     Console.Write("Tilesets: ");
     for (int i = 0; i < Map.TilesetIDs.Count; i++)
     {
         Console.Write(Map.TilesetIDs[i]);
         if (i != Map.TilesetIDs.Count - 1)
         {
             Console.Write(", ");
         }
     }
     Console.WriteLine();
     Console.Write("Autotiles: ");
     for (int i = 0; i < Map.AutotileIDs.Count; i++)
     {
         Console.Write(Map.AutotileIDs[i]);
         if (i != Map.AutotileIDs.Count - 1)
         {
             Console.Write(", ");
         }
     }
     Console.WriteLine();
     return(true);
 }
Ejemplo n.º 2
0
 public override bool Finalize()
 {
     if (IDs != null)
     {
         OldIDs = new List <int>(IDs);
         if (!Confirm && (RemoveID != -1 || SetList != null))
         {
             return(Error("You are about to alter the list of autotiles of this map. " +
                          "If the map is using tiles from autotiles that are to be deleted, these tiles will be deleted too. " +
                          "Repeat the command with '--confirm' appended to confirm your choice."));
         }
         if (AddID != -1 && IDs.Contains(AddID))
         {
             return(Error($"The autotile you tried to add, #{AddID}, is already present in the autotile list."));
         }
         if (RemoveID != -1 && !IDs.Contains(RemoveID))
         {
             return(Error($"The autotile you tried to remove, #{RemoveID} is not present in the autotile list."));
         }
         if (ReplaceID1 != -1 && !IDs.Contains(ReplaceID1))
         {
             return(Error($"The autotile you tried to replace, #{ReplaceID1} is not present in the autotile list."));
         }
         if (ReplaceID2 != -1 && IDs.Contains(ReplaceID2))
         {
             return(Error($"The autotile you tried to replace with, #{ReplaceID2}, is already present in the autotile list."));
         }
         if (AddID != -1 && RemoveID != -1 || AddID != -1 && ReplaceID1 != -1 || RemoveID != -1 && ReplaceID1 != -1 ||
             AddID != -1 && SetList != null || RemoveID != -1 && SetList != null || ReplaceID1 != -1 && SetList != null ||
             AddID != -1 && Clear || RemoveID != -1 && Clear || ReplaceID1 != -1 && Clear || SetList != null && Clear)
         {
             return(Error("Only one add/remove/replace/set/clear operation is allowed at a time on the autotile list."));
         }
         if (AddID != -1)
         {
             IDs.Add(AddID);
         }
         else if (RemoveID != -1)
         {
             IDs.Remove(RemoveID);
         }
         else if (ReplaceID1 != -1)
         {
             int Index = IDs.IndexOf(ReplaceID1);
             IDs.RemoveAt(Index);
             IDs.Insert(Index, ReplaceID2);
         }
         else if (SetList != null)
         {
             IDs = new List <int>(SetList);
         }
         else if (Clear)
         {
             IDs.Clear();
         }
         Game.Map Map = Game.Data.Maps[MapID];
         for (int layer = 0; layer < Map.Layers.Count; layer++)
         {
             for (int i = 0; i < Map.Layers[layer].Tiles.Count; i++)
             {
                 Game.TileData data = Map.Layers[layer].Tiles[i];
                 if (data == null)
                 {
                     continue;
                 }
                 if (data.TileType == Game.TileType.Tileset)
                 {
                     continue;
                 }
                 int AutotileIndex = data.Index;
                 int AutotileID    = OldIDs[AutotileIndex];
                 if (IDs.Contains(AutotileID))
                 {
                     data.Index = IDs.IndexOf(AutotileID);
                 }
                 else
                 {
                     Map.Layers[layer].Tiles[i] = null;
                 }
             }
         }
         Map.AutotileIDs = IDs;
     }
     return(true);
 }
Ejemplo n.º 3
0
 public override bool Finalize()
 {
     if (Create)
     {
         if (!Success && cli == null)
         {
             return(false);
         }
         if (Width == -1 || Height == -1)
         {
             return(Error("You must specify the map's size using the '--size' parameter."));
         }
         if (DevName == null)
         {
             return(Error("You must specify the map's development name using the '--dev-name' or '--name' parameter."));
         }
         if (DisplayName == null)
         {
             return(Error("You must specify the map's display name using the '--display-name' or '--name' parameter."));
         }
         if (cli != null && !cli.Success)
         {
             return(false);
         }
         Game.Map Map = new Game.Map();
         Map.ID          = Editor.GetFreeMapID();
         Map.DevName     = DevName;
         Map.DisplayName = DisplayName;
         Map.SetSize(Width, Height);
         Game.Data.Maps[Map.ID] = Map;
         if (ParentID != -1)
         {
             Editor.AddIDToMap(Editor.ProjectSettings.MapOrder, ParentID, Map.ID);
         }
         else
         {
             Editor.ProjectSettings.MapOrder.Add(Map.ID);
         }
         if (cli == null)
         {
             Map.TilesetIDs = new List <int>()
             {
                 1
             };
             Map.AutotileIDs = new List <int>();
         }
         else
         {
             if (cli is TilesetsCommandLineHandler)
             {
                 ((TilesetsCommandLineHandler)cli).IDs = new List <int>();
             }
             else
             {
                 ((AutotilesCommandLineHandler)cli).IDs = new List <int>();
             }
             if (cli is TilesetsCommandLineHandler)
             {
                 ((TilesetsCommandLineHandler)cli).MapID = Map.ID;
             }
             else
             {
                 ((AutotilesCommandLineHandler)cli).MapID = Map.ID;
             }
             cli.Finalize();
         }
         Console.WriteLine($"Created a new map with id #{Map.ID}.");
     }
     else
     {
         if (cli != null)
         {
             if (!cli.Success)
             {
                 return(false);
             }
             int CliMapID = -1;
             if (cli is TilesetsCommandLineHandler)
             {
                 CliMapID = ((TilesetsCommandLineHandler)cli).MapID;
             }
             else
             {
                 CliMapID = ((AutotilesCommandLineHandler)cli).MapID;
             }
             if (CliMapID == -1 && MapID == -1)
             {
                 return(Error("You must specify a map ID using the '--id' parameter."));
             }
             else if (CliMapID != -1)
             {
                 MapID = CliMapID;
             }
         }
         else if (!Success && MapID == -1)
         {
             return(false);
         }
         if (MapID == -1)
         {
             return(Error("You must specify a map ID using the '--id' parameter."));
         }
         Game.Map Map = Game.Data.Maps[MapID];
         if (cli != null)
         {
             if (cli is TilesetsCommandLineHandler)
             {
                 ((TilesetsCommandLineHandler)cli).IDs = Map.TilesetIDs;
             }
             else
             {
                 ((AutotilesCommandLineHandler)cli).IDs = Map.AutotileIDs;
             }
             if (cli is TilesetsCommandLineHandler)
             {
                 ((TilesetsCommandLineHandler)cli).MapID = Map.ID;
             }
             else
             {
                 ((AutotilesCommandLineHandler)cli).MapID = Map.ID;
             }
             if (!cli.Finalize())
             {
                 if (cli is TilesetsCommandLineHandler)
                 {
                     Map.TilesetIDs = ((TilesetsCommandLineHandler)cli).OldIDs;
                 }
                 else
                 {
                     Map.AutotileIDs = ((AutotilesCommandLineHandler)cli).OldIDs;
                 }
                 return(false);
             }
         }
         if (ParentID != -1 && MapID != -1 && ParentID == MapID)
         {
             return(Error($"Cannot make map #{MapID} a child of itself."));
         }
         if (ParentID > 0)
         {
             if (Editor.MapIsChildMap(Editor.ProjectSettings.MapOrder, Map.ID, ParentID))
             {
                 return(Error($"Map #{ParentID} is a child map of map #{Map.ID}, so map #{Map.ID} can't also be a child of map #{ParentID}."));
             }
             else
             {
                 object o = Editor.RemoveIDFromOrder(null, Editor.ProjectSettings.MapOrder, Map.ID);
                 Editor.AddIDToMap(Editor.ProjectSettings.MapOrder, ParentID, o);
             }
         }
         else if (ParentID == 0)
         {
             object o = Editor.RemoveIDFromOrder(null, Editor.ProjectSettings.MapOrder, Map.ID);
             Editor.ProjectSettings.MapOrder.Add(o);
         }
         if (!string.IsNullOrEmpty(DevName))
         {
             Map.DevName = DevName;
         }
         if (!string.IsNullOrEmpty(DisplayName))
         {
             Map.DisplayName = DisplayName;
         }
         if (Width != -1 && Height != -1)
         {
             Map.Resize(Map.Width, Width, Map.Height, Height);
         }
         Console.WriteLine($"Map #{Map.ID} has been edited successfully.");
     }
     return(true);
 }