Skip to content

Commit

Permalink
fix: optional system text json, disabled by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Chillu1 committed Aug 3, 2024
1 parent 2d63442 commit 3b0ef58
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 10 deletions.
7 changes: 1 addition & 6 deletions ModiBuff/ModiBuff.Tests/ModiBuff.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@

<PropertyGroup>
<Nullable>disable</Nullable>

<IsPackable>false</IsPackable>

<LangVersion>7.2</LangVersion>

<OutputType>Library</OutputType>

<TargetFramework>net6.0</TargetFramework>

<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>

Expand All @@ -27,4 +22,4 @@
<ProjectReference Include="..\ModiBuff\ModiBuff.csproj"/>
</ItemGroup>

</Project>
</Project>
45 changes: 45 additions & 0 deletions ModiBuff/ModiBuff.Tests/SaveLoadRecipeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ private void SaveLoadStateAndSetup(ModifierRecipes saveRecipes)
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveRecipeLoad()
{
var saveRecipes = new ModifierRecipes(IdManager, EffectTypeIdManager);
Expand All @@ -46,6 +49,9 @@ public void SaveRecipeLoad()
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveNamesRecipeLoad()
{
const string name = "InitDamage";
Expand All @@ -66,6 +72,9 @@ public void SaveNamesRecipeLoad()
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveStackRecipeLoad()
{
var saveRecipes = new ModifierRecipes(IdManager, EffectTypeIdManager);
Expand All @@ -83,6 +92,9 @@ public void SaveStackRecipeLoad()
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveAddDamageRecipeLoad()
{
var saveRecipes = new ModifierRecipes(IdManager, EffectTypeIdManager);
Expand All @@ -96,6 +108,9 @@ public void SaveAddDamageRecipeLoad()
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveIntervalRecipeLoad()
{
var saveRecipes = new ModifierRecipes(IdManager, EffectTypeIdManager);
Expand All @@ -111,6 +126,9 @@ public void SaveIntervalRecipeLoad()
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveModifierActionRecipeLoad()
{
var saveRecipes = new ModifierRecipes(IdManager, EffectTypeIdManager);
Expand All @@ -131,6 +149,9 @@ public void SaveModifierActionRecipeLoad()
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveRemoveRecipeLoad()
{
var saveRecipes = new ModifierRecipes(IdManager, EffectTypeIdManager);
Expand All @@ -147,6 +168,9 @@ public void SaveRemoveRecipeLoad()
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveRefreshIntervalRecipeLoad()
{
var saveRecipes = new ModifierRecipes(IdManager, EffectTypeIdManager);
Expand All @@ -165,6 +189,9 @@ public void SaveRefreshIntervalRecipeLoad()
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveRefreshDurationRecipeLoad()
{
var saveRecipes = new ModifierRecipes(IdManager, EffectTypeIdManager);
Expand All @@ -184,6 +211,9 @@ public void SaveRefreshDurationRecipeLoad()
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveRemoveStackRecipeLoad()
{
var saveRecipes = new ModifierRecipes(IdManager, EffectTypeIdManager);
Expand All @@ -201,6 +231,9 @@ public void SaveRemoveStackRecipeLoad()
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveRemoveCallbackUnitRecipeLoad()
{
var saveRecipes = new ModifierRecipes(IdManager, EffectTypeIdManager);
Expand All @@ -219,6 +252,9 @@ public void SaveRemoveCallbackUnitRecipeLoad()
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveDispelRecipeLoad()
{
var saveRecipes = new ModifierRecipes(IdManager, EffectTypeIdManager);
Expand All @@ -240,6 +276,9 @@ public void SaveDispelRecipeLoad()
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveTagRecipeLoad()
{
var saveRecipes = new ModifierRecipes(IdManager, EffectTypeIdManager);
Expand All @@ -254,6 +293,9 @@ public void SaveTagRecipeLoad()
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveRemoveTagRecipeLoad()
{
var saveRecipes = new ModifierRecipes(IdManager, EffectTypeIdManager);
Expand All @@ -268,6 +310,9 @@ public void SaveRemoveTagRecipeLoad()
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveSetTagRecipeLoad()
{
var saveRecipes = new ModifierRecipes(IdManager, EffectTypeIdManager);
Expand Down
46 changes: 46 additions & 0 deletions ModiBuff/ModiBuff.Tests/SaveLoadTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ private void LoadGameState(string gameStateFile, out Unit[] loadedUnits)
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveUnitLoad()
{
AddRecipe("AddDamageExtraState")
Expand All @@ -86,6 +89,9 @@ public void SaveUnitLoad()
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveEffectCooldownCheckLoad()
{
AddRecipe("AddDamageExtraState")
Expand All @@ -111,6 +117,9 @@ public void SaveEffectCooldownCheckLoad()
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveLoadStatusEffect()
{
AddRecipe("InitStun")
Expand All @@ -133,6 +142,9 @@ public void SaveLoadStatusEffect()
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveLoadEventCallbackState()
{
AddRecipe("InitCallbackState")
Expand Down Expand Up @@ -161,6 +173,9 @@ public void SaveLoadEventCallbackState()
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveLoadApplierState()
{
AddRecipe("InitDamageChecks")
Expand All @@ -184,6 +199,9 @@ public void SaveLoadApplierState()
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveLoadTargetId()
{
AddRecipe("DoT")
Expand All @@ -209,6 +227,9 @@ public void SaveLoadTargetId()
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveNewModifierIdLoad()
{
AddRecipe("DoT")
Expand All @@ -234,6 +255,9 @@ public void SaveNewModifierIdLoad()
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveNewModifierApplierIdLoad()
{
AddRecipe("DoT")
Expand Down Expand Up @@ -266,6 +290,9 @@ public void SaveNewModifierApplierIdLoad()
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveNewEffectIdLoad()
{
AddEffect("InitDamage", new DamageEffect(5));
Expand All @@ -288,6 +315,9 @@ public void SaveNewEffectIdLoad()
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveModifierNewEffectLoad()
{
AddRecipe("InitHeal")
Expand Down Expand Up @@ -338,6 +368,9 @@ public void SaveStatusEffectGenIdLoad()
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveCallbackLocalVarState()
{
AddRecipe("InitTakeFiveDamageOnTenDamageTaken")
Expand Down Expand Up @@ -372,13 +405,18 @@ public void SaveCallbackLocalVarState()
[Test]
public void SavePoisonEffectLoad()
{
#if !MODIBUFF_SYSTEM_TEXT_JSON
Setup();
Assert.Ignore("MODIBUFF_SYSTEM_TEXT_JSON not defined. Skipping test.");
#else
SerializationExtensions.AddCustomValueType<IReadOnlyDictionary<int, int>>(element =>
{
var dictionary = new Dictionary<int, int>();
foreach (var kvp in element.EnumerateObject())
dictionary.Add(int.Parse(kvp.Name), kvp.Value.GetInt32());
return dictionary;
});
#endif

AddRecipe(CentralizedCustomLogicTests.PoisonRecipe);
AddRecipe("PoisonThorns")
Expand Down Expand Up @@ -418,6 +456,10 @@ public void SavePoisonEffectLoad()
[Test]
public void SaveCallbackLocalTupleVarState()
{
#if !MODIBUFF_SYSTEM_TEXT_JSON
Setup();
Assert.Ignore("MODIBUFF_SYSTEM_TEXT_JSON not defined. Skipping test.");
#else
SerializationExtensions.AddCustomValueType<Tuple<float, float>>(element =>
{
float[] array = new float[2];
Expand All @@ -426,6 +468,7 @@ public void SaveCallbackLocalTupleVarState()
array[i++] = kvp.Value.GetSingle();
return new Tuple<float, float>(array[0], array[1]);
});
#endif

AddRecipe("InitTakeFiveDamageOnTenDamageTaken")
.Callback(CallbackType.CurrentHealthChanged, () =>
Expand Down Expand Up @@ -473,6 +516,9 @@ public void SaveCallbackLocalTupleVarState()
}

[Test]
#if !MODIBUFF_SYSTEM_TEXT_JSON
[Ignore("MODIBUFF_SYSTEM_TEXT_JSON not set. Skipping test")]
#endif
public void SaveCallbackEffectLocalFloatVarState()
{
AddRecipe("StunnedFourTimesDispelAllStatusEffects")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public void LoadState<TUnitCallback>(SaveData saveData)
}
}

#if MODIBUFF_SYSTEM_TEXT_JSON
(IEffect, EffectOn) HandleEffect(SaveInstruction instruction)
{
var values = ((System.Text.Json.JsonElement)instruction.Values).EnumerateObject();
Expand Down Expand Up @@ -189,6 +190,7 @@ public void LoadState<TUnitCallback>(SaveData saveData)

return ((IEffect)constructor.Invoke(effectStates), effectOn.Value);
}
#endif
}

public record SaveInstruction
Expand All @@ -206,8 +208,9 @@ public SaveInstruction(object values, int instructionId)
Values = values;
InstructionId = instructionId;
}

#if MODIBUFF_SYSTEM_TEXT_JSON
public object[] GetValues(params Type[] types) => ((System.Text.Json.JsonElement)Values).GetValues(types);
#endif

public sealed record Initialize : SaveInstruction
{
Expand Down
5 changes: 2 additions & 3 deletions ModiBuff/ModiBuff/ModiBuff.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants>TRACE MODIBUFF_SYSTEM_TEXT_JSON</DefineConstants>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>TRACE MODIBUFF_SYSTEM_TEXT_JSON</DefineConstants>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0"/>
<PackageReference Include="System.Text.Json" Version="7.0.3"/>
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 3b0ef58

Please sign in to comment.