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.
This commit is contained in:
Centronias
2018-08-28 08:39:20 -07:00
committed by Pieter-Jan Briers
parent 7b7b5cc59f
commit ef506006b3
7 changed files with 119 additions and 2 deletions

View File

@@ -67,6 +67,7 @@
<Compile Include="AI\AimShootLifeProcessor.cs" />
<Compile Include="EntryPoint.cs" />
<Compile Include="GameObjects\Components\Doors\ServerDoorComponent.cs" />
<Compile Include="GameObjects\Components\Interactable\HandheldLightComponent.cs" />
<Compile Include="GameObjects\Components\Interactable\Tools\BaseTool.cs" />
<Compile Include="GameObjects\Components\Interactable\Tools\CrowbarComponent.cs" />
<Compile Include="GameObjects\Components\Interactable\Tools\MultitoolComponent.cs" />

View File

@@ -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<ProjectileComponent>();
factory.Register<MeleeWeaponComponent>();
factory.Register<HandheldLightComponent>();
factory.Register<ServerStorageComponent>();
factory.RegisterReference<ServerStorageComponent, IActivate>();

View File

@@ -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
{
/// <summary>
/// Component that represents a handheld lightsource which can be toggled on and off.
/// </summary>
class HandheldLightComponent : Component, EntitySystems.IUse, EntitySystems.IExamine
{
PointLightComponent pointLight;
SpriteComponent spriteComponent;
public override string Name => "HandheldLight";
/// <summary>
/// Status of light, whether or not it is emitting light.
/// </summary>
public bool Activated { get; private set; } = false;
public override void Initialize()
{
base.Initialize();
pointLight = Owner.GetComponent<PointLightComponent>();
spriteComponent = Owner.GetComponent<SpriteComponent>();
}
bool IUse.UseEntity(IEntity user)
{
return ToggleStatus();
}
/// <summary>
/// Illuminates the light if it is not active, extinguishes it if it is active.
/// </summary>
/// <returns>True if the light's status was toggled, false otherwise.</returns>
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;
}
}
}

View File

@@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 B

View File

@@ -0,0 +1,31 @@
{
"version": 1,
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "lantern_off",
"select": [],
"flags": {},
"directions": 1,
"delays": [
[
1.0
]
]
},
{
"name": "lantern_on",
"select": [],
"flags": {},
"directions": 1,
"delays": [
[
1.0
]
]
}
]
}