forked from SubnauticaNitrox/Nitrox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync name and colors for vehicles, rocket and cyclops
- Loading branch information
1 parent
7e89ce6
commit 9efe596
Showing
27 changed files
with
401 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
NitroxClient/GameLogic/Spawning/Metadata/Abstract/NamedColoredMetadataProcessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Linq; | ||
using NitroxClient.Communication; | ||
using NitroxClient.Unity.Helper; | ||
using NitroxModel.DataStructures.GameLogic.Entities.Metadata; | ||
using NitroxModel.DataStructures.Unity; | ||
using NitroxModel.Packets; | ||
using NitroxModel_Subnautica.DataStructures; | ||
using UnityEngine; | ||
|
||
namespace NitroxClient.GameLogic.Spawning.Metadata.Abstract; | ||
|
||
public abstract class NamedColoredMetadataProcessor<T> : GenericEntityMetadataProcessor<T> where T : NamedColoredMetadata | ||
{ | ||
public override void ProcessMetadata(GameObject gameObject, T metadata) | ||
{ | ||
using (PacketSuppressor<EntityMetadataUpdate>.Suppress()) | ||
{ | ||
SetNameAndColors(gameObject, metadata.Name, metadata.Colors); | ||
} | ||
} | ||
|
||
protected void SetNameAndColors(GameObject gameObject, string text, NitroxVector3[] nitroxColor) | ||
{ | ||
SubName subName = gameObject.RequireComponent<SubName>(); | ||
if (!string.IsNullOrEmpty(text)) | ||
{ | ||
subName.DeserializeName(text); | ||
} | ||
if (nitroxColor != null) | ||
{ | ||
Vector3[] colors = nitroxColor.Select(c => c.ToUnity()).ToArray(); | ||
subName.DeserializeColors(colors); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
NitroxClient/GameLogic/Spawning/Metadata/Abstract/VehicleMetadataProcessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using NitroxClient.Communication; | ||
using NitroxClient.Unity.Helper; | ||
using NitroxModel.DataStructures.GameLogic.Entities.Metadata; | ||
using NitroxModel.Packets; | ||
using UnityEngine; | ||
|
||
namespace NitroxClient.GameLogic.Spawning.Metadata.Abstract; | ||
|
||
public abstract class VehicleMetadataProcessor<T> : NamedColoredMetadataProcessor<T> where T : VehicleMetadata | ||
{ | ||
private readonly LiveMixinManager liveMixinManager; | ||
|
||
public VehicleMetadataProcessor(LiveMixinManager liveMixinManager) | ||
{ | ||
this.liveMixinManager = liveMixinManager; | ||
} | ||
|
||
public override void ProcessMetadata(GameObject gameObject, T metadata) | ||
{ | ||
using (PacketSuppressor<EntityMetadataUpdate>.Suppress()) | ||
{ | ||
SetHealth(gameObject, metadata.Health); | ||
} | ||
|
||
base.ProcessMetadata(gameObject, metadata); | ||
} | ||
|
||
protected void SetHealth(GameObject gameObject, float health) | ||
{ | ||
LiveMixin liveMixin = gameObject.RequireComponentInChildren<LiveMixin>(true); | ||
liveMixinManager.SyncRemoteHealth(liveMixin, health); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
NitroxClient/GameLogic/Spawning/Metadata/ExosuitMetadataProcessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using NitroxClient.GameLogic.Spawning.Metadata.Abstract; | ||
using NitroxModel.DataStructures.GameLogic.Entities.Metadata; | ||
using UnityEngine; | ||
|
||
namespace NitroxClient.GameLogic.Spawning.Metadata; | ||
|
||
public class ExosuitMetadataProcessor : VehicleMetadataProcessor<ExosuitMetadata> | ||
{ | ||
public ExosuitMetadataProcessor(LiveMixinManager liveMixinManager) : base(liveMixinManager) | ||
{ } | ||
|
||
public override void ProcessMetadata(GameObject gameObject, ExosuitMetadata metadata) | ||
{ | ||
if (!gameObject.TryGetComponent(out Exosuit exosuit)) | ||
{ | ||
Log.ErrorOnce($"[{nameof(ExosuitMetadataProcessor)}] Could not find {nameof(Exosuit)} on {gameObject}"); | ||
return; | ||
} | ||
|
||
base.ProcessMetadata(gameObject, metadata); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
NitroxClient/GameLogic/Spawning/Metadata/Extractor/Abstract/NamedColoredMetadataExtractor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Linq; | ||
using NitroxClient.Unity.Helper; | ||
using NitroxModel.DataStructures.GameLogic.Entities.Metadata; | ||
using NitroxModel.DataStructures.Unity; | ||
using NitroxModel_Subnautica.DataStructures; | ||
|
||
namespace NitroxClient.GameLogic.Spawning.Metadata.Extractor.Abstract; | ||
|
||
public abstract class NamedColoredMetadataExtractor<I, O> : GenericEntityMetadataExtractor<I, O> where O : NamedColoredMetadata | ||
{ | ||
public string GetName(SubName subName) | ||
{ | ||
return subName.AliveOrNull()?.hullName.AliveOrNull()?.text; | ||
} | ||
|
||
public NitroxVector3[] GetColors(SubName subName) | ||
{ | ||
return subName.AliveOrNull()?.GetColors().Select(color => color.ToDto()).ToArray(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
NitroxClient/GameLogic/Spawning/Metadata/Extractor/Abstract/VehicleMetadataExtractor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using NitroxModel.DataStructures.GameLogic.Entities.Metadata; | ||
|
||
namespace NitroxClient.GameLogic.Spawning.Metadata.Extractor.Abstract; | ||
|
||
public abstract class VehicleMetadataExtractor<I, O> : NamedColoredMetadataExtractor<I, O> where O : VehicleMetadata | ||
{ | ||
public float GetHealth(LiveMixin liveMixin) | ||
{ | ||
return liveMixin.health; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
NitroxClient/GameLogic/Spawning/Metadata/Extractor/ExosuitMetadataExtractor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using NitroxClient.GameLogic.Spawning.Metadata.Extractor.Abstract; | ||
using NitroxModel.DataStructures.GameLogic.Entities.Metadata; | ||
|
||
namespace NitroxClient.GameLogic.Spawning.Metadata.Extractor; | ||
|
||
public class ExosuitMetadataExtractor : VehicleMetadataExtractor<Exosuit, ExosuitMetadata> | ||
{ | ||
public override ExosuitMetadata Extract(Exosuit exosuit) | ||
{ | ||
LiveMixin liveMixin = exosuit.liveMixin; | ||
SubName subName = exosuit.subName; | ||
|
||
return new(GetHealth(liveMixin), GetName(subName), GetColors(subName)); | ||
} | ||
} |
9 changes: 5 additions & 4 deletions
9
NitroxClient/GameLogic/Spawning/Metadata/Extractor/SeamothMetadataExtractor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
using NitroxClient.Unity.Helper; | ||
using NitroxClient.GameLogic.Spawning.Metadata.Extractor.Abstract; | ||
using NitroxModel.DataStructures.GameLogic.Entities.Metadata; | ||
|
||
namespace NitroxClient.GameLogic.Spawning.Metadata.Extractor; | ||
|
||
public class SeamothMetadataExtractor : GenericEntityMetadataExtractor<SeaMoth, SeamothMetadata> | ||
public class SeamothMetadataExtractor : VehicleMetadataExtractor<SeaMoth, SeamothMetadata> | ||
{ | ||
public override SeamothMetadata Extract(SeaMoth seamoth) | ||
{ | ||
bool lightsOn = (seamoth.toggleLights) ? seamoth.toggleLights.GetLightsActive() : true; | ||
float health = seamoth.RequireComponentInChildren<LiveMixin>().health; | ||
LiveMixin liveMixin = seamoth.liveMixin; | ||
SubName subName = seamoth.subName; | ||
|
||
return new(lightsOn, health); | ||
return new(lightsOn, GetHealth(liveMixin), GetName(subName), GetColors(subName)); | ||
} | ||
} |
11 changes: 4 additions & 7 deletions
11
NitroxClient/GameLogic/Spawning/Metadata/Extractor/SubNameInputMetadataExtractor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
using System.Linq; | ||
using NitroxClient.GameLogic.Spawning.Metadata.Extractor.Abstract; | ||
using NitroxModel.DataStructures.GameLogic.Entities.Metadata; | ||
using NitroxModel.DataStructures.Unity; | ||
using NitroxModel_Subnautica.DataStructures; | ||
|
||
namespace NitroxClient.GameLogic.Spawning.Metadata.Extractor; | ||
|
||
public class SubNameInputMetadataExtractor : GenericEntityMetadataExtractor<SubNameInput, SubNameInputMetadata> | ||
public class SubNameInputMetadataExtractor : NamedColoredMetadataExtractor<SubNameInput, SubNameInputMetadata> | ||
{ | ||
public override SubNameInputMetadata Extract(SubNameInput subNameInput) | ||
{ | ||
NitroxVector3[] colors = subNameInput.target.GetColors().Select(color => color.ToDto()).ToArray(); | ||
|
||
return new(subNameInput.inputField.text, colors); | ||
SubName subName = subNameInput.target; | ||
return new(subNameInput.selectedColorIndex, GetName(subName), GetColors(subName)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
NitroxClient/GameLogic/Spawning/Metadata/SubNameInputMetadataProcessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using NitroxClient.Communication; | ||
using NitroxClient.GameLogic.Spawning.Metadata.Abstract; | ||
using NitroxModel.DataStructures.GameLogic.Entities.Metadata; | ||
using NitroxModel.Packets; | ||
using UnityEngine; | ||
|
||
namespace NitroxClient.GameLogic.Spawning.Metadata; | ||
|
||
public class SubNameInputMetadataProcessor : NamedColoredMetadataProcessor<SubNameInputMetadata> | ||
{ | ||
public override void ProcessMetadata(GameObject gameObject, SubNameInputMetadata metadata) | ||
{ | ||
if (!gameObject.TryGetComponent(out SubNameInput subNameInput)) | ||
{ | ||
Log.ErrorOnce($"[{nameof(SubNameInputMetadataProcessor)}] Could not find {nameof(SubNameInput)} on {gameObject}"); | ||
return; | ||
} | ||
|
||
SubName subName = subNameInput.target; | ||
if (!subName && !subNameInput.TryGetComponent(out subName)) | ||
{ | ||
Log.ErrorOnce($"[{nameof(SubNameInputMetadataProcessor)}] {gameObject}'s {nameof(subNameInput)} doesn't have a target."); | ||
return; | ||
} | ||
|
||
// Name and color applying must be applied before SelectedColorIndex | ||
base.ProcessMetadata(subName.gameObject, metadata); | ||
using (PacketSuppressor<EntityMetadataUpdate>.Suppress()) | ||
{ | ||
subNameInput.SetSelected(metadata.SelectedColorIndex); | ||
} | ||
} | ||
} |
36 changes: 0 additions & 36 deletions
36
NitroxClient/GameLogic/Spawning/Metadata/SubNameInputProcessor.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.