From d6bc4ab8ebddb4114c9435b1513b004721076392 Mon Sep 17 00:00:00 2001 From: Lee23 <31892011+LeeTwentyThree@users.noreply.github.com> Date: Sat, 7 Dec 2024 15:31:24 -0500 Subject: [PATCH] chore: Vehicle Upgrade Module Gadget and Custom Buildable Example cleanup (#567) * Update CustomBuildableExample comments * Clean up awful vehicle module docs --- Example mod/CustomBuildableExample.cs | 6 +- .../Assets/Gadgets/UpgradeModuleGadget.cs | 225 ++++++++---------- 2 files changed, 100 insertions(+), 131 deletions(-) diff --git a/Example mod/CustomBuildableExample.cs b/Example mod/CustomBuildableExample.cs index 28cc516f1..4150e2226 100644 --- a/Example mod/CustomBuildableExample.cs +++ b/Example mod/CustomBuildableExample.cs @@ -32,13 +32,15 @@ public static void Register() // create prefab: CustomPrefab prefab = new CustomPrefab(Info); - // copy the model of a vanilla wreck piece (which looks like a taller locker): + // copy the model of a vanilla wreck piece (which looks like a taller locker) + // we pass in the Class ID of the original prefab, which was found on this page: + // https://github.com/SubnauticaModding/Nautilus/blob/master/Nautilus/Documentation/resources/SN1-PrefabPaths.json CloneTemplate lockerClone = new CloneTemplate(Info, "cd34fecd-794c-4a0c-8012-dd81b77f2840"); // modify the cloned model: lockerClone.ModifyPrefab += obj => { - // allow it to be placced inside bases and submarines on the ground, and can be rotated: + // allow it to be placed inside bases and submarines on the ground, and can be rotated: ConstructableFlags constructableFlags = ConstructableFlags.Inside | ConstructableFlags.Rotatable | ConstructableFlags.Ground | ConstructableFlags.Submarine; // find the object that holds the model: diff --git a/Nautilus/Assets/Gadgets/UpgradeModuleGadget.cs b/Nautilus/Assets/Gadgets/UpgradeModuleGadget.cs index cfd9698b7..a494656f6 100644 --- a/Nautilus/Assets/Gadgets/UpgradeModuleGadget.cs +++ b/Nautilus/Assets/Gadgets/UpgradeModuleGadget.cs @@ -7,62 +7,58 @@ namespace Nautilus.Assets.Gadgets; /// -/// Represents a vehicle module (or upgrade) gadget. +/// Represents a vehicle upgrade module gadget. /// public class UpgradeModuleGadget : Gadget { // UNIVERSAL /// - /// Max charge of this item. - /// Should apply to modules of vehicles and to chargeable items. + /// Defines the max charge in units of energy of this upgrade module when activated. + /// Applicable for chargeable vehicle modules. /// public double MaxCharge { get; set; } /// - /// Energy cost of this item. - /// Should apply to modules of vehicles. + /// Defines the energy cost of this upgrade module when activated. Applicable for all usable vehicle modules. /// + /// For chargeable modules, this defines the number of units of energy expended per second. public double EnergyCost { get; set; } /// - /// Cooldown for this module. - /// Does not work with Toggleable items. - /// May not work with certain vehicles. + /// Defines the cooldown of this upgrade module after being activated. Applicable for non-toggleable vehicle modules, + /// with some potential limitations. /// public double Cooldown { get; set; } = 0f; /// - /// Crush depth of this upgrade. - /// Leave to -1f to disable + /// Defines the crush depth of this upgrade module. Default value is -1. Only used when values are above 0. /// public float CrushDepth { get; set; } = -1f; /// - /// Wether the depth provided should be absolute or added to the default depth of the vehicle. + /// Whether the crush depth provided (if any) should be absolute or added to the default depth of the vehicle. /// Default value is false. /// public bool AbsoluteDepth { get; set; } = false; - - + // ON ADDED /// - /// This happens when the module is added to the vehicle. - /// Action that is executed after Nautilus' default action (if there is) on this event. + /// The Action that is executed after the vehicle module is added, called after default events. /// public Action delegateOnAdded { get; private set; } #if BELOWZERO /// - /// This happens when the module is added to the SeaTruck. - /// Action that is executed after Nautilus' default action (if there is) on this event. + /// The Action that is executed after the vehicle module is added to a Seatruck, + /// called after default events. /// public Action seatruckOnAdded { get; private set; } /// - /// This happens when the module is added to the Hoverbike. - /// Action that is executed after Nautilus' default action (if there is) on this event. + /// The Action that is executed after the vehicle module is added to a Snowfox, + /// called after default events. /// public Action hoverbikeOnAdded { get; private set; } #endif @@ -70,20 +66,18 @@ public class UpgradeModuleGadget : Gadget // ON REMOVED /// - /// This happens when the module is removed from the vehicle. - /// Action that is executed after Nautilus' default action (if there is) on this event. + /// The Action that is executed after the vehicle module is removed. /// public Action delegateOnRemoved { get; private set; } #if BELOWZERO /// - /// This happens when the module is removed from the SeaTruck. - /// Action that is executed after Nautilus' default action (if there is) on this event. + /// The Action that is executed after the vehicle module is removed from a Seatruck. /// public Action seatruckOnRemoved { get; private set; } /// - /// This happens when the module is removed from the Hoverbike. + /// The Action that is executed after the vehicle module is removed from a Snowfox. /// public Action hoverbikeOnRemoved { get; private set; } #endif @@ -91,25 +85,20 @@ public class UpgradeModuleGadget : Gadget // ON USED /// - /// This happens when the module is used. - /// The delegate is not run when the module is a toggleable. - /// Action that is executed after Nautilus' default action (if there is) on this event. + /// The Action that is executed when the module is used. Applies to non-toggleable vehicle modules. /// public Action delegateOnUsed { get; private set; } #if BELOWZERO /// - /// This happens when the module is used. - /// The delegate is not run when the module is a togglable. - /// Action that is executed after Nautilus' default action (if there is) on this event. - /// The first float represents the current quick slot charge, and the second one represents the charge scalar (a game internal). + /// The Action that is executed when the module is used on a Seatruck. Applies to non-toggleable vehicle modules. + /// The first float represents the current quick slot charge, and the second one represents the charge scalar. /// public Action seatruckOnUsed { get; private set; } /// - /// This happens when the module is used. - /// The delegate is not run when the module is a togglable. - /// Action that is executed after Nautilus' default action (if there is) on this event. + /// The Action that is executed when the module is used on a Snowfox. Applies to non-toggleable vehicle modules. + /// The first float represents the current quick slot charge, and the second one represents the charge scalar. /// public Action hoverbikeOnUsed { get; private set; } #endif @@ -117,32 +106,31 @@ public class UpgradeModuleGadget : Gadget // ON TOGGLED /// - /// This happens when the module is toggled.
- /// The boolean represents wether the module is on or off.
- /// The delegate is not executed when the module is a selectable, selectableChargeable or a chargeable. - /// Action that is executed after Nautilus' default action (if there is) on this event. + /// The Action that is executed when the module is toggled. Only applies to toggleable vehicle modules. ///
+ /// + /// The boolean represents whether the module is on or off. + /// public Action delegateOnToggled { get; private set; } #if BELOWZERO /// - /// This happens when the module is toggled.
- /// The boolean represents wether the module is on or off.
- /// The delegate is not executed when the module is a selectable, selectableChargeable or a chargeable. - /// Action that is executed after Nautilus' default action (if there is) on this event. + /// The Action that is executed when the module is toggled in a Seatruck. Only applies to toggleable vehicle modules. ///
+ /// + /// The boolean represents whether the module is on or off. + /// public Action seatruckOnToggled { get; private set; } /// - /// This happens when the module is toggled.
- /// The boolean represents wether the module is on or off.
- /// The delegate is not executed when the module is a selectable, selectableChargeable or a chargeable. - /// Action that is executed after Nautilus' default action (if there is) on this event. + /// The Action that is executed when the module is toggled in a Snowfox. Only applies to toggleable vehicle modules. ///
+ /// + /// The boolean represents whether the module is on or off. + /// public Action hoverbikeOnToggled { get; private set; } #endif - - + /// /// Constructs an equipment gadget. /// @@ -150,13 +138,14 @@ public class UpgradeModuleGadget : Gadget public UpgradeModuleGadget(ICustomPrefab prefab) : base(prefab) { } /// - /// The maximum charge of the item. - /// Usually used as a multiplier for vehicle modules. - /// (Seamoth defense perimeter, Seatruck defense perimeter) - /// Example: The Seamoth defense perimeter can be charged by holding the action key to make its damage bigger. + /// Sets the maximum charge of an upgrade module, in units of energy. /// - /// Charge multiplier - /// A reference to this instance after the operation has completed. + /// The maximum charge in total units of energy that can be expended. + /// A reference to this instance after the operation has been completed. + /// + /// This is used for the Seamoth and Seatruck Perimeter Defense Module to provide a strength modifier + /// based on how long the player holds the key. + /// public UpgradeModuleGadget WithMaxCharge(double maxCharge) { MaxCharge = maxCharge; @@ -164,12 +153,14 @@ public UpgradeModuleGadget WithMaxCharge(double maxCharge) } /// - /// The energy cost of the item. - /// Usually used for vehicle modules to consume energy. - /// (Seamoth perimeter defense, Seamoth sonar) + /// Sets the energy cost of this upgrade module when used. /// - /// Energy cost - /// A reference to this instance after the operation has completed. + /// The energy cost per use (or per second for chargeable modules). + /// A reference to this instance after the operation has been completed. + /// + /// For chargeable modules, this defines the number of units of energy expended per second + /// towards the total charge. + /// public UpgradeModuleGadget WithEnergyCost(double energyCost) { EnergyCost = energyCost; @@ -177,12 +168,11 @@ public UpgradeModuleGadget WithEnergyCost(double energyCost) } /// - /// The cooldown of the module when it is used. - /// Cooldown may not work with certain vehicles. - /// Does not work with toggleable and passive items. + /// Sets the cooldown of the module after it is used. /// - /// Cooldown of the module in seconds. - /// A reference to thihs instance after the operation has completed. + /// The cooldown of the module in seconds. + /// A reference to this instance after the operation has been completed. + /// Does not work with toggleable or passive items, and may not be implemented by all vehicles. public UpgradeModuleGadget WithCooldown(double cooldown) { Cooldown = cooldown; @@ -192,9 +182,9 @@ public UpgradeModuleGadget WithCooldown(double cooldown) /// /// Sets the crush depth given by this upgrade. /// - /// New crush depth, in meters. - /// Wether the provided depth should be absolute or added to the default max depth of the vehicle. - /// A reference to this instance after the operation has completed. + /// The new crush depth in meters. + /// Whether the provided depth should be absolute or added to the default max depth of the vehicle. + /// A reference to this instance after the operation has been completed. public UpgradeModuleGadget WithDepthUpgrade(float newCrushDepth, bool absolute = false) { CrushDepth = newCrushDepth; @@ -206,12 +196,10 @@ public UpgradeModuleGadget WithDepthUpgrade(float newCrushDepth, bool absolute = // DELEGATES /// - /// What happens when the module is added to a vehicle ?
- /// This action is run after Nautilus' default action (if the module is a hull, the new hull of the vehicle is automatically updated).
- /// For removed, see also . + /// Defines extra functionality when this upgrade module is added. ///
- /// Action that occurs when the module is added. - /// A reference to this instance after the operation has completed. + /// Action that occurs after the module is added. + /// A reference to this instance after the operation has been completed. public UpgradeModuleGadget WithOnModuleAdded(Action onAdded) { delegateOnAdded = onAdded; @@ -220,12 +208,10 @@ public UpgradeModuleGadget WithOnModuleAdded(Action onAdded) #if BELOWZERO /// - /// What happens when the module is added to a Seatruck ?
- /// This actions is run after Nautilus' default action (if the module is a hull, the new hull of the vehicle is automatically updated).
- /// For removed, see also . + /// Defines extra functionality when this upgrade module is added. ///
- /// Action that occurs when the module is added. - /// A reference to this instance after the operation has completed. + /// Action that occurs after the module is added. + /// A reference to this instance after the operation has been completed. public UpgradeModuleGadget WithOnModuleAdded(Action onAdded) { seatruckOnAdded = onAdded; @@ -233,12 +219,10 @@ public UpgradeModuleGadget WithOnModuleAdded(Action - /// What happens when the module is added to a seatruck ?
- /// This action is run after Nautilus' default action (if the module is a hull, the new hull of the vehicle is automatically updated).
- /// For removed, see also + /// Defines extra functionality when this upgrade module is added. /// - /// - /// + /// Action that occurs after the module is added. + /// A reference to this instance after the operation has been completed. public UpgradeModuleGadget WithOnModuleAdded(Action onAdded) { hoverbikeOnAdded = onAdded; @@ -247,12 +231,10 @@ public UpgradeModuleGadget WithOnModuleAdded(Action onAdded) #endif /// - /// What happens when the module is removed from a vehicle ?
- /// This action is run after Nautilus' default action (if the module is a hull, the new hull of the vehicle is automatically updated).
- /// For added, see also . + /// Defines extra functionality when this upgrade module is removed. ///
- /// Action that occurs when the module is removed. - /// A reference to this instance after the operation has completed. + /// Action that occurs after the module is removed. + /// A reference to this instance after the operation has been completed. public UpgradeModuleGadget WithOnModuleRemoved(Action onRemoved) { delegateOnRemoved = onRemoved; @@ -261,12 +243,10 @@ public UpgradeModuleGadget WithOnModuleRemoved(Action onRemoved) #if BELOWZERO /// - /// What happens when the module is removed from a Seatruck ?
- /// This action is run after Nautilus' default action (if the module is a hull, the new hull of the vehicle is automatically updated).
- /// For added, see also . + /// Defines extra functionality when this upgrade module is removed. ///
- /// Action that occurs when the module is removed. - /// A reference to this instance after the operation has completed. + /// Action that occurs after the module is removed. + /// A reference to this instance after the operation has been completed. public UpgradeModuleGadget WithOnModuleRemoved(Action onRemoved) { seatruckOnRemoved = onRemoved; @@ -274,12 +254,10 @@ public UpgradeModuleGadget WithOnModuleRemoved(Action - /// What happens when the module is removed from a Hoverbike ?
- /// This action is run after Nautilus' default action (if the module is a hull, the new hull of the vehicle is automatically updated).
- /// For added, see also . + /// Defines extra functionality when this upgrade module is removed. /// - /// Action that occurs when the module is removed. - /// A reference to this instance after the operation has completed. + /// Action that occurs after the module is removed. + /// A reference to this instance after the operation has been completed. public UpgradeModuleGadget WithOnModuleRemoved(Action onRemoved) { hoverbikeOnRemoved = onRemoved; @@ -288,12 +266,11 @@ public UpgradeModuleGadget WithOnModuleRemoved(Action onRemoved) #endif /// - /// What happens when the module is used ?
- /// This action is run after Nautilus' default action (cooldown and energy consumption are automatically set).
- /// For toggle, see also . + /// Defines extra functionality when this upgrade module is used, for non-toggleable modules. ///
/// Action that occurs when the module is used. - /// A reference to this instance after the operation has completed. + /// A reference to this instance after the operation has been completed. + /// The first float represents the current quick slot charge, and the second one represents the charge scalar. public UpgradeModuleGadget WithOnModuleUsed(Action onUsed) { delegateOnUsed = onUsed; @@ -302,13 +279,11 @@ public UpgradeModuleGadget WithOnModuleUsed(Action o #if BELOWZERO /// - /// What happens when the module is used ?
- /// This action is run after Nautilus' default action (cooldown and energy consumption are automatically set).
- /// For toggle, see also . - /// The first float represents the current quick slot charge, and the second one represents the charge scalar (a game internal). + /// Defines extra functionality when this upgrade module is used, for non-toggleable modules. ///
/// Action that occurs when the module is used. - /// A reference to this instance after the operation has completed. + /// A reference to this instance after the operation has been completed. + /// The first float represents the current quick slot charge, and the second one represents the charge scalar. public UpgradeModuleGadget WithOnModuleUsed(Action onUsed) { seatruckOnUsed = onUsed; @@ -316,12 +291,11 @@ public UpgradeModuleGadget WithOnModuleUsed(Action - /// What happens when the module is used ?
- /// This action is run after Nautilus' default action (cooldown and energy consumption are automatically set).
- /// For toggle, see also . + /// Defines extra functionality when this upgrade module is used, for non-toggleable modules. /// /// Action that occurs when the module is used. - /// A reference to this instance after the operation has completed. + /// A reference to this instance after the operation has been completed. + /// The first float represents the current quick slot charge, and the second one represents the charge scalar. public UpgradeModuleGadget WithOnModuleUsed(Action onUsed) { hoverbikeOnUsed = onUsed; @@ -330,13 +304,11 @@ public UpgradeModuleGadget WithOnModuleUsed(Action #endif /// - /// What happens when the module is toggled ?
- /// This actions is run after Nautilus' default action (energy consumption is automatically set).
- /// For use, see also . + /// Defines extra functionality when this upgrade module is toggled. ///
- /// Action that occurs when the module turns on and when it turns off.
- /// The boolean determines wether it is added or removed (added=true). - /// A reference to this instance after the operation has completed. + /// Action that occurs when the module is toggled. + /// A reference to this instance after the operation has been completed. + /// The boolean represents whether it is being added or removed. public UpgradeModuleGadget WithOnModuleToggled(Action onToggled) { delegateOnToggled = onToggled; @@ -345,13 +317,11 @@ public UpgradeModuleGadget WithOnModuleToggled(Action #if BELOWZERO /// - /// What happens when the module is toggled ?
- /// This action is run after Nautilus' default action (energy consumption is automatically set)
- /// For use, see also . + /// Defines extra functionality when this upgrade module is toggled. ///
- /// Action that occurs when the module turns on and when it turns off.
- /// The boolean determines wether it is added or removed (added=true). - /// A reference to this instance after the operation has completed. + /// Action that occurs when the module is toggled. + /// A reference to this instance after the operation has been completed. + /// The boolean represents whether it is being added or removed. public UpgradeModuleGadget WithOnModuleToggled(Action onToggled) { seatruckOnToggled = onToggled; @@ -359,12 +329,11 @@ public UpgradeModuleGadget WithOnModuleToggled(Action - /// What happens when the module is toggled ?
- /// This action is run after Nautilus' default action (energy consumption is automatically set)
- /// For use, see also + /// Defines extra functionality when this upgrade module is toggled. /// - /// - /// + /// Action that occurs when the module is toggled. + /// A reference to this instance after the operation has been completed. + /// The boolean represents whether it is being added or removed. public UpgradeModuleGadget WithOnModuleToggled(Action onToggled) { hoverbikeOnToggled = onToggled; @@ -372,8 +341,6 @@ public UpgradeModuleGadget WithOnModuleToggled(Action protected internal override void Build() {