Changes
Jump to navigation
Jump to search
← Older edit
Newer edit →
Modding:Modder Guide/APIs/Content
(view source)
Revision as of 02:47, 28 November 2022
564 bytes added
,
02:47, 28 November 2022
→Edit a dictionary
Line 284:
Line 284:
:: A reference to the loaded data. For example, here's how to add or replace a specific entry to the above example:
:: A reference to the loaded data. For example, here's how to add or replace a specific entry to the above example:
:: <syntaxhighlight lang="C#">
:: <syntaxhighlight lang="C#">
−
public
void Edit<
T
>(
IAssetData asset
)
+
−
{
+
/// <inheritdoc cref="IContentEvents.AssetRequested"/>
−
var editor = asset.AsDictionary<string, string>();
+
/// <param name="sender">The event sender.</param>
−
editor.Data["Key C"] = "Value C";
+
/// <param name="e">The event data.</param>
−
}
+
private
void
OnAssetRequested(object sender, AssetRequestedEventArgs e)
+
{
+
if (e.NameWithoutLocale.IsEquivalentTo("Location/Of/The/Asset"))
+
{
+
e.
Edit
(asset =>
+
{
+
var data = asset.AsDictionary
<
int, string
>(
).Data;
+
+
foreach ((int itemID, string itemData) in data
)
+
{
+
var editor = asset.AsDictionary<string, string>();
+
editor.Data["Key C"] = "Value C";
+
}
+
});
+
}
+
}
</syntaxhighlight>
</syntaxhighlight>
Atravita
528
edits
Navigation menu
Personal tools
Create account
Log in
Namespaces
Modding
Discussion
Variants
Views
Read
View source
View history
More
Search
Navigation
Main page
Recent changes
Admin noticeboard
Help Editing
Random page
Official Links
Official Site
Official Forums
Official Merchandise
Discord
Reddit
Tools
Upload file
Special pages
Printable version