Skip to content

Commit

Permalink
add settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jakzo committed Jul 22, 2024
1 parent b091750 commit 2b6418c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
4 changes: 4 additions & 0 deletions projects/LiveSplit/BoneworksHundredStatus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Shows game progress and achievements for Boneworks 100% speedruns in LiveSplit.

Be aware that some state may not be correct if you restart LiveSplit or Boneworks mid run

## Configuration

There is no UI for the component settings (yet) but you can change a few things (like height or whether to show missing items) by editing your layout file as a text file.

## How it works

- The order of collectibles are stored in `BONEWORKS/UserData/SpeedrunTools/collectible_order/LEVEL_NAME.txt`
Expand Down
52 changes: 36 additions & 16 deletions projects/LiveSplit/BoneworksHundredStatus/src/Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
using LiveSplit.Model;
using Sst.Common.LiveSplit;
using Sst.Common.Boneworks;
using System.Xml;

namespace Sst.Livesplit.BoneworksHundredStatus {
public class Component : IComponent {
public const string NAME = "Boneworks 100% Status";

private float _height = 240;
private bool _showMissingCollectibles = true;

public float HorizontalWidth { get => 300; }
public float VerticalHeight { get => 240; }
public float VerticalHeight { get => _height; }
public float MinimumWidth { get => HorizontalWidth; }
public float MinimumHeight { get => VerticalHeight; }

Expand Down Expand Up @@ -105,23 +109,35 @@ private void DrawGeneral(Graphics g, LiveSplitState state, float width,
public string ComponentName { get => NAME; }

public Control GetSettingsControl(LayoutMode mode) => null;
public System.Xml.XmlNode GetSettings(System.Xml.XmlDocument document) =>
document.CreateElement("Settings");
public void SetSettings(System.Xml.XmlNode settings) {}

// TODO: Settings page
// public Control GetSettingsControl(LayoutMode mode) {
// Settings.Mode = mode;
// return Settings;
// }
public XmlNode GetSettings(XmlDocument document) {
var root = document.CreateElement("Settings");

var height = document.CreateElement("Height");
height.InnerText = _height.ToString();
root.AppendChild(height);

// public System.Xml.XmlNode GetSettings(System.Xml.XmlDocument document) {
// return Settings.GetSettings(document);
// }
var showMissingCollectibles =
document.CreateElement("ShowMissingCollectibles");
showMissingCollectibles.InnerText = _showMissingCollectibles.ToString();
root.AppendChild(height);

return root;
}

// public void SetSettings(System.Xml.XmlNode settings) {
// Settings.SetSettings(settings);
// }
public void SetSettings(XmlNode settings) {
foreach (var n in settings.ChildNodes) {
var node = n as XmlNode;
switch (node.Name) {
case "Height":
_height = float.Parse(node.InnerText);
break;
case "ShowMissingCollectibles":
_showMissingCollectibles = bool.Parse(node.InnerText);
break;
}
}
}

public void Dispose() { _stateUpdater.Dispose(); }

Expand All @@ -135,13 +151,17 @@ public void Update(IInvalidator invalidator, LiveSplitState livesplitState,
if (state == null) {
_progressLabel.Text = "";
} else {
var missingCollectibleLines =
_showMissingCollectibles
? _missingCollectibles.Select(c => $"Missed: {c.DisplayName}")
: new string[] {};
var overallChance = state.rngUnlocks.Aggregate(
1f, (chance, pair) =>
chance * (1f - pair.Value.probabilityNotDroppedYet));
var overallChanceStr = (overallChance * 100f).ToString("N0");
_progressLabel.Text = string.Join(
"\n",
_missingCollectibles.Select(c => $"Missed: {c.DisplayName}")
missingCollectibleLines
.Concat(state.rngUnlocks.All(pair => pair.Value.hasDropped)
? new[] { $"Overall RNG chance: {overallChanceStr}%" }
: new string[] {})
Expand Down
4 changes: 2 additions & 2 deletions projects/LiveSplit/BoneworksHundredStatus/src/Factory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public IComponent Create(LiveSplitState state) =>
public string UpdateName => ComponentName;

public string UpdateURL =>
"https://raw.githubusercontent.com/jakzo/SlzMods/main/projects/LiveSplit/BoneworksHundredStatus";
"https://raw.githubusercontent.com/jakzo/SlzMods/main/projects/LiveSplit/BoneworksHundredStatus/";

public string XMLURL =>
$"{UpdateURL}/update.LiveSplit.BoneworksHundredStatus.xml";
$"{UpdateURL}update.LiveSplit.BoneworksHundredStatus.xml";

public Version Version =>
Version.Parse(Sst.Livesplit.BoneworksHundredStatus.AppVersion.Value);
Expand Down

0 comments on commit 2b6418c

Please sign in to comment.