Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Folding Plastic Table #2191

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Content.Shared/_NF/Foldable/FoldableFixtureComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Content.Shared._NF.Foldable.Systems;

[RegisterComponent]
public sealed partial class FoldableFixtureComponent : Component
{
[DataField(required: true)]
public List<string> FoldedFixtures;
[DataField(required: true)]
public List<string> UnfoldedFixtures;
}
56 changes: 56 additions & 0 deletions Content.Shared/_NF/Foldable/FoldableFixtureSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Content.Shared.Foldable;
using Robust.Shared.Physics.Systems;

namespace Content.Shared._NF.Foldable.Systems;

public sealed class FoldableFixtureSystem : EntitySystem
{
[Dependency] private readonly FixtureSystem _fixtures = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;

public override void Initialize()
{
SubscribeLocalEvent<FoldableFixtureComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<FoldableFixtureComponent, FoldedEvent>(OnFolded);
}

private void OnMapInit(EntityUid uid, FoldableFixtureComponent component, MapInitEvent args)
{
if (TryComp<FoldableComponent>(uid, out var foldable))
SetFoldedFixtures(uid, foldable.IsFolded, component);
}

private void OnFolded(EntityUid uid, FoldableFixtureComponent? component, ref FoldedEvent args)
{
SetFoldedFixtures(uid, args.IsFolded, component);
}

// Sets all relevant fixtures for the entity to an appropriate hard/soft state.
private void SetFoldedFixtures(EntityUid uid, bool isFolded, FoldableFixtureComponent? component)
{
if (!Resolve(uid, ref component))
return;

if (isFolded)
{
SetAllFixtureHardness(uid, component.FoldedFixtures, true);
SetAllFixtureHardness(uid, component.UnfoldedFixtures, false);
}
else
{
SetAllFixtureHardness(uid, component.FoldedFixtures, false);
SetAllFixtureHardness(uid, component.UnfoldedFixtures, true);
}
}

// Sets all fixtures on an entity in a list to either be hard or soft.
void SetAllFixtureHardness(EntityUid uid, List<string> fixtures, bool hard)
{
foreach (var fixName in fixtures)
{
var fixture = _fixtures.GetFixtureOrNull(uid, fixName);
if (fixture != null)
_physics.SetHard(uid, fixture, hard);
}
}
}
125 changes: 125 additions & 0 deletions Resources/Prototypes/_NF/Entities/Structures/Furniture/tables.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@

- type: entity
parent: BaseDeployFoldable
id: TableFolding
name: folding table
description: If you carry six of these you become the coolest kid at church.
components:
# Table bits
- type: SpriteFade
- type: Clickable
- type: InteractionOutline
- type: Climbable # Pointless without player-table collision, but I'll keep it
- type: GlassTable
climberDamage:
types:
Blunt: 15
tableDamage:
types:
Blunt: 25
tableMassLimit: 60
- type: PlaceableSurface
- type: Physics
bodyType: Dynamic
fixedRotation: true
- type: Pullable
- type: Fixtures
fixtures:
table:
shape:
!type:PhysShapeAabb
bounds: "-0.4,-0.4,0.4,0.4"
density: 55
mask: # tables should collide with other tables
- TableMask
layer:
- TableLayer
hard: true
item:
shape:
!type:PhysShapeAabb
bounds: "-0.25,-0.25,0.25,0.25"
density: 20
mask:
- ItemMask
restitution: 0.3 # fite me
friction: 0.2
- type: Bonkable
bonkDamage:
types:
Blunt: 4
bonkSound: !type:SoundCollectionSpecifier
collection: TrayHit
- type: FootstepModifier
footstepSoundCollection:
collection: FootstepHull
# Item bits
- type: MovedByPressure
- type: Item
size: Huge
- type: Sprite
sprite: _NF/Structures/Furniture/folding_table.rsi
layers:
- state: folding
map: ["unfoldedLayer"]
- state: folding_folded
map: ["foldedLayer"]
visible: false
noRot: true
- type: Appearance
- type: MeleeWeapon
damage:
types:
Blunt: 8
soundHit:
collection: MetalThud
- type: Damageable
damageContainer: StructuralInorganic
damageModifierSet: Metallic
- type: Destructible
thresholds:
- trigger:
!type:DamageTrigger
damage: 15
behaviors:
- !type:DoActsBehavior
acts: [ "Destruction" ]
- !type:PlaySoundBehavior
sound:
collection: MetalBreak
- trigger:
!type:DamageTrigger
damage: 5
behaviors:
- !type:PlaySoundBehavior
sound:
collection: MetalBreak
- !type:SpawnEntitiesBehavior
spawn:
SheetPlastic1:
min: 1
max: 1
- !type:DoActsBehavior
acts: [ "Destruction" ]
- type: StaticPrice
price: 20
- type: Construction
graph: TableFoldingGraph
node: TableFolding
- type: DamageExaminable
- type: FoldableFixture
foldedFixtures:
- item
unfoldedFixtures:
- table

- type: entity
parent: TableFolding
id: TableFoldingSpawnFolded
suffix: folded
components:
- type: InteractionOutline
- type: Physics
bodyType: Dynamic
- type: Foldable
folded: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
- type: constructionGraph
id: TableFoldingGraph
start: start
graph:
- node: start
actions:
- !type:DestroyEntity {}
edges:

- to: TableFolding
steps:
- material: Plastic
amount: 4
doAfter: 1
- material: MetalRod
amount: 4

- node: TableFolding
entity: TableFolding
edges:
- to: start
completed:
- !type:SpawnPrototype
prototype: SheetPlastic1
amount: 4
- !type:SpawnPrototype
prototype: PartRodMetal1
amount: 4
steps:
- tool: Screwing
doAfter: 2
18 changes: 18 additions & 0 deletions Resources/Prototypes/_NF/Recipes/Construction/furniture.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1126,3 +1126,21 @@
canBuildInImpassable: false
conditions:
- !type:TileNotBlocked

# Folding table
- type: construction
id: TableFolding
name: folding table
description: A table, but foldable.
graph: TableFoldingGraph
startNode: start
targetNode: TableFolding
category: construction-category-furniture
icon:
sprite: _NF/Structures/Furniture/folding_table.rsi
state: folding
objectType: Structure
placementMode: SnapgridCenter
canBuildInImpassable: false
conditions:
- !type:TileNotBlocked
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Taken from Beestation at commit https://github.com/BeeStation/BeeStation-Hornet/commit/9a035f9365bcb74ac40fbe79c74c43c4c80cc1e4",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "folding"
},
{
"name": "folding_folded"
},
{
"name": "inhand-left",
"directions": 4
},
{
"name": "inhand-right",
"directions": 4
}
]
}
Loading