Skip to content

Commit

Permalink
Created the first hit of the plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
cartersoft committed Jun 10, 2022
1 parent ef54790 commit 97bfdde
Show file tree
Hide file tree
Showing 8 changed files with 404 additions and 20 deletions.
19 changes: 19 additions & 0 deletions LiveSplit.RunCounter.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,35 @@ VisualStudioVersion = 15.0.28307.1972
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiveSplit.RunCounter", "LiveSplit.RunCounter\LiveSplit.RunCounter.csproj", "{688643C5-F171-48B0-87F7-AD6BA19EE7D8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiveSplit.Core", "..\LiveSplit\LiveSplit\LiveSplit.Core\LiveSplit.Core.csproj", "{6DE847DB-20A3-4848-AEEE-1B4364AECDFB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateManager", "..\LiveSplit\LiveSplit\UpdateManager\UpdateManager.csproj", "{56DEA3A0-2EB7-493B-B50F-A5E3AA8AE52A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release Candidate|Any CPU = Release Candidate|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{688643C5-F171-48B0-87F7-AD6BA19EE7D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{688643C5-F171-48B0-87F7-AD6BA19EE7D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{688643C5-F171-48B0-87F7-AD6BA19EE7D8}.Release Candidate|Any CPU.ActiveCfg = Release|Any CPU
{688643C5-F171-48B0-87F7-AD6BA19EE7D8}.Release Candidate|Any CPU.Build.0 = Release|Any CPU
{688643C5-F171-48B0-87F7-AD6BA19EE7D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{688643C5-F171-48B0-87F7-AD6BA19EE7D8}.Release|Any CPU.Build.0 = Release|Any CPU
{6DE847DB-20A3-4848-AEEE-1B4364AECDFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6DE847DB-20A3-4848-AEEE-1B4364AECDFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6DE847DB-20A3-4848-AEEE-1B4364AECDFB}.Release Candidate|Any CPU.ActiveCfg = Release Candidate|Any CPU
{6DE847DB-20A3-4848-AEEE-1B4364AECDFB}.Release Candidate|Any CPU.Build.0 = Release Candidate|Any CPU
{6DE847DB-20A3-4848-AEEE-1B4364AECDFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6DE847DB-20A3-4848-AEEE-1B4364AECDFB}.Release|Any CPU.Build.0 = Release|Any CPU
{56DEA3A0-2EB7-493B-B50F-A5E3AA8AE52A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{56DEA3A0-2EB7-493B-B50F-A5E3AA8AE52A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{56DEA3A0-2EB7-493B-B50F-A5E3AA8AE52A}.Release Candidate|Any CPU.ActiveCfg = Release Candidate|Any CPU
{56DEA3A0-2EB7-493B-B50F-A5E3AA8AE52A}.Release Candidate|Any CPU.Build.0 = Release Candidate|Any CPU
{56DEA3A0-2EB7-493B-B50F-A5E3AA8AE52A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{56DEA3A0-2EB7-493B-B50F-A5E3AA8AE52A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
54 changes: 36 additions & 18 deletions LiveSplit.RunCounter/LiveSplit.RunCounter.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>688643c5-f171-48b0-87f7-ad6ba19ee7d8</ProjectGuid>
<ProjectGuid>{688643C5-F171-48B0-87F7-AD6BA19EE7D8}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>LiveSplit.RunCounter</RootNamespace>
Expand All @@ -31,24 +31,42 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System"/>

<Reference Include="System.Core"/>
<Reference Include="System.Xml.Linq"/>
<Reference Include="System.Data.DataSetExtensions"/>


<Reference Include="Microsoft.CSharp"/>

<Reference Include="System.Data"/>

<Reference Include="System.Net.Http"/>

<Reference Include="System.Xml"/>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="UI\Components\RunCounterComponent.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UI\Components\RunCounterFactory.cs" />
<Compile Include="UI\Components\RunCounterSettings.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="UI\Components\RunCounterSettings.Designer.cs">
<DependentUpon>RunCounterSettings.cs</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\LiveSplit\LiveSplit\LiveSplit.Core\LiveSplit.Core.csproj">
<Project>{6de847db-20a3-4848-aeee-1b4364aecdfb}</Project>
<Name>LiveSplit.Core</Name>
</ProjectReference>
<ProjectReference Include="..\..\LiveSplit\LiveSplit\UpdateManager\UpdateManager.csproj">
<Project>{56dea3a0-2eb7-493b-b50f-a5e3aa8ae52a}</Project>
<Name>UpdateManager</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="UI\Components\RunCounterSettings.resx">
<DependentUpon>RunCounterSettings.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
2 changes: 2 additions & 0 deletions LiveSplit.RunCounter/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using LiveSplit.UI.Components;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
Expand Down Expand Up @@ -34,3 +35,4 @@
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: ComponentFactory(typeof(RunCounterFactory))]
69 changes: 67 additions & 2 deletions LiveSplit.RunCounter/UI/Components/RunCounterComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ public class RunCounterComponent : IComponent
{
protected InfoTextComponent InternalComponent { get; set; }
public RunCounterSettings Settings { get; set; }
public GraphicsCache Cache { get; set; }
protected LiveSplitState CurrentState { get; set; }
public string ComponentName => "Run Counter";
private int counterValue = 0;
private string counterField = "xx Runs: ";

public float HorizontalWidth => InternalComponent.HorizontalWidth;
public float MinimumWidth => InternalComponent.MinimumWidth;
Expand All @@ -29,7 +32,10 @@ public class RunCounterComponent : IComponent

public RunCounterComponent(LiveSplitState state)
{

Settings = new RunCounterSettings();
Cache = new GraphicsCache();
InternalComponent = new InfoTextComponent("xx Runs: ", "0");
CurrentState = state;
}

public void DrawHorizontal(Graphics g, LiveSplitState state, float height, Region clipRegion)
Expand Down Expand Up @@ -76,7 +82,10 @@ public void SetSettings(System.Xml.XmlNode settings)

public void Update(IInvalidator invalidator, LiveSplitState state, float width, float height, LayoutMode mode)
{

string count = GetSimilarTimeCount(getPBTime()).ToString();
InternalComponent.InformationName = counterField;
InternalComponent.InformationValue = counterValue >= 0 ? count : "?";
InternalComponent.Update(invalidator, state, width, height, mode);
}

public void Dispose()
Expand All @@ -85,5 +94,61 @@ public void Dispose()
}

public int GetSettingsHashCode() => Settings.GetSettingsHashCode();


// Lets get the PB Time to track
private Attempt getPBTime()
{
var bestTime = TimeSpan.MaxValue;
int bestIndex = 0;

if (CurrentState.Run.AttemptHistory.Count <= 0)
{
Attempt TempAttempt = new Attempt();
TempAttempt.Index = 0;
return TempAttempt;
}

foreach (Attempt attempt in CurrentState.Run.AttemptHistory)
{
if (attempt.Time[CurrentState.CurrentTimingMethod].HasValue)
{
if (attempt.Time[CurrentState.CurrentTimingMethod].Value < bestTime)
{
bestTime = attempt.Time[CurrentState.CurrentTimingMethod].Value;
bestIndex = attempt.Index;
}
}
}

if (bestIndex == 0)
return CurrentState.Run.AttemptHistory[0];
return CurrentState.Run.AttemptHistory[bestIndex - 1];
}

private int GetSimilarTimeCount(Attempt pbAttempt)
{
int tempCounter = 0;
string pbdays = pbAttempt.Duration.Value.Days.ToString(); // get the days (for really long pbs)
string pbhour = pbAttempt.Duration.Value.Hours.ToString(); // get the hour value (for long pbs)
string pbmin = pbAttempt.Duration.Value.Minutes.ToString(); // get the min value (for all pbs)

counterField = pbhour + ":" + pbmin + ":xx Runs: ";

foreach (Attempt attempt in CurrentState.Run.AttemptHistory) {

// get the attempts that match the same hour and minuite barriers so that any game can use this
string tempd = attempt.Duration.Value.Days.ToString();
string temph = attempt.Duration.Value.Hours.ToString();
string tempm = attempt.Duration.Value.Minutes.ToString();

if (pbdays.Equals(tempd) && pbhour.Equals(temph) && pbmin.Equals(tempm))
{
tempCounter++;
}
}

return tempCounter;
}
}
}
17 changes: 17 additions & 0 deletions LiveSplit.RunCounter/UI/Components/RunCounterFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using LiveSplit.Model;
using System;

namespace LiveSplit.UI.Components
{
public class RunCounterFactory : IComponentFactory
{
public string ComponentName => "Run Counter";
public string Description => "Displays the amount of similar run times you've had close to your pb (minute barriers).";
public ComponentCategory Category => ComponentCategory.Information;
public IComponent Create(LiveSplitState state) => new RunCounterComponent(state);
public string UpdateName => ComponentName;
public string UpdateURL => "";
public string XMLURL => UpdateURL + "";
public Version Version => Version.Parse("1.0.0");
}
}
84 changes: 84 additions & 0 deletions LiveSplit.RunCounter/UI/Components/RunCounterSettings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions LiveSplit.RunCounter/UI/Components/RunCounterSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Xml;

namespace LiveSplit.UI.Components
{
public partial class RunCounterSettings : UserControl
{
public bool Display2Rows { get; set; }
public LayoutMode Mode { get; set; }

public RunCounterSettings()
{
InitializeComponent();
Display2Rows = false;
}

private void RunCounterSettings_Load(object sender, EventArgs e)
{
if (Mode == LayoutMode.Horizontal)
{
chkTwoRows.Enabled = false;
chkTwoRows.DataBindings.Clear();
chkTwoRows.Checked = true;
}
else
{
chkTwoRows.Enabled = true;
chkTwoRows.DataBindings.Clear();
chkTwoRows.DataBindings.Add("Checked", this, "Display2Rows", false, DataSourceUpdateMode.OnPropertyChanged);
}
}

private int CreateSettingsNode(XmlDocument document, XmlElement parent)
{
return SettingsHelper.CreateSetting(document, parent, "Version", "1.0") ^
SettingsHelper.CreateSetting(document, parent, "Display2Rows", Display2Rows);
}

public XmlNode GetSettings(XmlDocument document)
{
var parent = document.CreateElement("Settings");
CreateSettingsNode(document, parent);
return parent;
}

public int GetSettingsHashCode()
{
return CreateSettingsNode(null, null);
}

public void SetSettings(XmlNode node)
{
var element = (XmlElement)node;
Display2Rows = SettingsHelper.ParseBool(element["Display2Rows"], false);
}
}
}
Loading

0 comments on commit 97bfdde

Please sign in to comment.