Skip to content

Commit

Permalink
Add electric gate support
Browse files Browse the repository at this point in the history
  • Loading branch information
Garrakx committed Nov 2, 2020
1 parent 85d890d commit 79213cc
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 12 deletions.
1 change: 1 addition & 0 deletions Custom-Regions/Custom-Regions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<Compile Include="RegionGateHook.cs" />
<Compile Include="RegionHook.cs" />
<Compile Include="RoomCameraHook.cs" />
<Compile Include="RoomHook.cs" />
<Compile Include="RoomSettingsHook.cs" />
<Compile Include="CustomMenu\SlugcatSelectMenuHook.cs" />
<Compile Include="SaveStateHook.cs" />
Expand Down
2 changes: 1 addition & 1 deletion Custom-Regions/CustomMenu/MenuIllustrationHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private static void MenuIllustration_LoadFile_1(On.Menu.MenuIllustration.orig_Lo
}
catch (Exception e)
{
CustomWorldMod.CustomWorldLog($"Custom Regions: Failed loading textures for {folder} - {self.fileName}");
CustomWorldMod.CustomWorldLog($"Custom Regions: Failed loading textures for {folder} - {self.fileName} "+e);
}

}
Expand Down
32 changes: 26 additions & 6 deletions Custom-Regions/Mod/CustomWorldMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class CustomWorldMod : PartialityMod
public CustomWorldMod()
{
ModID = "Custom Regions Mod";
Version = "0.4." + version;
Version = "0.5." + version;
author = "Garrakx";
}

Expand All @@ -53,7 +53,7 @@ public CustomWorldMod()

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

// Public key in base64 - don't touch!
public string keyE = "AQAB";
Expand Down Expand Up @@ -174,8 +174,9 @@ public struct RegionInformation
public string checksum;
public int loadOrder;
public string folderName;
public Dictionary<string, float> electricGates;

public RegionInformation(string regionID, string regionName, string description, bool activated, int loadOrder, string checksum, int regionNumber, string folderName)
public RegionInformation(string regionID, string regionName, string description, bool activated, int loadOrder, string checksum, int regionNumber, string folderName, Dictionary<string, float> electricGates)
{
this.regionID = regionID;
this.regionName = regionName;
Expand All @@ -185,6 +186,7 @@ public RegionInformation(string regionID, string regionName, string description,
this.loadOrder = loadOrder;
this.regionNumber = regionNumber;
this.folderName = folderName;
this.electricGates = electricGates;
}
}

Expand Down Expand Up @@ -1108,7 +1110,7 @@ public static void ReadSaveAnalyzer()
string checkSum = Regex.Split(minedLines.Find(x => x.Contains("SUM")), "<SUM>")[1];
int regionNumber = int.Parse(Regex.Split(minedLines.Find(x => x.Contains("ORDER")), "<ORDER>")[1]);

regionInfoInSaveSlot[saveSlot].Add(new RegionInformation(regionID, null, null, true, -20, checkSum, regionNumber, null));
regionInfoInSaveSlot[saveSlot].Add(new RegionInformation(regionID, null, null, true, -20, checkSum, regionNumber, null, null));

}
}
Expand Down Expand Up @@ -1326,9 +1328,11 @@ public static void LoadAvailableRegions()
}


Dictionary<string, object> dictionary = File.ReadAllText(pathOfRegionInfo).dictionaryFromJson();
RegionInformation regionInformation = new RegionInformation(string.Empty, string.Empty, "No description", true, loadOrder, string.Empty, -1, Path.GetFileNameWithoutExtension(dir));
RegionInformation regionInformation = new RegionInformation(string.Empty, string.Empty, "No description", true, loadOrder, string.Empty, -1, Path.GetFileNameWithoutExtension(dir), new Dictionary<string, float>());



Dictionary<string, object> dictionary = File.ReadAllText(pathOfRegionInfo).dictionaryFromJson();
if (dictionary != null)
{
if (GetRegionInfoJson("regionID", dictionary) != null)
Expand Down Expand Up @@ -1428,6 +1432,22 @@ public static void LoadAvailableRegions()
}


// Add electric gates
string pathToElectricGates = dir + Path.DirectorySeparatorChar + "World" + Path.DirectorySeparatorChar + "Gates" + Path.DirectorySeparatorChar + "electricGates.txt";
CustomWorldLog($"Loading electric gates for {regionInformation.regionID}");
if (File.Exists(pathToElectricGates))
{
string[] electricGates = File.ReadAllLines(pathToElectricGates);
for (int i = 0; i < electricGates.Length; i++)
{
string gateName = Regex.Split(electricGates[i], " : ")[0];
float meterHeigh = float.Parse(Regex.Split(electricGates[i], " : ")[1]);

CustomWorldLog($"Added new gate [{gateName}]. Meter height [{meterHeigh}]");
regionInformation.electricGates.Add(gateName, meterHeigh);
}
}

/*
CustomWorldMod.CustomWorldLog($"Custom Regions: Adding available region [{regionID}]");
try
Expand Down
9 changes: 8 additions & 1 deletion Custom-Regions/Mod/CustomWorldOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ public void MainTab(int tab)
return;
}

OpLabel errorLabel = new OpLabelLong(new Vector2(50, 490), new Vector2(600, 20), "", true, FLabelAlignment.Center)
{
text = "Green means activated, red means deactivated"
};

Tabs[tab].AddItems(errorLabel);

/*int cumulativeScrollSize = 0;
string labelCheck = "";
string labelDescri = "";*/
Expand Down Expand Up @@ -187,7 +194,7 @@ private void AnalyseSaveTab(int tab)
OpLabel labelDsc = new OpLabel(new Vector2(100f, 540), new Vector2(400f, 20f), $"Check problems in savelot {saveSlot+1}", FLabelAlignment.Center, false);
Tabs[tab].AddItems(labelDsc);

OpLabel errorLabel = new OpLabelLong(new Vector2(100, 490), new Vector2(600, 20), "", true, FLabelAlignment.Center)
OpLabel errorLabel = new OpLabelLong(new Vector2(50, 490), new Vector2(600, 20), "", true, FLabelAlignment.Center)
{
text = "No problems found in your save :D"
};
Expand Down
3 changes: 3 additions & 0 deletions Custom-Regions/Mod/CustomWorldScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public void Initialize()
// Custom Palette
RoomCameraHook.ApplyHook();

// Electric gate
RoomHook.ApplyHooks();

// Custom Decal
CustomDecalHook.ApplyHook();

Expand Down
2 changes: 2 additions & 0 deletions Custom-Regions/MusicPieceHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ private static void SubTrack_Update(On.Music.MusicPiece.SubTrack.orig_Update ori
+ "Assets" + Path.DirectorySeparatorChar + "Futile" + Path.DirectorySeparatorChar
+ "Resources" + Path.DirectorySeparatorChar + "Music" + Path.DirectorySeparatorChar + "Songs" + Path.DirectorySeparatorChar
+ self.trackName + ".ogg";

CustomWorldMod.CustomWorldLog($"Subtrack-path [{text}]");
if (File.Exists(text))
{
Expand All @@ -91,6 +92,7 @@ private static void SubTrack_Update(On.Music.MusicPiece.SubTrack.orig_Update ori
+ "Assets" + Path.DirectorySeparatorChar + "Futile" + Path.DirectorySeparatorChar
+ "Resources" + Path.DirectorySeparatorChar + "Music" + Path.DirectorySeparatorChar + "Procedural" + Path.DirectorySeparatorChar
+ self.trackName + ".ogg";

CustomWorldMod.CustomWorldLog($"Subtrack-path [{text2}]");
if (File.Exists(text2))
{
Expand Down
4 changes: 3 additions & 1 deletion Custom-Regions/OverWorldHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public static class OverWorldHook
public static void ApplyHooks()
{
On.OverWorld.LoadFirstWorld += OverWorld_LoadFirstWorld;
On.OverWorld.GetRegion += OverWorld_GetRegion;

//On.OverWorld.GetRegion += OverWorld_GetRegion;

On.OverWorld.GetRegion_1 += OverWorld_GetRegion_1;
On.OverWorld.LoadWorld += OverWorld_LoadWorld;
}
Expand Down
10 changes: 7 additions & 3 deletions Custom-Regions/PlayerProgressionHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace CustomRegions
{
public static class PlayerProgressionHook
{
private static Dictionary<string, int> tempDictionary = null;
//private static Dictionary<string, int> tempDictionary = null;

public static void ApplyHooks()
{
Expand Down Expand Up @@ -77,6 +77,7 @@ private static void PlayerProgression_SaveToDisk(On.PlayerProgression.orig_SaveT
}

// Debug
/*
private static string[] PlayerProgression_GetProgLines(On.PlayerProgression.orig_GetProgLines orig, PlayerProgression self)
{
tempDictionary = null;
Expand Down Expand Up @@ -130,7 +131,7 @@ private static string[] PlayerProgression_GetProgLines(On.PlayerProgression.orig
}
return progLines;
}

*/


private static void PlayerProgression_InitiateProgression(On.PlayerProgression.orig_InitiateProgression orig, PlayerProgression self)
Expand Down Expand Up @@ -159,12 +160,15 @@ private static void PlayerProgression_LoadProgression(On.PlayerProgression.orig_

private static void MiscProgressionData_FromString(On.PlayerProgression.MiscProgressionData.orig_FromString orig, PlayerProgression.MiscProgressionData self, string s)
{
/*
string debug2 = "Custom Regions: MISC PROGRESION FROM STRING - RegionNames { ";
for (int i = 0; i < self.owner.regionNames.Length; i++)
{
debug2 += self.owner.regionNames[i] + " , ";
}
CustomWorldMod.CustomWorldLog(debug2);
*/
CustomWorldMod.CustomWorldLog($"Custom Regions: MISC PROGRESION FROM STRING - RegionNames[{string.Join(", ", self.owner.regionNames)}]");

Dictionary<string, int> dictionaryTemp = new Dictionary<string, int>(7);
string[] array = Regex.Split(s, "<mpdA>");
Expand Down Expand Up @@ -242,7 +246,7 @@ private static void MiscProgressionData_FromString(On.PlayerProgression.MiscProg
CustomWorldMod.CustomWorldLog(debug);
orig(self, s);

debug2 = "Custom Regions: Discovered Shelters { ";
string debug2 = "Custom Regions: Discovered Shelters { ";
for (int i = 0; i < self.discoveredShelters.Length; i++)
{
if (self.discoveredShelters[i] != null)
Expand Down
59 changes: 59 additions & 0 deletions Custom-Regions/RoomHook.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using System.Text;
using CustomRegions.Mod;

namespace CustomRegions
{
static class RoomHook
{
public static void ApplyHooks()
{
On.Room.Loaded += Room_Loaded;
On.Room.AddObject += Room_AddObject;
}

private static void Room_AddObject(On.Room.orig_AddObject orig, Room self, UpdatableAndDeletable obj)
{
if (self.game == null)
{
return;
}

if (obj is WaterGate)
{
// Add electric gate
if (self.abstractRoom.gate)
{
foreach (KeyValuePair<string, CustomWorldMod.RegionInformation> entries in CustomWorldMod.availableRegions)
{
if (!entries.Value.activated || entries.Value.electricGates == null || entries.Value.electricGates.Count == 0)
{
continue;
}

if (entries.Value.electricGates.ContainsKey(self.abstractRoom.name))
{
CustomWorldMod.CustomWorldLog($"Added electric gate [{self.abstractRoom.name}] from [{entries.Key}]");
self.regionGate = new ElectricGate(self);
(self.regionGate as ElectricGate).meterHeight = entries.Value.electricGates[self.abstractRoom.name];
obj = self.regionGate;
break;
}
}
}
}

orig(self, obj);
}

private static void Room_Loaded(On.Room.orig_Loaded orig, Room self)
{
orig(self);


}
}
}

0 comments on commit 79213cc

Please sign in to comment.