Skip to content

Commit

Permalink
Unsupported Mod Support +semver: minor
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyTech6 committed Dec 9, 2024
1 parent 9d20cf8 commit f56d67e
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 8 deletions.
Binary file added .github/images/screenshots/banned.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/screenshots/generic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
`latest`
- Added support for "Generic" JSONs

`0.1.15`
- Added a new Mod: CrimsonBanned
- Support for CrimsonBanned's messages.json
- Icons for JSON Rising
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@ A simple GUI editor for JSON files for V Rising mods made with [ASP.NET Core](ht
> If you're unsure about the safety of this app, I would suggest running it through a service like [VirusTotal](https://www.virustotal.com).
## Supported Mods
- Generic JSONs
Rising will attempt to procedurally generate a GUI for any unknown JSON files given to it. This is useful for mods that don't have official support for JSON Rising.
_[BloodyEncounters/Generic screenshot](https://thunderstore.io/c/v-rising/p/Trodi/BloodyEncounters/)_
![GenericScreenshhot](https://raw.githubusercontent.com/CrimsonMods/JSONRising/master/.github/images/screenshots/generic.png)

- [CrimsonChatFilter](https://thunderstore.io/c/v-rising/p/skytech6/CrimsonChatFilter/)

- [CrimsonBanned](https://thunderstore.io/c/v-rising/p/skytech6/CrimsonBanned/)
_CrimsonBanned screenshot_
![CrimsonBannedScreenshot](https://raw.githubusercontent.com/CrimsonMods/JSONRising/master/.github/images/screenshots/banned.png)

## Support

Want to support my V Rising Mod development?
Expand Down
82 changes: 76 additions & 6 deletions src/Components/DynamicJsonEditor.razor
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,20 @@
else if (item.Value is List<object> list)
{
builder.OpenElement(7, "div");
builder.AddAttribute(8, "class", "array-items");
foreach (var listItem in list)
builder.AddAttribute(8, "class", "array-container");

// Add array controls
builder.OpenElement(20, "button");
builder.AddAttribute(21, "class", "array-button");
builder.AddAttribute(22, "onclick", EventCallback.Factory.Create(this, () => AddArrayItem(item.Key)));
builder.AddContent(23, "Add Item");
builder.CloseElement();

foreach (var (listItem, index) in list.Select((value, i) => (value, i)))
{
builder.OpenElement(24, "div");
builder.AddAttribute(25, "class", "array-item");

if (listItem is Dictionary<string, object> dictItem)
{
builder.AddContent(9, RenderJsonContent(dictItem));
Expand All @@ -52,6 +63,15 @@
builder.AddAttribute(12, "value", listItem?.ToString());
builder.CloseElement();
}

// Remove button for each item
builder.OpenElement(26, "button");
builder.AddAttribute(27, "class", "remove-button");
builder.AddAttribute(28, "onclick", EventCallback.Factory.Create(this, () => RemoveArrayItem(item.Key, index)));
builder.AddContent(29, "X");
builder.CloseElement();

builder.CloseElement();
}
builder.CloseElement();
}
Expand All @@ -63,10 +83,10 @@
builder.AddAttribute(16, "onchange", EventCallback.Factory.CreateBinder<string>(
this,
async value =>
{
JsonContent[item.Key] = value;
await OnValueChanged.InvokeAsync(JsonContent);
},
{
JsonContent[item.Key] = value;
await OnValueChanged.InvokeAsync(JsonContent);
},
item.Value?.ToString() ?? ""
));
builder.CloseElement();
Expand All @@ -84,6 +104,33 @@
_ => "text"
};
}

private async Task AddArrayItem(string key)
{
if (JsonContent[key] is List<object> list)
{
// Clone structure of first item if exists
if (list.Count > 0 && list[0] is Dictionary<string, object> template)
{
var newItem = new Dictionary<string, object>();
foreach (var kvp in template)
{
newItem[kvp.Key] = "";
}
list.Add(newItem);
}
await OnValueChanged.InvokeAsync(JsonContent);
}
}

private async Task RemoveArrayItem(string key, int index)
{
if (JsonContent[key] is List<object> list && index < list.Count)
{
list.RemoveAt(index);
await OnValueChanged.InvokeAsync(JsonContent);
}
}
}

<style>
Expand All @@ -98,6 +145,29 @@
border-left: 2px solid #ccc;
}
.array-container {
margin-left: 20px;
padding: 8px;
border-left: 2px solid #88c;
}
.array-item {
display: flex;
align-items: center;
margin: 4px 0;
}
.array-button {
margin: 8px 0;
padding: 4px 8px;
}
.remove-button {
margin-left: 8px;
padding: 2px 6px;
color: red;
}
.array-items {
margin-left: 20px;
padding: 8px;
Expand Down
5 changes: 4 additions & 1 deletion src/Components/ModCard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
<div class="mod-info">
<h3>@Mod.Name</h3>
<div class="mod-buttons">
<button class="thunderstore-btn" @onclick="OpenThunderstoreUrl">Thunderstore</button>
@if (!string.IsNullOrEmpty(Mod.ThunderstoreUrl))
{
<button class="thunderstore-btn" @onclick="OpenThunderstoreUrl">Thunderstore</button>
}
<button class="json-btn" @onclick="NavigateToJson">JSON(s)</button>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
{
Id = "unsupported",
Name = "Unsupported Mod",
IconUrl = "/images/mods/Banned.png",
IconUrl = "/images/icon_256.png",
IsDynamicMod = true
}
};
Expand Down

0 comments on commit f56d67e

Please sign in to comment.