Skip to content

Commit

Permalink
Merge pull request #24 from MrWoafer/add-pac-extension-to-config
Browse files Browse the repository at this point in the history
Added pac file extension to config
  • Loading branch information
MrWoafer authored Oct 24, 2024
2 parents a4661a7 + 8ccdb1d commit 261c1e8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
5 changes: 5 additions & 0 deletions Assets/Scripts/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ namespace PAC
{
public static class Config
{
public static class Files
{
public const string pacFileExtension = "pac";
}

public static class Tools
{
public const int minBrushSize = 1;
Expand Down
6 changes: 3 additions & 3 deletions Assets/Scripts/Files/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public static File OpenFile(string filePath)
{
return OpenJPEG(filePath);
}
else if (Path.GetExtension(filePath) == ".pac")
else if (Path.GetExtension(filePath) == "." + Config.Files.pacFileExtension)
{
return OpenPAC(filePath);
}
Expand Down Expand Up @@ -241,7 +241,7 @@ public static File OpenPAC(string filePath)
{
throw new System.Exception("filePath doesn't exist: " + filePath);
}
if (Path.GetExtension(filePath) != ".pac")
if (Path.GetExtension(filePath) != "." + Config.Files.pacFileExtension)
{
throw new System.Exception("The file is not a PAC file. File extension: " + Path.GetExtension(filePath));
}
Expand Down Expand Up @@ -303,7 +303,7 @@ public void SaveAsPAC(string filePath)
{
throw new System.Exception("filePath not fully qualified: " + filePath);
}
if (Path.GetExtension(filePath) != ".pac")
if (Path.GetExtension(filePath) != "." + Config.Files.pacFileExtension)
{
throw new System.Exception("The file is not a PAC file. File extension: " + Path.GetExtension(filePath));
}
Expand Down
20 changes: 13 additions & 7 deletions Assets/Scripts/Files/FileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,11 @@ public void NewFile(int width, int height)

public void OpenFileDialog()
{
ExtensionFilter[] extensions = new ExtensionFilter[] { new ExtensionFilter("Any File ", "png", "jpeg", "jpg", "pac"), new ExtensionFilter("Image File ", "png", "jpeg", "jpg"),
new ExtensionFilter("Pixel Art Creator File ", "pac") };
ExtensionFilter[] extensions = new ExtensionFilter[] {
new ExtensionFilter("Any File ", "png", "jpeg", "jpg",
Config.Files.pacFileExtension), new ExtensionFilter("Image File ", "png", "jpeg", "jpg"),
new ExtensionFilter("Pixel Art Creator File ", Config.Files.pacFileExtension)
};
string[] fileNames = StandaloneFileBrowser.OpenFilePanel("Open File", "", extensions, false);
if (fileNames.Length > 0)
{
Expand Down Expand Up @@ -218,8 +221,11 @@ public bool OpenFile(string filePath)

public void ImportDialog()
{
ExtensionFilter[] extensions = new ExtensionFilter[] { new ExtensionFilter("Any File ", "png", "jpeg", "jpg", "pac"), new ExtensionFilter("Image File ", "png", "jpeg", "jpg"),
new ExtensionFilter("Pixel Art Creator File ", "pac") };
ExtensionFilter[] extensions = new ExtensionFilter[] {
new ExtensionFilter("Any File ", "png", "jpeg", "jpg",
Config.Files.pacFileExtension), new ExtensionFilter("Image File ", "png", "jpeg", "jpg"),
new ExtensionFilter("Pixel Art Creator File ", Config.Files.pacFileExtension)
};
string[] fileNames = StandaloneFileBrowser.OpenFilePanel("Import", "", extensions, false);
if (fileNames.Length > 0)
{
Expand All @@ -235,7 +241,7 @@ public void ImportDialog()
currentFile.ImportImage(fileNames[0]);
}
}
else if (Path.GetExtension(fileNames[0]) == ".pac")
else if (Path.GetExtension(fileNames[0]) == "." + Config.Files.pacFileExtension)
{
File file = File.OpenPAC(fileNames[0]);
if (file.width != currentFile.width || file.height != currentFile.height)
Expand Down Expand Up @@ -309,7 +315,7 @@ public void SaveFileDialog(File file)
{
if (file.mostRecentSavePath == null)
{
ExtensionFilter[] extensions = new ExtensionFilter[] { new ExtensionFilter("Pixel Art Creator File ", "pac") };
ExtensionFilter[] extensions = new ExtensionFilter[] { new ExtensionFilter("Pixel Art Creator File ", Config.Files.pacFileExtension) };
string fileName = StandaloneFileBrowser.SaveFilePanel("Save", "", file.name, extensions);
if (fileName != "")
{
Expand All @@ -331,7 +337,7 @@ public void SaveAsCurrentFileDialog()
}
public void SaveAsFileDialog(File file)
{
ExtensionFilter[] extensions = new ExtensionFilter[] { new ExtensionFilter("Pixel Art Creator File ", "pac") };
ExtensionFilter[] extensions = new ExtensionFilter[] { new ExtensionFilter("Pixel Art Creator File ", Config.Files.pacFileExtension) };
string fileName = StandaloneFileBrowser.SaveFilePanel("Save As", "", file.name, extensions);
if (fileName != "")
{
Expand Down

0 comments on commit 261c1e8

Please sign in to comment.