Skip to content

Commit

Permalink
TerminalMenu nullability fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggog committed Aug 14, 2024
1 parent c2b3021 commit 933d3e9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@
<Object name="ATerminalMenuItemTarget" objType="Subrecord" abstract="true" />
<Object name="TerminalMenuItemDisplayText" objType="Subrecord" baseClass="ATerminalMenuItemTarget" >
<Fields>
<String name="DisplayText" translated="Normal" recordType="UNAM" nullable="False" />
<String name="DisplayText" translated="Normal" recordType="UNAM" />
</Fields>
</Object>
<Object name="TerminalMenuItemSubmenu" objType="Subrecord" baseClass="ATerminalMenuItemTarget" >
<Fields>
<FormLink name="Submenu" recordType="TNAM" refName="Terminal" nullable="False" />
<FormLink name="Submenu" recordType="TNAM" refName="Terminal" />
</Fields>
</Object>
<Object name="TerminalMenuItemDataslate" objType="Subrecord" baseClass="ATerminalMenuItemTarget" >
<Fields>
<FormLink name="Dataslate" recordType="BNAM" refName="Book" nullable="False" />
<FormLink name="Dataslate" recordType="BNAM" refName="Book" />
</Fields>
</Object>
<Object name="TerminalMenuItemReturnToDesktop" objType="Subrecord" baseClass="ATerminalMenuItemTarget" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,21 @@ public partial ParseResult TargetParseCustomParse(

private IATerminalMenuItemTargetGetter GetTarget()
{
var data = _targetLocation.HasValue ? _recordData.Slice(_targetLocation.Value) : Array.Empty<byte>();
switch (Type)
{
case TerminalMenuItemBinaryCreateTranslation.TypeOption.DisplayText:
return TerminalMenuItemDisplayTextBinaryOverlay.TerminalMenuItemDisplayTextFactory(_recordData.Slice(_targetLocation!.Value), _package);
return TerminalMenuItemDisplayTextBinaryOverlay.TerminalMenuItemDisplayTextFactory(data, _package);
case TerminalMenuItemBinaryCreateTranslation.TypeOption.SubmenuTerminalMenu:
return TerminalMenuItemSubmenuBinaryOverlay.TerminalMenuItemSubmenuFactory(_recordData.Slice(_targetLocation!.Value), _package);
return TerminalMenuItemSubmenuBinaryOverlay.TerminalMenuItemSubmenuFactory(data, _package);
case TerminalMenuItemBinaryCreateTranslation.TypeOption.ActionReturnToDesktop:
return new TerminalMenuItemReturnToDesktop();
case TerminalMenuItemBinaryCreateTranslation.TypeOption.ActionReturnToPrevious:
return new TerminalMenuItemReturnToPrevious();
case TerminalMenuItemBinaryCreateTranslation.TypeOption.ActionForceRedraw:
return new TerminalMenuItemForceRedraw();
case TerminalMenuItemBinaryCreateTranslation.TypeOption.DataSlateBOOK:
return TerminalMenuItemDataslateBinaryOverlay.TerminalMenuItemDataslateFactory(_recordData.Slice(_targetLocation!.Value), _package);
return TerminalMenuItemDataslateBinaryOverlay.TerminalMenuItemDataslateFactory(data, _package);
default:
throw new ArgumentOutOfRangeException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ public TerminalMenuItemDataslate()
#endregion

#region Dataslate
private readonly IFormLink<IBookGetter> _Dataslate = new FormLink<IBookGetter>();
public IFormLink<IBookGetter> Dataslate
private readonly IFormLinkNullable<IBookGetter> _Dataslate = new FormLinkNullable<IBookGetter>();
public IFormLinkNullable<IBookGetter> Dataslate
{
get => _Dataslate;
set => _Dataslate.SetTo(value);
}
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
IFormLinkGetter<IBookGetter> ITerminalMenuItemDataslateGetter.Dataslate => this.Dataslate;
IFormLinkNullableGetter<IBookGetter> ITerminalMenuItemDataslateGetter.Dataslate => this.Dataslate;
#endregion

#region To String
Expand Down Expand Up @@ -409,7 +409,7 @@ public partial interface ITerminalMenuItemDataslate :
ILoquiObjectSetter<ITerminalMenuItemDataslate>,
ITerminalMenuItemDataslateGetter
{
new IFormLink<IBookGetter> Dataslate { get; set; }
new IFormLinkNullable<IBookGetter> Dataslate { get; set; }
}

public partial interface ITerminalMenuItemDataslateGetter :
Expand All @@ -419,7 +419,7 @@ public partial interface ITerminalMenuItemDataslateGetter :
ILoquiObject<ITerminalMenuItemDataslateGetter>
{
static new ILoquiRegistration StaticRegistration => TerminalMenuItemDataslate_Registration.Instance;
IFormLinkGetter<IBookGetter> Dataslate { get; }
IFormLinkNullableGetter<IBookGetter> Dataslate { get; }

}

Expand Down Expand Up @@ -771,7 +771,7 @@ protected static void ToStringFields(
printMask: printMask);
if (printMask?.Dataslate ?? true)
{
sb.AppendItem(item.Dataslate.FormKey, "Dataslate");
sb.AppendItem(item.Dataslate.FormKeyNullable, "Dataslate");
}
}

Expand Down Expand Up @@ -838,7 +838,10 @@ public IEnumerable<IFormLinkGetter> EnumerateFormLinks(ITerminalMenuItemDataslat
{
yield return item;
}
yield return FormLinkInformation.Factory(obj.Dataslate);
if (FormLinkInformation.TryFactory(obj.Dataslate, out var DataslateInfo))
{
yield return DataslateInfo;
}
yield break;
}

Expand All @@ -865,7 +868,7 @@ public void DeepCopyIn(
deepCopy: deepCopy);
if ((copyMask?.GetShouldTranslate((int)TerminalMenuItemDataslate_FieldIndex.Dataslate) ?? true))
{
item.Dataslate.SetTo(rhs.Dataslate.FormKey);
item.Dataslate.SetTo(rhs.Dataslate.FormKeyNullable);
}
}

Expand Down Expand Up @@ -976,7 +979,7 @@ public static void WriteRecordTypes(
MutagenWriter writer,
TypedWriteParams translationParams)
{
FormLinkBinaryTranslation.Instance.Write(
FormLinkBinaryTranslation.Instance.WriteNullable(
writer: writer,
item: item.Dataslate,
header: translationParams.ConvertToCustom(RecordTypes.BNAM));
Expand Down Expand Up @@ -1092,7 +1095,7 @@ void IBinaryItem.WriteToBinary(

#region Dataslate
private int? _DataslateLocation;
public IFormLinkGetter<IBookGetter> Dataslate => FormLinkBinaryTranslation.Instance.NullableRecordOverlayFactory<IBookGetter>(_package, _recordData, _DataslateLocation);
public IFormLinkNullableGetter<IBookGetter> Dataslate => FormLinkBinaryTranslation.Instance.NullableRecordOverlayFactory<IBookGetter>(_package, _recordData, _DataslateLocation);
#endregion
partial void CustomFactoryEnd(
OverlayStream stream,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ public TerminalMenuItemDisplayText()
#endregion

#region DisplayText
public TranslatedString DisplayText { get; set; } = string.Empty;
ITranslatedStringGetter ITerminalMenuItemDisplayTextGetter.DisplayText => this.DisplayText;
public TranslatedString? DisplayText { get; set; }
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
ITranslatedStringGetter? ITerminalMenuItemDisplayTextGetter.DisplayText => this.DisplayText;
#endregion

#region To String
Expand Down Expand Up @@ -397,7 +398,7 @@ public partial interface ITerminalMenuItemDisplayText :
ILoquiObjectSetter<ITerminalMenuItemDisplayText>,
ITerminalMenuItemDisplayTextGetter
{
new TranslatedString DisplayText { get; set; }
new TranslatedString? DisplayText { get; set; }
}

public partial interface ITerminalMenuItemDisplayTextGetter :
Expand All @@ -406,7 +407,7 @@ public partial interface ITerminalMenuItemDisplayTextGetter :
ILoquiObject<ITerminalMenuItemDisplayTextGetter>
{
static new ILoquiRegistration StaticRegistration => TerminalMenuItemDisplayText_Registration.Instance;
ITranslatedStringGetter DisplayText { get; }
ITranslatedStringGetter? DisplayText { get; }

}

Expand Down Expand Up @@ -637,7 +638,7 @@ internal partial class TerminalMenuItemDisplayTextSetterCommon : ATerminalMenuIt
public void Clear(ITerminalMenuItemDisplayText item)
{
ClearPartial();
item.DisplayText.Clear();
item.DisplayText = default;
base.Clear(item);
}

Expand Down Expand Up @@ -755,9 +756,10 @@ protected static void ToStringFields(
item: item,
sb: sb,
printMask: printMask);
if (printMask?.DisplayText ?? true)
if ((printMask?.DisplayText ?? true)
&& item.DisplayText is {} DisplayTextItem)
{
sb.AppendItem(item.DisplayText, "DisplayText");
sb.AppendItem(DisplayTextItem, "DisplayText");
}
}

Expand Down Expand Up @@ -799,7 +801,10 @@ public override bool Equals(
public virtual int GetHashCode(ITerminalMenuItemDisplayTextGetter item)
{
var hash = new HashCode();
hash.Add(item.DisplayText);
if (item.DisplayText is {} DisplayTextitem)
{
hash.Add(DisplayTextitem);
}
hash.Add(base.GetHashCode());
return hash.ToHashCode();
}
Expand Down Expand Up @@ -850,7 +855,7 @@ public void DeepCopyIn(
deepCopy: deepCopy);
if ((copyMask?.GetShouldTranslate((int)TerminalMenuItemDisplayText_FieldIndex.DisplayText) ?? true))
{
item.DisplayText = rhs.DisplayText.DeepCopy();
item.DisplayText = rhs.DisplayText?.DeepCopy();
}
}

Expand Down Expand Up @@ -961,7 +966,7 @@ public static void WriteRecordTypes(
MutagenWriter writer,
TypedWriteParams translationParams)
{
StringBinaryTranslation.Instance.Write(
StringBinaryTranslation.Instance.WriteNullable(
writer: writer,
item: item.DisplayText,
header: translationParams.ConvertToCustom(RecordTypes.UNAM),
Expand Down Expand Up @@ -1081,7 +1086,7 @@ void IBinaryItem.WriteToBinary(

#region DisplayText
private int? _DisplayTextLocation;
public ITranslatedStringGetter DisplayText => _DisplayTextLocation.HasValue ? StringBinaryTranslation.Instance.Parse(HeaderTranslation.ExtractSubrecordMemory(_recordData, _DisplayTextLocation.Value, _package.MetaData.Constants), StringsSource.Normal, parsingBundle: _package.MetaData) : TranslatedString.Empty;
public ITranslatedStringGetter? DisplayText => _DisplayTextLocation.HasValue ? StringBinaryTranslation.Instance.Parse(HeaderTranslation.ExtractSubrecordMemory(_recordData, _DisplayTextLocation.Value, _package.MetaData.Constants), StringsSource.Normal, parsingBundle: _package.MetaData) : default(TranslatedString?);
#endregion
partial void CustomFactoryEnd(
OverlayStream stream,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ public TerminalMenuItemSubmenu()
#endregion

#region Submenu
private readonly IFormLink<ITerminalGetter> _Submenu = new FormLink<ITerminalGetter>();
public IFormLink<ITerminalGetter> Submenu
private readonly IFormLinkNullable<ITerminalGetter> _Submenu = new FormLinkNullable<ITerminalGetter>();
public IFormLinkNullable<ITerminalGetter> Submenu
{
get => _Submenu;
set => _Submenu.SetTo(value);
}
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
IFormLinkGetter<ITerminalGetter> ITerminalMenuItemSubmenuGetter.Submenu => this.Submenu;
IFormLinkNullableGetter<ITerminalGetter> ITerminalMenuItemSubmenuGetter.Submenu => this.Submenu;
#endregion

#region To String
Expand Down Expand Up @@ -409,7 +409,7 @@ public partial interface ITerminalMenuItemSubmenu :
ILoquiObjectSetter<ITerminalMenuItemSubmenu>,
ITerminalMenuItemSubmenuGetter
{
new IFormLink<ITerminalGetter> Submenu { get; set; }
new IFormLinkNullable<ITerminalGetter> Submenu { get; set; }
}

public partial interface ITerminalMenuItemSubmenuGetter :
Expand All @@ -419,7 +419,7 @@ public partial interface ITerminalMenuItemSubmenuGetter :
ILoquiObject<ITerminalMenuItemSubmenuGetter>
{
static new ILoquiRegistration StaticRegistration => TerminalMenuItemSubmenu_Registration.Instance;
IFormLinkGetter<ITerminalGetter> Submenu { get; }
IFormLinkNullableGetter<ITerminalGetter> Submenu { get; }

}

Expand Down Expand Up @@ -771,7 +771,7 @@ protected static void ToStringFields(
printMask: printMask);
if (printMask?.Submenu ?? true)
{
sb.AppendItem(item.Submenu.FormKey, "Submenu");
sb.AppendItem(item.Submenu.FormKeyNullable, "Submenu");
}
}

Expand Down Expand Up @@ -838,7 +838,10 @@ public IEnumerable<IFormLinkGetter> EnumerateFormLinks(ITerminalMenuItemSubmenuG
{
yield return item;
}
yield return FormLinkInformation.Factory(obj.Submenu);
if (FormLinkInformation.TryFactory(obj.Submenu, out var SubmenuInfo))
{
yield return SubmenuInfo;
}
yield break;
}

Expand All @@ -865,7 +868,7 @@ public void DeepCopyIn(
deepCopy: deepCopy);
if ((copyMask?.GetShouldTranslate((int)TerminalMenuItemSubmenu_FieldIndex.Submenu) ?? true))
{
item.Submenu.SetTo(rhs.Submenu.FormKey);
item.Submenu.SetTo(rhs.Submenu.FormKeyNullable);
}
}

Expand Down Expand Up @@ -976,7 +979,7 @@ public static void WriteRecordTypes(
MutagenWriter writer,
TypedWriteParams translationParams)
{
FormLinkBinaryTranslation.Instance.Write(
FormLinkBinaryTranslation.Instance.WriteNullable(
writer: writer,
item: item.Submenu,
header: translationParams.ConvertToCustom(RecordTypes.TNAM));
Expand Down Expand Up @@ -1092,7 +1095,7 @@ void IBinaryItem.WriteToBinary(

#region Submenu
private int? _SubmenuLocation;
public IFormLinkGetter<ITerminalGetter> Submenu => FormLinkBinaryTranslation.Instance.NullableRecordOverlayFactory<ITerminalGetter>(_package, _recordData, _SubmenuLocation);
public IFormLinkNullableGetter<ITerminalGetter> Submenu => FormLinkBinaryTranslation.Instance.NullableRecordOverlayFactory<ITerminalGetter>(_package, _recordData, _SubmenuLocation);
#endregion
partial void CustomFactoryEnd(
OverlayStream stream,
Expand Down

0 comments on commit 933d3e9

Please sign in to comment.