Skip to content

Commit

Permalink
Add static TouchPortalOptions.ActionDataIdSeparator option to split a…
Browse files Browse the repository at this point in the history
…ction data IDs on a character and only store the last part in the dictionary key (eg. for IDs like <plugin>.<category>.<action>.<data1> one could split on the period and have much shorter/simpler key lookups).
  • Loading branch information
mpaperno committed Apr 18, 2022
1 parent ebe0b1a commit 89a81c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions TouchPortalSDK/Configuration/ActionDataConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ public override ActionData Read(ref Utf8JsonReader reader, Type typeToConvert, J
var ret = new ActionData();
var actionDataDicts = JsonSerializer.Deserialize<ActionData[]>(ref reader);
if (actionDataDicts != null){
foreach (var dict in actionDataDicts)
ret.TryAdd(dict.GetValueOrDefault("id"), dict.GetValueOrDefault("value"));
foreach (var dict in actionDataDicts) {
string id = dict.GetValueOrDefault("id", string.Empty);
if (TouchPortalOptions.ActionDataIdSeparator != '\0')
id = id.Split(TouchPortalOptions.ActionDataIdSeparator, StringSplitOptions.RemoveEmptyEntries)[^1];
ret.TryAdd(id, dict.GetValueOrDefault("value", string.Empty));
}
}
return ret;
}
Expand Down
3 changes: 2 additions & 1 deletion TouchPortalSDK/TouchPortalOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ public class TouchPortalOptions
{
public string IpAddress { get; set; } = "127.0.0.1";
public int Port { get; set; } = 12136;
public static char ActionDataIdSeparator { get; set; } = '\0';
}
}
}

0 comments on commit 89a81c4

Please sign in to comment.