Skip to content

Commit

Permalink
Update Readme and Version
Browse files Browse the repository at this point in the history
  • Loading branch information
Garrakx committed Dec 4, 2020
1 parent 01475e1 commit 3ef9962
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 117 deletions.
82 changes: 41 additions & 41 deletions Custom-Regions/Mod/CustomWorldMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,15 @@ public class CustomWorldMod : PartialityMod
public CustomWorldMod()
{
ModID = "Custom Regions Mod";
Version = "0.6." + version;
Version = "0.7." + version;
author = "Garrakx";
}

// Code for AutoUpdate support
// Should be put in the main PartialityMod class.

// Update URL - don't touch!
public string updateURL = "http://beestuff.pythonanywhere.com/audb/api/mods/3/0";
public int version = 36;
public int version = 37;

// Public key in base64 - don't touch!
public string keyE = "AQAB";
Expand Down Expand Up @@ -231,7 +230,8 @@ public static void BuildModRegionsDictionary()
Log($"Extending SceneID enum ... [{string.Join(", ", debug.ToArray())}]");


} catch (Exception e)
}
catch (Exception e)
{
Log("Error extending SceneID enum " + e, true);
}
Expand Down Expand Up @@ -295,7 +295,7 @@ public static void Log(string test, bool throwException)
Log(test);
if (throwException)
{
Debug.LogError("[CustomRegions] "+test);
Debug.LogError("[CustomRegions] " + test);
}
}

Expand Down Expand Up @@ -350,7 +350,7 @@ public static void AnalyzeSave()
}

List<string> savedRegions = new List<string>();
foreach(RegionInformation info in regionInfoInSaveSlot[saveSlot])
foreach (RegionInformation info in regionInfoInSaveSlot[saveSlot])
{
savedRegions.Add(info.regionID);
string savedsum = info.checksum;
Expand All @@ -372,9 +372,9 @@ public static void AnalyzeSave()
saveProblems[saveSlot].extraRegions = loadedRegions.Keys.Except(savedRegions).ToList();


if (savedRegions.Count != loadedRegions.Count ||
(saveProblems[saveSlot].missingRegions != null && saveProblems[saveSlot].missingRegions.Count != 0) ||
(saveProblems[saveSlot].extraRegions != null && saveProblems[saveSlot].extraRegions.Count != 0) )
if (savedRegions.Count != loadedRegions.Count ||
(saveProblems[saveSlot].missingRegions != null && saveProblems[saveSlot].missingRegions.Count != 0) ||
(saveProblems[saveSlot].extraRegions != null && saveProblems[saveSlot].extraRegions.Count != 0))
{
saveProblems[saveSlot].installedRegions = true;
}
Expand All @@ -399,7 +399,7 @@ public static void ReadSaveAnalyzerFiles()
string saveFileName = Custom.RootFolderDirectory() + CustomWorldMod.regionSavePath + $"CRsav_{saveSlot + 1}.txt";


if(!File.Exists(Custom.RootFolderDirectory() + "UserData"+Path.DirectorySeparatorChar+ ((saveSlot != 0) ? ("sav_" + (saveSlot + 1)) : "sav") + ".txt"))
if (!File.Exists(Custom.RootFolderDirectory() + "UserData" + Path.DirectorySeparatorChar + ((saveSlot != 0) ? ("sav_" + (saveSlot + 1)) : "sav") + ".txt"))
{
File.Delete(saveFileName);
Log($"Deleting {saveFileName} since vanilla save is empty");
Expand Down Expand Up @@ -471,7 +471,7 @@ public static void ReadSaveAnalyzerFiles()
}
else
{
Log($"SaveSlot [{saveSlot+1}] does not have CR information");
Log($"SaveSlot [{saveSlot + 1}] does not have CR information");
}
}
}
Expand Down Expand Up @@ -508,7 +508,6 @@ public static string[] AddModdedRegions(string[] regionNames)
}



/// <summary>
/// Returns a List from WorldData
/// </summary>
Expand Down Expand Up @@ -627,9 +626,7 @@ public static void LoadAvailableRegions()

}



RegionInformation regionInformation = new RegionInformation(string.Empty, string.Empty, "No description",
RegionInformation regionInformation = new RegionInformation(string.Empty, string.Empty, "No description",
true, loadOrder, string.Empty, -1, new DirectoryInfo(dir).Name, string.Empty, new Dictionary<string, float>(), new Dictionary<string, RegionConfiguration>());


Expand All @@ -638,7 +635,7 @@ public static void LoadAvailableRegions()
{
dictionary = File.ReadAllText(pathOfRegionInfo).dictionaryFromJson();
}
catch (Exception e)
catch (Exception e)
{
Log($"CORRUPTED JSON FILE -- DELETING [{pathOfRegionInfo}] - [{e}]", true);
File.Delete(dir + Path.DirectorySeparatorChar + "regionInfo.json");
Expand All @@ -652,7 +649,7 @@ public static void LoadAvailableRegions()
FromDictionaryToRegionInfo(dictionary, ref regionInformation);

Log($"Description for ({regionInformation.regionName}) is: [{regionInformation.description}]");
// string oldDescription = regionInformation.description;
// string oldDescription = regionInformation.description;
if (regionInformation.description.Equals("N / A") || regionInformation.description.Equals(string.Empty))
{
regionInformation.description = "No description";
Expand Down Expand Up @@ -700,7 +697,7 @@ public static void LoadAvailableRegions()
Log($"New checksum for {regionInformation.regionName} [{newChecksum}]");
regionInformation.checksum = newChecksum;
}
if(!newDescr.Equals(string.Empty) && !newDescr.Equals(regionInformation.description))
if (!newDescr.Equals(string.Empty) && !newDescr.Equals(regionInformation.description))
{
Log($"New description for {regionInformation.regionName} [{newDescr}]");
regionInformation.description = newDescr;
Expand All @@ -712,7 +709,7 @@ public static void LoadAvailableRegions()
}

// Write new info
if ((!newDescr.Equals(string.Empty)&&regionInformation.description.Equals("No description")) || !newChecksum.Equals(string.Empty) || !newUrl.Equals(string.Empty))
if ((!newDescr.Equals(string.Empty) && regionInformation.description.Equals("No description")) || !newChecksum.Equals(string.Empty) || !newUrl.Equals(string.Empty))
{
Log($"Updating regionInfo for {regionInformation.regionName}");
File.Delete(dir + Path.DirectorySeparatorChar + "regionInfo.json");
Expand Down Expand Up @@ -749,7 +746,7 @@ public static void LoadAvailableRegions()
}

Log("-------");
}
}

foreach (KeyValuePair<string, RegionInformation> element in notSortedDictionary.OrderBy(d => d.Value.loadOrder))
{
Expand All @@ -776,6 +773,7 @@ private static void FromDictionaryToRegionInfo(Dictionary<string, object> dictio
regionInformation.regionName = (string)GetValueDictionary("regionName", dictionary);
}

// WHAT THE FRICC IS THIS
if (dictionary.ContainsKey("activated"))
{
regionInformation.activated = dictionary["activated"].ToString().ToLower().Contains("true");
Expand All @@ -790,6 +788,7 @@ private static void FromDictionaryToRegionInfo(Dictionary<string, object> dictio
{
regionInformation.checksum = (string)GetValueDictionary("checksum", dictionary);
}

if (GetValueDictionary("url", dictionary) != null)
{
regionInformation.url = (string)GetValueDictionary("url", dictionary);
Expand All @@ -816,6 +815,7 @@ public static void FromDictionaryToRegionConfig(Dictionary<string, object> dicti
}
catch (Exception) { regionConfiguration.kelpColor = null; }
}

if (GetValueDictionary("brother_color", dictionary) != null)
{
try
Expand Down Expand Up @@ -879,6 +879,7 @@ public static void LoadCustomPearls(string dir, string regionID)
pearlColor = OptionalUI.OpColorPicker.HexToColor(lineDivided[2]);
}
catch (Exception) { Log($"Pearl missing color from {regionID}", true); }

try
{
secondaryColor = OptionalUI.OpColorPicker.HexToColor(lineDivided[3]);
Expand Down Expand Up @@ -923,13 +924,12 @@ public static void LoadCustomPearls(string dir, string regionID)
}
}

// Only will apply to new regions added
public static void LoadVariations(string dir, RegionInformation regionInfo)
{
string pathToRegionsDir = dir + Path.DirectorySeparatorChar + "World" + Path.DirectorySeparatorChar + "Regions" + Path.DirectorySeparatorChar;
foreach (string regionDir in Directory.GetDirectories(pathToRegionsDir))
{
string pathConfig = regionDir +Path.DirectorySeparatorChar+ "CustomConfig.json";
string pathConfig = regionDir + Path.DirectorySeparatorChar + "CustomConfig.json";
// Load configuration
if (File.Exists(pathConfig))
{
Expand All @@ -943,8 +943,8 @@ public static void LoadVariations(string dir, RegionInformation regionInfo)
}
catch (Exception e)
{
Log($"CORRUPTED JSON FILE -- DELETING [{pathConfig}] - [{e}]", true);
File.Delete(pathConfig);
Log($"CORRUPTED JSON FILE [{pathConfig}] - [{e}]", true);
//File.Delete(pathConfig);
return;
}

Expand All @@ -958,9 +958,9 @@ public static void LoadVariations(string dir, RegionInformation regionInfo)
regionConfiguration.regionID = new DirectoryInfo(regionDir).Name;

// Load region information
CustomWorldMod.Log($"Adding configuration for region [{regionConfiguration.regionID}] from [{regionInfo.regionName}] - " +
$"AlbinoLev [{regionConfiguration.albinoLevi}] AlbinoJet [{regionConfiguration.albinoJet}] " +
$"KelpColor [{!regionConfiguration.kelpVanilla}] BLLColor [{!regionConfiguration.bllVanilla}]");
CustomWorldMod.Log($"Adding configuration for region [{regionConfiguration.regionID}] from [{regionInfo.regionName}] - " +
$"AlbinoLev [{regionConfiguration.albinoLevi}] AlbinoJet [{regionConfiguration.albinoJet}] " +
$"KelpColor [{!regionConfiguration.kelpVanilla}] BLLColor [{!regionConfiguration.bllVanilla}]");

if (regionInfo.regionID != string.Empty)
{
Expand Down Expand Up @@ -1046,24 +1046,24 @@ public static string SerializeRegionInfo(RegionInformation regionInfo)
return infoSerial;
}



public static void WriteRegionInfoJSONFile(string dirPath, string regionID, string description, string regionName, bool activated, int loadOrder, string url, string checksum)
{
// Create a file to write to.
using (StreamWriter sw = File.CreateText(dirPath + Path.DirectorySeparatorChar + "regionInfo.json"))
{
sw.WriteLine("{\n"
+ " \"regionID\": \"" + regionID + "\", \n"
+ " \"description\": \"" + description + "\", \n"
sw.WriteLine("{\n"
+ " \"regionID\": \"" + regionID + "\", \n"
+ " \"description\": \"" + description + "\", \n"

+ " \"regionName\": \"" + regionName + "\", \n"
+ " \"activated\": " + activated.ToString().ToLower() + ", \n"
+ " \"loadOrder\": " + loadOrder + ", \n"
+ " \"regionName\": \"" + regionName + "\", \n"
+ " \"activated\": " + activated.ToString().ToLower() + ", \n"
+ " \"loadOrder\": " + loadOrder + ", \n"

+ " \"url\": \"" + url + "\", \n"
+ " \"checksum\": \"" + checksum + "\" \n"
+ "}");
+ " \"url\": \"" + url + "\", \n"
+ " \"checksum\": \"" + checksum + "\" \n"
+ "}");
/*
sw.WriteLine(new Dictionary<string, object>() {
{ "regionID", regionID },
Expand All @@ -1078,7 +1078,7 @@ public static void WriteRegionInfoJSONFile(string dirPath, string regionID, stri
}
}

public static void WriteRegionConfigJSONFile(string dirPath, bool leviAlbino, bool jetfishAlbino,
public static void WriteRegionConfigJSONFile(string dirPath, bool leviAlbino, bool jetfishAlbino,
string shortcutColor, string kelpColor, string bllColor)
{
using (StreamWriter sw = File.CreateText(dirPath + Path.DirectorySeparatorChar + "regionConfiguration.json"))
Expand All @@ -1098,7 +1098,7 @@ public static void WriteRegionInfoJSONFile(string dirPath, string regionID, stri

internal static void DownloadThumbs()
{

Dictionary<string, string> thumbInfo = new Dictionary<string, string>();
foreach (KeyValuePair<string, RegionInformation> entry in CustomWorldMod.availableRegions)
{
Expand All @@ -1109,13 +1109,13 @@ internal static void DownloadThumbs()
}
}

if (ThumbnailDownloader.instance == null)
if (ThumbnailDownloader.instance == null)
{
ThumbnailDownloader.Create(thumbInfo);
}

//thumbnailDownloader = new ThumbnailDownloader(thumbInfo);


/*
string filePath = Custom.RootFolderDirectory() + CustomWorldMod.resourcePath +
Expand Down
Loading

0 comments on commit 3ef9962

Please sign in to comment.