Open JiaRG opened 4 months ago
Yes, that is correct
Shouldn't RescuingWorkTypeDef be a single case? In this case, adding and removal are the same object
Sorry but I don’t understand what you are saying.
like this
private static readonly Lazy<WorkTypeDef> Lazy = new(() => new()
{
defName = "Rescuing",
labelShort = "WorkType_Rescue_Label".Translate(),
pawnLabel = "WorkType_Rescue_PawnLabel".Translate(),
gerundLabel = "WorkType_Rescue_GerundLabel".Translate(),
description = "WorkType_Rescue_Description".Translate(),
verb = "Rescue",
naturalPriority = 1310,
alwaysStartActive = true,
workTags = WorkTags.Caring | WorkTags.Commoner | WorkTags.AllWork
});
public static WorkTypeDef RescuingWorkTypeDef => Lazy.Value;
Each call of Tools.RescuingworkTypef
will only generate an object instance
Why is it important to only have one instance? It’s a tiny object and will get garbage collected as soon as no references to it exist anymore.
If there is only one instance, the remove operation don't need 130-132 code , right?
Well, it’s not only about the worktab visuals. The def database has significant influence on mods and the base game
https://github.com/pardeike/Achtung2/blob/209d8fc813bd541d421de5825ea8db33d796cdb1/Source/Tools.cs#L33-L45
https://github.com/pardeike/Achtung2/blob/209d8fc813bd541d421de5825ea8db33d796cdb1/Source/Settings.cs#L132-L135
https://github.com/pardeike/Achtung2/blob/209d8fc813bd541d421de5825ea8db33d796cdb1/Source/Main.cs#L210-L213
Tools.RescuingWorkTypeDef
Calling it multiple times will generated different object.