Skip to content

Commit

Permalink
V2.5.1
Browse files Browse the repository at this point in the history
-Added debug options, currently these allow to toggle spammy/expensive debug logs and allow to define a key that manually triggers events
- Cleaned up some code
-Readded some logging and made put it behind the debug logs toggle
  • Loading branch information
Gamer025 committed Feb 5, 2024
1 parent 4f8a42d commit ce8892e
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 94 deletions.
23 changes: 20 additions & 3 deletions Config/RainWorldCEOI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ public RainWorldCEOI()
RainWorldCE.eventTimeout = config.Bind("eventTimeout", 60, new ConfigAcceptableRange<int>(10, 600));
RainWorldCE.eventTimeoutOffset = config.Bind("eventTimeoutOffset", 15, new ConfigAcceptableRange<int>(0, 600));
RainWorldCE.blockedEventPercent = config.Bind("blockedEventPercent", 50, new ConfigAcceptableRange<int>(0, 100));
RainWorldCE._maxEventCount = config.Bind("maxEventCount", 200, new ConfigAcceptableRange<int>(1, 200));
RainWorldCE.maxEventCount = config.Bind("maxEventCount", 200, new ConfigAcceptableRange<int>(1, 200));
RainWorldCE._eventDurationMult = config.Bind("eventDurationMult", 10, new ConfigAcceptableRange<int>(1, 50));
CEHUD.eventDisplayTime = config.Bind("eventDisplayTime", 5, new ConfigAcceptableRange<int>(0, 15));
RainWorldCE._showActiveEvents = config.Bind("showActiveEvents", true, new ConfigurableInfo("Show active events in the bottom left?", null, "Show active events"));
RainWorldCE.triggerEventKey = config.Bind("triggerEeventKey", KeyCode.None);
RainWorldCE.debugLogs = config.Bind("debugLogs2", false, new ConfigurableInfo("Enable extra debug logs", null, "May decrease performance"));

// Enable/Disable event checkboxes
List<Type> allEventTypes = RainWorldCE.GetAllCEEventTypes().OrderBy(x => x.Name).ToList();
Expand Down Expand Up @@ -69,10 +71,11 @@ public override void Initialize()
RainWorldCE.TryLoadCC();
RainWorldCE.ME.Logger_p.Log(LogLevel.Info, "Remix OI init");

Tabs = new OpTab[3]; // Each OpTab is 600 x 600 pixel sized canvas
Tabs = new OpTab[4]; // Each OpTab is 600 x 600 pixel sized canvas
Tabs[0] = new OpTab(this, "Main");
Tabs[1] = new OpTab(this, "Events");
Tabs[2] = new OpTab(this, "Event Config");
Tabs[3] = new OpTab(this, "Debug/Extras");

//Event Duration slider
Tabs[0].AddItems(new OpLabel(240f, 570f, "Duration between events:")
Expand All @@ -95,7 +98,7 @@ public override void Initialize()
//Max events slider
Tabs[0].AddItems(new OpLabel(10f, 400f, "Max events per cycle:")
{ description = "Maximum amount of chaos events to trigger per ingame cycle." });
Tabs[0].AddItems(new OpSlider(RainWorldCE._maxEventCount, new Vector2(140f, 395f), 200)
Tabs[0].AddItems(new OpSlider(RainWorldCE.maxEventCount, new Vector2(140f, 395f), 200)
{ description = "Maximum amount of chaos events to trigger per ingame cycle." });

//Event time multiplier
Expand Down Expand Up @@ -204,6 +207,20 @@ public override void Initialize()
}
}
eventConfigSB.SetContentSize(sbContentSize);

//Extras/Debug
Tabs[3].AddItems(new OpLabel(220f, 580f, "Debug/Extra features:", bigText: true)
{ description = "Debug and extra fun features" });

//Extra debug logs
Tabs[3].AddItems(new OpCheckBox(RainWorldCE.debugLogs, new Vector2(10f, 540f)));
Tabs[3].AddItems(new OpLabel(45f, 540f, "Enable extra debug logs")
{ description = "Log extra debug info. Only enable when debugging the mod!\n May cause decreased performance and bigger log files" });
//Event trigger key
Tabs[3].AddItems(new OpLabel(10f, 500f, "Trigger event key:")
{ description = "Key to trigger random event instantly" });
Tabs[3].AddItems(new OpKeyBinder(RainWorldCE.triggerEventKey, new Vector2(120f, 495f), new Vector2(120f, 15f), collisionCheck: false)
{ description = "Key to trigger random event instantly" });
}

private void OpenModFolder(UIfocusable trigger)
Expand Down
4 changes: 3 additions & 1 deletion Events/CEEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ public virtual void PlayerChangedRoomTrigger(ref RoomCamera self, ref Room room,
/// </summary>
/// <param name="level">The log level </param>
/// <param name="message">Message to print/log</param>
protected void WriteLog(LogLevel level, string message)
protected void WriteLog(LogLevel level, string message, bool debugLog = false)
{
if (debugLog && !RainWorldCE.debugLogs.Value)
return;
RainWorldCE.ME.Logger_p.Log(LogLevel.Debug, $"[{GetType().Name}] {message}");
}

Expand Down
4 changes: 2 additions & 2 deletions Events/CreatureRandomizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public override void PlayerChangedRoomTrigger(ref RoomCamera self, ref Room room
oldCreature.creatureTemplate.type == CreatureTemplate.Type.Deer ||
(oldCreature.creatureTemplate.type == MoreSlugcats.MoreSlugcatsEnums.CreatureTemplateType.SlugNPC && TryGetConfigAsBool("excludePups"))) continue;

WriteLog(LogLevel.Debug, $"Found {oldCreature} , pos: {oldCreature.pos}");
WriteLog(LogLevel.Debug, $"Found {oldCreature} , pos: {oldCreature.pos}", true);
CreatureTemplate.Type type = possibleCreatures[rnd.Next(possibleCreatures.Count)];
AbstractCreature newCreature = new AbstractCreature(game.world, StaticWorld.GetCreatureTemplate(type), null, oldCreature.pos, game.GetNewID());
WriteLog(LogLevel.Debug, $"Replace creature with {newCreature}");
WriteLog(LogLevel.Debug, $"Replace creature with {newCreature}", true);
movingTo.AddEntity(newCreature);
newCreature.Realize();
newCreature.realizedCreature.PlaceInRoom(room);
Expand Down
4 changes: 4 additions & 0 deletions Events/SecondChance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ public void CreatureEnterDenHook(On.AbstractCreature.orig_IsEnteringDen orig, Ab

private void SafePlayer()
{
//Useful for figuring out how the player was killed and why the safe didn't work
if (RainWorldCE.debugLogs.Value)
WriteLog(BepInEx.Logging.LogLevel.Debug, $"{new System.Diagnostics.StackTrace()}");

if (playerSaved) return;

if (lastRoom.realizedRoom == null)
Expand Down
2 changes: 1 addition & 1 deletion Events/Teleport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public Teleport()
public override void StartupTrigger()
{
List<AbstractRoom> rooms = EventHelpers.GetAllConnectedRooms(EventHelpers.MainPlayer.Room);
WriteLog(LogLevel.Debug, $"{string.Join(",", rooms.Select(x => x.name))}");
WriteLog(LogLevel.Debug, $"{string.Join(",", rooms.Select(x => x.name))}", true);
target = rooms[rnd.Next(rooms.Count)];
_description = $"Slugcat ~ ~ ~ {target.name}";

Expand Down
5 changes: 3 additions & 2 deletions RWHUD/CEHUD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public override void Update()
//Show random event names if selection in progress
if (eventSelection)
{
//RainWorldCE.ME.Logger_p.Log(LogLevel.Debug, $"Count: {eventNames.Count} Events: {String.Join(",", eventNames.ToArray())}");
eventNameLabel.text = eventNames[rand.Next(eventNames.Count)];
}
//Otherwise keep up the current text for around config seconds and then remove it
Expand Down Expand Up @@ -175,7 +174,9 @@ internal void FixActiveEventHoles()
//Start from the lowest label and work our way up
foreach (FLabel label in activeEventLabels.OrderBy(a => a.y))
{
//RainWorldCE.ME.Logger_p.Log(LogLevel.Debug, $"Label {label.text} at Ypos {label.y}. Should be at {startingY + 30f * counter}");
if (RainWorldCE.debugLogs.Value)
RainWorldCE.ME.Logger_p.Log(BepInEx.Logging.LogLevel.Debug, $"Label {label.text} at Ypos {label.y}. Should be at {startingY + 30f * counter}");

//If label not at expected y move it
if (label.y != startingY + 30f * counter)
{
Expand Down
Loading

0 comments on commit ce8892e

Please sign in to comment.