Skip to content

Commit

Permalink
Again fixes (#250)
Browse files Browse the repository at this point in the history
* Fix wiki json autogen + entity autogen (#1441)

(cherry picked from commit 68201fc1e806dad35d6f881ac61f8e9613fbd20d)

* [Fix?] Json generation for wiki works again (#1504)

(cherry picked from commit 65cfa17d9c2022297aef84ccd81b8377a4d831c9)

* fixes

* [Wiki] Update recipes generator regex (#1649)

(cherry picked from commit 59bdeb15ff681ab8c0d4f9dfc7441c210193e30f)

* [Wiki] Grindable recipes json generator fix (#1702)

(cherry picked from commit e4d82af829247bc4c28790c2730285b10d4d9880)

* Update update-wiki.yml (#1724)

(cherry picked from commit 3207d6f19cd5f8ba9654d343084937ccf35e8fca)

* Add more reaction info to wiki json (#2064)

(cherry picked from commit 6625e91ee19a132349d1c8e06d0fa7466ae7b0ee)

* Add wiki json about reagent health/damage (#2073)

(cherry picked from commit e0012a76e33d044b861d61b16da4094b49480e62)

* вики

* фиксы

---------

Co-authored-by: mhamster <[email protected]>
Co-authored-by: KrasnoshchekovPavel <[email protected]>
  • Loading branch information
3 people authored Oct 6, 2024
1 parent 4390d40 commit 9b33232
Show file tree
Hide file tree
Showing 29 changed files with 974 additions and 11 deletions.
92 changes: 92 additions & 0 deletions .github/workflows/update-wiki.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Update Wiki

on:
workflow_dispatch:
push:
branches: [ master, jsondump ]
paths:
- '.github/workflows/update-wiki.yml'
- 'Content.Shared/Chemistry/**.cs'
- 'Content.Server/Chemistry/**.cs'
- 'Content.Server/GuideGenerator/**.cs'
- 'Content.Server/Corvax/GuideGenerator/**.cs'
- 'Resources/Prototypes/Reagents/**.yml'
- 'Resources/Prototypes/Chemistry/**.yml'
- 'Resources/Prototypes/Recipes/Reactions/**.yml'
- 'RobustToolbox/'

jobs:
update-wiki:
name: Build and Publish JSON blobs to wiki
runs-on: ubuntu-latest

steps:
- name: Checkout Master
uses: actions/[email protected]

- name: Setup Submodule
run: |
git submodule update --init --recursive
- name: Pull Engine Updates
uses: space-wizards/[email protected]

- name: Update Engine Submodules
run: |
cd RobustToolbox/
git submodule update --init --recursive
- name: Setup .NET Core
uses: actions/[email protected]
with:
dotnet-version: 7.0.x

- name: Install Dependencies
run: dotnet restore

- name: Build Project
run: dotnet build --configuration Release --no-restore /p:WarningsAsErrors=nullable /m

- name: Generate JSON blobs for prototypes
run: dotnet ./bin/Content.Server/Content.Server.dll --cvar autogen.destination_file=prototypes.json
continue-on-error: true

- name: Upload chem_prototypes.json to wiki
uses: jtmullen/[email protected]
with:
wiki_text_file: ./bin/Content.Server/data/chem_prototypes.json
edit_summary: Update chem_prototypes.json via GitHub Actions
page_name: "${{ secrets.WIKI_PAGE_ROOT }}/chem_prototypes.json"
api_url: ${{ secrets.WIKI_ROOT_URL }}/api.php
username: ${{ secrets.WIKI_BOT_USER }}
password: ${{ secrets.WIKI_BOT_PASS }}

- name: Upload react_prototypes.json to wiki
uses: jtmullen/[email protected]
with:
wiki_text_file: ./bin/Content.Server/data/react_prototypes.json
edit_summary: Update react_prototypes.json via GitHub Actions
page_name: "${{ secrets.WIKI_PAGE_ROOT }}/react_prototypes.json"
api_url: ${{ secrets.WIKI_ROOT_URL }}/api.php
username: ${{ secrets.WIKI_BOT_USER }}
password: ${{ secrets.WIKI_BOT_PASS }}

- name: Upload entity_prototypes.json to wiki
uses: jtmullen/[email protected]
with:
wiki_text_file: ./bin/Content.Server/data/entity_prototypes.json
edit_summary: Update entity_prototypes.json via GitHub Actions
page_name: "${{ secrets.WIKI_PAGE_ROOT }}/entity_prototypes.json"
api_url: ${{ secrets.WIKI_ROOT_URL }}/api.php
username: ${{ secrets.WIKI_BOT_USER }}
password: ${{ secrets.WIKI_BOT_PASS }}

- name: Upload mealrecipes_prototypes.json to wiki
uses: jtmullen/[email protected]
with:
wiki_text_file: ./bin/Content.Server/data/mealrecipes_prototypes.json
edit_summary: Update mealrecipes_prototypes.json via GitHub Actions
page_name: "${{ secrets.WIKI_PAGE_ROOT }}/mealrecipes_prototypes.json"
api_url: ${{ secrets.WIKI_ROOT_URL }}/api.php
username: ${{ secrets.WIKI_BOT_USER }}
password: ${{ secrets.WIKI_BOT_PASS }}
23 changes: 23 additions & 0 deletions Content.Server/Corvax/GuideGenerator/EntityEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Text.Json.Serialization;
using Robust.Shared.Prototypes;

namespace Content.Server.GuideGenerator;

public sealed class EntityEntry
{
[JsonPropertyName("id")]
public string Id { get; }

[JsonPropertyName("name")]
public string Name { get; }

[JsonPropertyName("desc")]
public string Description { get; }

public EntityEntry(EntityPrototype proto)
{
Id = proto.ID;
Name = TextTools.TextTools.CapitalizeString(proto.Name); // Corvax-Wiki
Description = proto.Description;
}
}
27 changes: 27 additions & 0 deletions Content.Server/Corvax/GuideGenerator/EntityJsonGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.IO;
using System.Linq;
using System.Text.Json;
using Robust.Shared.Prototypes;

namespace Content.Server.GuideGenerator;

public sealed class EntityJsonGenerator
{
public static void PublishJson(StreamWriter file)
{
var prototype = IoCManager.Resolve<IPrototypeManager>();
var prototypes =
prototype
.EnumeratePrototypes<EntityPrototype>()
.Where(x => !x.Abstract)
.Select(x => new EntityEntry(x))
.ToDictionary(x => x.Id, x => x);

var serializeOptions = new JsonSerializerOptions
{
WriteIndented = true,
};

file.Write(JsonSerializer.Serialize(prototypes, serializeOptions));
}
}
74 changes: 74 additions & 0 deletions Content.Server/Corvax/GuideGenerator/GrindRecipeEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System.Text.Json.Serialization;
using Robust.Shared.Prototypes;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Chemistry.Components.SolutionManager;
using Content.Shared.Kitchen.Components;

namespace Content.Server.GuideGenerator;

public sealed class GrindRecipeEntry
{
/// <summary>
/// Id of grindable item
/// </summary>
[JsonPropertyName("id")]
public string Id { get; }

/// <summary>
/// Human-readable name of recipe.
/// Should automatically be localized by default
/// </summary>
[JsonPropertyName("name")]
public string Name { get; }

/// <summary>
/// Type of recipe
/// </summary>
[JsonPropertyName("type")]
public string Type { get; }

/// <summary>
/// Item that will be grinded into something
/// </summary>
[JsonPropertyName("input")]
public string Input { get; }

/// <summary>
/// Dictionary of reagents that entity contains; aka "Recipe Result"
/// </summary>
[JsonPropertyName("result")]
public Dictionary<string, int>? Result { get; } = new Dictionary<string, int>();


public GrindRecipeEntry(EntityPrototype proto)
{
Id = proto.ID;
Name = TextTools.TextTools.CapitalizeString(proto.Name);
Type = "grindableRecipes";
Input = proto.ID;
var foodSolutionName = "food"; // default to food because everything in prototypes defaults to "food"

// Now, to become a recipe, entity must:
// A) Have "Extractable" component on it.
// B) Have "SolutionContainerManager" component on it.
// C) Have "GrindableSolution" declared in "SolutionContainerManager" component.
// D) Have solution with name declared in "SolutionContainerManager.GrindableSolution" inside its "SolutionContainerManager" component.
// F) Have "Food" in its name (see Content.Server/Corvax/GuideGenerator/MealsRecipesJsonGenerator.cs)
if (proto.Components.TryGetComponent("Extractable", out var extractableComp) && proto.Components.TryGetComponent("SolutionContainerManager", out var solutionCompRaw))
{
var extractable = (ExtractableComponent) extractableComp;
var solutionComp = (SolutionContainerManagerComponent) solutionCompRaw;
foodSolutionName = extractable.GrindableSolution;

if (solutionComp.Solutions != null && foodSolutionName != null)
{
foreach (ReagentQuantity reagent in solutionComp.Solutions[(string) foodSolutionName].Contents)
{
Result[reagent.Reagent.Prototype] = reagent.Quantity.Int();
}
}
else
Result = null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using Content.Shared.Chemistry.Reagent;
using Robust.Shared.Prototypes;
using System.IO;
using System.Linq;
using System.Text.Json;
using Content.Server.Chemistry.ReagentEffects;

namespace Content.Server.Corvax.GuideGenerator;
public sealed class HealthChangeReagentsJsonGenerator
{
public static void PublishJson(StreamWriter file)
{
var prototype = IoCManager.Resolve<IPrototypeManager>();

Dictionary<string, Dictionary<string, Dictionary<string, float>>> healthChangeReagents = new();

// Сбор данных
foreach (var reagent in prototype.EnumeratePrototypes<ReagentPrototype>())
{
if (reagent.Metabolisms is null) continue;

foreach (var metabolism in reagent.Metabolisms)
{
foreach (HealthChange effect in metabolism.Value.Effects.Where(x => x is HealthChange))
{
foreach (var damage in effect.Damage.DamageDict)
{
var damageType = damage.Key;
var damageChangeType = damage.Value.Float() < 0 ? "health" : "damage";

if (!healthChangeReagents.ContainsKey(damageType))
{
healthChangeReagents.Add(damageType, new());
}

if (!healthChangeReagents[damageType].ContainsKey(damageChangeType))
{
healthChangeReagents[damageType].Add(damageChangeType, new());
}

// Берем максимальный показатель (один реагент может наносить разный урон при разных условиях)
var damageChangeValueAbs = Math.Abs(damage.Value.Float() / metabolism.Value.MetabolismRate.Float()); // вычисляем показатель за 1 ед. вещества, а не 1 сек. нахождения я в организме.
if (healthChangeReagents[damageType][damageChangeType].TryGetValue(reagent.ID, out var previousValue))
{
healthChangeReagents[damageType][damageChangeType][reagent.ID] = Math.Max(previousValue, damageChangeValueAbs);
}
else healthChangeReagents[damageType][damageChangeType].Add(reagent.ID, damageChangeValueAbs);
}
}
}
}

// Сортировка
Dictionary<string, Dictionary<string, List<string>>> healthChangeReagentsSorted = new();

foreach (var damageType in healthChangeReagents)
{
foreach (var damageChangeType in damageType.Value)
{
foreach (var reagent in damageChangeType.Value)
{
if (!healthChangeReagentsSorted.ContainsKey(damageType.Key))
{
healthChangeReagentsSorted.Add(damageType.Key, new());
}

if (!healthChangeReagentsSorted[damageType.Key].ContainsKey(damageChangeType.Key))
{
healthChangeReagentsSorted[damageType.Key].Add(damageChangeType.Key, new());
}

healthChangeReagentsSorted[damageType.Key][damageChangeType.Key].Add(reagent.Key);

}

healthChangeReagentsSorted[damageType.Key][damageChangeType.Key].Sort(Comparer<string>.Create((s1, s2) =>
-healthChangeReagents[damageType.Key][damageChangeType.Key][s1].CompareTo(healthChangeReagents[damageType.Key][damageChangeType.Key][s2])));
}
}



var serializeOptions = new JsonSerializerOptions
{
WriteIndented = true,
NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals
};

file.Write(JsonSerializer.Serialize(healthChangeReagentsSorted, serializeOptions));
}
}

Loading

0 comments on commit 9b33232

Please sign in to comment.