Skip to content

Commit e49d4b4

Browse files
committed
Custom Fields in Collections
1 parent 6af6b22 commit e49d4b4

13 files changed

Lines changed: 329 additions & 89 deletions

File tree

App/Interfaces/Controls/IBeatmapListingPresenter.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

App/Models/Controls/BeatmapListingModel.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,17 @@ public void SetBeatmaps(Beatmaps beatmaps)
8181

8282
public void SetCollection(ICollection collection)
8383
{
84+
CurrentCollection = collection;
8485
if (collection == null)
8586
{
8687
SetBeatmaps(null);
87-
CurrentCollection = collection;
88-
return;
8988
}
90-
CurrentCollection = collection;
91-
var maps = new Beatmaps();
92-
maps.AddRange(collection.AllBeatmaps());
93-
SetBeatmaps(maps);
89+
else
90+
{
91+
var maps = new Beatmaps();
92+
maps.AddRange(collection.AllBeatmaps());
93+
SetBeatmaps(maps);
94+
}
9495
}
9596

9697
public void FilterBeatmaps(string text)

App/Presenters/Controls/BeatmapListingPresenter.cs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,11 @@
66

77
namespace App.Presenters.Controls
88
{
9-
public class BeatmapListingPresenter: IBeatmapListingPresenter
9+
public class BeatmapListingPresenter
1010
{
1111
readonly IBeatmapListingView _view;
1212
readonly IBeatmapListingModel _model;
1313

14-
private Beatmaps _beatmaps;
15-
16-
public Beatmaps Beatmaps
17-
{
18-
get
19-
{
20-
return _beatmaps;
21-
}
22-
set
23-
{
24-
_beatmaps = value;
25-
_view.SetBeatmaps(value);
26-
}
27-
}
2814
public BeatmapListingPresenter(IBeatmapListingView view, IBeatmapListingModel model)
2915
{
3016
_view = view;
@@ -36,11 +22,11 @@ public BeatmapListingPresenter(IBeatmapListingView view, IBeatmapListingModel mo
3622
_view.BeatmapOperation += (s, a) => _model.EmitBeatmapOperation(a);
3723

3824
_model = model;
39-
_model.BeatmapsChanged += _model_BeatmapsChanged;
25+
_model.BeatmapsChanged += (_, _) => RefreshBeatmapsInViewFromModel();
4026
_model.FilteringStarted+=ModelOnFilteringStarted;
4127
_model.FilteringFinished += _model_FilteringFinished;
4228
_view.SetFilter(_model.GetFilter());
43-
Beatmaps = _model.GetBeatmaps();
29+
RefreshBeatmapsInViewFromModel();
4430
}
4531

4632
private void _model_FilteringFinished(object sender, EventArgs e)
@@ -63,9 +49,15 @@ private void ViewOnSearchTextChanged(object sender, EventArgs eventArgs)
6349
_model.FilterBeatmaps(_view.SearchText);
6450
}
6551

66-
private void _model_BeatmapsChanged(object sender, System.EventArgs e)
52+
private void RefreshBeatmapsInViewFromModel()
6753
{
68-
Beatmaps = _model.GetBeatmaps();
54+
_view.SetBeatmaps(_model.GetBeatmaps());
55+
_view.ClearCustomFieldDefinitions();
56+
var curCol = _model.CurrentCollection;
57+
if(curCol != null && curCol.CustomFieldDefinitions != null)
58+
{
59+
_view.SetCustomFieldDefinitions(curCol.CustomFieldDefinitions);
60+
}
6961
}
7062

7163

CollectionManagerDll/DataTypes/BeatmapExtension.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
24

35
namespace CollectionManager.DataTypes
46
{
@@ -13,5 +15,42 @@ public class BeatmapExtension : Beatmap
1315
public string UserComment { get; set; } = "";
1416

1517
#endregion
18+
19+
#region Custom Field Stuff
20+
21+
private Dictionary<string, object> _customFields;
22+
23+
public void SetCustomFieldValues(BeatmapExtension other)
24+
{
25+
_customFields = other._customFields == null ? null : new Dictionary<string, object>(other._customFields);
26+
}
27+
28+
public void SetCustomFieldValue(string key, object value)
29+
{
30+
_customFields ??= new Dictionary<string, object>();
31+
_customFields[key] = value;
32+
}
33+
34+
public object GetCustomFieldValue(string key)
35+
{
36+
if(_customFields == null ) return null;
37+
return _customFields.TryGetValue(key, out var value) ? value : null;
38+
}
39+
40+
public IEnumerable<string> GetStringCustomFieldValues()
41+
{
42+
if (_customFields == null) yield break;
43+
foreach(var customField in _customFields)
44+
{
45+
if(customField.Value is string stringValue) yield return stringValue;
46+
}
47+
}
48+
49+
public IEnumerable<KeyValuePair<string, object>> GetCustomFields()
50+
{
51+
return _customFields ?? Enumerable.Empty<KeyValuePair<string, object>>();
52+
}
53+
54+
#endregion
1655
}
1756
}

CollectionManagerDll/DataTypes/Collection.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public virtual int NumberOfBeatmaps
5858

5959
public int Id { get; set; }
6060

61+
public IReadOnlyCollection<CustomFieldDefinition> CustomFieldDefinitions { get; set; }
62+
6163
public void SetLoadedMaps(MapCacher instance)
6264
{
6365
if (instance == null)
@@ -161,6 +163,7 @@ public void AddBeatmapByMapId(int mapId)
161163
private void ProcessAdditionalProps(BeatmapExtension src, BeatmapExtension dest)
162164
{
163165
dest.UserComment = src.UserComment;
166+
dest.SetCustomFieldValues(src);
164167
}
165168
protected virtual void ProcessNewlyAddedMap(BeatmapExtension map)
166169
{
@@ -236,6 +239,5 @@ public IEnumerator GetEnumerator()
236239
{
237240
return this.AllBeatmaps().GetEnumerator();
238241
}
239-
240242
}
241243
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using CollectionManager.Enums;
2+
3+
namespace CollectionManager.DataTypes
4+
{
5+
public class CustomFieldDefinition
6+
{
7+
public string Key { get; set; }
8+
public CustomFieldType Type { get; set; }
9+
public string DisplayText { get; set; }
10+
}
11+
}

CollectionManagerDll/DataTypes/ICollection.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public interface ICollection
5353

5454
int Id { get; set; }
5555

56+
IReadOnlyCollection<CustomFieldDefinition> CustomFieldDefinitions { get; }
57+
5658
void SetLoadedMaps(MapCacher instance);
5759
IEnumerable<BeatmapExtension> AllBeatmaps();
5860
IEnumerable<BeatmapExtension> NotKnownBeatmaps();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace CollectionManager.Enums
2+
{
3+
public enum CustomFieldType
4+
{
5+
String,
6+
Boolean,
7+
GameMode,
8+
Grade,
9+
UInt8,
10+
UInt16,
11+
UInt32,
12+
UInt64,
13+
Int8,
14+
Int16,
15+
Int32,
16+
Int64,
17+
DateTime,
18+
Single,
19+
Double
20+
}
21+
}

0 commit comments

Comments
 (0)