Skip to content

Commit 0ed505d

Browse files
author
EmoSaru
committed
Let pack developers choose the item capture layout for attachable notes (#106)
Allow pack developers to point attachable markdown notes' item capture box at a grid other than the hardcoded tracker_capture_item. - Add pack-wide default: DefaultItemCaptureLayout on TrackerState, sourced from settings.json's capture_item_layout_default (fallback tracker_capture_item), reset on each pack load. - Add Location-level ItemCaptureLayout with child-Location inheritance (nearest explicit override wins, else pack default, else tracker_capture_item), parsed from the locations capture_item_layout key. - Resolve MarkdownTextWithItemsNote.ItemCaptureLayout through its owning Location (or the state pack default for non-Location sites) instead of the hardcoded string. No user-facing picker; value is pack-config only. Existing packs/notes without the keys fall back to tracker_capture_item.
1 parent c4a9e08 commit 0ed505d

6 files changed

Lines changed: 65 additions & 2 deletions

File tree

EmoTracker.Data/LocationDatabase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,8 @@ Location LoadLocation(IGamePackage package, Location parent, JObject data, Sessi
643643
if (!string.IsNullOrWhiteSpace(color))
644644
instance.Color = color;
645645

646+
instance.ItemCaptureLayout = data.GetValue<string>("capture_item_layout");
647+
646648
JArray rules = data.GetValue<JArray>("access_rules");
647649
if (rules != null)
648650
{

EmoTracker.Data/Locations/Location.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,31 @@ public string Color
115115
set { ColorRaw = value; NotifyPropertyChanged(); }
116116
}
117117

118+
// Item capture layout: per-location override, inherited by child
119+
// Locations until overridden deeper in the hierarchy. Used by
120+
// attachable markdown notes to resolve the item grid they present.
121+
[KVMutable]
122+
private partial string ItemCaptureLayoutRaw { get; set; }
123+
124+
public string ItemCaptureLayout
125+
{
126+
get
127+
{
128+
var raw = ItemCaptureLayoutRaw;
129+
if (!string.IsNullOrWhiteSpace(raw)) return raw;
130+
131+
var parent = Parent;
132+
if (parent != null) return parent.ItemCaptureLayout;
133+
134+
var state = this.OwnerState as Sessions.TrackerState;
135+
var packDefault = state?.DefaultItemCaptureLayout;
136+
if (!string.IsNullOrWhiteSpace(packDefault)) return packDefault;
137+
138+
return "tracker_capture_item";
139+
}
140+
set { ItemCaptureLayoutRaw = value; NotifyPropertyChanged(); }
141+
}
142+
118143
[KVMutable]
119144
public partial ImageReference Thumbnail { get; set; }
120145

EmoTracker.Data/Notes/MarkdownTextWithItemsNote.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
using System.Collections.Generic;
22
using System.Collections.ObjectModel;
3+
using EmoTracker.Data.Locations;
4+
using EmoTracker.Data.Sessions;
35

46
namespace EmoTracker.Data.Notes
57
{
68
public class MarkdownTextWithItemsNote : MarkdownTextNote, IItemCollection
79
{
810
ObservableCollection<ITrackableItem> mItems = new ObservableCollection<ITrackableItem>();
911

12+
internal NoteTakingSite Site { get; set; }
13+
1014
public string ItemCaptureLayout
1115
{
12-
get { return "tracker_capture_item"; }
16+
get
17+
{
18+
if (Site?.Owner is Location loc)
19+
return loc.ItemCaptureLayout;
20+
21+
var state = Site?.OwnerState as TrackerState;
22+
var packDefault = state?.DefaultItemCaptureLayout;
23+
if (!string.IsNullOrWhiteSpace(packDefault)) return packDefault;
24+
25+
return "tracker_capture_item";
26+
}
1327
}
1428

1529
public IEnumerable<ITrackableItem> Items

EmoTracker.Data/Notes/NoteTakingSite.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void SetOwnerState(Sessions.TrackerState state)
2626
mOwnerStateOverride = state;
2727
}
2828

29-
Sessions.TrackerState OwnerState
29+
internal Sessions.TrackerState OwnerState
3030
=> mOwnerStateOverride ?? (Owner?.OwnerState as Sessions.TrackerState);
3131
ObservableCollection<Note> mNotes = new ObservableCollection<Note>();
3232

@@ -51,6 +51,8 @@ public bool AddNote(Note note)
5151
{
5252
note.PropertyChanged += Note_PropertyChanged;
5353
mNotes.Add(note);
54+
if (note is MarkdownTextWithItemsNote itemNote)
55+
itemNote.Site = this;
5456
return true;
5557
}
5658

EmoTracker.Data/Sessions/PackageLoader.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ static void ResetPackageSettings(TrackerState target)
235235
{
236236
target.AllowResize = true;
237237
target.DisabledImageFilterSpec = TrackerDefaults.DisabledImageFilterSpec;
238+
target.DefaultItemCaptureLayout = TrackerDefaults.ItemCaptureLayout;
238239
}
239240

240241
// Mirrors Tracker.LoadPackageSettings, but operates on the target's
@@ -262,6 +263,10 @@ static void LoadPackageSettings(TrackerState target, IGamePackage package)
262263
if (spec != null)
263264
target.DisabledImageFilterSpec = spec;
264265

266+
string defaultLayout = root.GetValue<string>("capture_item_layout_default", null);
267+
if (!string.IsNullOrWhiteSpace(defaultLayout))
268+
target.DefaultItemCaptureLayout = defaultLayout;
269+
265270
target.Locations.ParseLocationVisualProperties(root, target.Locations.Root, package);
266271

267272
AccessibilityRule.EnableCache = root.GetValue<bool>("enable_accessibility_rule_caching", true);
@@ -313,5 +318,6 @@ static void LoadPackageSettings(TrackerState target, IGamePackage package)
313318
static class TrackerDefaults
314319
{
315320
public const string DisabledImageFilterSpec = "grayscale, dim";
321+
public const string ItemCaptureLayout = "tracker_capture_item";
316322
}
317323
}

EmoTracker.Data/Sessions/TrackerState.PackageOps.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ public bool AllowResize
7171
set { SetProperty(ref mAllowResize, value); }
7272
}
7373

74+
string mDefaultItemCaptureLayout = "tracker_capture_item";
75+
/// <summary>
76+
/// Pack-wide default item-capture layout grid used by attachable
77+
/// markdown notes that aren't covered by a Location-level
78+
/// <c>capture_item_layout</c>. Set by <c>settings.json</c>'s
79+
/// <c>capture_item_layout_default</c> key during pack load; falls
80+
/// back to <c>"tracker_capture_item"</c>.
81+
/// </summary>
82+
public string DefaultItemCaptureLayout
83+
{
84+
get => mDefaultItemCaptureLayout;
85+
set { SetProperty(ref mDefaultItemCaptureLayout, value); }
86+
}
87+
7488
// ---- Reload / Activate ------------------------------------------
7589

7690
bool mbReloadInProgress;

0 commit comments

Comments
 (0)