Skip to content

Commit

Permalink
Fixed character info and auto-configure problems when playing on Rubi…
Browse files Browse the repository at this point in the history
…-Ka 2019

This closes #3 and closes #4
  • Loading branch information
davghouse committed Jul 24, 2019
1 parent 29ed8bb commit 28c4bec
Show file tree
Hide file tree
Showing 19 changed files with 209 additions and 30 deletions.
1 change: 1 addition & 0 deletions AODamageMeter.UI/AODamageMeter.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
</ApplicationDefinition>
<Compile Include="Converters\BoolToNegationConverter.cs" />
<Compile Include="Converters\ColorToRowBrushConverter.cs" />
<Compile Include="Converters\DimensionNameConverter.cs" />
<Compile Include="Converters\IconPathToBitmapImageConverter.cs" />
<Compile Include="Converters\ObjectToBoolConverter.cs" />
<Compile Include="Converters\SelectedCharacterDescriptionConverter.cs" />
Expand Down
12 changes: 12 additions & 0 deletions AODamageMeter.UI/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@
<setting name="UpgradeRequired" serializeAs="String">
<value>True</value>
</setting>
<setting name="Dimensions" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
</value>
</setting>
<setting name="SelectedDimension" serializeAs="String">
<value>RubiKa</value>
</setting>
<setting name="DimensionColumnWidth" serializeAs="String">
<value>100</value>
</setting>
</AODamageMeter.UI.Properties.Settings>
</userSettings>
</configuration>
1 change: 1 addition & 0 deletions AODamageMeter.UI/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<converters:BoolToNegationConverter x:Key="BoolToNegationConverter"/>
<converters:ObjectToBoolConverter x:Key="ObjectToBoolConverter"/>
<converters:SelectedCharacterDescriptionConverter x:Key="SelectedCharacterDescriptionConverter"/>
<converters:DimensionNameConverter x:Key="DimensionNameConverter"/>
<BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter"/>

<Color x:Key="LightBlueColor">#73CBD3</Color>
Expand Down
16 changes: 16 additions & 0 deletions AODamageMeter.UI/Converters/DimensionNameConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Globalization;
using System.Windows.Data;

namespace AODamageMeter.UI.Converters
{
[ValueConversion(typeof(Dimension), typeof(string))]
public class DimensionNameConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
=> ((Dimension)value).GetName();

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
=> DimensionHelpers.GetDimensionOrDefault((string)value);
}
}
4 changes: 2 additions & 2 deletions AODamageMeter.UI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@

[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]

[assembly: AssemblyVersion("1.4.0.0")]
[assembly: AssemblyFileVersion("1.4.0.0")]
[assembly: AssemblyVersion("1.4.1.0")]
[assembly: AssemblyFileVersion("1.4.1.0")]
39 changes: 38 additions & 1 deletion AODamageMeter.UI/Properties/Settings.Designer.cs

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

10 changes: 10 additions & 0 deletions AODamageMeter.UI/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,15 @@
<Setting Name="UpgradeRequired" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="Dimensions" Type="System.Collections.Specialized.StringCollection" Scope="User">
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" /&gt;</Value>
</Setting>
<Setting Name="SelectedDimension" Type="AODamageMeter.Dimension" Scope="User">
<Value Profile="(Default)">RubiKa</Value>
</Setting>
<Setting Name="DimensionColumnWidth" Type="System.Double" Scope="User">
<Value Profile="(Default)">100</Value>
</Setting>
</Settings>
</SettingsFile>
22 changes: 20 additions & 2 deletions AODamageMeter.UI/ViewModels/CharacterInfoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ public sealed class CharacterInfoViewModel : ViewModelBase
private CharacterSelectionViewModel _characterSelectionViewModel;

public CharacterInfoViewModel(CharacterSelectionViewModel characterSelectionViewModel,
string characterName = null, string logFilePath = null)
string characterName = null, Dimension dimension = Dimension.RubiKa, string logFilePath = null)
{
_characterSelectionViewModel = characterSelectionViewModel;
CharacterName = characterName;
Dimension = dimension;
LogFilePath = logFilePath;
AutoConfigureCommand = new RelayCommand(ExecuteAutoConfigureCommand);
}
Expand All @@ -37,6 +38,23 @@ public string CharacterName
}
}

public static IReadOnlyList<string> Dimensions { get; } = DimensionHelpers.AllDimensions
.Select(d => d.GetName())
.ToArray();

private Dimension _dimension;
public Dimension Dimension
{
get => _dimension;
set
{
if (Set(ref _dimension, value))
{
AutoConfigureResult = null;
}
}
}

private string _logFilePath;
public string LogFilePath
{
Expand Down Expand Up @@ -120,7 +138,7 @@ private void ExecuteAutoConfigureCommand()
return;
}

var characterAndBioRetriever = Character.GetOrCreateCharacterAndBioRetriever(CharacterName);
var characterAndBioRetriever = Character.GetOrCreateCharacterAndBioRetriever(CharacterName, Dimension);
var character = characterAndBioRetriever.character;
characterAndBioRetriever.bioRetriever.Wait(); // Not worth using await and binding IsEnableds.
if (!character.HasPlayerInfo)
Expand Down
14 changes: 12 additions & 2 deletions AODamageMeter.UI/ViewModels/CharacterSelectionViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,35 @@ private void TryClearFile()
private void Load()
{
var characterNames = Settings.Default.CharacterNames.Cast<string>().ToArray();
var dimensions = Settings.Default.Dimensions.Cast<string>().ToArray();
var logFilePaths = Settings.Default.LogFilePaths.Cast<string>().ToArray();
for (int i = 0; i < characterNames.Length; ++i)
{
CharacterInfoViewModels.Add(new CharacterInfoViewModel(this, characterNames[i], logFilePaths[i]));
CharacterInfoViewModels.Add(new CharacterInfoViewModel(this,
characterNames[i],
DimensionHelpers.GetDimensionOrDefault(dimensions.ElementAtOrDefault(i)),
logFilePaths[i]));
}

string selectedCharacterName = Settings.Default.SelectedCharacterName;
Dimension selectedDimension = Settings.Default.SelectedDimension;
string selectedLogFilePath = Settings.Default.SelectedLogFilePath;
SelectedCharacterInfoViewModel = CharacterInfoViewModels
.FirstOrDefault(c => c.CharacterName == selectedCharacterName && c.LogFilePath == selectedLogFilePath);
.FirstOrDefault(c => c.CharacterName == selectedCharacterName
&& c.Dimension == selectedDimension
&& c.LogFilePath == selectedLogFilePath);
}

public void Save()
{
Settings.Default.CharacterNames.Clear();
Settings.Default.CharacterNames.AddRange(CharacterInfoViewModels.Select(c => c.CharacterName).ToArray());
Settings.Default.Dimensions.Clear();
Settings.Default.Dimensions.AddRange(CharacterInfoViewModels.Select(c => DimensionHelpers.GetName(c.Dimension)).ToArray());
Settings.Default.LogFilePaths.Clear();
Settings.Default.LogFilePaths.AddRange(CharacterInfoViewModels.Select(c => c.LogFilePath).ToArray());
Settings.Default.SelectedCharacterName = SelectedCharacterInfoViewModel?.CharacterName;
Settings.Default.SelectedDimension = SelectedCharacterInfoViewModel?.Dimension ?? Dimension.RubiKa;
Settings.Default.SelectedLogFilePath = SelectedCharacterInfoViewModel?.LogFilePath;
Settings.Default.Save();
}
Expand Down
15 changes: 11 additions & 4 deletions AODamageMeter.UI/ViewModels/DamageMeterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public sealed class DamageMeterViewModel : ViewModelBase
{
private readonly IProgress<object> _rowUpdater;
private string _characterName;
private Dimension _dimension;
private string _logFilePath;
private CancellationTokenSource _damageMeterUpdaterCTS;
private Task _damageMeterUpdater;
Expand All @@ -29,7 +30,10 @@ public DamageMeterViewModel()
ToggleIsPausedCommand = new RelayCommand(ExecuteToggleIsPausedCommand);
ResetAndSaveFightCommand = new RelayCommand(ExecuteResetAndSaveFightCommand);
ResetFightCommand = new RelayCommand(ExecuteResetFightCommand);
TryInitializeDamageMeter(Settings.Default.SelectedCharacterName, Settings.Default.SelectedLogFilePath);
TryInitializeDamageMeter(
Settings.Default.SelectedCharacterName,
Settings.Default.SelectedDimension,
Settings.Default.SelectedLogFilePath);
// Performance optimization: don't let performance degrade as the # of fights in the fight history increase.
// Would be more complicated to extend this to views within a historical fight, but possible. But don't need
// to do it there because it's less expensive than the unavoidable cost of updating the current fight.
Expand Down Expand Up @@ -78,12 +82,14 @@ public ObservableCollection<MainRowBase> DisplayedRows
private set => Set(ref _displayedRows, value);
}

public bool TryInitializeDamageMeter(string characterName, string logFilePath)
public bool TryInitializeDamageMeter(string characterName, Dimension dimension, string logFilePath)
{
if (string.IsNullOrWhiteSpace(characterName) || string.IsNullOrWhiteSpace(logFilePath))
return false;

if (characterName == _characterName && logFilePath == _logFilePath)
if (characterName == _characterName
&& dimension == _dimension
&& logFilePath == _logFilePath)
return true;

if (!File.Exists(logFilePath))
Expand All @@ -95,8 +101,9 @@ public bool TryInitializeDamageMeter(string characterName, string logFilePath)
DisposeDamageMeter();

_characterName = characterName;
_dimension = dimension;
_logFilePath = logFilePath;
DamageMeter = new DamageMeter(characterName, logFilePath)
DamageMeter = new DamageMeter(characterName, dimension, logFilePath)
{
IsPaused = IsPaused,
PetRegistrations = PetRegistrationRepository.PetRegistrations
Expand Down
6 changes: 6 additions & 0 deletions AODamageMeter.UI/Views/CharacterInfoView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
<TextBlock Text="Name:"/>
<TextBox Margin="0 2 0 10" x:Name="NameTextBox"
Text="{Binding CharacterName, UpdateSourceTrigger=PropertyChanged}"/>

<TextBlock Text="Dimension:"/>
<ComboBox Margin="0 2 0 10"
ItemsSource="{Binding Dimensions}"
SelectedValue="{Binding Dimension, Converter={StaticResource DimensionNameConverter}}"/>

<TextBlock Text="Log file:"/>
<TextBox Margin="0 2 0 5"
Text="{Binding LogFilePath, UpdateSourceTrigger=PropertyChanged}"/>
Expand Down
2 changes: 2 additions & 0 deletions AODamageMeter.UI/Views/CharacterSelectionView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
<GridView AllowsColumnReorder="False">
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding CharacterName}"
Width="{Binding Source={x:Static properties:Settings.Default}, Path=NameColumnWidth, Mode=TwoWay}"/>
<GridViewColumn Header="Dimension" DisplayMemberBinding="{Binding Dimension, Converter={StaticResource DimensionNameConverter}}"
Width="{Binding Source={x:Static properties:Settings.Default}, Path=DimensionColumnWidth, Mode=TwoWay}"/>
<GridViewColumn Header="Log File" DisplayMemberBinding="{Binding LogFilePath}"
Width="{Binding Source={x:Static properties:Settings.Default}, Path=LogFileColumnWidth, Mode=TwoWay}"/>
<GridViewColumn Header="File Size" DisplayMemberBinding="{Binding LogFileSize}"
Expand Down
2 changes: 1 addition & 1 deletion AODamageMeter.UI/Views/DamageMeterView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private void ShowCharacterSelection()
else
{
_damageMeterViewModel.TryInitializeDamageMeter(
Settings.Default.SelectedCharacterName, Settings.Default.SelectedLogFilePath);
Settings.Default.SelectedCharacterName, Settings.Default.SelectedDimension, Settings.Default.SelectedLogFilePath);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions AODamageMeter/AODamageMeter.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net462</TargetFramework>
<AssemblyVersion>1.4.0.0</AssemblyVersion>
<FileVersion>1.4.0.0</FileVersion>
<Version>1.4.0</Version>
<AssemblyVersion>1.4.1.0</AssemblyVersion>
<FileVersion>1.4.1.0</FileVersion>
<Version>1.4.1</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.3" />
Expand Down
23 changes: 14 additions & 9 deletions AODamageMeter/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ public class Character
protected static readonly Dictionary<Character, Task> _characterBioRetrievers = new Dictionary<Character, Task>();
protected readonly object _lock = new object(); // Just using a single object for convenience; see comments/links below.

protected Character(string name)
protected Character(string name, Dimension dimension)
{
Name = name;
UncoloredName = UncolorName(name);
Dimension = dimension;
}

public string Name { get; }
public string UncoloredName { get; }

public Dimension Dimension { get; }

protected bool _isPlayer;
public bool IsPlayer
{
Expand Down Expand Up @@ -117,14 +120,15 @@ public bool HasOrganizationInfo
// in of the bio, after the HTTP request comes in, that can happen in parallel. When it does happen in parallel we
// have to worry about locking and volatility and so on, which is why we use locks above. See:
// http://stackoverflow.com/q/33528408, http://stackoverflow.com/q/434890, http://jonskeet.uk/csharp/threads/volatility.shtml.
public static Character GetOrCreateCharacter(string name) => GetOrCreateCharacterAndBioRetriever(name).character;
public static (Character character, Task bioRetriever) GetOrCreateCharacterAndBioRetriever(string name)
public static Character GetOrCreateCharacter(string name, Dimension dimension)
=> GetOrCreateCharacterAndBioRetriever(name, dimension).character;
public static (Character character, Task bioRetriever) GetOrCreateCharacterAndBioRetriever(string name, Dimension dimension)
{
if (_characters.TryGetValue(name, out Character character))
if (_characters.TryGetValue($"{name} ({dimension.GetName()})", out Character character))
return (character, _characterBioRetrievers[character]);

character = new Character(name);
_characters.Add(name, character);
character = new Character(name, dimension);
_characters.Add($"{name} ({dimension.GetName()})", character);

Task characterBioRetriever = RetrieveCharacterBio(character);
_characterBioRetrievers.Add(character, characterBioRetriever);
Expand All @@ -148,7 +152,8 @@ protected static async Task RetrieveCharacterBio(Character character)
character.IsPlayer = !IsAmbiguousPlayerName(character.Name);

var response = await _httpClient
.GetAsync($"http://people.anarchy-online.com/character/bio/d/5/name/{character.Name}/bio.xml?data_type=json").ConfigureAwait(false);
.GetAsync($"http://people.anarchy-online.com/character/bio/d/{character.Dimension.GetDimensionID()}/name/{character.Name}/bio.xml?data_type=json")
.ConfigureAwait(false);
if (response.IsSuccessStatusCode)
{
var characterBio = await response.Content.ReadAsAsync<dynamic>().ConfigureAwait(false);
Expand All @@ -170,8 +175,8 @@ protected static async Task RetrieveCharacterBio(Character character)
}
}

public static bool TryGetCharacter(string name, out Character character)
=> _characters.TryGetValue(name, out character);
public static bool TryGetCharacter(string name, Dimension dimension, out Character character)
=> _characters.TryGetValue($"{name} ({dimension.GetName()})", out character);

private static bool IsUppercase(char c) => c >= 'A' && c <= 'Z';
private static bool IsLowercaseOrDigit(char c) => c >= 'a' && c <= 'z' || c >= '0' && c <= '9';
Expand Down
7 changes: 5 additions & 2 deletions AODamageMeter/DamageMeter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ public class DamageMeter : IDisposable
{
protected readonly StreamReader _logStreamReader;

public DamageMeter(string characterName, string logFilePath, DamageMeterMode mode = DamageMeterMode.RealTime)
public DamageMeter(string characterName, Dimension dimension, string logFilePath,
DamageMeterMode mode = DamageMeterMode.RealTime)
{
Dimension = dimension;
LogFilePath = logFilePath;
_logStreamReader = new StreamReader(File.Open(LogFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
Mode = mode;
Owner = Character.GetOrCreateCharacter(characterName);
Owner = Character.GetOrCreateCharacter(characterName, dimension);
Owner.IsPlayer = true;
}

public Dimension Dimension { get; }
public string LogFilePath { get; }
public DamageMeterMode Mode { get; }
public bool IsRealTimeMode => Mode == DamageMeterMode.RealTime;
Expand Down
Loading

0 comments on commit 28c4bec

Please sign in to comment.