Skip to content
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<Int32 name="Unknown3" default="-1" binary="NoGeneration" />
</Fields>
</Object>
<Object name="FunctionConditionData" objType="Subrecord" baseClass="ConditionData">
<Object name="FunctionConditionData" objType="Subrecord" baseClass="ConditionData" generateConditionData="false">
<Fields>
<Enum name="Function" enumName="Condition.Function" byteLength="2" />
<UInt16 name="Unknown2" />
Expand All @@ -41,7 +41,7 @@
<String name="ParameterTwoString" binary="NoGeneration" nullable="True" />
</Fields>
</Object>
<Object name="GetEventData" objType="Subrecord" baseClass="ConditionData">
<Object name="GetEventData" objType="Subrecord" baseClass="ConditionData" generateConditionData="false">
<Fields>
<!-- ToDo change to enum -->
<UInt16 name="EventFunction" />
Expand Down
75 changes: 75 additions & 0 deletions Mutagen.Bethesda.Generation/Modules/Plugin/ConditionDataModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using Loqui.Generation;
using Noggog;
using Noggog.StructuredStrings;
using Noggog.StructuredStrings.CSharp;
using ObjectType = Mutagen.Bethesda.Plugins.Meta.ObjectType;
namespace Mutagen.Bethesda.Generation.Modules.Plugin;

public class ConditionDataModule : GenerationModule
{
public override Task PreLoad(ObjectGeneration obj)
{
var data = obj.GetObjectData();
data.GenerateConditionData = obj.Node.GetAttribute("generateConditionData", defaultVal: true);
return base.PreLoad(obj);
}

public override async Task GenerateInClass(ObjectGeneration obj, StructuredStringBuilder sb)
{
await base.GenerateInClass(obj, sb);

if (obj.Abstract) return;
if (obj.GetObjectType() != ObjectType.Subrecord) return;
if (obj.BaseClass is null) return;
if (obj.BaseClassName != "ConditionData") return;
if (obj.GetObjectData().GenerateConditionData == false) return;

var i = 1;
foreach (var field in obj.Fields)
{
if (i > 2) break;
if (field.Name.Contains("UnusedStringParameter")) continue;
var isUnusedParameter = field.Name.Contains("Unused");

// Parameter property
sb.AppendLine($"public override object? Parameter{i}");
using (sb.CurlyBrace())
{
if (isUnusedParameter)
{
sb.AppendLine("get => null;");
sb.AppendLine("set");
using (sb.CurlyBrace())
{
sb.AppendLine();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting it here too, but we shuld check if it's not null and throw argument exception if it's not null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a similar design decision as throwing the other exception. Should be both or none.

}
}
else
{
var name = field.Name;
var setterTypeName = field.TypeName(false);
sb.AppendLine($"get => {name};");
sb.AppendLine($"set => {name} = (value is {setterTypeName} v ? v : throw new ArgumentException());");
}

}

// ParameterType property
sb.AppendLine($"public override Type? Parameter{i}Type");
using (sb.CurlyBrace())
{
if (isUnusedParameter)
{
sb.AppendLine("get => null;");
}
else
{
var name = field.TypeName(true);
sb.AppendLine($"get => typeof({name});");
}
}

i++;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class MutagenObjData
public RecordCollection AdditionalContainedRecordTypes = new();
public string TriggeringSource;
public bool CustomBinary;
public bool GenerateConditionData;
public BinaryGenerationType BinaryOverlay = BinaryGenerationType.Normal;
public bool BinaryOverlayGenerateCtor;
public CustomEnd CustomBinaryEnd;
Expand Down
1 change: 1 addition & 0 deletions Mutagen.Bethesda.Generation/Modules/Plugin/PluginModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public PluginModule()
SubModules.Add(new MajorRecordLinkEqualityModule());
SubModules.Add(new ImplicitsModule());
SubModules.Add(new BreakMarkingModule());
SubModules.Add(new ConditionDataModule());
SubModules.Add(new SubgroupsModule());
SubModules.Add(new CircularHandlingModule());
SubModules.Add(new PartialFormModule());
Expand Down
63 changes: 63 additions & 0 deletions Mutagen.Bethesda.Skyrim/Mutagen.Bethesda.Skyrim.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,69 @@
<Compile Include="Records\Common Subrecords\GetVATSValueActionConditionData.cs">
<DependentUpon>ConditionDatas.xml</DependentUpon>
</Compile>
<Compile Include="Records\Common Subrecords\GetVATSValueTargetConditionData.cs">
<DependentUpon>ConditionDatas.xml</DependentUpon>
</Compile>
<Compile Include="Records\Common Subrecords\GetVATSValueTargetOrListConditionData.cs">
<DependentUpon>ConditionDatas.xml</DependentUpon>
</Compile>
<Compile Include="Records\Common Subrecords\GetVATSValueTargetDistanceConditionData.cs">
<DependentUpon>ConditionDatas.xml</DependentUpon>
</Compile>
<Compile Include="Records\Common Subrecords\GetVATSValueCastingTypeConditionData.cs">
<DependentUpon>ConditionDatas.xml</DependentUpon>
</Compile>
<Compile Include="Records\Common Subrecords\GetVATSValueCripplePartConditionData.cs">
<DependentUpon>ConditionDatas.xml</DependentUpon>
</Compile>
<Compile Include="Records\Common Subrecords\GetVATSValueCriticalEffectConditionData.cs">
<DependentUpon>ConditionDatas.xml</DependentUpon>
</Compile>
<Compile Include="Records\Common Subrecords\GetVATSValueCriticalEffectOrListConditionData.cs">
<DependentUpon>ConditionDatas.xml</DependentUpon>
</Compile>
<Compile Include="Records\Common Subrecords\GetVATSValueDeliveryTypeConditionData.cs">
<DependentUpon>ConditionDatas.xml</DependentUpon>
</Compile>
<Compile Include="Records\Common Subrecords\GetVATSValueDismemberPartConditionData.cs">
<DependentUpon>ConditionDatas.xml</DependentUpon>
</Compile>
<Compile Include="Records\Common Subrecords\GetVATSValueExplodePartConditionData.cs">
<DependentUpon>ConditionDatas.xml</DependentUpon>
</Compile>
<Compile Include="Records\Common Subrecords\GetVATSValueIsCriticalConditionData.cs">
<DependentUpon>ConditionDatas.xml</DependentUpon>
</Compile>
<Compile Include="Records\Common Subrecords\GetVATSValueIsFatalConditionData.cs">
<DependentUpon>ConditionDatas.xml</DependentUpon>
</Compile>
<Compile Include="Records\Common Subrecords\GetVATSValueIsParalyzingPalmConditionData.cs">
<DependentUpon>ConditionDatas.xml</DependentUpon>
</Compile>
<Compile Include="Records\Common Subrecords\GetVATSValueIsStrangerConditionData.cs">
<DependentUpon>ConditionDatas.xml</DependentUpon>
</Compile>
<Compile Include="Records\Common Subrecords\GetVATSValueIsSuccessConditionData.cs">
<DependentUpon>ConditionDatas.xml</DependentUpon>
</Compile>
<Compile Include="Records\Common Subrecords\GetVATSValueProjectileTypeConditionData.cs">
<DependentUpon>ConditionDatas.xml</DependentUpon>
</Compile>
<Compile Include="Records\Common Subrecords\GetVATSValueTargetPartConditionData.cs">
<DependentUpon>ConditionDatas.xml</DependentUpon>
</Compile>
<Compile Include="Records\Common Subrecords\GetVATSValueUnknownConditionData.cs">
<DependentUpon>ConditionDatas.xml</DependentUpon>
</Compile>
<Compile Include="Records\Common Subrecords\GetVATSValueWeaponConditionData.cs">
<DependentUpon>ConditionDatas.xml</DependentUpon>
</Compile>
<Compile Include="Records\Common Subrecords\GetVATSValueWeaponOrListConditionData.cs">
<DependentUpon>ConditionDatas.xml</DependentUpon>
</Compile>
<Compile Include="Records\Common Subrecords\GetVATSValueWeaponTypeConditionData.cs">
<DependentUpon>ConditionDatas.xml</DependentUpon>
</Compile>
<Compile Include="Records\Common Subrecords\GetVelocityConditionData.cs">
<DependentUpon>ConditionDatas.xml</DependentUpon>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ public Mask(TItem initialValue)
public Mask(
TItem RunOnType,
TItem Reference,
TItem Unknown3,
TItem RunOnTypeIndex,
TItem UseAliases,
TItem UsePackageData,
TItem FirstUnusedStringParameter,
TItem SecondUnusedStringParameter)
: base(
RunOnType: RunOnType,
Reference: Reference,
Unknown3: Unknown3,
RunOnTypeIndex: RunOnTypeIndex,
UseAliases: UseAliases,
UsePackageData: UsePackageData)
{
Expand Down Expand Up @@ -598,7 +598,7 @@ internal enum AGetVATSValueConditionData_FieldIndex
{
RunOnType = 0,
Reference = 1,
Unknown3 = 2,
RunOnTypeIndex = 2,
UseAliases = 3,
UsePackageData = 4,
FirstUnusedStringParameter = 5,
Expand Down Expand Up @@ -821,7 +821,7 @@ public static AGetVATSValueConditionData_FieldIndex ConvertFieldIndex(ConditionD
return (AGetVATSValueConditionData_FieldIndex)((int)index);
case ConditionData_FieldIndex.Reference:
return (AGetVATSValueConditionData_FieldIndex)((int)index);
case ConditionData_FieldIndex.Unknown3:
case ConditionData_FieldIndex.RunOnTypeIndex:
return (AGetVATSValueConditionData_FieldIndex)((int)index);
case ConditionData_FieldIndex.UseAliases:
return (AGetVATSValueConditionData_FieldIndex)((int)index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public Mask(TItem initialValue)
public Mask(
TItem RunOnType,
TItem Reference,
TItem Unknown3,
TItem RunOnTypeIndex,
TItem UseAliases,
TItem UsePackageData,
TItem FirstUnusedIntParameter,
Expand All @@ -128,7 +128,7 @@ public Mask(
: base(
RunOnType: RunOnType,
Reference: Reference,
Unknown3: Unknown3,
RunOnTypeIndex: RunOnTypeIndex,
UseAliases: UseAliases,
UsePackageData: UsePackageData)
{
Expand Down Expand Up @@ -454,6 +454,33 @@ public static implicit operator TranslationMask(bool defaultOn)
}
#endregion

#region Mutagen
public override object? Parameter1
{
get => null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting null here feels fine. Feels a bit odd to just do nothing in the set. Gut is telling me we should throw if the given value is not null (similar to how we throw if the type is wrong for used parameters)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was worrying this could lead to strange behavior when you are working on generic conditions. Setting a property might not be intuitively something where you expect it throws when doing it? What do you think? You can of course just add a try catch block when you get any issues with this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, not a great way either route... but I think that's just the price of writing generic API that is trying to handle everything.

The downside of the current setup is that users will expect that if they set the field and it "went through", that something was modified. But instead, it didnt modify anything, and was just a "silent error" of sorts.

The throw at least is something the user can detect/handle, vs the silent error just leads to more of an undetectable paranoia, imo

set
{

}
}
public override Type? Parameter1Type
{
get => null;
}
public override object? Parameter2
{
get => null;
set
{

}
}
public override Type? Parameter2Type
{
get => null;
}
#endregion

#region Binary Translation
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
protected override object BinaryWriteTranslator => CanFlyHereConditionDataBinaryWriteTranslation.Instance;
Expand Down Expand Up @@ -677,7 +704,7 @@ internal enum CanFlyHereConditionData_FieldIndex
{
RunOnType = 0,
Reference = 1,
Unknown3 = 2,
RunOnTypeIndex = 2,
UseAliases = 3,
UsePackageData = 4,
FirstUnusedIntParameter = 5,
Expand Down Expand Up @@ -914,7 +941,7 @@ public static CanFlyHereConditionData_FieldIndex ConvertFieldIndex(ConditionData
return (CanFlyHereConditionData_FieldIndex)((int)index);
case ConditionData_FieldIndex.Reference:
return (CanFlyHereConditionData_FieldIndex)((int)index);
case ConditionData_FieldIndex.Unknown3:
case ConditionData_FieldIndex.RunOnTypeIndex:
return (CanFlyHereConditionData_FieldIndex)((int)index);
case ConditionData_FieldIndex.UseAliases:
return (CanFlyHereConditionData_FieldIndex)((int)index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public Mask(TItem initialValue)
public Mask(
TItem RunOnType,
TItem Reference,
TItem Unknown3,
TItem RunOnTypeIndex,
TItem UseAliases,
TItem UsePackageData,
TItem FirstUnusedIntParameter,
Expand All @@ -128,7 +128,7 @@ public Mask(
: base(
RunOnType: RunOnType,
Reference: Reference,
Unknown3: Unknown3,
RunOnTypeIndex: RunOnTypeIndex,
UseAliases: UseAliases,
UsePackageData: UsePackageData)
{
Expand Down Expand Up @@ -454,6 +454,33 @@ public static implicit operator TranslationMask(bool defaultOn)
}
#endregion

#region Mutagen
public override object? Parameter1
{
get => null;
set
{

}
}
public override Type? Parameter1Type
{
get => null;
}
public override object? Parameter2
{
get => null;
set
{

}
}
public override Type? Parameter2Type
{
get => null;
}
#endregion

#region Binary Translation
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
protected override object BinaryWriteTranslator => CanHaveFlamesConditionDataBinaryWriteTranslation.Instance;
Expand Down Expand Up @@ -677,7 +704,7 @@ internal enum CanHaveFlamesConditionData_FieldIndex
{
RunOnType = 0,
Reference = 1,
Unknown3 = 2,
RunOnTypeIndex = 2,
UseAliases = 3,
UsePackageData = 4,
FirstUnusedIntParameter = 5,
Expand Down Expand Up @@ -914,7 +941,7 @@ public static CanHaveFlamesConditionData_FieldIndex ConvertFieldIndex(ConditionD
return (CanHaveFlamesConditionData_FieldIndex)((int)index);
case ConditionData_FieldIndex.Reference:
return (CanHaveFlamesConditionData_FieldIndex)((int)index);
case ConditionData_FieldIndex.Unknown3:
case ConditionData_FieldIndex.RunOnTypeIndex:
return (CanHaveFlamesConditionData_FieldIndex)((int)index);
case ConditionData_FieldIndex.UseAliases:
return (CanHaveFlamesConditionData_FieldIndex)((int)index);
Expand Down
Loading
Loading