From ef506006b383e7f2349e22d2f5975ddbfbb70256 Mon Sep 17 00:00:00 2001 From: Centronias Date: Tue, 28 Aug 2018 08:39:20 -0700 Subject: [PATCH] Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter. --- Content.Server/Content.Server.csproj | 1 + Content.Server/EntryPoint.cs | 3 + .../Interactable/HandheldLightComponent.cs | 78 ++++++++++++++++++ Resources/Prototypes/Entities/Items.yml | 8 +- .../Objects/lantern.rsi/lantern_off.png | Bin 0 -> 259 bytes .../Objects/lantern.rsi/lantern_on.png | Bin 0 -> 293 bytes .../Textures/Objects/lantern.rsi/meta.json | 31 +++++++ 7 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 Content.Server/GameObjects/Components/Interactable/HandheldLightComponent.cs create mode 100644 Resources/Textures/Objects/lantern.rsi/lantern_off.png create mode 100644 Resources/Textures/Objects/lantern.rsi/lantern_on.png create mode 100644 Resources/Textures/Objects/lantern.rsi/meta.json diff --git a/Content.Server/Content.Server.csproj b/Content.Server/Content.Server.csproj index aa27026e39..cd4b7fd70e 100644 --- a/Content.Server/Content.Server.csproj +++ b/Content.Server/Content.Server.csproj @@ -67,6 +67,7 @@ + diff --git a/Content.Server/EntryPoint.cs b/Content.Server/EntryPoint.cs index f35b0d5009..bd303d0684 100644 --- a/Content.Server/EntryPoint.cs +++ b/Content.Server/EntryPoint.cs @@ -32,6 +32,7 @@ using Content.Server.GameObjects.Components.Mobs; using Content.Server.GameObjects.EntitySystems; using Content.Server.Mobs; using Content.Server.Players; +using Content.Server.GameObjects.Components.Interactable; namespace Content.Server { @@ -101,6 +102,8 @@ namespace Content.Server factory.Register(); factory.Register(); + factory.Register(); + factory.Register(); factory.RegisterReference(); diff --git a/Content.Server/GameObjects/Components/Interactable/HandheldLightComponent.cs b/Content.Server/GameObjects/Components/Interactable/HandheldLightComponent.cs new file mode 100644 index 0000000000..ea7c4903c6 --- /dev/null +++ b/Content.Server/GameObjects/Components/Interactable/HandheldLightComponent.cs @@ -0,0 +1,78 @@ +using Content.Server.GameObjects.EntitySystems; +using SS14.Server.GameObjects; +using SS14.Shared.Enums; +using SS14.Shared.GameObjects; +using SS14.Shared.Interfaces.GameObjects; +using SS14.Shared.Serialization; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Content.Server.GameObjects.Components.Interactable +{ + /// + /// Component that represents a handheld lightsource which can be toggled on and off. + /// + class HandheldLightComponent : Component, EntitySystems.IUse, EntitySystems.IExamine + { + PointLightComponent pointLight; + SpriteComponent spriteComponent; + + public override string Name => "HandheldLight"; + + /// + /// Status of light, whether or not it is emitting light. + /// + public bool Activated { get; private set; } = false; + + public override void Initialize() + { + base.Initialize(); + + pointLight = Owner.GetComponent(); + spriteComponent = Owner.GetComponent(); + } + + bool IUse.UseEntity(IEntity user) + { + return ToggleStatus(); + } + + /// + /// Illuminates the light if it is not active, extinguishes it if it is active. + /// + /// True if the light's status was toggled, false otherwise. + public bool ToggleStatus() + { + // Update the activation state. + Activated = !Activated; + + // Update sprite and light states to match the activation. + if (Activated) + { + spriteComponent.LayerSetState(0, "lantern_on"); + pointLight.State = LightState.On; + } + else + { + spriteComponent.LayerSetState(0, "lantern_off"); + pointLight.State = LightState.Off; + } + + // Toggle always succeeds. + return true; + } + + string IExamine.Examine() + { + if (Activated) + { + return "The light is currently on."; + } + + return null; + } + } +} diff --git a/Resources/Prototypes/Entities/Items.yml b/Resources/Prototypes/Entities/Items.yml index 578cea7125..d5cc9894f0 100644 --- a/Resources/Prototypes/Entities/Items.yml +++ b/Resources/Prototypes/Entities/Items.yml @@ -76,8 +76,12 @@ id: FlashlightLantern description: They light the way to freedom components: + - type: HandheldLight - type: Sprite - texture: Objects/Flashlight.png + sprite: Objects/lantern.rsi + state: lantern_off - type: Icon - texture: Objects/Flashlight.png + sprite: Objects/lantern.rsi + state: lantern_off - type: PointLight + state: Off diff --git a/Resources/Textures/Objects/lantern.rsi/lantern_off.png b/Resources/Textures/Objects/lantern.rsi/lantern_off.png new file mode 100644 index 0000000000000000000000000000000000000000..a7b3b4678de53ed2c9a4d24e055e8d1a0767b92d GIT binary patch literal 259 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnF3?v&v(vJfv-2k5u*Z&O-+={6-$#+#$!^Nblh?NaH8Pe2`2{mLJiCzw7lE`-p6cZP%8NI?yl7S(AD$&ctsny&diB?{7cUyAV5It zK(OWCjyukdJInbKx5=y*6sb|?2xlmnuE27DHG_{~{UQ~=2dAGZ1Kq>m>FVdQ&MBb@ E0812FE&u=k literal 0 HcmV?d00001 diff --git a/Resources/Textures/Objects/lantern.rsi/lantern_on.png b/Resources/Textures/Objects/lantern.rsi/lantern_on.png new file mode 100644 index 0000000000000000000000000000000000000000..b292f1c8b291c56e1d78c7dbe7e114cf19d916a1 GIT binary patch literal 293 zcmV+=0owkFP)2mZ0rLXFM%w%qg@z=Kfelu4Ge+0ehi3cPrm>d@pHyb0MqFlZGeu5 zN6*ajbcs7{!R*D=A*c4Yl+vANqKC08tG=t?sW4{}^AcBGQmP>NgiKMyoYU@5KNS&E rqSW4RnE}eXXuscn6Iifw2)>yY=