From ff681c54d8c60f5db783a44e15d9bdf7463b5943 Mon Sep 17 00:00:00 2001 From: CaYpeN1 Date: Tue, 19 Mar 2024 18:58:24 +0500 Subject: [PATCH] add: try add sprite module. attemp 1 --- .../WeaponsModules/WeaponModulesVisuals.cs | 42 ++++++++++++++++++ .../WeaponModulesVisualsComponent.cs | 15 +++++++ .../WeaponModules/WeaponModulesSystem.cs | 4 +- .../Objects/Weapons/Guns/Rifles/rifles.yml | 3 ++ .../Weapons/Guns/Rifles/ak.rsi/laser.png | Bin 0 -> 152 bytes .../Weapons/Guns/Rifles/ak.rsi/meta.json | 3 ++ 6 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 Content.Client/_White/WeaponsModules/WeaponModulesVisuals.cs create mode 100644 Content.Client/_White/WeaponsModules/WeaponModulesVisualsComponent.cs create mode 100644 Resources/Textures/Objects/Weapons/Guns/Rifles/ak.rsi/laser.png diff --git a/Content.Client/_White/WeaponsModules/WeaponModulesVisuals.cs b/Content.Client/_White/WeaponsModules/WeaponModulesVisuals.cs new file mode 100644 index 0000000000..a360aa9faf --- /dev/null +++ b/Content.Client/_White/WeaponsModules/WeaponModulesVisuals.cs @@ -0,0 +1,42 @@ +using Content.Client.Weapons.Ranged.Components; +using Content.Shared.Rounding; +using Content.Shared.Weapons.Ranged.Systems; +using Robust.Client.GameObjects; + +namespace Content.Client._White.WeaponsModules; + +public sealed partial class WeaponModulesVisuals : EntitySystem +{ + private void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(ComponentInit); + SubscribeLocalEvent(onModuleVisualChange); + } + + private void ComponentInit(EntityUid uid, WeaponModulesVisualsComponent component, ComponentInit args) + { + if (!TryComp(uid, out var sprite)) return; + + if (sprite.LayerMapTryGet(ModuleVisualState.Laser, out _)) + { + sprite.LayerSetState(ModuleVisualState.Laser, $"laser"); + sprite.LayerSetVisible(ModuleVisualState.Laser, false); + } + } + + private void onModuleVisualChange(EntityUid uid, WeaponModulesVisualsComponent component, ref AppearanceChangeEvent args) + { + var sprite = args.Sprite; + + if (sprite == null) return; + + if (sprite.LayerMapTryGet(ModuleVisualState.Laser, out _)) + { + sprite.LayerSetVisible(ModuleVisualState.Laser, true); + sprite.LayerSetState(ModuleVisualState.Laser, $"laser"); + } + } + +} diff --git a/Content.Client/_White/WeaponsModules/WeaponModulesVisualsComponent.cs b/Content.Client/_White/WeaponsModules/WeaponModulesVisualsComponent.cs new file mode 100644 index 0000000000..67d1d7aaa3 --- /dev/null +++ b/Content.Client/_White/WeaponsModules/WeaponModulesVisualsComponent.cs @@ -0,0 +1,15 @@ +using Robust.Shared.GameStates; + +namespace Content.Client._White.WeaponsModules; + +/// +[RegisterComponent, Access(typeof(WeaponModulesVisuals))] +public sealed partial class WeaponModulesVisualsComponent : Component +{ + [DataField()] public string? state; +} + +public enum ModuleVisualState : byte +{ + Laser +} diff --git a/Content.Server/_White/WeaponModules/WeaponModulesSystem.cs b/Content.Server/_White/WeaponModules/WeaponModulesSystem.cs index 0df6b63fe3..b919c07e15 100644 --- a/Content.Server/_White/WeaponModules/WeaponModulesSystem.cs +++ b/Content.Server/_White/WeaponModules/WeaponModulesSystem.cs @@ -1,7 +1,4 @@ using System.Numerics; -using Content.Server.Light.Events; -using Content.Server.Lightning; -using Content.Shared.Light; using Content.Shared.Weapons.Ranged.Components; using Content.Shared.Weapons.Ranged.Systems; using Robust.Server.GameObjects; @@ -14,6 +11,7 @@ public sealed class WeaponModulesSystem : EntitySystem { protected const string ModulesSlot = "gun_modules"; [Dependency] private readonly PointLightSystem _lightSystem = default!; + [Dependency] private readonly SharedAppearanceSystem Appearance = default!; [Dependency] private readonly SharedGunSystem _gunSystem = default!; SoundSpecifier? oldSoundGunshot; diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml index 9baf951015..c5525d983c 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml @@ -71,6 +71,8 @@ map: [ "enum.GunVisualLayers.Base" ] - state: mag-0 map: [ "enum.GunVisualLayers.Mag" ] + - state: laser + map: [ "enum.ModuleVisualState.Laser" ] - type: Gun fireRate: 5 soundGunshot: @@ -111,6 +113,7 @@ magState: mag steps: 1 zeroVisible: true + - type: WeaponModulesVisuals - type: Appearance - type: entity diff --git a/Resources/Textures/Objects/Weapons/Guns/Rifles/ak.rsi/laser.png b/Resources/Textures/Objects/Weapons/Guns/Rifles/ak.rsi/laser.png new file mode 100644 index 0000000000000000000000000000000000000000..efe0ab5bbb1e107d0de7a77c8ced9b242d71e4b5 GIT binary patch literal 152 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE3?yBabR7dyjKx9jP7LeL$-D$|L<4+6T!FN? znN?{?rKE(^GASu9FRxk#h97(X9|B6Smjw9*GyMPm|HuFT3k){Y0fpo|T^vI!dXp0* uSe0cAjEo*lPft!xO literal 0 HcmV?d00001 diff --git a/Resources/Textures/Objects/Weapons/Guns/Rifles/ak.rsi/meta.json b/Resources/Textures/Objects/Weapons/Guns/Rifles/ak.rsi/meta.json index 12a95021c6..c0a295d7d1 100644 --- a/Resources/Textures/Objects/Weapons/Guns/Rifles/ak.rsi/meta.json +++ b/Resources/Textures/Objects/Weapons/Guns/Rifles/ak.rsi/meta.json @@ -19,6 +19,9 @@ { "name": "mag-0" }, + { + "name": "laser" + }, { "name": "inhand-left", "directions": 4