From 5c50b1f6ed6c0fc683fcb18e856af68f1e676b18 Mon Sep 17 00:00:00 2001 From: Paul Ritter Date: Fri, 5 Mar 2021 01:08:38 +0100 Subject: [PATCH] Serialization v3 content PR (#3491) * serv3 in shared pt 1 * beginning of deepclone api * progress in implementing ideepclone & serv3 in content * adds target * its cant hurt you it cant hurt you * more changes to content.server * adds dataclasses * almost there * renamed & edited entry * finishes refactoring content to use serv3 * gasmixture runtimes, next: reagentunit * fucin hell that was an annoying one * adds flags * fixes some yaml errors * removes comment * fixes generic components for now * removes todo actually clones values my god paul fixes bug involving resolving custom data classes from other proj renames dataclass fixes spritecomp adds WithFormat.Constants support * adds deepclone to ResistanceSet * adds a bunch of deepclone implementations adds a deepclone analyzer (TODO) adds a deep clone fallback for classes & structs * fixes a bunch of runtimes * adds deepclone to entityuid * adds generator to sln * gets rid of warnings * fixes * argh * componentdata refactors * more deepclone impl * heck me i reworked all of content deepclone * renames custom dataclasstarget * misc * reworks prototypes * deepclone nuke * renamed customdataclass attribute * fixes everything * misc fixed * the killcommit * getting there * changed yamlfieldattribute namespace * adds back iselfserialize * renames everything to data(field/definition) * ouch * Fix most errors on content * Fix more errors in content * Fix some components * work on tests * fixes some customdataclasses * fuggin shit * yes * yeas * Remove data classes * Data field naming fixes * arg * Git resetti RobustToolbox * Merge fixes * General fixes * Fix startup serialization errors * Fix DamageContainerPrototype when supported classes or types are null * Implement construction graph step type serializer * Fix up construction serialization * Fix up construction serialization part 2 * Fix null list in technology database component * Fix body serialization * Fix entity storage serialization * Fix actions serialization * Fix AI serialization * Fix reaction serialization * Fix body serialization * Fix grid atmosphere serialization * Rename IServ3Manager to ISerializationManager * Convert every non generic serializer to the new format, general fixes * Serialization and body system fix * pushinheritance fix * Update all prototypes to have a parent and have consistent id/parent properties * Merge fixes * smh my head * cuddling slaps * Content commit for engine PR * stuff * more fixes * argh * yes even you are fixed * changelog fixes * fixes seeds * argh * Test fixes * Add writing for alert order prototype * Fix alert order writing * FIX * its been alot ok * Fix the rest of the visualizers * Fix server alerts component tests * Fix alert prototype tests not using the read value * Fix alert prototype tests initializing serialization multiple times * THIS IS AN AMERICAN CODEBASE GOD BLESS THE USA * Add ImplicitDataDefinitionForInheritors to IMechanismBehavior Fixes the behaviors not being found * Fix NRE in strap component Good night to the 1 buckle optimization * Fix clothing component slot flags serialization tag * Fix body component in all components test * Merge fixes * ffs * Make construction graph prototype use serialization hooks * human yaml linted * a * Do the thing for construction * stuff * a * monke see yaml linter * LINT HARDER * Remove redundant todo * yes * Add skip hook argument to readers and copiers * we gamin * test/datafield fixes * adds more verbose validation * moves linter to action * Improve construction graph step type serializer error message * Fix ammo box component NRE * gamin * some updates to the linter * yes * removes that test * misc fixes * array fix priority fix misc fixes * adds proper info the validation * adds alwaysrelevant usa * Make yaml linter take half as long to run (~50% less) * Make yaml linter 5 times faster (~80% less execution time) * based vera being based * fixes mapsaving * warning cleanup & moves surpressor * removes old msbuild targets * Revert "Make yaml linter 5 times faster (~80% less execution time)" This reverts commit 3e6091359a26252c3e98828199553de668031c63. * Add -nowarn to yaml linter run configuration * Improve yaml linter message feedback * Make dependencies an argument instead of a property on the serialization manager * yamllinting slaps * Clean up type serializers * Move yaml linter code to its own method * Fix yaml errors * Change yaml linter action name and remove -nowarn * yaml linter please shut * Git resetti robust toolbox Co-authored-by: Paul Co-authored-by: DrSmugleaf --- .github/workflows/yaml-linter.yml | 28 +++ Content.Client/Changelog/ChangelogManager.cs | 47 ++-- Content.Client/Content.Client.csproj | 1 + .../Components/Atmos/FireVisualizer.cs | 30 +-- .../Components/Atmos/GasAnalyzerVisualizer.cs | 11 +- .../Components/Atmos/GasCanisterVisualizer.cs | 12 +- .../Atmos/Piping/GasFilterVisualizer.cs | 15 +- .../Atmos/Piping/PipeConnectorVisualizer.cs | 21 +- .../Components/Atmos/Piping/PipeVisualizer.cs | 23 +- .../Components/Atmos/Piping/PumpVisualizer.cs | 16 +- .../Atmos/Piping/SiphonVisualizer.cs | 18 +- .../Components/Atmos/Piping/VentVisualizer.cs | 20 +- .../Components/Atmos/VaporVisualizer.cs | 34 ++- .../Cargo/GalacticMarketComponent.cs | 2 +- .../Components/Chemistry/FoamVisualizer.cs | 35 ++- .../Components/ClickableComponent.cs | 33 +-- .../ClientEntitySpawnerComponent.cs | 14 +- .../Components/Clothing/ClothingComponent.cs | 22 +- .../Components/ComputerVisualizer.cs | 30 +-- .../Components/Conveyor/ConveyorVisualizer.cs | 13 +- .../Conveyor/TwoWayLeverVisualizer.cs | 13 +- .../Components/Crayon/CrayonComponent.cs | 1 + .../Disposal/DisposalUnitVisualizer.cs | 69 +++--- .../Components/Disposal/DisposalVisualizer.cs | 13 +- .../Components/Doors/AirlockVisualizer.cs | 42 ++-- .../Explosion/ClusterFlashVisualizer.cs | 11 +- .../Components/Fluids/SprayVisualizer.cs | 18 +- .../Gravity/GravityGeneratorVisualizer.cs | 43 ++-- .../HUD/Inventory/ClientInventoryComponent.cs | 3 +- .../IconSmoothing/IconSmoothComponent.cs | 20 +- .../Instruments/InstrumentComponent.cs | 21 +- .../Interactable/MultiToolComponent.cs | 11 +- .../Interactable/WelderComponent.cs | 4 - .../Components/Items/ItemComponent.cs | 20 +- .../Kitchen/KitchenSpikeComponent.cs | 2 +- .../Components/LightBehaviourComponent.cs | 147 ++++++------- .../Components/Mobs/CameraRecoilComponent.cs | 3 +- .../Components/Mobs/DamageStateVisualizer.cs | 36 +++- .../Morgue/CrematoriumVisualizer.cs | 28 +-- .../Components/Morgue/MorgueVisualizer.cs | 34 +-- .../Movement/HandTeleporterVisualizer.cs | 2 + .../Nutrition/BurnStateVisualizer.cs | 26 +-- .../Nutrition/CreamPiedVisualizer.cs | 12 +- .../DrinkFoodContainerVisualizer2D.cs | 22 +- .../Nutrition/DrinkFoodVisualizer.cs | 9 +- .../Components/PDA/PDAVisualizer.cs | 13 +- .../ParticleAcceleratorPartVisualizer.cs | 30 ++- .../PoweredLightVisualizer.cs | 19 +- .../Components/Power/AutolatheVisualizer.cs | 5 +- .../Components/Power/PowerCellVisualizer.cs | 10 +- .../Components/Power/ProtolatheVisualizer.cs | 5 +- .../RadiationCollectorVisualizer.cs | 8 +- .../Recycling/RecyclerVisualizer.cs | 18 +- .../Components/ReinforcedWallComponent.cs | 12 +- .../Components/Sound/LoopingSoundComponent.cs | 19 +- .../GameObjects/Components/StackVisualizer.cs | 27 +-- .../Storage/BagOpenCloseVisualizer.cs | 16 +- .../Components/Storage/StorageVisualizer.cs | 24 +-- .../Trigger/TimerTriggerVisualizer.cs | 18 +- .../VendingMachineVisualizer.cs | 74 ++++--- .../Barrels/ClientMagazineBarrelComponent.cs | 11 +- .../Barrels/Visualizers/MagVisualizer.cs | 12 +- .../GameObjects/Components/WindowComponent.cs | 12 +- Content.Client/Research/LatheMenu.cs | 2 +- .../ContentIntegrationTest.cs | 1 + .../Tests/AI/BehaviorSetsTest.cs | 8 +- .../Tests/StorageFillTest.cs | 18 +- .../AI/Utility/AiLogic/UtilityAI.cs | 27 ++- .../AI/Utility/BehaviorSetPrototype.cs | 23 +- Content.Server/Actions/DebugInstant.cs | 13 +- Content.Server/Actions/DebugTargetEntity.cs | 7 +- Content.Server/Actions/DebugTargetPoint.cs | 7 +- Content.Server/Actions/DebugToggle.cs | 13 +- Content.Server/Actions/DisarmAction.cs | 16 +- Content.Server/Actions/GhostBoo.cs | 15 +- Content.Server/Actions/ScreamAction.cs | 29 ++- Content.Server/Alert/Click/RemoveCuffs.cs | 5 +- Content.Server/Alert/Click/ResistFire.cs | 11 +- Content.Server/Alert/Click/StopPiloting.cs | 9 +- Content.Server/Alert/Click/StopPulling.cs | 11 +- Content.Server/Alert/Click/Unbuckle.cs | 5 +- Content.Server/Atmos/GasMixture.cs | 41 ++-- .../Atmos/Reactions/GasReactionPrototype.cs | 35 ++- .../Atmos/Reactions/PlasmaFireReaction.cs | 7 +- .../Atmos/Reactions/TritiumFireReaction.cs | 7 +- Content.Server/Botany/Seed.cs | 203 ++++++++++-------- .../Chemistry/Metabolism/DefaultDrink.cs | 17 +- .../Chemistry/Metabolism/DefaultFood.cs | 23 +- .../PlantMetabolism/AdjustAttribute.cs | 13 +- .../Chemistry/PlantMetabolism/Clonexadone.cs | 7 +- .../Chemistry/PlantMetabolism/Diethylamine.cs | 7 +- .../PlantMetabolism/RobustHarvest.cs | 7 +- .../ReactionEffects/AreaReactionEffect.cs | 50 ++--- .../ExplosionReactionEffect.cs | 39 ++-- .../ReactionEffects/FoamAreaReactionEffect.cs | 2 + .../SmokeAreaReactionEffect.cs | 2 + .../TileReactions/CleanTileReaction.cs | 11 +- .../TileReactions/ExtinguishTileReaction.cs | 10 +- .../TileReactions/FlammableTileReaction.cs | 10 +- .../SpillIfPuddlePresentTileReaction.cs | 7 +- .../TileReactions/SpillTileReaction.cs | 20 +- .../Commands/GameTicking/TileWallsCommand.cs | 4 +- .../Construction/Completions/AddContainer.cs | 10 +- .../Construction/Completions/BuildComputer.cs | 10 +- .../Construction/Completions/BuildMachine.cs | 7 +- .../Construction/Completions/DeleteEntity.cs | 7 +- .../Completions/EmptyAllContainers.cs | 7 +- .../Completions/EmptyContainer.cs | 10 +- .../MachineFrameRegenerateProgress.cs | 6 +- .../Construction/Completions/PlaySound.cs | 13 +- .../Construction/Completions/PopupUser.cs | 13 +- .../Construction/Completions/SetAnchor.cs | 10 +- .../Construction/Completions/SetStackCount.cs | 12 +- .../Construction/Completions/SnapToGrid.cs | 13 +- .../Completions/SpawnPrototype.cs | 14 +- .../Construction/Completions/SpriteChange.cs | 13 +- .../Completions/SpriteStateChange.cs | 13 +- .../Completions/VisualizerDataInt.cs | 13 +- .../Construction/Conditions/AllWiresCut.cs | 10 +- .../Conditions/ComponentInTile.cs | 13 +- .../Construction/Conditions/ContainerEmpty.cs | 13 +- .../Construction/Conditions/DoorWelded.cs | 10 +- .../Construction/Conditions/EntityAnchored.cs | 10 +- .../Conditions/MachineFrameComplete.cs | 5 +- .../Conditions/ToiletLidClosed.cs | 7 +- .../Construction/Conditions/WirePanel.cs | 10 +- Content.Server/Content.Server.csproj | 1 + .../Components/AI/AiFactionPrototype.cs | 22 +- .../Components/AI/AiFactionTagComponent.cs | 28 +-- .../Components/Access/AccessComponent.cs | 16 +- .../Access/AccessReaderComponent.cs | 25 +-- .../Components/Access/IdCardComponent.cs | 14 +- .../Access/PresetIdCardComponent.cs | 9 +- .../ActionBlocking/HandcuffComponent.cs | 66 +++--- .../Components/AnchorableComponent.cs | 11 +- .../Arcade/SpaceVillainArcadeComponent.cs | 46 ++-- .../Components/Atmos/AirtightComponent.cs | 31 ++- .../Components/Atmos/BreathToolComponent.cs | 11 +- .../Components/Atmos/FlammableComponent.cs | 11 +- .../Components/Atmos/GasCanisterComponent.cs | 24 +-- .../Atmos/GasMixtureHolderComponent.cs | 13 +- .../Components/Atmos/GasTankComponent.cs | 31 ++- .../Atmos/GridAtmosphereComponent.cs | 145 +++++++------ .../Atmos/MovedByPressureComponent.cs | 13 +- .../Atmos/Piping/GasFilterComponent.cs | 39 ++-- .../Atmos/Piping/GasGeneratorComponent.cs | 25 +-- .../Atmos/Piping/Pumps/BasePumpComponent.cs | 18 +- .../Piping/Pumps/PressurePumpComponent.cs | 18 +- .../Atmos/Piping/Pumps/VolumePumpComponent.cs | 13 +- .../Atmos/Piping/Scrubbers/PressureSiphon.cs | 15 +- .../Piping/Vents/PressureVentComponent.cs | 19 +- .../Atmos/PressureProtectionComponent.cs | 16 +- .../Components/AtmosPlaqueComponent.cs | 12 +- .../Components/BarSign/BarSignComponent.cs | 9 +- .../Components/BarSign/BarSignPrototype.cs | 58 ++--- .../Components/Body/Behavior/LiverBehavior.cs | 17 +- .../Components/Body/Behavior/LungBehavior.cs | 49 ++--- .../Body/Behavior/MechanismBehavior.cs | 3 - .../Body/Behavior/StomachBehavior.cs | 16 +- .../Body/Circulatory/BloodstreamComponent.cs | 18 +- .../Body/Surgery/SurgeryToolComponent.cs | 16 +- .../Components/Botany/PlantHolderComponent.cs | 8 +- .../Components/Botany/ProduceComponent.cs | 30 ++- .../Components/Botany/SeedComponent.cs | 22 +- .../Components/Buckle/BuckleComponent.cs | 21 +- .../Components/Cargo/CargoConsoleComponent.cs | 14 +- .../Chemistry/ChemMasterComponent.cs | 3 + .../FoamSolutionAreaEffectComponent.cs | 10 +- .../Chemistry/HyposprayComponent.cs | 18 +- .../Components/Chemistry/InjectorComponent.cs | 23 +- .../Components/Chemistry/PillComponent.cs | 34 ++- .../Chemistry/ReagentDispenserComponent.cs | 14 +- .../Chemistry/ReagentTankComponent.cs | 16 +- .../Chemistry/RehydratableComponent.cs | 13 +- .../Chemistry/SolutionTransferComponent.cs | 35 +-- .../Components/Chemistry/VaporComponent.cs | 10 +- .../Components/CleanableComponent.cs | 11 +- .../Components/ComputerComponent.cs | 9 +- .../Components/ConfigurationComponent.cs | 44 ++-- .../Construction/ComputerBoardComponent.cs | 10 +- .../Construction/ConstructionComponent.cs | 16 +- .../Construction/MachineBoardComponent.cs | 42 ++-- .../Construction/MachineComponent.cs | 9 +- .../Construction/MachinePartComponent.cs | 16 +- .../Construction/WelderRefinableComponent.cs | 17 +- .../Components/Conveyor/ConveyorComponent.cs | 14 +- .../GameObjects/Components/CrayonComponent.cs | 21 +- .../Culinary/SliceableFoodComponent.cs | 39 ++-- .../Components/Culinary/UtensilComponent.cs | 34 +-- .../DamageOnHighSpeedImpactComponent.cs | 28 ++- .../Damage/DamageOnLandComponent.cs | 20 +- .../Damage/DamageOnToolInteractComponent.cs | 15 +- .../Damage/DamageOtherOnHitComponent.cs | 18 +- .../Destructible/DestructibleComponent.cs | 13 +- .../ChangeConstructionNodeBehavior.cs | 9 +- .../Thresholds/Behaviors/DoActsBehavior.cs | 19 +- .../Behaviors/EmptyAllContainersBehaviour.cs | 7 +- .../Thresholds/Behaviors/GibBehavior.cs | 10 +- .../Behaviors/IThresholdBehavior.cs | 3 +- .../Thresholds/Behaviors/PlaySoundBehavior.cs | 10 +- .../Behaviors/PlaySoundCollectionBehavior.cs | 11 +- .../Behaviors/SpawnEntitiesBehavior.cs | 9 +- .../Thresholds/Behaviors/SpillBehavior.cs | 5 +- .../Destructible/Thresholds/MinMax.cs | 13 +- .../Destructible/Thresholds/Threshold.cs | 26 +-- .../Thresholds/Triggers/AndTrigger.cs | 9 +- .../Thresholds/Triggers/DamageClassTrigger.cs | 11 +- .../Thresholds/Triggers/DamageTrigger.cs | 9 +- .../Thresholds/Triggers/DamageTypeTrigger.cs | 11 +- .../Thresholds/Triggers/IThresholdTrigger.cs | 3 +- .../Thresholds/Triggers/OrTrigger.cs | 9 +- .../Disposal/DisposalBendComponent.cs | 11 +- .../Disposal/DisposalHolderComponent.cs | 13 +- .../Disposal/DisposalJunctionComponent.cs | 10 +- .../Disposal/DisposalMailingUnitComponent.cs | 44 +--- .../Disposal/DisposalTubeComponent.cs | 11 +- .../Disposal/DisposalUnitComponent.cs | 46 ++-- .../Components/Doors/ServerDoorComponent.cs | 36 ++-- .../Explosion/ClusterFlashComponent.cs | 36 ++-- .../Explosion/ExplosiveComponent.cs | 24 +-- .../Explosion/FlashExplosiveComponent.cs | 26 +-- .../ExtinguisherCabinetComponent.cs | 12 +- .../Components/Fluids/BucketComponent.cs | 13 +- .../Components/Fluids/MopComponent.cs | 31 ++- .../Components/Fluids/PuddleComponent.cs | 32 ++- .../Components/Fluids/SprayComponent.cs | 43 ++-- .../Gravity/GravityGeneratorComponent.cs | 17 +- .../Components/Headset/HeadsetComponent.cs | 20 +- .../Instruments/InstrumentComponent.cs | 23 +- .../Interactable/HandheldLightComponent.cs | 21 +- .../Interactable/MatchstickComponent.cs | 15 +- .../Interactable/MultitoolComponent.cs | 53 ++--- .../Interactable/TilePryingComponent.cs | 9 +- .../Components/Interactable/ToolComponent.cs | 35 +-- .../Interactable/WelderComponent.cs | 8 +- .../Items/Clothing/ClothingComponent.cs | 38 +--- .../Components/Items/DiceComponent.cs | 24 ++- .../Items/FloorTileItemComponent.cs | 10 +- .../Components/Items/RCD/RCDAmmoComponent.cs | 11 +- .../Components/Items/RCD/RCDComponent.cs | 14 +- .../Items/Storage/EntityStorageComponent.cs | 42 ++-- .../Components/Items/Storage/ItemComponent.cs | 10 +- .../Items/Storage/SecretStashComponent.cs | 18 +- .../Storage/SecureEntityStorageComponent.cs | 13 +- .../Items/Storage/ServerStorageComponent.cs | 23 +- .../Items/Storage/StorageCounterComponent.cs | 12 +- .../Items/Storage/StorageFillComponent.cs | 42 ++-- .../Components/Items/ToysComponent.cs | 8 +- .../Kitchen/ButcherableComponent.cs | 9 +- .../Components/Kitchen/JuiceableComponent.cs | 10 +- .../Kitchen/KitchenSpikeComponent.cs | 2 +- .../Components/Kitchen/MicrowaveComponent.cs | 27 +-- .../Kitchen/ReagentGrinderComponent.cs | 13 +- .../MachineLinking/SignalReceiverComponent.cs | 9 +- .../MachineLinking/SignalSwitchComponent.cs | 10 +- .../SignalTransmitterComponent.cs | 86 ++++---- .../Components/MagbootsComponent.cs | 5 +- .../Markers/ConditionalSpawnerComponent.cs | 13 +- .../Components/Markers/SpawnPointComponent.cs | 13 +- .../Markers/TimedSpawnerComponent.cs | 28 ++- .../Markers/TrashSpawnerComponent.cs | 12 +- .../Components/Markers/WarpPointComponent.cs | 11 +- .../Components/Medical/CloningPodComponent.cs | 12 +- .../Components/Medical/HealingComponent.cs | 11 +- .../Metabolism/MetabolismComponent.cs | 38 ++-- .../Components/Mining/PickaxeComponent.cs | 15 +- .../Components/Mobs/MindComponent.cs | 15 +- .../Morgue/MorgueEntityStorageComponent.cs | 12 +- .../Movement/AiControllerComponent.cs | 20 +- .../Components/Movement/ClimbableComponent.cs | 12 +- .../Movement/ShuttleControllerComponent.cs | 12 +- .../Components/Movement/SlipperyComponent.cs | 10 +- .../NodeContainer/NodeContainerComponent.cs | 11 +- .../NodeContainer/Nodes/AdjacentNode.cs | 2 + .../Components/NodeContainer/Nodes/Node.cs | 15 +- .../NodeContainer/Nodes/PipeNode.cs | 14 +- .../Components/Nutrition/DrinkComponent.cs | 25 +-- .../Components/Nutrition/FoodComponent.cs | 55 ++--- .../Nutrition/FoodContainerComponent.cs | 15 +- .../Components/Nutrition/HungerComponent.cs | 12 +- .../Components/Nutrition/SmokingComponent.cs | 14 +- .../Components/Nutrition/ThirstComponent.cs | 11 +- .../Observer/GhostOnMoveComponent.cs | 11 +- .../Observer/GhostRoles/GhostRoleComponent.cs | 15 +- .../GhostRoleMobSpawnerComponent.cs | 24 +-- .../ParticleAcceleratorControlBoxComponent.cs | 37 ++-- .../PA/ParticleAcceleratorEmitterComponent.cs | 12 +- .../Components/PDA/PDAComponent.cs | 13 +- .../Components/PlaceableSurfaceComponent.cs | 20 +- .../Pointing/PointingArrowComponent.cs | 24 +-- .../Pointing/RoguePointingArrowComponent.cs | 24 +-- .../Components/Portal/PortalComponent.cs | 28 +-- .../Components/Portal/TeleporterComponent.cs | 41 ++-- .../PowerProviderComponent.cs | 11 +- .../PowerReceiverComponent.cs | 23 +- .../PowerReceiverUsers/BaseCharger.cs | 15 +- .../EmergencyLightComponent.cs | 19 +- .../PowerReceiverUsers/LightBulbComponent.cs | 17 +- .../PoweredLightComponent.cs | 31 +-- .../Power/BaseNetConnectorComponent.cs | 13 +- .../Components/Power/BatteryComponent.cs | 21 +- .../Components/Power/PowerCellComponent.cs | 9 +- .../Power/PowerCellSlotComponent.cs | 29 ++- .../BatteryDischargerComponent.cs | 10 +- .../BatteryStorageComponent.cs | 11 +- .../PowerConsumerComponent.cs | 13 +- .../PowerSupplierComponent.cs | 9 +- .../PowerNetComponents/SolarPanelComponent.cs | 10 +- .../Components/Power/WireComponent.cs | 15 +- .../Components/Power/WirePlacerComponent.cs | 15 +- .../ChemicalInjectionProjectileComponent.cs | 15 +- .../Projectiles/FlashProjectileComponent.cs | 15 +- .../Projectiles/HitscanComponent.cs | 33 ++- .../Projectiles/ProjectileComponent.cs | 22 +- .../StunnableProjectileComponent.cs | 19 +- .../Radio/HandheldRadioComponent.cs | 20 +- .../Components/RandomPottedPlantComponent.cs | 12 +- .../Components/RandomSpriteColorComponent.cs | 16 +- .../Components/RandomSpriteStateComponent.cs | 11 +- .../Recycling/RecyclableComponent.cs | 22 +- .../Components/Recycling/RecyclerComponent.cs | 18 +- .../Components/RepairableComponent.cs | 16 +- .../Components/Research/LatheComponent.cs | 6 +- .../Research/LatheDatabaseComponent.cs | 13 +- .../Research/MaterialStorageComponent.cs | 12 +- .../Research/ProtolatheDatabaseComponent.cs | 1 + .../Research/ResearchPointSourceComponent.cs | 12 +- .../Research/ResearchServerComponent.cs | 12 +- .../Rotatable/FlippableComponent.cs | 15 +- .../Rotatable/RotatableComponent.cs | 9 +- .../Singularity/EmitterComponent.cs | 29 +-- .../Sound/EmitSoundOnThrowComponent.cs | 11 +- .../Sound/EmitSoundOnUseComponent.cs | 16 +- .../Sound/FootstepModifierComponent.cs | 8 +- .../StationEvents/RadiationPulseComponent.cs | 34 ++- .../Components/Strap/StrapComponent.cs | 44 ++-- .../Temperature/TemperatureComponent.cs | 28 +-- .../Components/Timing/UseDelayComponent.cs | 11 +- .../OnUseTimerTriggerComponent.cs | 12 +- .../VendingMachineComponent.cs | 23 +- .../Components/Weapon/Melee/FlashComponent.cs | 26 +-- .../Melee/MeleeChemicalInjectorComponent.cs | 15 +- .../Weapon/Melee/MeleeWeaponComponent.cs | 55 +++-- .../Weapon/Melee/StunbatonComponent.cs | 16 +- .../Ranged/Ammunition/AmmoBoxComponent.cs | 33 +-- .../Weapon/Ranged/Ammunition/AmmoComponent.cs | 59 +++-- .../Ranged/Ammunition/AmmoComponentData.cs | 12 ++ .../Ammunition/ChemicalAmmoComponent.cs | 11 +- .../Ammunition/RangedMagazineComponent.cs | 21 +- .../Ranged/Ammunition/SpeedLoaderComponent.cs | 23 +- .../Barrels/BoltActionBarrelComponent.cs | 36 ++-- .../Ranged/Barrels/PumpBarrelComponent.cs | 42 ++-- .../Ranged/Barrels/RevolverBarrelComponent.cs | 68 +++--- .../Barrels/ServerBatteryBarrelComponent.cs | 34 ++- .../Barrels/ServerMagazineBarrelComponent.cs | 52 ++--- .../Barrels/ServerRangedBarrelComponent.cs | 141 ++++++------ .../Ranged/ServerRangedWeaponComponent.cs | 17 +- .../GameObjects/Components/WindowComponent.cs | 16 +- .../GameObjects/Components/WiresComponent.cs | 20 +- Content.Server/Holiday/Greet/Custom.cs | 10 +- Content.Server/Holiday/HolidayPrototype.cs | 61 +++--- .../Holiday/Interfaces/IHolidayCelebrate.cs | 6 +- .../Holiday/Interfaces/IHolidayGreet.cs | 5 +- .../Interfaces/IHolidayShouldCelebrate.cs | 6 +- .../Holiday/ShouldCelebrate/Computus.cs | 14 +- .../Holiday/ShouldCelebrate/DayOfYear.cs | 11 +- .../Holiday/ShouldCelebrate/WeekdayInMonth.cs | 13 +- .../Interfaces/IGasReactionEffect.cs | 3 +- Content.Server/Jobs/JanitorSpecial.cs | 15 +- .../Objectives/Conditions/DieCondition.cs | 2 + .../Conditions/KillRandomPersonCondition.cs | 2 + .../Conditions/StayAliveCondition.cs | 2 + .../Objectives/Conditions/StealCondition.cs | 15 +- .../Interfaces/IObjectiveCondition.cs | 5 +- .../Interfaces/IObjectiveRequirement.cs | 4 +- .../Objectives/ObjectivePrototype.cs | 34 ++- .../IncompatibleConditionsRequirement.cs | 11 +- .../IncompatibleObjectivesRequirement.cs | 11 +- .../Requirements/TraitorRequirement.cs | 5 +- Content.Shared/Access/AccessLevelPrototype.cs | 34 ++- Content.Shared/Actions/ActionPrototype.cs | 29 +-- Content.Shared/Actions/BaseActionPrototype.cs | 81 +++---- Content.Shared/Actions/IActionBehavior.cs | 5 +- Content.Shared/Actions/IItemActionBehavior.cs | 3 +- Content.Shared/Actions/ItemActionPrototype.cs | 29 +-- Content.Shared/Alert/AlertOrderPrototype.cs | 66 ++++-- Content.Shared/Alert/AlertPrototype.cs | 64 +++--- Content.Shared/Alert/IAlertClick.cs | 4 +- Content.Shared/Atmos/GasPrototype.cs | 55 +++-- .../Audio/SoundCollectionPrototype.cs | 25 +-- .../Chemistry/DefaultMetabolizable.cs | 20 +- Content.Shared/Chemistry/ReactionPrototype.cs | 68 +++--- Content.Shared/Chemistry/ReagentPrototype.cs | 110 +++++----- Content.Shared/Chemistry/Solution.cs | 23 +- .../ArbitraryInsertConstructionGraphStep.cs | 15 +- .../ComponentConstructionGraphStep.cs | 12 +- .../ConstructionConditions/LowWallInTile.cs | 5 +- .../ConstructionConditions/NoWindowsInTile.cs | 5 +- .../ConstructionConditions/TileNotBlocked.cs | 13 +- .../ConstructionConditions/TileType.cs | 15 +- .../WallmountCondition.cs | 9 +- .../Construction/ConstructionGraphEdge.cs | 101 +-------- .../Construction/ConstructionGraphNode.cs | 39 +--- .../ConstructionGraphPrototype.cs | 32 ++- .../Construction/ConstructionGraphStep.cs | 22 +- .../ConstructionGraphStepTypeSerializer.cs | 76 +++++++ .../Construction/ConstructionPrototype.cs | 62 +++--- .../EntityInsertConstructionGraphStep.cs | 12 +- .../Construction/IConstructionCondition.cs | 3 +- Content.Shared/Construction/IEdgeCondition.cs | 3 +- Content.Shared/Construction/IGraphAction.cs | 3 +- .../MaterialConstructionGraphStep.cs | 19 +- .../MultipleTagsConstructionGraphStep.cs | 16 +- .../NestedConstructionGraphStep.cs | 31 +-- .../PrototypeConstructionGraphStep.cs | 12 +- .../Construction/TagConstructionGraphStep.cs | 12 +- .../Construction/ToolConstructionGraphStep.cs | 16 +- Content.Shared/Content.Shared.csproj | 1 + .../DamageContainerPrototype.cs | 28 ++- .../ResistanceSet/ResistanceSetPrototype.cs | 35 +-- .../Body/Behavior/IMechanismBehavior.cs | 5 +- .../Mechanism/SharedMechanismComponent.cs | 72 +++---- .../Property/BodyPartPropertyComponent.cs | 14 +- .../Body/Part/Property/ExtensionComponent.cs | 14 +- .../Body/Part/Property/LegComponent.cs | 14 +- .../Body/Part/SharedBodyPartComponent.cs | 37 ++-- .../Body/Preset/BodyPresetPrototype.cs | 27 ++- .../Components/Body/SharedBodyComponent.cs | 184 ++++++---------- .../Body/Template/BodyTemplatePrototype.cs | 67 +++--- .../Buckle/SharedBuckleComponent.cs | 11 +- .../Cargo/SharedGalacticMarketComponent.cs | 62 +++--- .../ReagentDispenserInventoryPrototype.cs | 22 +- .../SharedSolutionContainerComponent.cs | 22 +- .../Components/Damage/DamageableComponent.cs | 93 +++----- .../Components/Doors/SharedDoorComponent.cs | 58 ++--- .../Inventory/SharedInventoryComponent.cs | 10 +- .../Components/Materials/MaterialComponent.cs | 63 +++--- .../Medical/SharedCloningPodComponent.cs | 1 - .../Components/Mobs/ExaminerComponent.cs | 10 +- .../Components/Mobs/ItemActionsComponent.cs | 38 ++-- .../Components/Mobs/SharedActionsComponent.cs | 9 +- .../Mobs/SharedStunnableComponent.cs | 26 ++- .../Mobs/Speech/SharedEmotingComponent.cs | 11 +- .../Mobs/Speech/SharedSpeechComponent.cs | 13 +- .../Components/Mobs/State/BaseMobState.cs | 5 +- .../Components/Mobs/State/IMobState.cs | 3 +- .../Mobs/State/SharedMobStateComponent.cs | 19 +- .../MovementSpeedModifierComponent.cs | 19 +- .../Movement/SharedClimbableComponent.cs | 13 +- .../Movement/SharedSlipperyComponent.cs | 24 +-- .../Research/SharedLatheDatabaseComponent.cs | 55 ++--- .../SharedMaterialStorageComponent.cs | 17 +- .../SharedProtolatheDatabaseComponent.cs | 50 ++--- .../SharedTechnologyDatabaseComponent.cs | 51 +++-- .../Components/SharedCrayonComponent.cs | 32 ++- .../SharedExpendableLightComponent.cs | 33 ++- .../Components/SharedStackComponent.cs | 39 +--- .../Sound/SharedLoopingSoundComponent.cs | 29 ++- .../Storage/SharedStorableComponent.cs | 11 +- .../Components/Tag/TagComponent.cs | 27 +-- .../Melee/MeleeWeaponAnimationPrototype.cs | 76 ++++--- .../EntitySystems/ExamineSystemShared.cs | 1 + .../Interfaces/Chemistry/IMetabolizable.cs | 3 +- .../Chemistry/IPlantMetabolizable.cs | 5 +- .../Interfaces/Chemistry/IReactionEffect.cs | 5 +- .../Interfaces/Chemistry/ITileReaction.cs | 3 +- .../Kitchen/SharedKitchenSpikeComponent.cs | 15 +- Content.Shared/Maps/ContentTileDefinition.cs | 105 +++------ Content.Shared/Materials/Material.cs | 108 +++------- .../Prototypes/Cargo/CargoProductPrototype.cs | 53 ++--- Content.Shared/Prototypes/DatasetPrototype.cs | 22 +- .../Kitchen/MicrowaveMealRecipePrototype.cs | 47 ++-- .../PDA/UplinkStoreListingPrototype.cs | 45 ++-- Content.Shared/Prototypes/Tag/TagPrototype.cs | 22 +- .../Research/LatheRecipePrototype.cs | 46 ++-- .../Research/TechnologyPrototype.cs | 48 ++--- Content.Shared/Roles/AntagPrototype.cs | 27 +-- Content.Shared/Roles/JobPrototype.cs | 54 ++--- Content.Shared/Roles/JobSpecial.cs | 14 +- Content.Shared/Roles/StartingGearPrototype.cs | 55 ++--- Content.Shared/Stacks/StackPrototype.cs | 31 ++- .../Utility/EntityPrototypeHelpers.cs | 2 +- .../VendingMachineInventoryPrototype.cs | 44 ++-- Content.Tests/Content.Tests.csproj | 1 + .../Mobs/ServerAlertsComponentTests.cs | 2 + .../Server/Preferences/ServerDbSqliteTests.cs | 3 +- .../Shared/Alert/AlertManagerTests.cs | 2 + .../Shared/Alert/AlertOrderPrototypeTests.cs | 4 + .../Shared/Alert/AlertPrototypeTests.cs | 15 +- .../Chemistry/ReagentPrototype_Tests.cs | 9 +- .../Shared/Utility/RandomExtensionsTests.cs | 3 +- Content.YAMLLinter/Content.YAMLLinter.csproj | 20 ++ Content.YAMLLinter/Program.cs | 107 +++++++++ Resources/Prototypes/Actions/actions.yml | 12 +- Resources/Prototypes/Actions/item_actions.yml | 12 +- Resources/Prototypes/Alerts/alerts.yml | 12 +- .../Body/Mechanisms/basic_human_organs.yml | 7 - .../Body/Mechanisms/basic_tests.yml | 5 - .../Prototypes/Body/Parts/human_parts.yml | 2 +- .../Prototypes/Body/Parts/slime_parts.yml | 2 +- .../Prototypes/Catalog/Fills/Boxes/food.yml | 1 - .../Clothing/OuterClothing/hardsuits.yml | 1 + .../Constructible/Furniture/bookshelf.yml | 3 - .../Constructible/Furniture/potted_plants.yml | 1 - .../Constructible/Furniture/storage.yml | 2 +- .../Constructible/Piping/gascanisters.yml | 9 +- .../Constructible/Power/cargo_console.yml | 1 - .../Entities/Constructible/Power/wires.yml | 2 +- .../Specific/Engines/PA/base.yml | 1 - .../Specific/Engines/PA/particles.yml | 7 +- .../Specific/gravity_generator.yml | 9 +- .../Entities/Effects/chemistry_effects.yml | 2 - .../Entities/Mobs/NPCs/dummy_npcs.yml | 1 - .../Entities/Mobs/NPCs/simplemob.yml | 1 - .../Prototypes/Entities/Mobs/Player/human.yml | 1 - .../Prototypes/Entities/Mobs/Player/slime.yml | 1 - .../Entities/Mobs/Species/human.yml | 1 - .../Entities/Mobs/Species/slime.yml | 1 - .../Smokeables/Cigarettes/rolling_paper.yml | 3 - .../Entities/Objects/Consumable/drinks.yml | 1 - .../Entities/Objects/Consumable/food.yml | 20 +- .../Entities/Objects/Fun/instruments.yml | 2 +- .../Entities/Objects/Specific/chemistry.yml | 6 - .../Guns/Ammunition/Shotgun/cartridges.yml | 5 +- .../Weapons/Guns/Ammunition/Toy/boxes.yml | 4 +- .../Guns/Ammunition/Toy/cartridges.yml | 4 +- .../Weapons/Guns/Battery/battery_guns.yml | 2 +- .../Objects/Weapons/Guns/LMGs/lmgs.yml | 1 - .../Weapons/Guns/Launchers/launchers.yml | 1 - .../Objects/Weapons/Guns/Pistols/pistols.yml | 2 - .../Weapons/Guns/Projectiles/projectiles.yml | 17 +- .../Objects/Weapons/Guns/Rifles/rifles.yml | 2 - .../Objects/Weapons/Guns/SMGs/smgs.yml | 1 - .../Weapons/Guns/Shotguns/shotguns.yml | 6 +- .../Prototypes/Reagents/Materials/glass.yml | 2 +- .../Reagents/Materials/materials.yml | 2 +- .../Prototypes/Reagents/Materials/metals.yml | 12 +- Resources/Prototypes/Reagents/chemicals.yml | 2 +- .../Recipes/Construction/Graphs/low_wall.yml | 8 +- Resources/Prototypes/Recipes/Lathes/sheet.yml | 6 +- Resources/Prototypes/Recipes/Lathes/tools.yml | 2 +- .../Roles/Jobs/Command/head_of_personnel.yml | 1 - .../Prototypes/Stacks/Materials/materials.yml | 2 +- Resources/Prototypes/Stacks/power_stacks.yml | 2 +- SpaceStation14.sln | 6 + 545 files changed, 4547 insertions(+), 6650 deletions(-) create mode 100644 .github/workflows/yaml-linter.yml create mode 100644 Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/AmmoComponentData.cs create mode 100644 Content.Shared/Construction/ConstructionGraphStepTypeSerializer.cs create mode 100644 Content.YAMLLinter/Content.YAMLLinter.csproj create mode 100644 Content.YAMLLinter/Program.cs diff --git a/.github/workflows/yaml-linter.yml b/.github/workflows/yaml-linter.yml new file mode 100644 index 0000000000..227ab7c1a8 --- /dev/null +++ b/.github/workflows/yaml-linter.yml @@ -0,0 +1,28 @@ +name: YAML Linter + +on: [push, pull_request] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup submodule + run: | + git submodule update --init --recursive + touch BuildChecker/DISABLE_SUBMODULE_AUTOUPDATE + - name: Pull engine updates + uses: space-wizards/submodule-dependency@v0.1.5 + - name: Update Engine Submodules + run: | + cd RobustToolbox/ + git submodule update --init --recursive + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 5.0.100 + - name: Install dependencies + run: dotnet restore + - name: Build + run: dotnet build --configuration Release --no-restore /nowarn /m + - name: Run Linter + run: dotnet run --project Content.YAMLLinter/Content.YAMLLinter.csproj --no-build diff --git a/Content.Client/Changelog/ChangelogManager.cs b/Content.Client/Changelog/ChangelogManager.cs index b6c5b7b04d..02ed7e1b42 100644 --- a/Content.Client/Changelog/ChangelogManager.cs +++ b/Content.Client/Changelog/ChangelogManager.cs @@ -7,8 +7,10 @@ using System.Threading.Tasks; using Robust.Shared.ContentPack; using Robust.Shared.IoC; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.Serialization.Markdown; using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; #nullable enable @@ -20,6 +22,7 @@ namespace Content.Client.Changelog public const string ForkId = "Wizards"; [Dependency] private readonly IResourceManager _resource = default!; + [Dependency] private readonly ISerializationManager _serialization = default!; public bool NewChangelogEntries { get; private set; } public int LastReadId { get; private set; } @@ -78,39 +81,41 @@ namespace Content.Client.Changelog if (yamlData.Documents.Count == 0) return new List(); - var serializer = YamlObjectSerializer.NewReader((YamlMappingNode) yamlData.Documents[0].RootNode); - - return serializer.ReadDataField>("Entries"); + var node = (MappingDataNode)yamlData.Documents[0].RootNode.ToDataNode(); + return _serialization.ReadValueOrThrow>(node["Entries"]); }); } - - public sealed class ChangelogEntry : IExposeData + [DataDefinition] + public sealed class ChangelogEntry : ISerializationHooks { + [DataField("id")] public int Id { get; private set; } - public string Author { get; private set; } = ""; - public DateTime Time { get; private set; } - public List Changes { get; private set; } = default!; - void IExposeData.ExposeData(ObjectSerializer serializer) + [field: DataField("author")] + public string Author { get; } = ""; + + [DataField("time")] private string _time = default!; + + public DateTime Time { get; private set; } + + [field: DataField("changes")] + public List Changes { get; } = default!; + + void ISerializationHooks.AfterDeserialization() { - Id = serializer.ReadDataField("id"); - Author = serializer.ReadDataField("author"); - Time = DateTime.Parse(serializer.ReadDataField("time"), null, DateTimeStyles.RoundtripKind); - Changes = serializer.ReadDataField>("changes"); + Time = DateTime.Parse(_time, null, DateTimeStyles.RoundtripKind); } } - public sealed class ChangelogChange : IExposeData + [DataDefinition] + public sealed class ChangelogChange : ISerializationHooks { + [DataField("type")] public ChangelogLineType Type { get; private set; } - public string Message { get; private set; } = ""; - void IExposeData.ExposeData(ObjectSerializer serializer) - { - Type = serializer.ReadDataField("type"); - Message = serializer.ReadDataField("message"); - } + [DataField("message")] + public string Message { get; private set; } = ""; } public enum ChangelogLineType diff --git a/Content.Client/Content.Client.csproj b/Content.Client/Content.Client.csproj index 5948fb4279..b18a998bc1 100644 --- a/Content.Client/Content.Client.csproj +++ b/Content.Client/Content.Client.csproj @@ -36,4 +36,5 @@ + diff --git a/Content.Client/GameObjects/Components/Atmos/FireVisualizer.cs b/Content.Client/GameObjects/Components/Atmos/FireVisualizer.cs index 0b837aad98..1a8da1956c 100644 --- a/Content.Client/GameObjects/Components/Atmos/FireVisualizer.cs +++ b/Content.Client/GameObjects/Components/Atmos/FireVisualizer.cs @@ -2,6 +2,7 @@ using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; @@ -10,9 +11,13 @@ namespace Content.Client.GameObjects.Components.Atmos [UsedImplicitly] public class FireVisualizer : AppearanceVisualizer { + [DataField("fireStackAlternateState")] private int _fireStackAlternateState = 3; + [DataField("normalState")] private string _normalState; + [DataField("alternateState")] private string _alternateState; + [DataField("sprite")] private string _sprite; public override void InitializeEntity(IEntity entity) @@ -25,31 +30,6 @@ namespace Content.Client.GameObjects.Components.Atmos sprite.LayerSetVisible(FireVisualLayers.Fire, false); } - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - - if (node.TryGetNode("sprite", out var sprite)) - { - _sprite = sprite.AsString(); - } - - if (node.TryGetNode("fireStackAlternateState", out var fireStack)) - { - _fireStackAlternateState = fireStack.AsInt(); - } - - if (node.TryGetNode("normalState", out var normalState)) - { - _normalState = normalState.AsString(); - } - - if (node.TryGetNode("alternateState", out var alternateState)) - { - _alternateState = alternateState.AsString(); - } - } - public override void OnChangeData(AppearanceComponent component) { base.OnChangeData(component); diff --git a/Content.Client/GameObjects/Components/Atmos/GasAnalyzerVisualizer.cs b/Content.Client/GameObjects/Components/Atmos/GasAnalyzerVisualizer.cs index dbad8ac1be..c642fa86af 100644 --- a/Content.Client/GameObjects/Components/Atmos/GasAnalyzerVisualizer.cs +++ b/Content.Client/GameObjects/Components/Atmos/GasAnalyzerVisualizer.cs @@ -1,6 +1,7 @@ using Content.Shared.GameObjects.Components.Atmos; using JetBrains.Annotations; using Robust.Client.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; @@ -9,17 +10,11 @@ namespace Content.Client.GameObjects.Components.Atmos [UsedImplicitly] public class GasAnalyzerVisualizer : AppearanceVisualizer { + [DataField("state_off")] private string _stateOff; + [DataField("state_working")] private string _stateWorking; - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - - _stateOff = node.GetNode("state_off").AsString(); - _stateWorking = node.GetNode("state_working").AsString(); - } - public override void OnChangeData(AppearanceComponent component) { base.OnChangeData(component); diff --git a/Content.Client/GameObjects/Components/Atmos/GasCanisterVisualizer.cs b/Content.Client/GameObjects/Components/Atmos/GasCanisterVisualizer.cs index 7d34455ce1..b513445401 100644 --- a/Content.Client/GameObjects/Components/Atmos/GasCanisterVisualizer.cs +++ b/Content.Client/GameObjects/Components/Atmos/GasCanisterVisualizer.cs @@ -1,6 +1,7 @@ using Content.Shared.GameObjects.Components.Atmos; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; @@ -8,18 +9,11 @@ namespace Content.Client.GameObjects.Components.Atmos { public class GasCanisterVisualizer : AppearanceVisualizer { + [DataField("stateConnected")] private string _stateConnected; + [DataField("pressureStates")] private string[] _statePressure = new string[] {"", "", "", ""}; - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - - _stateConnected = node.GetNode("stateConnected").AsString(); - for (int i = 0; i < _statePressure.Length; i++) - _statePressure[i] = node.GetNode("stateO" + i).AsString(); - } - public override void InitializeEntity(IEntity entity) { base.InitializeEntity(entity); diff --git a/Content.Client/GameObjects/Components/Atmos/Piping/GasFilterVisualizer.cs b/Content.Client/GameObjects/Components/Atmos/Piping/GasFilterVisualizer.cs index 18679ceff1..938c9d209f 100644 --- a/Content.Client/GameObjects/Components/Atmos/Piping/GasFilterVisualizer.cs +++ b/Content.Client/GameObjects/Components/Atmos/Piping/GasFilterVisualizer.cs @@ -3,22 +3,15 @@ using Content.Shared.GameObjects.Components.Atmos; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; -namespace Content.Client.GameObjects.Components.Atmos +namespace Content.Client.GameObjects.Components.Atmos.Piping { [UsedImplicitly] + [DataDefinition] public class GasFilterVisualizer : AppearanceVisualizer { - private string _filterEnabledState = default!; - - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - var serializer = YamlObjectSerializer.NewReader(node); - serializer.DataField(ref _filterEnabledState, "filterEnabledState", "gasFilterOn"); - } + [DataField("filterEnabledState")] private string _filterEnabledState = "gasFilterOn"; public override void InitializeEntity(IEntity entity) { diff --git a/Content.Client/GameObjects/Components/Atmos/Piping/PipeConnectorVisualizer.cs b/Content.Client/GameObjects/Components/Atmos/Piping/PipeConnectorVisualizer.cs index a2f9561ddd..dbdc1df5e9 100644 --- a/Content.Client/GameObjects/Components/Atmos/Piping/PipeConnectorVisualizer.cs +++ b/Content.Client/GameObjects/Components/Atmos/Piping/PipeConnectorVisualizer.cs @@ -9,26 +9,27 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using YamlDotNet.RepresentationModel; -namespace Content.Client.GameObjects.Components.Atmos +namespace Content.Client.GameObjects.Components.Atmos.Piping { [UsedImplicitly] - public class PipeConnectorVisualizer : AppearanceVisualizer + public class PipeConnectorVisualizer : AppearanceVisualizer, ISerializationHooks { - private string _baseState = string.Empty; + [DataField("rsi")] + private string _rsi = "Constructible/Atmos/pipe.rsi"; + + [DataField("baseState")] + private string _baseState = "pipeConnector"; private RSI? _connectorRsi; - public override void LoadData(YamlMappingNode node) + void ISerializationHooks.AfterDeserialization() { - base.LoadData(node); - var serializer = YamlObjectSerializer.NewReader(node); - - serializer.DataField(ref _baseState, "baseState", "pipeConnector"); - - var rsiString = SharedSpriteComponent.TextureRoot / serializer.ReadDataField("rsi", "Constructible/Atmos/pipe.rsi"); + var rsiString = SharedSpriteComponent.TextureRoot / _rsi; var resourceCache = IoCManager.Resolve(); + if (resourceCache.TryGetResource(rsiString, out RSIResource? rsi)) _connectorRsi = rsi.RSI; else diff --git a/Content.Client/GameObjects/Components/Atmos/Piping/PipeVisualizer.cs b/Content.Client/GameObjects/Components/Atmos/Piping/PipeVisualizer.cs index 90ec516dd0..bc5879eb67 100644 --- a/Content.Client/GameObjects/Components/Atmos/Piping/PipeVisualizer.cs +++ b/Content.Client/GameObjects/Components/Atmos/Piping/PipeVisualizer.cs @@ -1,4 +1,5 @@ #nullable enable +using System; using Content.Shared.GameObjects.Components.Atmos; using JetBrains.Annotations; using Robust.Client.GameObjects; @@ -8,29 +9,29 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Serialization; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; -namespace Content.Client.GameObjects.Components.Atmos +namespace Content.Client.GameObjects.Components.Atmos.Piping { /// /// Sets the state of the sprite based on what shape of pipe it is. /// [UsedImplicitly] - public class PipeVisualizer : AppearanceVisualizer + [DataDefinition] + public class PipeVisualizer : AppearanceVisualizer, ISerializationHooks { + [DataField("rsi")] private string _rsiString = "Constructible/Atmos/pipe.rsi"; private RSI? _pipeRSI; - public override void LoadData(YamlMappingNode node) + void ISerializationHooks.AfterDeserialization() { - base.LoadData(node); - var serializer = YamlObjectSerializer.NewReader(node); - - var rsiString = SharedSpriteComponent.TextureRoot / serializer.ReadDataField("rsi", "Constructible/Atmos/pipe.rsi"); + var rsiPath = SharedSpriteComponent.TextureRoot / _rsiString; var resourceCache = IoCManager.Resolve(); - if (resourceCache.TryGetResource(rsiString, out RSIResource? rsi)) + + if (resourceCache.TryGetResource(rsiPath, out RSIResource? rsi)) + { _pipeRSI = rsi.RSI; - else - Logger.Error($"{nameof(PipeVisualizer)} could not load to load RSI {rsiString}."); + } } public override void InitializeEntity(IEntity entity) diff --git a/Content.Client/GameObjects/Components/Atmos/Piping/PumpVisualizer.cs b/Content.Client/GameObjects/Components/Atmos/Piping/PumpVisualizer.cs index 6693626f5b..2e14e86eb1 100644 --- a/Content.Client/GameObjects/Components/Atmos/Piping/PumpVisualizer.cs +++ b/Content.Client/GameObjects/Components/Atmos/Piping/PumpVisualizer.cs @@ -2,23 +2,15 @@ using Content.Shared.GameObjects.Components.Atmos; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; -namespace Content.Client.GameObjects.Components.Atmos +namespace Content.Client.GameObjects.Components.Atmos.Piping { [UsedImplicitly] + [DataDefinition] public class PumpVisualizer : AppearanceVisualizer { - private string _pumpEnabledState; - - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - - var serializer = YamlObjectSerializer.NewReader(node); - serializer.DataField(ref _pumpEnabledState, "pumpEnabledState", "pumpPressureOn"); - } + [DataField("pumpEnabledState")] private string _pumpEnabledState = "pumpPressureOn"; public override void InitializeEntity(IEntity entity) { diff --git a/Content.Client/GameObjects/Components/Atmos/Piping/SiphonVisualizer.cs b/Content.Client/GameObjects/Components/Atmos/Piping/SiphonVisualizer.cs index 151ddf06ef..488d742950 100644 --- a/Content.Client/GameObjects/Components/Atmos/Piping/SiphonVisualizer.cs +++ b/Content.Client/GameObjects/Components/Atmos/Piping/SiphonVisualizer.cs @@ -1,24 +1,16 @@ +using Content.Shared.GameObjects.Components.Atmos; using JetBrains.Annotations; using Robust.Client.GameObjects; -using Content.Shared.GameObjects.Components.Atmos; using Robust.Shared.GameObjects; -using YamlDotNet.RepresentationModel; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; -namespace Content.Client.GameObjects.Components.Atmos +namespace Content.Client.GameObjects.Components.Atmos.Piping { [UsedImplicitly] + [DataDefinition] public class SiphonVisualizer : AppearanceVisualizer { - private string _siphonOnState; - - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - - var serializer = YamlObjectSerializer.NewReader(node); - serializer.DataField(ref _siphonOnState, "siphonOnState", "scrubOn"); - } + [DataField("siphonOnState")] private string _siphonOnState = "scrubOn"; public override void InitializeEntity(IEntity entity) { diff --git a/Content.Client/GameObjects/Components/Atmos/Piping/VentVisualizer.cs b/Content.Client/GameObjects/Components/Atmos/Piping/VentVisualizer.cs index 57323f447d..3d8790bb62 100644 --- a/Content.Client/GameObjects/Components/Atmos/Piping/VentVisualizer.cs +++ b/Content.Client/GameObjects/Components/Atmos/Piping/VentVisualizer.cs @@ -1,24 +1,16 @@ +using Content.Shared.GameObjects.Components.Atmos; using JetBrains.Annotations; using Robust.Client.GameObjects; -using Content.Shared.GameObjects.Components.Atmos; using Robust.Shared.GameObjects; -using YamlDotNet.RepresentationModel; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; -namespace Content.Client.GameObjects.Components.Atmos +namespace Content.Client.GameObjects.Components.Atmos.Piping { [UsedImplicitly] + [DataDefinition] public class VentVisualizer : AppearanceVisualizer { - private string _ventOnstate; - - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - - var serializer = YamlObjectSerializer.NewReader(node); - serializer.DataField(ref _ventOnstate, "ventOnState", "ventOn"); - } + [DataField("ventOnState")] private string _ventOnState = "ventOn"; public override void InitializeEntity(IEntity entity) { @@ -28,7 +20,7 @@ namespace Content.Client.GameObjects.Components.Atmos sprite.LayerMapReserveBlank(Layer.VentEnabled); var layer = sprite.LayerMapGet(Layer.VentEnabled); - sprite.LayerSetState(layer, _ventOnstate); + sprite.LayerSetState(layer, _ventOnState); } public override void OnChangeData(AppearanceComponent component) diff --git a/Content.Client/GameObjects/Components/Atmos/VaporVisualizer.cs b/Content.Client/GameObjects/Components/Atmos/VaporVisualizer.cs index b6ebbabad4..48d2c9431b 100644 --- a/Content.Client/GameObjects/Components/Atmos/VaporVisualizer.cs +++ b/Content.Client/GameObjects/Components/Atmos/VaporVisualizer.cs @@ -4,40 +4,32 @@ using JetBrains.Annotations; using Robust.Client.Animations; using Robust.Client.GameObjects; using Robust.Shared.Maths; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Client.GameObjects.Components.Atmos { [UsedImplicitly] - public class VaporVisualizer : AppearanceVisualizer + public class VaporVisualizer : AppearanceVisualizer, ISerializationHooks { private const string AnimationKey = "flick_animation"; + + [DataField("animation_time")] + private float _delay = 0.25f; + + [DataField("animation_state")] + private string _state = "chempuff"; + private Animation VaporFlick; - public override void LoadData(YamlMappingNode node) + void ISerializationHooks.AfterDeserialization() { - base.LoadData(node); - - var delay = 0.25f; - var state = "chempuff"; - - if (node.TryGetNode("animation_time", out var delayNode)) - { - delay = delayNode.AsFloat(); - } - - if (node.TryGetNode("animation_state", out var stateNode)) - { - state = stateNode.AsString(); - } - - VaporFlick = new Animation {Length = TimeSpan.FromSeconds(delay)}; + VaporFlick = new Animation {Length = TimeSpan.FromSeconds(_delay)}; { var flick = new AnimationTrackSpriteFlick(); VaporFlick.AnimationTracks.Add(flick); flick.LayerKey = VaporVisualLayers.Base; - flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame(state, 0f)); + flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame(_state, 0f)); } } diff --git a/Content.Client/GameObjects/Components/Cargo/GalacticMarketComponent.cs b/Content.Client/GameObjects/Components/Cargo/GalacticMarketComponent.cs index fde85e0c68..25eb0f1efa 100644 --- a/Content.Client/GameObjects/Components/Cargo/GalacticMarketComponent.cs +++ b/Content.Client/GameObjects/Components/Cargo/GalacticMarketComponent.cs @@ -22,7 +22,7 @@ namespace Content.Client.GameObjects.Components.Cargo base.HandleComponentState(curState, nextState); if (curState is not GalacticMarketState state) return; - _products.Clear(); + _productIds.Clear(); foreach (var productId in state.Products) { if (!_prototypeManager.TryIndex(productId, out CargoProductPrototype product)) diff --git a/Content.Client/GameObjects/Components/Chemistry/FoamVisualizer.cs b/Content.Client/GameObjects/Components/Chemistry/FoamVisualizer.cs index 47a1ba1825..bc78ab2b32 100644 --- a/Content.Client/GameObjects/Components/Chemistry/FoamVisualizer.cs +++ b/Content.Client/GameObjects/Components/Chemistry/FoamVisualizer.cs @@ -5,38 +5,31 @@ using JetBrains.Annotations; using Robust.Client.Animations; using Robust.Client.GameObjects; using Robust.Shared.Maths; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Client.GameObjects.Components.Chemistry { [UsedImplicitly] - public class FoamVisualizer : AppearanceVisualizer + public class FoamVisualizer : AppearanceVisualizer, ISerializationHooks { private const string AnimationKey = "foamdissolve_animation"; + + [DataField("animationTime")] + private float _delay = 0.6f; + + [DataField("animationState")] + private string _state = "foam-dissolve"; + private Animation _foamDissolve = new(); - public override void LoadData(YamlMappingNode node) + + void ISerializationHooks.AfterDeserialization() { - base.LoadData(node); - - var delay = 0.6f; - var state = "foam-dissolve"; - - if (node.TryGetNode("animationTime", out var delayNode)) - { - delay = delayNode.AsFloat(); - } - - if (node.TryGetNode("animationState", out var stateNode)) - { - state = stateNode.AsString(); - } - - _foamDissolve = new Animation {Length = TimeSpan.FromSeconds(delay)}; + _foamDissolve = new Animation {Length = TimeSpan.FromSeconds(_delay)}; var flick = new AnimationTrackSpriteFlick(); _foamDissolve.AnimationTracks.Add(flick); flick.LayerKey = FoamVisualLayers.Base; - flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame(state, 0f)); + flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame(_state, 0f)); } public override void OnChangeData(AppearanceComponent component) diff --git a/Content.Client/GameObjects/Components/ClickableComponent.cs b/Content.Client/GameObjects/Components/ClickableComponent.cs index 3cf8cae618..c9a695df18 100644 --- a/Content.Client/GameObjects/Components/ClickableComponent.cs +++ b/Content.Client/GameObjects/Components/ClickableComponent.cs @@ -6,7 +6,7 @@ using Robust.Client.Utility; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Maths; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Client.GameObjects.Components @@ -18,14 +18,7 @@ namespace Content.Client.GameObjects.Components [Dependency] private readonly IClickMapManager _clickMapManager = default!; - [ViewVariables] private DirBoundData _data = default!; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _data, "bounds", DirBoundData.Default); - } + [ViewVariables] [DataField("bounds")] private DirBoundData _data = DirBoundData.Default; /// /// Used to check whether a click worked. @@ -131,24 +124,16 @@ namespace Content.Client.GameObjects.Components return found; } - private sealed class DirBoundData : IExposeData + [DataDefinition] + public sealed class DirBoundData { - [ViewVariables] public Box2 All; - [ViewVariables] public Box2 North; - [ViewVariables] public Box2 South; - [ViewVariables] public Box2 East; - [ViewVariables] public Box2 West; + [ViewVariables] [DataField("all")] public Box2 All; + [ViewVariables] [DataField("north")] public Box2 North; + [ViewVariables] [DataField("south")] public Box2 South; + [ViewVariables] [DataField("east")] public Box2 East; + [ViewVariables] [DataField("west")] public Box2 West; public static DirBoundData Default { get; } = new(); - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(ref All, "all", default); - serializer.DataField(ref North, "north", default); - serializer.DataField(ref South, "south", default); - serializer.DataField(ref East, "east", default); - serializer.DataField(ref West, "west", default); - } } } } diff --git a/Content.Client/GameObjects/Components/ClientEntitySpawnerComponent.cs b/Content.Client/GameObjects/Components/ClientEntitySpawnerComponent.cs index 0bf9d0ea6f..f2224bc2f2 100644 --- a/Content.Client/GameObjects/Components/ClientEntitySpawnerComponent.cs +++ b/Content.Client/GameObjects/Components/ClientEntitySpawnerComponent.cs @@ -1,7 +1,7 @@ #nullable enable -using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; using System.Collections.Generic; +using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Client.GameObjects.Components { @@ -13,15 +13,9 @@ namespace Content.Client.GameObjects.Components { public override string Name => "ClientEntitySpawner"; - private List _prototypes = default!; + [DataField("prototypes")] private List _prototypes = new() { "HVDummyWire" }; - private List _entity = new(); - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _prototypes, "prototypes", new List { "HVDummyWire" }); - } + private readonly List _entity = new(); public override void Initialize() { diff --git a/Content.Client/GameObjects/Components/Clothing/ClothingComponent.cs b/Content.Client/GameObjects/Components/Clothing/ClothingComponent.cs index 306bb56e79..fcd17cb0f0 100644 --- a/Content.Client/GameObjects/Components/Clothing/ClothingComponent.cs +++ b/Content.Client/GameObjects/Components/Clothing/ClothingComponent.cs @@ -7,7 +7,7 @@ using Content.Shared.GameObjects.Components.Items; using Robust.Client.Graphics; using Robust.Shared.Containers; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Client.GameObjects.Components.Clothing @@ -17,13 +17,15 @@ namespace Content.Client.GameObjects.Components.Clothing [ComponentReference(typeof(IItemComponent))] public class ClothingComponent : ItemComponent { - private FemaleClothingMask _femaleMask; + [DataField("femaleMask")] + private FemaleClothingMask _femaleMask = FemaleClothingMask.UniformFull; public override string Name => "Clothing"; public override uint? NetID => ContentNetIDs.CLOTHING; private string? _clothingEquippedPrefix; [ViewVariables(VVAccess.ReadWrite)] + [DataField("ClothingPrefix")] public string? ClothingEquippedPrefix { get => _clothingEquippedPrefix; @@ -34,6 +36,8 @@ namespace Content.Client.GameObjects.Components.Clothing _clothingEquippedPrefix = value; + if(!Initialized) return; + if (!Owner.TryGetContainer(out IContainer? container)) return; if (!container.Owner.TryGetComponent(out ClientInventoryComponent? inventory)) @@ -45,6 +49,12 @@ namespace Content.Client.GameObjects.Components.Clothing } } + public override void Initialize() + { + base.Initialize(); + ClothingEquippedPrefix = ClothingEquippedPrefix; + } + [ViewVariables(VVAccess.ReadWrite)] public FemaleClothingMask FemaleMask { @@ -52,14 +62,6 @@ namespace Content.Client.GameObjects.Components.Clothing set => _femaleMask = value; } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _femaleMask, "femaleMask", FemaleClothingMask.UniformFull); - serializer.DataField(this, p => p.ClothingEquippedPrefix, "ClothingPrefix", null); - } - public (RSI rsi, RSI.StateId stateId)? GetEquippedStateInfo(EquipmentSlotDefines.SlotFlags slot) { if (RsiPath == null) diff --git a/Content.Client/GameObjects/Components/ComputerVisualizer.cs b/Content.Client/GameObjects/Components/ComputerVisualizer.cs index e1f48d51a5..d542b4822c 100644 --- a/Content.Client/GameObjects/Components/ComputerVisualizer.cs +++ b/Content.Client/GameObjects/Components/ComputerVisualizer.cs @@ -2,6 +2,7 @@ using Content.Shared.GameObjects.Components; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; @@ -10,37 +11,16 @@ namespace Content.Client.GameObjects.Components [UsedImplicitly] public sealed class ComputerVisualizer : AppearanceVisualizer { + [DataField("key")] private string KeyboardState = "generic_key"; + [DataField("screen")] private string ScreenState = "generic"; + [DataField("body")] private string BodyState = "computer"; + [DataField("bodyBroken")] private string BodyBrokenState = "broken"; private string ScreenBroken = "computer_broken"; - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - - if (node.TryGetNode("key", out var scalar)) - { - KeyboardState = scalar.AsString(); - } - - if (node.TryGetNode("screen", out scalar)) - { - ScreenState = scalar.AsString(); - } - - if (node.TryGetNode("body", out scalar)) - { - BodyState = scalar.AsString(); - } - - if (node.TryGetNode("bodyBroken", out scalar)) - { - BodyBrokenState = scalar.AsString(); - } - } - public override void InitializeEntity(IEntity entity) { base.InitializeEntity(entity); diff --git a/Content.Client/GameObjects/Components/Conveyor/ConveyorVisualizer.cs b/Content.Client/GameObjects/Components/Conveyor/ConveyorVisualizer.cs index 84cac3b021..c1ebda2be2 100644 --- a/Content.Client/GameObjects/Components/Conveyor/ConveyorVisualizer.cs +++ b/Content.Client/GameObjects/Components/Conveyor/ConveyorVisualizer.cs @@ -3,6 +3,7 @@ using Content.Shared.GameObjects.Components.Conveyor; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; @@ -11,8 +12,11 @@ namespace Content.Client.GameObjects.Components.Conveyor [UsedImplicitly] public class ConveyorVisualizer : AppearanceVisualizer { + [DataField("state_running")] private string _stateRunning; + [DataField("state_stopped")] private string _stateStopped; + [DataField("state_reversed")] private string _stateReversed; private void ChangeState(AppearanceComponent appearance) @@ -35,15 +39,6 @@ namespace Content.Client.GameObjects.Components.Conveyor sprite.LayerSetState(0, texture); } - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - - _stateRunning = node.GetNode("state_running").AsString(); - _stateStopped = node.GetNode("state_stopped").AsString(); - _stateReversed = node.GetNode("state_reversed").AsString(); - } - public override void InitializeEntity(IEntity entity) { base.InitializeEntity(entity); diff --git a/Content.Client/GameObjects/Components/Conveyor/TwoWayLeverVisualizer.cs b/Content.Client/GameObjects/Components/Conveyor/TwoWayLeverVisualizer.cs index c4880a4e44..df0e390060 100644 --- a/Content.Client/GameObjects/Components/Conveyor/TwoWayLeverVisualizer.cs +++ b/Content.Client/GameObjects/Components/Conveyor/TwoWayLeverVisualizer.cs @@ -2,6 +2,7 @@ using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; @@ -10,8 +11,11 @@ namespace Content.Client.GameObjects.Components.Conveyor [UsedImplicitly] public class TwoWayLeverVisualizer : AppearanceVisualizer { + [DataField("state_forward")] private string _stateForward; + [DataField("state_off")] private string _stateOff; + [DataField("state_reversed")] private string _stateReversed; private void ChangeState(AppearanceComponent appearance) @@ -34,15 +38,6 @@ namespace Content.Client.GameObjects.Components.Conveyor sprite.LayerSetState(0, texture); } - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - - _stateForward = node.GetNode("state_forward").AsString(); - _stateOff = node.GetNode("state_off").AsString(); - _stateReversed = node.GetNode("state_reversed").AsString(); - } - public override void InitializeEntity(IEntity entity) { base.InitializeEntity(entity); diff --git a/Content.Client/GameObjects/Components/Crayon/CrayonComponent.cs b/Content.Client/GameObjects/Components/Crayon/CrayonComponent.cs index 0b7b7e7ece..a58f67e691 100644 --- a/Content.Client/GameObjects/Components/Crayon/CrayonComponent.cs +++ b/Content.Client/GameObjects/Components/Crayon/CrayonComponent.cs @@ -5,6 +5,7 @@ using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Shared.GameObjects; using Robust.Shared.Localization; +using Robust.Shared.Maths; using Robust.Shared.Timing; using Robust.Shared.ViewVariables; diff --git a/Content.Client/GameObjects/Components/Disposal/DisposalUnitVisualizer.cs b/Content.Client/GameObjects/Components/Disposal/DisposalUnitVisualizer.cs index 9a82dd94c6..3376101ef5 100644 --- a/Content.Client/GameObjects/Components/Disposal/DisposalUnitVisualizer.cs +++ b/Content.Client/GameObjects/Components/Disposal/DisposalUnitVisualizer.cs @@ -3,28 +3,63 @@ using JetBrains.Annotations; using Robust.Client.Animations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using static Content.Shared.GameObjects.Components.Disposal.SharedDisposalUnitComponent; namespace Content.Client.GameObjects.Components.Disposal { [UsedImplicitly] - public class DisposalUnitVisualizer : AppearanceVisualizer + public class DisposalUnitVisualizer : AppearanceVisualizer, ISerializationHooks { private const string AnimationKey = "disposal_unit_animation"; + [DataField("state_anchored", required: true)] private string _stateAnchored; + + [DataField("state_unanchored", required: true)] private string _stateUnAnchored; + + [DataField("state_charging", required: true)] private string _stateCharging; + + [DataField("overlay_charging", required: true)] private string _overlayCharging; + + [DataField("overlay_ready", required: true)] private string _overlayReady; + + [DataField("overlay_full", required: true)] private string _overlayFull; + + [DataField("overlay_engaged", required: true)] private string _overlayEngaged; + + [DataField("state_flush", required: true)] private string _stateFlush; + [DataField("flush_sound", required: true)] + private string _flushSound; + + [DataField("flush_time", required: true)] + private float _flushTime; + private Animation _flushAnimation; + void ISerializationHooks.AfterDeserialization() + { + _flushAnimation = new Animation {Length = TimeSpan.FromSeconds(_flushTime)}; + + var flick = new AnimationTrackSpriteFlick(); + _flushAnimation.AnimationTracks.Add(flick); + flick.LayerKey = DisposalUnitVisualLayers.Base; + flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame(_stateFlush, 0)); + + var sound = new AnimationTrackPlaySound(); + _flushAnimation.AnimationTracks.Add(sound); + sound.KeyFrames.Add(new AnimationTrackPlaySound.KeyFrame(_flushSound, 0)); + } + private void ChangeState(AppearanceComponent appearance) { if (!appearance.TryGetData(Visuals.VisualState, out VisualState state)) @@ -106,34 +141,6 @@ namespace Content.Client.GameObjects.Components.Disposal } } - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - - _stateAnchored = node.GetNode("state_anchored").AsString(); - _stateUnAnchored = node.GetNode("state_unanchored").AsString(); - _stateCharging = node.GetNode("state_charging").AsString(); - _overlayCharging = node.GetNode("overlay_charging").AsString(); - _overlayReady = node.GetNode("overlay_ready").AsString(); - _overlayFull = node.GetNode("overlay_full").AsString(); - _overlayEngaged = node.GetNode("overlay_engaged").AsString(); - _stateFlush = node.GetNode("state_flush").AsString(); - - var flushSound = node.GetNode("flush_sound").AsString(); - var flushTime = node.GetNode("flush_time").AsFloat(); - - _flushAnimation = new Animation {Length = TimeSpan.FromSeconds(flushTime)}; - - var flick = new AnimationTrackSpriteFlick(); - _flushAnimation.AnimationTracks.Add(flick); - flick.LayerKey = DisposalUnitVisualLayers.Base; - flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame(_stateFlush, 0)); - - var sound = new AnimationTrackPlaySound(); - _flushAnimation.AnimationTracks.Add(sound); - sound.KeyFrames.Add(new AnimationTrackPlaySound.KeyFrame(flushSound, 0)); - } - public override void InitializeEntity(IEntity entity) { base.InitializeEntity(entity); diff --git a/Content.Client/GameObjects/Components/Disposal/DisposalVisualizer.cs b/Content.Client/GameObjects/Components/Disposal/DisposalVisualizer.cs index a4c691a5c2..8a22bb0acd 100644 --- a/Content.Client/GameObjects/Components/Disposal/DisposalVisualizer.cs +++ b/Content.Client/GameObjects/Components/Disposal/DisposalVisualizer.cs @@ -3,6 +3,7 @@ using Content.Shared.GameObjects.Components.Disposal; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; @@ -11,8 +12,11 @@ namespace Content.Client.GameObjects.Components.Disposal [UsedImplicitly] public class DisposalVisualizer : AppearanceVisualizer { + [DataField("state_free")] private string _stateFree; + [DataField("state_anchored")] private string _stateAnchored; + [DataField("state_broken")] private string _stateBroken; private void ChangeState(AppearanceComponent appearance) @@ -47,15 +51,6 @@ namespace Content.Client.GameObjects.Components.Disposal } } - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - - _stateFree = node.GetNode("state_free").AsString(); - _stateAnchored = node.GetNode("state_anchored").AsString(); - _stateBroken = node.GetNode("state_broken").AsString(); - } - public override void InitializeEntity(IEntity entity) { base.InitializeEntity(entity); diff --git a/Content.Client/GameObjects/Components/Doors/AirlockVisualizer.cs b/Content.Client/GameObjects/Components/Doors/AirlockVisualizer.cs index b3d46531d5..f32dc10c22 100644 --- a/Content.Client/GameObjects/Components/Doors/AirlockVisualizer.cs +++ b/Content.Client/GameObjects/Components/Doors/AirlockVisualizer.cs @@ -7,35 +7,35 @@ using JetBrains.Annotations; using Robust.Client.Animations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Client.GameObjects.Components.Doors { [UsedImplicitly] - public class AirlockVisualizer : AppearanceVisualizer + public class AirlockVisualizer : AppearanceVisualizer, ISerializationHooks { private const string AnimationKey = "airlock_animation"; + [DataField("open_sound", required: true)] + private string _openSound = default!; + + [DataField("close_sound", required: true)] + private string _closeSound = default!; + + [DataField("deny_sound", required: true)] + private string _denySound = default!; + + [DataField("animation_time")] + private float _delay = 0.8f; + private Animation CloseAnimation = default!; private Animation OpenAnimation = default!; private Animation DenyAnimation = default!; - public override void LoadData(YamlMappingNode node) + void ISerializationHooks.AfterDeserialization() { - base.LoadData(node); - - var delay = 0.8f; - - var openSound = node.GetNode("open_sound").AsString(); - var closeSound = node.GetNode("close_sound").AsString(); - var denySound = node.GetNode("deny_sound").AsString(); - if (node.TryGetNode("animation_time", out var yamlNode)) - { - delay = yamlNode.AsFloat(); - } - - CloseAnimation = new Animation {Length = TimeSpan.FromSeconds(delay)}; + CloseAnimation = new Animation {Length = TimeSpan.FromSeconds(_delay)}; { var flick = new AnimationTrackSpriteFlick(); CloseAnimation.AnimationTracks.Add(flick); @@ -54,10 +54,10 @@ namespace Content.Client.GameObjects.Components.Doors var sound = new AnimationTrackPlaySound(); CloseAnimation.AnimationTracks.Add(sound); - sound.KeyFrames.Add(new AnimationTrackPlaySound.KeyFrame(closeSound, 0)); + sound.KeyFrames.Add(new AnimationTrackPlaySound.KeyFrame(_closeSound, 0)); } - OpenAnimation = new Animation {Length = TimeSpan.FromSeconds(delay)}; + OpenAnimation = new Animation {Length = TimeSpan.FromSeconds(_delay)}; { var flick = new AnimationTrackSpriteFlick(); OpenAnimation.AnimationTracks.Add(flick); @@ -76,7 +76,7 @@ namespace Content.Client.GameObjects.Components.Doors var sound = new AnimationTrackPlaySound(); OpenAnimation.AnimationTracks.Add(sound); - sound.KeyFrames.Add(new AnimationTrackPlaySound.KeyFrame(openSound, 0)); + sound.KeyFrames.Add(new AnimationTrackPlaySound.KeyFrame(_openSound, 0)); } DenyAnimation = new Animation {Length = TimeSpan.FromSeconds(0.3f)}; @@ -88,7 +88,7 @@ namespace Content.Client.GameObjects.Components.Doors var sound = new AnimationTrackPlaySound(); DenyAnimation.AnimationTracks.Add(sound); - sound.KeyFrames.Add(new AnimationTrackPlaySound.KeyFrame(denySound, 0, () => AudioHelpers.WithVariation(0.05f))); + sound.KeyFrames.Add(new AnimationTrackPlaySound.KeyFrame(_denySound, 0, () => AudioHelpers.WithVariation(0.05f))); } } diff --git a/Content.Client/GameObjects/Components/Explosion/ClusterFlashVisualizer.cs b/Content.Client/GameObjects/Components/Explosion/ClusterFlashVisualizer.cs index 74112131a6..6b2e8e5e86 100644 --- a/Content.Client/GameObjects/Components/Explosion/ClusterFlashVisualizer.cs +++ b/Content.Client/GameObjects/Components/Explosion/ClusterFlashVisualizer.cs @@ -1,6 +1,7 @@ using Content.Shared.GameObjects.Components.Explosion; using JetBrains.Annotations; using Robust.Client.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; @@ -10,17 +11,9 @@ namespace Content.Client.GameObjects.Components.Explosion // ReSharper disable once InconsistentNaming public class ClusterFlashVisualizer : AppearanceVisualizer { + [DataField("state")] private string _state; - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - if (node.TryGetNode("state", out var state)) - { - _state = state.AsString(); - } - } - public override void OnChangeData(AppearanceComponent component) { base.OnChangeData(component); diff --git a/Content.Client/GameObjects/Components/Fluids/SprayVisualizer.cs b/Content.Client/GameObjects/Components/Fluids/SprayVisualizer.cs index fcea1c5257..ca8fcb4d76 100644 --- a/Content.Client/GameObjects/Components/Fluids/SprayVisualizer.cs +++ b/Content.Client/GameObjects/Components/Fluids/SprayVisualizer.cs @@ -1,6 +1,7 @@ using Content.Shared.GameObjects.Components.Fluids; using JetBrains.Annotations; using Robust.Client.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; @@ -9,24 +10,11 @@ namespace Content.Client.GameObjects.Components.Fluids [UsedImplicitly] public class SprayVisualizer : AppearanceVisualizer { + [DataField("safety_on_state")] private string _safetyOnState; + [DataField("safety_off_state")] private string _safetyOffState; - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - - if (node.TryGetNode("safety_on_state", out var safetyOn)) - { - _safetyOnState = safetyOn.AsString(); - } - - if (node.TryGetNode("safety_off_state", out var safetyOff)) - { - _safetyOffState = safetyOff.AsString(); - } - } - public override void OnChangeData(AppearanceComponent component) { base.OnChangeData(component); diff --git a/Content.Client/GameObjects/Components/Gravity/GravityGeneratorVisualizer.cs b/Content.Client/GameObjects/Components/Gravity/GravityGeneratorVisualizer.cs index 1b3f277f4b..b22fb039c0 100644 --- a/Content.Client/GameObjects/Components/Gravity/GravityGeneratorVisualizer.cs +++ b/Content.Client/GameObjects/Components/Gravity/GravityGeneratorVisualizer.cs @@ -6,14 +6,39 @@ using System; using System.Collections.Generic; using JetBrains.Annotations; using Robust.Shared.GameObjects; +using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using YamlDotNet.RepresentationModel; namespace Content.Client.GameObjects.Components.Gravity { [UsedImplicitly] - public class GravityGeneratorVisualizer : AppearanceVisualizer + public class GravityGeneratorVisualizer : AppearanceVisualizer, ISerializationHooks { - private readonly Dictionary _spriteMap = new(); + [DataField("spritemap")] + private Dictionary _rawSpriteMap = new(); + private Dictionary _spriteMap = new(); + + void ISerializationHooks.BeforeSerialization() + { + _rawSpriteMap = new Dictionary(); + foreach (var (status, sprite) in _spriteMap) + { + _rawSpriteMap.Add(status.ToString().ToLower(), sprite); + } + } + + void ISerializationHooks.AfterDeserialization() + { + // Get Sprites for each status + foreach (var status in (GravityGeneratorStatus[]) Enum.GetValues(typeof(GravityGeneratorStatus))) + { + if (_rawSpriteMap.TryGetValue(status.ToString().ToLower(), out var sprite)) + { + _spriteMap[status] = sprite; + } + } + } public override void InitializeEntity(IEntity entity) { @@ -26,20 +51,6 @@ namespace Content.Client.GameObjects.Components.Gravity sprite.LayerMapReserveBlank(GravityGeneratorVisualLayers.Core); } - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - - // Get Sprites for each status - foreach (var status in (GravityGeneratorStatus[]) Enum.GetValues(typeof(GravityGeneratorStatus))) - { - if (node.TryGetNode(status.ToString().ToLower(), out var sprite)) - { - _spriteMap[status] = sprite.AsString(); - } - } - } - public override void OnChangeData(AppearanceComponent component) { base.OnChangeData(component); diff --git a/Content.Client/GameObjects/Components/HUD/Inventory/ClientInventoryComponent.cs b/Content.Client/GameObjects/Components/HUD/Inventory/ClientInventoryComponent.cs index 987b229795..26fea3fe28 100644 --- a/Content.Client/GameObjects/Components/HUD/Inventory/ClientInventoryComponent.cs +++ b/Content.Client/GameObjects/Components/HUD/Inventory/ClientInventoryComponent.cs @@ -28,6 +28,7 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory [ViewVariables] public InventoryInterfaceController InterfaceController { get; private set; } = default!; + [ComponentDependency] private ISpriteComponent? _sprite; private bool _playerAttached = false; @@ -52,7 +53,7 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory InterfaceController = DynamicTypeFactory.CreateInstance(controllerType, args); InterfaceController.Initialize(); - if (Owner.TryGetComponent(out _sprite)) + if (_sprite != null) { foreach (var mask in InventoryInstance.SlotMasks.OrderBy(s => InventoryInstance.SlotDrawingOrder(s))) { diff --git a/Content.Client/GameObjects/Components/IconSmoothing/IconSmoothComponent.cs b/Content.Client/GameObjects/Components/IconSmoothing/IconSmoothComponent.cs index 5f8b165169..6e66500268 100644 --- a/Content.Client/GameObjects/Components/IconSmoothing/IconSmoothComponent.cs +++ b/Content.Client/GameObjects/Components/IconSmoothing/IconSmoothComponent.cs @@ -6,7 +6,9 @@ using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Map; using Robust.Shared.Maths; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using static Robust.Client.GameObjects.SpriteComponent; namespace Content.Client.GameObjects.Components.IconSmoothing @@ -25,9 +27,12 @@ namespace Content.Client.GameObjects.Components.IconSmoothing [RegisterComponent] public class IconSmoothComponent : Component { - private string _smoothKey; - private string _stateBase; - private IconSmoothingMode _mode; + [DataField("key")] + private string _smoothKey = default; + [DataField("base")] + private string _stateBase = ""; + [DataField("mode")] + private IconSmoothingMode _mode = IconSmoothingMode.Corners; public override string Name => "IconSmooth"; @@ -63,15 +68,6 @@ namespace Content.Client.GameObjects.Components.IconSmoothing Sprite = Owner.GetComponent(); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataFieldCached(ref _stateBase, "base", ""); - serializer.DataFieldCached(ref _smoothKey, "key", null); - serializer.DataFieldCached(ref _mode, "mode", IconSmoothingMode.Corners); - } - /// protected override void Startup() { diff --git a/Content.Client/GameObjects/Components/Instruments/InstrumentComponent.cs b/Content.Client/GameObjects/Components/Instruments/InstrumentComponent.cs index 003518394b..5c9c563459 100644 --- a/Content.Client/GameObjects/Components/Instruments/InstrumentComponent.cs +++ b/Content.Client/GameObjects/Components/Instruments/InstrumentComponent.cs @@ -11,8 +11,8 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Network; using Robust.Shared.Players; -using Robust.Shared.Serialization; using Robust.Shared.Timing; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Client.GameObjects.Components.Instruments @@ -35,19 +35,24 @@ namespace Content.Client.GameObjects.Components.Instruments private InstrumentSystem _instrumentSystem = default!; + [DataField("program")] private byte _instrumentProgram = 1; + [DataField("bank")] private byte _instrumentBank; private uint _sequenceDelay; private uint _sequenceStartTick; + [DataField("allowPercussion")] private bool _allowPercussion; + [DataField("allowProgramChange")] private bool _allowProgramChange; - private bool _respectMidiLimits; + [DataField("respectMidiLimits")] + private bool _respectMidiLimits = true; /// /// A queue of MidiEvents to be sent to the server. @@ -137,6 +142,7 @@ namespace Content.Client.GameObjects.Components.Instruments /// Whether this instrument is handheld or not. /// [ViewVariables] + [DataField("handheld")] public bool Handheld { get; set; } // TODO: Replace this by simply checking if the entity has an ItemComponent. /// @@ -263,17 +269,6 @@ namespace Content.Client.GameObjects.Components.Instruments EndRenderer(); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(this, x => x.Handheld, "handheld", false); - serializer.DataField(ref _instrumentProgram, "program", (byte) 1); - serializer.DataField(ref _instrumentBank, "bank", (byte) 0); - serializer.DataField(ref _allowPercussion, "allowPercussion", false); - serializer.DataField(ref _allowProgramChange, "allowProgramChange", false); - serializer.DataField(ref _respectMidiLimits, "respectMidiLimits", true); - } - public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession? session = null) { base.HandleNetworkMessage(message, channel, session); diff --git a/Content.Client/GameObjects/Components/Interactable/MultiToolComponent.cs b/Content.Client/GameObjects/Components/Interactable/MultiToolComponent.cs index c1f077323d..e64f2fae2b 100644 --- a/Content.Client/GameObjects/Components/Interactable/MultiToolComponent.cs +++ b/Content.Client/GameObjects/Components/Interactable/MultiToolComponent.cs @@ -5,7 +5,9 @@ using Content.Shared.GameObjects.Components.Interactable; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Timing; using Robust.Shared.ViewVariables; @@ -15,7 +17,8 @@ namespace Content.Client.GameObjects.Components.Interactable public class MultiToolComponent : Component, IItemStatus { private ToolQuality _behavior; - private bool _statusShowBehavior; + [DataField("statusShowBehavior")] + private bool _statusShowBehavior = true; [ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded; [ViewVariables] public bool StatusShowBehavior => _statusShowBehavior; @@ -24,12 +27,6 @@ namespace Content.Client.GameObjects.Components.Interactable public override string Name => "MultiTool"; public override uint? NetID => ContentNetIDs.MULTITOOLS; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _statusShowBehavior, "statusShowBehavior", true); - } - public override void HandleComponentState(ComponentState curState, ComponentState nextState) { base.HandleComponentState(curState, nextState); diff --git a/Content.Client/GameObjects/Components/Interactable/WelderComponent.cs b/Content.Client/GameObjects/Components/Interactable/WelderComponent.cs index 823f75dbdb..02bcc6af53 100644 --- a/Content.Client/GameObjects/Components/Interactable/WelderComponent.cs +++ b/Content.Client/GameObjects/Components/Interactable/WelderComponent.cs @@ -26,10 +26,6 @@ namespace Content.Client.GameObjects.Components.Interactable [ViewVariables] public bool Activated { get; private set; } [ViewVariables] public override ToolQuality Qualities => _behavior; - public override void ExposeData(ObjectSerializer serializer) - { - } - public override void HandleComponentState(ComponentState curState, ComponentState nextState) { base.HandleComponentState(curState, nextState); diff --git a/Content.Client/GameObjects/Components/Items/ItemComponent.cs b/Content.Client/GameObjects/Components/Items/ItemComponent.cs index 84479cc19a..e448f7bf51 100644 --- a/Content.Client/GameObjects/Components/Items/ItemComponent.cs +++ b/Content.Client/GameObjects/Components/Items/ItemComponent.cs @@ -8,7 +8,9 @@ using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Maths; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -23,10 +25,15 @@ namespace Content.Client.GameObjects.Components.Items public override string Name => "Item"; public override uint? NetID => ContentNetIDs.ITEM; - [ViewVariables] protected ResourcePath RsiPath; + [ViewVariables] + [DataField("sprite")] + protected ResourcePath RsiPath; - [ViewVariables(VVAccess.ReadWrite)] protected Color Color; + [ViewVariables(VVAccess.ReadWrite)] + [DataField("color")] + protected Color Color = Color.White; + [DataField("HeldPrefix")] private string _equippedPrefix; [ViewVariables(VVAccess.ReadWrite)] @@ -60,15 +67,6 @@ namespace Content.Client.GameObjects.Components.Items return null; } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataFieldCached(ref Color, "color", Color.White); - serializer.DataFieldCached(ref RsiPath, "sprite", null); - serializer.DataFieldCached(ref _equippedPrefix, "HeldPrefix", null); - } - protected RSI GetRSI() { return _resourceCache.GetResource(SharedSpriteComponent.TextureRoot / RsiPath).RSI; diff --git a/Content.Client/GameObjects/Components/Kitchen/KitchenSpikeComponent.cs b/Content.Client/GameObjects/Components/Kitchen/KitchenSpikeComponent.cs index 1868788f17..37c7822493 100644 --- a/Content.Client/GameObjects/Components/Kitchen/KitchenSpikeComponent.cs +++ b/Content.Client/GameObjects/Components/Kitchen/KitchenSpikeComponent.cs @@ -1,6 +1,6 @@ #nullable enable -using Content.Shared.GameObjects.Components.Kitchen; using Content.Shared.Interfaces.GameObjects.Components; +using Content.Shared.Kitchen; using Robust.Shared.GameObjects; namespace Content.Client.GameObjects.Components.Kitchen diff --git a/Content.Client/GameObjects/Components/LightBehaviourComponent.cs b/Content.Client/GameObjects/Components/LightBehaviourComponent.cs index deaad269ed..8dd9c2d20d 100644 --- a/Content.Client/GameObjects/Components/LightBehaviourComponent.cs +++ b/Content.Client/GameObjects/Components/LightBehaviourComponent.cs @@ -12,6 +12,7 @@ using Robust.Shared.Log; using Robust.Shared.Maths; using Robust.Shared.Random; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Client.GameObjects.Components @@ -22,37 +23,43 @@ namespace Content.Client.GameObjects.Components /// This AnimationTrack derivative does not rely on keyframes since it often needs to have a randomized duration. /// [Serializable] - public abstract class LightBehaviourAnimationTrack : AnimationTrackProperty, IExposeData + [ImplicitDataDefinitionForInheritors] + public abstract class LightBehaviourAnimationTrack : AnimationTrackProperty { - [ViewVariables] public string ID { get; set; } - [ViewVariables] public string Property { get; protected set; } - [ViewVariables] public bool IsLooped { get; set; } - [ViewVariables] public bool Enabled { get; set; } - [ViewVariables] public float StartValue { get; set; } - [ViewVariables] public float EndValue { get; set; } - [ViewVariables] public float MinDuration { get; set; } - [ViewVariables] public float MaxDuration { get; set; } - [ViewVariables] public AnimationInterpolationMode InterpolateMode { get; set; } + [DataField("id")] [ViewVariables] public string ID { get; set; } = string.Empty; + + [DataField("property")] + [ViewVariables] + public virtual string Property { get; protected set; } = "Radius"; + + [DataField("isLooped")] [ViewVariables] public bool IsLooped { get; set; } + + [DataField("enabled")] [ViewVariables] public bool Enabled { get; set; } + + [DataField("startValue")] [ViewVariables] public float StartValue { get; set; } + + [DataField("endValue")] + [ViewVariables] + public float EndValue { get; set; } = 2f; + + [DataField("minDuration")] + [ViewVariables] + public float MinDuration { get; set; } = -1f; + + [DataField("maxDuration")] + [ViewVariables] + public float MaxDuration { get; set; } = 2f; + + [DataField("interpolate")] + [ViewVariables] + public AnimationInterpolationMode InterpolateMode { get; set; } = AnimationInterpolationMode.Linear; [ViewVariables] protected float MaxTime { get; set; } - protected PointLightComponent Light = default; - protected IRobustRandom RobustRandom = default; + protected PointLightComponent Light; + protected IRobustRandom RobustRandom; private float _maxTime = default; - public virtual void ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.ID, "id", string.Empty); - serializer.DataField(this, x => x.IsLooped, "isLooped", false); - serializer.DataField(this, x => x.Enabled, "enabled", false); - serializer.DataField(this, x => x.StartValue, "startValue", 0f); - serializer.DataField(this, x => x.EndValue, "endValue", 2f); - serializer.DataField(this, x => x.MinDuration, "minDuration", -1f); - serializer.DataField(this, x => x.MaxDuration, "maxDuration", 2f); - serializer.DataField(this, x => x.Property, "property", "Radius"); - serializer.DataField(this, x => x.InterpolateMode, "interpolate", AnimationInterpolationMode.Linear); - } - public void Initialize(PointLightComponent light) { Light = light; @@ -212,10 +219,10 @@ namespace Content.Client.GameObjects.Components [UsedImplicitly] public class RandomizeBehaviour : LightBehaviourAnimationTrack { - private object _randomValue1 = default; - private object _randomValue2 = default; - private object _randomValue3 = default; - private object _randomValue4 = default; + private object _randomValue1; + private object _randomValue2; + private object _randomValue3; + private object _randomValue4; public override void OnInitialize() { @@ -275,11 +282,16 @@ namespace Content.Client.GameObjects.Components /// A light behaviour that cycles through a list of colors. /// [UsedImplicitly] - public class ColorCycleBehaviour : LightBehaviourAnimationTrack + [DataDefinition] + public class ColorCycleBehaviour : LightBehaviourAnimationTrack, ISerializationHooks { - public List ColorsToCycle { get; set; } + [DataField("property")] + [ViewVariables] + public override string Property { get; protected set; } = "Color"; - private int _colorIndex = 0; + [DataField("colors")] public List ColorsToCycle { get; set; } = new(); + + private int _colorIndex; public override void OnStart() { @@ -320,23 +332,13 @@ namespace Content.Client.GameObjects.Components return (-1, playingTime); } - public override void ExposeData(ObjectSerializer serializer) + void ISerializationHooks.AfterDeserialization() { - serializer.DataField(this, x => x.ID, "id", string.Empty); - serializer.DataField(this, x => x.IsLooped, "isLooped", false); - serializer.DataField(this, x => x.Enabled, "enabled", false); - serializer.DataField(this, x => x.MinDuration, "minDuration", -1f); - serializer.DataField(this, x => x.MaxDuration, "maxDuration", 2f); - serializer.DataField(this, x => x.InterpolateMode, "interpolate", AnimationInterpolationMode.Linear); - ColorsToCycle = serializer.ReadDataField("colors", new List()); - Property = "Color"; - if (ColorsToCycle.Count < 2) { throw new InvalidOperationException($"{nameof(ColorCycleBehaviour)} has less than 2 colors to cycle"); } } - } #endregion @@ -344,11 +346,11 @@ namespace Content.Client.GameObjects.Components /// A component which applies a specific behaviour to a PointLightComponent on its owner. /// [RegisterComponent] - public class LightBehaviourComponent : SharedLightBehaviourComponent + public class LightBehaviourComponent : SharedLightBehaviourComponent, ISerializationHooks { private const string KeyPrefix = nameof(LightBehaviourComponent); - private class AnimationContainer + public class AnimationContainer { public AnimationContainer(int key, Animation animation, LightBehaviourAnimationTrack track) { @@ -363,16 +365,36 @@ namespace Content.Client.GameObjects.Components public LightBehaviourAnimationTrack LightBehaviour { get; set; } } + [ViewVariables(VVAccess.ReadOnly)] + [DataField("behaviours")] + public readonly List Behaviours = new(); + [ViewVariables(VVAccess.ReadOnly)] private readonly List _animations = new(); - private float _originalRadius = default; - private float _originalEnergy = default; - private Angle _originalRotation = default; - private Color _originalColor = default; - private bool _originalEnabled = default; - private PointLightComponent _lightComponent = default; - private AnimationPlayerComponent _animationPlayer = default; + private float _originalRadius; + private float _originalEnergy; + private Angle _originalRotation; + private Color _originalColor; + private bool _originalEnabled; + private PointLightComponent _lightComponent; + private AnimationPlayerComponent _animationPlayer; + + void ISerializationHooks.AfterDeserialization() + { + var key = 0; + + foreach (var behaviour in Behaviours) + { + var animation = new Animation() + { + AnimationTracks = { behaviour } + }; + + _animations.Add(new AnimationContainer(key, animation, behaviour)); + key++; + } + } protected override void Startup() { @@ -380,7 +402,7 @@ namespace Content.Client.GameObjects.Components CopyLightSettings(); _animationPlayer = Owner.EnsureComponent(); - _animationPlayer.AnimationCompleted += s => OnAnimationCompleted(s); + _animationPlayer.AnimationCompleted += OnAnimationCompleted; foreach (var container in _animations) { @@ -516,24 +538,5 @@ namespace Content.Client.GameObjects.Components StartLightBehaviour(behaviour.ID); } } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - var behaviours = serializer.ReadDataField("behaviours", new List()); - var key = 0; - - foreach (LightBehaviourAnimationTrack behaviour in behaviours) - { - var animation = new Animation() - { - AnimationTracks = { behaviour } - }; - - _animations.Add(new AnimationContainer(key, animation, behaviour)); - key++; - } - } } } diff --git a/Content.Client/GameObjects/Components/Mobs/CameraRecoilComponent.cs b/Content.Client/GameObjects/Components/Mobs/CameraRecoilComponent.cs index 59864826c6..362cd24d2d 100644 --- a/Content.Client/GameObjects/Components/Mobs/CameraRecoilComponent.cs +++ b/Content.Client/GameObjects/Components/Mobs/CameraRecoilComponent.cs @@ -29,7 +29,8 @@ namespace Content.Client.GameObjects.Components.Mobs private Vector2 _currentKick; private float _lastKickTime; - [ComponentDependency] private readonly EyeComponent? _eye = null; + [ComponentDependency] + private readonly EyeComponent? _eye = default; // Basically I needed a way to chain this effect for the attack lunge animation. // Sorry! diff --git a/Content.Client/GameObjects/Components/Mobs/DamageStateVisualizer.cs b/Content.Client/GameObjects/Components/Mobs/DamageStateVisualizer.cs index edf95601b4..4ffe84623a 100644 --- a/Content.Client/GameObjects/Components/Mobs/DamageStateVisualizer.cs +++ b/Content.Client/GameObjects/Components/Mobs/DamageStateVisualizer.cs @@ -1,36 +1,52 @@ +#nullable enable using System.Collections.Generic; using Content.Shared.GameObjects; using Content.Shared.GameObjects.Components.Mobs; using JetBrains.Annotations; using Robust.Client.GameObjects; +using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; namespace Content.Client.GameObjects.Components.Mobs { [UsedImplicitly] - public sealed class DamageStateVisualizer : AppearanceVisualizer + public sealed class DamageStateVisualizer : AppearanceVisualizer, ISerializationHooks { private DamageState _data = DamageState.Alive; - private readonly Dictionary _stateMap = new(); + private Dictionary _stateMap = new(); private int? _originalDrawDepth; - public override void LoadData(YamlMappingNode node) + [DataField("normal")] + private string? normal; + [DataField("crit")] + private string? crit; + [DataField("dead")] + private string? dead; + + void ISerializationHooks.BeforeSerialization() { - base.LoadData(node); - if (node.TryGetNode("normal", out var normal)) + _stateMap.TryGetValue(DamageState.Alive, out normal); + _stateMap.TryGetValue(DamageState.Critical, out crit); + _stateMap.TryGetValue(DamageState.Dead, out dead); + } + + void ISerializationHooks.AfterDeserialization() + { + if (normal != null) { - _stateMap.Add(DamageState.Alive, normal.AsString()); + _stateMap.Add(DamageState.Alive, normal); } - if (node.TryGetNode("crit", out var crit)) + if (crit != null) { - _stateMap.Add(DamageState.Critical, crit.AsString()); + _stateMap.Add(DamageState.Critical, crit); } - if (node.TryGetNode("dead", out var dead)) + if (dead != null) { - _stateMap.Add(DamageState.Dead, dead.AsString()); + _stateMap.Add(DamageState.Dead, dead); } } diff --git a/Content.Client/GameObjects/Components/Morgue/CrematoriumVisualizer.cs b/Content.Client/GameObjects/Components/Morgue/CrematoriumVisualizer.cs index c0d364e0fb..bc6d4ff7b5 100644 --- a/Content.Client/GameObjects/Components/Morgue/CrematoriumVisualizer.cs +++ b/Content.Client/GameObjects/Components/Morgue/CrematoriumVisualizer.cs @@ -2,6 +2,7 @@ using Content.Shared.GameObjects.Components.Morgue; using JetBrains.Annotations; using Robust.Client.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; @@ -10,35 +11,16 @@ namespace Content.Client.GameObjects.Components.Morgue [UsedImplicitly] public sealed class CrematoriumVisualizer : AppearanceVisualizer { + [DataField("state_open")] private string _stateOpen = ""; + [DataField("state_closed")] private string _stateClosed = ""; + [DataField("light_contents")] private string _lightContents = ""; + [DataField("light_burning")] private string _lightBurning = ""; - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - - if (node.TryGetNode("state_open", out var child)) - { - _stateOpen = child.AsString(); - } - if (node.TryGetNode("state_closed", out child)) - { - _stateClosed = child.AsString(); - } - - if (node.TryGetNode("light_contents", out child)) - { - _lightContents = child.AsString(); - } - if (node.TryGetNode("light_burning", out child)) - { - _lightBurning = child.AsString(); - } - } - public override void OnChangeData(AppearanceComponent component) { base.OnChangeData(component); diff --git a/Content.Client/GameObjects/Components/Morgue/MorgueVisualizer.cs b/Content.Client/GameObjects/Components/Morgue/MorgueVisualizer.cs index ad66bd65e1..bf49fa44b0 100644 --- a/Content.Client/GameObjects/Components/Morgue/MorgueVisualizer.cs +++ b/Content.Client/GameObjects/Components/Morgue/MorgueVisualizer.cs @@ -1,6 +1,8 @@ #nullable enable +using System.Runtime.CompilerServices; using Content.Shared.GameObjects.Components.Morgue; using Robust.Client.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; @@ -8,40 +10,18 @@ namespace Content.Client.GameObjects.Components.Storage { public sealed class MorgueVisualizer : AppearanceVisualizer { + [DataField("state_open")] private string _stateOpen = ""; + [DataField("state_closed")] private string _stateClosed = ""; + [DataField("light_contents")] private string _lightContents = ""; + [DataField("light_mob")] private string _lightMob = ""; + [DataField("light_soul")] private string _lightSoul = ""; - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - - if (node.TryGetNode("state_open", out var child)) - { - _stateOpen = child.AsString(); - } - if (node.TryGetNode("state_closed", out child)) - { - _stateClosed = child.AsString(); - } - - if (node.TryGetNode("light_contents", out child)) - { - _lightContents = child.AsString(); - } - if (node.TryGetNode("light_mob", out child)) - { - _lightMob = child.AsString(); - } - if (node.TryGetNode("light_soul", out child)) - { - _lightSoul = child.AsString(); - } - } - public override void OnChangeData(AppearanceComponent component) { base.OnChangeData(component); diff --git a/Content.Client/GameObjects/Components/Movement/HandTeleporterVisualizer.cs b/Content.Client/GameObjects/Components/Movement/HandTeleporterVisualizer.cs index 7229620921..fc5d4849e8 100644 --- a/Content.Client/GameObjects/Components/Movement/HandTeleporterVisualizer.cs +++ b/Content.Client/GameObjects/Components/Movement/HandTeleporterVisualizer.cs @@ -1,4 +1,6 @@ using System; +using Content.Client.GameObjects.Components.Items; +using Content.Shared.GameObjects.Components.Movement; using Content.Shared.GameObjects.Components.Portal; using JetBrains.Annotations; using Robust.Client.GameObjects; diff --git a/Content.Client/GameObjects/Components/Nutrition/BurnStateVisualizer.cs b/Content.Client/GameObjects/Components/Nutrition/BurnStateVisualizer.cs index fa823240a2..8f756f5756 100644 --- a/Content.Client/GameObjects/Components/Nutrition/BurnStateVisualizer.cs +++ b/Content.Client/GameObjects/Components/Nutrition/BurnStateVisualizer.cs @@ -1,6 +1,7 @@ using Content.Shared.GameObjects.Components; using JetBrains.Annotations; using Robust.Client.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; @@ -9,30 +10,13 @@ namespace Content.Client.GameObjects.Components.Nutrition [UsedImplicitly] public class BurnStateVisualizer : AppearanceVisualizer { + [DataField("burntIcon")] private string _burntIcon = "burnt-icon"; + [DataField("litIcon")] private string _litIcon = "lit-icon"; + [DataField("unlitIcon")] private string _unlitIcon = "icon"; - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - - if (node.TryGetNode("unlitIcon", out var unlitIcon)) - { - _unlitIcon = unlitIcon.AsString(); - } - - if (node.TryGetNode("litIcon", out var litIcon)) - { - _litIcon = litIcon.AsString(); - } - - if (node.TryGetNode("burntIcon", out var burntIcon)) - { - _burntIcon = burntIcon.AsString(); - } - } - public override void OnChangeData(AppearanceComponent component) { base.OnChangeData(component); @@ -62,4 +46,4 @@ namespace Content.Client.GameObjects.Components.Nutrition } } } -} \ No newline at end of file +} diff --git a/Content.Client/GameObjects/Components/Nutrition/CreamPiedVisualizer.cs b/Content.Client/GameObjects/Components/Nutrition/CreamPiedVisualizer.cs index 465d5d76f6..ac7a247ce6 100644 --- a/Content.Client/GameObjects/Components/Nutrition/CreamPiedVisualizer.cs +++ b/Content.Client/GameObjects/Components/Nutrition/CreamPiedVisualizer.cs @@ -2,6 +2,7 @@ using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; @@ -10,6 +11,7 @@ namespace Content.Client.GameObjects.Components.Nutrition [UsedImplicitly] public class CreamPiedVisualizer : AppearanceVisualizer { + [DataField("state")] private string _state; public override void InitializeEntity(IEntity entity) @@ -23,16 +25,6 @@ namespace Content.Client.GameObjects.Components.Nutrition sprite.LayerSetVisible(CreamPiedVisualLayers.Pie, false); } - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - - if (node.TryGetNode("state", out var otherNode)) - { - _state = otherNode.AsString(); - } - } - public override void OnChangeData(AppearanceComponent component) { base.OnChangeData(component); diff --git a/Content.Client/GameObjects/Components/Nutrition/DrinkFoodContainerVisualizer2D.cs b/Content.Client/GameObjects/Components/Nutrition/DrinkFoodContainerVisualizer2D.cs index 919a50bc63..cc17ba9877 100644 --- a/Content.Client/GameObjects/Components/Nutrition/DrinkFoodContainerVisualizer2D.cs +++ b/Content.Client/GameObjects/Components/Nutrition/DrinkFoodContainerVisualizer2D.cs @@ -4,6 +4,7 @@ using Content.Shared.GameObjects.Components.Nutrition; using Content.Shared.Utility; using JetBrains.Annotations; using Robust.Client.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; @@ -12,25 +13,12 @@ namespace Content.Client.GameObjects.Components.Nutrition [UsedImplicitly] public sealed class FoodContainerVisualizer : AppearanceVisualizer { + [DataField("base_state", required: true)] private string _baseState; + [DataField("steps", required: true)] private int _steps; - private FoodContainerVisualMode _mode; - - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - - _baseState = node.GetNode("base_state").AsString(); - _steps = node.GetNode("steps").AsInt(); - try - { - _mode = node.GetNode("mode").AsEnum(); - } - catch (KeyNotFoundException) - { - _mode = FoodContainerVisualMode.Rounded; - } - } + [DataField("mode")] + private FoodContainerVisualMode _mode = FoodContainerVisualMode.Rounded; public override void OnChangeData(AppearanceComponent component) { diff --git a/Content.Client/GameObjects/Components/Nutrition/DrinkFoodVisualizer.cs b/Content.Client/GameObjects/Components/Nutrition/DrinkFoodVisualizer.cs index f2fe48aba7..c5d493c02c 100644 --- a/Content.Client/GameObjects/Components/Nutrition/DrinkFoodVisualizer.cs +++ b/Content.Client/GameObjects/Components/Nutrition/DrinkFoodVisualizer.cs @@ -2,6 +2,7 @@ using Content.Shared.GameObjects.Components.Nutrition; using Content.Shared.Utility; using JetBrains.Annotations; using Robust.Client.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; @@ -10,15 +11,9 @@ namespace Content.Client.GameObjects.Components.Nutrition [UsedImplicitly] public sealed class DrinkFoodVisualizer : AppearanceVisualizer { + [DataField("steps")] private int _steps; - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - - _steps = node.GetNode("steps").AsInt(); - } - public override void OnChangeData(AppearanceComponent component) { base.OnChangeData(component); diff --git a/Content.Client/GameObjects/Components/PDA/PDAVisualizer.cs b/Content.Client/GameObjects/Components/PDA/PDAVisualizer.cs index c52b62359a..f52ab1ad48 100644 --- a/Content.Client/GameObjects/Components/PDA/PDAVisualizer.cs +++ b/Content.Client/GameObjects/Components/PDA/PDAVisualizer.cs @@ -2,6 +2,7 @@ using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; @@ -14,6 +15,7 @@ namespace Content.Client.GameObjects.Components.PDA /// /// The base PDA sprite state, eg. "pda", "pda-clown" /// + [DataField("state")] private string _state; private enum PDAVisualLayers : byte @@ -23,15 +25,6 @@ namespace Content.Client.GameObjects.Components.PDA IDLight } - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - if (node.TryGetNode("state", out var child)) - { - _state = child.AsString(); - } - } - public override void InitializeEntity(IEntity entity) { base.InitializeEntity(entity); @@ -62,7 +55,5 @@ namespace Content.Client.GameObjects.Components.PDA } } - - } } diff --git a/Content.Client/GameObjects/Components/ParticleAcceleratorPartVisualizer.cs b/Content.Client/GameObjects/Components/ParticleAcceleratorPartVisualizer.cs index 19e974cc1d..dc03aa9f97 100644 --- a/Content.Client/GameObjects/Components/ParticleAcceleratorPartVisualizer.cs +++ b/Content.Client/GameObjects/Components/ParticleAcceleratorPartVisualizer.cs @@ -4,32 +4,26 @@ using Content.Shared.GameObjects.Components; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; -using Robust.Shared.Prototypes; using Robust.Shared.Serialization; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Client.GameObjects.Components { [UsedImplicitly] - public class ParticleAcceleratorPartVisualizer : AppearanceVisualizer + [DataDefinition] + public class ParticleAcceleratorPartVisualizer : AppearanceVisualizer, ISerializationHooks { - private readonly Dictionary _states = new(); + [DataField("baseState", required: true)] + private string _baseState; + private Dictionary _states = new(); - public override void LoadData(YamlMappingNode node) + void ISerializationHooks.AfterDeserialization() { - base.LoadData(node); - - var serializer = YamlObjectSerializer.NewReader(node); - if (!serializer.TryReadDataField("baseState", out var baseState)) - { - throw new PrototypeLoadException("No baseState property specified for ParticleAcceleratorPartVisualizer"); - } - - _states.Add(ParticleAcceleratorVisualState.Powered, baseState+"p"); - _states.Add(ParticleAcceleratorVisualState.Level0, baseState+"p0"); - _states.Add(ParticleAcceleratorVisualState.Level1, baseState+"p1"); - _states.Add(ParticleAcceleratorVisualState.Level2, baseState+"p2"); - _states.Add(ParticleAcceleratorVisualState.Level3, baseState+"p3"); + _states.Add(ParticleAcceleratorVisualState.Powered, _baseState+"p"); + _states.Add(ParticleAcceleratorVisualState.Level0, _baseState+"p0"); + _states.Add(ParticleAcceleratorVisualState.Level1, _baseState+"p1"); + _states.Add(ParticleAcceleratorVisualState.Level2, _baseState+"p2"); + _states.Add(ParticleAcceleratorVisualState.Level3, _baseState+"p3"); } public override void InitializeEntity(IEntity entity) diff --git a/Content.Client/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/PoweredLightVisualizer.cs b/Content.Client/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/PoweredLightVisualizer.cs index 2c06aaf864..2262a4ecfa 100644 --- a/Content.Client/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/PoweredLightVisualizer.cs +++ b/Content.Client/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/PoweredLightVisualizer.cs @@ -9,32 +9,21 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Maths; using Robust.Shared.Random; -using Robust.Shared.Serialization; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Client.GameObjects.Components.Power.ApcNetComponents.PowerReceiverUsers { [UsedImplicitly] public class PoweredLightVisualizer : AppearanceVisualizer { - private float _minBlinkingTime; - private float _maxBlinkingTime; - private string? _blinkingSound; + [DataField("minBlinkingTime")] private float _minBlinkingTime = 0.5f; + [DataField("maxBlinkingTime")] private float _maxBlinkingTime = 2; + [DataField("blinkingSound")] private string? _blinkingSound; private bool _wasBlinking; private Action? _blinkingCallback; - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - - var serializer = YamlObjectSerializer.NewReader(node); - serializer.DataField(ref _minBlinkingTime, "minBlinkingTime", 0.5f); - serializer.DataField(ref _maxBlinkingTime, "maxBlinkingTime", 2.0f); - serializer.DataField(ref _blinkingSound, "blinkingSound", null); - } - public override void OnChangeData(AppearanceComponent component) { base.OnChangeData(component); diff --git a/Content.Client/GameObjects/Components/Power/AutolatheVisualizer.cs b/Content.Client/GameObjects/Components/Power/AutolatheVisualizer.cs index 39e6296af2..36e4af586d 100644 --- a/Content.Client/GameObjects/Components/Power/AutolatheVisualizer.cs +++ b/Content.Client/GameObjects/Components/Power/AutolatheVisualizer.cs @@ -20,10 +20,8 @@ namespace Content.Client.GameObjects.Components.Power private Animation _insertingPlasmaAnimation; private Animation _insertingPlasticAnimation; - public override void LoadData(YamlMappingNode node) + public AutolatheVisualizer() { - base.LoadData(node); - _buildingAnimation = PopulateAnimation("building", "building_unlit", 0.5f); _insertingMetalAnimation = PopulateAnimation("inserting_metal", "inserting_unlit", 0.5f); _insertingGlassAnimation = PopulateAnimation("inserting_glass", "inserting_unlit", 0.5f); @@ -123,6 +121,7 @@ namespace Content.Client.GameObjects.Components.Power var glowingPartsVisible = !(component.TryGetData(PowerDeviceVisuals.Powered, out bool powered) && !powered); sprite.LayerSetVisible(AutolatheVisualLayers.BaseUnlit, glowingPartsVisible); } + public enum AutolatheVisualLayers : byte { Base, diff --git a/Content.Client/GameObjects/Components/Power/PowerCellVisualizer.cs b/Content.Client/GameObjects/Components/Power/PowerCellVisualizer.cs index bfc856bdbb..ba876758f7 100644 --- a/Content.Client/GameObjects/Components/Power/PowerCellVisualizer.cs +++ b/Content.Client/GameObjects/Components/Power/PowerCellVisualizer.cs @@ -1,7 +1,9 @@ +using System.Diagnostics; using Content.Shared.GameObjects.Components.Power; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; @@ -10,15 +12,9 @@ namespace Content.Client.GameObjects.Components.Power [UsedImplicitly] public class PowerCellVisualizer : AppearanceVisualizer { + [DataField("prefix")] private string _prefix; - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - - _prefix = node.GetNode("prefix").AsString(); - } - public override void InitializeEntity(IEntity entity) { base.InitializeEntity(entity); diff --git a/Content.Client/GameObjects/Components/Power/ProtolatheVisualizer.cs b/Content.Client/GameObjects/Components/Power/ProtolatheVisualizer.cs index 50e7b14029..838ef3a89f 100644 --- a/Content.Client/GameObjects/Components/Power/ProtolatheVisualizer.cs +++ b/Content.Client/GameObjects/Components/Power/ProtolatheVisualizer.cs @@ -20,10 +20,8 @@ namespace Content.Client.GameObjects.Components.Power private Animation _insertingPlasmaAnimation; private Animation _insertingPlasticAnimation; - public override void LoadData(YamlMappingNode node) + public ProtolatheVisualizer() { - base.LoadData(node); - _buildingAnimation = PopulateAnimation("building", "building_unlit", 0.8f); _insertingMetalAnimation = PopulateAnimation("inserting_metal", "inserting_unlit", 0.8f); _insertingGlassAnimation = PopulateAnimation("inserting_glass", "inserting_unlit", 0.8f); @@ -123,6 +121,7 @@ namespace Content.Client.GameObjects.Components.Power var glowingPartsVisible = !(component.TryGetData(PowerDeviceVisuals.Powered, out bool powered) && !powered); sprite.LayerSetVisible(ProtolatheVisualLayers.BaseUnlit, glowingPartsVisible); } + public enum ProtolatheVisualLayers : byte { Base, diff --git a/Content.Client/GameObjects/Components/RadiationCollectorVisualizer.cs b/Content.Client/GameObjects/Components/RadiationCollectorVisualizer.cs index dc502b4a98..00c5d9035e 100644 --- a/Content.Client/GameObjects/Components/RadiationCollectorVisualizer.cs +++ b/Content.Client/GameObjects/Components/RadiationCollectorVisualizer.cs @@ -4,19 +4,19 @@ using JetBrains.Annotations; using Robust.Client.Animations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization; namespace Content.Client.GameObjects.Components { [UsedImplicitly] - public class RadiationCollectorVisualizer : AppearanceVisualizer + public class RadiationCollectorVisualizer : AppearanceVisualizer, ISerializationHooks { private const string AnimationKey = "radiationcollector_animation"; private Animation ActivateAnimation; private Animation DeactiveAnimation; - public override void LoadData(YamlMappingNode node) + void ISerializationHooks.AfterDeserialization() { ActivateAnimation = new Animation {Length = TimeSpan.FromSeconds(0.8f)}; { @@ -51,7 +51,6 @@ namespace Content.Client.GameObjects.Components } } - public override void OnChangeData(AppearanceComponent component) { base.OnChangeData(component); @@ -91,7 +90,6 @@ namespace Content.Client.GameObjects.Components break; } } - } public enum RadiationCollectorVisualLayers : byte { diff --git a/Content.Client/GameObjects/Components/Recycling/RecyclerVisualizer.cs b/Content.Client/GameObjects/Components/Recycling/RecyclerVisualizer.cs index 3a1dbac61f..3001139977 100644 --- a/Content.Client/GameObjects/Components/Recycling/RecyclerVisualizer.cs +++ b/Content.Client/GameObjects/Components/Recycling/RecyclerVisualizer.cs @@ -2,6 +2,7 @@ using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; @@ -10,24 +11,11 @@ namespace Content.Client.GameObjects.Components.Recycling [UsedImplicitly] public class RecyclerVisualizer : AppearanceVisualizer { + [DataField("state_clean")] private string _stateClean; + [DataField("state_bloody")] private string _stateBloody; - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - - if (node.TryGetNode("state_clean", out var child)) - { - _stateClean = child.AsString(); - } - - if (node.TryGetNode("state_bloody", out child)) - { - _stateBloody = child.AsString(); - } - } - public override void InitializeEntity(IEntity entity) { base.InitializeEntity(entity); diff --git a/Content.Client/GameObjects/Components/ReinforcedWallComponent.cs b/Content.Client/GameObjects/Components/ReinforcedWallComponent.cs index 9bbec1b026..fce7793bd4 100644 --- a/Content.Client/GameObjects/Components/ReinforcedWallComponent.cs +++ b/Content.Client/GameObjects/Components/ReinforcedWallComponent.cs @@ -1,6 +1,8 @@ using Content.Client.GameObjects.Components.IconSmoothing; using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; using static Robust.Client.GameObjects.SpriteComponent; @@ -13,14 +15,8 @@ namespace Content.Client.GameObjects.Components public override string Name => "ReinforcedWall"; [ViewVariables(VVAccess.ReadWrite)] - private string _reinforcedStateBase; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _reinforcedStateBase, "reinforcedBase", null); - } + [DataField("reinforcedBase")] + private string _reinforcedStateBase = default; protected override void Startup() { diff --git a/Content.Client/GameObjects/Components/Sound/LoopingSoundComponent.cs b/Content.Client/GameObjects/Components/Sound/LoopingSoundComponent.cs index a780dd79ab..7da6c6878e 100644 --- a/Content.Client/GameObjects/Components/Sound/LoopingSoundComponent.cs +++ b/Content.Client/GameObjects/Components/Sound/LoopingSoundComponent.cs @@ -8,7 +8,7 @@ using Robust.Shared.Network; using Robust.Shared.Player; using Robust.Shared.Players; using Robust.Shared.Random; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Client.GameObjects.Components.Sound { @@ -19,6 +19,13 @@ namespace Content.Client.GameObjects.Components.Sound private readonly Dictionary _audioStreams = new(); + [DataField("schedules", true)] + private List _scheduledSounds + { + set => value.ForEach(AddScheduledSound); + get => new(); + } + public override void StopAllSounds() { foreach (var kvp in _audioStreams) @@ -94,15 +101,5 @@ namespace Content.Client.GameObjects.Components.Sound base.Initialize(); SoundSystem.OcclusionCollisionMask = (int) CollisionGroup.Impassable; } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataReadFunction( - "schedules", - new List(), - schedules => schedules.ForEach(AddScheduledSound)); - } } } diff --git a/Content.Client/GameObjects/Components/StackVisualizer.cs b/Content.Client/GameObjects/Components/StackVisualizer.cs index d72685c0d7..bc666fe1ef 100644 --- a/Content.Client/GameObjects/Components/StackVisualizer.cs +++ b/Content.Client/GameObjects/Components/StackVisualizer.cs @@ -6,6 +6,7 @@ using Content.Shared.Utility; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; @@ -59,6 +60,7 @@ namespace Content.Client.GameObjects.Components /// Sprite layers used in stack visualizer. Sprites first in layer correspond to lower stack states /// e.g. _spriteLayers[0] is lower stack level than _spriteLayers[1]. /// + [DataField("stackLayers")] private readonly List _spriteLayers = new(); /// @@ -74,32 +76,11 @@ namespace Content.Client.GameObjects.Components /// /// /// + [DataField("composite")] private bool _isComposite; + [DataField("sprite")] private ResourcePath? _spritePath; - public override void LoadData(YamlMappingNode mapping) - { - base.LoadData(mapping); - - if (mapping.TryGetNode("stackLayers", out var spriteSequenceNode)) - { - foreach (var yamlNode in spriteSequenceNode) - { - _spriteLayers.Add(((YamlScalarNode) yamlNode).Value!); - } - } - - if (mapping.TryGetNode("composite", out var transparent)) - { - _isComposite = transparent.AsBool(); - } - - if (mapping.TryGetNode("sprite", out var spritePath)) - { - _spritePath = spritePath.AsResourcePath(); - } - } - public override void InitializeEntity(IEntity entity) { base.InitializeEntity(entity); diff --git a/Content.Client/GameObjects/Components/Storage/BagOpenCloseVisualizer.cs b/Content.Client/GameObjects/Components/Storage/BagOpenCloseVisualizer.cs index 103e21d0bb..fa7f650ba9 100644 --- a/Content.Client/GameObjects/Components/Storage/BagOpenCloseVisualizer.cs +++ b/Content.Client/GameObjects/Components/Storage/BagOpenCloseVisualizer.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Log; +using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; using static Robust.Shared.Utility.SpriteSpecifier; @@ -12,21 +14,15 @@ using static Robust.Shared.Utility.SpriteSpecifier; namespace Content.Client.GameObjects.Components.Storage { [UsedImplicitly] - public class BagOpenCloseVisualizer : AppearanceVisualizer + public class BagOpenCloseVisualizer : AppearanceVisualizer, ISerializationHooks { private const string OpenIcon = "openIcon"; + [DataField(OpenIcon)] private string? _openIcon; - public override void LoadData(YamlMappingNode node) + void ISerializationHooks.AfterDeserialization() { - base.LoadData(node); - - if (node.TryGetNode(OpenIcon, out var openIconNode)) - { - _openIcon = openIconNode.Value; - } - else - { + if(_openIcon == null){ Logger.Warning("BagOpenCloseVisualizer is useless with no `openIcon`"); } } diff --git a/Content.Client/GameObjects/Components/Storage/StorageVisualizer.cs b/Content.Client/GameObjects/Components/Storage/StorageVisualizer.cs index 0c5f1e58ca..d58e6eac58 100644 --- a/Content.Client/GameObjects/Components/Storage/StorageVisualizer.cs +++ b/Content.Client/GameObjects/Components/Storage/StorageVisualizer.cs @@ -2,6 +2,7 @@ using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; @@ -10,30 +11,13 @@ namespace Content.Client.GameObjects.Components.Storage [UsedImplicitly] public sealed class StorageVisualizer : AppearanceVisualizer { + [DataField("state")] private string _stateBase; + [DataField("state_open")] private string _stateOpen; + [DataField("state_closed")] private string _stateClosed; - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - - if (node.TryGetNode("state", out var child)) - { - _stateBase = child.AsString(); - } - - if (node.TryGetNode("state_open", out child)) - { - _stateOpen = child.AsString(); - } - - if (node.TryGetNode("state_closed", out child)) - { - _stateClosed = child.AsString(); - } - } - public override void InitializeEntity(IEntity entity) { if (!entity.TryGetComponent(out ISpriteComponent sprite)) diff --git a/Content.Client/GameObjects/Components/Trigger/TimerTriggerVisualizer.cs b/Content.Client/GameObjects/Components/Trigger/TimerTriggerVisualizer.cs index 65d541521d..3fc4682e9a 100644 --- a/Content.Client/GameObjects/Components/Trigger/TimerTriggerVisualizer.cs +++ b/Content.Client/GameObjects/Components/Trigger/TimerTriggerVisualizer.cs @@ -4,25 +4,23 @@ using JetBrains.Annotations; using Robust.Client.Animations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Client.GameObjects.Components.Trigger { [UsedImplicitly] - public class TimerTriggerVisualizer : AppearanceVisualizer + public class TimerTriggerVisualizer : AppearanceVisualizer, ISerializationHooks { private const string AnimationKey = "priming_animation"; + [DataField("countdown_sound", required: true)] + private string _countdownSound; + private Animation PrimingAnimation; - public override void LoadData(YamlMappingNode node) + void ISerializationHooks.AfterDeserialization() { - base.LoadData(node); - - var countdownSound = node.GetNode("countdown_sound").AsString(); - - PrimingAnimation = new Animation { Length = TimeSpan.MaxValue }; { var flick = new AnimationTrackSpriteFlick(); @@ -32,7 +30,7 @@ namespace Content.Client.GameObjects.Components.Trigger var sound = new AnimationTrackPlaySound(); PrimingAnimation.AnimationTracks.Add(sound); - sound.KeyFrames.Add(new AnimationTrackPlaySound.KeyFrame(countdownSound, 0)); + sound.KeyFrames.Add(new AnimationTrackPlaySound.KeyFrame(_countdownSound, 0)); } } diff --git a/Content.Client/GameObjects/Components/VendingMachines/VendingMachineVisualizer.cs b/Content.Client/GameObjects/Components/VendingMachines/VendingMachineVisualizer.cs index 2e8a731f30..7042ca0261 100644 --- a/Content.Client/GameObjects/Components/VendingMachines/VendingMachineVisualizer.cs +++ b/Content.Client/GameObjects/Components/VendingMachines/VendingMachineVisualizer.cs @@ -4,14 +4,14 @@ using JetBrains.Annotations; using Robust.Client.Animations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using static Content.Shared.GameObjects.Components.VendingMachines.SharedVendingMachineComponent; namespace Content.Client.GameObjects.Components.VendingMachines { [UsedImplicitly] - public sealed class VendingMachineVisualizer : AppearanceVisualizer + public sealed class VendingMachineVisualizer : AppearanceVisualizer, ISerializationHooks { // TODO: Should default to off or broken if damaged // @@ -37,41 +37,53 @@ namespace Content.Client.GameObjects.Components.VendingMachines {"broken", VendingMachineVisualLayers.Unlit}, }; + [DataField("screen")] + private bool _screen; + + [DataField("normal")] + private bool _normal; + + [DataField("normalUnshaded")] + private bool _normalUnshaded; + + [DataField("eject")] + private bool _eject; + + [DataField("ejectUnshaded")] + private bool _ejectUnshaded; + + [DataField("deny")] + private bool _deny; + + [DataField("denyUnshaded")] + private bool _denyUnshaded; + + [DataField("broken")] + private bool _broken; + + [DataField("brokenUnshaded")] + private bool _brokenUnshaded; + private readonly Dictionary _animations = new(); - public override void LoadData(YamlMappingNode node) + void ISerializationHooks.AfterDeserialization() { - base.LoadData(node); - - _baseStates = new Dictionary + // Used a dictionary so the yaml can adhere to the style-guide and the texture states can be clear + var states = new Dictionary { {"off", true}, + {"screen", _screen}, + {"normal", _normal}, + {"normal-unshaded", _normalUnshaded}, + {"eject", _eject}, + {"eject-unshaded", _ejectUnshaded}, + {"deny", _deny}, + {"deny-unshaded", _denyUnshaded}, + {"broken", _broken}, + {"broken-unshaded", _brokenUnshaded}, }; - // Used a dictionary so the yaml can adhere to the style-guide and the texture states can be clear - var states = new Dictionary - { - {"screen", "screen"}, - {"normal", "normal"}, - {"normalUnshaded", "normal-unshaded"}, - {"eject", "eject"}, - {"ejectUnshaded", "eject-unshaded"}, - {"deny", "deny"}, - {"denyUnshaded", "deny-unshaded"}, - {"broken", "broken"}, - {"brokenUnshaded", "broken-unshaded"}, - }; - - foreach (var (state, textureState) in states) - { - if (!node.TryGetNode(state, out var yamlNode)) - { - _baseStates[textureState] = false; - continue; - } - - _baseStates.Add(textureState, yamlNode.AsBool()); - } + _baseStates = states; if (_baseStates["deny"]) { diff --git a/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/ClientMagazineBarrelComponent.cs b/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/ClientMagazineBarrelComponent.cs index 8304017321..f125a64a18 100644 --- a/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/ClientMagazineBarrelComponent.cs +++ b/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/ClientMagazineBarrelComponent.cs @@ -13,7 +13,9 @@ using Robust.Shared.GameObjects; using Robust.Shared.Maths; using Robust.Shared.Network; using Robust.Shared.Players; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Client.GameObjects.Components.Weapons.Ranged.Barrels @@ -87,14 +89,7 @@ namespace Content.Client.GameObjects.Components.Weapons.Ranged.Barrels [ViewVariables] public (int count, int max)? MagazineCount { get; private set; } - [ViewVariables(VVAccess.ReadWrite)] private bool _isLmgAlarmAnimation; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _isLmgAlarmAnimation, "lmg_alarm_animation", false); - } + [ViewVariables(VVAccess.ReadWrite)] [DataField("lmg_alarm_animation")] private bool _isLmgAlarmAnimation = default; public override void HandleComponentState(ComponentState curState, ComponentState nextState) { diff --git a/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/Visualizers/MagVisualizer.cs b/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/Visualizers/MagVisualizer.cs index 3024d631db..08e72b3add 100644 --- a/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/Visualizers/MagVisualizer.cs +++ b/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/Visualizers/MagVisualizer.cs @@ -3,6 +3,7 @@ using Content.Shared.Utility; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; @@ -12,18 +13,13 @@ namespace Content.Client.GameObjects.Components.Weapons.Ranged.Barrels.Visualize public sealed class MagVisualizer : AppearanceVisualizer { private bool _magLoaded; + [DataField("magState")] private string _magState; + [DataField("steps")] private int _magSteps; + [DataField("zeroVisible")] private bool _zeroVisible; - public override void LoadData(YamlMappingNode node) - { - base.LoadData(node); - _magState = node.GetNode("magState").AsString(); - _magSteps = node.GetNode("steps").AsInt(); - _zeroVisible = node.GetNode("zeroVisible").AsBool(); - } - public override void InitializeEntity(IEntity entity) { base.InitializeEntity(entity); diff --git a/Content.Client/GameObjects/Components/WindowComponent.cs b/Content.Client/GameObjects/Components/WindowComponent.cs index ce356ce52b..a542c3efd2 100644 --- a/Content.Client/GameObjects/Components/WindowComponent.cs +++ b/Content.Client/GameObjects/Components/WindowComponent.cs @@ -3,7 +3,7 @@ using Content.Client.GameObjects.EntitySystems; using Content.Shared.GameObjects.Components; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using static Content.Client.GameObjects.Components.IconSmoothing.IconSmoothComponent; namespace Content.Client.GameObjects.Components @@ -12,7 +12,8 @@ namespace Content.Client.GameObjects.Components [ComponentReference(typeof(SharedWindowComponent))] public sealed class WindowComponent : SharedWindowComponent { - private string _stateBase; + [DataField("base")] + private string _stateBase = default; private ISpriteComponent _sprite; private SnapGridComponent _snapGrid; @@ -101,13 +102,6 @@ namespace Content.Client.GameObjects.Components return null; } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _stateBase, "base", null); - } } [SuppressMessage("ReSharper", "InconsistentNaming")] diff --git a/Content.Client/Research/LatheMenu.cs b/Content.Client/Research/LatheMenu.cs index 51f4ccc363..3b05afe2f0 100644 --- a/Content.Client/Research/LatheMenu.cs +++ b/Content.Client/Research/LatheMenu.cs @@ -160,7 +160,7 @@ namespace Content.Client.Research foreach (var (id, amount) in Owner.Storage) { if (!_prototypeManager.TryIndex(id, out MaterialPrototype materialPrototype)) continue; - var material = materialPrototype.Material; + var material = materialPrototype; _materials.AddItem($"{material.Name} {amount} cm³", material.Icon.Frame0(), false); } } diff --git a/Content.IntegrationTests/ContentIntegrationTest.cs b/Content.IntegrationTests/ContentIntegrationTest.cs index b8dc263a77..17cc1be958 100644 --- a/Content.IntegrationTests/ContentIntegrationTest.cs +++ b/Content.IntegrationTests/ContentIntegrationTest.cs @@ -64,6 +64,7 @@ namespace Content.IntegrationTests typeof(Server.EntryPoint).Assembly, typeof(ContentIntegrationTest).Assembly }; + options.BeforeStart += () => { IoCManager.Resolve().SetModuleBaseCallbacks(new ServerModuleTestingCallbacks diff --git a/Content.IntegrationTests/Tests/AI/BehaviorSetsTest.cs b/Content.IntegrationTests/Tests/AI/BehaviorSetsTest.cs index 683996524a..849eae250d 100644 --- a/Content.IntegrationTests/Tests/AI/BehaviorSetsTest.cs +++ b/Content.IntegrationTests/Tests/AI/BehaviorSetsTest.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading.Tasks; using Content.Server.AI.Utility; using Content.Server.AI.Utility.Actions; +using Content.Server.AI.Utility.AiLogic; using NUnit.Framework; using Robust.Shared.Prototypes; using Robust.Shared.Reflection; @@ -49,12 +50,11 @@ namespace Content.IntegrationTests.Tests.AI { foreach (var entity in protoManager.EnumeratePrototypes()) { - if (!entity.Components.TryGetValue("UtilityAI", out var npcNode)) continue; - var sets = npcNode["behaviorSets"]; + if (!entity.TryGetComponent("UtilityAI", out var npcNode)) continue; - foreach (var entry in (YamlSequenceNode) sets) + foreach (var entry in npcNode.BehaviorSets) { - Assert.That(behaviorSets.ContainsKey(entry.ToString()), $"BehaviorSet {entry} in entity {entity.ID} not found"); + Assert.That(behaviorSets.ContainsKey(entry), $"BehaviorSet {entry} in entity {entity.ID} not found"); } } }); diff --git a/Content.IntegrationTests/Tests/StorageFillTest.cs b/Content.IntegrationTests/Tests/StorageFillTest.cs index 893bc5e7f3..6444ae2ae2 100644 --- a/Content.IntegrationTests/Tests/StorageFillTest.cs +++ b/Content.IntegrationTests/Tests/StorageFillTest.cs @@ -1,5 +1,6 @@ #nullable enable using System.Threading.Tasks; +using Content.Server.GameObjects.Components.Items.Storage; using NUnit.Framework; using Robust.Shared.Prototypes; using Robust.Shared.Utility; @@ -21,19 +22,20 @@ namespace Content.IntegrationTests.Tests { foreach (var proto in protoManager.EnumeratePrototypes()) { - if (!proto.Components.TryGetValue("StorageFill", out var storageNode) || - !storageNode.TryGetNode("contents", out YamlSequenceNode? contentsNode)) continue; + if (!proto.TryGetComponent("StorageFill", out var storage)) continue; - foreach (var child in contentsNode) + foreach (var entry in storage.Contents) { - if (child is not YamlMappingNode mapping) continue; - var name = mapping.GetNode("name").AsString(); - Assert.That(protoManager.HasIndex(name), $"Unable to find StorageFill prototype of {name} in prototype {proto.ID}"); + var name = entry.PrototypeName; - if (mapping.TryGetNode("amount", out var amount)) + if (name == null) { - Assert.That(amount.AsInt() > 0, $"Specified invalid amount of {amount} for prototype {proto.ID}"); + continue; } + + Assert.That(protoManager.HasIndex(name), $"Unable to find StorageFill prototype of {name} in prototype {proto.ID}"); + Assert.That(entry.Amount > 0, $"Specified invalid amount of {entry.Amount} for prototype {proto.ID}"); + Assert.That(entry.SpawnProbability > 0, $"Specified invalid probability of {entry.SpawnProbability} for prototype {proto.ID}"); } } }); diff --git a/Content.Server/AI/Utility/AiLogic/UtilityAI.cs b/Content.Server/AI/Utility/AiLogic/UtilityAI.cs index 45a88d0a0f..f402aedc95 100644 --- a/Content.Server/AI/Utility/AiLogic/UtilityAI.cs +++ b/Content.Server/AI/Utility/AiLogic/UtilityAI.cs @@ -15,13 +15,14 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.AI.Utility.AiLogic { // TODO: Need to split out the IMover stuff for NPC to a generic one that can be used for hoomans as well. [RegisterComponent] [ComponentReference(typeof(AiControllerComponent)), ComponentReference(typeof(IMoverComponent))] - internal sealed class UtilityAi : AiControllerComponent + public sealed class UtilityAi : AiControllerComponent, ISerializationHooks { public override string Name => "UtilityAI"; @@ -34,6 +35,7 @@ namespace Content.Server.AI.Utility.AiLogic /// /// The sum of all BehaviorSets gives us what actions the AI can take /// + [field: DataField("behaviorSets")] public HashSet BehaviorSets { get; } = new(); public List AvailableActions { get; set; } = new(); @@ -62,26 +64,35 @@ namespace Content.Server.AI.Utility.AiLogic /// private bool _isDead; - public override void ExposeData(ObjectSerializer serializer) + /*public void AfterDeserialization() { - base.ExposeData(serializer); - var bSets = serializer.ReadDataField("behaviorSets", new List()); - - if (bSets.Count > 0) + if (BehaviorSets.Count > 0) { var behaviorManager = IoCManager.Resolve(); - foreach (var bSet in bSets) + foreach (var bSet in BehaviorSets) { behaviorManager.AddBehaviorSet(this, bSet, false); } behaviorManager.RebuildActions(this); } - } + }*/ public override void Initialize() { + if (BehaviorSets.Count > 0) + { + var behaviorManager = IoCManager.Resolve(); + + foreach (var bSet in BehaviorSets) + { + behaviorManager.AddBehaviorSet(this, bSet, false); + } + + behaviorManager.RebuildActions(this); + } + base.Initialize(); _planCooldownRemaining = PlanCooldown; _blackboard = new Blackboard(Owner); diff --git a/Content.Server/AI/Utility/BehaviorSetPrototype.cs b/Content.Server/AI/Utility/BehaviorSetPrototype.cs index 401fb620d5..b5f579239e 100644 --- a/Content.Server/AI/Utility/BehaviorSetPrototype.cs +++ b/Content.Server/AI/Utility/BehaviorSetPrototype.cs @@ -1,8 +1,8 @@ #nullable enable using System.Collections.Generic; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; namespace Content.Server.AI.Utility { @@ -12,19 +12,18 @@ namespace Content.Server.AI.Utility /// /// Name of the BehaviorSet. /// - public string ID { get; private set; } = default!; + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; + + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } /// /// Actions that this BehaviorSet grants to the entity. /// - public IReadOnlyList Actions { get; private set; } = default!; - - public void LoadFrom(YamlMappingNode mapping) - { - var serializer = YamlObjectSerializer.NewReader(mapping); - - serializer.DataField(this, x => x.ID, "id", string.Empty); - serializer.DataField(this, x => x.Actions, "actions", new List()); - } + [DataField("actions")] + public IReadOnlyList Actions { get; private set; } = new List(); } } diff --git a/Content.Server/Actions/DebugInstant.cs b/Content.Server/Actions/DebugInstant.cs index 568d3827a9..d20029b192 100644 --- a/Content.Server/Actions/DebugInstant.cs +++ b/Content.Server/Actions/DebugInstant.cs @@ -2,7 +2,7 @@ using Content.Shared.Actions; using Content.Shared.Utility; using JetBrains.Annotations; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Actions { @@ -10,16 +10,11 @@ namespace Content.Server.Actions /// Just shows a popup message.asd /// [UsedImplicitly] + [DataDefinition] public class DebugInstant : IInstantAction, IInstantItemAction { - public string Message { get; private set; } - public float Cooldown { get; private set; } - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Message, "message", "Instant action used."); - serializer.DataField(this, x => x.Cooldown, "cooldown", 0); - } + [DataField("message")] public string Message { get; [UsedImplicitly] private set; } = "Instant action used."; + [DataField("cooldown")] public float Cooldown { get; [UsedImplicitly] private set; } public void DoInstantAction(InstantItemActionEventArgs args) { diff --git a/Content.Server/Actions/DebugTargetEntity.cs b/Content.Server/Actions/DebugTargetEntity.cs index 0809a33e72..a6537ae47b 100644 --- a/Content.Server/Actions/DebugTargetEntity.cs +++ b/Content.Server/Actions/DebugTargetEntity.cs @@ -1,17 +1,14 @@ using Content.Server.Utility; using Content.Shared.Actions; using JetBrains.Annotations; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Actions { [UsedImplicitly] + [DataDefinition] public class DebugTargetEntity : ITargetEntityAction, ITargetEntityItemAction { - void IExposeData.ExposeData(ObjectSerializer serializer) - { - } - public void DoTargetEntityAction(TargetEntityItemActionEventArgs args) { args.Performer.PopupMessageEveryone(args.Item.Name + ": Clicked " + diff --git a/Content.Server/Actions/DebugTargetPoint.cs b/Content.Server/Actions/DebugTargetPoint.cs index 3e1b831bf6..c26959076a 100644 --- a/Content.Server/Actions/DebugTargetPoint.cs +++ b/Content.Server/Actions/DebugTargetPoint.cs @@ -1,17 +1,14 @@ using Content.Server.Utility; using Content.Shared.Actions; using JetBrains.Annotations; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Actions { [UsedImplicitly] + [DataDefinition] public class DebugTargetPoint : ITargetPointAction, ITargetPointItemAction { - void IExposeData.ExposeData(ObjectSerializer serializer) - { - } - public void DoTargetPointAction(TargetPointItemActionEventArgs args) { args.Performer.PopupMessageEveryone(args.Item.Name + ": Clicked local position " + diff --git a/Content.Server/Actions/DebugToggle.cs b/Content.Server/Actions/DebugToggle.cs index 92b002c463..a2ddaa1500 100644 --- a/Content.Server/Actions/DebugToggle.cs +++ b/Content.Server/Actions/DebugToggle.cs @@ -1,21 +1,16 @@ using Content.Server.Utility; using Content.Shared.Actions; using JetBrains.Annotations; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Actions { [UsedImplicitly] + [DataDefinition] public class DebugToggle : IToggleAction, IToggleItemAction { - public string MessageOn { get; private set; } - public string MessageOff { get; private set; } - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.MessageOn, "messageOn", "on!"); - serializer.DataField(this, x => x.MessageOff, "messageOff", "off!"); - } + [DataField("messageOn")] public string MessageOn { get; private set; } = "on!"; + [DataField("messageOff")] public string MessageOff { get; private set; } = "off!"; public bool DoToggleAction(ToggleItemActionEventArgs args) { diff --git a/Content.Server/Actions/DisarmAction.cs b/Content.Server/Actions/DisarmAction.cs index 10a6971469..5e2e7cd722 100644 --- a/Content.Server/Actions/DisarmAction.cs +++ b/Content.Server/Actions/DisarmAction.cs @@ -18,23 +18,17 @@ using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Maths; using Robust.Shared.Random; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Actions { [UsedImplicitly] + [DataDefinition] public class DisarmAction : ITargetEntityAction { - private float _failProb; - private float _pushProb; - private float _cooldown; - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(ref _failProb, "failProb", 0.4f); - serializer.DataField(ref _pushProb, "pushProb", 0.4f); - serializer.DataField(ref _cooldown, "cooldown", 1.5f); - } + [DataField("failProb")] private float _failProb = 0.4f; + [DataField("pushProb")] private float _pushProb = 0.4f; + [DataField("cooldown")] private float _cooldown = 1.5f; public void DoTargetEntityAction(TargetEntityActionEventArgs args) { diff --git a/Content.Server/Actions/GhostBoo.cs b/Content.Server/Actions/GhostBoo.cs index e8ab01becc..f272ad9334 100644 --- a/Content.Server/Actions/GhostBoo.cs +++ b/Content.Server/Actions/GhostBoo.cs @@ -6,6 +6,7 @@ using Content.Shared.GameObjects.Components.Mobs; using Content.Shared.Utility; using JetBrains.Annotations; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Actions { @@ -13,18 +14,12 @@ namespace Content.Server.Actions /// Blink lights and scare livings /// [UsedImplicitly] + [DataDefinition] public class GhostBoo : IInstantAction { - private float _radius; - private float _cooldown; - private int _maxTargets; - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(ref _radius, "radius", 3); - serializer.DataField(ref _cooldown, "cooldown", 120); - serializer.DataField(ref _maxTargets, "maxTargets", 3); - } + [DataField("radius")] private float _radius = 3; + [DataField("cooldown")] private float _cooldown = 120; + [DataField("maxTargets")] private int _maxTargets = 3; public void DoInstantAction(InstantActionEventArgs args) { diff --git a/Content.Server/Actions/ScreamAction.cs b/Content.Server/Actions/ScreamAction.cs index 542ad73840..04ec08e597 100644 --- a/Content.Server/Actions/ScreamAction.cs +++ b/Content.Server/Actions/ScreamAction.cs @@ -1,4 +1,5 @@ -using System; +#nullable enable +using System; using System.Collections.Generic; using Content.Server.GameObjects.Components.Mobs; using Content.Shared.Actions; @@ -13,35 +14,29 @@ using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Random; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Actions { [UsedImplicitly] + [DataDefinition] public class ScreamAction : IInstantAction { private const float Variation = 0.125f; private const float Volume = 4f; - private List _male; - private List _female; - private string _wilhelm; - /// seconds - private float _cooldown; + [Dependency] private readonly IRobustRandom _random = default!; - private IRobustRandom _random; + [DataField("male")] private List? _male; + [DataField("female")] private List? _female; + [DataField("wilhelm")] private string? _wilhelm; + + /// seconds + [DataField("cooldown")] private float _cooldown = 10; public ScreamAction() { - _random = IoCManager.Resolve(); - } - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(ref _male, "male", null); - serializer.DataField(ref _female, "female", null); - serializer.DataField(ref _wilhelm, "wilhelm", null); - serializer.DataField(ref _cooldown, "cooldown", 10); + IoCManager.InjectDependencies(this); } public void DoInstantAction(InstantActionEventArgs args) diff --git a/Content.Server/Alert/Click/RemoveCuffs.cs b/Content.Server/Alert/Click/RemoveCuffs.cs index 06f615a2ec..29a1ea7b81 100644 --- a/Content.Server/Alert/Click/RemoveCuffs.cs +++ b/Content.Server/Alert/Click/RemoveCuffs.cs @@ -2,7 +2,7 @@ using Content.Server.GameObjects.Components.ActionBlocking; using Content.Shared.Alert; using JetBrains.Annotations; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Alert.Click { @@ -10,10 +10,9 @@ namespace Content.Server.Alert.Click /// Try to remove handcuffs from yourself /// [UsedImplicitly] + [DataDefinition] public class RemoveCuffs : IAlertClick { - void IExposeData.ExposeData(ObjectSerializer serializer) {} - public void AlertClicked(ClickAlertEventArgs args) { if (args.Player.TryGetComponent(out CuffableComponent? cuffableComponent)) diff --git a/Content.Server/Alert/Click/ResistFire.cs b/Content.Server/Alert/Click/ResistFire.cs index 7f45cfa408..7a6e2a5fe0 100644 --- a/Content.Server/Alert/Click/ResistFire.cs +++ b/Content.Server/Alert/Click/ResistFire.cs @@ -1,7 +1,7 @@ -using Content.Server.GameObjects.Components.Atmos; - using Content.Shared.Alert; - using JetBrains.Annotations; - using Robust.Shared.Serialization; +using Content.Server.GameObjects.Components.Atmos; +using Content.Shared.Alert; +using JetBrains.Annotations; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Alert.Click { @@ -9,10 +9,9 @@ namespace Content.Server.Alert.Click /// Resist fire /// [UsedImplicitly] + [DataDefinition] public class ResistFire : IAlertClick { - void IExposeData.ExposeData(ObjectSerializer serializer) { } - public void AlertClicked(ClickAlertEventArgs args) { if (args.Player.TryGetComponent(out FlammableComponent flammable)) diff --git a/Content.Server/Alert/Click/StopPiloting.cs b/Content.Server/Alert/Click/StopPiloting.cs index 2b27062bbe..6b50396d4d 100644 --- a/Content.Server/Alert/Click/StopPiloting.cs +++ b/Content.Server/Alert/Click/StopPiloting.cs @@ -1,7 +1,7 @@ using Content.Server.GameObjects.Components.Movement; - using Content.Shared.Alert; - using JetBrains.Annotations; -using Robust.Shared.Serialization; +using Content.Shared.Alert; +using JetBrains.Annotations; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Alert.Click { @@ -9,10 +9,9 @@ namespace Content.Server.Alert.Click /// Stop piloting shuttle /// [UsedImplicitly] + [DataDefinition] public class StopPiloting : IAlertClick { - void IExposeData.ExposeData(ObjectSerializer serializer) { } - public void AlertClicked(ClickAlertEventArgs args) { if (args.Player.TryGetComponent(out ShuttleControllerComponent controller)) diff --git a/Content.Server/Alert/Click/StopPulling.cs b/Content.Server/Alert/Click/StopPulling.cs index b0bde32872..d1cb2b0778 100644 --- a/Content.Server/Alert/Click/StopPulling.cs +++ b/Content.Server/Alert/Click/StopPulling.cs @@ -1,9 +1,9 @@ using Content.Shared.Alert; - using Content.Shared.GameObjects.Components.Pulling; - using Content.Shared.GameObjects.EntitySystems; - using JetBrains.Annotations; +using Content.Shared.GameObjects.Components.Pulling; +using Content.Shared.GameObjects.EntitySystems; +using JetBrains.Annotations; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Alert.Click { @@ -11,10 +11,9 @@ namespace Content.Server.Alert.Click /// Stop pulling something /// [UsedImplicitly] + [DataDefinition] public class StopPulling : IAlertClick { - void IExposeData.ExposeData(ObjectSerializer serializer) { } - public void AlertClicked(ClickAlertEventArgs args) { EntitySystem diff --git a/Content.Server/Alert/Click/Unbuckle.cs b/Content.Server/Alert/Click/Unbuckle.cs index 48d3e182de..210575748f 100644 --- a/Content.Server/Alert/Click/Unbuckle.cs +++ b/Content.Server/Alert/Click/Unbuckle.cs @@ -1,7 +1,7 @@ using Content.Server.GameObjects.Components.Buckle; using Content.Shared.Alert; -using Robust.Shared.Serialization; using JetBrains.Annotations; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Alert.Click { @@ -9,10 +9,9 @@ namespace Content.Server.Alert.Click /// Unbuckles if player is currently buckled. /// [UsedImplicitly] + [DataDefinition] public class Unbuckle : IAlertClick { - void IExposeData.ExposeData(ObjectSerializer serializer) { } - public void AlertClicked(ClickAlertEventArgs args) { if (args.Player.TryGetComponent(out BuckleComponent buckle)) diff --git a/Content.Server/Atmos/GasMixture.cs b/Content.Server/Atmos/GasMixture.cs index be9cb63c56..9c1721b01f 100644 --- a/Content.Server/Atmos/GasMixture.cs +++ b/Content.Server/Atmos/GasMixture.cs @@ -10,6 +10,7 @@ using Content.Shared.Atmos; using Robust.Shared.GameObjects; using Robust.Shared.Maths; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.Atmos @@ -18,28 +19,28 @@ namespace Content.Server.Atmos /// A general-purpose, variable volume gas mixture. /// [Serializable] - public class GasMixture : IExposeData, IEquatable, ICloneable + [DataDefinition] + public class GasMixture : IEquatable, ICloneable, ISerializationHooks { - private readonly AtmosphereSystem _atmosphereSystem; + private AtmosphereSystem? _atmosphereSystem; public static GasMixture SpaceGas => new() {Volume = 2500f, Immutable = true, Temperature = Atmospherics.TCMB}; // This must always have a length that is a multiple of 4 for SIMD acceleration. - [ViewVariables] - private float[] _moles; + [DataField("moles")] [ViewVariables] private float[] _moles = new float[Atmospherics.AdjustedNumberOfGases]; - [ViewVariables] - private float[] _molesArchived; + [DataField("molesArchived")] [ViewVariables] + private float[] _molesArchived = new float[Atmospherics.AdjustedNumberOfGases]; - [ViewVariables] + [DataField("temperature")] [ViewVariables] private float _temperature = Atmospherics.TCMB; public IReadOnlyList Gases => _moles; - [ViewVariables] + [DataField("immutable")] [ViewVariables] public bool Immutable { get; private set; } - [ViewVariables] + [DataField("lastShare")] [ViewVariables] public float LastShare { get; private set; } [ViewVariables] @@ -55,6 +56,7 @@ namespace Content.Server.Atmos [MethodImpl(MethodImplOptions.AggressiveInlining)] get { + _atmosphereSystem ??= EntitySystem.Get(); Span tmp = stackalloc float[_moles.Length]; NumericsHelpers.Multiply(_moles, _atmosphereSystem.GasSpecificHeats, tmp); @@ -68,6 +70,7 @@ namespace Content.Server.Atmos [MethodImpl(MethodImplOptions.AggressiveInlining)] get { + _atmosphereSystem ??= EntitySystem.Get(); Span tmp = stackalloc float[_moles.Length]; NumericsHelpers.Multiply(_molesArchived, _atmosphereSystem.GasSpecificHeats, tmp); @@ -106,10 +109,10 @@ namespace Content.Server.Atmos [ViewVariables] public float ThermalEnergy => Temperature * HeatCapacity; - [ViewVariables] + [DataField("temperatureArchived")] [ViewVariables] public float TemperatureArchived { get; private set; } - [ViewVariables] + [DataField("volume")] [ViewVariables] public float Volume { get; set; } public GasMixture() : this(null) @@ -118,9 +121,7 @@ namespace Content.Server.Atmos public GasMixture(AtmosphereSystem? atmosphereSystem) { - _atmosphereSystem = atmosphereSystem ?? EntitySystem.Get(); - _moles = new float[Atmospherics.AdjustedNumberOfGases]; - _molesArchived = new float[Atmospherics.AdjustedNumberOfGases]; + _atmosphereSystem = atmosphereSystem; } public GasMixture(float volume, AtmosphereSystem? atmosphereSystem = null): this(atmosphereSystem) @@ -262,6 +263,7 @@ namespace Content.Server.Atmos [MethodImpl(MethodImplOptions.AggressiveInlining)] public float Share(GasMixture sharer, int atmosAdjacentTurfs) { + _atmosphereSystem ??= EntitySystem.Get(); var temperatureDelta = TemperatureArchived - sharer.TemperatureArchived; var absTemperatureDelta = Math.Abs(temperatureDelta); var oldHeatCapacity = 0f; @@ -485,6 +487,7 @@ namespace Content.Server.Atmos [MethodImpl(MethodImplOptions.AggressiveInlining)] public ReactionResult React(IGasMixtureHolder holder) { + _atmosphereSystem ??= EntitySystem.Get(); var reaction = ReactionResult.NoReaction; var temperature = Temperature; var energy = ThermalEnergy; @@ -533,16 +536,8 @@ namespace Content.Server.Atmos NumericsHelpers.Multiply(_moles, multiplier); } - void IExposeData.ExposeData(ObjectSerializer serializer) + void ISerializationHooks.AfterDeserialization() { - serializer.DataField(this, x => x.Immutable, "immutable", false); - serializer.DataField(this, x => x.Volume, "volume", 0f); - serializer.DataField(this, x => x.LastShare, "lastShare", 0f); - serializer.DataField(this, x => x.TemperatureArchived, "temperatureArchived", 0f); - serializer.DataField(ref _moles, "moles", new float[Atmospherics.AdjustedNumberOfGases]); - serializer.DataField(ref _molesArchived, "molesArchived", new float[Atmospherics.AdjustedNumberOfGases]); - serializer.DataField(ref _temperature, "temperature", Atmospherics.TCMB); - // The arrays MUST have a specific length. Array.Resize(ref _moles, Atmospherics.AdjustedNumberOfGases); Array.Resize(ref _molesArchived, Atmospherics.AdjustedNumberOfGases); diff --git a/Content.Server/Atmos/Reactions/GasReactionPrototype.cs b/Content.Server/Atmos/Reactions/GasReactionPrototype.cs index 6805f8f2d2..179864a04a 100644 --- a/Content.Server/Atmos/Reactions/GasReactionPrototype.cs +++ b/Content.Server/Atmos/Reactions/GasReactionPrototype.cs @@ -1,11 +1,12 @@ +#nullable enable using System; using System.Collections.Generic; using Content.Server.Interfaces; using Content.Shared.Atmos; using Robust.Server.GameObjects; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; namespace Content.Server.Atmos.Reactions { @@ -25,45 +26,43 @@ namespace Content.Server.Atmos.Reactions [Prototype("gasReaction")] public class GasReactionPrototype : IPrototype { - public string ID { get; private set; } + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; + + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } /// /// Minimum gas amount requirements. /// - public float[] MinimumRequirements { get; private set; } + [DataField("minimumRequirements")] + public float[] MinimumRequirements { get; private set; } = new float[Atmospherics.TotalNumberOfGases]; /// /// Minimum temperature requirement. /// - public float MinimumTemperatureRequirement { get; private set; } + [DataField("minimumTemperature")] + public float MinimumTemperatureRequirement { get; private set; } = Atmospherics.TCMB; /// /// Minimum energy requirement. /// + [DataField("minimumEnergy")] public float MinimumEnergyRequirement { get; private set; } /// /// Lower numbers are checked/react later than higher numbers. /// If two reactions have the same priority, they may happen in either order. /// + [DataField("priority")] public int Priority { get; private set; } /// /// A list of effects this will produce. /// - private List _effects; - - public void LoadFrom(YamlMappingNode mapping) - { - var serializer = YamlObjectSerializer.NewReader(mapping); - - serializer.DataField(this, x => x.ID, "id", string.Empty); - serializer.DataField(this, x => x.Priority, "priority", 100); - serializer.DataField(this, x => x.MinimumRequirements, "minimumRequirements", new float[Atmospherics.TotalNumberOfGases]); - serializer.DataField(this, x => x.MinimumTemperatureRequirement, "minimumTemperature", Atmospherics.TCMB); - serializer.DataField(this, x => x.MinimumEnergyRequirement, "minimumEnergy", 0f); - serializer.DataField(ref _effects, "effects", new List()); - } + [DataField("effects")] private List _effects = new(); public ReactionResult React(GasMixture mixture, IGasMixtureHolder holder, GridTileLookupSystem gridLookup) { diff --git a/Content.Server/Atmos/Reactions/PlasmaFireReaction.cs b/Content.Server/Atmos/Reactions/PlasmaFireReaction.cs index ae4197b3a8..8dde9eb74a 100644 --- a/Content.Server/Atmos/Reactions/PlasmaFireReaction.cs +++ b/Content.Server/Atmos/Reactions/PlasmaFireReaction.cs @@ -5,11 +5,12 @@ using Content.Server.Utility; using Content.Shared.Atmos; using JetBrains.Annotations; using Robust.Server.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Atmos.Reactions { [UsedImplicitly] + [DataDefinition] public class PlasmaFireReaction : IGasReactionEffect { public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, GridTileLookupSystem gridTileLookup) @@ -87,9 +88,5 @@ namespace Content.Server.Atmos.Reactions return mixture.ReactionResults[GasReaction.Fire] != 0 ? ReactionResult.Reacting : ReactionResult.NoReaction; } - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - } } } diff --git a/Content.Server/Atmos/Reactions/TritiumFireReaction.cs b/Content.Server/Atmos/Reactions/TritiumFireReaction.cs index 4a5109d5e2..a605480726 100644 --- a/Content.Server/Atmos/Reactions/TritiumFireReaction.cs +++ b/Content.Server/Atmos/Reactions/TritiumFireReaction.cs @@ -4,17 +4,14 @@ using Content.Server.Utility; using Content.Shared.Atmos; using JetBrains.Annotations; using Robust.Server.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Atmos.Reactions { [UsedImplicitly] + [DataDefinition] public class TritiumFireReaction : IGasReactionEffect { - void IExposeData.ExposeData(ObjectSerializer serializer) - { - } - public ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, GridTileLookupSystem gridTileLookup) { var energyReleased = 0f; diff --git a/Content.Server/Botany/Seed.cs b/Content.Server/Botany/Seed.cs index e56ed2c28f..44b5ed898f 100644 --- a/Content.Server/Botany/Seed.cs +++ b/Content.Server/Botany/Seed.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Collections.Generic; using System.Linq; @@ -15,10 +16,9 @@ using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Prototypes; using Robust.Shared.Random; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; -using YamlDotNet.RepresentationModel; namespace Content.Server.Botany { @@ -59,19 +59,29 @@ namespace Content.Server.Botany } */ + [DataDefinition] public struct SeedChemQuantity { + [DataField("Min")] public int Min; + [DataField("Max")] public int Max; + [DataField("PotencyDivisor")] public int PotencyDivisor; } [Prototype("seed")] - public class Seed : IPrototype, IExposeData + public class Seed : IPrototype { private const string SeedPrototype = "SeedBase"; - public string ID { get; private set; } + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; private init; } = default!; + + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } /// /// Unique identifier of this seed. Do NOT set this. @@ -79,45 +89,84 @@ namespace Content.Server.Botany public int Uid { get; internal set; } = -1; #region Tracking - [ViewVariables] public string Name { get; set; } - [ViewVariables] public string SeedName { get; set; } - [ViewVariables] public string SeedNoun { get; set; } - [ViewVariables] public string DisplayName { get; set; } - [ViewVariables] public bool RoundStart { get; private set; } - [ViewVariables] public bool Mysterious { get; set; } - [ViewVariables] public bool Immutable { get; set; } + + [ViewVariables] [DataField("name")] public string Name { get; set; } = string.Empty; + [ViewVariables] [DataField("seedName")] public string SeedName { get; set; } = string.Empty; + + [ViewVariables] + [DataField("seedNoun")] + public string SeedNoun { get; set; } = "seeds"; + [ViewVariables] [DataField("displayName")] public string DisplayName { get; set; } = string.Empty; + + [ViewVariables] + [DataField("roundStart")] + public bool RoundStart { get; private set; } = true; + [ViewVariables] [DataField("mysterious")] public bool Mysterious { get; set; } + [ViewVariables] [DataField("immutable")] public bool Immutable { get; set; } #endregion #region Output - [ViewVariables] public List ProductPrototypes { get; set; } - [ViewVariables] public Dictionary Chemicals { get; set; } - [ViewVariables] public Dictionary ConsumeGasses { get; set; } - [ViewVariables]public Dictionary ExudeGasses { get; set; } + + [ViewVariables] + [DataField("productPrototypes")] + public List ProductPrototypes { get; set; } = new(); + + [ViewVariables] + [DataField("chemicals")] + public Dictionary Chemicals { get; set; } = new(); + + [ViewVariables] + [DataField("consumeGasses")] + public Dictionary ConsumeGasses { get; set; } = new(); + + [ViewVariables] + [DataField("exudeGasses")] + public Dictionary ExudeGasses { get; set; } = new(); #endregion #region Tolerances - [ViewVariables] public float NutrientConsumption { get; set; } - [ViewVariables] public float WaterConsumption { get; set; } - [ViewVariables] public float IdealHeat { get; set; } - [ViewVariables] public float HeatTolerance { get; set; } - [ViewVariables] public float IdealLight { get; set; } - [ViewVariables] public float LightTolerance { get; set; } - [ViewVariables] public float ToxinsTolerance { get; set; } - [ViewVariables] public float LowPressureTolerance { get; set; } - [ViewVariables] public float HighPressureTolerance { get; set; } - [ViewVariables] public float PestTolerance { get; set; } - [ViewVariables] public float WeedTolerance { get; set; } + + [ViewVariables] + [DataField("nutrientConsumption")] + public float NutrientConsumption { get; set; } = 0.25f; + + [ViewVariables] [DataField("waterConsumption")] public float WaterConsumption { get; set; } = 3f; + [ViewVariables] [DataField("idealHeat")] public float IdealHeat { get; set; } = 293f; + [ViewVariables] [DataField("heatTolerance")] public float HeatTolerance { get; set; } = 20f; + [ViewVariables] [DataField("idealLight")] public float IdealLight { get; set; } = 7f; + [ViewVariables] [DataField("lightTolerance")] public float LightTolerance { get; set; } = 5f; + [ViewVariables] [DataField("toxinsTolerance")] public float ToxinsTolerance { get; set; } = 4f; + + [ViewVariables] + [DataField("lowPressureTolerance")] + public float LowPressureTolerance { get; set; } = 25f; + + [ViewVariables] + [DataField("highPressureTolerance")] + public float HighPressureTolerance { get; set; } = 200f; + + [ViewVariables] + [DataField("pestTolerance")] + public float PestTolerance { get; set; } = 5f; + + [ViewVariables] + [DataField("weedTolerance")] + public float WeedTolerance { get; set; } = 5f; #endregion #region General traits - [ViewVariables] public float Endurance { get; set; } - [ViewVariables] public int Yield { get; set; } - [ViewVariables] public float Lifespan { get; set; } - [ViewVariables] public float Maturation { get; set; } - [ViewVariables] public float Production { get; set; } - [ViewVariables] public int GrowthStages { get; set; } - [ViewVariables] public HarvestType HarvestRepeat { get; set; } - [ViewVariables] public float Potency { get; set; } + + [ViewVariables] + [DataField("endurance")] + public float Endurance { get; set; } = 100f; + [ViewVariables] [DataField("yield")] public int Yield { get; set; } + [ViewVariables] [DataField("lifespan")] public float Lifespan { get; set; } + [ViewVariables] [DataField("maturation")] public float Maturation { get; set; } + [ViewVariables] [DataField("production")] public float Production { get; set; } + [ViewVariables] [DataField("growthStages")] public int GrowthStages { get; set; } = 6; + [ViewVariables] [DataField("harvestRepeat")] public HarvestType HarvestRepeat { get; set; } = HarvestType.NoRepeat; + + [ViewVariables] [DataField("potency")] public float Potency { get; set; } = 1f; // No, I'm not removing these. //public PlantSpread Spread { get; set; } //public PlantMutation Mutation { get; set; } @@ -127,72 +176,36 @@ namespace Content.Server.Botany //public bool Hematophage { get; set; } //public bool Thorny { get; set; } //public bool Stinging { get; set; } + [DataField("ligneous")] public bool Ligneous { get; set; } // public bool Teleporting { get; set; } // public PlantJuicy Juicy { get; set; } #endregion #region Cosmetics - [ViewVariables]public ResourcePath PlantRsi { get; set; } - [ViewVariables] public string PlantIconState { get; set; } - [ViewVariables] public bool Bioluminescent { get; set; } - [ViewVariables] public Color BioluminescentColor { get; set; } - [ViewVariables] public string SplatPrototype { get; set; } + + [ViewVariables] + [DataField("plantRsi", required: true)] + public ResourcePath PlantRsi { get; set; } = default!; + + [ViewVariables] + [DataField("plantIconState")] + public string PlantIconState { get; set; } = "produce"; + + [ViewVariables] + [DataField("bioluminescent")] + public bool Bioluminescent { get; set; } + + [ViewVariables] + [DataField("bioluminescentColor")] + public Color BioluminescentColor { get; set; } = Color.White; + + [ViewVariables] + [DataField("splatPrototype")] + public string? SplatPrototype { get; set; } + #endregion - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - InternalExposeData(serializer); - } - - public void InternalExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.ID, "id", string.Empty); - serializer.DataField(this, x => x.Name, "name", string.Empty); - serializer.DataField(this, x => x.SeedName, "seedName", string.Empty); - serializer.DataField(this, x => x.SeedNoun, "seedNoun", "seeds"); - serializer.DataField(this, x => x.DisplayName, "displayName", string.Empty); - serializer.DataField(this, x => x.RoundStart, "roundStart", true); - serializer.DataField(this, x => x.Mysterious, "mysterious", false); - serializer.DataField(this, x => x.Immutable, "immutable", false); - serializer.DataField(this, x => x.ProductPrototypes, "productPrototypes", new List()); - serializer.DataField(this, x => x.Chemicals, "chemicals", new Dictionary()); - serializer.DataField(this, x => x.ConsumeGasses, "consumeGasses", new Dictionary()); - serializer.DataField(this, x => x.ExudeGasses, "exudeGasses", new Dictionary()); - serializer.DataField(this, x => x.NutrientConsumption, "nutrientConsumption", 0.25f); - serializer.DataField(this, x => x.WaterConsumption, "waterConsumption", 3f); - serializer.DataField(this, x => x.IdealHeat, "idealHeat", 293f); - serializer.DataField(this, x => x.HeatTolerance, "heatTolerance", 20f); - serializer.DataField(this, x => x.IdealLight, "idealLight", 7f); - serializer.DataField(this, x => x.LightTolerance, "lightTolerance", 5f); - serializer.DataField(this, x => x.ToxinsTolerance, "toxinsTolerance", 4f); - serializer.DataField(this, x => x.LowPressureTolerance, "lowPressureTolerance", 25f); - serializer.DataField(this, x => x.HighPressureTolerance, "highPressureTolerance", 200f); - serializer.DataField(this, x => x.PestTolerance, "pestTolerance", 5f); - serializer.DataField(this, x => x.WeedTolerance, "weedTolerance", 5f); - serializer.DataField(this, x => x.Endurance, "endurance", 100f); - serializer.DataField(this, x => x.Yield, "yield", 0); - serializer.DataField(this, x => x.Lifespan, "lifespan", 0f); - serializer.DataField(this, x => x.Maturation, "maturation", 0f); - serializer.DataField(this, x => x.Production, "production", 0f); - serializer.DataField(this, x => x.GrowthStages, "growthStages", 6); - serializer.DataField(this, x => x.HarvestRepeat, "harvestRepeat", HarvestType.NoRepeat); - serializer.DataField(this, x => x.Potency, "potency", 1f); - serializer.DataField(this, x => x.Ligneous, "ligneous", false); - serializer.DataField(this, x => x.PlantRsi, "plantRsi", null); - serializer.DataField(this, x => x.PlantIconState, "plantIconState", "produce"); - serializer.DataField(this, x => x.Bioluminescent, "bioluminescent", false); - serializer.DataField(this, x => x.BioluminescentColor, "bioluminescentColor", Color.White); - serializer.DataField(this, x => x.SplatPrototype, "splatPrototype", string.Empty); - } - - public void LoadFrom(YamlMappingNode mapping) - { - var serializer = YamlObjectSerializer.NewReader(mapping); - InternalExposeData(serializer); - } - public Seed Clone() { var newSeed = new Seed() @@ -240,7 +253,7 @@ namespace Content.Server.Botany return newSeed; } - public IEntity SpawnSeedPacket(EntityCoordinates transformCoordinates, IEntityManager entityManager = null) + public IEntity SpawnSeedPacket(EntityCoordinates transformCoordinates, IEntityManager? entityManager = null) { entityManager ??= IoCManager.Resolve(); @@ -249,7 +262,7 @@ namespace Content.Server.Botany var seedComp = seed.EnsureComponent(); seedComp.Seed = this; - if (seed.TryGetComponent(out SpriteComponent sprite)) + if (seed.TryGetComponent(out SpriteComponent? sprite)) { // Seed state will always be seed. Blame the spriter if that's not the case! sprite.LayerSetSprite(0, new SpriteSpecifier.Rsi(PlantRsi, "seed")); @@ -346,7 +359,7 @@ namespace Content.Server.Botany return Clone(); } - public bool CheckHarvest(IEntity user, IEntity held = null) + public bool CheckHarvest(IEntity user, IEntity? held = null) { return (!Ligneous || (Ligneous && held != null && held.HasTag("BotanySharp"))); } diff --git a/Content.Server/Chemistry/Metabolism/DefaultDrink.cs b/Content.Server/Chemistry/Metabolism/DefaultDrink.cs index 5edd38f1e9..1803f475f9 100644 --- a/Content.Server/Chemistry/Metabolism/DefaultDrink.cs +++ b/Content.Server/Chemistry/Metabolism/DefaultDrink.cs @@ -2,7 +2,7 @@ using Content.Shared.Chemistry; using Content.Shared.Interfaces.Chemistry; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Chemistry.Metabolism { @@ -10,21 +10,16 @@ namespace Content.Server.Chemistry.Metabolism /// Default metabolism for drink reagents. Attempts to find a ThirstComponent on the target, /// and to update it's thirst values. /// + [DataDefinition] public class DefaultDrink : IMetabolizable { //Rate of metabolism in units / second - private ReagentUnit _metabolismRate; - public ReagentUnit MetabolismRate => _metabolismRate; + [DataField("rate")] + public ReagentUnit MetabolismRate { get; set; } = ReagentUnit.New(1); //How much thirst is satiated when 1u of the reagent is metabolized - private float _hydrationFactor; - public float HydrationFactor => _hydrationFactor; - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(ref _metabolismRate, "rate", ReagentUnit.New(1)); - serializer.DataField(ref _hydrationFactor, "nutrimentFactor", 30.0f); - } + [DataField("hydrationFactor")] + public float HydrationFactor { get; set; } = 30.0f; //Remove reagent at set rate, satiate thirst if a ThirstComponent can be found ReagentUnit IMetabolizable.Metabolize(IEntity solutionEntity, string reagentId, float tickTime) diff --git a/Content.Server/Chemistry/Metabolism/DefaultFood.cs b/Content.Server/Chemistry/Metabolism/DefaultFood.cs index 8259073a30..3cca60f728 100644 --- a/Content.Server/Chemistry/Metabolism/DefaultFood.cs +++ b/Content.Server/Chemistry/Metabolism/DefaultFood.cs @@ -2,7 +2,7 @@ using Content.Shared.Chemistry; using Content.Shared.Interfaces.Chemistry; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Chemistry.Metabolism { @@ -10,21 +10,18 @@ namespace Content.Server.Chemistry.Metabolism /// Default metabolism for food reagents. Attempts to find a HungerComponent on the target, /// and to update it's hunger values. /// + [DataDefinition] public class DefaultFood : IMetabolizable { - //Rate of metabolism in units / second - private ReagentUnit _metabolismRate; - public ReagentUnit MetabolismRate => _metabolismRate; + /// + /// Rate of metabolism in units / second + /// + [DataField("rate")] public ReagentUnit MetabolismRate { get; private set; } = ReagentUnit.New(1.0); - //How much hunger is satiated when 1u of the reagent is metabolized - private float _nutritionFactor; - public float NutritionFactor => _nutritionFactor; - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(ref _metabolismRate, "rate", ReagentUnit.New(1.0)); - serializer.DataField(ref _nutritionFactor, "nutrimentFactor", 30.0f); - } + /// + /// How much hunger is satiated when 1u of the reagent is metabolized + /// + [DataField("nutritionFactor")] public float NutritionFactor { get; set; } = 30.0f; //Remove reagent at set rate, satiate hunger if a HungerComponent can be found ReagentUnit IMetabolizable.Metabolize(IEntity solutionEntity, string reagentId, float tickTime) diff --git a/Content.Server/Chemistry/PlantMetabolism/AdjustAttribute.cs b/Content.Server/Chemistry/PlantMetabolism/AdjustAttribute.cs index fc8491c429..27bb681f30 100644 --- a/Content.Server/Chemistry/PlantMetabolism/AdjustAttribute.cs +++ b/Content.Server/Chemistry/PlantMetabolism/AdjustAttribute.cs @@ -5,22 +5,17 @@ using Content.Shared.Interfaces.Chemistry; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Random; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Chemistry.PlantMetabolism { + [ImplicitDataDefinitionForInheritors] public abstract class AdjustAttribute : IPlantMetabolizable { [Dependency] private readonly IRobustRandom _robustRandom = default!; - public float Amount { get; private set; } - public float Prob { get; private set; } - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Amount, "amount", 1f); - serializer.DataField(this, x => x.Prob, "prob", 1f); - } + [DataField("amount")] public float Amount { get; protected set; } = 1; + [DataField("prob")] public float Prob { get; protected set; } = 1; // = (80); /// /// Checks if the plant holder can metabolize the reagent or not. Checks if it has an alive plant by default. diff --git a/Content.Server/Chemistry/PlantMetabolism/Clonexadone.cs b/Content.Server/Chemistry/PlantMetabolism/Clonexadone.cs index b741ac23da..546567bfa9 100644 --- a/Content.Server/Chemistry/PlantMetabolism/Clonexadone.cs +++ b/Content.Server/Chemistry/PlantMetabolism/Clonexadone.cs @@ -6,17 +6,14 @@ using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Random; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Chemistry.PlantMetabolism { [UsedImplicitly] + [DataDefinition] public class Clonexadone : IPlantMetabolizable { - void IExposeData.ExposeData(ObjectSerializer serializer) - { - } - public void Metabolize(IEntity plantHolder, float customPlantMetabolism = 1) { if (plantHolder.Deleted || !plantHolder.TryGetComponent(out PlantHolderComponent? plantHolderComp) diff --git a/Content.Server/Chemistry/PlantMetabolism/Diethylamine.cs b/Content.Server/Chemistry/PlantMetabolism/Diethylamine.cs index 85d577a3a4..3e7d40fa6b 100644 --- a/Content.Server/Chemistry/PlantMetabolism/Diethylamine.cs +++ b/Content.Server/Chemistry/PlantMetabolism/Diethylamine.cs @@ -6,17 +6,14 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Maths; using Robust.Shared.Random; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Chemistry.PlantMetabolism { [UsedImplicitly] + [DataDefinition] public class Diethylamine : IPlantMetabolizable { - void IExposeData.ExposeData(ObjectSerializer serializer) - { - } - public void Metabolize(IEntity plantHolder, float customPlantMetabolism = 1) { if (plantHolder.Deleted || !plantHolder.TryGetComponent(out PlantHolderComponent? plantHolderComp) diff --git a/Content.Server/Chemistry/PlantMetabolism/RobustHarvest.cs b/Content.Server/Chemistry/PlantMetabolism/RobustHarvest.cs index e2bbbab75d..68b36c9349 100644 --- a/Content.Server/Chemistry/PlantMetabolism/RobustHarvest.cs +++ b/Content.Server/Chemistry/PlantMetabolism/RobustHarvest.cs @@ -6,17 +6,14 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Maths; using Robust.Shared.Random; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Chemistry.PlantMetabolism { [UsedImplicitly] + [DataDefinition] public class RobustHarvest : IPlantMetabolizable { - void IExposeData.ExposeData(ObjectSerializer serializer) - { - } - public void Metabolize(IEntity plantHolder, float customPlantMetabolism = 1f) { if (plantHolder.Deleted || !plantHolder.TryGetComponent(out PlantHolderComponent? plantHolderComp) diff --git a/Content.Server/Chemistry/ReactionEffects/AreaReactionEffect.cs b/Content.Server/Chemistry/ReactionEffects/AreaReactionEffect.cs index 275c5dd2db..4eb1d9a83e 100644 --- a/Content.Server/Chemistry/ReactionEffects/AreaReactionEffect.cs +++ b/Content.Server/Chemistry/ReactionEffects/AreaReactionEffect.cs @@ -1,16 +1,16 @@ #nullable enable using System; using Content.Server.GameObjects.Components.Chemistry; -using Content.Server.Interfaces.Chemistry; using Content.Server.Utility; using Content.Shared.Audio; +using Content.Shared.Interfaces.Chemistry; using JetBrains.Annotations; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Map; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Chemistry.ReactionEffects { @@ -18,6 +18,7 @@ namespace Content.Server.Chemistry.ReactionEffects /// Basically smoke and foam reactions. /// [UsedImplicitly] + [ImplicitDataDefinitionForInheritors] public abstract class AreaReactionEffect : IReactionEffect { [Dependency] private readonly IMapManager _mapManager = default!; @@ -25,82 +26,65 @@ namespace Content.Server.Chemistry.ReactionEffects /// /// Used for calculating the spread range of the effect based on the intensity of the reaction. /// - private float _rangeConstant; - private float _rangeMultiplier; - private int _maxRange; + [DataField("rangeConstant")] private float _rangeConstant; + [DataField("rangeMultiplier")] private float _rangeMultiplier = 1.1f; + [DataField("maxRange")] private int _maxRange = 10; /// /// If true the reagents get diluted or concentrated depending on the range of the effect /// - private bool _diluteReagents; + [DataField("diluteReagents")] private bool _diluteReagents; /// /// At what range should the reagents volume stay the same. If the effect range is higher than this then the reagents /// will get diluted. If the effect range is lower than this then the reagents will get concentrated. /// - private int _reagentDilutionStart; + [DataField("reagentDilutionStart")] private int _reagentDilutionStart = 4; /// /// Used to calculate dilution. Increasing this makes the reagents get more diluted. This means that a lower range /// will be needed to make the reagents volume get closer to zero. /// - private float _reagentDilutionFactor; + [DataField("reagentDilutionFactor")] private float _reagentDilutionFactor = 1; /// /// Used to calculate concentration. Reagents get linearly more concentrated as the range goes from /// _reagentDilutionStart to zero. When the range is zero the reagents volume gets multiplied by this. /// - private float _reagentMaxConcentrationFactor; + [DataField("reagentMaxConcentrationFactor")] + private float _reagentMaxConcentrationFactor = 2; /// /// How many seconds will the effect stay, counting after fully spreading. /// - private float _duration; + [DataField("duration")] private float _duration = 10; /// /// How many seconds between each spread step. /// - private float _spreadDelay; + [DataField("spreadDelay")] private float _spreadDelay = 0.5f; /// /// How many seconds between each remove step. /// - private float _removeDelay; + [DataField("removeDelay")] private float _removeDelay = 0.5f; /// /// The entity prototype that will be spawned as the effect. It needs a component derived from SolutionAreaEffectComponent. /// - private string? _prototypeId; + [DataField("prototypeId", required: true)] + private string _prototypeId = default!; /// /// Sound that will get played when this reaction effect occurs. /// - private string? _sound; + [DataField("sound")] private string? _sound; protected AreaReactionEffect() { IoCManager.InjectDependencies(this); } - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(ref _rangeConstant, "rangeConstant",0f); - serializer.DataField(ref _rangeMultiplier, "rangeMultiplier",1.1f); - serializer.DataField(ref _maxRange, "maxRange", 10); - serializer.DataField(ref _diluteReagents, "diluteReagents", false); - serializer.DataField(ref _reagentDilutionStart, "reagentDilutionStart", 4); - serializer.DataField(ref _reagentDilutionFactor, "reagentDilutionFactor", 1f); - serializer.DataField(ref _reagentMaxConcentrationFactor, "reagentMaxConcentrationFactor",2f); - serializer.DataField(ref _duration, "duration", 10f); - serializer.DataField(ref _spreadDelay, "spreadDelay", 0.5f); - serializer.DataField(ref _removeDelay, "removeDelay", 0.5f); - serializer.DataField(ref _sound, "sound", null); - serializer.DataField(ref _prototypeId, "prototypeId", null); - - if (_prototypeId == null) - Logger.Error("prototypeId wasn't provided to AreaReactionEffect, check yaml"); - } - public void React(IEntity solutionEntity, double intensity) { if (!solutionEntity.TryGetComponent(out SolutionContainerComponent? contents)) diff --git a/Content.Server/Chemistry/ReactionEffects/ExplosionReactionEffect.cs b/Content.Server/Chemistry/ReactionEffects/ExplosionReactionEffect.cs index 57286a0b3b..6b7167adbb 100644 --- a/Content.Server/Chemistry/ReactionEffects/ExplosionReactionEffect.cs +++ b/Content.Server/Chemistry/ReactionEffects/ExplosionReactionEffect.cs @@ -1,43 +1,34 @@ using System; using Content.Server.Explosions; using Content.Server.GameObjects.Components.Chemistry; -using Content.Server.Interfaces.Chemistry; +using Content.Shared.Interfaces.Chemistry; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Chemistry.ReactionEffects { + [DataDefinition] public class ExplosionReactionEffect : IReactionEffect { - private float _devastationRange; - private float _heavyImpactRange; - private float _lightImpactRange; - private float _flashRange; + [DataField("devastationRange")] private float _devastationRange = 1; + [DataField("heavyImpactRange")] private float _heavyImpactRange = 2; + [DataField("lightImpactRange")] private float _lightImpactRange = 3; + [DataField("flashRange")] private float _flashRange; /// /// If true, then scale ranges by intensity. If not, the ranges are the same regardless of reactant amount. /// - private bool _scaled; + [DataField("scaled")] private bool _scaled; + /// /// Maximum scaling on ranges. For example, if it equals 5, then it won't scaled anywhere past /// 5 times the minimum reactant amount. /// - private float _maxScale; - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(ref _devastationRange, "devastationRange", 1); - serializer.DataField(ref _heavyImpactRange, "heavyImpactRange", 2); - serializer.DataField(ref _lightImpactRange, "lightImpactRange", 3); - serializer.DataField(ref _flashRange, "flashRange", 0); - - serializer.DataField(ref _scaled, "scaled", false); - serializer.DataField(ref _maxScale, "maxScale", 1); - } + [DataField("maxScale")] private float _maxScale = 1; public void React(IEntity solutionEntity, double intensity) { - float floatIntensity = (float)intensity; + var floatIntensity = (float)intensity; if (solutionEntity == null) return; if(!solutionEntity.TryGetComponent(out SolutionContainerComponent solution)) @@ -54,10 +45,10 @@ namespace Content.Server.Chemistry.ReactionEffects } //Calculate intensities - int finalDevastationRange = (int)MathF.Round(_devastationRange * floatIntensity); - int finalHeavyImpactRange = (int)MathF.Round(_heavyImpactRange * floatIntensity); - int finalLightImpactRange = (int)MathF.Round(_lightImpactRange * floatIntensity); - int finalFlashRange = (int)MathF.Round(_flashRange * floatIntensity); + var finalDevastationRange = (int)MathF.Round(_devastationRange * floatIntensity); + var finalHeavyImpactRange = (int)MathF.Round(_heavyImpactRange * floatIntensity); + var finalLightImpactRange = (int)MathF.Round(_lightImpactRange * floatIntensity); + var finalFlashRange = (int)MathF.Round(_flashRange * floatIntensity); solutionEntity.SpawnExplosion(finalDevastationRange, finalHeavyImpactRange, finalLightImpactRange, finalFlashRange); } diff --git a/Content.Server/Chemistry/ReactionEffects/FoamAreaReactionEffect.cs b/Content.Server/Chemistry/ReactionEffects/FoamAreaReactionEffect.cs index 2e3b10a6ab..afa22d2e7f 100644 --- a/Content.Server/Chemistry/ReactionEffects/FoamAreaReactionEffect.cs +++ b/Content.Server/Chemistry/ReactionEffects/FoamAreaReactionEffect.cs @@ -2,10 +2,12 @@ using Content.Server.GameObjects.Components.Chemistry; using JetBrains.Annotations; using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Chemistry.ReactionEffects { [UsedImplicitly] + [DataDefinition] public class FoamAreaReactionEffect : AreaReactionEffect { protected override SolutionAreaEffectComponent? GetAreaEffectComponent(IEntity entity) diff --git a/Content.Server/Chemistry/ReactionEffects/SmokeAreaReactionEffect.cs b/Content.Server/Chemistry/ReactionEffects/SmokeAreaReactionEffect.cs index 1537ecdd8b..993fdbec6b 100644 --- a/Content.Server/Chemistry/ReactionEffects/SmokeAreaReactionEffect.cs +++ b/Content.Server/Chemistry/ReactionEffects/SmokeAreaReactionEffect.cs @@ -2,10 +2,12 @@ using Content.Server.GameObjects.Components.Chemistry; using JetBrains.Annotations; using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Chemistry.ReactionEffects { [UsedImplicitly] + [DataDefinition] public class SmokeAreaReactionEffect : AreaReactionEffect { protected override SolutionAreaEffectComponent? GetAreaEffectComponent(IEntity entity) diff --git a/Content.Server/Chemistry/TileReactions/CleanTileReaction.cs b/Content.Server/Chemistry/TileReactions/CleanTileReaction.cs index 6a693f582b..2780c105bb 100644 --- a/Content.Server/Chemistry/TileReactions/CleanTileReaction.cs +++ b/Content.Server/Chemistry/TileReactions/CleanTileReaction.cs @@ -1,19 +1,16 @@ -using Content.Server.GameObjects.Components; +using System.Linq; +using Content.Server.GameObjects.Components; using Content.Server.Utility; using Content.Shared.Chemistry; using Content.Shared.Interfaces.Chemistry; using Robust.Shared.Map; -using Robust.Shared.Serialization; -using System.Linq; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Chemistry.TileReactions { + [DataDefinition] public class CleanTileReaction : ITileReaction { - void IExposeData.ExposeData(ObjectSerializer serializer) - { - } - ReagentUnit ITileReaction.TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume) { var entities = tile.GetEntitiesInTileFast().ToArray(); diff --git a/Content.Server/Chemistry/TileReactions/ExtinguishTileReaction.cs b/Content.Server/Chemistry/TileReactions/ExtinguishTileReaction.cs index 876497d876..b9e05a5454 100644 --- a/Content.Server/Chemistry/TileReactions/ExtinguishTileReaction.cs +++ b/Content.Server/Chemistry/TileReactions/ExtinguishTileReaction.cs @@ -5,19 +5,15 @@ using Content.Shared.Chemistry; using Content.Shared.Interfaces.Chemistry; using JetBrains.Annotations; using Robust.Shared.Map; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Chemistry.TileReactions { [UsedImplicitly] + [DataDefinition] public class ExtinguishTileReaction : ITileReaction { - private float _coolingTemperature = 2f; - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(ref _coolingTemperature, "coolingTemperature", 2f); - } + [DataField("coolingTemperature")] private float _coolingTemperature = 2f; public ReagentUnit TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume) { diff --git a/Content.Server/Chemistry/TileReactions/FlammableTileReaction.cs b/Content.Server/Chemistry/TileReactions/FlammableTileReaction.cs index 7194772906..d09312ee28 100644 --- a/Content.Server/Chemistry/TileReactions/FlammableTileReaction.cs +++ b/Content.Server/Chemistry/TileReactions/FlammableTileReaction.cs @@ -4,19 +4,15 @@ using Content.Shared.Chemistry; using Content.Shared.Interfaces.Chemistry; using JetBrains.Annotations; using Robust.Shared.Map; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Chemistry.TileReactions { [UsedImplicitly] + [DataDefinition] public class FlammableTileReaction : ITileReaction { - private float _temperatureMultiplier = 1.25f; - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(ref _temperatureMultiplier, "temperatureMultiplier", 1.15f); - } + [DataField("temperatureMultiplier")] private float _temperatureMultiplier = 1.15f; public ReagentUnit TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume) { diff --git a/Content.Server/Chemistry/TileReactions/SpillIfPuddlePresentTileReaction.cs b/Content.Server/Chemistry/TileReactions/SpillIfPuddlePresentTileReaction.cs index 1f978d1983..410d788ffc 100644 --- a/Content.Server/Chemistry/TileReactions/SpillIfPuddlePresentTileReaction.cs +++ b/Content.Server/Chemistry/TileReactions/SpillIfPuddlePresentTileReaction.cs @@ -3,17 +3,14 @@ using Content.Shared.Chemistry; using Content.Shared.Interfaces.Chemistry; using JetBrains.Annotations; using Robust.Shared.Map; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Chemistry.TileReactions { [UsedImplicitly] + [DataDefinition] public class SpillIfPuddlePresentTileReaction : ITileReaction { - void IExposeData.ExposeData(ObjectSerializer serializer) - { - } - public ReagentUnit TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume) { if (reactVolume < 5 || !tile.TryGetPuddle(null, out _)) return ReagentUnit.Zero; diff --git a/Content.Server/Chemistry/TileReactions/SpillTileReaction.cs b/Content.Server/Chemistry/TileReactions/SpillTileReaction.cs index a2435706ee..f54cba13ba 100644 --- a/Content.Server/Chemistry/TileReactions/SpillTileReaction.cs +++ b/Content.Server/Chemistry/TileReactions/SpillTileReaction.cs @@ -4,26 +4,18 @@ using Content.Shared.Chemistry; using Content.Shared.Interfaces.Chemistry; using JetBrains.Annotations; using Robust.Shared.Map; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Chemistry.TileReactions { [UsedImplicitly] + [DataDefinition] public class SpillTileReaction : ITileReaction { - private float _launchForwardsMultiplier = 1f; - private float _requiredSlipSpeed = 6f; - private float _paralyzeTime = 1f; - private bool _overflow; - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - // If you want to modify more puddle/slippery values, add them here. - serializer.DataField(ref _paralyzeTime, "paralyzeTime", 1f); - serializer.DataField(ref _launchForwardsMultiplier, "launchForwardsMultiplier", 1f); - serializer.DataField(ref _requiredSlipSpeed, "requiredSlipSpeed", 6f); - serializer.DataField(ref _overflow, "overflow", false); - } + [DataField("launchForwardsMultiplier")] private float _launchForwardsMultiplier = 1; + [DataField("requiredSlipSpeed")] private float _requiredSlipSpeed = 6; + [DataField("paralyzeTime")] private float _paralyzeTime = 1; + [DataField("overflow")] private bool _overflow; public ReagentUnit TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume) { diff --git a/Content.Server/Commands/GameTicking/TileWallsCommand.cs b/Content.Server/Commands/GameTicking/TileWallsCommand.cs index dd402f7320..4873af00d5 100644 --- a/Content.Server/Commands/GameTicking/TileWallsCommand.cs +++ b/Content.Server/Commands/GameTicking/TileWallsCommand.cs @@ -6,6 +6,7 @@ using Robust.Shared.Console; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Map; +using Robust.Shared.Prototypes; namespace Content.Server.Commands.GameTicking { @@ -62,6 +63,7 @@ namespace Content.Server.Commands.GameTicking } var tileDefinitionManager = IoCManager.Resolve(); + var prototypeManager = IoCManager.Resolve(); var underplating = tileDefinitionManager["underplating"]; var underplatingTile = new Tile(underplating.TileId); var changed = 0; @@ -80,7 +82,7 @@ namespace Content.Server.Commands.GameTicking break; } - prototype = prototype.Parent; + prototype = prototypeManager.Index(prototype.Parent); } if (prototype?.ID != "base_wall") diff --git a/Content.Server/Construction/Completions/AddContainer.cs b/Content.Server/Construction/Completions/AddContainer.cs index ab3ae50fa8..dda330691f 100644 --- a/Content.Server/Construction/Completions/AddContainer.cs +++ b/Content.Server/Construction/Completions/AddContainer.cs @@ -4,19 +4,15 @@ using Content.Server.GameObjects.Components.Construction; using Content.Shared.Construction; using JetBrains.Annotations; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Construction.Completions { [UsedImplicitly] + [DataDefinition] public class AddContainer : IGraphAction { - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Container, "container", null); - } - - public string? Container { get; private set; } = null; + [DataField("container")] public string? Container { get; private set; } = null; public async Task PerformAction(IEntity entity, IEntity? user) { diff --git a/Content.Server/Construction/Completions/BuildComputer.cs b/Content.Server/Construction/Completions/BuildComputer.cs index da71d12e8c..7c7f63ccea 100644 --- a/Content.Server/Construction/Completions/BuildComputer.cs +++ b/Content.Server/Construction/Completions/BuildComputer.cs @@ -7,19 +7,15 @@ using JetBrains.Annotations; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Log; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Construction.Completions { [UsedImplicitly] + [DataDefinition] public class BuildComputer : IGraphAction { - public string Container { get; private set; } = string.Empty; - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Container, "container", string.Empty); - } + [DataField("container")] public string Container { get; private set; } = string.Empty; public async Task PerformAction(IEntity entity, IEntity? user) { diff --git a/Content.Server/Construction/Completions/BuildMachine.cs b/Content.Server/Construction/Completions/BuildMachine.cs index 6804c9a765..ecac0dc52b 100644 --- a/Content.Server/Construction/Completions/BuildMachine.cs +++ b/Content.Server/Construction/Completions/BuildMachine.cs @@ -7,11 +7,12 @@ using JetBrains.Annotations; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Log; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Construction.Completions { [UsedImplicitly] + [DataDefinition] public class BuildMachine : IGraphAction { public async Task PerformAction(IEntity entity, IEntity? user) @@ -104,9 +105,5 @@ namespace Content.Server.Construction.Completions entity.Delete(); } - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - } } } diff --git a/Content.Server/Construction/Completions/DeleteEntity.cs b/Content.Server/Construction/Completions/DeleteEntity.cs index 2b924578a5..cf21ebf322 100644 --- a/Content.Server/Construction/Completions/DeleteEntity.cs +++ b/Content.Server/Construction/Completions/DeleteEntity.cs @@ -3,17 +3,14 @@ using System.Threading.Tasks; using Content.Shared.Construction; using JetBrains.Annotations; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Construction.Completions { [UsedImplicitly] + [DataDefinition] public class DeleteEntity : IGraphAction { - void IExposeData.ExposeData(ObjectSerializer serializer) - { - } - public async Task PerformAction(IEntity entity, IEntity? user) { if (entity.Deleted) return; diff --git a/Content.Server/Construction/Completions/EmptyAllContainers.cs b/Content.Server/Construction/Completions/EmptyAllContainers.cs index fd03859f01..f18ec92397 100644 --- a/Content.Server/Construction/Completions/EmptyAllContainers.cs +++ b/Content.Server/Construction/Completions/EmptyAllContainers.cs @@ -4,17 +4,14 @@ using Content.Shared.Construction; using JetBrains.Annotations; using Robust.Shared.Containers; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Construction.Completions { [UsedImplicitly] + [DataDefinition] public class EmptyAllContainers : IGraphAction { - void IExposeData.ExposeData(ObjectSerializer serializer) - { - } - public async Task PerformAction(IEntity entity, IEntity? user) { if (entity.Deleted || !entity.TryGetComponent(out var containerManager)) diff --git a/Content.Server/Construction/Completions/EmptyContainer.cs b/Content.Server/Construction/Completions/EmptyContainer.cs index 95f27a83b0..6d76d7f713 100644 --- a/Content.Server/Construction/Completions/EmptyContainer.cs +++ b/Content.Server/Construction/Completions/EmptyContainer.cs @@ -5,19 +5,15 @@ using Content.Shared.Construction; using JetBrains.Annotations; using Robust.Shared.Containers; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Construction.Completions { [UsedImplicitly] + [DataDefinition] public class EmptyContainer : IGraphAction { - public string Container { get; private set; } = string.Empty; - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Container, "container", string.Empty); - } + [DataField("container")] public string Container { get; private set; } = string.Empty; public async Task PerformAction(IEntity entity, IEntity? user) { diff --git a/Content.Server/Construction/Completions/MachineFrameRegenerateProgress.cs b/Content.Server/Construction/Completions/MachineFrameRegenerateProgress.cs index c76ca72184..404e76fac9 100644 --- a/Content.Server/Construction/Completions/MachineFrameRegenerateProgress.cs +++ b/Content.Server/Construction/Completions/MachineFrameRegenerateProgress.cs @@ -4,16 +4,14 @@ using Content.Server.GameObjects.Components.Construction; using Content.Shared.Construction; using JetBrains.Annotations; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Construction.Completions { [UsedImplicitly] + [DataDefinition] public class MachineFrameRegenerateProgress : IGraphAction { - void IExposeData.ExposeData(ObjectSerializer serializer) - { } - public async Task PerformAction(IEntity entity, IEntity? user) { if (entity.Deleted) diff --git a/Content.Server/Construction/Completions/PlaySound.cs b/Content.Server/Construction/Completions/PlaySound.cs index be859e9726..891b600907 100644 --- a/Content.Server/Construction/Completions/PlaySound.cs +++ b/Content.Server/Construction/Completions/PlaySound.cs @@ -5,21 +5,16 @@ using Content.Shared.Construction; using JetBrains.Annotations; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Construction.Completions { [UsedImplicitly] + [DataDefinition] public class PlaySound : IGraphAction { - public string SoundCollection { get; private set; } = string.Empty; - public string Sound { get; private set; } = string.Empty; - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Sound, "sound", string.Empty); - serializer.DataField(this, x => x.SoundCollection, "soundCollection", string.Empty); - } + [DataField("soundCollection")] public string SoundCollection { get; private set; } = string.Empty; + [DataField("sound")] public string Sound { get; private set; } = string.Empty; public async Task PerformAction(IEntity entity, IEntity? user) { diff --git a/Content.Server/Construction/Completions/PopupUser.cs b/Content.Server/Construction/Completions/PopupUser.cs index 28275c806e..275fbd78d0 100644 --- a/Content.Server/Construction/Completions/PopupUser.cs +++ b/Content.Server/Construction/Completions/PopupUser.cs @@ -4,21 +4,16 @@ using Content.Shared.Construction; using Content.Shared.Interfaces; using JetBrains.Annotations; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Construction.Completions { [UsedImplicitly] + [DataDefinition] public class PopupUser : IGraphAction { - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Text, "text", string.Empty); - serializer.DataField(this, x => x.Cursor, "cursor", false); - } - - public bool Cursor { get; private set; } = false; - public string Text { get; private set; } = string.Empty; + [DataField("cursor")] public bool Cursor { get; private set; } = false; + [DataField("text")] public string Text { get; private set; } = string.Empty; public async Task PerformAction(IEntity entity, IEntity? user) { diff --git a/Content.Server/Construction/Completions/SetAnchor.cs b/Content.Server/Construction/Completions/SetAnchor.cs index 69037b8b79..7127b29294 100644 --- a/Content.Server/Construction/Completions/SetAnchor.cs +++ b/Content.Server/Construction/Completions/SetAnchor.cs @@ -3,19 +3,15 @@ using System.Threading.Tasks; using Content.Shared.Construction; using JetBrains.Annotations; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Construction.Completions { [UsedImplicitly] + [DataDefinition] public class SetAnchor : IGraphAction { - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Value, "value", true); - } - - public bool Value { get; private set; } = true; + [DataField("value")] public bool Value { get; private set; } = true; public async Task PerformAction(IEntity entity, IEntity? user) { diff --git a/Content.Server/Construction/Completions/SetStackCount.cs b/Content.Server/Construction/Completions/SetStackCount.cs index 9ac78c5dfb..87c001f18c 100644 --- a/Content.Server/Construction/Completions/SetStackCount.cs +++ b/Content.Server/Construction/Completions/SetStackCount.cs @@ -1,24 +1,20 @@ #nullable enable +using System; using System.Threading.Tasks; using Content.Server.GameObjects.Components.Stack; using Content.Shared.Construction; using JetBrains.Annotations; -using System; using Robust.Shared.GameObjects; using Robust.Shared.Log; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Construction.Completions { [UsedImplicitly] + [DataDefinition] public class SetStackCount : IGraphAction { - public int Amount { get; private set; } - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Amount, "amount", 1); - } + [DataField("amount")] public int Amount { get; private set; } = 1; public async Task PerformAction(IEntity entity, IEntity? user) { diff --git a/Content.Server/Construction/Completions/SnapToGrid.cs b/Content.Server/Construction/Completions/SnapToGrid.cs index b0a9356769..33b015aacf 100644 --- a/Content.Server/Construction/Completions/SnapToGrid.cs +++ b/Content.Server/Construction/Completions/SnapToGrid.cs @@ -6,20 +6,17 @@ using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.Serialization; using Robust.Shared.Maths; +using Robust.Shared.Serialization.Manager.Attributes; +using YamlDotNet.Serialization; namespace Content.Server.Construction.Completions { [UsedImplicitly] + [DataDefinition] public class SnapToGrid : IGraphAction { - public SnapGridOffset Offset { get; private set; } = SnapGridOffset.Center; - public bool SouthRotation { get; private set; } = false; - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Offset, "offset", SnapGridOffset.Center); - serializer.DataField(this, x => x.SouthRotation, "southRotation", false); - } + [DataField("offset")] public SnapGridOffset Offset { get; private set; } = SnapGridOffset.Center; + [DataField("southRotation")] public bool SouthRotation { get; private set; } = false; public async Task PerformAction(IEntity entity, IEntity? user) { diff --git a/Content.Server/Construction/Completions/SpawnPrototype.cs b/Content.Server/Construction/Completions/SpawnPrototype.cs index be3b2fc7b4..bf0a1d020b 100644 --- a/Content.Server/Construction/Completions/SpawnPrototype.cs +++ b/Content.Server/Construction/Completions/SpawnPrototype.cs @@ -7,22 +7,16 @@ using Content.Shared.Utility; using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Construction.Completions { [UsedImplicitly] + [DataDefinition] public class SpawnPrototype : IGraphAction { - public string Prototype { get; private set; } = string.Empty; - public int Amount { get; private set; } = 1; - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Prototype, "prototype", string.Empty); - serializer.DataField(this, x => x.Amount, "amount", 1); - } - + [DataField("prototype")] public string Prototype { get; private set; } = string.Empty; + [DataField("amount")] public int Amount { get; private set; } = 1; public async Task PerformAction(IEntity entity, IEntity? user) { diff --git a/Content.Server/Construction/Completions/SpriteChange.cs b/Content.Server/Construction/Completions/SpriteChange.cs index 8547407196..bf62c52b27 100644 --- a/Content.Server/Construction/Completions/SpriteChange.cs +++ b/Content.Server/Construction/Completions/SpriteChange.cs @@ -4,22 +4,17 @@ using Content.Shared.Construction; using JetBrains.Annotations; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; namespace Content.Server.Construction.Completions { [UsedImplicitly] + [DataDefinition] public class SpriteChange : IGraphAction { - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.SpriteSpecifier, "specifier", SpriteSpecifier.Invalid); - serializer.DataField(this, x => x.Layer, "layer", 0); - } - - public int Layer { get; private set; } = 0; - public SpriteSpecifier? SpriteSpecifier { get; private set; } = SpriteSpecifier.Invalid; + [DataField("layer")] public int Layer { get; private set; } = 0; + [DataField("specifier")] public SpriteSpecifier? SpriteSpecifier { get; private set; } = SpriteSpecifier.Invalid; public async Task PerformAction(IEntity entity, IEntity? user) { diff --git a/Content.Server/Construction/Completions/SpriteStateChange.cs b/Content.Server/Construction/Completions/SpriteStateChange.cs index 7296b42662..bef8330d92 100644 --- a/Content.Server/Construction/Completions/SpriteStateChange.cs +++ b/Content.Server/Construction/Completions/SpriteStateChange.cs @@ -4,21 +4,16 @@ using Content.Shared.Construction; using JetBrains.Annotations; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Construction.Completions { [UsedImplicitly] + [DataDefinition] public class SpriteStateChange : IGraphAction { - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.State, "state", string.Empty); - serializer.DataField(this, x => x.Layer, "layer", 0); - } - - public int Layer { get; private set; } = 0; - public string? State { get; private set; } = string.Empty; + [DataField("layer")] public int Layer { get; private set; } = 0; + [DataField("state")] public string? State { get; private set; } = string.Empty; public async Task PerformAction(IEntity entity, IEntity? user) { diff --git a/Content.Server/Construction/Completions/VisualizerDataInt.cs b/Content.Server/Construction/Completions/VisualizerDataInt.cs index 1cb52454f6..59ddaf7579 100644 --- a/Content.Server/Construction/Completions/VisualizerDataInt.cs +++ b/Content.Server/Construction/Completions/VisualizerDataInt.cs @@ -6,11 +6,12 @@ using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Reflection; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Construction.Completions { [UsedImplicitly] + [DataDefinition] public class VisualizerDataInt : IGraphAction { [Dependency] private readonly IReflectionManager _reflectionManager = default!; @@ -20,14 +21,8 @@ namespace Content.Server.Construction.Completions IoCManager.InjectDependencies(this); } - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Key, "key", string.Empty); - serializer.DataField(this, x => x.Data, "data", 0); - } - - public string? Key { get; private set; } = string.Empty; - public int Data { get; private set; } = 0; + [DataField("key")] public string Key { get; private set; } = string.Empty; + [DataField("data")] public int Data { get; private set; } = 0; public async Task PerformAction(IEntity entity, IEntity? user) { diff --git a/Content.Server/Construction/Conditions/AllWiresCut.cs b/Content.Server/Construction/Conditions/AllWiresCut.cs index de2d53fe6c..3a3cffc687 100644 --- a/Content.Server/Construction/Conditions/AllWiresCut.cs +++ b/Content.Server/Construction/Conditions/AllWiresCut.cs @@ -3,7 +3,7 @@ using Content.Server.GameObjects.Components; using Content.Shared.Construction; using JetBrains.Annotations; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Construction.Conditions { @@ -12,14 +12,10 @@ namespace Content.Server.Construction.Conditions /// Returns true if the entity doesn't have a wires component. /// [UsedImplicitly] + [DataDefinition] public class AllWiresCut : IEdgeCondition { - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Value, "value", true); - } - - public bool Value { get; private set; } = true; + [DataField("value")] public bool Value { get; private set; } = true; public async Task Condition(IEntity entity) { diff --git a/Content.Server/Construction/Conditions/ComponentInTile.cs b/Content.Server/Construction/Conditions/ComponentInTile.cs index 45cc323fba..83e04cc6c5 100644 --- a/Content.Server/Construction/Conditions/ComponentInTile.cs +++ b/Content.Server/Construction/Conditions/ComponentInTile.cs @@ -5,7 +5,7 @@ using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Map; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Construction.Conditions { @@ -13,6 +13,7 @@ namespace Content.Server.Construction.Conditions /// Makes the condition fail if any entities on a tile have (or not) a component. /// [UsedImplicitly] + [DataDefinition] public class ComponentInTile : IEdgeCondition { [Dependency] private readonly IComponentFactory _componentFactory = default!; @@ -23,22 +24,18 @@ namespace Content.Server.Construction.Conditions IoCManager.InjectDependencies(this); } - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Component, "component", string.Empty); - serializer.DataField(this, x => x.HasEntity, "hasEntity", true); - } - /// /// If true, any entity on the tile must have the component. /// If false, no entity on the tile must have the component. /// + [DataField("hasEntity")] public bool HasEntity { get; private set; } /// /// The component name in question. /// - public string Component { get; private set; } + [DataField("component")] + public string Component { get; private set; } = string.Empty; public async Task Condition(IEntity entity) { diff --git a/Content.Server/Construction/Conditions/ContainerEmpty.cs b/Content.Server/Construction/Conditions/ContainerEmpty.cs index 3dbd549dc7..89e6de21f3 100644 --- a/Content.Server/Construction/Conditions/ContainerEmpty.cs +++ b/Content.Server/Construction/Conditions/ContainerEmpty.cs @@ -4,22 +4,17 @@ using Content.Shared.Construction; using JetBrains.Annotations; using Robust.Shared.Containers; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; namespace Content.Server.Construction.Conditions { [UsedImplicitly] + [DataDefinition] public class ContainerEmpty : IEdgeCondition { - public string Container { get; private set; } = string.Empty; - public string Text { get; private set; } = string.Empty; - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Container, "container", string.Empty); - serializer.DataField(this, x => x.Text, "text", string.Empty); - } + [DataField("container")] public string Container { get; private set; } = string.Empty; + [DataField("text")] public string Text { get; private set; } = string.Empty; public async Task Condition(IEntity entity) { diff --git a/Content.Server/Construction/Conditions/DoorWelded.cs b/Content.Server/Construction/Conditions/DoorWelded.cs index 982f88d3ef..8d1810703e 100644 --- a/Content.Server/Construction/Conditions/DoorWelded.cs +++ b/Content.Server/Construction/Conditions/DoorWelded.cs @@ -4,20 +4,16 @@ using Content.Shared.Construction; using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.Localization; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; namespace Content.Server.Construction.Conditions { [UsedImplicitly] + [DataDefinition] public class DoorWelded : IEdgeCondition { - public bool Welded { get; private set; } - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Welded, "welded", true); - } + [DataField("welded")] public bool Welded { get; private set; } = true; public async Task Condition(IEntity entity) { diff --git a/Content.Server/Construction/Conditions/EntityAnchored.cs b/Content.Server/Construction/Conditions/EntityAnchored.cs index 8dcb5bfc76..c72a93c713 100644 --- a/Content.Server/Construction/Conditions/EntityAnchored.cs +++ b/Content.Server/Construction/Conditions/EntityAnchored.cs @@ -2,20 +2,16 @@ using Content.Shared.Construction; using JetBrains.Annotations; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; namespace Content.Server.Construction.Conditions { [UsedImplicitly] + [DataDefinition] public class EntityAnchored : IEdgeCondition { - public bool Anchored { get; private set; } - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Anchored, "anchored", true); - } + [DataField("anchored")] public bool Anchored { get; private set; } = true; public async Task Condition(IEntity entity) { diff --git a/Content.Server/Construction/Conditions/MachineFrameComplete.cs b/Content.Server/Construction/Conditions/MachineFrameComplete.cs index bc66d08aea..61a1984c30 100644 --- a/Content.Server/Construction/Conditions/MachineFrameComplete.cs +++ b/Content.Server/Construction/Conditions/MachineFrameComplete.cs @@ -4,7 +4,7 @@ using Content.Shared.Construction; using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.Localization; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; namespace Content.Server.Construction.Conditions @@ -13,10 +13,9 @@ namespace Content.Server.Construction.Conditions /// Checks that the entity has all parts needed in the machine frame component. /// [UsedImplicitly] + [DataDefinition] public class MachineFrameComplete : IEdgeCondition { - void IExposeData.ExposeData(ObjectSerializer serializer) { } - public async Task Condition(IEntity entity) { if (entity.Deleted || !entity.TryGetComponent(out var machineFrame)) diff --git a/Content.Server/Construction/Conditions/ToiletLidClosed.cs b/Content.Server/Construction/Conditions/ToiletLidClosed.cs index 93bc91b085..2fb7043279 100644 --- a/Content.Server/Construction/Conditions/ToiletLidClosed.cs +++ b/Content.Server/Construction/Conditions/ToiletLidClosed.cs @@ -5,12 +5,13 @@ using Content.Shared.Construction; using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.Localization; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; namespace Content.Server.Construction.Conditions { [UsedImplicitly] + [DataDefinition] public class ToiletLidClosed : IEdgeCondition { public async Task Condition(IEntity entity) @@ -27,9 +28,5 @@ namespace Content.Server.Construction.Conditions message.AddMarkup(Loc.GetString("Use a [color=yellow]crowbar[/color] to close the lid.\n")); return true; } - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - } } } diff --git a/Content.Server/Construction/Conditions/WirePanel.cs b/Content.Server/Construction/Conditions/WirePanel.cs index 8d76ff3b18..6344dc0bd8 100644 --- a/Content.Server/Construction/Conditions/WirePanel.cs +++ b/Content.Server/Construction/Conditions/WirePanel.cs @@ -4,20 +4,16 @@ using Content.Shared.Construction; using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.Localization; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; namespace Content.Server.Construction.Conditions { [UsedImplicitly] + [DataDefinition] public class WirePanel : IEdgeCondition { - public bool Open { get; private set; } - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Open, "open", true); - } + [DataField("open")] public bool Open { get; private set; } = true; public async Task Condition(IEntity entity) { diff --git a/Content.Server/Content.Server.csproj b/Content.Server/Content.Server.csproj index 5ea8cbed75..92daac324a 100644 --- a/Content.Server/Content.Server.csproj +++ b/Content.Server/Content.Server.csproj @@ -25,4 +25,5 @@ + diff --git a/Content.Server/GameObjects/Components/AI/AiFactionPrototype.cs b/Content.Server/GameObjects/Components/AI/AiFactionPrototype.cs index 5a0c15fd36..02790d7b3d 100644 --- a/Content.Server/GameObjects/Components/AI/AiFactionPrototype.cs +++ b/Content.Server/GameObjects/Components/AI/AiFactionPrototype.cs @@ -1,8 +1,8 @@ #nullable enable using System.Collections.Generic; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.AI { @@ -11,17 +11,15 @@ namespace Content.Server.GameObjects.Components.AI { // These are immutable so any dynamic changes aren't saved back over. // AiFactionSystem will just read these and then store them. + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; - public string ID { get; private set; } = default!; + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } - public IReadOnlyList Hostile { get; private set; } = default!; - - public void LoadFrom(YamlMappingNode mapping) - { - var serializer = YamlObjectSerializer.NewReader(mapping); - - serializer.DataField(this, x => x.ID, "id", string.Empty); - serializer.DataField(this, x => x.Hostile, "hostile", new List()); - } + [DataField("hostile")] + public IReadOnlyList Hostile { get; private set; } = new List(); } } diff --git a/Content.Server/GameObjects/Components/AI/AiFactionTagComponent.cs b/Content.Server/GameObjects/Components/AI/AiFactionTagComponent.cs index 8a87590260..57f6a0f0b5 100644 --- a/Content.Server/GameObjects/Components/AI/AiFactionTagComponent.cs +++ b/Content.Server/GameObjects/Components/AI/AiFactionTagComponent.cs @@ -1,9 +1,7 @@ #nullable enable -using System; -using System.Collections.Generic; using Content.Server.GameObjects.EntitySystems.AI; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.AI { @@ -12,29 +10,7 @@ namespace Content.Server.GameObjects.Components.AI { public override string Name => "AiFactionTag"; + [DataField("factions")] public Faction Factions { get; private set; } = Faction.None; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataReadWriteFunction( - "factions", - new List(), - factions => factions.ForEach(faction => Factions |= faction), - () => - { - var writeFactions = new List(); - foreach (Faction fac in Enum.GetValues(typeof(Faction))) - { - if ((Factions & fac) != 0) - { - writeFactions.Add(fac); - } - } - - return writeFactions; - }); - } } } diff --git a/Content.Server/GameObjects/Components/Access/AccessComponent.cs b/Content.Server/GameObjects/Components/Access/AccessComponent.cs index ad3d1f21a1..e90ecbf9e1 100644 --- a/Content.Server/GameObjects/Components/Access/AccessComponent.cs +++ b/Content.Server/GameObjects/Components/Access/AccessComponent.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using Content.Server.Interfaces; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Access @@ -16,25 +16,13 @@ namespace Content.Server.GameObjects.Components.Access { public override string Name => "Access"; + [DataField("tags")] [ViewVariables] private readonly HashSet _tags = new(); public ISet Tags => _tags; public bool IsReadOnly => false; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataReadWriteFunction("tags", new List(), - value => - { - _tags.Clear(); - _tags.UnionWith(value); - }, - () => new List(_tags)); - } - public void SetTags(IEnumerable newTags) { _tags.Clear(); diff --git a/Content.Server/GameObjects/Components/Access/AccessReaderComponent.cs b/Content.Server/GameObjects/Components/Access/AccessReaderComponent.cs index 24fbb5e26c..7333ce0aba 100644 --- a/Content.Server/GameObjects/Components/Access/AccessReaderComponent.cs +++ b/Content.Server/GameObjects/Components/Access/AccessReaderComponent.cs @@ -13,7 +13,7 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Access @@ -28,14 +28,15 @@ namespace Content.Server.GameObjects.Components.Access { public override string Name => "AccessReader"; - private readonly List> _accessLists = new(); private readonly HashSet _denyTags = new(); /// /// List of access lists to check allowed against. For an access check to pass /// there has to be an access list that is a subset of the access in the checking list. /// - [ViewVariables] public IList> AccessLists => _accessLists; + [field: DataField("access")] + [ViewVariables] + public List> AccessLists { get; } = new(); /// /// The set of tags that will automatically deny an allowed check, if any of them are present. @@ -69,7 +70,7 @@ namespace Content.Server.GameObjects.Components.Access return false; } - return _accessLists.Count == 0 || _accessLists.Any(a => a.IsSubsetOf(accessTags)); + return AccessLists.Count == 0 || AccessLists.Any(a => a.IsSubsetOf(accessTags)); } public static ICollection FindAccessTags(IEntity entity) @@ -120,21 +121,5 @@ namespace Content.Server.GameObjects.Components.Access } } } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataReadWriteFunction("access", new List>(), - v => - { - if (v.Count != 0) - { - _accessLists.Clear(); - _accessLists.AddRange(v.Select(a => new HashSet(a))); - } - }, - () => _accessLists.Select(p => new List(p)).ToList()); - } } } diff --git a/Content.Server/GameObjects/Components/Access/IdCardComponent.cs b/Content.Server/GameObjects/Components/Access/IdCardComponent.cs index fca076ed8b..7a40a78631 100644 --- a/Content.Server/GameObjects/Components/Access/IdCardComponent.cs +++ b/Content.Server/GameObjects/Components/Access/IdCardComponent.cs @@ -1,6 +1,8 @@ using Robust.Shared.GameObjects; using Robust.Shared.Localization; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Access @@ -11,8 +13,10 @@ namespace Content.Server.GameObjects.Components.Access public override string Name => "IdCard"; /// See . + [DataField("originalOwnerName")] private string _ownerOriginalName; + [DataField("fullName")] private string _fullName; [ViewVariables(VVAccess.ReadWrite)] public string FullName @@ -25,6 +29,7 @@ namespace Content.Server.GameObjects.Components.Access } } + [DataField("jobTitle")] private string _jobTitle; [ViewVariables(VVAccess.ReadWrite)] public string JobTitle @@ -70,14 +75,5 @@ namespace Content.Server.GameObjects.Components.Access _ownerOriginalName ??= Owner.Name; UpdateEntityName(); } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _fullName, "fullName", string.Empty); - serializer.DataField(ref _jobTitle, "jobTitle", string.Empty); - serializer.DataField(ref _ownerOriginalName, "originalOwnerName", null); - } } } diff --git a/Content.Server/GameObjects/Components/Access/PresetIdCardComponent.cs b/Content.Server/GameObjects/Components/Access/PresetIdCardComponent.cs index d7b8016563..14ddfb36fd 100644 --- a/Content.Server/GameObjects/Components/Access/PresetIdCardComponent.cs +++ b/Content.Server/GameObjects/Components/Access/PresetIdCardComponent.cs @@ -5,6 +5,7 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Access { @@ -13,15 +14,9 @@ namespace Content.Server.GameObjects.Components.Access { public override string Name => "PresetIdCard"; + [DataField("job")] private string? _jobName; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _jobName, "job", null); - } - void IMapInit.MapInit() { if (_jobName == null) diff --git a/Content.Server/GameObjects/Components/ActionBlocking/HandcuffComponent.cs b/Content.Server/GameObjects/Components/ActionBlocking/HandcuffComponent.cs index af50391eaf..feb55e0df3 100644 --- a/Content.Server/GameObjects/Components/ActionBlocking/HandcuffComponent.cs +++ b/Content.Server/GameObjects/Components/ActionBlocking/HandcuffComponent.cs @@ -14,7 +14,7 @@ using Robust.Shared.GameObjects; using Robust.Shared.Localization; using Robust.Shared.Maths; using Robust.Shared.Players; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.ActionBlocking @@ -27,60 +27,70 @@ namespace Content.Server.GameObjects.Components.ActionBlocking /// The time it takes to apply a to an entity. /// [ViewVariables] - public float CuffTime { get; set; } + [DataField("cuffTime")] + public float CuffTime { get; set; } = 5f; /// /// The time it takes to remove a from an entity. /// [ViewVariables] - public float UncuffTime { get; set; } + [DataField("uncuffTime")] + public float UncuffTime { get; set; } = 5f; /// /// The time it takes for a cuffed entity to remove from itself. /// [ViewVariables] - public float BreakoutTime { get; set; } + [DataField("breakoutTime")] + public float BreakoutTime { get; set; } = 30f; /// /// If an entity being cuffed is stunned, this amount of time is subtracted from the time it takes to add/remove their cuffs. /// [ViewVariables] - public float StunBonus { get; set; } + [DataField("stunBonus")] + public float StunBonus { get; set; } = 2f; /// /// Will the cuffs break when removed? /// [ViewVariables] + [DataField("breakOnRemove")] public bool BreakOnRemove { get; set; } /// /// The path of the RSI file used for the player cuffed overlay. /// [ViewVariables] - public string? CuffedRSI { get; set; } + [DataField("cuffedRSI")] + public string? CuffedRSI { get; set; } = "Objects/Misc/handcuffs.rsi"; /// /// The iconstate used with the RSI file for the player cuffed overlay. /// [ViewVariables] - public string? OverlayIconState { get; set; } + [DataField("bodyIconState")] + public string? OverlayIconState { get; set; } = "body-overlay"; /// /// The iconstate used for broken handcuffs /// [ViewVariables] + [DataField("brokenIconState")] public string? BrokenState { get; set; } /// /// The iconstate used for broken handcuffs /// [ViewVariables] + [DataField("brokenName")] public string BrokenName { get; set; } = default!; /// /// The iconstate used for broken handcuffs /// [ViewVariables] + [DataField("brokenDesc")] public string BrokenDesc { get; set; } = default!; [ViewVariables] @@ -101,12 +111,21 @@ namespace Content.Server.GameObjects.Components.ActionBlocking } } - public string? StartCuffSound { get; set; } - public string? EndCuffSound { get; set; } - public string? StartBreakoutSound { get; set; } - public string? StartUncuffSound { get; set; } - public string? EndUncuffSound { get; set; } - public Color Color { get; set; } + [DataField("startCuffSound")] + public string StartCuffSound { get; set; } = "/Audio/Items/Handcuffs/cuff_start.ogg"; + + [DataField("endCuffSound")] public string EndCuffSound { get; set; } = "/Audio/Items/Handcuffs/cuff_end.ogg"; + + [DataField("startBreakoutSound")] + public string StartBreakoutSound { get; set; } = "/Audio/Items/Handcuffs/cuff_breakout_start.ogg"; + + [DataField("startUncuffSound")] + public string StartUncuffSound { get; set; } = "/Audio/Items/Handcuffs/cuff_takeoff_start.ogg"; + + [DataField("endUncuffSound")] + public string EndUncuffSound { get; set; } = "/Audio/Items/Handcuffs/cuff_takeoff_end.ogg"; + [DataField("color")] + public Color Color { get; set; } = Color.White; // Non-exposed data fields private bool _isBroken = false; @@ -116,27 +135,6 @@ namespace Content.Server.GameObjects.Components.ActionBlocking /// private bool _cuffing; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(this, x => x.CuffTime, "cuffTime", 5.0f); - serializer.DataField(this, x => x.BreakoutTime, "breakoutTime", 30.0f); - serializer.DataField(this, x => x.UncuffTime, "uncuffTime", 5.0f); - serializer.DataField(this, x => x.StunBonus, "stunBonus", 2.0f); - serializer.DataField(this, x => x.StartCuffSound, "startCuffSound", "/Audio/Items/Handcuffs/cuff_start.ogg"); - serializer.DataField(this, x => x.EndCuffSound, "endCuffSound", "/Audio/Items/Handcuffs/cuff_end.ogg"); - serializer.DataField(this, x => x.StartUncuffSound, "startUncuffSound", "/Audio/Items/Handcuffs/cuff_takeoff_start.ogg"); - serializer.DataField(this, x => x.EndUncuffSound, "endUncuffSound", "/Audio/Items/Handcuffs/cuff_takeoff_end.ogg"); - serializer.DataField(this, x => x.StartBreakoutSound, "startBreakoutSound", "/Audio/Items/Handcuffs/cuff_breakout_start.ogg"); - serializer.DataField(this, x => x.CuffedRSI, "cuffedRSI", "Objects/Misc/handcuffs.rsi"); - serializer.DataField(this, x => x.OverlayIconState, "bodyIconState", "body-overlay"); - serializer.DataField(this, x => x.Color, "color", Color.White); - serializer.DataField(this, x => x.BreakOnRemove, "breakOnRemove", false); - serializer.DataField(this, x => x.BrokenState, "brokenIconState", string.Empty); - serializer.DataField(this, x => x.BrokenName, "brokenName", string.Empty); - serializer.DataField(this, x => x.BrokenDesc, "brokenDesc", string.Empty); - } - public override ComponentState GetComponentState(ICommonSession player) { return new HandcuffedComponentState(Broken ? BrokenState : string.Empty); diff --git a/Content.Server/GameObjects/Components/AnchorableComponent.cs b/Content.Server/GameObjects/Components/AnchorableComponent.cs index d6ed4b447e..5054f8eada 100644 --- a/Content.Server/GameObjects/Components/AnchorableComponent.cs +++ b/Content.Server/GameObjects/Components/AnchorableComponent.cs @@ -7,7 +7,7 @@ using Content.Server.Utility; using Content.Shared.GameObjects.Components.Interactable; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components @@ -18,21 +18,16 @@ namespace Content.Server.GameObjects.Components public override string Name => "Anchorable"; [ViewVariables] + [DataField("tool")] public ToolQuality Tool { get; private set; } = ToolQuality.Anchoring; [ViewVariables] int IInteractUsing.Priority => 1; [ViewVariables(VVAccess.ReadWrite)] + [DataField("snap")] public bool Snap { get; private set; } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(this, x => x.Tool, "tool", ToolQuality.Anchoring); - serializer.DataField(this, x => x.Snap, "snap", false); - } - /// /// Checks if a tool can change the anchored status. /// diff --git a/Content.Server/GameObjects/Components/Arcade/SpaceVillainArcadeComponent.cs b/Content.Server/GameObjects/Components/Arcade/SpaceVillainArcadeComponent.cs index e5f646873c..e801fa1c64 100644 --- a/Content.Server/GameObjects/Components/Arcade/SpaceVillainArcadeComponent.cs +++ b/Content.Server/GameObjects/Components/Arcade/SpaceVillainArcadeComponent.cs @@ -13,8 +13,10 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Maths; +using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Arcade @@ -36,33 +38,23 @@ namespace Content.Server.GameObjects.Components.Arcade [ViewVariables] private bool _enemyInvincibilityFlag; [ViewVariables] private SpaceVillainGame _game = null!; - [ViewVariables(VVAccess.ReadWrite)] private List _possibleFightVerbs = null!; - [ViewVariables(VVAccess.ReadWrite)] private List _possibleFirstEnemyNames = null!; - [ViewVariables(VVAccess.ReadWrite)] private List _possibleLastEnemyNames = null!; - [ViewVariables(VVAccess.ReadWrite)] private List _possibleRewards = null!; - - public override void ExposeData(ObjectSerializer serializer) + [ViewVariables(VVAccess.ReadWrite)] [DataField("possibleFightVerbs")] private List _possibleFightVerbs = new List() + {"Defeat", "Annihilate", "Save", "Strike", "Stop", "Destroy", "Robust", "Romance", "Pwn", "Own"}; + [ViewVariables(VVAccess.ReadWrite)] [DataField("possibleFirstEnemyNames")] private List _possibleFirstEnemyNames = new List(){ + "the Automatic", "Farmer", "Lord", "Professor", "the Cuban", "the Evil", "the Dread King", + "the Space", "Lord", "the Great", "Duke", "General" + }; + [ViewVariables(VVAccess.ReadWrite)] [DataField("possibleLastEnemyNames")] private List _possibleLastEnemyNames = new List() { - serializer.DataField(ref _possibleFightVerbs, "possibleFightVerbs", new List() - {"Defeat", "Annihilate", "Save", "Strike", "Stop", "Destroy", "Robust", "Romance", "Pwn", "Own"}); - serializer.DataField(ref _possibleFirstEnemyNames, "possibleFirstEnemyNames", new List(){ - "the Automatic", "Farmer", "Lord", "Professor", "the Cuban", "the Evil", "the Dread King", - "the Space", "Lord", "the Great", "Duke", "General" - }); - serializer.DataField(ref _possibleLastEnemyNames, "possibleLastEnemyNames", new List() - { - "Melonoid", "Murdertron", "Sorcerer", "Ruin", "Jeff", "Ectoplasm", "Crushulon", "Uhangoid", - "Vhakoid", "Peteoid", "slime", "Griefer", "ERPer", "Lizard Man", "Unicorn" - }); - serializer.DataField(ref _possibleRewards, "possibleRewards", new List() - { - "ToyMouse", "ToyAi", "ToyNuke", "ToyAssistant", "ToyGriffin", "ToyHonk", "ToyIan", - "ToyMarauder", "ToyMauler", "ToyGygax", "ToyOdysseus", "ToyOwlman", "ToyDeathRipley", - "ToyPhazon", "ToyFireRipley", "ToyReticence", "ToyRipley", "ToySeraph", "ToyDurand", "ToySkeleton" - }); - - _game = new SpaceVillainGame(this); - } + "Melonoid", "Murdertron", "Sorcerer", "Ruin", "Jeff", "Ectoplasm", "Crushulon", "Uhangoid", + "Vhakoid", "Peteoid", "slime", "Griefer", "ERPer", "Lizard Man", "Unicorn" + }; + [ViewVariables(VVAccess.ReadWrite)] [DataField("possibleRewards")] private List _possibleRewards = new List() + { + "ToyMouse", "ToyAi", "ToyNuke", "ToyAssistant", "ToyGriffin", "ToyHonk", "ToyIan", + "ToyMarauder", "ToyMauler", "ToyGygax", "ToyOdysseus", "ToyOwlman", "ToyDeathRipley", + "ToyPhazon", "ToyFireRipley", "ToyReticence", "ToyRipley", "ToySeraph", "ToyDurand", "ToySkeleton" + }; void IActivate.Activate(ActivateEventArgs eventArgs) { @@ -76,6 +68,8 @@ namespace Content.Server.GameObjects.Components.Arcade } if(!ActionBlockerSystem.CanInteract(actor.playerSession.AttachedEntity)) return; + _game ??= new SpaceVillainGame(this); + if (_wiresComponent?.IsPanelOpen == true) { _wiresComponent.OpenInterface(actor.playerSession); diff --git a/Content.Server/GameObjects/Components/Atmos/AirtightComponent.cs b/Content.Server/GameObjects/Components/Atmos/AirtightComponent.cs index 1974e7a21f..649212903b 100644 --- a/Content.Server/GameObjects/Components/Atmos/AirtightComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/AirtightComponent.cs @@ -5,7 +5,7 @@ using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Map; using Robust.Shared.Maths; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Atmos @@ -18,17 +18,25 @@ namespace Content.Server.GameObjects.Components.Atmos public override string Name => "Airtight"; + [DataFieldWithFlag("airBlockedDirection", typeof(AtmosDirectionFlags))] [ViewVariables] - private int _initialAirBlockedDirection; - [ViewVariables] - private int _currentAirBlockedDirection; - private bool _airBlocked = true; - private bool _fixVacuum; + private int _initialAirBlockedDirection = (int) AtmosDirection.All; [ViewVariables] + private int _currentAirBlockedDirection; + + [DataField("airBlocked")] + private bool _airBlocked = true; + + [DataField("fixVacuum")] + private bool _fixVacuum = true; + + [ViewVariables] + [DataField("rotateAirBlocked")] private bool _rotateAirBlocked = true; [ViewVariables] + [DataField("fixAirBlockedDirectionInitialize")] private bool _fixAirBlockedDirectionInitialize = true; [ViewVariables(VVAccess.ReadWrite)] @@ -58,17 +66,6 @@ namespace Content.Server.GameObjects.Components.Atmos [ViewVariables] public bool FixVacuum => _fixVacuum; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _airBlocked, "airBlocked", true); - serializer.DataField(ref _fixVacuum, "fixVacuum", true); - serializer.DataField(ref _initialAirBlockedDirection, "airBlockedDirection", (int)AtmosDirection.All, WithFormat.Flags()); - serializer.DataField(ref _rotateAirBlocked, "rotateAirBlocked", true); - serializer.DataField(ref _fixAirBlockedDirectionInitialize, "fixAirBlockedDirectionInitialize", true); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Atmos/BreathToolComponent.cs b/Content.Server/GameObjects/Components/Atmos/BreathToolComponent.cs index 5d8b269030..7a4d365b4a 100644 --- a/Content.Server/GameObjects/Components/Atmos/BreathToolComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/BreathToolComponent.cs @@ -3,7 +3,7 @@ using Content.Server.GameObjects.Components.Body.Respiratory; using Content.Shared.GameObjects.Components.Inventory; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Atmos { @@ -16,18 +16,13 @@ namespace Content.Server.GameObjects.Components.Atmos /// /// Tool is functional only in allowed slots /// - private EquipmentSlotDefines.SlotFlags _allowedSlots; + [DataField("allowedSlots")] + private EquipmentSlotDefines.SlotFlags _allowedSlots = EquipmentSlotDefines.SlotFlags.MASK; public override string Name => "BreathMask"; public bool IsFunctional { get; private set; } public IEntity? ConnectedInternalsEntity { get; private set; } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _allowedSlots, "allowedSlots", EquipmentSlotDefines.SlotFlags.MASK); - } - protected override void Shutdown() { base.Shutdown(); diff --git a/Content.Server/GameObjects/Components/Atmos/FlammableComponent.cs b/Content.Server/GameObjects/Components/Atmos/FlammableComponent.cs index 26777a5488..e278595d33 100644 --- a/Content.Server/GameObjects/Components/Atmos/FlammableComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/FlammableComponent.cs @@ -15,7 +15,7 @@ using Content.Shared.Interfaces.GameObjects.Components; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Localization; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Atmos @@ -33,18 +33,13 @@ namespace Content.Server.GameObjects.Components.Atmos public float FireStacks { get; private set; } [ViewVariables(VVAccess.ReadWrite)] + [DataField("fireSpread")] public bool FireSpread { get; private set; } = false; [ViewVariables(VVAccess.ReadWrite)] + [DataField("canResistFire")] public bool CanResistFire { get; private set; } = false; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(this, x => x.FireSpread, "fireSpread", false); - serializer.DataField(this, x => x.CanResistFire, "canResistFire", false); - } - public void Ignite() { if (FireStacks > 0 && !OnFire) diff --git a/Content.Server/GameObjects/Components/Atmos/GasCanisterComponent.cs b/Content.Server/GameObjects/Components/Atmos/GasCanisterComponent.cs index 9c1d0f329b..682c9ab26b 100644 --- a/Content.Server/GameObjects/Components/Atmos/GasCanisterComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/GasCanisterComponent.cs @@ -1,18 +1,18 @@ #nullable enable using System; +using System.Linq; using Content.Server.Atmos; using Content.Server.GameObjects.Components.Atmos.Piping; using Content.Server.Interfaces; -using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; -using Robust.Shared.ViewVariables; -using System.Linq; using Content.Server.Utility; -using Content.Shared.GameObjects.Components.Atmos; -using Content.Shared.Interfaces.GameObjects.Components; using Content.Shared.Atmos; +using Content.Shared.GameObjects.Components.Atmos; using Content.Shared.GameObjects.EntitySystems.ActionBlocker; +using Content.Shared.Interfaces.GameObjects.Components; using Robust.Server.GameObjects; +using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Atmos { @@ -37,7 +37,8 @@ namespace Content.Server.GameObjects.Components.Atmos /// What the canister contains. /// [ViewVariables(VVAccess.ReadWrite)] - public GasMixture Air { get; set; } = default!; + [DataField("gasMixture")] + public GasMixture Air { get; set; } = new (DefaultVolume); [ViewVariables] public bool Anchored => !Owner.TryGetComponent(out var physics) || physics.Anchored; @@ -51,7 +52,7 @@ namespace Content.Server.GameObjects.Components.Atmos [ViewVariables] public bool ConnectedToPort => ConnectedPort != null; - private const float DefaultVolume = 10; + public const float DefaultVolume = 10; [ViewVariables(VVAccess.ReadWrite)] public float ReleasePressure { get; set; } @@ -67,13 +68,6 @@ namespace Content.Server.GameObjects.Components.Atmos private AppearanceComponent? _appearance; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(this, x => Air, "gasMixture", new GasMixture(DefaultVolume)); - } - - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Atmos/GasMixtureHolderComponent.cs b/Content.Server/GameObjects/Components/Atmos/GasMixtureHolderComponent.cs index 3ef464f36c..48c01afe58 100644 --- a/Content.Server/GameObjects/Components/Atmos/GasMixtureHolderComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/GasMixtureHolderComponent.cs @@ -1,7 +1,9 @@ using Content.Server.Atmos; using Content.Server.Interfaces; using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Atmos @@ -11,15 +13,6 @@ namespace Content.Server.GameObjects.Components.Atmos { public override string Name => "GasMixtureHolder"; - [ViewVariables] public GasMixture Air { get; set; } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - Air = new GasMixture(); - - serializer.DataField(this, x => x.Air, "air", new GasMixture()); - } + [ViewVariables] [DataField("air")] public GasMixture Air { get; set; } = new GasMixture(); } } diff --git a/Content.Server/GameObjects/Components/Atmos/GasTankComponent.cs b/Content.Server/GameObjects/Components/Atmos/GasTankComponent.cs index 22cbe0db73..9533c00a90 100644 --- a/Content.Server/GameObjects/Components/Atmos/GasTankComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/GasTankComponent.cs @@ -20,7 +20,7 @@ using Robust.Server.Player; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Localization; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -33,7 +33,8 @@ namespace Content.Server.GameObjects.Components.Atmos private const float MaxExplosionRange = 14f; private const float DefaultOutputPressure = Atmospherics.OneAtmosphere; - private float _pressureResistance; + [DataField("pressureResistance")] + private float _pressureResistance = Atmospherics.OneAtmosphere * 5f; private int _integrity = 3; @@ -41,12 +42,14 @@ namespace Content.Server.GameObjects.Components.Atmos [ViewVariables] private BoundUserInterface? _userInterface; - [ViewVariables] public GasMixture? Air { get; set; } + [DataField("air")] [ViewVariables] public GasMixture? Air { get; set; } = new(); /// /// Distributed pressure. /// - [ViewVariables] public float OutputPressure { get; private set; } + [DataField("outputPressure")] + [ViewVariables] + public float OutputPressure { get; private set; } = DefaultOutputPressure; /// /// Tank is connected to internals. @@ -61,21 +64,25 @@ namespace Content.Server.GameObjects.Components.Atmos /// /// Pressure at which tanks start leaking. /// + [DataField("tankLeakPressure")] public float TankLeakPressure { get; set; } = 30 * Atmospherics.OneAtmosphere; /// /// Pressure at which tank spills all contents into atmosphere. /// + [DataField("tankRupturePressure")] public float TankRupturePressure { get; set; } = 40 * Atmospherics.OneAtmosphere; /// /// Base 3x3 explosion. /// + [DataField("tankFragmentPressure")] public float TankFragmentPressure { get; set; } = 50 * Atmospherics.OneAtmosphere; /// /// Increases explosion for each scale kPa above threshold. /// + [DataField("tankFragmentScale")] public float TankFragmentScale { get; set; } = 10 * Atmospherics.OneAtmosphere; public override void Initialize() @@ -94,19 +101,6 @@ namespace Content.Server.GameObjects.Components.Atmos UpdateUserInterface(true); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, x => x.Air, "air", new GasMixture()); - serializer.DataField(this, x => x.OutputPressure, "outputPressure", DefaultOutputPressure); - serializer.DataField(this, x => x.TankLeakPressure, "tankLeakPressure", 30 * Atmospherics.OneAtmosphere); - serializer.DataField(this, x => x.TankRupturePressure, "tankRupturePressure", 40 * Atmospherics.OneAtmosphere); - serializer.DataField(this, x => x.TankFragmentPressure, "tankFragmentPressure", 50 * Atmospherics.OneAtmosphere); - serializer.DataField(this, x => x.TankFragmentScale, "tankFragmentScale", 10 * Atmospherics.OneAtmosphere); - serializer.DataField(ref _pressureResistance, "pressureResistance", Atmospherics.OneAtmosphere * 5f); - } - public void Examine(FormattedMessage message, bool inDetailsRange) { message.AddMarkup(Loc.GetString("gas-tank-examine", ("pressure", Math.Round(Air?.Pressure ?? 0)))); @@ -355,10 +349,9 @@ namespace Content.Server.GameObjects.Components.Atmos } [UsedImplicitly] + [DataDefinition] public class ToggleInternalsAction : IToggleItemAction { - void IExposeData.ExposeData(ObjectSerializer serializer) {} - public bool DoToggleAction(ToggleItemActionEventArgs args) { if (!args.Item.TryGetComponent(out var gasTankComponent)) return false; diff --git a/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs b/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs index da167ff466..0d9f4b57c3 100644 --- a/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs @@ -1,4 +1,5 @@ #nullable enable +// ReSharper disable once RedundantUsingDirective using System; using System.Collections; using System.Collections.Generic; @@ -13,12 +14,15 @@ using Content.Shared.Atmos; using Content.Shared.Maps; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Timing; using Robust.Shared.ViewVariables; +using Dependency = Robust.Shared.IoC.DependencyAttribute; namespace Content.Server.GameObjects.Components.Atmos { @@ -27,11 +31,11 @@ namespace Content.Server.GameObjects.Components.Atmos /// [ComponentReference(typeof(IGridAtmosphereComponent))] [RegisterComponent, Serializable] - public class GridAtmosphereComponent : Component, IGridAtmosphereComponent + public class GridAtmosphereComponent : Component, IGridAtmosphereComponent, ISerializationHooks { - [Robust.Shared.IoC.Dependency] private IMapManager _mapManager = default!; - [Robust.Shared.IoC.Dependency] private ITileDefinitionManager _tileDefinitionManager = default!; - [Robust.Shared.IoC.Dependency] private IServerEntityManager _serverEntityManager = default!; + [Dependency] private IMapManager _mapManager = default!; + [Dependency] private ITileDefinitionManager _tileDefinitionManager = default!; + [Dependency] private IServerEntityManager _serverEntityManager = default!; public GridTileLookupSystem GridTileLookupSystem { get; private set; } = default!; internal GasTileOverlaySystem GasTileOverlaySystem { get; private set; } = default!; @@ -44,12 +48,12 @@ namespace Content.Server.GameObjects.Components.Atmos public override string Name => "GridAtmosphere"; - private bool _paused = false; - private float _timer = 0f; + private bool _paused; + private float _timer; private Stopwatch _stopwatch = new(); private GridId _gridId; - [ComponentDependency] private IMapGridComponent? _mapGridComponent = default!; + [ComponentDependency] private IMapGridComponent? _mapGridComponent; [ViewVariables] public int UpdateCounter { get; private set; } = 0; @@ -66,6 +70,12 @@ namespace Content.Server.GameObjects.Components.Atmos [ViewVariables] private double _excitedGroupLastProcess; + [DataField("uniqueMixes")] + private List? _uniqueMixes; + + [DataField("tiles")] + private Dictionary? _tiles; + [ViewVariables] protected readonly Dictionary Tiles = new(1000); @@ -138,6 +148,11 @@ namespace Content.Server.GameObjects.Components.Atmos [ViewVariables] private ProcessState _state = ProcessState.TileEqualize; + public GridAtmosphereComponent() + { + _paused = false; + } + private enum ProcessState { TileEqualize, @@ -158,9 +173,59 @@ namespace Content.Server.GameObjects.Components.Atmos indices.PryTile(_gridId, _mapManager, _tileDefinitionManager, _serverEntityManager); } + void ISerializationHooks.BeforeSerialization() + { + var uniqueMixes = new List(); + var uniqueMixHash = new Dictionary(); + var tiles = new Dictionary(); + + foreach (var (indices, tile) in Tiles) + { + if (tile.Air == null) continue; + + if (uniqueMixHash.TryGetValue(tile.Air, out var index)) + { + tiles[indices] = index; + continue; + } + + uniqueMixes.Add(tile.Air); + var newIndex = uniqueMixes.Count - 1; + uniqueMixHash[tile.Air] = newIndex; + tiles[indices] = newIndex; + } + + if (uniqueMixes.Count == 0) uniqueMixes = null; + if (tiles.Count == 0) tiles = null; + + _uniqueMixes = uniqueMixes; + _tiles = tiles; + } + public override void Initialize() { base.Initialize(); + + Tiles.Clear(); + + if (_tiles != null && Owner.TryGetComponent(out IMapGridComponent? mapGrid)) + { + foreach (var (indices, mix) in _tiles) + { + try + { + Tiles.Add(indices, new TileAtmosphere(this, mapGrid.GridIndex, indices, (GasMixture) _uniqueMixes![mix].Clone())); + } + catch (ArgumentOutOfRangeException) + { + Logger.Error($"Error during atmos serialization! Tile at {indices} points to an unique mix ({mix}) out of range!"); + throw; + } + + Invalidate(indices); + } + } + GridTileLookupSystem = EntitySystem.Get(); GasTileOverlaySystem = EntitySystem.Get(); AtmosphereSystem = EntitySystem.Get(); @@ -840,60 +905,6 @@ namespace Content.Server.GameObjects.Components.Atmos } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - if (serializer.Reading && Owner.TryGetComponent(out IMapGridComponent? mapGrid)) - { - var gridId = mapGrid.Grid.Index; - - if (!serializer.TryReadDataField("uniqueMixes", out List? uniqueMixes) || - !serializer.TryReadDataField("tiles", out Dictionary? tiles)) - return; - - Tiles.Clear(); - - foreach (var (indices, mix) in tiles!) - { - try - { - Tiles.Add(indices, new TileAtmosphere(this, gridId, indices, (GasMixture)uniqueMixes![mix].Clone())); - } - catch (ArgumentOutOfRangeException) - { - Logger.Error($"Error during atmos serialization! Tile at {indices} points to an unique mix ({mix}) out of range!"); - throw; - } - - Invalidate(indices); - } - } - else if (serializer.Writing) - { - var uniqueMixes = new List(); - var uniqueMixHash = new Dictionary(); - var tiles = new Dictionary(); - foreach (var (indices, tile) in Tiles) - { - if (tile.Air == null) continue; - - if (uniqueMixHash.TryGetValue(tile.Air, out var index)) - { - tiles[indices] = index; - continue; - } - - uniqueMixes.Add(tile.Air); - var newIndex = uniqueMixes.Count - 1; - uniqueMixHash[tile.Air] = newIndex; - tiles[indices] = newIndex; - } - - serializer.DataField(ref uniqueMixes, "uniqueMixes", new List()); - serializer.DataField(ref tiles, "tiles", new Dictionary()); - } - } - public IEnumerator GetEnumerator() { return Tiles.Values.GetEnumerator(); @@ -910,4 +921,16 @@ namespace Content.Server.GameObjects.Components.Atmos // TODO ATMOS } } + + public struct IntermediateTileAtmosphere + { + public readonly Vector2i Indices; + public readonly GasMixture GasMixture; + + public IntermediateTileAtmosphere(Vector2i indices, GasMixture gasMixture) + { + Indices = indices; + GasMixture = gasMixture; + } + } } diff --git a/Content.Server/GameObjects/Components/Atmos/MovedByPressureComponent.cs b/Content.Server/GameObjects/Components/Atmos/MovedByPressureComponent.cs index 36a5bae151..fd172bd489 100644 --- a/Content.Server/GameObjects/Components/Atmos/MovedByPressureComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/MovedByPressureComponent.cs @@ -1,7 +1,7 @@ #nullable enable using System.Diagnostics.CodeAnalysis; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Atmos @@ -12,21 +12,16 @@ namespace Content.Server.GameObjects.Components.Atmos public override string Name => "MovedByPressure"; [ViewVariables(VVAccess.ReadWrite)] + [DataField("enabled")] public bool Enabled { get; set; } = true; [ViewVariables(VVAccess.ReadWrite)] + [DataField("pressureResistance")] public float PressureResistance { get; set; } = 1f; [ViewVariables(VVAccess.ReadWrite)] + [DataField("moveResist")] public float MoveResist { get; set; } = 100f; [ViewVariables(VVAccess.ReadWrite)] public int LastHighPressureMovementAirCycle { get; set; } = 0; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(this, x => x.Enabled, "enabled", true); - serializer.DataField(this, x => PressureResistance, "pressureResistance", 1f); - serializer.DataField(this, x => MoveResist, "moveResist", 100f); - } } public static class MovedByPressureExtensions diff --git a/Content.Server/GameObjects/Components/Atmos/Piping/GasFilterComponent.cs b/Content.Server/GameObjects/Components/Atmos/Piping/GasFilterComponent.cs index d120fe4d29..37d815736e 100644 --- a/Content.Server/GameObjects/Components/Atmos/Piping/GasFilterComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/Piping/GasFilterComponent.cs @@ -1,4 +1,6 @@ #nullable enable +using System; +using System.Linq; using Content.Server.Atmos; using Content.Server.GameObjects.Components.NodeContainer; using Content.Server.GameObjects.Components.NodeContainer.Nodes; @@ -7,12 +9,10 @@ using Content.Shared.GameObjects.Components.Atmos; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Log; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; -using System; -using System.Linq; -namespace Content.Server.GameObjects.Components.Atmos.Piping.Filters +namespace Content.Server.GameObjects.Components.Atmos.Piping { [RegisterComponent] public class GasFilterComponent : Component @@ -44,7 +44,8 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Filters UpdateAppearance(); } } - private Gas _gasToFilter; + + [DataField("gasToFilter")] private Gas _gasToFilter = Gas.Plasma; [ViewVariables(VVAccess.ReadWrite)] public int VolumeFilterRate @@ -52,6 +53,8 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Filters get => _volumeFilterRate; set => _volumeFilterRate = Math.Clamp(value, 0, MaxVolumeFilterRate); } + + [DataField("startingVolumePumpRate")] private int _volumeFilterRate; [ViewVariables(VVAccess.ReadWrite)] @@ -60,22 +63,23 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Filters get => _maxVolumeFilterRate; set => Math.Max(value, 0); } - private int _maxVolumeFilterRate; - [ViewVariables] - private PipeDirection _initialInletDirection; + [DataField("maxVolumePumpRate")] private int _maxVolumeFilterRate = 100; + + [DataField("inletDirection")] [ViewVariables] + private PipeDirection _initialInletDirection = PipeDirection.None; /// /// The direction the filtered-out gas goes. /// - [ViewVariables] - private PipeDirection _initialFilterOutletDirection; + [DataField("filterOutletDirection")] [ViewVariables] + private PipeDirection _initialFilterOutletDirection = PipeDirection.None; /// /// The direction the rest of the gas goes. /// - [ViewVariables] - private PipeDirection _initialOutletDirection; + [DataField("outletDirection")] [ViewVariables] + private PipeDirection _initialOutletDirection = PipeDirection.None; [ViewVariables] private PipeNode? _inletPipe; @@ -89,17 +93,6 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Filters [ComponentDependency] private readonly AppearanceComponent? _appearance = default; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _volumeFilterRate, "startingVolumePumpRate", 0); - serializer.DataField(ref _maxVolumeFilterRate, "maxVolumePumpRate", 100); - serializer.DataField(ref _gasToFilter, "gasToFilter", Gas.Plasma); - serializer.DataField(ref _initialInletDirection, "inletDirection", PipeDirection.None); - serializer.DataField(ref _initialFilterOutletDirection, "filterOutletDirection", PipeDirection.None); - serializer.DataField(ref _initialOutletDirection, "outletDirection", PipeDirection.None); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Atmos/Piping/GasGeneratorComponent.cs b/Content.Server/GameObjects/Components/Atmos/Piping/GasGeneratorComponent.cs index d4362bbb2a..c8d9de799f 100644 --- a/Content.Server/GameObjects/Components/Atmos/Piping/GasGeneratorComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/Piping/GasGeneratorComponent.cs @@ -1,12 +1,12 @@ #nullable enable +using System.Linq; using Content.Server.GameObjects.Components.NodeContainer; using Content.Server.GameObjects.Components.NodeContainer.Nodes; using Content.Shared.Atmos; using Robust.Shared.GameObjects; using Robust.Shared.Log; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; -using System.Linq; namespace Content.Server.GameObjects.Components.Atmos.Piping { @@ -21,26 +21,30 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping /// /// If the generator is producing gas. /// + [DataField("generatorEnabled")] [ViewVariables(VVAccess.ReadWrite)] - public bool GeneratorEnabled { get; set; } + public bool GeneratorEnabled { get; set; } = true; /// /// What gas is being generated. /// + [DataField("generatedGas")] [ViewVariables(VVAccess.ReadWrite)] - public Gas GeneratedGas { get; set; } + public Gas GeneratedGas { get; set; } = Gas.Oxygen; /// /// Molar rate of gas generation. /// + [DataField("gasGenerationRate")] [ViewVariables(VVAccess.ReadWrite)] - public float GasGenerationRate { get; set; } + public float GasGenerationRate { get; set; } = 10; /// /// The pipe pressure above which the generator stops producing gas. /// + [DataField("generatorPressureCap")] [ViewVariables(VVAccess.ReadWrite)] - public float GeneratorPressureCap { get; set; } + public float GeneratorPressureCap { get; set; } = 10; /// /// The pipe to which generated gas is added. @@ -48,15 +52,6 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping [ViewVariables] private PipeNode? Pipe { get; set; } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(this, x => x.GeneratorEnabled, "generatorEnabled", true); - serializer.DataField(this, x => x.GeneratedGas, "generatedGas", Gas.Oxygen); - serializer.DataField(this, x => x.GasGenerationRate, "gasGenerationRate", 10); - serializer.DataField(this, x => x.GeneratorPressureCap, "generatorPressureCap", 10); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Atmos/Piping/Pumps/BasePumpComponent.cs b/Content.Server/GameObjects/Components/Atmos/Piping/Pumps/BasePumpComponent.cs index 672743c018..7b9e5a3258 100644 --- a/Content.Server/GameObjects/Components/Atmos/Piping/Pumps/BasePumpComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/Piping/Pumps/BasePumpComponent.cs @@ -8,7 +8,9 @@ using Content.Shared.Interfaces.GameObjects.Components; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Log; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Atmos.Piping.Pumps @@ -31,19 +33,23 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Pumps UpdateAppearance(); } } + + [DataField("pumpEnabled")] private bool _pumpEnabled; /// /// Needs to be same as that of a on this entity. /// [ViewVariables] - private PipeDirection _initialInletDirection; + [DataField("initialInletDirection")] + private PipeDirection _initialInletDirection = PipeDirection.None; /// /// Needs to be same as that of a on this entity. /// [ViewVariables] - private PipeDirection _initialOutletDirection; + [DataField("initialOutletDirection")] + private PipeDirection _initialOutletDirection = PipeDirection.None; [ViewVariables] private PipeNode? _inletPipe; @@ -53,14 +59,6 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Pumps private AppearanceComponent? _appearance; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _initialInletDirection, "inletDirection", PipeDirection.None); - serializer.DataField(ref _initialOutletDirection, "outletDirection", PipeDirection.None); - serializer.DataField(ref _pumpEnabled, "pumpEnabled", false); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Atmos/Piping/Pumps/PressurePumpComponent.cs b/Content.Server/GameObjects/Components/Atmos/Piping/Pumps/PressurePumpComponent.cs index 4135ef4389..011e53da51 100644 --- a/Content.Server/GameObjects/Components/Atmos/Piping/Pumps/PressurePumpComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/Piping/Pumps/PressurePumpComponent.cs @@ -3,7 +3,9 @@ using System; using Content.Server.Atmos; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Atmos.Piping.Pumps @@ -24,6 +26,8 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Pumps get => _pressurePumpTarget; set => _pressurePumpTarget = Math.Clamp(value, 0, MaxPressurePumpTarget); } + + [DataField("startingPressurePumpTarget")] private int _pressurePumpTarget; /// @@ -35,7 +39,8 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Pumps get => _maxPressurePumpTarget; set => Math.Max(value, 0); } - private int _maxPressurePumpTarget; + [DataField("maxPressurePumpTarget")] + private int _maxPressurePumpTarget = 100; /// /// Every update, this pump will only increase the outlet pressure by this fraction of the amount needed to reach the . @@ -46,15 +51,8 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Pumps get => _transferRatio; set => _transferRatio = Math.Clamp(value, 0, 1); } - private float _transferRatio; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _pressurePumpTarget, "startingPressurePumpTarget", 0); - serializer.DataField(ref _maxPressurePumpTarget, "maxPressurePumpTarget", 100); - serializer.DataField(ref _transferRatio, "transferRatio", 0.5f); - } + [DataField("transferRatio")] + private float _transferRatio = 0.5f; protected override void PumpGas(GasMixture inletGas, GasMixture outletGas) { diff --git a/Content.Server/GameObjects/Components/Atmos/Piping/Pumps/VolumePumpComponent.cs b/Content.Server/GameObjects/Components/Atmos/Piping/Pumps/VolumePumpComponent.cs index 51824e1738..e58472df79 100644 --- a/Content.Server/GameObjects/Components/Atmos/Piping/Pumps/VolumePumpComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/Piping/Pumps/VolumePumpComponent.cs @@ -3,7 +3,9 @@ using System; using Content.Server.Atmos; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Atmos.Piping.Pumps @@ -19,6 +21,7 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Pumps get => _volumePumpRate; set => _volumePumpRate = Math.Clamp(value, 0, MaxVolumePumpRate); } + [DataField("startingVolumePumpRate")] private int _volumePumpRate; [ViewVariables(VVAccess.ReadWrite)] @@ -27,17 +30,11 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Pumps get => _maxVolumePumpRate; set => Math.Max(value, 0); } - private int _maxVolumePumpRate; + [DataField("maxVolumePumpRate")] + private int _maxVolumePumpRate = 100; public override string Name => "VolumePump"; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _volumePumpRate, "startingVolumePumpRate", 0); - serializer.DataField(ref _maxVolumePumpRate, "maxVolumePumpRate", 100); - } - protected override void PumpGas(GasMixture inletGas, GasMixture outletGas) { var volumeRatio = Math.Clamp(VolumePumpRate / inletGas.Volume, 0, 1); diff --git a/Content.Server/GameObjects/Components/Atmos/Piping/Scrubbers/PressureSiphon.cs b/Content.Server/GameObjects/Components/Atmos/Piping/Scrubbers/PressureSiphon.cs index dd66336038..37f96e4a4e 100644 --- a/Content.Server/GameObjects/Components/Atmos/Piping/Scrubbers/PressureSiphon.cs +++ b/Content.Server/GameObjects/Components/Atmos/Piping/Scrubbers/PressureSiphon.cs @@ -3,7 +3,9 @@ using System; using Content.Server.Atmos; using Content.Shared.Atmos; using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Atmos.Piping.Scrubbers @@ -23,7 +25,8 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Scrubbers get => _siphonPressureTarget; set => _siphonPressureTarget = Math.Max(value, 0); } - private float _siphonPressureTarget; + [DataField("startingSiphonPressureTarget")] + private float _siphonPressureTarget = Atmospherics.OneAtmosphere * 2; /// /// Every update, this siphon will only decrease the inlet pressure by this fraction of the amount needed to reach the . @@ -34,14 +37,8 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Scrubbers get => _transferRatio; set => _transferRatio = Math.Clamp(value, 0, 1); } - private float _transferRatio; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _siphonPressureTarget, "startingSiphonPressureTarget", Atmospherics.OneAtmosphere * 2); - serializer.DataField(ref _transferRatio, "transferRatio", 0.5f); - } + [DataField("transferRatio")] + private float _transferRatio = 0.5f; protected override void ScrubGas(GasMixture inletGas, GasMixture outletGas) { diff --git a/Content.Server/GameObjects/Components/Atmos/Piping/Vents/PressureVentComponent.cs b/Content.Server/GameObjects/Components/Atmos/Piping/Vents/PressureVentComponent.cs index e84c67ec9f..f58c674d06 100644 --- a/Content.Server/GameObjects/Components/Atmos/Piping/Vents/PressureVentComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/Piping/Vents/PressureVentComponent.cs @@ -5,6 +5,8 @@ using Robust.Shared.GameObjects; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; using System; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Atmos.Piping.Vents { @@ -23,7 +25,8 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Vents get => _ventPressureTarget; set => _ventPressureTarget = Math.Clamp(value, 0, MaxVentPressureTarget); } - private float _ventPressureTarget; + [DataField("startingVentPressureTarget")] + private float _ventPressureTarget = Atmospherics.OneAtmosphere; /// /// Max value can be set to. @@ -34,7 +37,8 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Vents get => _maxVentPressureTarget; set => Math.Max(value, 0); } - private float _maxVentPressureTarget; + [DataField("maxVentPressureTarget")] + private float _maxVentPressureTarget = Atmospherics.OneAtmosphere * 2; /// /// Every update, this vent will only increase the outlet pressure by this fraction of the amount needed to reach the . @@ -45,15 +49,8 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Vents get => _transferRatio; set => _transferRatio = Math.Clamp(value, 0, 1); } - private float _transferRatio; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _ventPressureTarget, "startingVentPressureTarget", Atmospherics.OneAtmosphere); - serializer.DataField(ref _maxVentPressureTarget, "maxVentPressureTarget", Atmospherics.OneAtmosphere * 2); - serializer.DataField(ref _transferRatio, "transferRatio", 0.5f); - } + [DataField("transferRatio")] + private float _transferRatio = 0.5f; protected override void VentGas(GasMixture inletGas, GasMixture outletGas) { diff --git a/Content.Server/GameObjects/Components/Atmos/PressureProtectionComponent.cs b/Content.Server/GameObjects/Components/Atmos/PressureProtectionComponent.cs index 054617b4b2..e8de0df2f7 100644 --- a/Content.Server/GameObjects/Components/Atmos/PressureProtectionComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/PressureProtectionComponent.cs @@ -1,6 +1,8 @@ using Content.Server.Interfaces.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Atmos @@ -11,17 +13,11 @@ namespace Content.Server.GameObjects.Components.Atmos public override string Name => "PressureProtection"; [ViewVariables] - public float HighPressureMultiplier { get; private set; } + [DataField("highPressureMultiplier")] + public float HighPressureMultiplier { get; private set; } = 1f; [ViewVariables] - public float LowPressureMultiplier { get; private set; } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, x => x.HighPressureMultiplier, "highPressureMultiplier", 1f); - serializer.DataField(this, x => x.LowPressureMultiplier, "lowPressureMultiplier", 1f); - } + [DataField("lowPressureMultiplier")] + public float LowPressureMultiplier { get; private set; } = 1f; } } diff --git a/Content.Server/GameObjects/Components/AtmosPlaqueComponent.cs b/Content.Server/GameObjects/Components/AtmosPlaqueComponent.cs index 2d5c1545a5..ad4c3513b3 100644 --- a/Content.Server/GameObjects/Components/AtmosPlaqueComponent.cs +++ b/Content.Server/GameObjects/Components/AtmosPlaqueComponent.cs @@ -2,7 +2,9 @@ using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Random; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components @@ -10,7 +12,8 @@ namespace Content.Server.GameObjects.Components [RegisterComponent] public sealed class AtmosPlaqueComponent : Component, IMapInit { - private PlaqueType _type; + [DataField("plaqueType")] + private PlaqueType _type = PlaqueType.Unset; public override string Name => "AtmosPlaque"; [ViewVariables(VVAccess.ReadWrite)] @@ -89,13 +92,6 @@ namespace Content.Server.GameObjects.Components } } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _type, "plaqueType", PlaqueType.Unset); - } - public enum PlaqueType { Unset = 0, diff --git a/Content.Server/GameObjects/Components/BarSign/BarSignComponent.cs b/Content.Server/GameObjects/Components/BarSign/BarSignComponent.cs index cbf0df733e..74fd6db350 100644 --- a/Content.Server/GameObjects/Components/BarSign/BarSignComponent.cs +++ b/Content.Server/GameObjects/Components/BarSign/BarSignComponent.cs @@ -9,6 +9,7 @@ using Robust.Shared.Log; using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.BarSign @@ -21,6 +22,7 @@ namespace Content.Server.GameObjects.Components.BarSign [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IRobustRandom _robustRandom = default!; + [DataField("current")] private string? _currentSign; [ViewVariables(VVAccess.ReadWrite)] @@ -98,13 +100,6 @@ namespace Content.Server.GameObjects.Components.BarSign UpdateSignInfo(); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _currentSign, "current", null); - } - public void MapInit() { if (_currentSign != null) diff --git a/Content.Server/GameObjects/Components/BarSign/BarSignPrototype.cs b/Content.Server/GameObjects/Components/BarSign/BarSignPrototype.cs index 79e2d7903d..07b6975904 100644 --- a/Content.Server/GameObjects/Components/BarSign/BarSignPrototype.cs +++ b/Content.Server/GameObjects/Components/BarSign/BarSignPrototype.cs @@ -1,40 +1,44 @@ +#nullable enable using Robust.Shared.Localization; using Robust.Shared.Prototypes; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.BarSign { [Prototype("barSign")] public class BarSignPrototype : IPrototype { - public string ID { get; private set; } - public string Icon { get; private set; } - public string Name { get; private set; } - public string Description { get; private set; } - public bool RenameArea { get; private set; } = true; - public bool Hidden { get; private set; } + private string _description = ""; + private string _name = ""; - public void LoadFrom(YamlMappingNode mapping) + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; + + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } + + [DataField("icon")] public string Icon { get; private set; } = ""; + + [DataField("name")] + public string Name { - ID = mapping.GetNode("id").AsString(); - Name = Loc.GetString(mapping.GetNode("name").AsString()); - Icon = mapping.GetNode("icon").AsString(); - - if (mapping.TryGetNode("hidden", out var node)) - { - Hidden = node.AsBool(); - } - - if (mapping.TryGetNode("renameArea", out node)) - { - RenameArea = node.AsBool(); - } - - if (mapping.TryGetNode("description", out node)) - { - Description = Loc.GetString(node.AsString()); - } + get => _name; + private set => _name = Loc.GetString(value); } + + [DataField("description")] + public string Description + { + get => _description; + private set => _description = Loc.GetString(value); + } + + [DataField("renameArea")] + public bool RenameArea { get; private set; } = true; + [DataField("hidden")] + public bool Hidden { get; private set; } } } diff --git a/Content.Server/GameObjects/Components/Body/Behavior/LiverBehavior.cs b/Content.Server/GameObjects/Components/Body/Behavior/LiverBehavior.cs index a6a882e0a6..af65dd2fd6 100644 --- a/Content.Server/GameObjects/Components/Body/Behavior/LiverBehavior.cs +++ b/Content.Server/GameObjects/Components/Body/Behavior/LiverBehavior.cs @@ -3,9 +3,10 @@ using System.Linq; using Content.Server.GameObjects.Components.Body.Circulatory; using Content.Shared.Chemistry; using Content.Shared.GameObjects.Components.Body.Networks; +using Content.Shared.Interfaces.Chemistry; using Robust.Shared.IoC; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Body.Behavior @@ -27,21 +28,25 @@ namespace Content.Server.GameObjects.Components.Body.Behavior /// /// Modifier for alcohol damage. /// + [DataField("alcoholLethality")] [ViewVariables] private float _alcoholLethality = 0.005f; /// /// Modifier for alcohol damage. /// + [DataField("alcoholExponent")] [ViewVariables] private float _alcoholExponent = 1.6f; /// /// Toxin volume that can be purged without damage. /// + [DataField("toxinTolerance")] [ViewVariables] private float _toxinTolerance = 3f; /// /// Toxin damage modifier. /// + [DataField("toxinLethality")] [ViewVariables] private float _toxinLethality = 0.01f; /// @@ -102,15 +107,5 @@ namespace Content.Server.GameObjects.Components.Body.Behavior } } } - - public override void ExposeData(ObjectSerializer serializer) - { - //Uses typical human values for defaults. - base.ExposeData(serializer); - serializer.DataField(ref _alcoholLethality, "alcoholLethality", 0.005f); - serializer.DataField(ref _alcoholExponent, "alcoholExponent", 1.6f); - serializer.DataField(ref _toxinTolerance, "toxinTolerance", 3f); - serializer.DataField(ref _toxinLethality, "toxinLethality", 0.01f); - } } } diff --git a/Content.Server/GameObjects/Components/Body/Behavior/LungBehavior.cs b/Content.Server/GameObjects/Components/Body/Behavior/LungBehavior.cs index 00d8be4d71..e92f732e4b 100644 --- a/Content.Server/GameObjects/Components/Body/Behavior/LungBehavior.cs +++ b/Content.Server/GameObjects/Components/Body/Behavior/LungBehavior.cs @@ -10,12 +10,13 @@ using Content.Shared.GameObjects.Components.Body; using Content.Shared.GameObjects.Components.Mobs.State; using Robust.Shared.IoC; using Robust.Shared.Localization; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Timing; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Body.Behavior { + [DataDefinition] public class LungBehavior : MechanismBehavior { [Dependency] private readonly IGameTiming _gameTiming = default!; @@ -24,43 +25,27 @@ namespace Content.Server.GameObjects.Components.Body.Behavior [ViewVariables] private TimeSpan _lastGaspPopupTime; - [ViewVariables] public GasMixture Air { get; set; } = default!; + [DataField("air")] + [ViewVariables] + public GasMixture Air { get; set; } = new() + { + Volume = 6, + Temperature = Atmospherics.NormalBodyTemperature + }; - [ViewVariables] public float Temperature => Air.Temperature; - - [ViewVariables] public float Volume => Air.Volume; - - [ViewVariables] public TimeSpan GaspPopupCooldown { get; private set; } + [DataField("gaspPopupCooldown")] + [ViewVariables] + public TimeSpan GaspPopupCooldown { get; private set; } = TimeSpan.FromSeconds(8); [ViewVariables] public LungStatus Status { get; set; } - [ViewVariables] public float CycleDelay { get; set; } + [DataField("cycleDelay")] + [ViewVariables] + public float CycleDelay { get; set; } = 2; - public override void ExposeData(ObjectSerializer serializer) + public LungBehavior() { - base.ExposeData(serializer); - - Air = new GasMixture {Temperature = Atmospherics.NormalBodyTemperature}; - - serializer.DataField(this, l => l.CycleDelay, "cycleDelay", 2); - - serializer.DataReadWriteFunction( - "volume", - 6, - vol => Air.Volume = vol, - () => Air.Volume); - - serializer.DataReadWriteFunction( - "temperature", - Atmospherics.NormalBodyTemperature, - temp => Air.Temperature = temp, - () => Air.Temperature); - - serializer.DataReadWriteFunction( - "gaspPopupCooldown", - 8f, - delay => GaspPopupCooldown = TimeSpan.FromSeconds(delay), - () => GaspPopupCooldown.TotalSeconds); + IoCManager.InjectDependencies(this); } protected override void OnAddedToBody(IBody body) diff --git a/Content.Server/GameObjects/Components/Body/Behavior/MechanismBehavior.cs b/Content.Server/GameObjects/Components/Body/Behavior/MechanismBehavior.cs index a3629ad1fc..e4b42103dd 100644 --- a/Content.Server/GameObjects/Components/Body/Behavior/MechanismBehavior.cs +++ b/Content.Server/GameObjects/Components/Body/Behavior/MechanismBehavior.cs @@ -4,7 +4,6 @@ using Content.Shared.GameObjects.Components.Body.Behavior; using Content.Shared.GameObjects.Components.Body.Mechanism; using Content.Shared.GameObjects.Components.Body.Part; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; using Robust.Shared.Utility; namespace Content.Server.GameObjects.Components.Body.Behavior @@ -19,8 +18,6 @@ namespace Content.Server.GameObjects.Components.Body.Behavior public IEntity Owner => Parent.Owner; - public virtual void ExposeData(ObjectSerializer serializer) { } - public virtual void Initialize(IMechanism parent) { Parent = parent; diff --git a/Content.Server/GameObjects/Components/Body/Behavior/StomachBehavior.cs b/Content.Server/GameObjects/Components/Body/Behavior/StomachBehavior.cs index b29983f7af..5eafd2565e 100644 --- a/Content.Server/GameObjects/Components/Body/Behavior/StomachBehavior.cs +++ b/Content.Server/GameObjects/Components/Body/Behavior/StomachBehavior.cs @@ -7,7 +7,7 @@ using Content.Shared.Chemistry; using Content.Shared.GameObjects.Components.Body.Networks; using Content.Shared.GameObjects.Components.Chemistry; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Body.Behavior @@ -89,15 +89,16 @@ namespace Content.Server.GameObjects.Components.Body.Behavior /// /// Initial internal solution storage volume /// + [DataField("maxVolume")] [ViewVariables] - protected ReagentUnit InitialMaxVolume { get; private set; } + protected ReagentUnit InitialMaxVolume { get; private set; } = ReagentUnit.New(100); /// /// Time in seconds between reagents being ingested and them being /// transferred to /// - [ViewVariables] - private float _digestionDelay; + [DataField("digestionDelay")] [ViewVariables] + private float _digestionDelay = 20; /// /// Used to track how long each reagent has been in the stomach @@ -105,13 +106,6 @@ namespace Content.Server.GameObjects.Components.Body.Behavior [ViewVariables] private readonly List _reagentDeltas = new(); - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(this, s => s.InitialMaxVolume, "maxVolume", ReagentUnit.New(100)); - serializer.DataField(ref _digestionDelay, "digestionDelay", 20); - } - public override void Startup() { base.Startup(); diff --git a/Content.Server/GameObjects/Components/Body/Circulatory/BloodstreamComponent.cs b/Content.Server/GameObjects/Components/Body/Circulatory/BloodstreamComponent.cs index e915c526ce..c57ac645a0 100644 --- a/Content.Server/GameObjects/Components/Body/Circulatory/BloodstreamComponent.cs +++ b/Content.Server/GameObjects/Components/Body/Circulatory/BloodstreamComponent.cs @@ -7,7 +7,9 @@ using Content.Shared.Atmos; using Content.Shared.Chemistry; using Content.Shared.GameObjects.Components.Body.Networks; using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Body.Circulatory @@ -21,7 +23,8 @@ namespace Content.Server.GameObjects.Components.Body.Circulatory /// /// Max volume of internal solution storage /// - [ViewVariables] private ReagentUnit _initialMaxVolume; + [DataField("maxVolume")] + [ViewVariables] private ReagentUnit _initialMaxVolume = ReagentUnit.New(250); /// /// Internal solution for reagent storage @@ -33,7 +36,9 @@ namespace Content.Server.GameObjects.Components.Body.Circulatory /// [ViewVariables] public ReagentUnit EmptyVolume => _internalSolution.EmptyVolume; - [ViewVariables] public GasMixture Air { get; set; } + [ViewVariables] + public GasMixture Air { get; set; } = new(6) + {Temperature = Atmospherics.NormalBodyTemperature}; [ViewVariables] public SolutionContainerComponent Solution => _internalSolution; @@ -45,15 +50,6 @@ namespace Content.Server.GameObjects.Components.Body.Circulatory _internalSolution.MaxVolume = _initialMaxVolume; } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - Air = new GasMixture(6) {Temperature = Atmospherics.NormalBodyTemperature}; - - serializer.DataField(ref _initialMaxVolume, "maxVolume", ReagentUnit.New(250)); - } - /// /// Attempt to transfer provided solution to internal solution. /// Only supports complete transfers diff --git a/Content.Server/GameObjects/Components/Body/Surgery/SurgeryToolComponent.cs b/Content.Server/GameObjects/Components/Body/Surgery/SurgeryToolComponent.cs index 7a93fa7e54..1adcce5967 100644 --- a/Content.Server/GameObjects/Components/Body/Surgery/SurgeryToolComponent.cs +++ b/Content.Server/GameObjects/Components/Body/Surgery/SurgeryToolComponent.cs @@ -16,7 +16,9 @@ using Robust.Server.Player; using Robust.Shared.GameObjects; using Robust.Shared.Localization; using Robust.Shared.Log; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Body.Surgery @@ -33,13 +35,15 @@ namespace Content.Server.GameObjects.Components.Body.Surgery private readonly Dictionary _optionsCache = new(); - private float _baseOperateTime; + [DataField("baseOperateTime")] + private float _baseOperateTime = 5; private ISurgeon.MechanismRequestCallback? _callbackCache; private int _idHash; - private SurgeryType _surgeryType; + [DataField("surgeryType")] + private SurgeryType _surgeryType = SurgeryType.Incision; [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(SurgeryUIKey.Key); @@ -141,14 +145,6 @@ namespace Content.Server.GameObjects.Components.Body.Surgery } } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _surgeryType, "surgeryType", SurgeryType.Incision); - serializer.DataField(ref _baseOperateTime, "baseOperateTime", 5); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Botany/PlantHolderComponent.cs b/Content.Server/GameObjects/Components/Botany/PlantHolderComponent.cs index 64755954cb..4caabbcc92 100644 --- a/Content.Server/GameObjects/Components/Botany/PlantHolderComponent.cs +++ b/Content.Server/GameObjects/Components/Botany/PlantHolderComponent.cs @@ -28,6 +28,7 @@ using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Serialization; using Robust.Shared.Timing; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -52,6 +53,7 @@ namespace Content.Server.GameObjects.Components.Botany [ViewVariables(VVAccess.ReadWrite)] private bool _updateSpriteAfterUpdate; [ViewVariables(VVAccess.ReadWrite)] + [DataField("drawWarnings")] public bool DrawWarnings { get; private set; } = false; [ViewVariables(VVAccess.ReadWrite)] @@ -124,12 +126,6 @@ namespace Content.Server.GameObjects.Components.Botany Owner.EnsureComponentWarn(); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(this, x => x.DrawWarnings, "drawWarnings", false); - } - public void WeedInvasion() { // TODO diff --git a/Content.Server/GameObjects/Components/Botany/ProduceComponent.cs b/Content.Server/GameObjects/Components/Botany/ProduceComponent.cs index cd6e2b6eaf..6684f226f9 100644 --- a/Content.Server/GameObjects/Components/Botany/ProduceComponent.cs +++ b/Content.Server/GameObjects/Components/Botany/ProduceComponent.cs @@ -1,4 +1,5 @@ -using Content.Server.Botany; +#nullable enable +using Content.Server.Botany; using Content.Server.GameObjects.Components.Chemistry; using Content.Shared.Chemistry; using Robust.Server.GameObjects; @@ -7,39 +8,36 @@ using Robust.Shared.IoC; using Robust.Shared.Maths; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Botany { [RegisterComponent] - public class ProduceComponent : Component + public class ProduceComponent : Component, ISerializationHooks { [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + public override string Name => "Produce"; + [DataField("seed")] + private string? _seedName; + [ViewVariables] - public Seed Seed { get; set; } = null; - - public float Potency => Seed.Potency; - - public override void ExposeData(ObjectSerializer serializer) + public Seed? Seed { - base.ExposeData(serializer); - - serializer.DataReadFunction("seed", null, - (s) => - { - if(!string.IsNullOrEmpty(s)) - Seed = _prototypeManager.Index(s); - }); + get => _seedName != null ? IoCManager.Resolve().Index(_seedName) : null; + set => _seedName = value?.ID; } + public float Potency => Seed?.Potency ?? 0; + public void Grown() { if (Seed == null) return; - if (Owner.TryGetComponent(out SpriteComponent sprite)) + if (Owner.TryGetComponent(out SpriteComponent? sprite)) { sprite.LayerSetRSI(0, Seed.PlantRsi); sprite.LayerSetState(0, Seed.PlantIconState); diff --git a/Content.Server/GameObjects/Components/Botany/SeedComponent.cs b/Content.Server/GameObjects/Components/Botany/SeedComponent.cs index d314677bc6..8fdbee0804 100644 --- a/Content.Server/GameObjects/Components/Botany/SeedComponent.cs +++ b/Content.Server/GameObjects/Components/Botany/SeedComponent.cs @@ -1,10 +1,12 @@ -using Content.Server.Botany; +#nullable enable +using Content.Server.Botany; using Content.Shared.GameObjects.EntitySystems; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -16,19 +18,15 @@ namespace Content.Server.GameObjects.Components.Botany [Dependency] private readonly IPrototypeManager _prototypeManager = default!; public override string Name => "Seed"; + + [DataField("seed")] + private string? _seedName; + [ViewVariables] - public Seed Seed { get; set; } = null; - - public override void ExposeData(ObjectSerializer serializer) + public Seed? Seed { - base.ExposeData(serializer); - - serializer.DataReadFunction("seed", null, - (s) => - { - if(!string.IsNullOrEmpty(s)) - Seed = _prototypeManager.Index(s); - }); + get => _seedName != null ? IoCManager.Resolve().Index(_seedName) : null; + set => _seedName = value?.ID; } public void Examine(FormattedMessage message, bool inDetailsRange) diff --git a/Content.Server/GameObjects/Components/Buckle/BuckleComponent.cs b/Content.Server/GameObjects/Components/Buckle/BuckleComponent.cs index cfb582a447..06d33b1413 100644 --- a/Content.Server/GameObjects/Components/Buckle/BuckleComponent.cs +++ b/Content.Server/GameObjects/Components/Buckle/BuckleComponent.cs @@ -22,7 +22,7 @@ using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Maths; using Robust.Shared.Players; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Timing; using Robust.Shared.ViewVariables; @@ -42,14 +42,16 @@ namespace Content.Server.GameObjects.Components.Buckle [ComponentDependency] private readonly StunnableComponent? _stunnable = null; [ComponentDependency] private readonly MobStateComponent? _mobState = null; - private int _size; + [DataField("size")] + private int _size = 100; /// /// The amount of time that must pass for this entity to /// be able to unbuckle after recently buckling. /// + [DataField("delay")] [ViewVariables] - private TimeSpan _unbuckleDelay; + private TimeSpan _unbuckleDelay = TimeSpan.FromSeconds(0.25f); /// /// The time that this entity buckled at. @@ -383,19 +385,6 @@ namespace Content.Server.GameObjects.Components.Buckle return TryBuckle(user, to); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _size, "size", 100); - - serializer.DataReadWriteFunction( - "cooldown", - 0.25f, - seconds => _unbuckleDelay = TimeSpan.FromSeconds(seconds), - () => (float) _unbuckleDelay.TotalSeconds); - } - protected override void Startup() { base.Startup(); diff --git a/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs b/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs index 03c4b88717..20e3590618 100644 --- a/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs +++ b/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs @@ -14,6 +14,9 @@ using Robust.Shared.ViewVariables; using System.Collections.Generic; using Robust.Server.GameObjects; using Robust.Shared.Map; +using System.Linq; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Cargo { @@ -55,6 +58,7 @@ namespace Content.Server.GameObjects.Components.Cargo } } + [DataField("requestOnly")] private bool _requestOnly = false; private bool Powered => !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered; @@ -88,16 +92,6 @@ namespace Content.Server.GameObjects.Components.Cargo base.OnRemove(); } - /// - /// Reads data from YAML - /// - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _requestOnly, "requestOnly", false); - } - private void UserInterfaceOnOnReceiveMessage(ServerBoundUserInterfaceMessage serverMsg) { if (!Owner.TryGetComponent(out CargoOrderDatabaseComponent? orders)) diff --git a/Content.Server/GameObjects/Components/Chemistry/ChemMasterComponent.cs b/Content.Server/GameObjects/Components/Chemistry/ChemMasterComponent.cs index bb6a2b0782..2b65d6c35c 100644 --- a/Content.Server/GameObjects/Components/Chemistry/ChemMasterComponent.cs +++ b/Content.Server/GameObjects/Components/Chemistry/ChemMasterComponent.cs @@ -20,6 +20,9 @@ using Robust.Shared.Audio; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Localization; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Chemistry diff --git a/Content.Server/GameObjects/Components/Chemistry/FoamSolutionAreaEffectComponent.cs b/Content.Server/GameObjects/Components/Chemistry/FoamSolutionAreaEffectComponent.cs index 30f5c8704d..c27d791218 100644 --- a/Content.Server/GameObjects/Components/Chemistry/FoamSolutionAreaEffectComponent.cs +++ b/Content.Server/GameObjects/Components/Chemistry/FoamSolutionAreaEffectComponent.cs @@ -7,7 +7,7 @@ using Content.Shared.GameObjects.Components.Chemistry; using Content.Shared.GameObjects.Components.Inventory; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Chemistry { @@ -17,13 +17,7 @@ namespace Content.Server.GameObjects.Components.Chemistry { public override string Name => "FoamSolutionAreaEffect"; - private string? _foamedMetalPrototype; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _foamedMetalPrototype, "foamedMetalPrototype", null); - } + [DataField("foamedMetalPrototype")] private string? _foamedMetalPrototype; protected override void UpdateVisuals() { diff --git a/Content.Server/GameObjects/Components/Chemistry/HyposprayComponent.cs b/Content.Server/GameObjects/Components/Chemistry/HyposprayComponent.cs index 50bf2b5b9f..e518075211 100644 --- a/Content.Server/GameObjects/Components/Chemistry/HyposprayComponent.cs +++ b/Content.Server/GameObjects/Components/Chemistry/HyposprayComponent.cs @@ -13,6 +13,7 @@ using Robust.Shared.Localization; using Robust.Shared.Maths; using Robust.Shared.Players; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; #nullable enable @@ -22,19 +23,16 @@ namespace Content.Server.GameObjects.Components.Chemistry [RegisterComponent] public sealed class HyposprayComponent : SharedHyposprayComponent, IAttack, ISolutionChange, IAfterInteract { - [ViewVariables(VVAccess.ReadWrite)] public float ClumsyFailChance { get; set; } - [ViewVariables(VVAccess.ReadWrite)] public ReagentUnit TransferAmount { get; set; } + [DataField("ClumsyFailChance")] + [ViewVariables(VVAccess.ReadWrite)] + public float ClumsyFailChance { get; set; } = 0.5f; + + [DataField("TransferAmount")] + [ViewVariables(VVAccess.ReadWrite)] + public ReagentUnit TransferAmount { get; set; } = ReagentUnit.New(5); [ComponentDependency] private readonly SolutionContainerComponent? _solution = default!; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, x => x.ClumsyFailChance, "ClumsyFailChance", 0.5f); - serializer.DataField(this, x => x.TransferAmount, "TransferAmount", ReagentUnit.New(5)); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Chemistry/InjectorComponent.cs b/Content.Server/GameObjects/Components/Chemistry/InjectorComponent.cs index 9f73405034..ce26f92a6c 100644 --- a/Content.Server/GameObjects/Components/Chemistry/InjectorComponent.cs +++ b/Content.Server/GameObjects/Components/Chemistry/InjectorComponent.cs @@ -12,6 +12,7 @@ using Robust.Shared.GameObjects; using Robust.Shared.Localization; using Robust.Shared.Players; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Chemistry @@ -28,18 +29,24 @@ namespace Content.Server.GameObjects.Components.Chemistry /// Whether or not the injector is able to draw from containers or if it's a single use /// device that can only inject. /// - [ViewVariables] private bool _injectOnly; + [ViewVariables] + [DataField("injectOnly")] + private bool _injectOnly; /// /// Amount to inject or draw on each usage. If the injector is inject only, it will /// attempt to inject it's entire contents upon use. /// - [ViewVariables] private ReagentUnit _transferAmount; + [ViewVariables] + [DataField("transferAmount")] + private ReagentUnit _transferAmount = ReagentUnit.New(5); /// /// Initial storage volume of the injector /// - [ViewVariables] private ReagentUnit _initialMaxVolume; + [ViewVariables] + [DataField("initialMaxVolume")] + private ReagentUnit _initialMaxVolume = ReagentUnit.New(15); private InjectorToggleMode _toggleState; @@ -59,16 +66,6 @@ namespace Content.Server.GameObjects.Components.Chemistry } } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _injectOnly, "injectOnly", false); - serializer.DataField(ref _initialMaxVolume, "initialMaxVolume", ReagentUnit.New(15)); - serializer.DataField(ref _transferAmount, "transferAmount", ReagentUnit.New(5)); - serializer.DataField(ref _toggleState, "toggleState", - _injectOnly ? InjectorToggleMode.Inject : InjectorToggleMode.Draw); - } - protected override void Startup() { base.Startup(); diff --git a/Content.Server/GameObjects/Components/Chemistry/PillComponent.cs b/Content.Server/GameObjects/Components/Chemistry/PillComponent.cs index 1750dae021..4008cf87af 100644 --- a/Content.Server/GameObjects/Components/Chemistry/PillComponent.cs +++ b/Content.Server/GameObjects/Components/Chemistry/PillComponent.cs @@ -1,8 +1,8 @@ using System.Linq; using System.Threading.Tasks; using Content.Server.GameObjects.Components.Body.Behavior; -using Content.Server.GameObjects.Components.Nutrition; using Content.Server.GameObjects.Components.Culinary; +using Content.Server.GameObjects.Components.Nutrition; using Content.Shared.Chemistry; using Content.Shared.GameObjects.Components.Body; using Content.Shared.Interfaces; @@ -13,8 +13,7 @@ using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; -using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Chemistry @@ -27,22 +26,19 @@ namespace Content.Server.GameObjects.Components.Chemistry public override string Name => "Pill"; [ViewVariables] - private string _useSound; + [DataField("useSound")] + protected override string UseSound { get; set; } = default; + [ViewVariables] - private string _trashPrototype; + [DataField("trash")] + protected override string TrashPrototype { get; set; } = default; + + [ViewVariables] + [DataField("transferAmount")] + protected override ReagentUnit TransferAmount { get; set; } = ReagentUnit.New(1000); + [ViewVariables] private SolutionContainerComponent _contents; - [ViewVariables] - private ReagentUnit _transferAmount; - - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _useSound, "useSound", null); - serializer.DataField(ref _transferAmount, "transferAmount", ReagentUnit.New(1000)); - serializer.DataField(ref _trashPrototype, "trash", null); - } public override void Initialize() { @@ -88,7 +84,7 @@ namespace Content.Server.GameObjects.Components.Chemistry return false; } - var transferAmount = ReagentUnit.Min(_transferAmount, _contents.CurrentVolume); + var transferAmount = ReagentUnit.Min(TransferAmount, _contents.CurrentVolume); var split = _contents.SplitSolution(transferAmount); var firstStomach = stomachs.FirstOrDefault(stomach => stomach.CanTransferSolution(split)); @@ -106,10 +102,10 @@ namespace Content.Server.GameObjects.Components.Chemistry firstStomach.TryTransferSolution(split); - if (_useSound != null) + if (UseSound != null) { _entitySystem.GetEntitySystem() - .PlayFromEntity(_useSound, trueTarget, AudioParams.Default.WithVolume(-1f)); + .PlayFromEntity(UseSound, trueTarget, AudioParams.Default.WithVolume(-1f)); } trueTarget.PopupMessage(user, Loc.GetString("You swallow the pill.")); diff --git a/Content.Server/GameObjects/Components/Chemistry/ReagentDispenserComponent.cs b/Content.Server/GameObjects/Components/Chemistry/ReagentDispenserComponent.cs index cd399862d1..630c693314 100644 --- a/Content.Server/GameObjects/Components/Chemistry/ReagentDispenserComponent.cs +++ b/Content.Server/GameObjects/Components/Chemistry/ReagentDispenserComponent.cs @@ -24,6 +24,7 @@ using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Chemistry @@ -44,7 +45,7 @@ namespace Content.Server.GameObjects.Components.Chemistry [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [ViewVariables] private ContainerSlot _beakerContainer = default!; - [ViewVariables] private string _packPrototypeId = ""; + [ViewVariables] [DataField("pack")] private string _packPrototypeId = ""; [ViewVariables] private bool HasBeaker => _beakerContainer.ContainedEntity != null; [ViewVariables] private ReagentUnit _dispenseAmount = ReagentUnit.New(10); @@ -54,17 +55,6 @@ namespace Content.Server.GameObjects.Components.Chemistry [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(ReagentDispenserUiKey.Key); - /// - /// Shows the serializer how to save/load this components yaml prototype. - /// - /// Yaml serializer - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _packPrototypeId, "pack", string.Empty); - } - /// /// Called once per instance of this component. Gets references to any other components needed /// by this component and initializes it's UI and other data. diff --git a/Content.Server/GameObjects/Components/Chemistry/ReagentTankComponent.cs b/Content.Server/GameObjects/Components/Chemistry/ReagentTankComponent.cs index 0f654380fb..ab1a5fdec6 100644 --- a/Content.Server/GameObjects/Components/Chemistry/ReagentTankComponent.cs +++ b/Content.Server/GameObjects/Components/Chemistry/ReagentTankComponent.cs @@ -1,6 +1,6 @@ using Content.Shared.Chemistry; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; #nullable enable @@ -12,19 +12,13 @@ namespace Content.Server.GameObjects.Components.Chemistry { public override string Name => "ReagentTank"; + [DataField("transferAmount")] [ViewVariables(VVAccess.ReadWrite)] - public ReagentUnit TransferAmount { get; set; } + public ReagentUnit TransferAmount { get; set; } = ReagentUnit.New(10); + [DataField("tankType")] [ViewVariables(VVAccess.ReadWrite)] - public ReagentTankType TankType { get; set; } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, c => c.TransferAmount, "transferAmount", ReagentUnit.New(10)); - serializer.DataField(this, c => c.TankType, "tankType", ReagentTankType.Unspecified); - } + public ReagentTankType TankType { get; set; } = ReagentTankType.Unspecified; } public enum ReagentTankType : byte diff --git a/Content.Server/GameObjects/Components/Chemistry/RehydratableComponent.cs b/Content.Server/GameObjects/Components/Chemistry/RehydratableComponent.cs index 789ee73f54..e9784e720d 100644 --- a/Content.Server/GameObjects/Components/Chemistry/RehydratableComponent.cs +++ b/Content.Server/GameObjects/Components/Chemistry/RehydratableComponent.cs @@ -5,7 +5,9 @@ using Content.Shared.GameObjects.EntitySystems; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; using Robust.Shared.Localization; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Chemistry @@ -22,19 +24,14 @@ namespace Content.Server.GameObjects.Components.Chemistry public override string Name => "Rehydratable"; [ViewVariables] - private string _catalystPrototype = ""; + [DataField("catalyst")] + private string _catalystPrototype = "chem.Water"; [ViewVariables] + [DataField("target")] private string? _targetPrototype; private bool _expanding; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _catalystPrototype, "catalyst", "chem.Water"); - serializer.DataField(ref _targetPrototype, "target", null); - } - ReagentUnit IReagentReaction.ReagentReactTouch(ReagentPrototype reagent, ReagentUnit volume) => Reaction(reagent, volume); ReagentUnit IReagentReaction.ReagentReactInjection(ReagentPrototype reagent, ReagentUnit volume) => Reaction(reagent, volume); diff --git a/Content.Server/GameObjects/Components/Chemistry/SolutionTransferComponent.cs b/Content.Server/GameObjects/Components/Chemistry/SolutionTransferComponent.cs index 37f9aa7323..7ac131e929 100644 --- a/Content.Server/GameObjects/Components/Chemistry/SolutionTransferComponent.cs +++ b/Content.Server/GameObjects/Components/Chemistry/SolutionTransferComponent.cs @@ -6,7 +6,7 @@ using Content.Shared.Interfaces; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; using Robust.Shared.Localization; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Chemistry @@ -24,47 +24,26 @@ namespace Content.Server.GameObjects.Components.Chemistry public override string Name => "SolutionTransfer"; - private ReagentUnit _transferAmount; - private bool _canReceive; - private bool _canSend; - /// /// The amount of solution to be transferred from this solution when clicking on other solutions with it. /// + [DataField("transferAmount")] [ViewVariables(VVAccess.ReadWrite)] - public ReagentUnit TransferAmount - { - get => _transferAmount; - set => _transferAmount = value; - } + public ReagentUnit TransferAmount { get; set; } = ReagentUnit.New(5); /// /// Can this entity take reagent from reagent tanks? /// + [DataField("canReceive")] [ViewVariables(VVAccess.ReadWrite)] - public bool CanReceive - { - get => _canReceive; - set => _canReceive = value; - } + public bool CanReceive { get; set; } = true; /// /// Can this entity give reagent to other reagent containers? /// + [DataField("canSend")] [ViewVariables(VVAccess.ReadWrite)] - public bool CanSend - { - get => _canSend; - set => _canSend = value; - } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _transferAmount, "transferAmount", ReagentUnit.New(5)); - serializer.DataField(ref _canReceive, "canReceive", true); - serializer.DataField(ref _canSend, "canSend", true); - } + public bool CanSend { get; set; } = true; async Task IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs) { diff --git a/Content.Server/GameObjects/Components/Chemistry/VaporComponent.cs b/Content.Server/GameObjects/Components/Chemistry/VaporComponent.cs index 040bf9eb92..9daf69f41c 100644 --- a/Content.Server/GameObjects/Components/Chemistry/VaporComponent.cs +++ b/Content.Server/GameObjects/Components/Chemistry/VaporComponent.cs @@ -9,6 +9,7 @@ using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Chemistry @@ -22,7 +23,8 @@ namespace Content.Server.GameObjects.Components.Chemistry [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [ViewVariables] - private ReagentUnit _transferAmount; + [DataField("transferAmount")] + private ReagentUnit _transferAmount = ReagentUnit.New(0.5); private bool _reached; private float _reactTimer; @@ -55,12 +57,6 @@ namespace Content.Server.GameObjects.Components.Chemistry } } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _transferAmount, "transferAmount", ReagentUnit.New(0.5)); - } - public void Update(float frameTime) { if (!Owner.TryGetComponent(out SolutionContainerComponent contents)) diff --git a/Content.Server/GameObjects/Components/CleanableComponent.cs b/Content.Server/GameObjects/Components/CleanableComponent.cs index a93d18661b..055c06c24c 100644 --- a/Content.Server/GameObjects/Components/CleanableComponent.cs +++ b/Content.Server/GameObjects/Components/CleanableComponent.cs @@ -1,6 +1,8 @@ using Content.Shared.Chemistry; using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components @@ -10,14 +12,9 @@ namespace Content.Server.GameObjects.Components { public override string Name => "Cleanable"; - private ReagentUnit _cleanAmount; + [DataField("cleanAmount")] + private ReagentUnit _cleanAmount = ReagentUnit.Zero; [ViewVariables(VVAccess.ReadWrite)] public ReagentUnit CleanAmount => _cleanAmount; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _cleanAmount, "cleanAmount", ReagentUnit.Zero); - } } } diff --git a/Content.Server/GameObjects/Components/ComputerComponent.cs b/Content.Server/GameObjects/Components/ComputerComponent.cs index d35a48b2e1..9757f0ae90 100644 --- a/Content.Server/GameObjects/Components/ComputerComponent.cs +++ b/Content.Server/GameObjects/Components/ComputerComponent.cs @@ -5,7 +5,9 @@ using Robust.Server.GameObjects; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Log; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components @@ -14,14 +16,9 @@ namespace Content.Server.GameObjects.Components public sealed class ComputerComponent : SharedComputerComponent, IMapInit { [ViewVariables] + [DataField("board")] private string _boardPrototype; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _boardPrototype, "board", string.Empty); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/ConfigurationComponent.cs b/Content.Server/GameObjects/Components/ConfigurationComponent.cs index 8bc3e39a93..24c00d33dd 100644 --- a/Content.Server/GameObjects/Components/ConfigurationComponent.cs +++ b/Content.Server/GameObjects/Components/ConfigurationComponent.cs @@ -1,34 +1,51 @@ -using Content.Server.GameObjects.Components.Interactable; +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using Content.Server.GameObjects.Components.Interactable; using Content.Server.Utility; using Content.Shared.GameObjects.Components; using Content.Shared.GameObjects.Components.Interactable; using Content.Shared.GameObjects.Verbs; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Server.Console; +using Robust.Server.GameObjects; using Robust.Server.Player; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; -using System.Collections.Generic; -using System.Linq; -using System.Text.RegularExpressions; -using System.Threading.Tasks; -using Robust.Server.GameObjects; namespace Content.Server.GameObjects.Components { [RegisterComponent] [ComponentReference(typeof(SharedConfigurationComponent))] - public class ConfigurationComponent : SharedConfigurationComponent, IInteractUsing + public class ConfigurationComponent : SharedConfigurationComponent, IInteractUsing, ISerializationHooks { [ViewVariables] private BoundUserInterface UserInterface => Owner.GetUIOrNull(ConfigurationUiKey.Key); + [DataField("keys")] private List _keys = new(); + [ViewVariables] private readonly Dictionary _config = new(); - private Regex _validation; + [DataField("validation")] + private readonly Regex _validation = new ("^[a-zA-Z0-9 ]*$", RegexOptions.Compiled); + + void ISerializationHooks.BeforeSerialization() + { + _keys = _config.Keys.ToList(); + } + + void ISerializationHooks.AfterDeserialization() + { + foreach (var key in _keys) + { + _config.Add(key, ""); + } + } public override void OnAdd() { @@ -48,17 +65,6 @@ namespace Content.Server.GameObjects.Components } } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataReadWriteFunction("keys", new List(), - (list) => FillConfiguration(list, _config, ""), - () => _config.Keys.ToList()); - - serializer.DataReadFunction("validation", "^[a-zA-Z0-9 ]*$", value => _validation = new Regex("^[a-zA-Z0-9 ]*$", RegexOptions.Compiled)); - } - public string GetConfig(string name) { return _config.GetValueOrDefault(name); diff --git a/Content.Server/GameObjects/Components/Construction/ComputerBoardComponent.cs b/Content.Server/GameObjects/Components/Construction/ComputerBoardComponent.cs index 5289e11f45..eb9d53813a 100644 --- a/Content.Server/GameObjects/Components/Construction/ComputerBoardComponent.cs +++ b/Content.Server/GameObjects/Components/Construction/ComputerBoardComponent.cs @@ -1,5 +1,7 @@ using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Construction @@ -9,14 +11,8 @@ namespace Content.Server.GameObjects.Components.Construction { public override string Name => "ComputerBoard"; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, x => x.Prototype, "prototype", string.Empty); - } - [ViewVariables] + [DataField("prototype")] public string Prototype { get; private set; } } } diff --git a/Content.Server/GameObjects/Components/Construction/ConstructionComponent.cs b/Content.Server/GameObjects/Components/Construction/ConstructionComponent.cs index 8cb38af3da..678fe75f28 100644 --- a/Content.Server/GameObjects/Components/Construction/ConstructionComponent.cs +++ b/Content.Server/GameObjects/Components/Construction/ConstructionComponent.cs @@ -18,6 +18,7 @@ using Robust.Shared.Localization; using Robust.Shared.Log; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -33,8 +34,11 @@ namespace Content.Server.GameObjects.Components.Construction private bool _handling = false; private TaskCompletionSource? _handlingTask = null; + [DataField("graph")] private string _graphIdentifier = string.Empty; + [DataField("node")] private string _startingNodeIdentifier = string.Empty; + [DataField("defaultTarget")] private string _startingTargetNodeIdentifier = string.Empty; [ViewVariables] @@ -77,19 +81,9 @@ namespace Content.Server.GameObjects.Components.Construction public int EdgeStep { get; private set; } = 0; [ViewVariables] + [DataField("deconstructionTarget")] public string DeconstructionNodeIdentifier { get; private set; } = "start"; - /// - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _graphIdentifier, "graph", string.Empty); - serializer.DataField(ref _startingNodeIdentifier, "node", string.Empty); - serializer.DataField(ref _startingTargetNodeIdentifier, "defaultTarget", string.Empty); - serializer.DataField(this, x => x.DeconstructionNodeIdentifier, "deconstructionTarget", "start"); - } - /// /// Attempts to set a new pathfinding target. /// diff --git a/Content.Server/GameObjects/Components/Construction/MachineBoardComponent.cs b/Content.Server/GameObjects/Components/Construction/MachineBoardComponent.cs index feadfabc69..2ca8841006 100644 --- a/Content.Server/GameObjects/Components/Construction/MachineBoardComponent.cs +++ b/Content.Server/GameObjects/Components/Construction/MachineBoardComponent.cs @@ -3,13 +3,11 @@ using System.Collections.Generic; using Content.Server.Construction; using Content.Shared.GameObjects.EntitySystems; using Content.Shared.Stacks; -using Microsoft.Extensions.Logging; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; -using Robust.Shared.Log; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -23,17 +21,23 @@ namespace Content.Server.GameObjects.Components.Construction public override string Name => "MachineBoard"; [ViewVariables] - private Dictionary _requirements; + [DataField("requirements")] + private Dictionary _requirements = new(); [ViewVariables] - private Dictionary _materialIdRequirements; + [DataField("materialRequirements")] + private Dictionary _materialIdRequirements = new(); [ViewVariables] - private Dictionary _componentRequirements; + [DataField("componentRequirements")] + private Dictionary _componentRequirements = new(); [ViewVariables(VVAccess.ReadWrite)] + [DataField("prototype")] public string Prototype { get; private set; } + public IReadOnlyDictionary Requirements => _requirements; + public IReadOnlyDictionary MaterialIdRequirements => _materialIdRequirements; public IEnumerable> MaterialRequirements @@ -50,28 +54,6 @@ namespace Content.Server.GameObjects.Components.Construction public IReadOnlyDictionary ComponentRequirements => _componentRequirements; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(this, x => x.Prototype, "prototype", null); - serializer.DataField(ref _requirements, "requirements", new Dictionary()); - serializer.DataField(ref _materialIdRequirements, "materialRequirements", new Dictionary()); - serializer.DataField(ref _componentRequirements, "componentRequirements", new Dictionary()); - } - - protected override void Startup() - { - base.Startup(); - - foreach (var material in _materialIdRequirements.Keys) - { - if (!_prototypeManager.HasIndex(material)) - { - Logger.Error($"No {nameof(StackPrototype)} found with id {material}"); - } - } - } - public void Examine(FormattedMessage message, bool inDetailsRange) { message.AddMarkup(Loc.GetString("Requires:\n")); @@ -93,10 +75,14 @@ namespace Content.Server.GameObjects.Components.Construction } [Serializable] + [DataDefinition] public struct ComponentPartInfo { + [DataField("Amount")] public int Amount; + [DataField("ExamineName")] public string ExamineName; + [DataField("DefaultPrototype")] public string DefaultPrototype; } } diff --git a/Content.Server/GameObjects/Components/Construction/MachineComponent.cs b/Content.Server/GameObjects/Components/Construction/MachineComponent.cs index 5b2e2ef163..caa3a313cd 100644 --- a/Content.Server/GameObjects/Components/Construction/MachineComponent.cs +++ b/Content.Server/GameObjects/Components/Construction/MachineComponent.cs @@ -5,7 +5,9 @@ using Content.Server.Interfaces.GameObjects; using Robust.Server.GameObjects; using Robust.Shared.Containers; using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Construction { @@ -14,17 +16,12 @@ namespace Content.Server.GameObjects.Components.Construction { public override string Name => "Machine"; + [DataField("board")] public string BoardPrototype { get; private set; } private Container _boardContainer; private Container _partContainer; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(this, x => x.BoardPrototype, "board", null); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Construction/MachinePartComponent.cs b/Content.Server/GameObjects/Components/Construction/MachinePartComponent.cs index 18a8e8ce27..145709aaee 100644 --- a/Content.Server/GameObjects/Components/Construction/MachinePartComponent.cs +++ b/Content.Server/GameObjects/Components/Construction/MachinePartComponent.cs @@ -3,7 +3,9 @@ using Content.Server.Construction; using Content.Shared.GameObjects.EntitySystems; using Robust.Shared.GameObjects; using Robust.Shared.Localization; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -31,19 +33,11 @@ namespace Content.Server.GameObjects.Components.Construction public override string Name => "MachinePart"; - [ViewVariables] - public MachinePart PartType { get; private set; } + [ViewVariables] [DataField("part")] public MachinePart PartType { get; private set; } = MachinePart.Capacitor; [ViewVariables(VVAccess.ReadWrite)] - public int Rating { get; private set; } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, x => x.PartType, "part", MachinePart.Capacitor); - serializer.DataField(this, x => x.Rating, "rating", 1); - } + [DataField("rating")] + public int Rating { get; private set; } = 1; public void Examine(FormattedMessage message, bool inDetailsRange) { diff --git a/Content.Server/GameObjects/Components/Construction/WelderRefinableComponent.cs b/Content.Server/GameObjects/Components/Construction/WelderRefinableComponent.cs index a642da142b..d0d5961b62 100644 --- a/Content.Server/GameObjects/Components/Construction/WelderRefinableComponent.cs +++ b/Content.Server/GameObjects/Components/Construction/WelderRefinableComponent.cs @@ -6,7 +6,9 @@ using Content.Server.GameObjects.Components.Stack; using Content.Shared.GameObjects.Components.Interactable; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Construction @@ -19,22 +21,17 @@ namespace Content.Server.GameObjects.Components.Construction public class WelderRefinableComponent : Component, IInteractUsing { [ViewVariables] - private HashSet? _refineResult = default; + [DataField("refineResult")] + private HashSet? _refineResult = new() { "GlassStack" }; [ViewVariables] - private float _refineTime; + [DataField("refineTime")] + private float _refineTime = 2f; private bool _beingWelded; public override string Name => "WelderRefinable"; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _refineResult, "refineResult", new HashSet { "GlassStack" }); - serializer.DataField(ref _refineTime, "refineTime", 2f); - } - - async Task IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) + public async Task InteractUsing(InteractUsingEventArgs eventArgs) { // check if object is welder if (!eventArgs.Using.TryGetComponent(out ToolComponent? tool)) diff --git a/Content.Server/GameObjects/Components/Conveyor/ConveyorComponent.cs b/Content.Server/GameObjects/Components/Conveyor/ConveyorComponent.cs index 363e935724..625492786c 100644 --- a/Content.Server/GameObjects/Components/Conveyor/ConveyorComponent.cs +++ b/Content.Server/GameObjects/Components/Conveyor/ConveyorComponent.cs @@ -9,7 +9,9 @@ using Robust.Server.GameObjects; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Maths; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Conveyor @@ -25,13 +27,15 @@ namespace Content.Server.GameObjects.Components.Conveyor /// The angle to move entities by in relation to the owner's rotation. /// [ViewVariables(VVAccess.ReadWrite)] + [DataField("angle")] private Angle _angle; /// /// The amount of units to move the entity by per second. /// [ViewVariables(VVAccess.ReadWrite)] - private float _speed; + [DataField("speed")] + private float _speed = 2f; private ConveyorState _state; /// @@ -171,14 +175,6 @@ namespace Content.Server.GameObjects.Components.Conveyor } } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _angle, "angle", 0); - serializer.DataField(ref _speed, "speed", 2); - } - public void TriggerSignal(TwoWayLeverSignal signal) { State = signal switch diff --git a/Content.Server/GameObjects/Components/CrayonComponent.cs b/Content.Server/GameObjects/Components/CrayonComponent.cs index 18cd8bdc1d..61e6cde42d 100644 --- a/Content.Server/GameObjects/Components/CrayonComponent.cs +++ b/Content.Server/GameObjects/Components/CrayonComponent.cs @@ -16,32 +16,33 @@ using Robust.Shared.Players; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components { [RegisterComponent] - public class CrayonComponent : SharedCrayonComponent, IAfterInteract, IUse, IDropped + public class CrayonComponent : SharedCrayonComponent, IAfterInteract, IUse, IDropped, ISerializationHooks { [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + //TODO: useSound - private string? _useSound; + [DataField("useSound")] + private string? _useSound = string.Empty; + [ViewVariables] public Color Color { get; set; } [ViewVariables(VVAccess.ReadWrite)] public int Charges { get; set; } - private int _capacity; + [ViewVariables(VVAccess.ReadWrite)] - public int Capacity { get => _capacity; set => _capacity = value; } + [field: DataField("capacity")] + public int Capacity { get; set; } = 30; [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(CrayonUiKey.Key); - public override void ExposeData(ObjectSerializer serializer) + void ISerializationHooks.AfterDeserialization() { - base.ExposeData(serializer); - serializer.DataField(ref _useSound, "useSound", string.Empty); - serializer.DataField(ref _color, "color", "white"); - serializer.DataField(ref _capacity, "capacity", 30); Color = Color.FromName(_color); } @@ -126,7 +127,7 @@ namespace Content.Server.GameObjects.Components if (entity.TryGetComponent(out AppearanceComponent? appearance)) { appearance.SetData(CrayonVisuals.State, SelectedState); - appearance.SetData(CrayonVisuals.Color, Color); + appearance.SetData(CrayonVisuals.Color, _color); appearance.SetData(CrayonVisuals.Rotation, eventArgs.User.Transform.LocalRotation); } diff --git a/Content.Server/GameObjects/Components/Culinary/SliceableFoodComponent.cs b/Content.Server/GameObjects/Components/Culinary/SliceableFoodComponent.cs index 1ecfa1c8ac..4f9969b37a 100644 --- a/Content.Server/GameObjects/Components/Culinary/SliceableFoodComponent.cs +++ b/Content.Server/GameObjects/Components/Culinary/SliceableFoodComponent.cs @@ -1,19 +1,19 @@ using System.Threading.Tasks; -using Content.Shared.Chemistry; -using Content.Shared.Interfaces.GameObjects.Components; -using Content.Shared.GameObjects.EntitySystems; -using Content.Server.GameObjects.Components.Nutrition; using Content.Server.GameObjects.Components.Chemistry; using Content.Server.GameObjects.Components.GUI; using Content.Server.GameObjects.Components.Items.Storage; +using Content.Server.GameObjects.Components.Nutrition; +using Content.Shared.Chemistry; +using Content.Shared.GameObjects.EntitySystems; +using Content.Shared.Interfaces.GameObjects.Components; using Robust.Server.GameObjects; -using Robust.Shared.GameObjects; -using Robust.Shared.Containers; -using Robust.Shared.Serialization; -using Robust.Shared.Localization; -using Robust.Shared.ViewVariables; -using Robust.Shared.Utility; using Robust.Shared.Audio; +using Robust.Shared.Containers; +using Robust.Shared.GameObjects; +using Robust.Shared.Localization; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.Utility; +using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Culinary { @@ -24,20 +24,17 @@ namespace Content.Server.GameObjects.Components.Culinary int IInteractUsing.Priority => 1; // take priority over eating with utensils - [ViewVariables(VVAccess.ReadWrite)] private string _slice; - private ushort _totalCount; - [ViewVariables(VVAccess.ReadWrite)] private string _sound; + [DataField("slice")] [ViewVariables(VVAccess.ReadWrite)] + private string _slice = string.Empty; + + [DataField("sound")] [ViewVariables(VVAccess.ReadWrite)] + private string _sound = "/Audio/Items/Culinary/chop.ogg"; + + [DataField("count")] [ViewVariables(VVAccess.ReadWrite)] + private ushort _totalCount = 5; [ViewVariables(VVAccess.ReadWrite)] public ushort Count; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _slice, "slice", string.Empty); - serializer.DataField(ref _sound, "sound", "/Audio/Items/Culinary/chop.ogg"); - serializer.DataField(ref _totalCount, "count", 5); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Culinary/UtensilComponent.cs b/Content.Server/GameObjects/Components/Culinary/UtensilComponent.cs index f23fc9b744..41e9b77e61 100644 --- a/Content.Server/GameObjects/Components/Culinary/UtensilComponent.cs +++ b/Content.Server/GameObjects/Components/Culinary/UtensilComponent.cs @@ -1,6 +1,5 @@ #nullable enable using System; -using System.Collections.Generic; using System.Threading.Tasks; using Content.Server.GameObjects.Components.Nutrition; using Content.Shared.Interfaces.GameObjects.Components; @@ -10,7 +9,7 @@ using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Random; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Culinary @@ -20,6 +19,7 @@ namespace Content.Server.GameObjects.Components.Culinary { public override string Name => "Utensil"; + [DataField("types")] private UtensilType _types = UtensilType.None; [ViewVariables] @@ -40,13 +40,15 @@ namespace Content.Server.GameObjects.Components.Culinary /// A value of 0 means that it is unbreakable. /// [ViewVariables] + [DataField("breakChance")] private float _breakChance; /// /// The sound to be played if the utensil breaks. /// [ViewVariables] - private string? _breakSound; + [DataField("breakSound")] + private string? _breakSound = "/Audio/Items/snap.ogg"; public void AddType(UtensilType type) { @@ -78,32 +80,6 @@ namespace Content.Server.GameObjects.Components.Culinary } } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataReadWriteFunction("types", - new List(), - types => types.ForEach(AddType), - () => - { - var types = new List(); - - foreach (UtensilType type in Enum.GetValues(typeof(UtensilType))) - { - if ((Types & type) != 0) - { - types.Add(type); - } - } - - return types; - }); - - serializer.DataField(ref _breakChance, "breakChance", 0); - serializer.DataField(ref _breakSound, "breakSound", "/Audio/Items/snap.ogg"); - } - async Task IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs) { TryUseUtensil(eventArgs.User, eventArgs.Target); diff --git a/Content.Server/GameObjects/Components/Damage/DamageOnHighSpeedImpactComponent.cs b/Content.Server/GameObjects/Components/Damage/DamageOnHighSpeedImpactComponent.cs index 5d98dd7bc0..036aa4bedd 100644 --- a/Content.Server/GameObjects/Components/Damage/DamageOnHighSpeedImpactComponent.cs +++ b/Content.Server/GameObjects/Components/Damage/DamageOnHighSpeedImpactComponent.cs @@ -6,9 +6,11 @@ using Content.Shared.GameObjects.Components.Damage; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.IoC; +using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Serialization; using Robust.Shared.Timing; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Damage { @@ -20,32 +22,26 @@ namespace Content.Server.GameObjects.Components.Damage public override string Name => "DamageOnHighSpeedImpact"; + [DataField("damage")] public DamageType Damage { get; set; } = DamageType.Blunt; + [DataField("minimumSpeed")] public float MinimumSpeed { get; set; } = 20f; + [DataField("baseDamage")] public int BaseDamage { get; set; } = 5; - public float Factor { get; set; } = 0.75f; + [DataField("factor")] + public float Factor { get; set; } = 1f; + [DataField("soundHit")] public string SoundHit { get; set; } = ""; + [DataField("stunChance")] public float StunChance { get; set; } = 0.25f; + [DataField("stunMinimumDamage")] public int StunMinimumDamage { get; set; } = 10; + [DataField("stunSeconds")] public float StunSeconds { get; set; } = 1f; + [DataField("damageCooldown")] public float DamageCooldown { get; set; } = 2f; private TimeSpan _lastHit = TimeSpan.Zero; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, x => x.Damage, "damage", DamageType.Blunt); - serializer.DataField(this, x => x.MinimumSpeed, "minimumSpeed", 20f); - serializer.DataField(this, x => x.BaseDamage, "baseDamage", 5); - serializer.DataField(this, x => x.Factor, "factor", 1f); - serializer.DataField(this, x => x.SoundHit, "soundHit", ""); - serializer.DataField(this, x => x.StunChance, "stunChance", 0.25f); - serializer.DataField(this, x => x.StunSeconds, "stunSeconds", 1f); - serializer.DataField(this, x => x.DamageCooldown, "damageCooldown", 2f); - serializer.DataField(this, x => x.StunMinimumDamage, "stunMinimumDamage", 10); - } - public void CollideWith(IEntity collidedWith) { if (!Owner.TryGetComponent(out IPhysicsComponent physics) || !Owner.TryGetComponent(out IDamageableComponent damageable)) return; diff --git a/Content.Server/GameObjects/Components/Damage/DamageOnLandComponent.cs b/Content.Server/GameObjects/Components/Damage/DamageOnLandComponent.cs index b90ef13ad8..7dc420dca9 100644 --- a/Content.Server/GameObjects/Components/Damage/DamageOnLandComponent.cs +++ b/Content.Server/GameObjects/Components/Damage/DamageOnLandComponent.cs @@ -2,7 +2,7 @@ using Content.Shared.Damage; using Content.Shared.GameObjects.Components.Damage; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Damage { @@ -11,19 +11,15 @@ namespace Content.Server.GameObjects.Components.Damage { public override string Name => "DamageOnLand"; - private DamageType _damageType; - private int _amount; + [DataField("damageType")] + private DamageType _damageType = DamageType.Blunt; + + [DataField("amount")] + private int _amount = 1; + + [DataField("ignoreResistances")] private bool _ignoreResistances; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _damageType, "damageType", DamageType.Blunt); - serializer.DataField(ref _amount, "amount", 1); - serializer.DataField(ref _ignoreResistances, "ignoreResistances", false); - } - void ILand.Land(LandEventArgs eventArgs) { if (!Owner.TryGetComponent(out IDamageableComponent damageable)) return; diff --git a/Content.Server/GameObjects/Components/Damage/DamageOnToolInteractComponent.cs b/Content.Server/GameObjects/Components/Damage/DamageOnToolInteractComponent.cs index 5643095593..b2f39bf518 100644 --- a/Content.Server/GameObjects/Components/Damage/DamageOnToolInteractComponent.cs +++ b/Content.Server/GameObjects/Components/Damage/DamageOnToolInteractComponent.cs @@ -6,7 +6,7 @@ using Content.Shared.GameObjects.Components.Damage; using Content.Shared.GameObjects.Components.Interactable; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Damage { @@ -15,19 +15,12 @@ namespace Content.Server.GameObjects.Components.Damage { public override string Name => "DamageOnToolInteract"; - /* Set in YAML */ + [DataField("damage")] protected int Damage; + + [DataField("tools")] private List _tools = new(); - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref Damage, "damage", 0); - - serializer.DataField(ref _tools, "tools", new List()); - } - async Task IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { if (eventArgs.Using.TryGetComponent(out var tool)) diff --git a/Content.Server/GameObjects/Components/Damage/DamageOtherOnHitComponent.cs b/Content.Server/GameObjects/Components/Damage/DamageOtherOnHitComponent.cs index b6bd45ce95..596fddb56b 100644 --- a/Content.Server/GameObjects/Components/Damage/DamageOtherOnHitComponent.cs +++ b/Content.Server/GameObjects/Components/Damage/DamageOtherOnHitComponent.cs @@ -2,7 +2,9 @@ using Content.Shared.Damage; using Content.Shared.GameObjects.Components.Damage; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Damage { @@ -11,19 +13,13 @@ namespace Content.Server.GameObjects.Components.Damage { public override string Name => "DamageOtherOnHit"; - private DamageType _damageType; - private int _amount; + [DataField("damageType")] + private DamageType _damageType = DamageType.Blunt; + [DataField("amount")] + private int _amount = 1; + [DataField("ignoreResistances")] private bool _ignoreResistances; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _damageType, "damageType", DamageType.Blunt); - serializer.DataField(ref _amount, "amount", 1); - serializer.DataField(ref _ignoreResistances, "ignoreResistances", false); - } - void IThrowCollide.DoHit(ThrowCollideEventArgs eventArgs) { if (!eventArgs.Target.TryGetComponent(out IDamageableComponent damageable)) return; diff --git a/Content.Server/GameObjects/Components/Destructible/DestructibleComponent.cs b/Content.Server/GameObjects/Components/Destructible/DestructibleComponent.cs index a5924a7ce0..13333d0191 100644 --- a/Content.Server/GameObjects/Components/Destructible/DestructibleComponent.cs +++ b/Content.Server/GameObjects/Components/Destructible/DestructibleComponent.cs @@ -4,7 +4,7 @@ using Content.Server.GameObjects.Components.Destructible.Thresholds; using Content.Server.GameObjects.EntitySystems; using Content.Shared.GameObjects.Components.Damage; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Destructible @@ -20,17 +20,12 @@ namespace Content.Server.GameObjects.Components.Destructible public override string Name => "Destructible"; - [ViewVariables] private List _thresholds = new(); + [ViewVariables] + [DataField("thresholds")] + private List _thresholds = new(); public IReadOnlyList Thresholds => _thresholds; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _thresholds, "thresholds", new List()); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/ChangeConstructionNodeBehavior.cs b/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/ChangeConstructionNodeBehavior.cs index e892fb75e7..e115ef3a29 100644 --- a/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/ChangeConstructionNodeBehavior.cs +++ b/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/ChangeConstructionNodeBehavior.cs @@ -3,20 +3,17 @@ using System; using Content.Server.GameObjects.Components.Construction; using Content.Server.GameObjects.EntitySystems; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Behaviors { [Serializable] + [DataDefinition] public class ChangeConstructionNodeBehavior : IThresholdBehavior { + [DataField("node")] public string Node { get; private set; } = string.Empty; - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Node, "node", string.Empty); - } - public async void Execute(IEntity owner, DestructibleSystem system) { if (string.IsNullOrEmpty(Node) || diff --git a/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/DoActsBehavior.cs b/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/DoActsBehavior.cs index a87cd294eb..dc64c30904 100644 --- a/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/DoActsBehavior.cs +++ b/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/DoActsBehavior.cs @@ -2,33 +2,24 @@ using Content.Server.GameObjects.EntitySystems; using Content.Shared.GameObjects.EntitySystems; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Behaviors { [Serializable] + [DataDefinition] public class DoActsBehavior : IThresholdBehavior { - private int _acts; - /// /// What acts should be triggered upon activation. /// See . /// - public ThresholdActs Acts - { - get => (ThresholdActs) _acts; - set => _acts = (int) value; - } - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(ref _acts, "acts", 0, WithFormat.Flags()); - } + [DataField("acts")] + public ThresholdActs Acts { get; set; } public bool HasAct(ThresholdActs act) { - return (_acts & (int) act) != 0; + return (Acts & act) != 0; } public void Execute(IEntity owner, DestructibleSystem system) diff --git a/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/EmptyAllContainersBehaviour.cs b/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/EmptyAllContainersBehaviour.cs index d1b6956c90..0991a4743e 100644 --- a/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/EmptyAllContainersBehaviour.cs +++ b/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/EmptyAllContainersBehaviour.cs @@ -2,18 +2,16 @@ using Content.Server.GameObjects.EntitySystems; using Robust.Shared.Containers; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; - +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Behaviors { /// /// Drop all items from all containers /// + [DataDefinition] public class EmptyAllContainersBehaviour : IThresholdBehavior { - void IExposeData.ExposeData(ObjectSerializer serializer) { } - public void Execute(IEntity owner, DestructibleSystem system) { if (owner.Deleted || !owner.TryGetComponent(out var containerManager)) @@ -24,6 +22,5 @@ namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Behavior container.EmptyContainer(true, owner.Transform.Coordinates); } } - } } diff --git a/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/GibBehavior.cs b/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/GibBehavior.cs index bbb76e255d..4138717516 100644 --- a/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/GibBehavior.cs +++ b/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/GibBehavior.cs @@ -2,19 +2,15 @@ using Content.Server.GameObjects.EntitySystems; using Content.Shared.GameObjects.Components.Body; using JetBrains.Annotations; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Behaviors { [UsedImplicitly] + [DataDefinition] public class GibBehavior : IThresholdBehavior { - private bool _recursive = true; - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(ref _recursive, "recursive", true); - } + [DataField("recursive")] private bool _recursive = true; public void Execute(IEntity owner, DestructibleSystem system) { diff --git a/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/IThresholdBehavior.cs b/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/IThresholdBehavior.cs index 1b5e9ad12a..1caa5cff0c 100644 --- a/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/IThresholdBehavior.cs +++ b/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/IThresholdBehavior.cs @@ -1,10 +1,9 @@ using Content.Server.GameObjects.EntitySystems; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Behaviors { - public interface IThresholdBehavior : IExposeData + public interface IThresholdBehavior { /// /// Executes this behavior. diff --git a/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/PlaySoundBehavior.cs b/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/PlaySoundBehavior.cs index 4cc6932b11..5f260d96a3 100644 --- a/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/PlaySoundBehavior.cs +++ b/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/PlaySoundBehavior.cs @@ -2,22 +2,18 @@ using Content.Server.GameObjects.EntitySystems; using Content.Shared.Audio; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Behaviors { [Serializable] + [DataDefinition] public class PlaySoundBehavior : IThresholdBehavior { /// /// Sound played upon destruction. /// - public string Sound { get; set; } - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Sound, "sound", string.Empty); - } + [DataField("sound")] public string Sound { get; set; } = string.Empty; public void Execute(IEntity owner, DestructibleSystem system) { diff --git a/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/PlaySoundCollectionBehavior.cs b/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/PlaySoundCollectionBehavior.cs index 028477ad0a..3a638e9367 100644 --- a/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/PlaySoundCollectionBehavior.cs +++ b/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/PlaySoundCollectionBehavior.cs @@ -2,22 +2,19 @@ using Content.Server.GameObjects.EntitySystems; using Content.Shared.Audio; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Behaviors { [Serializable] + [DataDefinition] public class PlaySoundCollectionBehavior : IThresholdBehavior { /// /// Sound collection from which to pick a random sound to play. /// - private string SoundCollection { get; set; } - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.SoundCollection, "soundCollection", string.Empty); - } + [DataField("soundCollection")] + private string SoundCollection { get; set; } = string.Empty; public void Execute(IEntity owner, DestructibleSystem system) { diff --git a/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/SpawnEntitiesBehavior.cs b/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/SpawnEntitiesBehavior.cs index 87a9ce7c85..d69a8071de 100644 --- a/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/SpawnEntitiesBehavior.cs +++ b/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/SpawnEntitiesBehavior.cs @@ -5,23 +5,20 @@ using Content.Server.GameObjects.Components.Stack; using Content.Server.GameObjects.EntitySystems; using Content.Shared.Utility; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Behaviors { [Serializable] + [DataDefinition] public class SpawnEntitiesBehavior : IThresholdBehavior { /// /// Entities spawned on reaching this threshold, from a min to a max. /// + [DataField("spawn")] public Dictionary Spawn { get; set; } = new(); - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Spawn, "spawn", new Dictionary()); - } - public void Execute(IEntity owner, DestructibleSystem system) { foreach (var (entityId, minMax) in Spawn) diff --git a/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/SpillBehavior.cs b/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/SpillBehavior.cs index 7d3712aa39..0cd2299f82 100644 --- a/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/SpillBehavior.cs +++ b/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/SpillBehavior.cs @@ -4,15 +4,14 @@ using Content.Server.GameObjects.Components.Fluids; using Content.Server.GameObjects.EntitySystems; using JetBrains.Annotations; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Behaviors { [UsedImplicitly] + [DataDefinition] public class SpillBehavior : IThresholdBehavior { - void IExposeData.ExposeData(ObjectSerializer serializer) { } - public void Execute(IEntity owner, DestructibleSystem system) { if (!owner.TryGetComponent(out SolutionContainerComponent? solutionContainer)) diff --git a/Content.Server/GameObjects/Components/Destructible/Thresholds/MinMax.cs b/Content.Server/GameObjects/Components/Destructible/Thresholds/MinMax.cs index ed7be9adc4..a402e08168 100644 --- a/Content.Server/GameObjects/Components/Destructible/Thresholds/MinMax.cs +++ b/Content.Server/GameObjects/Components/Destructible/Thresholds/MinMax.cs @@ -1,22 +1,19 @@ using System; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Destructible.Thresholds { [Serializable] - public struct MinMax : IExposeData + [DataDefinition] + public struct MinMax { [ViewVariables] + [DataField("min")] public int Min; [ViewVariables] + [DataField("max")] public int Max; - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(ref Min, "min", 0); - serializer.DataField(ref Max, "max", 0); - } } } diff --git a/Content.Server/GameObjects/Components/Destructible/Thresholds/Threshold.cs b/Content.Server/GameObjects/Components/Destructible/Thresholds/Threshold.cs index 046b075e20..99275614c7 100644 --- a/Content.Server/GameObjects/Components/Destructible/Thresholds/Threshold.cs +++ b/Content.Server/GameObjects/Components/Destructible/Thresholds/Threshold.cs @@ -5,13 +5,15 @@ using Content.Server.GameObjects.Components.Destructible.Thresholds.Triggers; using Content.Server.GameObjects.EntitySystems; using Content.Shared.GameObjects.Components.Damage; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Destructible.Thresholds { - public class Threshold : IExposeData + [DataDefinition] + public class Threshold { + [DataField("behaviors")] private List _behaviors = new(); /// @@ -23,7 +25,9 @@ namespace Content.Server.GameObjects.Components.Destructible.Thresholds /// /// Whether or not this threshold has already been triggered. /// - [ViewVariables] public bool Triggered { get; private set; } + [ViewVariables] + [DataField("triggered")] + public bool Triggered { get; private set; } /// /// Whether or not this threshold only triggers once. @@ -31,26 +35,22 @@ namespace Content.Server.GameObjects.Components.Destructible.Thresholds /// and then damaged to reach this threshold once again. /// It will not repeatedly trigger as damage rises beyond that. /// - [ViewVariables] public bool TriggersOnce { get; set; } + [ViewVariables] + [DataField("triggersOnce")] + public bool TriggersOnce { get; set; } /// /// The trigger that decides if this threshold has been reached. /// - [ViewVariables] public IThresholdTrigger? Trigger { get; set; } + [ViewVariables] + [DataField("trigger")] + public IThresholdTrigger? Trigger { get; set; } /// /// Behaviors to activate once this threshold is triggered. /// [ViewVariables] public IReadOnlyList Behaviors => _behaviors; - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Triggered, "triggered", false); - serializer.DataField(this, x => x.TriggersOnce, "triggersOnce", false); - serializer.DataField(this, x => x.Trigger, "trigger", null); - serializer.DataField(ref _behaviors, "behaviors", new List()); - } - public bool Reached(IDamageableComponent damageable, DestructibleSystem system) { if (Trigger == null) diff --git a/Content.Server/GameObjects/Components/Destructible/Thresholds/Triggers/AndTrigger.cs b/Content.Server/GameObjects/Components/Destructible/Thresholds/Triggers/AndTrigger.cs index f478fffb7f..90736f1889 100644 --- a/Content.Server/GameObjects/Components/Destructible/Thresholds/Triggers/AndTrigger.cs +++ b/Content.Server/GameObjects/Components/Destructible/Thresholds/Triggers/AndTrigger.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; using Content.Server.GameObjects.EntitySystems; using Content.Shared.GameObjects.Components.Damage; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Triggers { @@ -11,15 +11,12 @@ namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Triggers /// A trigger that will activate when all of its triggers have activated. /// [Serializable] + [DataDefinition] public class AndTrigger : IThresholdTrigger { + [DataField("triggers")] public List Triggers { get; set; } = new(); - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Triggers, "triggers", new List()); - } - public bool Reached(IDamageableComponent damageable, DestructibleSystem system) { foreach (var trigger in Triggers) diff --git a/Content.Server/GameObjects/Components/Destructible/Thresholds/Triggers/DamageClassTrigger.cs b/Content.Server/GameObjects/Components/Destructible/Thresholds/Triggers/DamageClassTrigger.cs index fe48c1ea56..91749bd928 100644 --- a/Content.Server/GameObjects/Components/Destructible/Thresholds/Triggers/DamageClassTrigger.cs +++ b/Content.Server/GameObjects/Components/Destructible/Thresholds/Triggers/DamageClassTrigger.cs @@ -3,7 +3,7 @@ using System; using Content.Server.GameObjects.EntitySystems; using Content.Shared.Damage; using Content.Shared.GameObjects.Components.Damage; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Triggers { @@ -12,24 +12,21 @@ namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Triggers /// of the specified class is above the specified threshold. /// [Serializable] + [DataDefinition] public class DamageClassTrigger : IThresholdTrigger { /// /// The class to check the damage of. /// + [DataField("class")] public DamageClass? Class { get; set; } /// /// The amount of damage at which this threshold will trigger. /// + [DataField("damage")] public int Damage { get; set; } - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Class, "class", null); - serializer.DataField(this, x => x.Damage, "damage", 0); - } - public bool Reached(IDamageableComponent damageable, DestructibleSystem system) { if (Class == null) diff --git a/Content.Server/GameObjects/Components/Destructible/Thresholds/Triggers/DamageTrigger.cs b/Content.Server/GameObjects/Components/Destructible/Thresholds/Triggers/DamageTrigger.cs index bca3121211..1ecc5b151e 100644 --- a/Content.Server/GameObjects/Components/Destructible/Thresholds/Triggers/DamageTrigger.cs +++ b/Content.Server/GameObjects/Components/Destructible/Thresholds/Triggers/DamageTrigger.cs @@ -2,7 +2,7 @@ using System; using Content.Server.GameObjects.EntitySystems; using Content.Shared.GameObjects.Components.Damage; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Triggers { @@ -11,18 +11,15 @@ namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Triggers /// is above the specified threshold. /// [Serializable] + [DataDefinition] public class DamageTrigger : IThresholdTrigger { /// /// The amount of damage at which this threshold will trigger. /// + [DataField("damage")] public int Damage { get; set; } - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Damage, "damage", 0); - } - public bool Reached(IDamageableComponent damageable, DestructibleSystem system) { return damageable.TotalDamage >= Damage; diff --git a/Content.Server/GameObjects/Components/Destructible/Thresholds/Triggers/DamageTypeTrigger.cs b/Content.Server/GameObjects/Components/Destructible/Thresholds/Triggers/DamageTypeTrigger.cs index 25d50ee341..fd281d2632 100644 --- a/Content.Server/GameObjects/Components/Destructible/Thresholds/Triggers/DamageTypeTrigger.cs +++ b/Content.Server/GameObjects/Components/Destructible/Thresholds/Triggers/DamageTypeTrigger.cs @@ -3,7 +3,7 @@ using System; using Content.Server.GameObjects.EntitySystems; using Content.Shared.Damage; using Content.Shared.GameObjects.Components.Damage; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Triggers { @@ -12,18 +12,15 @@ namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Triggers /// of the specified type is above the specified threshold. /// [Serializable] + [DataDefinition] public class DamageTypeTrigger : IThresholdTrigger { + [DataField("type")] public DamageType? Type { get; set; } + [DataField("damage")] public int Damage { get; set; } - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Type, "type", null); - serializer.DataField(this, x => x.Damage, "damage", 0); - } - public bool Reached(IDamageableComponent damageable, DestructibleSystem system) { if (Type == null) diff --git a/Content.Server/GameObjects/Components/Destructible/Thresholds/Triggers/IThresholdTrigger.cs b/Content.Server/GameObjects/Components/Destructible/Thresholds/Triggers/IThresholdTrigger.cs index 69e0a61f17..19495a756e 100644 --- a/Content.Server/GameObjects/Components/Destructible/Thresholds/Triggers/IThresholdTrigger.cs +++ b/Content.Server/GameObjects/Components/Destructible/Thresholds/Triggers/IThresholdTrigger.cs @@ -1,11 +1,10 @@ #nullable enable using Content.Server.GameObjects.EntitySystems; using Content.Shared.GameObjects.Components.Damage; -using Robust.Shared.Serialization; namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Triggers { - public interface IThresholdTrigger : IExposeData + public interface IThresholdTrigger { /// /// Checks if this trigger has been reached. diff --git a/Content.Server/GameObjects/Components/Destructible/Thresholds/Triggers/OrTrigger.cs b/Content.Server/GameObjects/Components/Destructible/Thresholds/Triggers/OrTrigger.cs index 6eea78fc5b..bf40183577 100644 --- a/Content.Server/GameObjects/Components/Destructible/Thresholds/Triggers/OrTrigger.cs +++ b/Content.Server/GameObjects/Components/Destructible/Thresholds/Triggers/OrTrigger.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; using Content.Server.GameObjects.EntitySystems; using Content.Shared.GameObjects.Components.Damage; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Triggers { @@ -11,15 +11,12 @@ namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Triggers /// A trigger that will activate when any of its triggers have activated. /// [Serializable] + [DataDefinition] public class OrTrigger : IThresholdTrigger { + [field: DataField("triggers")] public List Triggers { get; } = new(); - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Triggers, "triggers", new List()); - } - public bool Reached(IDamageableComponent damageable, DestructibleSystem system) { foreach (var trigger in Triggers) diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalBendComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalBendComponent.cs index b53c63a5dc..aa48e19e17 100644 --- a/Content.Server/GameObjects/Components/Disposal/DisposalBendComponent.cs +++ b/Content.Server/GameObjects/Components/Disposal/DisposalBendComponent.cs @@ -1,6 +1,8 @@ using Robust.Shared.GameObjects; using Robust.Shared.Maths; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Disposal { @@ -8,7 +10,8 @@ namespace Content.Server.GameObjects.Components.Disposal [ComponentReference(typeof(IDisposalTubeComponent))] public class DisposalBendComponent : DisposalTubeComponent { - private int _sideDegrees; + [DataField("sideDegrees")] + private int _sideDegrees = -90; public override string Name => "DisposalBend"; @@ -33,11 +36,5 @@ namespace Content.Server.GameObjects.Components.Disposal var previousDirection = DirectionTo(previousTube); return previousDirection == directions[0] ? directions[1] : directions[0]; } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _sideDegrees, "sideDegrees", -90); - } } } diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalHolderComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalHolderComponent.cs index 48e92f60f0..b55d01dc0a 100644 --- a/Content.Server/GameObjects/Components/Disposal/DisposalHolderComponent.cs +++ b/Content.Server/GameObjects/Components/Disposal/DisposalHolderComponent.cs @@ -9,7 +9,9 @@ using Content.Shared.GameObjects.Components.Body; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Maths; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Disposal @@ -50,14 +52,9 @@ namespace Content.Server.GameObjects.Components.Disposal [ViewVariables] public HashSet Tags { get; set; } = new(); - [ViewVariables] public GasMixture Air { get; set; } = default!; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, x => x.Air, "air", new GasMixture(Atmospherics.CellVolume)); - } + [ViewVariables] + [DataField("air")] + public GasMixture Air { get; set; } = new GasMixture(Atmospherics.CellVolume); public override void Initialize() { diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalJunctionComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalJunctionComponent.cs index 92c2da865d..cd2f4cf45f 100644 --- a/Content.Server/GameObjects/Components/Disposal/DisposalJunctionComponent.cs +++ b/Content.Server/GameObjects/Components/Disposal/DisposalJunctionComponent.cs @@ -3,8 +3,10 @@ using System.Linq; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Maths; +using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Disposal @@ -19,6 +21,7 @@ namespace Content.Server.GameObjects.Components.Disposal /// The angles to connect to. /// [ViewVariables] + [DataField("degrees")] private List _degrees; public override string Name => "DisposalJunction"; @@ -43,12 +46,5 @@ namespace Content.Server.GameObjects.Components.Disposal return next; } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _degrees, "degrees", null); - } } } diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalMailingUnitComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalMailingUnitComponent.cs index fbae639349..42dad72f4f 100644 --- a/Content.Server/GameObjects/Components/Disposal/DisposalMailingUnitComponent.cs +++ b/Content.Server/GameObjects/Components/Disposal/DisposalMailingUnitComponent.cs @@ -26,7 +26,7 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Log; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Timing; using Robust.Shared.ViewVariables; using Timer = Robust.Shared.Timing.Timer; @@ -37,7 +37,7 @@ namespace Content.Server.GameObjects.Components.Disposal [ComponentReference(typeof(SharedDisposalMailingUnitComponent))] [ComponentReference(typeof(IActivate))] [ComponentReference(typeof(IInteractUsing))] - public class DisposalMailingUnitComponent : SharedDisposalMailingUnitComponent, IInteractHand, IActivate, IInteractUsing + public class DisposalMailingUnitComponent : SharedDisposalMailingUnitComponent, IInteractHand, IActivate, IInteractUsing, IDragDropOn { [Dependency] private readonly IGameTiming _gameTiming = default!; @@ -61,18 +61,22 @@ namespace Content.Server.GameObjects.Components.Disposal /// Prevents it from flushing if it is not equal to or bigger than 1. /// [ViewVariables] - private float _pressure; + [DataField("pressure")] + private float _pressure = 1f; private bool _engaged; [ViewVariables(VVAccess.ReadWrite)] - private TimeSpan _automaticEngageTime; + [DataField("autoEngageTime")] + private readonly TimeSpan _automaticEngageTime = TimeSpan.FromSeconds(30); [ViewVariables(VVAccess.ReadWrite)] - private TimeSpan _flushDelay; + [DataField("flushDelay")] + private readonly TimeSpan _flushDelay = TimeSpan.FromSeconds(3); [ViewVariables(VVAccess.ReadWrite)] - private float _entryDelay; + [DataField("entryDelay")] + private float _entryDelay = 0.5f; /// /// Token used to cancel the automatic engage of a disposal unit @@ -98,6 +102,7 @@ namespace Content.Server.GameObjects.Components.Disposal private string? _target; [ViewVariables(VVAccess.ReadWrite)] + [DataField("Tag")] private string _tag = string.Empty; [ViewVariables] @@ -558,33 +563,6 @@ namespace Content.Server.GameObjects.Components.Disposal } } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataReadWriteFunction( - "pressure", - 1.0f, - pressure => _pressure = pressure, - () => _pressure); - - serializer.DataReadWriteFunction( - "automaticEngageTime", - 30, - seconds => _automaticEngageTime = TimeSpan.FromSeconds(seconds), - () => (int) _automaticEngageTime.TotalSeconds); - - serializer.DataReadWriteFunction( - "flushDelay", - 3, - seconds => _flushDelay = TimeSpan.FromSeconds(seconds), - () => (int) _flushDelay.TotalSeconds); - - serializer.DataField(ref _entryDelay, "entryDelay", 0.5f); - - serializer.DataField(ref _tag, "Tag", ""); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalTubeComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalTubeComponent.cs index 592fca1f48..26c0005c56 100644 --- a/Content.Server/GameObjects/Components/Disposal/DisposalTubeComponent.cs +++ b/Content.Server/GameObjects/Components/Disposal/DisposalTubeComponent.cs @@ -12,8 +12,10 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Maths; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; using Robust.Shared.Timing; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Disposal @@ -27,7 +29,8 @@ namespace Content.Server.GameObjects.Components.Disposal private bool _connected; private bool _broken; - private string _clangSound = default!; + [DataField("clangSound")] + private string _clangSound = "/Audio/Effects/clang.ogg"; /// /// Container of entities that are currently inside this tube @@ -213,12 +216,6 @@ namespace Content.Server.GameObjects.Components.Disposal UpdateVisualState(); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _clangSound, "clangSound", "/Audio/Effects/clang.ogg"); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs index 89a59c57cc..48a6d01b1c 100644 --- a/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs +++ b/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs @@ -6,16 +6,16 @@ using System.Threading; using System.Threading.Tasks; using Content.Server.Atmos; using Content.Server.GameObjects.Components.GUI; -using Content.Server.GameObjects.Components.Power.ApcNetComponents; using Content.Server.GameObjects.Components.Items.Storage; +using Content.Server.GameObjects.Components.Power.ApcNetComponents; using Content.Server.GameObjects.EntitySystems; using Content.Server.GameObjects.EntitySystems.DoAfter; using Content.Server.Interfaces; using Content.Server.Interfaces.GameObjects.Components.Items; using Content.Server.Utility; -using Content.Shared.GameObjects.Components.Disposal; using Content.Shared.Atmos; using Content.Shared.GameObjects.Components.Body; +using Content.Shared.GameObjects.Components.Disposal; using Content.Shared.GameObjects.Components.Mobs.State; using Content.Shared.GameObjects.EntitySystems.ActionBlocker; using Content.Shared.GameObjects.Verbs; @@ -29,7 +29,7 @@ using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Log; using Robust.Shared.Random; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Timing; using Robust.Shared.ViewVariables; @@ -61,21 +61,25 @@ namespace Content.Server.GameObjects.Components.Disposal /// Prevents it from flushing if it is not equal to or bigger than 1. /// [ViewVariables] + [DataField("pressure")] private float _pressure; private bool _engaged; [ViewVariables(VVAccess.ReadWrite)] - private TimeSpan _automaticEngageTime; + [DataField("autoEngageTime")] + private readonly TimeSpan _automaticEngageTime = TimeSpan.FromSeconds(30); [ViewVariables(VVAccess.ReadWrite)] - private TimeSpan _flushDelay; + [DataField("flushDelay")] + private readonly TimeSpan _flushDelay = TimeSpan.FromSeconds(3); /// /// Delay from trying to enter disposals ourselves. /// [ViewVariables(VVAccess.ReadWrite)] - private float _entryDelay; + [DataField("entryDelay")] + private float _entryDelay = 0.5f; /// /// Delay from trying to shove someone else into disposals. @@ -132,7 +136,8 @@ namespace Content.Server.GameObjects.Components.Disposal /// private (PressureState State, string Localized) _locState; - public GasMixture Air { get; set; } = default!; + [DataField("air")] + public GasMixture Air { get; set; } = new GasMixture(Atmospherics.CellVolume); public override bool CanInsert(IEntity entity) { @@ -515,33 +520,6 @@ namespace Content.Server.GameObjects.Components.Disposal } } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataReadWriteFunction( - "pressure", - 1.0f, - pressure => _pressure = pressure, - () => _pressure); - - serializer.DataReadWriteFunction( - "automaticEngageTime", - 30, - seconds => _automaticEngageTime = TimeSpan.FromSeconds(seconds), - () => (int) _automaticEngageTime.TotalSeconds); - - serializer.DataReadWriteFunction( - "flushDelay", - 3, - seconds => _flushDelay = TimeSpan.FromSeconds(seconds), - () => (int) _flushDelay.TotalSeconds); - - serializer.DataField(this, x => x.Air, "air", new GasMixture(Atmospherics.CellVolume)); - serializer.DataField(ref _entryDelay, "entryDelay", 1.0f); - serializer.DataField(ref _draggedEntryDelay, "draggedEntryDelay", 3.0f); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Doors/ServerDoorComponent.cs b/Content.Server/GameObjects/Components/Doors/ServerDoorComponent.cs index b75158b618..88f241aebb 100644 --- a/Content.Server/GameObjects/Components/Doors/ServerDoorComponent.cs +++ b/Content.Server/GameObjects/Components/Doors/ServerDoorComponent.cs @@ -25,7 +25,7 @@ using Robust.Shared.Log; using Robust.Shared.Maths; using Robust.Shared.Physics; using Robust.Shared.Players; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; using Timer = Robust.Shared.Timing.Timer; @@ -38,7 +38,7 @@ namespace Content.Server.GameObjects.Components.Doors { [ComponentDependency] private readonly IDoorCheck? _doorCheck = null; - + public override DoorState State { get => base.State; @@ -79,31 +79,36 @@ namespace Content.Server.GameObjects.Components.Doors /// /// Whether the door will ever crush. /// - [ViewVariables(VVAccess.ReadOnly)] + [ViewVariables(VVAccess.ReadWrite)] [DataField("inhibitCrush")] private bool _inhibitCrush; /// /// Whether the door blocks light. /// - [ViewVariables(VVAccess.ReadWrite)] private bool _occludes; + [ViewVariables(VVAccess.ReadWrite)] [DataField("occludes")] + private bool _occludes = true; public bool Occludes => _occludes; /// /// Whether the door will open when it is bumped into. /// - [ViewVariables(VVAccess.ReadWrite)] private bool _bumpOpen; + [ViewVariables(VVAccess.ReadWrite)] [DataField("bumpOpen")] + private bool _bumpOpen = true; /// /// Whether the door starts open when it's first loaded from prototype. A door won't start open if its prototype is also welded shut. /// Handled in Startup(). /// + [ViewVariables(VVAccess.ReadWrite)] [DataField("startOpen")] private bool _startOpen; /// /// Whether the airlock is welded shut. Can be set by the prototype, although this will fail if the door isn't weldable. /// When set by prototype, handled in Startup(). /// + [DataField("welded")] private bool _isWeldedShut; + /// /// Whether the airlock is welded shut. /// @@ -127,6 +132,7 @@ namespace Content.Server.GameObjects.Components.Doors /// Whether the door can ever be welded shut. /// private bool _weldable; + /// /// Whether the door can currently be welded. /// @@ -135,19 +141,11 @@ namespace Content.Server.GameObjects.Components.Doors /// /// Whether something is currently using a welder on this so DoAfter isn't spammed. /// - private bool _beingWelded = false; + private bool _beingWelded; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _isWeldedShut, "welded", false); - serializer.DataField(ref _startOpen, "startOpen", false); - serializer.DataField(ref _weldable, "weldable", true); - serializer.DataField(ref _bumpOpen, "bumpOpen", true); - serializer.DataField(ref _occludes, "occludes", true); - serializer.DataField(ref _inhibitCrush, "inhibitCrush", false); - } + [ViewVariables(VVAccess.ReadWrite)] + [DataField("canCrush")] + private bool _canCrush = true; protected override void Startup() { @@ -308,7 +306,7 @@ namespace Content.Server.GameObjects.Components.Doors { return _doorCheck.OpenCheck(); } - + return true; } @@ -452,7 +450,7 @@ namespace Content.Server.GameObjects.Components.Doors OnPartialClose(); await Timer.Delay(CloseTimeTwo, _stateChangeCancelTokenSource.Token); - + if (Occludes && Owner.TryGetComponent(out OccluderComponent? occluder)) { occluder.Enabled = true; diff --git a/Content.Server/GameObjects/Components/Explosion/ClusterFlashComponent.cs b/Content.Server/GameObjects/Components/Explosion/ClusterFlashComponent.cs index 748dbf3396..7b878c561f 100644 --- a/Content.Server/GameObjects/Components/Explosion/ClusterFlashComponent.cs +++ b/Content.Server/GameObjects/Components/Explosion/ClusterFlashComponent.cs @@ -1,23 +1,22 @@ #nullable enable -using Content.Shared.Interfaces.GameObjects.Components; -using Content.Server.GameObjects.Components.Explosion; -using Robust.Shared.GameObjects; -using System.Threading.Tasks; -using Robust.Shared.Serialization; using System; using System.Diagnostics.CodeAnalysis; +using System.Threading.Tasks; using Content.Server.GameObjects.Components.Trigger.TimerTrigger; using Content.Server.Throw; -using Robust.Server.GameObjects; using Content.Shared.GameObjects.Components.Explosion; using Robust.Shared.Containers; +using Content.Shared.Interfaces.GameObjects.Components; +using Robust.Server.GameObjects; +using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Random; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; -namespace Content.Server.GameObjects.Components.Explosives +namespace Content.Server.GameObjects.Components.Explosion { [RegisterComponent] public sealed class ClusterFlashComponent : Component, IInteractUsing, IUse @@ -29,7 +28,7 @@ namespace Content.Server.GameObjects.Components.Explosives /// /// What we fill our prototype with if we want to pre-spawn with grenades. /// - [ViewVariables] + [ViewVariables] [DataField("fillPrototype")] private string? _fillPrototype; /// @@ -40,20 +39,20 @@ namespace Content.Server.GameObjects.Components.Explosives /// /// Maximum grenades in the container. /// - [ViewVariables] - private int _maxGrenades; + [ViewVariables] [DataField("maxGrenadesCount")] + private int _maxGrenades = 3; /// /// How long until our grenades are shot out and armed. /// - [ViewVariables(VVAccess.ReadWrite)] - private float _delay; + [ViewVariables(VVAccess.ReadWrite)] [DataField("delay")] + private float _delay = 1; /// /// Max distance grenades can be thrown. /// - [ViewVariables(VVAccess.ReadWrite)] - private float _throwDistance; + [ViewVariables(VVAccess.ReadWrite)] [DataField("distance")] + private float _throwDistance = 3; /// /// This is the end. @@ -70,15 +69,6 @@ namespace Content.Server.GameObjects.Components.Explosives return true; } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _fillPrototype, "fillPrototype", null); - serializer.DataField(ref _maxGrenades, "maxGrenadesCount", 3); - serializer.DataField(ref _delay, "delay", 1.0f); - serializer.DataField(ref _throwDistance, "distance", 3.0f); - } public override void Initialize() { diff --git a/Content.Server/GameObjects/Components/Explosion/ExplosiveComponent.cs b/Content.Server/GameObjects/Components/Explosion/ExplosiveComponent.cs index 8b8ab5227a..9c24f370e1 100644 --- a/Content.Server/GameObjects/Components/Explosion/ExplosiveComponent.cs +++ b/Content.Server/GameObjects/Components/Explosion/ExplosiveComponent.cs @@ -2,7 +2,9 @@ using Content.Server.Explosions; using Content.Server.GameObjects.EntitySystems; using Content.Shared.GameObjects.EntitySystems; using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Explosion { @@ -11,23 +13,17 @@ namespace Content.Server.GameObjects.Components.Explosion { public override string Name => "Explosive"; - public int DevastationRange = 0; - public int HeavyImpactRange = 0; - public int LightImpactRange = 0; - public int FlashRange = 0; + [DataField("devastationRange")] + public int DevastationRange; + [DataField("heavyImpactRange")] + public int HeavyImpactRange; + [DataField("lightImpactRange")] + public int LightImpactRange; + [DataField("flashRange")] + public int FlashRange; public bool Exploding { get; private set; } = false; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref DevastationRange, "devastationRange", 0); - serializer.DataField(ref HeavyImpactRange, "heavyImpactRange", 0); - serializer.DataField(ref LightImpactRange, "lightImpactRange", 0); - serializer.DataField(ref FlashRange, "flashRange", 0); - } - public bool Explosion() { if (Exploding) diff --git a/Content.Server/GameObjects/Components/Explosion/FlashExplosiveComponent.cs b/Content.Server/GameObjects/Components/Explosion/FlashExplosiveComponent.cs index 3b2a6300c6..708f7e4562 100644 --- a/Content.Server/GameObjects/Components/Explosion/FlashExplosiveComponent.cs +++ b/Content.Server/GameObjects/Components/Explosion/FlashExplosiveComponent.cs @@ -5,7 +5,7 @@ using Content.Shared.GameObjects.EntitySystems; using Robust.Server.GameObjects; using Robust.Shared.Containers; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Explosion { @@ -17,22 +17,14 @@ namespace Content.Server.GameObjects.Components.Explosion { public override string Name => "FlashExplosive"; - private float _range; - - private float _duration; - - private string _sound; - private bool _deleteOnFlash; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _range, "range", 7.0f); - serializer.DataField(ref _duration, "duration", 8.0f); - serializer.DataField(ref _sound, "sound", "/Audio/Effects/flash_bang.ogg"); - serializer.DataField(ref _deleteOnFlash, "deleteOnFlash", true); - } + [DataField("range")] + private float _range = 7.0f; + [DataField("duration")] + private float _duration = 8.0f; + [DataField("sound")] + private string _sound = "/Audio/Effects/flash_bang.ogg"; + [DataField("deleteOnFlash")] + private bool _deleteOnFlash = true; public bool Explode() { diff --git a/Content.Server/GameObjects/Components/ExtinguisherCabinetComponent.cs b/Content.Server/GameObjects/Components/ExtinguisherCabinetComponent.cs index 46d597da06..06a5c63094 100644 --- a/Content.Server/GameObjects/Components/ExtinguisherCabinetComponent.cs +++ b/Content.Server/GameObjects/Components/ExtinguisherCabinetComponent.cs @@ -11,7 +11,9 @@ using Robust.Server.GameObjects; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Localization; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components @@ -24,7 +26,8 @@ namespace Content.Server.GameObjects.Components public override string Name => "ExtinguisherCabinet"; private bool _opened = false; - private string _doorSound; + [DataField("doorSound")] + private string _doorSound = "/Audio/Machines/machine_switch.ogg"; [ViewVariables] protected ContainerSlot ItemContainer; [ViewVariables] public string DoorSound => _doorSound; @@ -37,13 +40,6 @@ namespace Content.Server.GameObjects.Components ContainerHelpers.EnsureContainer(Owner, "extinguisher_cabinet", out _); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _doorSound, "doorSound", "/Audio/Machines/machine_switch.ogg"); - } - async Task IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { if (!_opened) diff --git a/Content.Server/GameObjects/Components/Fluids/BucketComponent.cs b/Content.Server/GameObjects/Components/Fluids/BucketComponent.cs index 6990b77fd0..11bd04735f 100644 --- a/Content.Server/GameObjects/Components/Fluids/BucketComponent.cs +++ b/Content.Server/GameObjects/Components/Fluids/BucketComponent.cs @@ -1,5 +1,4 @@ #nullable enable -using System; using System.Collections.Generic; using System.Threading.Tasks; using Content.Server.GameObjects.Components.Chemistry; @@ -11,8 +10,7 @@ using Content.Shared.Utility; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Localization; -using Robust.Shared.Log; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Fluids { @@ -42,13 +40,8 @@ namespace Content.Server.GameObjects.Components.Fluids ? solution.CurrentVolume : ReagentUnit.Zero; - private string? _sound; - - /// - public override void ExposeData(ObjectSerializer serializer) - { - serializer.DataFieldCached(ref _sound, "sound", "/Audio/Effects/Fluids/watersplash.ogg"); - } + [DataField("sound")] + private string? _sound = "/Audio/Effects/Fluids/watersplash.ogg"; /// public override void Initialize() diff --git a/Content.Server/GameObjects/Components/Fluids/MopComponent.cs b/Content.Server/GameObjects/Components/Fluids/MopComponent.cs index c2a5774dd6..fca0d3ad9e 100644 --- a/Content.Server/GameObjects/Components/Fluids/MopComponent.cs +++ b/Content.Server/GameObjects/Components/Fluids/MopComponent.cs @@ -11,6 +11,8 @@ using System.Threading.Tasks; using Content.Server.GameObjects.EntitySystems.DoAfter; using Robust.Server.GameObjects; using Robust.Shared.ViewVariables; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Fluids { @@ -22,12 +24,10 @@ namespace Content.Server.GameObjects.Components.Fluids { public override string Name => "Mop"; - public bool Mopping => _mopping; - /// /// Used to prevent do_after spam if we're currently mopping. /// - private bool _mopping; + public bool Mopping { get; private set; } public SolutionContainerComponent? Contents => Owner.GetComponentOrNull(); @@ -50,25 +50,18 @@ namespace Content.Server.GameObjects.Components.Fluids // Picking up a puddle requires multiple clicks // Dumping in a bucket requires 1 click // Long-term you'd probably use a cooldown and start the pickup once we have some form of global cooldown - public ReagentUnit PickupAmount => _pickupAmount; - private ReagentUnit _pickupAmount; + [field: DataField("pickup_amount")] + public ReagentUnit PickupAmount { get; } = ReagentUnit.New(5); - private string? _pickupSound; + [DataField("pickup_sound")] + private string? _pickupSound = "/Audio/Effects/Fluids/slosh.ogg"; /// /// Multiplier for the do_after delay for how fast the mop works. /// [ViewVariables] - private float _mopSpeed; - - /// - public override void ExposeData(ObjectSerializer serializer) - { - serializer.DataFieldCached(ref _pickupSound, "pickup_sound", "/Audio/Effects/Fluids/slosh.ogg"); - // The turbo mop will pickup more - serializer.DataFieldCached(ref _pickupAmount, "pickup_amount", ReagentUnit.New(5)); - serializer.DataField(ref _mopSpeed, "speed", 1.0f); - } + [DataField("speed")] + private float _mopSpeed = 1; public override void Initialize() { @@ -88,7 +81,7 @@ namespace Content.Server.GameObjects.Components.Fluids */ if (!Owner.TryGetComponent(out SolutionContainerComponent? contents) || - _mopping || + Mopping || !eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true)) { return false; @@ -121,7 +114,7 @@ namespace Content.Server.GameObjects.Components.Fluids return false; } - _mopping = true; + Mopping = true; // So if the puddle has 20 units we mop in 2 seconds. Don't just store CurrentVolume given it can change so need to re-calc it anyway. var doAfterArgs = new DoAfterEventArgs(eventArgs.User, _mopSpeed * puddleVolume.Float() / 10.0f, target: eventArgs.Target) @@ -132,7 +125,7 @@ namespace Content.Server.GameObjects.Components.Fluids }; var result = await EntitySystem.Get().DoAfter(doAfterArgs); - _mopping = false; + Mopping = false; if (result == DoAfterStatus.Cancelled || Owner.Deleted || diff --git a/Content.Server/GameObjects/Components/Fluids/PuddleComponent.cs b/Content.Server/GameObjects/Components/Fluids/PuddleComponent.cs index 90104dde43..7e8479ac9a 100644 --- a/Content.Server/GameObjects/Components/Fluids/PuddleComponent.cs +++ b/Content.Server/GameObjects/Components/Fluids/PuddleComponent.cs @@ -16,7 +16,9 @@ using Robust.Shared.Localization; using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Random; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -45,7 +47,8 @@ namespace Content.Server.GameObjects.Components.Fluids public override string Name => "Puddle"; private CancellationTokenSource _evaporationToken; - private ReagentUnit _evaporateThreshold; // How few we can hold prior to self-destructing + [DataField("evaporate_threshold")] + private ReagentUnit _evaporateThreshold = ReagentUnit.New(20); // How few we can hold prior to self-destructing public ReagentUnit EvaporateThreshold { get => _evaporateThreshold; @@ -61,9 +64,11 @@ namespace Content.Server.GameObjects.Components.Fluids /// /// The time that it will take this puddle to evaporate, in seconds. /// - public float EvaporateTime { get; private set; } + [DataField("evaporate_time")] + public float EvaporateTime { get; private set; } = 5f; - private string _spillSound; + [DataField("spill_sound")] + private string _spillSound = "/Audio/Effects/Fluids/splat.ogg"; /// /// Whether or not this puddle is currently overflowing onto its neighbors @@ -86,29 +91,20 @@ namespace Content.Server.GameObjects.Components.Fluids // Currently a random number, potentially change public ReagentUnit OverflowVolume => _overflowVolume; [ViewVariables] - private ReagentUnit _overflowVolume; + [DataField("overflow_volume")] + private ReagentUnit _overflowVolume = ReagentUnit.New(20); private ReagentUnit OverflowLeft => CurrentVolume - OverflowVolume; private SolutionContainerComponent _contents; public bool EmptyHolder => _contents.ReagentList.Count == 0; - private int _spriteVariants; + [DataField("variants")] + private int _spriteVariants = 1; // Whether the underlying solution color should be used - private bool _recolor; + [DataField("recolor")] + private bool _recolor = default; private bool Slippery => Owner.TryGetComponent(out SlipperyComponent slippery) && slippery.Slippery; - /// - public override void ExposeData(ObjectSerializer serializer) - { - serializer.DataFieldCached(ref _spillSound, "spill_sound", "/Audio/Effects/Fluids/splat.ogg"); - serializer.DataField(ref _overflowVolume, "overflow_volume", ReagentUnit.New(20)); - serializer.DataField(this, x => x.EvaporateTime, "evaporate_time", 5.0f); - // Long-term probably have this based on the underlying reagents - serializer.DataField(ref _evaporateThreshold, "evaporate_threshold", ReagentUnit.New(20)); - serializer.DataField(ref _spriteVariants, "variants", 1); - serializer.DataField(ref _recolor, "recolor", false); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Fluids/SprayComponent.cs b/Content.Server/GameObjects/Components/Fluids/SprayComponent.cs index 698adf5268..ee5893a142 100644 --- a/Content.Server/GameObjects/Components/Fluids/SprayComponent.cs +++ b/Content.Server/GameObjects/Components/Fluids/SprayComponent.cs @@ -14,8 +14,10 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Maths; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; using Robust.Shared.Timing; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Fluids @@ -28,18 +30,28 @@ namespace Content.Server.GameObjects.Components.Fluids [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IServerEntityManager _serverEntityManager = default!; - private ReagentUnit _transferAmount; + [DataField("transferAmount")] + private ReagentUnit _transferAmount = ReagentUnit.New(10); + [DataField("spraySound")] private string _spraySound; - private float _sprayVelocity; - private float _sprayAliveTime; + [DataField("sprayVelocity")] + private float _sprayVelocity = 1.5f; + [DataField("sprayAliveTime")] + private float _sprayAliveTime = 0.75f; private TimeSpan _lastUseTime; private TimeSpan _cooldownEnd; - private float _cooldownTime; - private string _vaporPrototype; - private int _vaporAmount; - private float _vaporSpread; + [DataField("cooldownTime")] + private float _cooldownTime = 0.5f; + [DataField("sprayedPrototype")] + private string _vaporPrototype = "Vapor"; + [DataField("vaporAmount")] + private int _vaporAmount = 1; + [DataField("vaporSpread")] + private float _vaporSpread = 90f; + [DataField("hasSafety")] private bool _hasSafety; - private bool _safety; + [DataField("safety")] + private bool _safety = true; /// /// The amount of solution to be sprayer from this solution when using it @@ -77,21 +89,6 @@ namespace Content.Server.GameObjects.Components.Fluids } } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _vaporPrototype, "sprayedPrototype", "Vapor"); - serializer.DataField(ref _vaporAmount, "vaporAmount", 1); - serializer.DataField(ref _vaporSpread, "vaporSpread", 90f); - serializer.DataField(ref _cooldownTime, "cooldownTime", 0.5f); - serializer.DataField(ref _transferAmount, "transferAmount", ReagentUnit.New(10)); - serializer.DataField(ref _sprayVelocity, "sprayVelocity", 1.5f); - serializer.DataField(ref _spraySound, "spraySound", string.Empty); - serializer.DataField(ref _sprayAliveTime, "sprayAliveTime", 0.75f); - serializer.DataField(ref _hasSafety, "hasSafety", false); - serializer.DataField(ref _safety, "safety", true); - } - async Task IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs) { if (!ActionBlockerSystem.CanInteract(eventArgs.User)) diff --git a/Content.Server/GameObjects/Components/Gravity/GravityGeneratorComponent.cs b/Content.Server/GameObjects/Components/Gravity/GravityGeneratorComponent.cs index 52b0bdb63a..2c51a5b0ca 100644 --- a/Content.Server/GameObjects/Components/Gravity/GravityGeneratorComponent.cs +++ b/Content.Server/GameObjects/Components/Gravity/GravityGeneratorComponent.cs @@ -7,7 +7,10 @@ using Content.Shared.Interfaces.GameObjects.Components; using Robust.Server.GameObjects; using Robust.Server.Player; using Robust.Shared.GameObjects; +using Robust.Shared.Localization; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Gravity @@ -17,9 +20,11 @@ namespace Content.Server.GameObjects.Components.Gravity { [ComponentDependency] private readonly AppearanceComponent? _appearance = default!; - private bool _switchedOn; + [DataField("switchedOn")] + private bool _switchedOn = true; - private bool _intact; + [DataField("intact")] + private bool _intact = true; private GravityGeneratorStatus _status; @@ -70,14 +75,6 @@ namespace Content.Server.GameObjects.Components.Gravity UpdateState(); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _switchedOn, "switchedOn", true); - serializer.DataField(ref _intact, "intact", true); - } - bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs) { if (!eventArgs.User.TryGetComponent(out var actor)) diff --git a/Content.Server/GameObjects/Components/Headset/HeadsetComponent.cs b/Content.Server/GameObjects/Components/Headset/HeadsetComponent.cs index 46f035c872..318fd69906 100644 --- a/Content.Server/GameObjects/Components/Headset/HeadsetComponent.cs +++ b/Content.Server/GameObjects/Components/Headset/HeadsetComponent.cs @@ -9,7 +9,9 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Network; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -26,29 +28,21 @@ namespace Content.Server.GameObjects.Components.Headset private RadioSystem _radioSystem = default!; - private List _channels = new(); + [DataField("channels")] + private List _channels = new(){1459}; [ViewVariables(VVAccess.ReadWrite)] - private int BroadcastFrequency { get; set; } + [DataField("broadcastChannel")] + private int BroadcastFrequency { get; set; } = 1459; [ViewVariables(VVAccess.ReadWrite)] + [DataField("listenRange")] public int ListenRange { get; private set; } public IReadOnlyList Channels => _channels; public bool RadioRequested { get; set; } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - // Only listens to speech in exact same position - serializer.DataField(this, h => h.ListenRange, "listenRange", 0); - - serializer.DataField(ref _channels, "channels", new List {1459}); - serializer.DataField(this, h => h.BroadcastFrequency, "broadcastChannel", 1459); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Instruments/InstrumentComponent.cs b/Content.Server/GameObjects/Components/Instruments/InstrumentComponent.cs index e20089dffb..db4ee06d6c 100644 --- a/Content.Server/GameObjects/Components/Instruments/InstrumentComponent.cs +++ b/Content.Server/GameObjects/Components/Instruments/InstrumentComponent.cs @@ -15,7 +15,9 @@ using Robust.Shared.GameObjects; using Robust.Shared.Localization; using Robust.Shared.Network; using Robust.Shared.Players; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Instruments @@ -40,6 +42,7 @@ namespace Content.Server.GameObjects.Components.Instruments [ViewVariables] private IPlayerSession? _instrumentPlayer; + [DataField("handheld")] private bool _handheld; [ViewVariables] @@ -60,11 +63,16 @@ namespace Content.Server.GameObjects.Components.Instruments [ViewVariables] private int _midiEventCount = 0; - private byte _instrumentProgram; + [DataField("program")] + private byte _instrumentProgram = 1; + [DataField("bank")] private byte _instrumentBank; + [DataField("allowPercussion")] private bool _allowPercussion; + [DataField("allowProgramChange")] private bool _allowProgramChange; - private bool _respectMidiLimits; + [DataField("respectMidiLimits")] + private bool _respectMidiLimits = true; public override byte InstrumentProgram { get => _instrumentProgram; set @@ -164,17 +172,6 @@ namespace Content.Server.GameObjects.Components.Instruments _instrumentSystem = EntitySystem.Get(); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _handheld, "handheld", false); - serializer.DataField(ref _instrumentProgram, "program", (byte) 1); - serializer.DataField(ref _instrumentBank, "bank", (byte) 0); - serializer.DataField(ref _allowPercussion, "allowPercussion", false); - serializer.DataField(ref _allowProgramChange, "allowProgramChange", false); - serializer.DataField(ref _respectMidiLimits, "respectMidiLimits", true); - } - public override ComponentState GetComponentState(ICommonSession player) { return new InstrumentState(Playing, InstrumentProgram, InstrumentBank, AllowPercussion, AllowProgramChange, RespectMidiLimits, _lastSequencerTick); diff --git a/Content.Server/GameObjects/Components/Interactable/HandheldLightComponent.cs b/Content.Server/GameObjects/Components/Interactable/HandheldLightComponent.cs index 4e777d26bc..dee577215f 100644 --- a/Content.Server/GameObjects/Components/Interactable/HandheldLightComponent.cs +++ b/Content.Server/GameObjects/Components/Interactable/HandheldLightComponent.cs @@ -19,6 +19,7 @@ using Robust.Shared.Localization; using Robust.Shared.Maths; using Robust.Shared.Players; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -30,7 +31,7 @@ namespace Content.Server.GameObjects.Components.Interactable [RegisterComponent] internal sealed class HandheldLightComponent : SharedHandheldLightComponent, IUse, IExamine, IInteractUsing { - [ViewVariables(VVAccess.ReadWrite)] public float Wattage { get; set; } + [ViewVariables(VVAccess.ReadWrite)] [DataField("wattage")] public float Wattage { get; set; } = 3f; [ViewVariables] private PowerCellSlotComponent _cellSlot = default!; private PowerCellComponent? Cell => _cellSlot.Cell; @@ -42,9 +43,9 @@ namespace Content.Server.GameObjects.Components.Interactable [ViewVariables] protected override bool HasCell => _cellSlot.HasCell; - [ViewVariables(VVAccess.ReadWrite)] public string? TurnOnSound; - [ViewVariables(VVAccess.ReadWrite)] public string? TurnOnFailSound; - [ViewVariables(VVAccess.ReadWrite)] public string? TurnOffSound; + [ViewVariables(VVAccess.ReadWrite)] [DataField("turnOnSound")] public string? TurnOnSound = "/Audio/Items/flashlight_toggle.ogg"; + [ViewVariables(VVAccess.ReadWrite)] [DataField("turnOnFailSound")] public string? TurnOnFailSound = "/Audio/Machines/button.ogg"; + [ViewVariables(VVAccess.ReadWrite)] [DataField("turnOffSound")] public string? TurnOffSound = "/Audio/Items/flashlight_toggle.ogg"; [ComponentDependency] private readonly ItemActionsComponent? _itemActions = null; @@ -53,15 +54,6 @@ namespace Content.Server.GameObjects.Components.Interactable /// private byte? _lastLevel; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(this, x => x.Wattage, "wattage", 3f); - serializer.DataField(ref TurnOnSound, "turnOnSound", "/Audio/Items/flashlight_toggle.ogg"); - serializer.DataField(ref TurnOnFailSound, "turnOnFailSound", "/Audio/Machines/button.ogg"); - serializer.DataField(ref TurnOffSound, "turnOffSound", "/Audio/Items/flashlight_toggle.ogg"); - } - public override void Initialize() { base.Initialize(); @@ -272,10 +264,9 @@ namespace Content.Server.GameObjects.Components.Interactable } [UsedImplicitly] + [DataDefinition] public class ToggleLightAction : IToggleItemAction { - void IExposeData.ExposeData(ObjectSerializer serializer) {} - public bool DoToggleAction(ToggleItemActionEventArgs args) { if (!args.Item.TryGetComponent(out var lightComponent)) return false; diff --git a/Content.Server/GameObjects/Components/Interactable/MatchstickComponent.cs b/Content.Server/GameObjects/Components/Interactable/MatchstickComponent.cs index cbe44e559b..05836a8e9f 100644 --- a/Content.Server/GameObjects/Components/Interactable/MatchstickComponent.cs +++ b/Content.Server/GameObjects/Components/Interactable/MatchstickComponent.cs @@ -5,7 +5,7 @@ using Content.Shared.GameObjects.Components; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Interactable @@ -21,12 +21,13 @@ namespace Content.Server.GameObjects.Components.Interactable /// /// How long will matchstick last in seconds. /// - [ViewVariables(VVAccess.ReadOnly)] private int _duration; + [ViewVariables(VVAccess.ReadOnly)] [DataField("duration")] + private int _duration = 10; /// /// Sound played when you ignite the matchstick. /// - private string? _igniteSound; + [DataField("igniteSound")] private string? _igniteSound; /// /// Point light component. Gives matches a glow in dark effect. @@ -57,14 +58,6 @@ namespace Content.Server.GameObjects.Components.Interactable } } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _duration, "duration", 10); - serializer.DataField(ref _igniteSound, "igniteSound", null); - } - bool IHotItem.IsCurrentlyHot() { return CurrentState == SharedBurningStates.Lit; diff --git a/Content.Server/GameObjects/Components/Interactable/MultitoolComponent.cs b/Content.Server/GameObjects/Components/Interactable/MultitoolComponent.cs index 502336ba5d..68217c2bd7 100644 --- a/Content.Server/GameObjects/Components/Interactable/MultitoolComponent.cs +++ b/Content.Server/GameObjects/Components/Interactable/MultitoolComponent.cs @@ -5,7 +5,7 @@ using Content.Shared.Interfaces.GameObjects.Components; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Players; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Interactable { @@ -15,38 +15,33 @@ namespace Content.Server.GameObjects.Components.Interactable [RegisterComponent] public class MultiToolComponent : Component, IUse { - public class ToolEntry : IExposeData + [DataDefinition] + public class ToolEntry { - private string _state; - private string _sound; - private string _soundCollection; - private string _texture; - private string _sprite; - private string _changeSound; + [DataField("behavior")] public ToolQuality Behavior { get; private set; } = ToolQuality.None; - public ToolQuality Behavior { get; private set; } - public string State => _state; - public string Texture => _texture; - public string Sprite => _sprite; - public string Sound => _sound; - public string SoundCollection => _soundCollection; - public string ChangeSound => _changeSound; + [field: DataField("state")] + public string State { get; } = string.Empty; - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.Behavior, "behavior", ToolQuality.None); - serializer.DataField(ref _state, "state", string.Empty); - serializer.DataField(ref _sprite, "sprite", string.Empty); - serializer.DataField(ref _texture, "texture", string.Empty); - serializer.DataField(ref _sound, "useSound", string.Empty); - serializer.DataField(ref _soundCollection, "useSoundCollection", string.Empty); - serializer.DataField(ref _changeSound, "changeSound", string.Empty); - } + [field: DataField("texture")] + public string Texture { get; } = string.Empty; + + [field: DataField("sprite")] + public string Sprite { get; } = string.Empty; + + [field: DataField("useSound")] + public string Sound { get; } = string.Empty; + + [field: DataField("useSoundCollection")] + public string SoundCollection { get; } = string.Empty; + + [field: DataField("changeSound")] + public string ChangeSound { get; } = string.Empty; } public override string Name => "MultiTool"; public override uint? NetID => ContentNetIDs.MULTITOOLS; - private List _tools; + [DataField("tools")] private List _tools = new(); private int _currentTool = 0; private AudioSystem _audioSystem; @@ -96,12 +91,6 @@ namespace Content.Server.GameObjects.Components.Interactable Dirty(); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _tools, "tools", new List()); - } - bool IUse.UseEntity(UseEntityEventArgs eventArgs) { Cycle(); diff --git a/Content.Server/GameObjects/Components/Interactable/TilePryingComponent.cs b/Content.Server/GameObjects/Components/Interactable/TilePryingComponent.cs index d6d49ead72..e601547d52 100644 --- a/Content.Server/GameObjects/Components/Interactable/TilePryingComponent.cs +++ b/Content.Server/GameObjects/Components/Interactable/TilePryingComponent.cs @@ -7,6 +7,8 @@ using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Serialization; using System.Threading.Tasks; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Interactable { @@ -17,6 +19,7 @@ namespace Content.Server.GameObjects.Components.Interactable [Dependency] private readonly IMapManager _mapManager = default!; public override string Name => "TilePrying"; + [DataField("toolComponentNeeded")] private bool _toolComponentNeeded = true; async Task IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs) @@ -25,12 +28,6 @@ namespace Content.Server.GameObjects.Components.Interactable return true; } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _toolComponentNeeded, "toolComponentNeeded", true); - } - public async void TryPryTile(IEntity user, EntityCoordinates clickLocation) { if (!Owner.TryGetComponent(out var tool) && _toolComponentNeeded) diff --git a/Content.Server/GameObjects/Components/Interactable/ToolComponent.cs b/Content.Server/GameObjects/Components/Interactable/ToolComponent.cs index 3b2ff9ccac..42403fac5b 100644 --- a/Content.Server/GameObjects/Components/Interactable/ToolComponent.cs +++ b/Content.Server/GameObjects/Components/Interactable/ToolComponent.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Threading.Tasks; using Content.Server.GameObjects.EntitySystems.DoAfter; using Content.Shared.Audio; @@ -7,7 +6,7 @@ using Content.Shared.GameObjects.Components.Interactable; using Content.Shared.GameObjects.EntitySystems.ActionBlocker; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Interactable @@ -21,6 +20,7 @@ namespace Content.Server.GameObjects.Components.Interactable [ComponentReference(typeof(IToolComponent))] public class ToolComponent : SharedToolComponent, IToolComponent { + [DataField("qualities")] protected ToolQuality _qualities = ToolQuality.None; [ViewVariables] @@ -38,10 +38,13 @@ namespace Content.Server.GameObjects.Components.Interactable /// For tool interactions that have a delay before action this will modify the rate, time to wait is divided by this value /// [ViewVariables(VVAccess.ReadWrite)] + [DataField("speed")] public float SpeedModifier { get; set; } = 1; + [DataField("useSound")] public string UseSound { get; set; } + [DataField("useSoundCollection")] public string UseSoundCollection { get; set; } public void AddQuality(ToolQuality quality) @@ -61,34 +64,6 @@ namespace Content.Server.GameObjects.Components.Interactable return _qualities.HasFlag(quality); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataReadWriteFunction( - "qualities", - new List(), - qualities => qualities.ForEach(AddQuality), - () => - { - var qualities = new List(); - - foreach (ToolQuality quality in Enum.GetValues(typeof(ToolQuality))) - { - if ((_qualities & quality) != 0) - { - qualities.Add(quality); - } - } - - return qualities; - }); - - serializer.DataField(this, mod => SpeedModifier, "speed", 1); - serializer.DataField(this, use => UseSound, "useSound", string.Empty); - serializer.DataField(this, collection => UseSoundCollection, "useSoundCollection", string.Empty); - } - public virtual async Task UseTool(IEntity user, IEntity target, float doAfterDelay, ToolQuality toolQualityNeeded, Func doAfterCheck = null) { if (!HasQuality(toolQualityNeeded) || !ActionBlockerSystem.CanInteract(user)) diff --git a/Content.Server/GameObjects/Components/Interactable/WelderComponent.cs b/Content.Server/GameObjects/Components/Interactable/WelderComponent.cs index fad7009cb5..556e857917 100644 --- a/Content.Server/GameObjects/Components/Interactable/WelderComponent.cs +++ b/Content.Server/GameObjects/Components/Interactable/WelderComponent.cs @@ -21,7 +21,9 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Players; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -54,6 +56,7 @@ namespace Content.Server.GameObjects.Components.Interactable private SolutionContainerComponent? _solutionComponent; private PointLightComponent? _pointLightComponent; + [DataField("weldSoundCollection")] public string? WeldSoundCollection { get; set; } [ViewVariables] @@ -94,11 +97,6 @@ namespace Content.Server.GameObjects.Components.Interactable Owner.TryGetComponent(out _pointLightComponent); } - public override void ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, collection => WeldSoundCollection, "weldSoundCollection", string.Empty); - } - public override ComponentState GetComponentState(ICommonSession player) { return new WelderComponentState(FuelCapacity, Fuel, WelderLit); diff --git a/Content.Server/GameObjects/Components/Items/Clothing/ClothingComponent.cs b/Content.Server/GameObjects/Components/Items/Clothing/ClothingComponent.cs index c12066b38e..d61db6cdc9 100644 --- a/Content.Server/GameObjects/Components/Items/Clothing/ClothingComponent.cs +++ b/Content.Server/GameObjects/Components/Items/Clothing/ClothingComponent.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using Content.Server.GameObjects.Components.GUI; +using Content.Server.GameObjects.Components.GUI; using Content.Server.GameObjects.Components.Items.Storage; using Content.Shared.GameObjects; using Content.Shared.GameObjects.Components.Items; @@ -9,7 +7,7 @@ using Content.Shared.Interfaces; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; using Robust.Shared.Players; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines; @@ -26,21 +24,24 @@ namespace Content.Server.GameObjects.Components.Items.Clothing public override uint? NetID => ContentNetIDs.CLOTHING; [ViewVariables] + [DataField("Slots")] public SlotFlags SlotFlags = SlotFlags.PREVENTEQUIP; //Different from None, NONE allows equips if no slot flags are required + [DataField("QuickEquip")] private bool _quickEquipEnabled = true; - private int _heatResistance; + + [DataField("HeatResistance")] + private int _heatResistance = 323; + [ViewVariables(VVAccess.ReadWrite)] public int HeatResistance => _heatResistance; + [DataField("ClothingPrefix")] private string _clothingEquippedPrefix; [ViewVariables(VVAccess.ReadWrite)] public string ClothingEquippedPrefix { - get - { - return _clothingEquippedPrefix; - } + get => _clothingEquippedPrefix; set { Dirty(); @@ -48,25 +49,6 @@ namespace Content.Server.GameObjects.Components.Items.Clothing } } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _clothingEquippedPrefix, "ClothingPrefix", null); - - // TODO: Writing. - serializer.DataReadFunction("Slots", new List(0), list => - { - foreach (var slotflagsloaded in list) - { - SlotFlags |= (SlotFlags)Enum.Parse(typeof(SlotFlags), slotflagsloaded.ToUpper()); - } - }); - - serializer.DataField(ref _quickEquipEnabled, "QuickEquip", true); - serializer.DataFieldCached(ref _heatResistance, "HeatResistance", 323); - } - public override ComponentState GetComponentState(ICommonSession player) { return new ClothingComponentState(ClothingEquippedPrefix, EquippedPrefix); diff --git a/Content.Server/GameObjects/Components/Items/DiceComponent.cs b/Content.Server/GameObjects/Components/Items/DiceComponent.cs index a2a251fca0..5c2417bde1 100644 --- a/Content.Server/GameObjects/Components/Items/DiceComponent.cs +++ b/Content.Server/GameObjects/Components/Items/DiceComponent.cs @@ -9,6 +9,7 @@ using Robust.Shared.Localization; using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -22,27 +23,30 @@ namespace Content.Server.GameObjects.Components.Items public override string Name => "Dice"; + [DataField("step")] private int _step = 1; private int _sides = 20; private int _currentSide = 20; [ViewVariables] + [DataField("diceSoundCollection")] public string _soundCollectionName = "dice"; [ViewVariables] public int Step => _step; [ViewVariables] - public int Sides => _sides; + [DataField("sides")] + public int Sides + { + get => _sides; + set + { + _sides = value; + _currentSide = value; + } + } + [ViewVariables] public int CurrentSide => _currentSide; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _step, "step", 1); - serializer.DataField(ref _sides, "sides", 20); - serializer.DataField(ref _soundCollectionName, "diceSoundCollection", "dice"); - _currentSide = _sides; - } - public void Roll() { _currentSide = _random.Next(1, (_sides/_step)+1) * _step; diff --git a/Content.Server/GameObjects/Components/Items/FloorTileItemComponent.cs b/Content.Server/GameObjects/Components/Items/FloorTileItemComponent.cs index be10b279fd..81d3941be8 100644 --- a/Content.Server/GameObjects/Components/Items/FloorTileItemComponent.cs +++ b/Content.Server/GameObjects/Components/Items/FloorTileItemComponent.cs @@ -11,6 +11,8 @@ using Robust.Shared.Serialization; using System.Collections.Generic; using System.Threading.Tasks; using Robust.Server.GameObjects; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Items { @@ -20,15 +22,9 @@ namespace Content.Server.GameObjects.Components.Items [Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!; public override string Name => "FloorTile"; + [DataField("outputs")] private List _outputTiles; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _outputTiles, "outputs", null); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Items/RCD/RCDAmmoComponent.cs b/Content.Server/GameObjects/Components/Items/RCD/RCDAmmoComponent.cs index 7c874a59a1..a5091e095b 100644 --- a/Content.Server/GameObjects/Components/Items/RCD/RCDAmmoComponent.cs +++ b/Content.Server/GameObjects/Components/Items/RCD/RCDAmmoComponent.cs @@ -6,7 +6,9 @@ using Content.Shared.Interfaces; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; using Robust.Shared.Localization; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -18,14 +20,7 @@ namespace Content.Server.GameObjects.Components.Items.RCD public override string Name => "RCDAmmo"; //How much ammo we refill - [ViewVariables(VVAccess.ReadWrite)] private int refillAmmo = 5; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref refillAmmo, "refillAmmo", 5); - } + [ViewVariables(VVAccess.ReadWrite)] [DataField("refillAmmo")] private int refillAmmo = 5; public void Examine(FormattedMessage message, bool inDetailsRange) { diff --git a/Content.Server/GameObjects/Components/Items/RCD/RCDComponent.cs b/Content.Server/GameObjects/Components/Items/RCD/RCDComponent.cs index 2771f6ae74..7cdc578015 100644 --- a/Content.Server/GameObjects/Components/Items/RCD/RCDComponent.cs +++ b/Content.Server/GameObjects/Components/Items/RCD/RCDComponent.cs @@ -13,7 +13,9 @@ using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Map; using Robust.Shared.Maths; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -30,9 +32,9 @@ namespace Content.Server.GameObjects.Components.Items.RCD public override string Name => "RCD"; private RcdMode _mode = 0; //What mode are we on? Can be floors, walls, deconstruct. private readonly RcdMode[] _modes = (RcdMode[]) Enum.GetValues(typeof(RcdMode)); - [ViewVariables(VVAccess.ReadWrite)] public int maxAmmo; + [ViewVariables(VVAccess.ReadWrite)] [DataField("maxAmmo")] public int maxAmmo = 5; public int _ammo; //How much "ammo" we have left. You can refill this with RCD ammo. - [ViewVariables(VVAccess.ReadWrite)] private float _delay; + [ViewVariables(VVAccess.ReadWrite)] [DataField("delay")] private float _delay = 2f; private DoAfterSystem doAfterSystem; @@ -45,14 +47,6 @@ namespace Content.Server.GameObjects.Components.Items.RCD Deconstruct } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref maxAmmo, "maxAmmo", 5); - serializer.DataField(ref _delay, "delay", 2f); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Items/Storage/EntityStorageComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/EntityStorageComponent.cs index 0f226dcdce..ce0e305540 100644 --- a/Content.Server/GameObjects/Components/Items/Storage/EntityStorageComponent.cs +++ b/Content.Server/GameObjects/Components/Items/Storage/EntityStorageComponent.cs @@ -18,7 +18,7 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Maths; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Timing; using Robust.Shared.ViewVariables; @@ -39,17 +39,35 @@ namespace Content.Server.GameObjects.Components.Items.Storage private TimeSpan _lastInternalOpenAttempt; [ViewVariables] - private int _storageCapacityMax; + [DataField("Capacity")] + private int _storageCapacityMax = 30; + [ViewVariables] + [DataField("IsCollidableWhenOpen")] private bool _isCollidableWhenOpen; + [ViewVariables] protected IEntityQuery? EntityQuery; + + [DataField("showContents")] private bool _showContents; - private bool _occludesLight; + + [DataField("occludesLight")] + private bool _occludesLight = true; + + [DataField("open")] private bool _open; - private bool _canWeldShut; + + [DataField("CanWeldShut")] + private bool _canWeldShut = true; + + [DataField("IsWeldedShut")] private bool _isWeldedShut; + + [DataField("closeSound")] private string _closeSound = "/Audio/Machines/closetclose.ogg"; + + [DataField("openSound")] private string _openSound = "/Audio/Machines/closetopen.ogg"; [ViewVariables] @@ -136,22 +154,6 @@ namespace Content.Server.GameObjects.Components.Items.Storage } } - /// - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _storageCapacityMax, "Capacity", 30); - serializer.DataField(ref _isCollidableWhenOpen, "IsCollidableWhenOpen", false); - serializer.DataField(ref _showContents, "showContents", false); - serializer.DataField(ref _occludesLight, "occludesLight", true); - serializer.DataField(ref _open, "open", false); - serializer.DataField(this, a => a.IsWeldedShut, "IsWeldedShut", false); - serializer.DataField(this, a => a.CanWeldShut, "CanWeldShut", true); - serializer.DataField(this, x => x._closeSound, "closeSound", "/Audio/Machines/closetclose.ogg"); - serializer.DataField(this, x => x._openSound, "openSound", "/Audio/Machines/closetopen.ogg"); - } - public virtual void Activate(ActivateEventArgs eventArgs) { ToggleOpen(eventArgs.User); diff --git a/Content.Server/GameObjects/Components/Items/Storage/ItemComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/ItemComponent.cs index da37b1240b..b4c15b8b14 100644 --- a/Content.Server/GameObjects/Components/Items/Storage/ItemComponent.cs +++ b/Content.Server/GameObjects/Components/Items/Storage/ItemComponent.cs @@ -14,7 +14,9 @@ using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Localization; using Robust.Shared.Players; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Items.Storage { @@ -27,6 +29,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage public override string Name => "Item"; public override uint? NetID => ContentNetIDs.ITEM; + [DataField("HeldPrefix")] private string _equippedPrefix; public string EquippedPrefix @@ -68,13 +71,6 @@ namespace Content.Server.GameObjects.Components.Items.Storage RemovedFromSlot(); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _equippedPrefix, "HeldPrefix", null); - } - public bool CanPickup(IEntity user) { if (!ActionBlockerSystem.CanPickup(user)) diff --git a/Content.Server/GameObjects/Components/Items/Storage/SecretStashComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/SecretStashComponent.cs index 46857cc2b8..d79c45a232 100644 --- a/Content.Server/GameObjects/Components/Items/Storage/SecretStashComponent.cs +++ b/Content.Server/GameObjects/Components/Items/Storage/SecretStashComponent.cs @@ -6,7 +6,7 @@ using Content.Shared.Interfaces; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Localization; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Items.Storage @@ -19,25 +19,21 @@ namespace Content.Server.GameObjects.Components.Items.Storage { public override string Name => "SecretStash"; - [ViewVariables] private int _maxItemSize; - [ViewVariables] private string? _secretPartName; + [ViewVariables] [DataField("maxItemSize")] + private int _maxItemSize = (int) ReferenceSizes.Pocket; + + [ViewVariables] [DataField("secretPartName")] + private readonly string? _secretPartNameOverride = null; [ViewVariables] private ContainerSlot _itemContainer = default!; - public string SecretPartName => _secretPartName ?? Loc.GetString("{0:theName}", Owner); + public string SecretPartName => _secretPartNameOverride ?? Loc.GetString("{0:theName}", Owner); public override void Initialize() { base.Initialize(); _itemContainer = ContainerHelpers.EnsureContainer(Owner, "stash", out _); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _maxItemSize, "maxItemSize", (int) ReferenceSizes.Pocket); - serializer.DataField(ref _secretPartName, "secretPartName", null); - } /// /// Tries to hide item inside secret stash from hands of user diff --git a/Content.Server/GameObjects/Components/Items/Storage/SecureEntityStorageComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/SecureEntityStorageComponent.cs index 42c9b3ed6d..b3b2fa4bd2 100644 --- a/Content.Server/GameObjects/Components/Items/Storage/SecureEntityStorageComponent.cs +++ b/Content.Server/GameObjects/Components/Items/Storage/SecureEntityStorageComponent.cs @@ -8,7 +8,10 @@ using Robust.Server.GameObjects; using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.Localization; +using Robust.Shared.Log; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Items.Storage @@ -20,7 +23,8 @@ namespace Content.Server.GameObjects.Components.Items.Storage public class SecureEntityStorageComponent : EntityStorageComponent { public override string Name => "SecureEntityStorage"; - private bool _locked; + [DataField("locked")] + private bool _locked = true; [ViewVariables(VVAccess.ReadWrite)] public bool Locked @@ -37,13 +41,6 @@ namespace Content.Server.GameObjects.Components.Items.Storage } } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _locked, "locked", true); - } - protected override void Startup() { base.Startup(); diff --git a/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs index 0c388a830f..18345093fb 100644 --- a/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs +++ b/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs @@ -23,7 +23,9 @@ using Robust.Shared.Log; using Robust.Shared.Map; using Robust.Shared.Network; using Robust.Shared.Players; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Items.Storage @@ -41,14 +43,19 @@ namespace Content.Server.GameObjects.Components.Items.Storage private Container? _storage; private readonly Dictionary _sizeCache = new(); - private bool _occludesLight; + [DataField("occludesLight")] + private bool _occludesLight = true; + [DataField("quickInsert")] private bool _quickInsert; //Can insert storables by "attacking" them with the storage entity + [DataField("areaInsert")] private bool _areaInsert; //"Attacking" with the storage entity causes it to insert all nearby storables after a delay private bool _storageInitialCalculated; private int _storageUsed; - private int _storageCapacityMax; + [DataField("capacity")] + private int _storageCapacityMax = 10000; public readonly HashSet SubscribedSessions = new(); + [DataField("storageSoundCollection")] public string? StorageSoundCollection { get; set; } [ViewVariables] @@ -355,18 +362,6 @@ namespace Content.Server.GameObjects.Components.Items.Storage _storage.OccludesLight = _occludesLight; } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _storageCapacityMax, "capacity", 10000); - serializer.DataField(ref _occludesLight, "occludesLight", true); - serializer.DataField(ref _quickInsert, "quickInsert", false); - serializer.DataField(ref _areaInsert, "areaInsert", false); - serializer.DataField(this, x => x.StorageSoundCollection, "storageSoundCollection", string.Empty); - //serializer.DataField(ref StorageUsed, "used", 0); - } - public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession? session = null) { base.HandleNetworkMessage(message, channel, session); diff --git a/Content.Server/GameObjects/Components/Items/Storage/StorageCounterComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/StorageCounterComponent.cs index 8ffd5d4375..1120352fba 100644 --- a/Content.Server/GameObjects/Components/Items/Storage/StorageCounterComponent.cs +++ b/Content.Server/GameObjects/Components/Items/Storage/StorageCounterComponent.cs @@ -8,6 +8,7 @@ using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Log; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Items.Storage { @@ -22,9 +23,12 @@ namespace Content.Server.GameObjects.Components.Items.Storage /// countTag: Cigarette # Note: field doesn't point to entity Id, but its tag /// [RegisterComponent] - public class StorageCounterComponent : Component + public class StorageCounterComponent : Component, ISerializationHooks { + [DataField("countTag")] private string? _countTag; + + [DataField("amount")] private int? _maxAmount; /// @@ -34,16 +38,12 @@ namespace Content.Server.GameObjects.Components.Items.Storage public override string Name => "StorageCounter"; - public override void ExposeData(ObjectSerializer serializer) + void ISerializationHooks.AfterDeserialization() { - base.ExposeData(serializer); - - serializer.DataField(ref _countTag, "countTag", null); if (_countTag == null) { Logger.Warning("StorageCounterComponent without a `countTag` is useless"); } - serializer.DataField(ref _maxAmount, "amount", null); } public override void HandleMessage(ComponentMessage message, IComponent? component) diff --git a/Content.Server/GameObjects/Components/Items/Storage/StorageFillComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/StorageFillComponent.cs index 5c9029db69..44a87e99bd 100644 --- a/Content.Server/GameObjects/Components/Items/Storage/StorageFillComponent.cs +++ b/Content.Server/GameObjects/Components/Items/Storage/StorageFillComponent.cs @@ -1,27 +1,24 @@ +#nullable enable using System; using System.Collections.Generic; -using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.IoC; +using Robust.Shared.Log; using Robust.Shared.Random; -using Robust.Shared.Serialization; -using Logger = Robust.Shared.Log.Logger; +using Robust.Shared.Serialization.Manager; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Items.Storage { [RegisterComponent] - internal sealed class StorageFillComponent : Component, IMapInit + public sealed class StorageFillComponent : Component, IMapInit { public override string Name => "StorageFill"; - private List _contents; + [DataField("contents")] + private List _contents = new(); - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _contents, "contents", new List()); - } + public IReadOnlyList Contents => _contents; void IMapInit.MapInit() { @@ -30,11 +27,12 @@ namespace Content.Server.GameObjects.Components.Items.Storage return; } - if (!Owner.TryGetComponent(out IStorageComponent storage)) + if (!Owner.TryGetComponent(out IStorageComponent? storage)) { Logger.Error($"StorageFillComponent couldn't find any StorageComponent ({Owner})"); return; } + var random = IoCManager.Resolve(); var alreadySpawnedGroups = new List(); @@ -58,19 +56,25 @@ namespace Content.Server.GameObjects.Components.Items.Storage } [Serializable] - private struct PrototypeItemData : IExposeData + [DataDefinition] + public struct StorageFillEntry : IPopulateDefaultValues { - public string PrototypeName; + [DataField("name")] + public string? PrototypeName; + + [DataField("prob")] public float SpawnProbability; + + [DataField("orGroup")] public string GroupId; + + [DataField("amount")] public int Amount; - void IExposeData.ExposeData(ObjectSerializer serializer) + public void PopulateDefaultValues() { - serializer.DataField(ref PrototypeName, "name", null); - serializer.DataField(ref Amount, "amount", 1); - serializer.DataField(ref SpawnProbability, "prob", 1f); - serializer.DataField(ref GroupId, "orGroup", null); + Amount = 1; + SpawnProbability = 1; } } } diff --git a/Content.Server/GameObjects/Components/Items/ToysComponent.cs b/Content.Server/GameObjects/Components/Items/ToysComponent.cs index 5d55567bd2..d123f56eaf 100644 --- a/Content.Server/GameObjects/Components/Items/ToysComponent.cs +++ b/Content.Server/GameObjects/Components/Items/ToysComponent.cs @@ -7,6 +7,7 @@ using Robust.Shared.IoC; using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Items @@ -20,14 +21,9 @@ namespace Content.Server.GameObjects.Components.Items public override string Name => "Toys"; [ViewVariables] + [DataField("toySqueak")] public string _soundCollectionName = "ToySqueak"; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _soundCollectionName, "toySqueak", "ToySqueak"); - } - public void Squeak() { PlaySqueakEffect(); diff --git a/Content.Server/GameObjects/Components/Kitchen/ButcherableComponent.cs b/Content.Server/GameObjects/Components/Kitchen/ButcherableComponent.cs index f785fba921..8a6fa76c03 100644 --- a/Content.Server/GameObjects/Components/Kitchen/ButcherableComponent.cs +++ b/Content.Server/GameObjects/Components/Kitchen/ButcherableComponent.cs @@ -1,6 +1,8 @@ #nullable enable using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Kitchen @@ -17,13 +19,8 @@ namespace Content.Server.GameObjects.Components.Kitchen public string? MeatPrototype => _meatPrototype; [ViewVariables] + [DataField("meat")] private string? _meatPrototype; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _meatPrototype, "meat", null); - } } } diff --git a/Content.Server/GameObjects/Components/Kitchen/JuiceableComponent.cs b/Content.Server/GameObjects/Components/Kitchen/JuiceableComponent.cs index bb4ae5a6a7..9e5f285bdf 100644 --- a/Content.Server/GameObjects/Components/Kitchen/JuiceableComponent.cs +++ b/Content.Server/GameObjects/Components/Kitchen/JuiceableComponent.cs @@ -1,6 +1,8 @@ using Content.Shared.Chemistry; using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Kitchen @@ -12,12 +14,6 @@ namespace Content.Server.GameObjects.Components.Kitchen public class JuiceableComponent : Component { public override string Name => "Juiceable"; - [ViewVariables] public Solution JuiceResultSolution; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(this, x => x.JuiceResultSolution, "result", new Solution()); - - } + [ViewVariables] [DataField("result")] public Solution JuiceResultSolution = new(); } } diff --git a/Content.Server/GameObjects/Components/Kitchen/KitchenSpikeComponent.cs b/Content.Server/GameObjects/Components/Kitchen/KitchenSpikeComponent.cs index f97a5cc723..88294a663c 100644 --- a/Content.Server/GameObjects/Components/Kitchen/KitchenSpikeComponent.cs +++ b/Content.Server/GameObjects/Components/Kitchen/KitchenSpikeComponent.cs @@ -7,10 +7,10 @@ using Content.Server.Interfaces.GameObjects; using Content.Server.Utility; using Content.Shared.Interfaces; using Content.Shared.Interfaces.GameObjects.Components; +using Content.Shared.Kitchen; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Localization; -using Content.Shared.GameObjects.Components.Kitchen; namespace Content.Server.GameObjects.Components.Kitchen { diff --git a/Content.Server/GameObjects/Components/Kitchen/MicrowaveComponent.cs b/Content.Server/GameObjects/Components/Kitchen/MicrowaveComponent.cs index 872e5bc886..d8339228c3 100644 --- a/Content.Server/GameObjects/Components/Kitchen/MicrowaveComponent.cs +++ b/Content.Server/GameObjects/Components/Kitchen/MicrowaveComponent.cs @@ -26,7 +26,7 @@ using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Kitchen @@ -38,11 +38,16 @@ namespace Content.Server.GameObjects.Components.Kitchen [Dependency] private readonly RecipeManager _recipeManager = default!; #region YAMLSERIALIZE - private int _cookTimeDefault; - private int _cookTimeMultiplier; //For upgrades and stuff I guess? - private string _badRecipeName = ""; - private string _startCookingSound = ""; - private string _cookingCompleteSound = ""; + [DataField("cookTime")] + private int _cookTimeDefault = 5; + [DataField("cookTimeMultiplier")] + private int _cookTimeMultiplier = 1000; //For upgrades and stuff I guess? + [DataField("failureResult")] + private string _badRecipeName = "FoodBadRecipe"; + [DataField("beginCookingSound")] + private string _startCookingSound = "/Audio/Machines/microwave_start_beep.ogg"; + [DataField("foodDoneSound")] + private string _cookingCompleteSound = "/Audio/Machines/microwave_done_beep.ogg"; #endregion [ViewVariables] @@ -68,16 +73,6 @@ namespace Content.Server.GameObjects.Components.Kitchen [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(MicrowaveUiKey.Key); - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _badRecipeName, "failureResult", "FoodBadRecipe"); - serializer.DataField(ref _cookTimeDefault, "cookTime", 5); - serializer.DataField(ref _cookTimeMultiplier, "cookTimeMultiplier", 1000); - serializer.DataField(ref _startCookingSound, "beginCookingSound","/Audio/Machines/microwave_start_beep.ogg" ); - serializer.DataField(ref _cookingCompleteSound, "foodDoneSound","/Audio/Machines/microwave_done_beep.ogg" ); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Kitchen/ReagentGrinderComponent.cs b/Content.Server/GameObjects/Components/Kitchen/ReagentGrinderComponent.cs index 5046f10925..3c54c414ab 100644 --- a/Content.Server/GameObjects/Components/Kitchen/ReagentGrinderComponent.cs +++ b/Content.Server/GameObjects/Components/Kitchen/ReagentGrinderComponent.cs @@ -19,7 +19,9 @@ using Robust.Shared.Audio; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Localization; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Kitchen @@ -64,15 +66,8 @@ namespace Content.Server.GameObjects.Components.Kitchen private bool _busy = false; //YAML serialization vars - [ViewVariables(VVAccess.ReadWrite)] private int _storageCap = 16; - [ViewVariables(VVAccess.ReadWrite)] private int _workTime = 3500; //3.5 seconds, completely arbitrary for now. - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _storageCap, "chamberCapacity", 16); - serializer.DataField(ref _workTime, "workTime", 3500); - } + [ViewVariables(VVAccess.ReadWrite)] [DataField("chamberCapacity")] private int _storageCap = 16; + [ViewVariables(VVAccess.ReadWrite)] [DataField("workTime")] private int _workTime = 3500; //3.5 seconds, completely arbitrary for now. public override void Initialize() { diff --git a/Content.Server/GameObjects/Components/MachineLinking/SignalReceiverComponent.cs b/Content.Server/GameObjects/Components/MachineLinking/SignalReceiverComponent.cs index 8b70ee18da..a269b7e8da 100644 --- a/Content.Server/GameObjects/Components/MachineLinking/SignalReceiverComponent.cs +++ b/Content.Server/GameObjects/Components/MachineLinking/SignalReceiverComponent.cs @@ -6,7 +6,10 @@ using Content.Shared.Interfaces; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; using Robust.Shared.Localization; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.Utility; namespace Content.Server.GameObjects.Components.MachineLinking { @@ -17,6 +20,7 @@ namespace Content.Server.GameObjects.Components.MachineLinking private List _transmitters; + [DataField("maxTransmitters")] private int? _maxTransmitters = default; public override void Initialize() @@ -26,11 +30,6 @@ namespace Content.Server.GameObjects.Components.MachineLinking _transmitters = new List(); } - public override void ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x=> x._maxTransmitters, "maxTransmitters", null); - } - public void DistributeSignal(T state) { foreach (var comp in Owner.GetAllComponents>()) diff --git a/Content.Server/GameObjects/Components/MachineLinking/SignalSwitchComponent.cs b/Content.Server/GameObjects/Components/MachineLinking/SignalSwitchComponent.cs index 01fbc8f6cf..8c1bd3c9d2 100644 --- a/Content.Server/GameObjects/Components/MachineLinking/SignalSwitchComponent.cs +++ b/Content.Server/GameObjects/Components/MachineLinking/SignalSwitchComponent.cs @@ -5,7 +5,9 @@ using Content.Shared.Interfaces.GameObjects.Components; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Localization; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.MachineLinking { @@ -14,6 +16,7 @@ namespace Content.Server.GameObjects.Components.MachineLinking { public override string Name => "SignalSwitch"; + [DataField("on")] private bool _on; public override void Initialize() @@ -23,13 +26,6 @@ namespace Content.Server.GameObjects.Components.MachineLinking UpdateSprite(); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _on, "on", true); - } - void IActivate.Activate(ActivateEventArgs eventArgs) { TransmitSignal(eventArgs.User); diff --git a/Content.Server/GameObjects/Components/MachineLinking/SignalTransmitterComponent.cs b/Content.Server/GameObjects/Components/MachineLinking/SignalTransmitterComponent.cs index bee6a01384..3472276fa0 100644 --- a/Content.Server/GameObjects/Components/MachineLinking/SignalTransmitterComponent.cs +++ b/Content.Server/GameObjects/Components/MachineLinking/SignalTransmitterComponent.cs @@ -7,23 +7,60 @@ using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; using Robust.Shared.Localization; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.MachineLinking { [RegisterComponent] - public class SignalTransmitterComponent : Component, IInteractUsing + public class SignalTransmitterComponent : Component, IInteractUsing, ISerializationHooks { public override string Name => "SignalTransmitter"; private List _unresolvedReceivers; - private List _receivers; - [ViewVariables] private float _range; + private List _receivers = new(); /// /// 0 is unlimited range /// - public float Range { get => _range; private set => _range = value; } + [ViewVariables] + [field: DataField("range")] + public float Range { get; private set; } = 10; + + [DataField("signalReceivers")] private List _receiverIds = new(); + + void ISerializationHooks.BeforeSerialization() + { + var entityList = new List(); + + foreach (var receiver in _receivers) + { + if (receiver.Deleted) + { + continue; + } + + entityList.Add(receiver.Owner.Uid); + } + + _receiverIds = entityList; + } + + void ISerializationHooks.AfterDeserialization() + { + _unresolvedReceivers = new List(); + + foreach (var id in _receiverIds) + { + if (!Owner.EntityManager.TryGetEntity(id, out var entity) || + !entity.TryGetComponent(out var receiver)) + { + continue; + } + + _unresolvedReceivers.Add(receiver); + } + } public override void Initialize() { @@ -41,47 +78,6 @@ namespace Content.Server.GameObjects.Components.MachineLinking } } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _range, "range", 10); - if (serializer.Reading) - { - if (!serializer.TryReadDataField("signalReceivers", out List entityUids)) - { - return; - } - - _unresolvedReceivers = new List(); - foreach (var entityUid in entityUids) - { - if (!Owner.EntityManager.TryGetEntity(entityUid, out var entity) - || !entity.TryGetComponent(out var receiver)) - { - continue; - } - - _unresolvedReceivers.Add(receiver); - } - } - else if (serializer.Writing) - { - var entityList = new List(); - foreach (var receiver in _receivers) - { - if (receiver.Deleted) - { - continue; - } - - entityList.Add(receiver.Owner.Uid); - } - - serializer.DataWriteFunction("signalReceivers", null, () => entityList); - } - } - public bool TransmitSignal(T signal) { if (_receivers.Count == 0) diff --git a/Content.Server/GameObjects/Components/MagbootsComponent.cs b/Content.Server/GameObjects/Components/MagbootsComponent.cs index 650185a05c..041793540d 100644 --- a/Content.Server/GameObjects/Components/MagbootsComponent.cs +++ b/Content.Server/GameObjects/Components/MagbootsComponent.cs @@ -16,7 +16,7 @@ using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Localization; using Robust.Shared.Players; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines; @@ -140,10 +140,9 @@ namespace Content.Server.GameObjects.Components } [UsedImplicitly] + [DataDefinition] public sealed class ToggleMagbootsAction : IToggleItemAction { - void IExposeData.ExposeData(ObjectSerializer serializer) { } - public bool DoToggleAction(ToggleItemActionEventArgs args) { if (!args.Item.TryGetComponent(out var magboots)) diff --git a/Content.Server/GameObjects/Components/Markers/ConditionalSpawnerComponent.cs b/Content.Server/GameObjects/Components/Markers/ConditionalSpawnerComponent.cs index 674bffeac5..f5ed93b73e 100644 --- a/Content.Server/GameObjects/Components/Markers/ConditionalSpawnerComponent.cs +++ b/Content.Server/GameObjects/Components/Markers/ConditionalSpawnerComponent.cs @@ -6,9 +6,11 @@ using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Log; +using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Reflection; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Markers @@ -23,12 +25,15 @@ namespace Content.Server.GameObjects.Components.Markers public override string Name => "ConditionalSpawner"; [ViewVariables(VVAccess.ReadWrite)] + [DataField("prototypes")] public List Prototypes { get; set; } = new(); [ViewVariables(VVAccess.ReadWrite)] + [DataField("gameRules")] private readonly List _gameRules = new(); [ViewVariables(VVAccess.ReadWrite)] + [DataField("chance")] public float Chance { get; set; } = 1.0f; public IEnumerable GameRules @@ -42,14 +47,6 @@ namespace Content.Server.GameObjects.Components.Markers } } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(this, x => x.Prototypes, "prototypes", new List()); - serializer.DataField(this, x => x.Chance, "chance", 1.0f); - serializer.DataField(this, x => x._gameRules, "gameRules", new List()); - } - private void RuleAdded(GameRuleAddedEventArgs obj) { if(_gameRules.Contains(obj.GameRule.GetType().Name)) diff --git a/Content.Server/GameObjects/Components/Markers/SpawnPointComponent.cs b/Content.Server/GameObjects/Components/Markers/SpawnPointComponent.cs index a2d145ec49..cfaa213625 100644 --- a/Content.Server/GameObjects/Components/Markers/SpawnPointComponent.cs +++ b/Content.Server/GameObjects/Components/Markers/SpawnPointComponent.cs @@ -4,6 +4,7 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Markers @@ -15,20 +16,14 @@ namespace Content.Server.GameObjects.Components.Markers [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [ViewVariables(VVAccess.ReadWrite)] - private SpawnPointType _spawnType; + [DataField("spawn_type")] + private SpawnPointType _spawnType = SpawnPointType.Unset; [ViewVariables(VVAccess.ReadWrite)] + [DataField("job_id")] private string _jobId; public SpawnPointType SpawnType => _spawnType; public JobPrototype Job => string.IsNullOrEmpty(_jobId) ? null : _prototypeManager.Index(_jobId); - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _spawnType, "spawn_type", SpawnPointType.Unset); - serializer.DataField(ref _jobId, "job_id", null); - } } public enum SpawnPointType diff --git a/Content.Server/GameObjects/Components/Markers/TimedSpawnerComponent.cs b/Content.Server/GameObjects/Components/Markers/TimedSpawnerComponent.cs index 6b870bf103..36a929dddd 100644 --- a/Content.Server/GameObjects/Components/Markers/TimedSpawnerComponent.cs +++ b/Content.Server/GameObjects/Components/Markers/TimedSpawnerComponent.cs @@ -5,34 +5,46 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Random; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Markers { [RegisterComponent] - public class TimedSpawnerComponent : Component + public class TimedSpawnerComponent : Component, ISerializationHooks { [Dependency] private readonly IRobustRandom _robustRandom = default!; public override string Name => "TimedSpawner"; [ViewVariables(VVAccess.ReadWrite)] + [DataField("prototypes")] public List Prototypes { get; set; } = new(); [ViewVariables(VVAccess.ReadWrite)] + [DataField("chance")] public float Chance { get; set; } = 1.0f; [ViewVariables(VVAccess.ReadWrite)] + [DataField("intervalSeconds")] public int IntervalSeconds { get; set; } = 60; [ViewVariables(VVAccess.ReadWrite)] + [DataField("MinimumEntitiesSpawned")] public int MinimumEntitiesSpawned { get; set; } = 1; [ViewVariables(VVAccess.ReadWrite)] + [DataField("MaximumEntitiesSpawned")] public int MaximumEntitiesSpawned { get; set; } = 1; private CancellationTokenSource TokenSource; + void ISerializationHooks.AfterDeserialization() + { + if (MinimumEntitiesSpawned > MaximumEntitiesSpawned) + throw new ArgumentException("MaximumEntitiesSpawned can't be lower than MinimumEntitiesSpawned!"); + } + public override void Initialize() { base.Initialize(); @@ -45,20 +57,6 @@ namespace Content.Server.GameObjects.Components.Markers TokenSource.Cancel(); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, x => x.Prototypes, "prototypes", new List()); - serializer.DataField(this, x => x.Chance, "chance", 1.0f); - serializer.DataField(this, x => x.IntervalSeconds, "intervalSeconds", 60); - serializer.DataField(this, x => x.MinimumEntitiesSpawned, "minimumEntitiesSpawned", 1); - serializer.DataField(this, x => x.MaximumEntitiesSpawned, "maximumEntitiesSpawned", 1); - - if(MinimumEntitiesSpawned > MaximumEntitiesSpawned) - throw new ArgumentException("MaximumEntitiesSpawned can't be lower than MinimumEntitiesSpawned!"); - } - private void SetupTimer() { TokenSource?.Cancel(); diff --git a/Content.Server/GameObjects/Components/Markers/TrashSpawnerComponent.cs b/Content.Server/GameObjects/Components/Markers/TrashSpawnerComponent.cs index 25ca65473b..e09cd10610 100644 --- a/Content.Server/GameObjects/Components/Markers/TrashSpawnerComponent.cs +++ b/Content.Server/GameObjects/Components/Markers/TrashSpawnerComponent.cs @@ -3,8 +3,10 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Maths; +using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Markers @@ -17,21 +19,17 @@ namespace Content.Server.GameObjects.Components.Markers public override string Name => "TrashSpawner"; [ViewVariables(VVAccess.ReadWrite)] + [DataField("rarePrototypes")] public List RarePrototypes { get; set; } = new(); [ViewVariables(VVAccess.ReadWrite)] + [DataField("rareChance")] public float RareChance { get; set; } = 0.05f; [ViewVariables(VVAccess.ReadWrite)] + [DataField("offset")] public float Offset { get; set; } = 0.2f; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(this, x => x.RarePrototypes, "rarePrototypes", new List()); - serializer.DataField(this, x => x.RareChance, "rareChance", 0.05f); - serializer.DataField(this, x => x.Offset, "offset", 0.2f); - } public override void Spawn() { if (RarePrototypes.Count > 0 && (RareChance == 1.0f || _robustRandom.Prob(RareChance))) diff --git a/Content.Server/GameObjects/Components/Markers/WarpPointComponent.cs b/Content.Server/GameObjects/Components/Markers/WarpPointComponent.cs index f67e91ab82..61a9f4cf74 100644 --- a/Content.Server/GameObjects/Components/Markers/WarpPointComponent.cs +++ b/Content.Server/GameObjects/Components/Markers/WarpPointComponent.cs @@ -1,7 +1,9 @@ using Content.Shared.GameObjects.EntitySystems; using Robust.Shared.GameObjects; using Robust.Shared.Localization; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -12,14 +14,7 @@ namespace Content.Server.GameObjects.Components.Markers { public override string Name => "WarpPoint"; - [ViewVariables(VVAccess.ReadWrite)] public string Location { get; set; } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, x => x.Location, "location", null); - } + [ViewVariables(VVAccess.ReadWrite)] [DataField("location")] public string Location { get; set; } public void Examine(FormattedMessage message, bool inDetailsRange) { diff --git a/Content.Server/GameObjects/Components/Medical/CloningPodComponent.cs b/Content.Server/GameObjects/Components/Medical/CloningPodComponent.cs index 52bcfb65b8..6be7d0566d 100644 --- a/Content.Server/GameObjects/Components/Medical/CloningPodComponent.cs +++ b/Content.Server/GameObjects/Components/Medical/CloningPodComponent.cs @@ -19,7 +19,9 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Maths; using Robust.Shared.Network; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Medical @@ -43,14 +45,8 @@ namespace Content.Server.GameObjects.Components.Medical private Mind? _capturedMind; private CloningPodStatus _status; private float _cloningProgress = 0; - private float _cloningTime; - - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _cloningTime, "cloningTime", 10f); - } + [DataField("cloningTime")] + private float _cloningTime = 10f; public override void Initialize() { diff --git a/Content.Server/GameObjects/Components/Medical/HealingComponent.cs b/Content.Server/GameObjects/Components/Medical/HealingComponent.cs index 56e265edf3..f6d7e00d9d 100644 --- a/Content.Server/GameObjects/Components/Medical/HealingComponent.cs +++ b/Content.Server/GameObjects/Components/Medical/HealingComponent.cs @@ -7,7 +7,9 @@ using Content.Shared.GameObjects.EntitySystems.ActionBlocker; using Content.Shared.Interfaces.GameObjects.Components; using Content.Shared.Utility; using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Medical { @@ -16,14 +18,7 @@ namespace Content.Server.GameObjects.Components.Medical { public override string Name => "Healing"; - public Dictionary Heal { get; private set; } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, h => h.Heal, "heal", new Dictionary()); - } + [DataField("heal")] public Dictionary Heal { get; private set; } = new(); async Task IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs) { diff --git a/Content.Server/GameObjects/Components/Metabolism/MetabolismComponent.cs b/Content.Server/GameObjects/Components/Metabolism/MetabolismComponent.cs index b79cc1c7a5..177be613a3 100644 --- a/Content.Server/GameObjects/Components/Metabolism/MetabolismComponent.cs +++ b/Content.Server/GameObjects/Components/Metabolism/MetabolismComponent.cs @@ -19,7 +19,7 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Metabolism @@ -38,78 +38,66 @@ namespace Content.Server.GameObjects.Components.Metabolism private bool _isShivering; private bool _isSweating; - [ViewVariables(VVAccess.ReadWrite)] private int _suffocationDamage; + [ViewVariables(VVAccess.ReadWrite)] [DataField("suffocationDamage")] private int _suffocationDamage = 1; - [ViewVariables(VVAccess.ReadWrite)] private int _suffocationDamageRecovery; + [ViewVariables(VVAccess.ReadWrite)] [DataField("suffocationDamageRecovery")] private int _suffocationDamageRecovery = 1; - [ViewVariables] public Dictionary NeedsGases { get; set; } = new(); + [ViewVariables] [DataField("needsGases")] public Dictionary NeedsGases { get; set; } = new(); - [ViewVariables] public Dictionary ProducesGases { get; set; } = new(); + [ViewVariables] [DataField("producesGases")] public Dictionary ProducesGases { get; set; } = new(); - [ViewVariables] public Dictionary DeficitGases { get; set; } = new(); + [ViewVariables] [DataField("deficitGases")] public Dictionary DeficitGases { get; set; } = new(); /// /// Heat generated due to metabolism. It's generated via metabolism /// [ViewVariables] + [DataField("metabolismHeat")] public float MetabolismHeat { get; private set; } /// /// Heat output via radiation. /// [ViewVariables] + [DataField("radiatedHeat")] public float RadiatedHeat { get; private set; } /// /// Maximum heat regulated via sweat /// [ViewVariables] + [DataField("sweatHeatRegulation")] public float SweatHeatRegulation { get; private set; } /// /// Maximum heat regulated via shivering /// [ViewVariables] + [DataField("shiveringHeatRegulation")] public float ShiveringHeatRegulation { get; private set; } /// /// Amount of heat regulation that represents thermal regulation processes not /// explicitly coded. /// + [DataField("implicitHeatRegulation")] public float ImplicitHeatRegulation { get; private set; } /// /// Normal body temperature /// [ViewVariables] + [DataField("normalBodyTemperature")] public float NormalBodyTemperature { get; private set; } /// /// Deviation from normal temperature for body to start thermal regulation /// + [DataField("thermalRegulationTemperatureThreshold")] public float ThermalRegulationTemperatureThreshold { get; private set; } [ViewVariables] public bool Suffocating { get; private set; } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, b => b.NeedsGases, "needsGases", new Dictionary()); - serializer.DataField(this, b => b.ProducesGases, "producesGases", new Dictionary()); - serializer.DataField(this, b => b.DeficitGases, "deficitGases", new Dictionary()); - serializer.DataField(this, b => b.MetabolismHeat, "metabolismHeat", 0); - serializer.DataField(this, b => b.RadiatedHeat, "radiatedHeat", 0); - serializer.DataField(this, b => b.SweatHeatRegulation, "sweatHeatRegulation", 0); - serializer.DataField(this, b => b.ShiveringHeatRegulation, "shiveringHeatRegulation", 0); - serializer.DataField(this, b => b.ImplicitHeatRegulation, "implicitHeatRegulation", 0); - serializer.DataField(this, b => b.NormalBodyTemperature, "normalBodyTemperature", 0); - serializer.DataField(this, b => b.ThermalRegulationTemperatureThreshold, - "thermalRegulationTemperatureThreshold", 0); - serializer.DataField(ref _suffocationDamage, "suffocationDamage", 1); - serializer.DataField(ref _suffocationDamageRecovery, "suffocationDamageRecovery", 1); - } - private Dictionary NeedsAndDeficit(float frameTime) { var needs = new Dictionary(NeedsGases); diff --git a/Content.Server/GameObjects/Components/Mining/PickaxeComponent.cs b/Content.Server/GameObjects/Components/Mining/PickaxeComponent.cs index 97172bfb7e..0b6acb5a97 100644 --- a/Content.Server/GameObjects/Components/Mining/PickaxeComponent.cs +++ b/Content.Server/GameObjects/Components/Mining/PickaxeComponent.cs @@ -1,5 +1,7 @@ using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Mining { @@ -8,14 +10,9 @@ namespace Content.Server.GameObjects.Components.Mining { public override string Name => "Pickaxe"; - public string MiningSound; - public float MiningSpeedMultiplier; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref MiningSound, "miningSound", "/Audio/Items/Mining/pickaxe.ogg"); - serializer.DataField(ref MiningSpeedMultiplier, "miningSpeedMultiplier", 1f); - } + [DataField("miningSound")] + public string MiningSound = "/Audio/Items/Mining/pickaxe.ogg"; + [DataField("miningSpeedMultiplier")] + public float MiningSpeedMultiplier = 1f; } } diff --git a/Content.Server/GameObjects/Components/Mobs/MindComponent.cs b/Content.Server/GameObjects/Components/Mobs/MindComponent.cs index 2f572b6a8d..60bba6a664 100644 --- a/Content.Server/GameObjects/Components/Mobs/MindComponent.cs +++ b/Content.Server/GameObjects/Components/Mobs/MindComponent.cs @@ -9,8 +9,8 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Map; -using Robust.Shared.Serialization; using Robust.Shared.Timing; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -22,6 +22,8 @@ namespace Content.Server.GameObjects.Components.Mobs [RegisterComponent] public class MindComponent : Component, IExamine { + [DataField("show_examine_info")] + private bool _showExamineInfo; /// public override string Name => "Mind"; @@ -42,13 +44,15 @@ namespace Content.Server.GameObjects.Components.Mobs /// Whether examining should show information about the mind or not. /// [ViewVariables(VVAccess.ReadWrite)] + [DataField("showExamineInfo")] public bool ShowExamineInfo { get; set; } /// /// Whether the mind will be put on a ghost after this component is shutdown. /// [ViewVariables(VVAccess.ReadWrite)] - public bool GhostOnShutdown { get; set; } + [DataField("ghostOnShutdown")] + public bool GhostOnShutdown { get; set; } = true; /// /// Don't call this unless you know what the hell you're doing. @@ -119,13 +123,6 @@ namespace Content.Server.GameObjects.Components.Mobs } } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(this, x => x.ShowExamineInfo, "showExamineInfo", false); - serializer.DataField(this, x => x.GhostOnShutdown, "ghostOnShutdown", true); - } - public void Examine(FormattedMessage message, bool inDetailsRange) { if (!ShowExamineInfo || !inDetailsRange) diff --git a/Content.Server/GameObjects/Components/Morgue/MorgueEntityStorageComponent.cs b/Content.Server/GameObjects/Components/Morgue/MorgueEntityStorageComponent.cs index 15b2830270..535f38b70c 100644 --- a/Content.Server/GameObjects/Components/Morgue/MorgueEntityStorageComponent.cs +++ b/Content.Server/GameObjects/Components/Morgue/MorgueEntityStorageComponent.cs @@ -13,7 +13,9 @@ using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Localization; using Robust.Shared.Maths; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -28,6 +30,7 @@ namespace Content.Server.GameObjects.Components.Morgue public override string Name => "MorgueEntityStorage"; [ViewVariables(VVAccess.ReadWrite)] + [DataField("trayPrototype")] private string? _trayPrototypeId; [ViewVariables] @@ -37,6 +40,7 @@ namespace Content.Server.GameObjects.Components.Morgue public ContainerSlot? TrayContainer { get; private set; } [ViewVariables(VVAccess.ReadWrite)] + [DataField("doSoulBeep")] public bool DoSoulBeep = true; [ViewVariables] @@ -50,14 +54,6 @@ namespace Content.Server.GameObjects.Components.Morgue TrayContainer = ContainerHelpers.EnsureContainer(Owner, "morgue_tray", out _); } - /// - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _trayPrototypeId, "trayPrototype", ""); - serializer.DataField(ref DoSoulBeep, "doSoulBeep", true); - } - public override Vector2 ContentsDumpPosition() { if (_tray != null) return _tray.Transform.WorldPosition; diff --git a/Content.Server/GameObjects/Components/Movement/AiControllerComponent.cs b/Content.Server/GameObjects/Components/Movement/AiControllerComponent.cs index e846046e46..fdacd95bb7 100644 --- a/Content.Server/GameObjects/Components/Movement/AiControllerComponent.cs +++ b/Content.Server/GameObjects/Components/Movement/AiControllerComponent.cs @@ -1,6 +1,4 @@ #nullable enable -using Content.Server.AI.Utility.AiLogic; -using Content.Server.GameObjects.EntitySystems.AI; using Content.Server.Interfaces.GameTicking; using Content.Shared.GameObjects.Components.Movement; using Content.Shared.Roles; @@ -9,7 +7,7 @@ using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Movement @@ -17,11 +15,12 @@ namespace Content.Server.GameObjects.Components.Movement [RegisterComponent, ComponentReference(typeof(IMoverComponent))] public class AiControllerComponent : Component, IMoverComponent { - private float _visionRadius; + [DataField("logic")] private float _visionRadius = 8.0f; public override string Name => "AiController"; [ViewVariables(VVAccess.ReadWrite)] + [DataField("startingGear")] public string? StartingGearPrototype { get; set; } [ViewVariables(VVAccess.ReadWrite)] @@ -54,19 +53,6 @@ namespace Content.Server.GameObjects.Components.Movement } } - /// - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataReadWriteFunction( - "startingGear", - null, - startingGear => StartingGearPrototype = startingGear, - () => StartingGearPrototype); - serializer.DataField(ref _visionRadius, "vision", 8.0f); - } - /// /// Movement speed (m/s) that the entity walks, after modifiers /// diff --git a/Content.Server/GameObjects/Components/Movement/ClimbableComponent.cs b/Content.Server/GameObjects/Components/Movement/ClimbableComponent.cs index bc85f07eb5..1ba64a3f7e 100644 --- a/Content.Server/GameObjects/Components/Movement/ClimbableComponent.cs +++ b/Content.Server/GameObjects/Components/Movement/ClimbableComponent.cs @@ -13,7 +13,7 @@ using Robust.Shared.GameObjects; using Robust.Shared.Localization; using Robust.Shared.Log; using Robust.Shared.Maths; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Movement @@ -26,7 +26,8 @@ namespace Content.Server.GameObjects.Components.Movement /// The time it takes to climb onto the entity. /// [ViewVariables] - private float _climbDelay; + [DataField("delay")] + private float _climbDelay = 0.8f; public override void Initialize() { @@ -38,13 +39,6 @@ namespace Content.Server.GameObjects.Components.Movement } } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _climbDelay, "delay", 0.8f); - } - public override bool CanDragDropOn(DragDropEventArgs eventArgs) { if (!base.CanDragDropOn(eventArgs)) diff --git a/Content.Server/GameObjects/Components/Movement/ShuttleControllerComponent.cs b/Content.Server/GameObjects/Components/Movement/ShuttleControllerComponent.cs index 5cdadde4cd..07a4d06cc5 100644 --- a/Content.Server/GameObjects/Components/Movement/ShuttleControllerComponent.cs +++ b/Content.Server/GameObjects/Components/Movement/ShuttleControllerComponent.cs @@ -10,7 +10,9 @@ using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Map; using Robust.Shared.Maths; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Movement @@ -29,7 +31,8 @@ namespace Content.Server.GameObjects.Components.Movement /// /// ID of the alert to show when piloting /// - private AlertType _pilotingAlertType; + [DataField("pilotingAlertType")] + private AlertType _pilotingAlertType = AlertType.PilotingShuttle; /// /// The entity that's currently controlling this component. @@ -203,13 +206,6 @@ namespace Content.Server.GameObjects.Components.Movement } } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _pilotingAlertType, "pilotingAlertType", AlertType.PilotingShuttle); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Movement/SlipperyComponent.cs b/Content.Server/GameObjects/Components/Movement/SlipperyComponent.cs index 006b24b684..13914e77ca 100644 --- a/Content.Server/GameObjects/Components/Movement/SlipperyComponent.cs +++ b/Content.Server/GameObjects/Components/Movement/SlipperyComponent.cs @@ -3,7 +3,7 @@ using Content.Shared.GameObjects.Components.Movement; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Players; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Movement @@ -22,6 +22,7 @@ namespace Content.Server.GameObjects.Components.Movement /// Path to the sound to be played when a mob slips. /// [ViewVariables] + [DataField("slipSound")] private string SlipSound { get; set; } = "/Audio/Effects/slip.ogg"; /// @@ -87,13 +88,6 @@ namespace Content.Server.GameObjects.Components.Movement set => _launchForwardsMultiplier = value; } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, x => x.SlipSound, "slipSound", "/Audio/Effects/slip.ogg"); - } - protected override void OnSlip() { if (!string.IsNullOrEmpty(SlipSound)) diff --git a/Content.Server/GameObjects/Components/NodeContainer/NodeContainerComponent.cs b/Content.Server/GameObjects/Components/NodeContainer/NodeContainerComponent.cs index 8d8827837f..c6d7152fa5 100644 --- a/Content.Server/GameObjects/Components/NodeContainer/NodeContainerComponent.cs +++ b/Content.Server/GameObjects/Components/NodeContainer/NodeContainerComponent.cs @@ -5,8 +5,10 @@ using Content.Server.GameObjects.Components.NodeContainer.Nodes; using Content.Shared.GameObjects.EntitySystems; using Robust.Shared.GameObjects; using Robust.Shared.Localization; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; using Robust.Shared.Utility; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.NodeContainer @@ -21,16 +23,11 @@ namespace Content.Server.GameObjects.Components.NodeContainer [ViewVariables] public IReadOnlyList Nodes => _nodes; + [DataField("nodes")] private List _nodes = new(); + [DataField("examinable")] private bool _examinable; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _nodes, "nodes", new List()); - serializer.DataField(ref _examinable, "examinable", false); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/NodeContainer/Nodes/AdjacentNode.cs b/Content.Server/GameObjects/Components/NodeContainer/Nodes/AdjacentNode.cs index a5ce141a19..dc2ab8c666 100644 --- a/Content.Server/GameObjects/Components/NodeContainer/Nodes/AdjacentNode.cs +++ b/Content.Server/GameObjects/Components/NodeContainer/Nodes/AdjacentNode.cs @@ -1,12 +1,14 @@ #nullable enable using System.Collections.Generic; using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.NodeContainer.Nodes { /// /// A that can reach other s that are directly adjacent to it. /// + [DataDefinition] public class AdjacentNode : Node { protected override IEnumerable GetReachableNodes() diff --git a/Content.Server/GameObjects/Components/NodeContainer/Nodes/Node.cs b/Content.Server/GameObjects/Components/NodeContainer/Nodes/Node.cs index 2c0fa4ec10..a326c1d663 100644 --- a/Content.Server/GameObjects/Components/NodeContainer/Nodes/Node.cs +++ b/Content.Server/GameObjects/Components/NodeContainer/Nodes/Node.cs @@ -5,7 +5,7 @@ using System.Linq; using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.NodeContainer.Nodes @@ -14,14 +14,16 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes /// Organizes themselves into distinct s with other s /// that they can "reach" and have the same . /// - public abstract class Node : IExposeData + [ImplicitDataDefinitionForInheritors] + public abstract class Node { /// /// An ID used as a criteria for combining into groups. Determines which /// implementation is used as a group, detailed in . /// [ViewVariables] - public NodeGroupID NodeGroupID { get; private set; } + [DataField("nodeGroupID")] + public NodeGroupID NodeGroupID { get; private set; } = NodeGroupID.Default; [ViewVariables] public INodeGroup NodeGroup { get => _nodeGroup; set => SetNodeGroup(value); } @@ -43,12 +45,7 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes /// /// Prevents a node from being used by other nodes while midway through removal. /// - private bool _deleting = false; - - public virtual void ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.NodeGroupID, "nodeGroupID", NodeGroupID.Default); - } + private bool _deleting; public virtual void Initialize(IEntity owner) { diff --git a/Content.Server/GameObjects/Components/NodeContainer/Nodes/PipeNode.cs b/Content.Server/GameObjects/Components/NodeContainer/Nodes/PipeNode.cs index b3361503db..c4d5ce4b55 100644 --- a/Content.Server/GameObjects/Components/NodeContainer/Nodes/PipeNode.cs +++ b/Content.Server/GameObjects/Components/NodeContainer/Nodes/PipeNode.cs @@ -7,7 +7,7 @@ using Content.Shared.GameObjects.Components.Atmos; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Maths; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.NodeContainer.Nodes @@ -16,6 +16,7 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes /// Connects with other s whose /// correctly correspond. /// + [DataDefinition] public class PipeNode : Node, IGasMixtureHolder, IRotatableNode { /// @@ -30,6 +31,7 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes /// Used to check if this pipe can connect to another pipe in a given direction. /// [ViewVariables] + [DataField("pipeDirection")] public PipeDirection PipeDirection { get; private set; } /// @@ -80,7 +82,8 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes /// Only for usage by s. /// [ViewVariables] - public GasMixture LocalAir { get; set; } = default!; + [DataField("gasMixture")] + public GasMixture LocalAir { get; set; } = new(DefaultVolume); [ViewVariables] public float Volume => LocalAir.Volume; @@ -89,13 +92,6 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes private const float DefaultVolume = 1; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(this, x => x.PipeDirection, "pipeDirection", PipeDirection.None); - serializer.DataField(this, x => x.LocalAir, "gasMixture", new GasMixture(DefaultVolume)); - } - public override void Initialize(IEntity owner) { base.Initialize(owner); diff --git a/Content.Server/GameObjects/Components/Nutrition/DrinkComponent.cs b/Content.Server/GameObjects/Components/Nutrition/DrinkComponent.cs index db16790c8f..76744aaea9 100644 --- a/Content.Server/GameObjects/Components/Nutrition/DrinkComponent.cs +++ b/Content.Server/GameObjects/Components/Nutrition/DrinkComponent.cs @@ -20,7 +20,7 @@ using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Prototypes; using Robust.Shared.Random; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -40,9 +40,11 @@ namespace Content.Server.GameObjects.Components.Nutrition private bool _opened; [ViewVariables] - private string _useSound = string.Empty; + [DataField("useSound")] + private string _useSound = "/Audio/Items/drink.ogg"; [ViewVariables] + [DataField("isOpen")] private bool _defaultToOpened; [ViewVariables(VVAccess.ReadWrite)] @@ -67,19 +69,12 @@ namespace Content.Server.GameObjects.Components.Nutrition [ViewVariables] public bool Empty => Owner.GetComponentOrNull()?.DrainAvailable <= 0; - private string _soundCollection = string.Empty; - private bool _pressurized; - private string _burstSound = string.Empty; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _useSound, "useSound", "/Audio/Items/drink.ogg"); - serializer.DataField(ref _defaultToOpened, "isOpen", false); // For things like cups of coffee. - serializer.DataField(ref _soundCollection, "openSounds", "canOpenSounds"); - serializer.DataField(ref _pressurized, "pressurized", false); - serializer.DataField(ref _burstSound, "burstSound", "/Audio/Effects/flash_bang.ogg"); - } + [DataField("openSounds")] + private string _soundCollection = "canOpenSounds"; + [DataField("pressurized")] + private bool _pressurized = default; + [DataField("burstSound")] + private string _burstSound = "/Audio/Effects/flash_bang.ogg"; public override void Initialize() { diff --git a/Content.Server/GameObjects/Components/Nutrition/FoodComponent.cs b/Content.Server/GameObjects/Components/Nutrition/FoodComponent.cs index f1f5d10620..cadf507a7d 100644 --- a/Content.Server/GameObjects/Components/Nutrition/FoodComponent.cs +++ b/Content.Server/GameObjects/Components/Nutrition/FoodComponent.cs @@ -5,9 +5,9 @@ using System.Linq; using System.Threading.Tasks; using Content.Server.GameObjects.Components.Body.Behavior; using Content.Server.GameObjects.Components.Chemistry; +using Content.Server.GameObjects.Components.Culinary; using Content.Server.GameObjects.Components.GUI; using Content.Server.GameObjects.Components.Items.Storage; -using Content.Server.GameObjects.Components.Culinary; using Content.Shared.Chemistry; using Content.Shared.GameObjects.Components.Body; using Content.Shared.Interfaces; @@ -18,23 +18,26 @@ using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; -using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Nutrition { [RegisterComponent] + [ComponentReference(typeof(IAfterInteract))] public class FoodComponent : Component, IUse, IAfterInteract { [Dependency] private readonly IEntitySystemManager _entitySystem = default!; public override string Name => "Food"; - [ViewVariables] private string _useSound = ""; - [ViewVariables] private string? _trashPrototype; - [ViewVariables] private ReagentUnit _transferAmount; - private UtensilType _utensilsNeeded; + [ViewVariables] [DataField("useSound")] protected virtual string UseSound { get; set; } = "/Audio/Items/eatfood.ogg"; + + [ViewVariables] [DataField("trash")] protected virtual string? TrashPrototype { get; set; } + + [ViewVariables] [DataField("transferAmount")] protected virtual ReagentUnit TransferAmount { get; set; } = ReagentUnit.New(5); + + [DataField("utensilsNeeded")] private UtensilType _utensilsNeeded = UtensilType.None; [ViewVariables] public int UsesRemaining @@ -48,38 +51,10 @@ namespace Content.Server.GameObjects.Components.Nutrition return solution.CurrentVolume == 0 ? 0 - : Math.Max(1, (int)Math.Ceiling((solution.CurrentVolume / _transferAmount).Float())); + : Math.Max(1, (int)Math.Ceiling((solution.CurrentVolume / TransferAmount).Float())); } } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _useSound, "useSound", "/Audio/Items/eatfood.ogg"); - serializer.DataField(ref _transferAmount, "transferAmount", ReagentUnit.New(5)); - serializer.DataField(ref _trashPrototype, "trash", null); - - serializer.DataReadWriteFunction( - "utensils", - new List(), - types => types.ForEach(type => _utensilsNeeded |= type), - () => - { - var types = new List(); - - foreach (var type in (UtensilType[]) Enum.GetValues(typeof(UtensilType))) - { - if ((_utensilsNeeded & type) != 0) - { - types.Add(type); - } - } - - return types; - }); - } - public override void Initialize() { base.Initialize(); @@ -170,7 +145,7 @@ namespace Content.Server.GameObjects.Components.Nutrition return false; } - var transferAmount = ReagentUnit.Min(_transferAmount, solution.CurrentVolume); + var transferAmount = ReagentUnit.Min(TransferAmount, solution.CurrentVolume); var split = solution.SplitSolution(transferAmount); var firstStomach = stomachs.FirstOrDefault(stomach => stomach.CanTransferSolution(split)); @@ -187,7 +162,7 @@ namespace Content.Server.GameObjects.Components.Nutrition firstStomach.TryTransferSolution(split); _entitySystem.GetEntitySystem() - .PlayFromEntity(_useSound, trueTarget, AudioParams.Default.WithVolume(-1f)); + .PlayFromEntity(UseSound, trueTarget, AudioParams.Default.WithVolume(-1f)); trueTarget.PopupMessage(user, Loc.GetString("Nom")); // If utensils were used @@ -204,7 +179,7 @@ namespace Content.Server.GameObjects.Components.Nutrition return true; } - if (string.IsNullOrEmpty(_trashPrototype)) + if (string.IsNullOrEmpty(TrashPrototype)) { Owner.Delete(); return true; @@ -212,7 +187,7 @@ namespace Content.Server.GameObjects.Components.Nutrition //We're empty. Become trash. var position = Owner.Transform.Coordinates; - var finisher = Owner.EntityManager.SpawnEntity(_trashPrototype, position); + var finisher = Owner.EntityManager.SpawnEntity(TrashPrototype, position); // If the user is holding the item if (user.TryGetComponent(out HandsComponent? handsComponent) && diff --git a/Content.Server/GameObjects/Components/Nutrition/FoodContainerComponent.cs b/Content.Server/GameObjects/Components/Nutrition/FoodContainerComponent.cs index fd2aa64b78..6f7c430e6d 100644 --- a/Content.Server/GameObjects/Components/Nutrition/FoodContainerComponent.cs +++ b/Content.Server/GameObjects/Components/Nutrition/FoodContainerComponent.cs @@ -8,7 +8,9 @@ using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Random; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Nutrition @@ -25,8 +27,10 @@ namespace Content.Server.GameObjects.Components.Nutrition public override string Name => "FoodContainer"; private AppearanceComponent _appearance; - private Dictionary _prototypes; - private uint _capacity; + [DataField("prototypes")] + private Dictionary _prototypes = default; + [DataField("capacity")] + private uint _capacity = 5; public int Capacity => (int)_capacity; [ViewVariables] @@ -34,13 +38,6 @@ namespace Content.Server.GameObjects.Components.Nutrition private int _count = 0; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _prototypes, "prototypes", null); - serializer.DataField(ref _capacity, "capacity", 5); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Nutrition/HungerComponent.cs b/Content.Server/GameObjects/Components/Nutrition/HungerComponent.cs index 7d0c858817..1ee8c10809 100644 --- a/Content.Server/GameObjects/Components/Nutrition/HungerComponent.cs +++ b/Content.Server/GameObjects/Components/Nutrition/HungerComponent.cs @@ -12,7 +12,9 @@ using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Players; using Robust.Shared.Random; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Nutrition @@ -29,7 +31,8 @@ namespace Content.Server.GameObjects.Components.Nutrition get => _baseDecayRate; set => _baseDecayRate = value; } - private float _baseDecayRate; + [DataField("base_decay_rate")] + private float _baseDecayRate = 0.1f; [ViewVariables(VVAccess.ReadWrite)] public float ActualDecayRate @@ -65,13 +68,6 @@ namespace Content.Server.GameObjects.Components.Nutrition {HungerThreshold.Dead, 0.0f}, }; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _baseDecayRate, "base_decay_rate", 0.1f); - } - - public static readonly Dictionary HungerThresholdAlertTypes = new() { { HungerThreshold.Overfed, AlertType.Overfed }, diff --git a/Content.Server/GameObjects/Components/Nutrition/SmokingComponent.cs b/Content.Server/GameObjects/Components/Nutrition/SmokingComponent.cs index 361d59c851..eced150ed7 100644 --- a/Content.Server/GameObjects/Components/Nutrition/SmokingComponent.cs +++ b/Content.Server/GameObjects/Components/Nutrition/SmokingComponent.cs @@ -6,6 +6,7 @@ using Content.Shared.Interfaces.GameObjects.Components; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Nutrition @@ -37,7 +38,8 @@ namespace Content.Server.GameObjects.Components.Nutrition /// Generally it ticks down whether it's time-based /// or consumption-based. /// - [ViewVariables] private int _duration; + [ViewVariables] [DataField("duration")] + private int _duration = 30; /// /// What is the temperature of the cigar? @@ -45,7 +47,8 @@ namespace Content.Server.GameObjects.Components.Nutrition /// For a regular cigar, the temp approaches around 400°C or 580°C /// dependant on where you measure. /// - [ViewVariables] private float _temperature; + [ViewVariables] [DataField("temperature")] + private float _temperature = 673.15f; [ViewVariables] private SharedBurningStates CurrentState @@ -74,13 +77,6 @@ namespace Content.Server.GameObjects.Components.Nutrition } } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _duration, "duration", 30); - serializer.DataField(ref _temperature, "temperature", 673.15f); - } - async Task IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { if (eventArgs.Using.TryGetComponent(out IHotItem? lighter) diff --git a/Content.Server/GameObjects/Components/Nutrition/ThirstComponent.cs b/Content.Server/GameObjects/Components/Nutrition/ThirstComponent.cs index d447eb83df..134d851aa8 100644 --- a/Content.Server/GameObjects/Components/Nutrition/ThirstComponent.cs +++ b/Content.Server/GameObjects/Components/Nutrition/ThirstComponent.cs @@ -12,7 +12,9 @@ using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Players; using Robust.Shared.Random; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Nutrition @@ -29,7 +31,8 @@ namespace Content.Server.GameObjects.Components.Nutrition get => _baseDecayRate; set => _baseDecayRate = value; } - private float _baseDecayRate; + [DataField("base_decay_rate")] + private float _baseDecayRate = 0.1f; [ViewVariables(VVAccess.ReadWrite)] public float ActualDecayRate @@ -71,12 +74,6 @@ namespace Content.Server.GameObjects.Components.Nutrition {ThirstThreshold.Parched, AlertType.Parched}, }; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _baseDecayRate, "base_decay_rate", 0.1f); - } - public void ThirstThresholdEffect(bool force = false) { if (_currentThirstThreshold != _lastThirstThreshold || force) diff --git a/Content.Server/GameObjects/Components/Observer/GhostOnMoveComponent.cs b/Content.Server/GameObjects/Components/Observer/GhostOnMoveComponent.cs index 3a21cb8cd3..5876280f0d 100644 --- a/Content.Server/GameObjects/Components/Observer/GhostOnMoveComponent.cs +++ b/Content.Server/GameObjects/Components/Observer/GhostOnMoveComponent.cs @@ -8,7 +8,7 @@ using Robust.Shared.Console; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Players; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Observer { @@ -18,14 +18,7 @@ namespace Content.Server.GameObjects.Components.Observer { public override string Name => "GhostOnMove"; - public bool CanReturn { get; set; } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, x => x.CanReturn, "canReturn", true); - } + [DataField("canReturn")] public bool CanReturn { get; set; } = true; void IRelayMoveInput.MoveInputPressed(ICommonSession session) { diff --git a/Content.Server/GameObjects/Components/Observer/GhostRoles/GhostRoleComponent.cs b/Content.Server/GameObjects/Components/Observer/GhostRoles/GhostRoleComponent.cs index b768a081eb..e4e8f41483 100644 --- a/Content.Server/GameObjects/Components/Observer/GhostRoles/GhostRoleComponent.cs +++ b/Content.Server/GameObjects/Components/Observer/GhostRoles/GhostRoleComponent.cs @@ -1,15 +1,16 @@ using Content.Server.GameObjects.EntitySystems; using Robust.Server.Player; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Observer.GhostRoles { public abstract class GhostRoleComponent : Component { - private string _roleName; - private string _roleDescription; + [DataField("name")] private string _roleName = "Unknown"; + + [DataField("description")] private string _roleDescription = "Unknown"; // We do this so updating RoleName and RoleDescription in VV updates the open EUIs. @@ -41,14 +42,6 @@ namespace Content.Server.GameObjects.Components.Observer.GhostRoles [ViewVariables] public uint Identifier { get; set; } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _roleName, "name", "Unknown"); - serializer.DataField(ref _roleDescription, "description", "Unknown"); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Observer/GhostRoles/GhostRoleMobSpawnerComponent.cs b/Content.Server/GameObjects/Components/Observer/GhostRoles/GhostRoleMobSpawnerComponent.cs index db9e0ceb11..3f55db9d3e 100644 --- a/Content.Server/GameObjects/Components/Observer/GhostRoles/GhostRoleMobSpawnerComponent.cs +++ b/Content.Server/GameObjects/Components/Observer/GhostRoles/GhostRoleMobSpawnerComponent.cs @@ -5,7 +5,7 @@ using Content.Server.Players; using JetBrains.Annotations; using Robust.Server.Player; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Observer.GhostRoles @@ -18,30 +18,22 @@ namespace Content.Server.GameObjects.Components.Observer.GhostRoles { public override string Name => "GhostRoleMobSpawner"; - - [ViewVariables(VVAccess.ReadWrite)] + [ViewVariables(VVAccess.ReadWrite)] [DataField("deleteOnSpawn")] private bool _deleteOnSpawn = true; - [ViewVariables(VVAccess.ReadWrite)] + [ViewVariables(VVAccess.ReadWrite)] [DataField("makeSentient")] private bool _makeSentient = true; - [ViewVariables(VVAccess.ReadWrite)] + [ViewVariables(VVAccess.ReadWrite)] [DataField("availableTakeovers")] private int _availableTakeovers = 1; [ViewVariables] private int _currentTakeovers = 0; - [CanBeNull, ViewVariables(VVAccess.ReadWrite)] public string Prototype { get; private set; } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, x => x.Prototype, "prototype", null); - serializer.DataField(ref _deleteOnSpawn, "deleteOnSpawn", true); - serializer.DataField(ref _makeSentient, "makeSentient", true); - serializer.DataField(ref _availableTakeovers, "availableTakeovers", 1); - } + [CanBeNull] + [ViewVariables(VVAccess.ReadWrite)] + [DataField("prototype")] + public string Prototype { get; private set; } public override bool Take(IPlayerSession session) { diff --git a/Content.Server/GameObjects/Components/PA/ParticleAcceleratorControlBoxComponent.cs b/Content.Server/GameObjects/Components/PA/ParticleAcceleratorControlBoxComponent.cs index 36bc1037aa..d1d55561f3 100644 --- a/Content.Server/GameObjects/Components/PA/ParticleAcceleratorControlBoxComponent.cs +++ b/Content.Server/GameObjects/Components/PA/ParticleAcceleratorControlBoxComponent.cs @@ -16,7 +16,9 @@ using Robust.Shared.GameObjects; using Robust.Shared.Localization; using Robust.Shared.Log; using Robust.Shared.Maths; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; using static Content.Shared.GameObjects.Components.SharedWiresComponent; @@ -68,10 +70,20 @@ namespace Content.Server.GameObjects.Components.PA /// /// Delay between consecutive PA shots. /// - [ViewVariables(VVAccess.ReadWrite)] private TimeSpan _firingDelay; + // Fun fact: + // On /vg/station (can't check TG because lol they removed singulo), + // the PA emitter parts have var/fire_delay = 50. + // For anybody from the future not BYOND-initiated, that's 5 seconds. + // However, /obj/machinery/particle_accelerator/control_box/process(), + // which calls emit_particle() on the emitters, + // only gets called every *2* seconds, because of CarnMC timing. + // So the *actual* effective firing delay of the PA is 6 seconds, not 5 as listed in the code. + // So... + // I have reflected that here to be authentic. + [ViewVariables(VVAccess.ReadWrite)] [DataField("fireDelay")] private TimeSpan _firingDelay = TimeSpan.FromSeconds(6); - [ViewVariables(VVAccess.ReadWrite)] private int _powerDrawBase; - [ViewVariables(VVAccess.ReadWrite)] private int _powerDrawMult; + [ViewVariables(VVAccess.ReadWrite)] [DataField("powerDrawBase")] private int _powerDrawBase = 500; + [ViewVariables(VVAccess.ReadWrite)] [DataField("powerDrawMult")] private int _powerDrawMult = 1500; [ViewVariables] private bool ConsolePowered => _powerReceiverComponent?.Powered ?? true; @@ -84,25 +96,6 @@ namespace Content.Server.GameObjects.Components.PA ? ParticleAcceleratorPowerState.Level3 : ParticleAcceleratorPowerState.Level2; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - // Fun fact: - // On /vg/station (can't check TG because lol they removed singulo), - // the PA emitter parts have var/fire_delay = 50. - // For anybody from the future not BYOND-initiated, that's 5 seconds. - // However, /obj/machinery/particle_accelerator/control_box/process(), - // which calls emit_particle() on the emitters, - // only gets called every *2* seconds, because of CarnMC timing. - // So the *actual* effective firing delay of the PA is 6 seconds, not 5 as listed in the code. - // So... - // I have reflected that here to be authentic. - serializer.DataField(ref _firingDelay, "fireDelay", TimeSpan.FromSeconds(6)); - serializer.DataField(ref _powerDrawBase, "powerDrawBase", 500); - serializer.DataField(ref _powerDrawMult, "powerDrawMult", 1500); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/PA/ParticleAcceleratorEmitterComponent.cs b/Content.Server/GameObjects/Components/PA/ParticleAcceleratorEmitterComponent.cs index 23359f88ee..aa66c8d554 100644 --- a/Content.Server/GameObjects/Components/PA/ParticleAcceleratorEmitterComponent.cs +++ b/Content.Server/GameObjects/Components/PA/ParticleAcceleratorEmitterComponent.cs @@ -1,7 +1,9 @@ using Content.Shared.GameObjects.Components; using Robust.Shared.GameObjects; using Robust.Shared.Log; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.PA { @@ -10,14 +12,8 @@ namespace Content.Server.GameObjects.Components.PA public class ParticleAcceleratorEmitterComponent : ParticleAcceleratorPartComponent { public override string Name => "ParticleAcceleratorEmitter"; - public ParticleAcceleratorEmitterType Type; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref Type, "emitterType", ParticleAcceleratorEmitterType.Center); - } + [DataField("emitterType")] + public ParticleAcceleratorEmitterType Type = ParticleAcceleratorEmitterType.Center; public void Fire(ParticleAcceleratorPowerState strength) { diff --git a/Content.Server/GameObjects/Components/PDA/PDAComponent.cs b/Content.Server/GameObjects/Components/PDA/PDAComponent.cs index a457bf0494..c7c1df91b3 100644 --- a/Content.Server/GameObjects/Components/PDA/PDAComponent.cs +++ b/Content.Server/GameObjects/Components/PDA/PDAComponent.cs @@ -23,7 +23,9 @@ using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.PDA @@ -41,8 +43,8 @@ namespace Content.Server.GameObjects.Components.PDA [ViewVariables] private bool _lightOn; - [ViewVariables] private string? _startingIdCard = default!; - [ViewVariables] private string? _startingPen = default!; + [ViewVariables] [DataField("idCard")] private string? _startingIdCard = "AssistantIDCard"; + [ViewVariables] [DataField("pen")] private string? _startingPen = "Pen"; [ViewVariables] public string? OwnerName { get; private set; } @@ -63,13 +65,6 @@ namespace Content.Server.GameObjects.Components.PDA _accessSet = new PdaAccessSet(this); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _startingIdCard, "idCard", "AssistantIDCard"); - serializer.DataField(ref _startingPen, "pen", "Pen"); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/PlaceableSurfaceComponent.cs b/Content.Server/GameObjects/Components/PlaceableSurfaceComponent.cs index 6940c345d7..3a36110f27 100644 --- a/Content.Server/GameObjects/Components/PlaceableSurfaceComponent.cs +++ b/Content.Server/GameObjects/Components/PlaceableSurfaceComponent.cs @@ -5,7 +5,7 @@ using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; using Robust.Shared.Maths; using Robust.Shared.Players; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components @@ -14,10 +14,15 @@ namespace Content.Server.GameObjects.Components [ComponentReference(typeof(SharedPlaceableSurfaceComponent))] public class PlaceableSurfaceComponent : SharedPlaceableSurfaceComponent, IInteractUsing { - private bool _isPlaceable; + [DataField("placeCentered")] private bool _placeCentered; + + [DataField("positionOffset")] private Vector2 _positionOffset; + [DataField("IsPlaceable")] + private bool _isPlaceable = true; + [ViewVariables(VVAccess.ReadWrite)] public override bool IsPlaceable { @@ -74,16 +79,7 @@ namespace Content.Server.GameObjects.Components [ViewVariables] int IInteractUsing.Priority => -10; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _isPlaceable, "IsPlaceable", true); - serializer.DataField(ref _placeCentered, "placeCentered", false); - serializer.DataField(ref _positionOffset, "positionOffset", Vector2.Zero); - } - - public override ComponentState GetComponentState(ICommonSession player) + public override ComponentState GetComponentState(ICommonSession session) { return new PlaceableSurfaceComponentState(_isPlaceable,_placeCentered,_positionOffset); } diff --git a/Content.Server/GameObjects/Components/Pointing/PointingArrowComponent.cs b/Content.Server/GameObjects/Components/Pointing/PointingArrowComponent.cs index caff655173..146c5c712a 100644 --- a/Content.Server/GameObjects/Components/Pointing/PointingArrowComponent.cs +++ b/Content.Server/GameObjects/Components/Pointing/PointingArrowComponent.cs @@ -2,7 +2,9 @@ using Content.Shared.GameObjects.Components.Pointing; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; using DrawDepth = Content.Shared.GameObjects.DrawDepth; @@ -15,20 +17,23 @@ namespace Content.Server.GameObjects.Components.Pointing /// The current amount of seconds left on this arrow. /// [ViewVariables(VVAccess.ReadWrite)] - private float _duration; + [DataField("duration")] + private float _duration = 4; /// /// The amount of seconds before the arrow changes movement direction. /// [ViewVariables(VVAccess.ReadWrite)] - private float _step; + [DataField("step")] + private float _step = 0.5f; /// /// The amount of units that this arrow will move by when multiplied /// by the frame time. /// [ViewVariables(VVAccess.ReadWrite)] - private float _speed; + [DataField("speed")] + private float _speed = 1; /// /// The current amount of seconds left before the arrow changes @@ -48,17 +53,8 @@ namespace Content.Server.GameObjects.Components.Pointing /// when its duration runs out. /// [ViewVariables(VVAccess.ReadWrite)] - private bool _rogue; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _duration, "duration", 4); - serializer.DataField(ref _step, "step", 0.5f); - serializer.DataField(ref _speed, "speed", 1); - serializer.DataField(ref _rogue, "rogue", false); - } + [DataField("rogue")] + private bool _rogue = default; protected override void Startup() { diff --git a/Content.Server/GameObjects/Components/Pointing/RoguePointingArrowComponent.cs b/Content.Server/GameObjects/Components/Pointing/RoguePointingArrowComponent.cs index c004112240..f7d3999bdd 100644 --- a/Content.Server/GameObjects/Components/Pointing/RoguePointingArrowComponent.cs +++ b/Content.Server/GameObjects/Components/Pointing/RoguePointingArrowComponent.cs @@ -7,8 +7,10 @@ using Robust.Server.Player; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Maths; +using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; using DrawDepth = Content.Shared.GameObjects.DrawDepth; @@ -24,16 +26,20 @@ namespace Content.Server.GameObjects.Components.Pointing private IEntity? _chasing; [ViewVariables(VVAccess.ReadWrite)] - private float _turningDelay; + [DataField("turningDelay")] + private float _turningDelay = 2; [ViewVariables(VVAccess.ReadWrite)] - private float _chasingDelay; + [DataField("chasingDelay")] + private float _chasingDelay = 1; [ViewVariables(VVAccess.ReadWrite)] - private float _chasingSpeed; + [DataField("chasingSpeed")] + private float _chasingSpeed = 5; [ViewVariables(VVAccess.ReadWrite)] - private float _chasingTime; + [DataField("chasingTime")] + private float _chasingTime = 1; private IEntity? RandomNearbyPlayer() { @@ -71,16 +77,6 @@ namespace Content.Server.GameObjects.Components.Pointing } } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _turningDelay, "turningDelay", 2); - serializer.DataField(ref _chasingDelay, "chasingDelay", 1); - serializer.DataField(ref _chasingSpeed, "chasingSpeed", 5); - serializer.DataField(ref _chasingTime, "chasingTime", 1f); - } - public void Update(float frameTime) { _chasing ??= RandomNearbyPlayer(); diff --git a/Content.Server/GameObjects/Components/Portal/PortalComponent.cs b/Content.Server/GameObjects/Components/Portal/PortalComponent.cs index 96bc5314e9..30d71a4f3e 100644 --- a/Content.Server/GameObjects/Components/Portal/PortalComponent.cs +++ b/Content.Server/GameObjects/Components/Portal/PortalComponent.cs @@ -5,7 +5,7 @@ using Content.Shared.GameObjects.Components.Portal; using Content.Shared.GameObjects.Components.Tag; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Portal @@ -21,29 +21,13 @@ namespace Content.Server.GameObjects.Components.Portal private IEntity? _connectingTeleporter; private PortalState _state = PortalState.Pending; - [ViewVariables(VVAccess.ReadWrite)] private float _individualPortalCooldown; - [ViewVariables] private float _overallPortalCooldown; + [ViewVariables(VVAccess.ReadWrite)] [DataField("individual_cooldown")] private float _individualPortalCooldown = 2.1f; + [ViewVariables] [DataField("overall_cooldown")] private float _overallPortalCooldown = 2.0f; [ViewVariables] private bool _onCooldown; - [ViewVariables] private string _departureSound = ""; - [ViewVariables] private string _arrivalSound = ""; + [ViewVariables] [DataField("departure_sound")] private string _departureSound = "/Audio/Effects/teleport_departure.ogg"; + [ViewVariables] [DataField("arrival_sound")] private string _arrivalSound = "/Audio/Effects/teleport_arrival.ogg"; public readonly List ImmuneEntities = new(); // K - [ViewVariables(VVAccess.ReadWrite)] private float _aliveTime; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - // How long will the portal stay up: 0 is infinite - serializer.DataField(ref _aliveTime, "alive_time", 10.0f); - - // How long before a specific person can go back into it - serializer.DataField(ref _individualPortalCooldown, "individual_cooldown", 2.1f); - - // How long before anyone can go in it - serializer.DataField(ref _overallPortalCooldown, "overall_cooldown", 2.0f); - - serializer.DataField(ref _departureSound, "departure_sound", "/Audio/Effects/teleport_departure.ogg"); - serializer.DataField(ref _arrivalSound, "arrival_sound", "/Audio/Effects/teleport_arrival.ogg"); - } + [ViewVariables(VVAccess.ReadWrite)] [DataField("alive_time")] private float _aliveTime = 10f; public override void OnAdd() { diff --git a/Content.Server/GameObjects/Components/Portal/TeleporterComponent.cs b/Content.Server/GameObjects/Components/Portal/TeleporterComponent.cs index 3b5f33bc3a..56abada91e 100644 --- a/Content.Server/GameObjects/Components/Portal/TeleporterComponent.cs +++ b/Content.Server/GameObjects/Components/Portal/TeleporterComponent.cs @@ -10,7 +10,7 @@ using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Random; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Portal @@ -26,32 +26,23 @@ namespace Content.Server.GameObjects.Components.Portal public override string Name => "ItemTeleporter"; - [ViewVariables] private float _chargeTime; - [ViewVariables] private float _cooldown; - [ViewVariables] private int _range; + [DataField("charge_time")] + [ViewVariables] private float _chargeTime = 0.2f; + [DataField("cooldown")] + [ViewVariables] private float _cooldown = 2f; + [DataField("range")] + [ViewVariables] private int _range = 15; [ViewVariables] private ItemTeleporterState _state; - [ViewVariables] private TeleporterType _teleporterType; - [ViewVariables] private string _departureSound = ""; - [ViewVariables] private string _arrivalSound = ""; - [ViewVariables] private string? _cooldownSound; + [DataField("teleporter_type")] + [ViewVariables] private TeleporterType _teleporterType = TeleporterType.Random; + [ViewVariables] [DataField("departure_sound")] private string _departureSound = "/Audio/Effects/teleport_departure.ogg"; + [ViewVariables] [DataField("arrival_sound")] private string _arrivalSound = "/Audio/Effects/teleport_arrival.ogg"; + [ViewVariables] [DataField("cooldown_sound")] private string? _cooldownSound = default; // If the direct OR random teleport will try to avoid hitting collidables - [ViewVariables] private bool _avoidCollidable; - [ViewVariables] private float _portalAliveTime; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _teleporterType, "teleporter_type", TeleporterType.Random); - serializer.DataField(ref _range, "range", 15); - serializer.DataField(ref _chargeTime, "charge_time", 0.2f); - serializer.DataField(ref _cooldown, "cooldown", 2.0f); - serializer.DataField(ref _avoidCollidable, "avoid_walls", true); - serializer.DataField(ref _departureSound, "departure_sound", "/Audio/Effects/teleport_departure.ogg"); - serializer.DataField(ref _arrivalSound, "arrival_sound", "/Audio/Effects/teleport_arrival.ogg"); - serializer.DataField(ref _cooldownSound, "cooldown_sound", null); - serializer.DataField(ref _portalAliveTime, "portal_alive_time", 5.0f); // TODO: Change this to 0 before PR? - } + [DataField("avoid_walls")] [ViewVariables] + private bool _avoidCollidable = true; + [DataField("portal_alive_time")] + [ViewVariables] private float _portalAliveTime = 5f; private void SetState(ItemTeleporterState newState) { diff --git a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerProviderComponent.cs b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerProviderComponent.cs index 08c17258ef..b795c9231e 100644 --- a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerProviderComponent.cs +++ b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerProviderComponent.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Power.ApcNetComponents @@ -39,7 +39,8 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents /// [ViewVariables(VVAccess.ReadWrite)] public int PowerTransferRange { get => _powerTransferRange; set => SetPowerTransferRange(value); } - private int _powerTransferRange; + [DataField("powerTransferRange")] + private int _powerTransferRange = 3; [ViewVariables] public IReadOnlyList LinkedReceivers => _linkedReceivers; @@ -74,12 +75,6 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents Net.UpdatePowerProviderReceivers(this, oldLoad, newLoad); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _powerTransferRange, "powerTransferRange", 3); - } - protected override void Startup() { base.Startup(); diff --git a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverComponent.cs b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverComponent.cs index a933be6cb6..1ebcc7eef4 100644 --- a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverComponent.cs +++ b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverComponent.cs @@ -7,7 +7,9 @@ using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -39,7 +41,8 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents /// [ViewVariables(VVAccess.ReadWrite)] public int PowerReceptionRange { get => _powerReceptionRange; set => SetPowerReceptionRange(value); } - private int _powerReceptionRange; + [DataField("powerReceptionRange")] + private int _powerReceptionRange = 3; [ViewVariables] public IPowerProvider Provider { get => _provider; set => SetProvider(value); } @@ -60,31 +63,25 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents /// [ViewVariables(VVAccess.ReadWrite)] public int Load { get => _load; set => SetLoad(value); } - private int _load; + [DataField("powerLoad")] + private int _load = 5; /// /// When false, causes this to appear powered even if not receiving power from an Apc. /// [ViewVariables(VVAccess.ReadWrite)] public bool NeedsPower { get => _needsPower; set => SetNeedsPower(value); } - private bool _needsPower; + [DataField("needsPower")] + private bool _needsPower = true; /// /// When true, causes this to never appear powered. /// [ViewVariables(VVAccess.ReadWrite)] public bool PowerDisabled { get => _powerDisabled; set => SetPowerDisabled(value); } + [DataField("powerDisabled")] private bool _powerDisabled; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _powerReceptionRange, "powerReceptionRange", 3); - serializer.DataField(ref _load, "powerLoad", 5); - serializer.DataField(ref _needsPower, "needsPower", true); - serializer.DataField(ref _powerDisabled, "powerDisabled", false); - } - protected override void Startup() { base.Startup(); @@ -98,7 +95,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents } } - public override void OnRemove() + public override void OnRemove() { _provider.RemoveReceiver(this); base.OnRemove(); diff --git a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/BaseCharger.cs b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/BaseCharger.cs index 3f883e0cd2..bd4b12f27a 100644 --- a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/BaseCharger.cs +++ b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/BaseCharger.cs @@ -13,7 +13,9 @@ using Robust.Server.GameObjects; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Localization; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerReceiverUsers @@ -32,17 +34,12 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece private CellChargerStatus _status; [ViewVariables] - private int _chargeRate; + [DataField("chargeRate")] + private int _chargeRate = 100; [ViewVariables] - private float _transferEfficiency; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _chargeRate, "chargeRate", 100); - serializer.DataField(ref _transferEfficiency, "transferEfficiency", 0.85f); - } + [DataField("transferEfficiency")] + private float _transferEfficiency = 0.85f; public override void Initialize() { diff --git a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/EmergencyLightComponent.cs b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/EmergencyLightComponent.cs index 108cc3b2ad..51df93cd4f 100644 --- a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/EmergencyLightComponent.cs +++ b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/EmergencyLightComponent.cs @@ -5,7 +5,9 @@ using Content.Shared.GameObjects.EntitySystems; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Localization; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -36,19 +38,14 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece private EmergencyLightState _state = EmergencyLightState.Empty; [ViewVariables(VVAccess.ReadWrite)] - private float _wattage; + [DataField("wattage")] + private float _wattage = 5; [ViewVariables(VVAccess.ReadWrite)] - private float _chargingWattage; + [DataField("chargingWattage")] + private float _chargingWattage = 60; [ViewVariables(VVAccess.ReadWrite)] - private float _chargingEfficiency; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _wattage, "wattage", 5); - serializer.DataField(ref _chargingWattage, "chargingWattage", 60); - serializer.DataField(ref _chargingEfficiency, "chargingEfficiency", 0.85f); - } + [DataField("chargingEfficiency")] + private float _chargingEfficiency = 0.85f; /// /// For attaching UpdateState() to events. diff --git a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/LightBulbComponent.cs b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/LightBulbComponent.cs index e09700dbf5..5db2572224 100644 --- a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/LightBulbComponent.cs +++ b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/LightBulbComponent.cs @@ -10,6 +10,7 @@ using Robust.Shared.Maths; using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerReceiverUsers @@ -42,6 +43,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece public event EventHandler? OnLightBulbStateChange; public event EventHandler? OnLightColorChange; + [DataField("color")] private Color _color = Color.White; [ViewVariables(VVAccess.ReadWrite)] public Color Color @@ -57,12 +59,15 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece public override string Name => "LightBulb"; + [DataField("bulb")] public LightBulbType Type = LightBulbType.Tube; - private int _burningTemperature; + [DataField("BurningTemperature")] + private int _burningTemperature = 1400; public int BurningTemperature => _burningTemperature; - private int _powerUse; + [DataField("PowerUse")] + private int _powerUse = 40; public int PowerUse => _powerUse; /// @@ -94,14 +99,6 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece private LightBulbState _state = LightBulbState.Normal; - public override void ExposeData(ObjectSerializer serializer) - { - serializer.DataField(ref Type, "bulb", LightBulbType.Tube); - serializer.DataField(ref _color, "color", Color.White); - serializer.DataFieldCached(ref _burningTemperature, "BurningTemperature", 1400); - serializer.DataFieldCached(ref _powerUse, "PowerUse", 40); - } - public void UpdateColor() { if (!Owner.TryGetComponent(out SpriteComponent? sprite)) diff --git a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/PoweredLightComponent.cs b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/PoweredLightComponent.cs index da470a93f3..e466e7a15f 100644 --- a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/PoweredLightComponent.cs +++ b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/PoweredLightComponent.cs @@ -19,8 +19,7 @@ using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; -using Robust.Shared.Log; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Timing; using Robust.Shared.ViewVariables; @@ -46,13 +45,23 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece private TimeSpan _lastThunk; private TimeSpan? _lastGhostBlink; - private bool _hasLampOnSpawn; - [ViewVariables] private bool _on; - [ViewVariables] private bool _currentLit; - [ViewVariables] private bool _isBlinking; - [ViewVariables] private bool _ignoreGhostsBoo; + [DataField("hasLampOnSpawn")] + private bool _hasLampOnSpawn = true; + [ViewVariables] [DataField("on")] + private bool _on = true; + + [ViewVariables] + private bool _currentLit; + + [ViewVariables] + private bool _isBlinking; + + [ViewVariables] [DataField("ignoreGhostsBoo")] + private bool _ignoreGhostsBoo; + + [DataField("bulb")] private LightBulbType BulbType = LightBulbType.Tube; [ViewVariables] private ContainerSlot _lightBulbContainer = default!; @@ -156,14 +165,6 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece bulb.Owner.Transform.Coordinates = user.Transform.Coordinates; } - public override void ExposeData(ObjectSerializer serializer) - { - serializer.DataField(ref BulbType, "bulb", LightBulbType.Tube); - serializer.DataField(ref _on, "on", true); - serializer.DataField(ref _hasLampOnSpawn, "hasLampOnSpawn", true); - serializer.DataField(ref _ignoreGhostsBoo, "ignoreGhostsBoo", false); - } - /// /// For attaching UpdateLight() to events. /// diff --git a/Content.Server/GameObjects/Components/Power/BaseNetConnectorComponent.cs b/Content.Server/GameObjects/Components/Power/BaseNetConnectorComponent.cs index 44a5310c98..8a5a08bd8f 100644 --- a/Content.Server/GameObjects/Components/Power/BaseNetConnectorComponent.cs +++ b/Content.Server/GameObjects/Components/Power/BaseNetConnectorComponent.cs @@ -1,10 +1,10 @@ -#nullable enable +#nullable enable using System.Diagnostics.CodeAnalysis; using System.Linq; using Content.Server.GameObjects.Components.NodeContainer; using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Power @@ -13,7 +13,8 @@ namespace Content.Server.GameObjects.Components.Power { [ViewVariables(VVAccess.ReadWrite)] public Voltage Voltage { get => _voltage; set => SetVoltage(value); } - private Voltage _voltage; + [DataField("voltage")] + private Voltage _voltage = Voltage.High; [ViewVariables] public TNetType Net { get => _net; set => SetNet(value); } @@ -30,12 +31,6 @@ namespace Content.Server.GameObjects.Components.Power _net = NullNet; } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _voltage, "voltage", Voltage.High); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Power/BatteryComponent.cs b/Content.Server/GameObjects/Components/Power/BatteryComponent.cs index c7dce26485..6fe34a7161 100644 --- a/Content.Server/GameObjects/Components/Power/BatteryComponent.cs +++ b/Content.Server/GameObjects/Components/Power/BatteryComponent.cs @@ -2,7 +2,9 @@ using System; using Robust.Shared.GameObjects; using Robust.Shared.Maths; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Power @@ -16,35 +18,28 @@ namespace Content.Server.GameObjects.Components.Power /// Maximum charge of the battery in joules (ie. watt seconds) /// [ViewVariables(VVAccess.ReadWrite)] public int MaxCharge { get => _maxCharge; set => SetMaxCharge(value); } - private int _maxCharge; + [DataField("maxCharge")] + private int _maxCharge = 1000; /// /// Current charge of the battery in joules (ie. watt seconds) /// [ViewVariables(VVAccess.ReadWrite)] public float CurrentCharge { get => _currentCharge; set => SetCurrentCharge(value); } - private float _currentCharge; + [DataField("startingCharge")] + private float _currentCharge = 500; /// /// True if the battery is fully charged. /// [ViewVariables] public bool IsFullyCharged => MathHelper.CloseTo(CurrentCharge, MaxCharge); - [ViewVariables(VVAccess.ReadWrite)] public bool AutoRecharge { get; set; } + [ViewVariables(VVAccess.ReadWrite)] [DataField("autoRecharge")] public bool AutoRecharge { get; set; } - [ViewVariables(VVAccess.ReadWrite)] public float AutoRechargeRate { get; set; } + [ViewVariables(VVAccess.ReadWrite)] [DataField("autoRechargeRate")] public float AutoRechargeRate { get; set; } [ViewVariables] public BatteryState BatteryState { get; private set; } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _maxCharge, "maxCharge", 1000); - serializer.DataField(ref _currentCharge, "startingCharge", 500); - serializer.DataField(this, x => x.AutoRecharge, "autoRecharge", false); - serializer.DataField(this, x => x.AutoRechargeRate, "autoRechargeRate", 0); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Power/PowerCellComponent.cs b/Content.Server/GameObjects/Components/Power/PowerCellComponent.cs index 0652e6bba7..c825cfbdf7 100644 --- a/Content.Server/GameObjects/Components/Power/PowerCellComponent.cs +++ b/Content.Server/GameObjects/Components/Power/PowerCellComponent.cs @@ -8,7 +8,9 @@ using Content.Shared.Utility; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Localization; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -25,16 +27,11 @@ namespace Content.Server.GameObjects.Components.Power public override string Name => "PowerCell"; [ViewVariables] public PowerCellSize CellSize => _cellSize; + [DataField("cellSize")] private PowerCellSize _cellSize = PowerCellSize.Small; [ViewVariables] public bool IsRigged { get; private set; } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _cellSize, "cellSize", PowerCellSize.Small); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Power/PowerCellSlotComponent.cs b/Content.Server/GameObjects/Components/Power/PowerCellSlotComponent.cs index b7561d62ab..65b686583a 100644 --- a/Content.Server/GameObjects/Components/Power/PowerCellSlotComponent.cs +++ b/Content.Server/GameObjects/Components/Power/PowerCellSlotComponent.cs @@ -10,7 +10,9 @@ using Robust.Server.GameObjects; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Localization; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -29,18 +31,21 @@ namespace Content.Server.GameObjects.Components.Power /// What size of cell fits into this component. /// [ViewVariables(VVAccess.ReadWrite)] + [DataField("slotSize")] public PowerCellSize SlotSize { get; set; } = PowerCellSize.Small; /// /// Can the cell be removed ? /// [ViewVariables(VVAccess.ReadWrite)] + [DataField("canRemoveCell")] public bool CanRemoveCell { get; set; } = true; /// /// Should the "Remove cell" verb be displayed on this component? /// [ViewVariables(VVAccess.ReadWrite)] + [DataField("showVerb")] public bool ShowVerb { get; set; } = true; /// @@ -49,21 +54,24 @@ namespace Content.Server.GameObjects.Components.Power /// Use null to show no text. /// [ViewVariables(VVAccess.ReadWrite)] - public string? DescFormatString { get; set; } + [DataField("descFormatString")] + public string? DescFormatString { get; set; } = "It uses size {0} power cells."; /// /// File path to a sound file that should be played when the cell is removed. /// /// "/Audio/Items/pistol_magout.ogg" [ViewVariables(VVAccess.ReadWrite)] - public string? CellRemoveSound { get; set; } + [DataField("cellRemoveSound")] + public string? CellRemoveSound { get; set; } = "/Audio/Items/pistol_magin.ogg"; /// /// File path to a sound file that should be played when a cell is inserted. /// /// "/Audio/Items/pistol_magin.ogg" [ViewVariables(VVAccess.ReadWrite)] - public string? CellInsertSound { get; set; } + [DataField("cellInsertSound")] + public string? CellInsertSound { get; set; } = "/Audio/Items/pistol_magout.ogg"; [ViewVariables] private ContainerSlot _cellContainer = default!; @@ -82,26 +90,15 @@ namespace Content.Server.GameObjects.Components.Power /// /// True if we don't want a cell inserted during map init. /// + [DataField("startEmpty")] private bool _startEmpty = false; /// /// If not null, this cell type will be inserted at MapInit instead of the default Standard cell. /// + [DataField("startingCellType")] private string? _startingCellType = null; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(this, x => x.SlotSize, "slotSize", PowerCellSize.Small); - serializer.DataField(this, x => x.CanRemoveCell, "canRemoveCell", true); - serializer.DataField(this, x => x.ShowVerb, "showVerb", true); - serializer.DataField(ref _startEmpty, "startEmpty", false); - serializer.DataField(ref _startingCellType, "startingCellType", null); - serializer.DataField(this, x => x.CellRemoveSound, "cellRemoveSound", "/Audio/Items/pistol_magin.ogg"); - serializer.DataField(this, x => x.CellInsertSound, "cellInsertSound", "/Audio/Items/pistol_magout.ogg"); - serializer.DataField(this, x => x.DescFormatString, "descFormatString", "It uses size {0} power cells."); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryDischargerComponent.cs b/Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryDischargerComponent.cs index e6b2d15038..72caf8f90a 100644 --- a/Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryDischargerComponent.cs +++ b/Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryDischargerComponent.cs @@ -1,6 +1,8 @@ #nullable enable using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Power.PowerNetComponents @@ -21,13 +23,9 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents [ViewVariables(VVAccess.ReadWrite)] public int ActiveSupplyRate { get => _activeSupplyRate; set => SetActiveSupplyRate(value); } - private int _activeSupplyRate; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _activeSupplyRate, "activeSupplyRate", 50); - } + [DataField("activeSupplyRate")] + private int _activeSupplyRate = 50; public override void Initialize() { diff --git a/Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryStorageComponent.cs b/Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryStorageComponent.cs index 6ef26d5cca..5f13902aa2 100644 --- a/Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryStorageComponent.cs +++ b/Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryStorageComponent.cs @@ -1,6 +1,8 @@ #nullable enable using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Power.PowerNetComponents @@ -15,7 +17,8 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents [ViewVariables(VVAccess.ReadWrite)] public int ActiveDrawRate { get => _activeDrawRate; set => SetActiveDrawRate(value); } - private int _activeDrawRate; + [DataField("activeDrawRate")] + private int _activeDrawRate = 100; [ViewVariables] [ComponentDependency] private BatteryComponent? _battery = default!; @@ -25,12 +28,6 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents [ComponentDependency] private PowerConsumerComponent? _consumer = default!; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _activeDrawRate, "activeDrawRate", 100); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Power/PowerNetComponents/PowerConsumerComponent.cs b/Content.Server/GameObjects/Components/Power/PowerNetComponents/PowerConsumerComponent.cs index c6118c87f3..ddf2e38078 100644 --- a/Content.Server/GameObjects/Components/Power/PowerNetComponents/PowerConsumerComponent.cs +++ b/Content.Server/GameObjects/Components/Power/PowerNetComponents/PowerConsumerComponent.cs @@ -3,7 +3,9 @@ using System; using System.Diagnostics; using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Power.PowerNetComponents @@ -18,6 +20,7 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents /// [ViewVariables(VVAccess.ReadWrite)] public int DrawRate { get => _drawRate; set => SetDrawRate(value); } + [DataField("drawRate")] private int _drawRate; /// @@ -26,7 +29,8 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents /// [ViewVariables(VVAccess.ReadWrite)] public Priority Priority { get => _priority; set => SetPriority(value); } - private Priority _priority; + [DataField("priority")] + private Priority _priority = Priority.First; /// /// How much power this is currently receiving from s. @@ -37,13 +41,6 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents public event EventHandler? OnReceivedPowerChanged; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _drawRate, "drawRate", 0); - serializer.DataField(ref _priority, "priority", Priority.First); - } - protected override void AddSelfToNet(IPowerNet powerNet) { powerNet.AddConsumer(this); diff --git a/Content.Server/GameObjects/Components/Power/PowerNetComponents/PowerSupplierComponent.cs b/Content.Server/GameObjects/Components/Power/PowerNetComponents/PowerSupplierComponent.cs index 02047fe80c..9c65240250 100644 --- a/Content.Server/GameObjects/Components/Power/PowerNetComponents/PowerSupplierComponent.cs +++ b/Content.Server/GameObjects/Components/Power/PowerNetComponents/PowerSupplierComponent.cs @@ -1,7 +1,9 @@ #nullable enable using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Power.PowerNetComponents @@ -13,14 +15,9 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents [ViewVariables(VVAccess.ReadWrite)] public int SupplyRate { get => _supplyRate; set => SetSupplyRate(value); } + [DataField("supplyRate")] private int _supplyRate; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _supplyRate, "supplyRate", 0); - } - protected override void AddSelfToNet(IPowerNet powerNet) { powerNet.AddSupplier(this); diff --git a/Content.Server/GameObjects/Components/Power/PowerNetComponents/SolarPanelComponent.cs b/Content.Server/GameObjects/Components/Power/PowerNetComponents/SolarPanelComponent.cs index 86abbbc9d7..bd71aeaffe 100644 --- a/Content.Server/GameObjects/Components/Power/PowerNetComponents/SolarPanelComponent.cs +++ b/Content.Server/GameObjects/Components/Power/PowerNetComponents/SolarPanelComponent.cs @@ -4,7 +4,7 @@ using Content.Server.GameObjects.EntitySystems; using Content.Shared.GameObjects.EntitySystems; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Timing; using Robust.Shared.ViewVariables; @@ -23,6 +23,7 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents /// /// Maximum supply output by this panel (coverage = 1) /// + [DataField("maxsupply")] private int _maxSupply = 1500; [ViewVariables(VVAccess.ReadWrite)] public int MaxSupply @@ -78,13 +79,6 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents UpdateSupply(); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _maxSupply, "maxsupply", 1500); - } - public void OnBreak(BreakageEventArgs args) { if (!Owner.TryGetComponent(out var sprite)) diff --git a/Content.Server/GameObjects/Components/Power/WireComponent.cs b/Content.Server/GameObjects/Components/Power/WireComponent.cs index 40352a73f8..4495c1b5ea 100644 --- a/Content.Server/GameObjects/Components/Power/WireComponent.cs +++ b/Content.Server/GameObjects/Components/Power/WireComponent.cs @@ -5,7 +5,9 @@ using Content.Server.GameObjects.Components.Stack; using Content.Shared.GameObjects.Components.Interactable; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Power @@ -19,7 +21,8 @@ namespace Content.Server.GameObjects.Components.Power public override string Name => "Wire"; [ViewVariables] - private string? _wireDroppedOnCutPrototype; + [DataField("wireDroppedOnCutPrototype")] + private string? _wireDroppedOnCutPrototype = "HVWireStack1"; /// /// Checked by to determine if there is @@ -27,14 +30,8 @@ namespace Content.Server.GameObjects.Components.Power /// [ViewVariables] public WireType WireType => _wireType; - private WireType _wireType; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _wireDroppedOnCutPrototype, "wireDroppedOnCutPrototype", "HVWireStack1"); - serializer.DataField(ref _wireType, "wireType", WireType.HighVoltage); - } + [DataField("wireType")] + private WireType _wireType = WireType.HighVoltage; async Task IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { diff --git a/Content.Server/GameObjects/Components/Power/WirePlacerComponent.cs b/Content.Server/GameObjects/Components/Power/WirePlacerComponent.cs index 596748c16a..33678d16f1 100644 --- a/Content.Server/GameObjects/Components/Power/WirePlacerComponent.cs +++ b/Content.Server/GameObjects/Components/Power/WirePlacerComponent.cs @@ -7,6 +7,8 @@ using Robust.Shared.IoC; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; using System.Threading.Tasks; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Map; namespace Content.Server.GameObjects.Components.Power @@ -20,17 +22,12 @@ namespace Content.Server.GameObjects.Components.Power public override string Name => "WirePlacer"; [ViewVariables] - private string? _wirePrototypeID; + [DataField("wirePrototypeID")] + private string? _wirePrototypeID = "HVWire"; [ViewVariables] - private WireType _blockingWireType; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _wirePrototypeID, "wirePrototypeID", "HVWire"); - serializer.DataField(ref _blockingWireType, "blockingWireType", WireType.HighVoltage); - } + [DataField("blockingWireType")] + private WireType _blockingWireType = WireType.HighVoltage; /// async Task IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs) diff --git a/Content.Server/GameObjects/Components/Projectiles/ChemicalInjectionProjectileComponent.cs b/Content.Server/GameObjects/Components/Projectiles/ChemicalInjectionProjectileComponent.cs index f5e0fd90a5..7ba064c6c5 100644 --- a/Content.Server/GameObjects/Components/Projectiles/ChemicalInjectionProjectileComponent.cs +++ b/Content.Server/GameObjects/Components/Projectiles/ChemicalInjectionProjectileComponent.cs @@ -5,6 +5,8 @@ using Robust.Shared.GameObjects; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; using System; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Projectiles { @@ -17,18 +19,13 @@ namespace Content.Server.GameObjects.Components.Projectiles private SolutionContainerComponent _solutionContainer; [ViewVariables(VVAccess.ReadWrite)] - public ReagentUnit TransferAmount { get; set; } + [DataField("transferAmount")] + public ReagentUnit TransferAmount { get; set; } = ReagentUnit.New(1); [ViewVariables(VVAccess.ReadWrite)] public float TransferEfficiency { get => _transferEfficiency; set => _transferEfficiency = Math.Clamp(value, 0, 1); } - private float _transferEfficiency; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(this, x => x.TransferAmount, "transferAmount", ReagentUnit.New(1)); - serializer.DataField(ref _transferEfficiency, "transferEfficiency", 1f); - } + [DataField("transferEfficiency")] + private float _transferEfficiency = 1f; public override void Initialize() { diff --git a/Content.Server/GameObjects/Components/Projectiles/FlashProjectileComponent.cs b/Content.Server/GameObjects/Components/Projectiles/FlashProjectileComponent.cs index 84475b77f5..60acb7926b 100644 --- a/Content.Server/GameObjects/Components/Projectiles/FlashProjectileComponent.cs +++ b/Content.Server/GameObjects/Components/Projectiles/FlashProjectileComponent.cs @@ -1,6 +1,6 @@ using Content.Server.GameObjects.Components.Weapon; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Projectiles { @@ -12,18 +12,13 @@ namespace Content.Server.GameObjects.Components.Projectiles { public override string Name => "FlashProjectile"; - private float _range; - private float _duration; + [DataField("range")] + private float _range = 1.0f; + [DataField("duration")] + private float _duration = 8.0f; private bool _flashed; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _range, "range", 1.0f); - serializer.DataField(ref _duration, "duration", 8.0f); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Projectiles/HitscanComponent.cs b/Content.Server/GameObjects/Components/Projectiles/HitscanComponent.cs index 28ee924f96..ecbd57f327 100644 --- a/Content.Server/GameObjects/Components/Projectiles/HitscanComponent.cs +++ b/Content.Server/GameObjects/Components/Projectiles/HitscanComponent.cs @@ -6,9 +6,8 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Maths; -using Robust.Shared.Physics; -using Robust.Shared.Serialization; using Robust.Shared.Timing; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Projectiles { @@ -22,38 +21,34 @@ namespace Content.Server.GameObjects.Components.Projectiles public override string Name => "Hitscan"; public CollisionGroup CollisionMask => (CollisionGroup) _collisionMask; - private int _collisionMask; + + [DataField("layers")] //todo WithFormat.Flags() + private int _collisionMask = (int) CollisionGroup.Opaque; public float Damage { get => _damage; set => _damage = value; } - private float _damage; + [DataField("damage")] + private float _damage = 10f; public DamageType DamageType => _damageType; - private DamageType _damageType; + [DataField("damageType")] + private DamageType _damageType = DamageType.Heat; public float MaxLength => 20.0f; private TimeSpan _startTime; private TimeSpan _deathTime; public float ColorModifier { get; set; } = 1.0f; - private string _spriteName; + [DataField("spriteName")] + private string _spriteName = "Objects/Weapons/Guns/Projectiles/laser.png"; + [DataField("muzzleFlash")] private string _muzzleFlash; + [DataField("impactFlash")] private string _impactFlash; - private string _soundHitWall; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _collisionMask, "layers", (int) CollisionGroup.Opaque, WithFormat.Flags()); - serializer.DataField(ref _damage, "damage", 10.0f); - serializer.DataField(ref _damageType, "damageType", DamageType.Heat); - serializer.DataField(ref _spriteName, "spriteName", "Objects/Weapons/Guns/Projectiles/laser.png"); - serializer.DataField(ref _muzzleFlash, "muzzleFlash", null); - serializer.DataField(ref _impactFlash, "impactFlash", null); - serializer.DataField(ref _soundHitWall, "soundHitWall", "/Audio/Weapons/Guns/Hits/laser_sear_wall.ogg"); - } + [DataField("soundHitWall")] + private string _soundHitWall = "/Audio/Weapons/Guns/Hits/laser_sear_wall.ogg"; public void FireEffects(IEntity user, float distance, Angle angle, IEntity hitEntity = null) { diff --git a/Content.Server/GameObjects/Components/Projectiles/ProjectileComponent.cs b/Content.Server/GameObjects/Components/Projectiles/ProjectileComponent.cs index daa721cc10..303f5748a3 100644 --- a/Content.Server/GameObjects/Components/Projectiles/ProjectileComponent.cs +++ b/Content.Server/GameObjects/Components/Projectiles/ProjectileComponent.cs @@ -7,6 +7,7 @@ using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Players; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Projectiles @@ -18,7 +19,7 @@ namespace Content.Server.GameObjects.Components.Projectiles private EntityUid _shooter = EntityUid.Invalid; - private Dictionary _damages; + [DataField("damages")] private Dictionary _damages = new(); [ViewVariables] public Dictionary Damages @@ -28,24 +29,17 @@ namespace Content.Server.GameObjects.Components.Projectiles } public bool DeleteOnCollide => _deleteOnCollide; - private bool _deleteOnCollide; + [DataField("delete_on_collide")] + private bool _deleteOnCollide = true; // Get that juicy FPS hit sound - private string _soundHit; - private string _soundHitSpecies; + [DataField("soundHit")] + private string _soundHit = default; + [DataField("soundHitSpecies")] + private string _soundHitSpecies = default; private bool _damagedEntity; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _deleteOnCollide, "delete_on_collide", true); - // If not specified 0 damage - serializer.DataField(ref _damages, "damages", new Dictionary()); - serializer.DataField(ref _soundHit, "soundHit", null); - serializer.DataField(ref _soundHitSpecies, "soundHitSpecies", null); - } - public float TimeLeft { get; set; } = 10; /// diff --git a/Content.Server/GameObjects/Components/Projectiles/StunnableProjectileComponent.cs b/Content.Server/GameObjects/Components/Projectiles/StunnableProjectileComponent.cs index d8ce946c24..10086a67a1 100644 --- a/Content.Server/GameObjects/Components/Projectiles/StunnableProjectileComponent.cs +++ b/Content.Server/GameObjects/Components/Projectiles/StunnableProjectileComponent.cs @@ -1,6 +1,6 @@ using Content.Server.GameObjects.Components.Mobs; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Projectiles { @@ -13,17 +13,12 @@ namespace Content.Server.GameObjects.Components.Projectiles public override string Name => "StunnableProjectile"; // See stunnable for what these do - private int _stunAmount; - private int _knockdownAmount; - private int _slowdownAmount; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _stunAmount, "stunAmount", 0); - serializer.DataField(ref _knockdownAmount, "knockdownAmount", 0); - serializer.DataField(ref _slowdownAmount, "slowdownAmount", 0); - } + [DataField("stunAmount")] + private int _stunAmount = default; + [DataField("knockdownAmount")] + private int _knockdownAmount = default; + [DataField("slowdownAmount")] + private int _slowdownAmount = default; public override void Initialize() { diff --git a/Content.Server/GameObjects/Components/Radio/HandheldRadioComponent.cs b/Content.Server/GameObjects/Components/Radio/HandheldRadioComponent.cs index c85e2f53b8..23d37b7a1f 100644 --- a/Content.Server/GameObjects/Components/Radio/HandheldRadioComponent.cs +++ b/Content.Server/GameObjects/Components/Radio/HandheldRadioComponent.cs @@ -8,7 +8,9 @@ using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -25,13 +27,14 @@ namespace Content.Server.GameObjects.Components.Radio private RadioSystem _radioSystem = default!; private bool _radioOn; - private List _channels = new(); + [DataField("channels")] + private List _channels = new(){1459}; [ViewVariables(VVAccess.ReadWrite)] - private int BroadcastFrequency { get; set; } + [DataField("broadcastChannel")] + private int BroadcastFrequency { get; set; } = 1459; - [ViewVariables(VVAccess.ReadWrite)] - public int ListenRange { get; private set; } + [ViewVariables(VVAccess.ReadWrite)] [DataField("listenRange")] public int ListenRange { get; private set; } = 7; [ViewVariables(VVAccess.ReadWrite)] public bool RadioOn @@ -46,15 +49,6 @@ namespace Content.Server.GameObjects.Components.Radio [ViewVariables] public IReadOnlyList Channels => _channels; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, h => h.ListenRange, "listenRange", 7); - serializer.DataField(ref _channels, "channels", new List {1459}); - serializer.DataField(this, h => h.BroadcastFrequency, "broadcastChannel", 1459); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/RandomPottedPlantComponent.cs b/Content.Server/GameObjects/Components/RandomPottedPlantComponent.cs index 0db4787b8c..7d5a6caf75 100644 --- a/Content.Server/GameObjects/Components/RandomPottedPlantComponent.cs +++ b/Content.Server/GameObjects/Components/RandomPottedPlantComponent.cs @@ -3,8 +3,10 @@ using JetBrains.Annotations; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.IoC; +using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components { @@ -16,7 +18,9 @@ namespace Content.Server.GameObjects.Components private static readonly string[] RegularPlantStates; private static readonly string[] PlasticPlantStates; + [DataField("selected")] private string _selectedState; + [DataField("plastic")] private bool _plastic; // for shared string dict, since we don't define these anywhere in content @@ -53,14 +57,6 @@ namespace Content.Server.GameObjects.Components PlasticPlantStates = states.ToArray(); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _selectedState, "selected", null); - serializer.DataField(ref _plastic, "plastic", false); - } - protected override void Startup() { base.Startup(); diff --git a/Content.Server/GameObjects/Components/RandomSpriteColorComponent.cs b/Content.Server/GameObjects/Components/RandomSpriteColorComponent.cs index aaaf167bf5..ed4f6588b2 100644 --- a/Content.Server/GameObjects/Components/RandomSpriteColorComponent.cs +++ b/Content.Server/GameObjects/Components/RandomSpriteColorComponent.cs @@ -3,8 +3,10 @@ using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Maths; +using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components { @@ -13,18 +15,12 @@ namespace Content.Server.GameObjects.Components { public override string Name => "RandomSpriteColor"; + [DataField("selected")] private string _selectedColor; - private string _baseState; - private Dictionary _colors; + [DataField("state")] + private string _baseState = "error"; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _selectedColor, "selected", null); - serializer.DataField(ref _baseState, "state", "error"); - serializer.DataFieldCached(ref _colors, "colors", new Dictionary()); - } + [DataField("colors")] private Dictionary _colors = new(); void IMapInit.MapInit() { diff --git a/Content.Server/GameObjects/Components/RandomSpriteStateComponent.cs b/Content.Server/GameObjects/Components/RandomSpriteStateComponent.cs index 0651329a35..e326a58407 100644 --- a/Content.Server/GameObjects/Components/RandomSpriteStateComponent.cs +++ b/Content.Server/GameObjects/Components/RandomSpriteStateComponent.cs @@ -2,8 +2,10 @@ using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.IoC; +using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components { @@ -13,17 +15,12 @@ namespace Content.Server.GameObjects.Components [Dependency] private readonly IRobustRandom _random = default!; public override string Name => "RandomSpriteState"; + [DataField("spriteStates")] private List _spriteStates; + [DataField("spriteLayer")] private int _spriteLayer; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _spriteStates, "spriteStates", null); - serializer.DataField(ref _spriteLayer, "spriteLayer", 0); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Recycling/RecyclableComponent.cs b/Content.Server/GameObjects/Components/Recycling/RecyclableComponent.cs index ccd69fb4b6..18b0b0ee2b 100644 --- a/Content.Server/GameObjects/Components/Recycling/RecyclableComponent.cs +++ b/Content.Server/GameObjects/Components/Recycling/RecyclableComponent.cs @@ -1,39 +1,31 @@ #nullable enable using System; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Recycling { [RegisterComponent] public class RecyclableComponent : Component { + public override string Name => "Recyclable"; + /// /// The prototype that will be spawned on recycle. /// - private string? _prototype; + [DataField("prototype")] private string? _prototype; /// /// The amount of things that will be spawned on recycle. /// - private int _amount; + [DataField("amount")] private int _amount = 1; /// /// Whether this is "safe" to recycle or not. /// If this is false, the recycler's safety must be disabled to recycle it. /// - private bool _safe; - public override string Name => "Recyclable"; - - public bool Safe => _safe; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _prototype, "prototype", null); - serializer.DataField(ref _safe, "safe", true); - serializer.DataField(ref _amount, "amount", 1); - } + [DataField("safe")] + public bool Safe { get; set; } = true; public void Recycle(float efficiency = 1f) { diff --git a/Content.Server/GameObjects/Components/Recycling/RecyclerComponent.cs b/Content.Server/GameObjects/Components/Recycling/RecyclerComponent.cs index 3b34e50b79..a35716a15b 100644 --- a/Content.Server/GameObjects/Components/Recycling/RecyclerComponent.cs +++ b/Content.Server/GameObjects/Components/Recycling/RecyclerComponent.cs @@ -19,7 +19,9 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Maths; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Recycling @@ -35,14 +37,14 @@ namespace Content.Server.GameObjects.Components.Recycling /// /// Whether or not sentient beings will be recycled /// - [ViewVariables(VVAccess.ReadWrite)] - private bool _safe; + [ViewVariables(VVAccess.ReadWrite)] [DataField("safe")] + private bool _safe = true; /// /// The percentage of material that will be recovered /// - [ViewVariables(VVAccess.ReadWrite)] - private float _efficiency; + [ViewVariables(VVAccess.ReadWrite)] [DataField("efficiency")] + private float _efficiency = 0.25f; private bool Powered => !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || @@ -168,14 +170,6 @@ namespace Content.Server.GameObjects.Components.Recycling } } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _safe, "safe", true); - serializer.DataField(ref _efficiency, "efficiency", 0.25f); - } - void ICollideBehavior.CollideWith(IEntity collidedWith) { Recycle(collidedWith); diff --git a/Content.Server/GameObjects/Components/RepairableComponent.cs b/Content.Server/GameObjects/Components/RepairableComponent.cs index c7ff53097d..f5aa891eeb 100644 --- a/Content.Server/GameObjects/Components/RepairableComponent.cs +++ b/Content.Server/GameObjects/Components/RepairableComponent.cs @@ -8,6 +8,7 @@ using Content.Server.GameObjects.Components.Interactable; using Robust.Shared.GameObjects; using Robust.Shared.Localization; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components @@ -17,18 +18,11 @@ namespace Content.Server.GameObjects.Components { public override string Name => "Repairable"; - [ViewVariables(VVAccess.ReadWrite)] - private int _fuelCost; + [ViewVariables(VVAccess.ReadWrite)] [DataField("fuelCost")] + private int _fuelCost = 5; - [ViewVariables(VVAccess.ReadWrite)] - private int _doAfterDelay; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _fuelCost, "fuelCost", 5); - serializer.DataField(ref _doAfterDelay, "doAfterDelay", 1); - } + [ViewVariables(VVAccess.ReadWrite)] [DataField("doAfterDelay")] + private int _doAfterDelay = 1; async Task IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { diff --git a/Content.Server/GameObjects/Components/Research/LatheComponent.cs b/Content.Server/GameObjects/Components/Research/LatheComponent.cs index 7977ce8939..fb68fc1920 100644 --- a/Content.Server/GameObjects/Components/Research/LatheComponent.cs +++ b/Content.Server/GameObjects/Components/Research/LatheComponent.cs @@ -160,7 +160,7 @@ namespace Content.Server.GameObjects.Components.Research var totalAmount = 0; // Check if it can insert all materials. - foreach (var mat in material.MaterialTypes.Values) + foreach (var (_, mat) in material.MaterialTypes) { // TODO: Change how MaterialComponent works so this is not hard-coded. if (!storage.CanInsertMaterial(mat.ID, VolumePerSheet * multiplier)) return false; @@ -170,13 +170,13 @@ namespace Content.Server.GameObjects.Components.Research // Check if it can take ALL of the material's volume. if (storage.CanTakeAmount(totalAmount)) return false; - foreach (var mat in material.MaterialTypes.Values) + foreach (var (_, mat) in material.MaterialTypes) { storage.InsertMaterial(mat.ID, VolumePerSheet * multiplier); } State = LatheState.Inserting; - switch (material.MaterialTypes.Values.First().Name) + switch (material.MaterialTypes.First().Value.Name) { case "steel": SetAppearance(LatheVisualState.InsertingMetal); diff --git a/Content.Server/GameObjects/Components/Research/LatheDatabaseComponent.cs b/Content.Server/GameObjects/Components/Research/LatheDatabaseComponent.cs index 474f412d4b..c92bdfed32 100644 --- a/Content.Server/GameObjects/Components/Research/LatheDatabaseComponent.cs +++ b/Content.Server/GameObjects/Components/Research/LatheDatabaseComponent.cs @@ -2,7 +2,7 @@ using Content.Shared.Research; using Robust.Shared.GameObjects; using Robust.Shared.Players; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Research @@ -15,21 +15,14 @@ namespace Content.Server.GameObjects.Components.Research /// Whether new recipes can be added to this database or not. /// [ViewVariables] - public bool Static => _static; - private bool _static = false; + [field: DataField("static")] + public bool Static { get; private set; } = false; public override ComponentState GetComponentState(ICommonSession player) { return new LatheDatabaseState(GetRecipeIdList()); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _static, "static", false); - } - public override void Clear() { if (Static) return; diff --git a/Content.Server/GameObjects/Components/Research/MaterialStorageComponent.cs b/Content.Server/GameObjects/Components/Research/MaterialStorageComponent.cs index 11207827ea..e82e9cfbd0 100644 --- a/Content.Server/GameObjects/Components/Research/MaterialStorageComponent.cs +++ b/Content.Server/GameObjects/Components/Research/MaterialStorageComponent.cs @@ -2,7 +2,9 @@ using Content.Shared.GameObjects.Components.Research; using Robust.Shared.GameObjects; using Robust.Shared.Players; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Research @@ -19,7 +21,8 @@ namespace Content.Server.GameObjects.Components.Research /// [ViewVariables] public int StorageLimit => _storageLimit; - private int _storageLimit; + [DataField("StorageLimit")] + private int _storageLimit = -1; public override ComponentState GetComponentState(ICommonSession player) { @@ -77,12 +80,5 @@ namespace Content.Server.GameObjects.Components.Research { return InsertMaterial(ID, -amount); } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _storageLimit, "StorageLimit", -1); - } } } diff --git a/Content.Server/GameObjects/Components/Research/ProtolatheDatabaseComponent.cs b/Content.Server/GameObjects/Components/Research/ProtolatheDatabaseComponent.cs index 0d3b90f473..049cc8a592 100644 --- a/Content.Server/GameObjects/Components/Research/ProtolatheDatabaseComponent.cs +++ b/Content.Server/GameObjects/Components/Research/ProtolatheDatabaseComponent.cs @@ -1,3 +1,4 @@ +using System.Linq; using Content.Shared.GameObjects.Components.Research; using Content.Shared.Research; using Robust.Shared.GameObjects; diff --git a/Content.Server/GameObjects/Components/Research/ResearchPointSourceComponent.cs b/Content.Server/GameObjects/Components/Research/ResearchPointSourceComponent.cs index 3ccd94d443..54a816aef7 100644 --- a/Content.Server/GameObjects/Components/Research/ResearchPointSourceComponent.cs +++ b/Content.Server/GameObjects/Components/Research/ResearchPointSourceComponent.cs @@ -1,7 +1,9 @@ using Content.Server.GameObjects.Components.Power.ApcNetComponents; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Research @@ -12,7 +14,9 @@ namespace Content.Server.GameObjects.Components.Research { public override string Name => "ResearchPointSource"; + [DataField("pointspersecond")] private int _pointsPerSecond; + [DataField("active")] private bool _active; private PowerReceiverComponent _powerReceiver; @@ -42,13 +46,5 @@ namespace Content.Server.GameObjects.Components.Research base.Initialize(); Owner.TryGetComponent(out _powerReceiver); } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _pointsPerSecond, "pointspersecond", 0); - serializer.DataField(ref _active, "active", false); - } } } diff --git a/Content.Server/GameObjects/Components/Research/ResearchServerComponent.cs b/Content.Server/GameObjects/Components/Research/ResearchServerComponent.cs index 785735594b..d546dead49 100644 --- a/Content.Server/GameObjects/Components/Research/ResearchServerComponent.cs +++ b/Content.Server/GameObjects/Components/Research/ResearchServerComponent.cs @@ -3,7 +3,7 @@ using Content.Server.GameObjects.Components.Power.ApcNetComponents; using Content.Server.GameObjects.EntitySystems; using Content.Shared.Research; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Research @@ -17,11 +17,12 @@ namespace Content.Server.GameObjects.Components.Research [ViewVariables(VVAccess.ReadWrite)] public string ServerName => _serverName; + [DataField("servername")] private string _serverName = "RDSERVER"; private float _timer = 0f; public TechnologyDatabaseComponent Database { get; private set; } - [ViewVariables(VVAccess.ReadWrite)] private int _points = 0; + [ViewVariables(VVAccess.ReadWrite)] [DataField("points")] private int _points = 0; [ViewVariables(VVAccess.ReadOnly)] public int Id { get; private set; } @@ -83,13 +84,6 @@ namespace Content.Server.GameObjects.Components.Research EntitySystem.Get()?.UnregisterServer(this); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _serverName, "servername", "RDSERVER"); - serializer.DataField(ref _points, "points", 0); - } - public bool CanUnlockTechnology(TechnologyPrototype technology) { if (!Database.CanUnlockTechnology(technology) || _points < technology.RequiredPoints || diff --git a/Content.Server/GameObjects/Components/Rotatable/FlippableComponent.cs b/Content.Server/GameObjects/Components/Rotatable/FlippableComponent.cs index 0ff258fd57..4d9b210db8 100644 --- a/Content.Server/GameObjects/Components/Rotatable/FlippableComponent.cs +++ b/Content.Server/GameObjects/Components/Rotatable/FlippableComponent.cs @@ -4,7 +4,9 @@ using Content.Shared.GameObjects.Verbs; using Content.Shared.Interfaces; using Robust.Shared.GameObjects; using Robust.Shared.Localization; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Rotatable { @@ -13,7 +15,11 @@ namespace Content.Server.GameObjects.Components.Rotatable { public override string Name => "Flippable"; - private string? _entity; + + private string? _entity => _internalEntity ?? Owner.Prototype?.ID; + + [DataField("entity")] + private string? _internalEntity; private void TryFlip(IEntity user) { @@ -33,13 +39,6 @@ namespace Content.Server.GameObjects.Components.Rotatable Owner.Delete(); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _entity, "entity", Owner.Prototype?.ID); - } - [Verb] private sealed class FlippableVerb : Verb { diff --git a/Content.Server/GameObjects/Components/Rotatable/RotatableComponent.cs b/Content.Server/GameObjects/Components/Rotatable/RotatableComponent.cs index 877c8bdbc5..8482173fe9 100644 --- a/Content.Server/GameObjects/Components/Rotatable/RotatableComponent.cs +++ b/Content.Server/GameObjects/Components/Rotatable/RotatableComponent.cs @@ -4,7 +4,9 @@ using Content.Shared.Interfaces; using Robust.Shared.GameObjects; using Robust.Shared.Localization; using Robust.Shared.Maths; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Rotatable @@ -18,14 +20,9 @@ namespace Content.Server.GameObjects.Components.Rotatable /// If true, this entity can be rotated even while anchored. /// [ViewVariables(VVAccess.ReadWrite)] + [DataField("rotateWhileAnchored")] public bool RotateWhileAnchored { get; private set; } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(this, x => x.RotateWhileAnchored, "rotateWhileAnchored", false); - } - private void TryRotate(IEntity user, Angle angle) { if (!RotateWhileAnchored && Owner.TryGetComponent(out IPhysicsComponent physics)) diff --git a/Content.Server/GameObjects/Components/Singularity/EmitterComponent.cs b/Content.Server/GameObjects/Components/Singularity/EmitterComponent.cs index 0cd2924d93..64a7f52f86 100644 --- a/Content.Server/GameObjects/Components/Singularity/EmitterComponent.cs +++ b/Content.Server/GameObjects/Components/Singularity/EmitterComponent.cs @@ -15,8 +15,10 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Log; +using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; using Timer = Robust.Shared.Timing.Timer; @@ -48,26 +50,13 @@ namespace Content.Server.GameObjects.Components.Singularity [ViewVariables(VVAccess.ReadWrite)] private int _fireShotCounter; - [ViewVariables(VVAccess.ReadWrite)] private string _fireSound = default!; - [ViewVariables(VVAccess.ReadWrite)] private string _boltType = default!; - [ViewVariables(VVAccess.ReadWrite)] private int _powerUseActive; - [ViewVariables(VVAccess.ReadWrite)] private int _fireBurstSize; - [ViewVariables(VVAccess.ReadWrite)] private TimeSpan _fireInterval; - [ViewVariables(VVAccess.ReadWrite)] private TimeSpan _fireBurstDelayMin; - [ViewVariables(VVAccess.ReadWrite)] private TimeSpan _fireBurstDelayMax; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _fireBurstDelayMin, "fireBurstDelayMin", TimeSpan.FromSeconds(2)); - serializer.DataField(ref _fireBurstDelayMax, "fireBurstDelayMax", TimeSpan.FromSeconds(10)); - serializer.DataField(ref _fireInterval, "fireInterval", TimeSpan.FromSeconds(2)); - serializer.DataField(ref _fireBurstSize, "fireBurstSize", 3); - serializer.DataField(ref _powerUseActive, "powerUseActive", 500); - serializer.DataField(ref _boltType, "boltType", "EmitterBolt"); - serializer.DataField(ref _fireSound, "fireSound", "/Audio/Weapons/emitter.ogg"); - } + [ViewVariables(VVAccess.ReadWrite)] [DataField("fireSound")] private string _fireSound = "/Audio/Weapons/emitter.ogg"; + [ViewVariables(VVAccess.ReadWrite)] [DataField("boltType")] private string _boltType = "EmitterBolt"; + [ViewVariables(VVAccess.ReadWrite)] [DataField("powerUseActive")] private int _powerUseActive = 500; + [ViewVariables(VVAccess.ReadWrite)] [DataField("fireBurstSize")] private int _fireBurstSize = 3; + [ViewVariables(VVAccess.ReadWrite)] [DataField("fireInterval")] private TimeSpan _fireInterval = TimeSpan.FromSeconds(2); + [ViewVariables(VVAccess.ReadWrite)] [DataField("fireBurstDelayMin")] private TimeSpan _fireBurstDelayMin = TimeSpan.FromSeconds(2); + [ViewVariables(VVAccess.ReadWrite)] [DataField("fireBurstDelayMax")] private TimeSpan _fireBurstDelayMax = TimeSpan.FromSeconds(10); public override void Initialize() { diff --git a/Content.Server/GameObjects/Components/Sound/EmitSoundOnThrowComponent.cs b/Content.Server/GameObjects/Components/Sound/EmitSoundOnThrowComponent.cs index 931f275ec9..b3a7ee4644 100644 --- a/Content.Server/GameObjects/Components/Sound/EmitSoundOnThrowComponent.cs +++ b/Content.Server/GameObjects/Components/Sound/EmitSoundOnThrowComponent.cs @@ -3,7 +3,7 @@ using Content.Shared.Interfaces.GameObjects.Components; using Robust.Server.GameObjects; using Robust.Shared.Audio; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Sound { @@ -17,16 +17,11 @@ namespace Content.Server.GameObjects.Components.Sound /// public override string Name => "EmitSoundOnThrow"; + [DataField("sound")] public string _soundName; + [DataField("variation")] public float _pitchVariation; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _soundName, "sound", string.Empty); - serializer.DataField(ref _pitchVariation, "variation", 0.0f); - } public void PlaySoundEffect() { if (!string.IsNullOrWhiteSpace(_soundName)) diff --git a/Content.Server/GameObjects/Components/Sound/EmitSoundOnUseComponent.cs b/Content.Server/GameObjects/Components/Sound/EmitSoundOnUseComponent.cs index b95752eaac..8d2fe3e08a 100644 --- a/Content.Server/GameObjects/Components/Sound/EmitSoundOnUseComponent.cs +++ b/Content.Server/GameObjects/Components/Sound/EmitSoundOnUseComponent.cs @@ -3,7 +3,7 @@ using Content.Shared.Interfaces.GameObjects.Components; using Robust.Server.GameObjects; using Robust.Shared.Audio; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Sound @@ -18,17 +18,9 @@ namespace Content.Server.GameObjects.Components.Sound /// public override string Name => "EmitSoundOnUse"; - [ViewVariables(VVAccess.ReadWrite)] public string _soundName; - [ViewVariables(VVAccess.ReadWrite)] public float _pitchVariation; - [ViewVariables(VVAccess.ReadWrite)] public int _semitoneVariation; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _soundName, "sound", string.Empty); - serializer.DataField(ref _pitchVariation, "variation", 0.0f); - serializer.DataField(ref _semitoneVariation, "semitoneVariation", 0); - } + [ViewVariables(VVAccess.ReadWrite)] [DataField("sound")] public string _soundName; + [ViewVariables(VVAccess.ReadWrite)] [DataField("variation")] public float _pitchVariation; + [ViewVariables(VVAccess.ReadWrite)] [DataField("semitoneVariation")] public int _semitoneVariation; bool IUse.UseEntity(UseEntityEventArgs eventArgs) { diff --git a/Content.Server/GameObjects/Components/Sound/FootstepModifierComponent.cs b/Content.Server/GameObjects/Components/Sound/FootstepModifierComponent.cs index 73c4d28bd6..dcbb37ac16 100644 --- a/Content.Server/GameObjects/Components/Sound/FootstepModifierComponent.cs +++ b/Content.Server/GameObjects/Components/Sound/FootstepModifierComponent.cs @@ -6,6 +6,7 @@ using Robust.Shared.IoC; using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Sound { @@ -21,14 +22,9 @@ namespace Content.Server.GameObjects.Components.Sound /// public override string Name => "FootstepModifier"; + [DataField("footstepSoundCollection")] public string _soundCollectionName; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _soundCollectionName, "footstepSoundCollection", ""); - } - public void PlayFootstep() { if (!string.IsNullOrWhiteSpace(_soundCollectionName)) diff --git a/Content.Server/GameObjects/Components/StationEvents/RadiationPulseComponent.cs b/Content.Server/GameObjects/Components/StationEvents/RadiationPulseComponent.cs index d68fa49cec..6c18dd9a50 100644 --- a/Content.Server/GameObjects/Components/StationEvents/RadiationPulseComponent.cs +++ b/Content.Server/GameObjects/Components/StationEvents/RadiationPulseComponent.cs @@ -5,8 +5,8 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Players; using Robust.Shared.Random; -using Robust.Shared.Serialization; using Robust.Shared.Timing; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.StationEvents { @@ -18,16 +18,17 @@ namespace Content.Server.GameObjects.Components.StationEvents [Dependency] private readonly IRobustRandom _random = default!; private float _duration; - private float _radsPerSecond; - private float _range; + private float _radsPerSecond = 40f; + private float _range = 5f; private TimeSpan _endTime; - private bool _draw; - private bool _decay; + private bool _draw = true; + private bool _decay = true; /// /// Whether the entity will delete itself after a certain duration defined by /// and /// + [DataField("decay")] public override bool Decay { get => _decay; @@ -38,10 +39,13 @@ namespace Content.Server.GameObjects.Components.StationEvents } } - public float MinPulseLifespan { get; set; } + [DataField("minPulseLifespan")] + public float MinPulseLifespan { get; set; } = 0.8f; - public float MaxPulseLifespan { get; set; } + [DataField("maxPulseLifespan")] + public float MaxPulseLifespan { get; set; } = 2.5f; + [DataField("dps")] public override float RadsPerSecond { get => _radsPerSecond; @@ -52,8 +56,9 @@ namespace Content.Server.GameObjects.Components.StationEvents } } - public string Sound { get; set; } + [DataField("sound")] public string Sound { get; set; } = "/Audio/Weapons/Guns/Gunshots/laser3.ogg"; + [DataField("range")] public override float Range { get => _range; @@ -64,6 +69,7 @@ namespace Content.Server.GameObjects.Components.StationEvents } } + [DataField("draw")] public override bool Draw { get => _draw; @@ -76,18 +82,6 @@ namespace Content.Server.GameObjects.Components.StationEvents public override TimeSpan EndTime => _endTime; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(this, x => x.RadsPerSecond, "dps", 40.0f); - serializer.DataField(this, x => x.Sound, "sound", "/Audio/Weapons/Guns/Gunshots/laser3.ogg"); - serializer.DataField(this, x => x.Range, "range", 5.0f); - serializer.DataField(this, x => x.Draw, "draw", true); - serializer.DataField(this, x => x.Decay, "decay", true); - serializer.DataField(this, x => x.MaxPulseLifespan, "maxPulseLifespan", 2.5f); - serializer.DataField(this, x => x.MinPulseLifespan, "minPulseLifespan", 0.8f); - } - public void DoPulse() { if (Decay) diff --git a/Content.Server/GameObjects/Components/Strap/StrapComponent.cs b/Content.Server/GameObjects/Components/Strap/StrapComponent.cs index af9d88c38a..0c426e2bb3 100644 --- a/Content.Server/GameObjects/Components/Strap/StrapComponent.cs +++ b/Content.Server/GameObjects/Components/Strap/StrapComponent.cs @@ -13,33 +13,29 @@ using Robust.Shared.GameObjects; using Robust.Shared.Localization; using Robust.Shared.Players; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Strap { [RegisterComponent] [ComponentReference(typeof(SharedStrapComponent))] - public class StrapComponent : SharedStrapComponent, IInteractHand + public class StrapComponent : SharedStrapComponent, IInteractHand, ISerializationHooks { [ComponentDependency] public readonly SpriteComponent? SpriteComponent = null; - private HashSet _buckledEntities = null!; - private StrapPosition _position; - private string _buckleSound = null!; - private string _unbuckleSound = null!; - private AlertType _buckledAlertType; + private readonly HashSet _buckledEntities = new(); /// /// The angle in degrees to rotate the player by when they get strapped /// - [ViewVariables] + [ViewVariables] [DataField("rotation")] private int _rotation; /// /// The size of the strap which is compared against when buckling entities /// - [ViewVariables] - private int _size; + [ViewVariables] [DataField("size")] private int _size = 100; private int _occupiedSize; /// @@ -50,25 +46,29 @@ namespace Content.Server.GameObjects.Components.Strap /// /// The change in position to the strapped mob /// - public StrapPosition Position => _position; + [field: DataField("position")] + public StrapPosition Position { get; } = StrapPosition.None; /// /// The sound to be played when a mob is buckled /// [ViewVariables] - public string BuckleSound => _buckleSound; + [field: DataField("buckleSound")] + public string BuckleSound { get; } = "/Audio/Effects/buckle.ogg"; /// /// The sound to be played when a mob is unbuckled /// [ViewVariables] - public string UnbuckleSound => _unbuckleSound; + [field: DataField("unbuckleSound")] + public string UnbuckleSound { get; } = "/Audio/Effects/unbuckle.ogg"; /// /// ID of the alert to show when buckled /// [ViewVariables] - public AlertType BuckledAlertType => _buckledAlertType; + [field: DataField("buckledAlertType")] + public AlertType BuckledAlertType { get; } = AlertType.Buckled; /// /// The sum of the sizes of all the buckled entities in this strap @@ -130,24 +130,6 @@ namespace Content.Server.GameObjects.Components.Strap } } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _position, "position", StrapPosition.None); - serializer.DataField(ref _buckleSound, "buckleSound", "/Audio/Effects/buckle.ogg"); - serializer.DataField(ref _unbuckleSound, "unbuckleSound", "/Audio/Effects/unbuckle.ogg"); - serializer.DataField(ref _buckledAlertType, "buckledAlertType", AlertType.Buckled); - serializer.DataField(ref _rotation, "rotation", 0); - - var defaultSize = 100; - - serializer.DataField(ref _size, "size", defaultSize); - _buckledEntities = new HashSet(_size / defaultSize); - - _occupiedSize = 0; - } - public override void OnRemove() { base.OnRemove(); diff --git a/Content.Server/GameObjects/Components/Temperature/TemperatureComponent.cs b/Content.Server/GameObjects/Components/Temperature/TemperatureComponent.cs index 4536d0625c..e4f2488e7c 100644 --- a/Content.Server/GameObjects/Components/Temperature/TemperatureComponent.cs +++ b/Content.Server/GameObjects/Components/Temperature/TemperatureComponent.cs @@ -5,7 +5,7 @@ using Content.Shared.Atmos; using Content.Shared.Damage; using Content.Shared.GameObjects.Components.Damage; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Temperature @@ -40,22 +40,16 @@ namespace Content.Server.GameObjects.Components.Temperature [ViewVariables] public float SpecificHeat => _specificHeat; - private float _heatDamageThreshold; - private float _coldDamageThreshold; - private float _tempDamageCoefficient; - private float _currentTemperature; - private float _specificHeat; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _heatDamageThreshold, "heatDamageThreshold", 0); - serializer.DataField(ref _coldDamageThreshold, "coldDamageThreshold", 0); - serializer.DataField(ref _tempDamageCoefficient, "tempDamageCoefficient", 1); - serializer.DataField(ref _currentTemperature, "currentTemperature", Atmospherics.T20C); - serializer.DataField(ref _specificHeat, "specificHeat", Atmospherics.MinimumHeatCapacity); - } + [DataField("heatDamageThreshold")] + private float _heatDamageThreshold = default; + [DataField("coldDamageThreshold")] + private float _coldDamageThreshold = default; + [DataField("tempDamageCoefficient")] + private float _tempDamageCoefficient = 1; + [DataField("currentTemperature")] + private float _currentTemperature = Atmospherics.T20C; + [DataField("specificHeat")] + private float _specificHeat = Atmospherics.MinimumHeatCapacity; public void Update() { diff --git a/Content.Server/GameObjects/Components/Timing/UseDelayComponent.cs b/Content.Server/GameObjects/Components/Timing/UseDelayComponent.cs index 5775efbba9..1b1c6d301a 100644 --- a/Content.Server/GameObjects/Components/Timing/UseDelayComponent.cs +++ b/Content.Server/GameObjects/Components/Timing/UseDelayComponent.cs @@ -3,8 +3,10 @@ using System.Threading; using Content.Shared.GameObjects.Components.Items; using Robust.Shared.GameObjects; using Robust.Shared.IoC; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; using Robust.Shared.Timing; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Timing @@ -19,7 +21,8 @@ namespace Content.Server.GameObjects.Components.Timing private TimeSpan _lastUseTime; - private float _delay; + [DataField("delay")] + private float _delay = 1; /// /// The time, in seconds, between an object's use and when it can be used again /// @@ -30,12 +33,6 @@ namespace Content.Server.GameObjects.Components.Timing private CancellationTokenSource cancellationTokenSource; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _delay, "delay", 1); - } - public void BeginDelay() { if (ActiveDelay) diff --git a/Content.Server/GameObjects/Components/Trigger/TimerTrigger/OnUseTimerTriggerComponent.cs b/Content.Server/GameObjects/Components/Trigger/TimerTrigger/OnUseTimerTriggerComponent.cs index df1c143af3..47b216e8a9 100644 --- a/Content.Server/GameObjects/Components/Trigger/TimerTrigger/OnUseTimerTriggerComponent.cs +++ b/Content.Server/GameObjects/Components/Trigger/TimerTrigger/OnUseTimerTriggerComponent.cs @@ -5,7 +5,7 @@ using Content.Shared.GameObjects.Components.Trigger; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Trigger.TimerTrigger { @@ -14,14 +14,8 @@ namespace Content.Server.GameObjects.Components.Trigger.TimerTrigger { public override string Name => "OnUseTimerTrigger"; - private float _delay; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _delay, "delay", 0f); - } + [DataField("delay")] + private float _delay = 0f; public void Trigger(IEntity user) { diff --git a/Content.Server/GameObjects/Components/VendingMachines/VendingMachineComponent.cs b/Content.Server/GameObjects/Components/VendingMachines/VendingMachineComponent.cs index ce7ce5d482..ec32be41b9 100644 --- a/Content.Server/GameObjects/Components/VendingMachines/VendingMachineComponent.cs +++ b/Content.Server/GameObjects/Components/VendingMachines/VendingMachineComponent.cs @@ -17,6 +17,7 @@ using Robust.Shared.Localization; using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; using static Content.Shared.GameObjects.Components.SharedWiresComponent; @@ -32,15 +33,20 @@ namespace Content.Server.GameObjects.Components.VendingMachines private bool _ejecting; private TimeSpan _animationDuration = TimeSpan.Zero; - private string _packPrototypeId = ""; + [DataField("pack")] + private string _packPrototypeId = string.Empty; private string? _description; private string _spriteName = ""; private bool Powered => !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered; private bool _broken; - private string _soundVend = ""; - private string _soundDeny = ""; + [DataField("soundVend")] + // Grabbed from: https://github.com/discordia-space/CEV-Eris/blob/f702afa271136d093ddeb415423240a2ceb212f0/sound/machines/vending_drop.ogg + private string _soundVend = "/Audio/Machines/machine_vend.ogg"; + [DataField("soundDeny")] + // Yoinked from: https://github.com/discordia-space/CEV-Eris/blob/35bbad6764b14e15c03a816e3e89aa1751660ba9/sound/machines/Custom_deny.ogg + private string _soundDeny = "/Audio/Machines/custom_deny.ogg"; [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(VendingMachineUiKey.Key); @@ -63,17 +69,6 @@ namespace Content.Server.GameObjects.Components.VendingMachines } } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _packPrototypeId, "pack", string.Empty); - // Grabbed from: https://github.com/discordia-space/CEV-Eris/blob/f702afa271136d093ddeb415423240a2ceb212f0/sound/machines/vending_drop.ogg - serializer.DataField(ref _soundVend, "soundVend", "/Audio/Machines/machine_vend.ogg"); - // Yoinked from: https://github.com/discordia-space/CEV-Eris/blob/35bbad6764b14e15c03a816e3e89aa1751660ba9/sound/machines/Custom_deny.ogg - serializer.DataField(ref _soundDeny, "soundDeny", "/Audio/Machines/custom_deny.ogg"); - } - private void InitializeFromPrototype() { if (string.IsNullOrEmpty(_packPrototypeId)) { return; } diff --git a/Content.Server/GameObjects/Components/Weapon/Melee/FlashComponent.cs b/Content.Server/GameObjects/Components/Weapon/Melee/FlashComponent.cs index ba8f076a50..5b0bf5a4c7 100644 --- a/Content.Server/GameObjects/Components/Weapon/Melee/FlashComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Melee/FlashComponent.cs @@ -7,7 +7,7 @@ using Robust.Server.GameObjects; using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.Localization; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -18,11 +18,14 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee { public override string Name => "Flash"; - [ViewVariables(VVAccess.ReadWrite)] private int _flashDuration = 5000; - [ViewVariables(VVAccess.ReadWrite)] private int _uses = 5; - [ViewVariables(VVAccess.ReadWrite)] private float _range = 3f; - [ViewVariables(VVAccess.ReadWrite)] private int _aoeFlashDuration = 5000 / 3; - [ViewVariables(VVAccess.ReadWrite)] private float _slowTo = 0.75f; + public FlashComponent() { Range = 7f; } + + [DataField("duration")] [ViewVariables(VVAccess.ReadWrite)] private int _flashDuration = 5000; + [DataField("uses")] [ViewVariables(VVAccess.ReadWrite)] private int _uses = 5; + [ViewVariables(VVAccess.ReadWrite)] private float _range => Range; + [ViewVariables(VVAccess.ReadWrite)] private int _aoeFlashDuration => _internalAoeFlashDuration ?? _flashDuration / 3; + [DataField("aoeFlashDuration")] private int? _internalAoeFlashDuration; + [DataField("slowTo")] [ViewVariables(VVAccess.ReadWrite)] private float _slowTo = 0.75f; private bool _flashing; private int Uses @@ -37,17 +40,6 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee private bool HasUses => _uses > 0; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _flashDuration, "duration", 5000); - serializer.DataField(ref _uses, "uses", 5); - serializer.DataField(ref _range, "range", 7f); - serializer.DataField(ref _aoeFlashDuration, "aoeFlashDuration", _flashDuration / 3); - serializer.DataField(ref _slowTo, "slowTo", 0.75f); - } - protected override bool OnHitEntities(IReadOnlyList entities, AttackEventArgs eventArgs) { if (entities.Count == 0) diff --git a/Content.Server/GameObjects/Components/Weapon/Melee/MeleeChemicalInjectorComponent.cs b/Content.Server/GameObjects/Components/Weapon/Melee/MeleeChemicalInjectorComponent.cs index 5873ffb54f..d11925e4e5 100644 --- a/Content.Server/GameObjects/Components/Weapon/Melee/MeleeChemicalInjectorComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Melee/MeleeChemicalInjectorComponent.cs @@ -8,6 +8,8 @@ using Robust.Shared.ViewVariables; using System; using System.Collections.Generic; using System.Linq; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Weapon.Melee { @@ -17,18 +19,13 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee public override string Name => "MeleeChemicalInjector"; [ViewVariables(VVAccess.ReadWrite)] - public ReagentUnit TransferAmount { get; set; } + [DataField("transferAmount")] + public ReagentUnit TransferAmount { get; set; } = ReagentUnit.New(1); [ViewVariables(VVAccess.ReadWrite)] public float TransferEfficiency { get => _transferEfficiency; set => _transferEfficiency = Math.Clamp(value, 0, 1); } - private float _transferEfficiency; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(this, x => x.TransferAmount, "transferAmount", ReagentUnit.New(1)); - serializer.DataField(ref _transferEfficiency, "transferEfficiency", 1f); - } + [DataField("transferEfficiency")] + private float _transferEfficiency = 1f; public override void HandleMessage(ComponentMessage message, IComponent? component) { diff --git a/Content.Server/GameObjects/Components/Weapon/Melee/MeleeWeaponComponent.cs b/Content.Server/GameObjects/Components/Weapon/Melee/MeleeWeaponComponent.cs index 3feb2f9703..7e5fad59eb 100644 --- a/Content.Server/GameObjects/Components/Weapon/Melee/MeleeWeaponComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Melee/MeleeWeaponComponent.cs @@ -12,8 +12,10 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Maths; using Robust.Shared.Physics; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; using Robust.Shared.Timing; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Weapon.Melee @@ -28,48 +30,41 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee private TimeSpan _lastAttackTime; private TimeSpan _cooldownEnd; - private readonly string _hitSound = default!; - private readonly string _missSound = default!; + [DataField("hitSound")] + private string _hitSound = "/Audio/Weapons/genhit1.ogg"; + + [DataField("missSound")] + private string _missSound = "/Audio/Weapons/punchmiss.ogg"; + + [DataField("arcCooldownTime")] public float ArcCooldownTime { get; private set; } = 1f; - public float CooldownTime { get; private set; } = 0.5f; + + [DataField("cooldownTime")] + public float CooldownTime { get; private set; } = 1f; [ViewVariables(VVAccess.ReadWrite)] - public string ClickArc { get; set; } + [DataField("clickArc")] + public string ClickArc { get; set; } = "punch"; [ViewVariables(VVAccess.ReadWrite)] - public string Arc { get; set; } + [DataField("arc")] + public string Arc { get; set; } = "default"; + + [ViewVariables(VVAccess.ReadWrite)] [DataField("arcwidth")] public float ArcWidth { get; set; } = 90; [ViewVariables(VVAccess.ReadWrite)] - public float ArcWidth { get; set; } + [DataField("range")] + public float Range { get; set; } = 1; [ViewVariables(VVAccess.ReadWrite)] - public float Range { get; set; } + [DataField("damage")] + public int Damage { get; set; } = 5; [ViewVariables(VVAccess.ReadWrite)] - public int Damage { get; set; } + [DataField("damageType")] + public DamageType DamageType { get; set; } = DamageType.Blunt; - [ViewVariables(VVAccess.ReadWrite)] - public DamageType DamageType { get; set; } - - [ViewVariables(VVAccess.ReadWrite)] - public bool ClickAttackEffect { get; set; } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, x => x.Damage, "damage", 5); - serializer.DataField(this, x => x.Range, "range", 1); - serializer.DataField(this, x => x.ArcWidth, "arcwidth", 90); - serializer.DataField(this, x => x.Arc, "arc", "default"); - serializer.DataField(this, x => x.ClickArc, "clickArc", "punch"); - serializer.DataField(this, x => x._hitSound, "hitSound", "/Audio/Weapons/genhit1.ogg"); - serializer.DataField(this, x => x._missSound, "missSound", "/Audio/Weapons/punchmiss.ogg"); - serializer.DataField(this, x => x.ArcCooldownTime, "arcCooldownTime", 1f); - serializer.DataField(this, x => x.CooldownTime, "cooldownTime", 1f); - serializer.DataField(this, x => x.DamageType, "damageType", DamageType.Blunt); - serializer.DataField(this, x => x.ClickAttackEffect, "clickAttackEffect", true); - } + [ViewVariables(VVAccess.ReadWrite)] [DataField("clickAttackEffect")] public bool ClickAttackEffect { get; set; } = true; protected virtual bool OnHitEntities(IReadOnlyList entities, AttackEventArgs eventArgs) { diff --git a/Content.Server/GameObjects/Components/Weapon/Melee/StunbatonComponent.cs b/Content.Server/GameObjects/Components/Weapon/Melee/StunbatonComponent.cs index d57d2dab44..0633f1600d 100644 --- a/Content.Server/GameObjects/Components/Weapon/Melee/StunbatonComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Melee/StunbatonComponent.cs @@ -13,8 +13,10 @@ using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; +using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -33,15 +35,19 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee private PowerCellComponent? Cell => _cellSlot.Cell; [ViewVariables(VVAccess.ReadWrite)] + [DataField("paralyzeChanceNoSlowdown")] private float _paralyzeChanceNoSlowdown = 0.35f; [ViewVariables(VVAccess.ReadWrite)] + [DataField("paralyzeChanceWithSlowdown")] private float _paralyzeChanceWithSlowdown = 0.85f; [ViewVariables(VVAccess.ReadWrite)] + [DataField("paralyzeTime")] private float _paralyzeTime = 10f; [ViewVariables(VVAccess.ReadWrite)] + [DataField("slowdownTime")] private float _slowdownTime = 5f; [ViewVariables(VVAccess.ReadWrite)] public float EnergyPerUse { get; set; } = 50; @@ -55,16 +61,6 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee _cellSlot = Owner.EnsureComponent(); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _paralyzeChanceNoSlowdown, "paralyzeChanceNoSlowdown", 0.35f); - serializer.DataField(ref _paralyzeChanceWithSlowdown, "paralyzeChanceWithSlowdown", 0.85f); - serializer.DataField(ref _paralyzeTime, "paralyzeTime", 10f); - serializer.DataField(ref _slowdownTime, "slowdownTime", 5f); - } - public override void HandleMessage(ComponentMessage message, IComponent? component) { base.HandleMessage(message, component); diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/AmmoBoxComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/AmmoBoxComponent.cs index a58d164f90..45bdac9236 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/AmmoBoxComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/AmmoBoxComponent.cs @@ -14,7 +14,7 @@ using Robust.Server.GameObjects; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Localization; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition @@ -24,27 +24,30 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition { public override string Name => "AmmoBox"; - private BallisticCaliber _caliber; - public int Capacity => _capacity; - private int _capacity; + [DataField("caliber")] + private BallisticCaliber _caliber = BallisticCaliber.Unspecified; + + [DataField("capacity")] + public int Capacity + { + get => _capacity; + set + { + _capacity = value; + _spawnedAmmo = new Stack(value); + } + } + + private int _capacity = 30; public int AmmoLeft => _spawnedAmmo.Count + _unspawnedCount; - private Stack _spawnedAmmo; + private Stack _spawnedAmmo = new(); private Container _ammoContainer; private int _unspawnedCount; + [DataField("fillPrototype")] private string _fillPrototype; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _caliber, "caliber", BallisticCaliber.Unspecified); - serializer.DataField(ref _capacity, "capacity", 30); - serializer.DataField(ref _fillPrototype, "fillPrototype", null); - - _spawnedAmmo = new Stack(_capacity); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/AmmoComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/AmmoComponent.cs index d5e63eebf8..b4855be939 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/AmmoComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/AmmoComponent.cs @@ -9,6 +9,7 @@ using Robust.Shared.Log; using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Timing; using Robust.Shared.Utility; @@ -19,13 +20,15 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition /// Generally used for bullets but can be used for other things like bananas /// [RegisterComponent] - public class AmmoComponent : Component, IExamine + public class AmmoComponent : Component, IExamine, ISerializationHooks { [Dependency] private readonly IGameTiming _gameTiming = default!; public override string Name => "Ammo"; - public BallisticCaliber Caliber => _caliber; - private BallisticCaliber _caliber; + + [field: DataField("caliber")] + public BallisticCaliber Caliber { get; } = BallisticCaliber.Unspecified; + public bool Spent { get @@ -38,64 +41,60 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition return _spent; } } + private bool _spent; /// /// Used for anything without a case that fires itself /// + [DataField("isProjectile")] private bool _ammoIsProjectile; /// /// Used for something that is deleted when the projectile is retrieved /// - public bool Caseless => _caseless; - private bool _caseless; + [field: DataField("caseless")] + public bool Caseless { get; } + // Rather than managing bullet / case state seemed easier to just have 2 toggles // ammoIsProjectile being for a beanbag for example and caseless being for ClRifle rounds /// /// For shotguns where they might shoot multiple entities /// - public int ProjectilesFired => _projectilesFired; - private int _projectilesFired; + [field: DataField("projectilesFired")] + public int ProjectilesFired { get; } = 1; + + [DataField("projectile")] private string _projectileId; + // How far apart each entity is if multiple are shot - public float EvenSpreadAngle => _evenSpreadAngle; - private float _evenSpreadAngle; + [field: DataField("ammoSpread")] + public float EvenSpreadAngle { get; } = default; + /// /// How fast the shot entities travel /// - public float Velocity => _velocity; - private float _velocity; + [field: DataField("ammoVelocity")] + public float Velocity { get; } = 20f; - private string _muzzleFlashSprite; + [DataField("muzzleFlash")] + private string _muzzleFlashSprite = "Objects/Weapons/Guns/Projectiles/bullet_muzzle.png"; - public string SoundCollectionEject => _soundCollectionEject; - private string _soundCollectionEject; + [field: DataField("soundCollectionEject")] + public string SoundCollectionEject { get; } = "CasingEject"; - public override void ExposeData(ObjectSerializer serializer) + void ISerializationHooks.AfterDeserialization() { - base.ExposeData(serializer); - // For shotty of whatever as well - serializer.DataField(ref _projectileId, "projectile", null); - serializer.DataField(ref _caliber, "caliber", BallisticCaliber.Unspecified); - serializer.DataField(ref _projectilesFired, "projectilesFired", 1); - // Used for shotty to determine overall pellet spread - serializer.DataField(ref _evenSpreadAngle, "ammoSpread", 0); - serializer.DataField(ref _velocity, "ammoVelocity", 20.0f); - serializer.DataField(ref _ammoIsProjectile, "isProjectile", false); - serializer.DataField(ref _caseless, "caseless", false); // Being both caseless and shooting yourself doesn't make sense - DebugTools.Assert(!(_ammoIsProjectile && _caseless)); - serializer.DataField(ref _muzzleFlashSprite, "muzzleFlash", "Objects/Weapons/Guns/Projectiles/bullet_muzzle.png"); - serializer.DataField(ref _soundCollectionEject, "soundCollectionEject", "CasingEject"); + DebugTools.Assert(!(_ammoIsProjectile == true && Caseless == true)); - if (_projectilesFired < 1) + if (ProjectilesFired < 1) { Logger.Error("Ammo can't have less than 1 projectile"); } - if (_evenSpreadAngle > 0 && _projectilesFired == 1) + if (EvenSpreadAngle > 0 && ProjectilesFired == 1) { Logger.Error("Can't have an even spread if only 1 projectile is fired"); throw new InvalidOperationException(); diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/AmmoComponentData.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/AmmoComponentData.cs new file mode 100644 index 0000000000..c6420f1a35 --- /dev/null +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/AmmoComponentData.cs @@ -0,0 +1,12 @@ +using System; +using Robust.Shared.Log; +using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.Utility; + +namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition +{ + public partial class AmmoComponentData : ISerializationHooks + { + } +} diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/ChemicalAmmoComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/ChemicalAmmoComponent.cs index bf3c1defb7..996f7042aa 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/ChemicalAmmoComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/ChemicalAmmoComponent.cs @@ -4,6 +4,8 @@ using Robust.Shared.GameObjects; using Robust.Shared.Serialization; using System.Collections.Generic; using System.Linq; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition { @@ -12,13 +14,8 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition { public override string Name => "ChemicalAmmo"; - private float _fractionTransfered; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _fractionTransfered, "fractionTransfered", 1); - } + [DataField("fractionTransfered")] + private float _fractionTransfered = 1; public override void HandleMessage(ComponentMessage message, IComponent component) { diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/RangedMagazineComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/RangedMagazineComponent.cs index 7cb2111230..42cd9a96de 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/RangedMagazineComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/RangedMagazineComponent.cs @@ -12,7 +12,9 @@ using Robust.Server.GameObjects; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Localization; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition @@ -27,30 +29,25 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition public int ShotsLeft => _spawnedAmmo.Count + _unspawnedCount; public int Capacity => _capacity; - private int _capacity; + [DataField("capacity")] + private int _capacity = 20; public MagazineType MagazineType => _magazineType; - private MagazineType _magazineType; + [DataField("magazineType")] + private MagazineType _magazineType = MagazineType.Unspecified; public BallisticCaliber Caliber => _caliber; - private BallisticCaliber _caliber; + [DataField("caliber")] + private BallisticCaliber _caliber = BallisticCaliber.Unspecified; private AppearanceComponent _appearanceComponent; // If there's anything already in the magazine + [DataField("fillPrototype")] private string _fillPrototype; // By default the magazine won't spawn the entity until needed so we need to keep track of how many left we can spawn // Generally you probablt don't want to use this private int _unspawnedCount; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _magazineType, "magazineType", MagazineType.Unspecified); - serializer.DataField(ref _caliber, "caliber", BallisticCaliber.Unspecified); - serializer.DataField(ref _fillPrototype, "fillPrototype", null); - serializer.DataField(ref _capacity, "capacity", 20); - } - void IMapInit.MapInit() { if (_fillPrototype != null) diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/SpeedLoaderComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/SpeedLoaderComponent.cs index 6c159aed26..61da797f84 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/SpeedLoaderComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Ammunition/SpeedLoaderComponent.cs @@ -10,7 +10,9 @@ using Robust.Server.GameObjects; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Localization; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition { @@ -22,26 +24,19 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition { public override string Name => "SpeedLoader"; - private BallisticCaliber _caliber; + [DataField("caliber")] + private BallisticCaliber _caliber = BallisticCaliber.Unspecified; public int Capacity => _capacity; - private int _capacity; + [DataField("capacity")] + private int _capacity = 6; private Container _ammoContainer; - private Stack _spawnedAmmo; + private Stack _spawnedAmmo = new(); private int _unspawnedCount; public int AmmoLeft => _spawnedAmmo.Count + _unspawnedCount; - private string _fillPrototype; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _caliber, "caliber", BallisticCaliber.Unspecified); - serializer.DataField(ref _capacity, "capacity", 6); - serializer.DataField(ref _fillPrototype, "fillPrototype", null); - - _spawnedAmmo = new Stack(_capacity); - } + [DataField("fillPrototype")] + private string _fillPrototype = default; public override void Initialize() { diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/BoltActionBarrelComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/BoltActionBarrelComponent.cs index 32a82fe162..700b358803 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/BoltActionBarrelComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/BoltActionBarrelComponent.cs @@ -15,7 +15,7 @@ using Robust.Shared.GameObjects; using Robust.Shared.Localization; using Robust.Shared.Map; using Robust.Shared.Players; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -42,16 +42,19 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels } } public override int Capacity => _capacity; - private int _capacity; + [DataField("capacity")] + private int _capacity = 6; private ContainerSlot _chamberContainer; private Stack _spawnedAmmo; private Container _ammoContainer; [ViewVariables] - private BallisticCaliber _caliber; + [DataField("caliber")] + private BallisticCaliber _caliber = BallisticCaliber.Unspecified; [ViewVariables] + [DataField("fillPrototype")] private string _fillPrototype; [ViewVariables] private int _unspawnedCount; @@ -91,28 +94,19 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels } } private bool _boltOpen; + [DataField("autoCycle")] private bool _autoCycle; private AppearanceComponent _appearanceComponent; // Sounds - private string _soundCycle; - private string _soundBoltOpen; - private string _soundBoltClosed; - private string _soundInsert; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _caliber, "caliber", BallisticCaliber.Unspecified); - serializer.DataField(ref _capacity, "capacity", 6); - serializer.DataField(ref _fillPrototype, "fillPrototype", null); - serializer.DataField(ref _autoCycle, "autoCycle", false); - - serializer.DataField(ref _soundCycle, "soundCycle", "/Audio/Weapons/Guns/Cock/sf_rifle_cock.ogg"); - serializer.DataField(ref _soundBoltOpen, "soundBoltOpen", "/Audio/Weapons/Guns/Bolt/rifle_bolt_open.ogg"); - serializer.DataField(ref _soundBoltClosed, "soundBoltClosed", "/Audio/Weapons/Guns/Bolt/rifle_bolt_closed.ogg"); - serializer.DataField(ref _soundInsert, "soundInsert", "/Audio/Weapons/Guns/MagIn/bullet_insert.ogg"); - } + [DataField("soundCycle")] + private string _soundCycle = "/Audio/Weapons/Guns/Cock/sf_rifle_cock.ogg"; + [DataField("soundBoltOpen")] + private string _soundBoltOpen = "/Audio/Weapons/Guns/Bolt/rifle_bolt_open.ogg"; + [DataField("soundBoltClosed")] + private string _soundBoltClosed = "/Audio/Weapons/Guns/Bolt/rifle_bolt_closed.ogg"; + [DataField("soundInsert")] + private string _soundInsert = "/Audio/Weapons/Guns/MagIn/bullet_insert.ogg"; void IMapInit.MapInit() { diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/PumpBarrelComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/PumpBarrelComponent.cs index c90540a67c..37b61444e3 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/PumpBarrelComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/PumpBarrelComponent.cs @@ -3,7 +3,6 @@ using System.Threading.Tasks; using Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition; using Content.Shared.GameObjects; using Content.Shared.GameObjects.Components.Weapons.Ranged.Barrels; -using Content.Shared.GameObjects.EntitySystems; using Content.Shared.Interfaces; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Server.GameObjects; @@ -14,6 +13,7 @@ using Robust.Shared.Localization; using Robust.Shared.Map; using Robust.Shared.Players; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -23,7 +23,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels /// Bolt-action rifles /// [RegisterComponent] - public sealed class PumpBarrelComponent : ServerRangedBarrelComponent, IMapInit, IExamine + public sealed class PumpBarrelComponent : ServerRangedBarrelComponent, IMapInit, ISerializationHooks { public override string Name => "PumpBarrel"; public override uint? NetID => ContentNetIDs.PUMP_BARREL; @@ -37,43 +37,36 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels } } - public override int Capacity => _capacity; - private int _capacity; + private const int DefaultCapacity = 6; + [field: DataField("capacity")] + public override int Capacity { get; } = DefaultCapacity; // Even a point having a chamber? I guess it makes some of the below code cleaner private ContainerSlot _chamberContainer; - private Stack _spawnedAmmo; + private Stack _spawnedAmmo = new (DefaultCapacity-1); private Container _ammoContainer; [ViewVariables] - private BallisticCaliber _caliber; + [DataField("caliber")] + private BallisticCaliber _caliber = BallisticCaliber.Unspecified; [ViewVariables] + [DataField("fillPrototype")] private string _fillPrototype; [ViewVariables] private int _unspawnedCount; - private bool _manualCycle; + [DataField("manualCycle")] + private bool _manualCycle = true; private AppearanceComponent _appearanceComponent; // Sounds - private string _soundCycle; - private string _soundInsert; + [DataField("soundCycle")] + private string _soundCycle = "/Audio/Weapons/Guns/Cock/sf_rifle_cock.ogg"; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _caliber, "caliber", BallisticCaliber.Unspecified); - serializer.DataField(ref _capacity, "capacity", 6); - serializer.DataField(ref _fillPrototype, "fillPrototype", null); - serializer.DataField(ref _manualCycle, "manualCycle", true); - - serializer.DataField(ref _soundCycle, "soundCycle", "/Audio/Weapons/Guns/Cock/sf_rifle_cock.ogg"); - serializer.DataField(ref _soundInsert, "soundInsert", "/Audio/Weapons/Guns/MagIn/bullet_insert.ogg"); - - _spawnedAmmo = new Stack(_capacity - 1); - } + [DataField("soundInsert")] + private string _soundInsert = "/Audio/Weapons/Guns/MagIn/bullet_insert.ogg"; void IMapInit.MapInit() { @@ -101,6 +94,11 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels SoundGunshot); } + void ISerializationHooks.AfterDeserialization() + { + _spawnedAmmo = new Stack(Capacity - 1); + } + public override void Initialize() { base.Initialize(); diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/RevolverBarrelComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/RevolverBarrelComponent.cs index daf0c1996f..33992c63ca 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/RevolverBarrelComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/RevolverBarrelComponent.cs @@ -17,12 +17,13 @@ using Robust.Shared.Map; using Robust.Shared.Players; using Robust.Shared.Random; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels { [RegisterComponent] - public sealed class RevolverBarrelComponent : ServerRangedBarrelComponent + public sealed class RevolverBarrelComponent : ServerRangedBarrelComponent, ISerializationHooks { [Dependency] private readonly IRobustRandom _random = default!; @@ -30,42 +31,49 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels public override uint? NetID => ContentNetIDs.REVOLVER_BARREL; [ViewVariables] - private BallisticCaliber _caliber; + [DataField("caliber")] + private BallisticCaliber _caliber = BallisticCaliber.Unspecified; + private Container _ammoContainer; + [ViewVariables] - private int _currentSlot = 0; + private int _currentSlot; + public override int Capacity => _ammoSlots.Length; - private IEntity[] _ammoSlots; + + [DataField("capacity")] + private int _serializedCapacity = 6; + + [DataField("ammoSlots", readOnly: true)] + private IEntity[] _ammoSlots = Array.Empty(); public override int ShotsLeft => _ammoContainer.ContainedEntities.Count; - private AppearanceComponent _appearanceComponent; [ViewVariables] + [DataField("fillPrototype")] private string _fillPrototype; + [ViewVariables] private int _unspawnedCount; // Sounds - private string _soundEject; - private string _soundInsert; - private string _soundSpin; + [DataField("soundEject")] + private string _soundEject = "/Audio/Weapons/Guns/MagOut/revolver_magout.ogg"; - public override void ExposeData(ObjectSerializer serializer) + [DataField("soundInsert")] + private string _soundInsert = "/Audio/Weapons/Guns/MagIn/revolver_magin.ogg"; + + [DataField("soundSpin")] + private string _soundSpin = "/Audio/Weapons/Guns/Misc/revolver_spin.ogg"; + + void ISerializationHooks.BeforeSerialization() { - base.ExposeData(serializer); + _serializedCapacity = _ammoSlots.Length; + } - serializer.DataField(ref _caliber, "caliber", BallisticCaliber.Unspecified); - serializer.DataReadWriteFunction( - "capacity", - 6, - cap => _ammoSlots = new IEntity[cap], - () => _ammoSlots.Length); - serializer.DataField(ref _fillPrototype, "fillPrototype", null); - - // Sounds - serializer.DataField(ref _soundEject, "soundEject", "/Audio/Weapons/Guns/MagOut/revolver_magout.ogg"); - serializer.DataField(ref _soundInsert, "soundInsert", "/Audio/Weapons/Guns/MagIn/revolver_magin.ogg"); - serializer.DataField(ref _soundSpin, "soundSpin", "/Audio/Weapons/Guns/Misc/revolver_spin.ogg"); + void ISerializationHooks.AfterDeserialization() + { + _ammoSlots = new IEntity[_serializedCapacity]; } public override ComponentState GetComponentState(ICommonSession player) @@ -112,21 +120,21 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels idx++; } - if (Owner.TryGetComponent(out AppearanceComponent appearanceComponent)) - { - _appearanceComponent = appearanceComponent; - } - UpdateAppearance(); Dirty(); } private void UpdateAppearance() { + if (!Owner.TryGetComponent(out AppearanceComponent appearance)) + { + return; + } + // Placeholder, at this stage it's just here for the RPG - _appearanceComponent?.SetData(MagazineBarrelVisuals.MagLoaded, ShotsLeft > 0); - _appearanceComponent?.SetData(AmmoVisuals.AmmoCount, ShotsLeft); - _appearanceComponent?.SetData(AmmoVisuals.AmmoMax, Capacity); + appearance.SetData(MagazineBarrelVisuals.MagLoaded, ShotsLeft > 0); + appearance.SetData(AmmoVisuals.AmmoCount, ShotsLeft); + appearance.SetData(AmmoVisuals.AmmoMax, Capacity); } public bool TryInsertBullet(IEntity user, IEntity entity) diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerBatteryBarrelComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerBatteryBarrelComponent.cs index 4d21579723..5715f260b0 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerBatteryBarrelComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerBatteryBarrelComponent.cs @@ -18,7 +18,7 @@ using Robust.Shared.GameObjects; using Robust.Shared.Localization; using Robust.Shared.Map; using Robust.Shared.Players; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels @@ -30,17 +30,22 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels public override uint? NetID => ContentNetIDs.BATTERY_BARREL; // The minimum change we need before we can fire - [ViewVariables] private float _lowerChargeLimit; - [ViewVariables] private int _baseFireCost; + [DataField("lowerChargeLimit")] + [ViewVariables] private float _lowerChargeLimit = 10; + [DataField("fireCost")] + [ViewVariables] private int _baseFireCost = 300; // What gets fired + [DataField("ammoPrototype")] [ViewVariables] private string _ammoPrototype; [ViewVariables] public IEntity PowerCellEntity => _powerCellContainer.ContainedEntity; public BatteryComponent PowerCell => _powerCellContainer.ContainedEntity?.GetComponent(); private ContainerSlot _powerCellContainer; private ContainerSlot _ammoContainer; - private string _powerCellPrototype; - [ViewVariables] private bool _powerCellRemovable; + [DataField("powerCellPrototype")] + private string _powerCellPrototype = default; + [DataField("powerCellRemovable")] + [ViewVariables] private bool _powerCellRemovable = default; public override int ShotsLeft { @@ -75,21 +80,10 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels private AppearanceComponent _appearanceComponent; // Sounds - private string _soundPowerCellInsert; - private string _soundPowerCellEject; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _powerCellPrototype, "powerCellPrototype", null); - serializer.DataField(ref _powerCellRemovable, "powerCellRemovable", false); - serializer.DataField(ref _baseFireCost, "fireCost", 300); - serializer.DataField(ref _ammoPrototype, "ammoPrototype", null); - serializer.DataField(ref _lowerChargeLimit, "lowerChargeLimit", 10); - serializer.DataField(ref _soundPowerCellInsert, "soundPowerCellInsert", null); - serializer.DataField(ref _soundPowerCellEject, "soundPowerCellEject", null); - } + [DataField("soundPowerCellInsert")] + private string _soundPowerCellInsert = default; + [DataField("soundPowerCellEject")] + private string _soundPowerCellEject = default; public override ComponentState GetComponentState(ICommonSession player) { diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerMagazineBarrelComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerMagazineBarrelComponent.cs index a7f0ffe9ea..3fb10170e7 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerMagazineBarrelComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerMagazineBarrelComponent.cs @@ -19,7 +19,7 @@ using Robust.Shared.GameObjects; using Robust.Shared.Localization; using Robust.Shared.Map; using Robust.Shared.Players; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -37,9 +37,11 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels private ContainerSlot _magazineContainer; [ViewVariables] public MagazineType MagazineTypes => _magazineTypes; - private MagazineType _magazineTypes; + [DataField("magazineTypes")] + private MagazineType _magazineTypes = default; [ViewVariables] public BallisticCaliber Caliber => _caliber; - private BallisticCaliber _caliber; + [DataField("caliber")] + private BallisticCaliber _caliber = BallisticCaliber.Unspecified; public override int ShotsLeft { @@ -77,6 +79,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels } } + [DataField("magFillPrototype")] private string _magFillPrototype; public bool BoltOpen @@ -115,40 +118,28 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels } private bool _boltOpen = true; + [DataField("autoEjectMag")] private bool _autoEjectMag; // If the bolt needs to be open before we can insert / remove the mag (i.e. for LMGs) public bool MagNeedsOpenBolt => _magNeedsOpenBolt; - private bool _magNeedsOpenBolt; + [DataField("magNeedsOpenBolt")] + private bool _magNeedsOpenBolt = default; private AppearanceComponent _appearanceComponent; // Sounds - private string _soundBoltOpen; - private string _soundBoltClosed; - private string _soundRack; - private string _soundMagInsert; - private string _soundMagEject; - private string _soundAutoEject; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataReadWriteFunction( - "magazineTypes", - new List(), - types => types.ForEach(mag => _magazineTypes |= mag), GetMagazineTypes); - serializer.DataField(ref _caliber, "caliber", BallisticCaliber.Unspecified); - serializer.DataField(ref _magFillPrototype, "magFillPrototype", null); - serializer.DataField(ref _autoEjectMag, "autoEjectMag", false); - serializer.DataField(ref _magNeedsOpenBolt, "magNeedsOpenBolt", false); - serializer.DataField(ref _soundBoltOpen, "soundBoltOpen", null); - serializer.DataField(ref _soundBoltClosed, "soundBoltClosed", null); - serializer.DataField(ref _soundRack, "soundRack", null); - serializer.DataField(ref _soundMagInsert, "soundMagInsert", null); - serializer.DataField(ref _soundMagEject, "soundMagEject", null); - serializer.DataField(ref _soundAutoEject, "soundAutoEject", "/Audio/Weapons/Guns/EmptyAlarm/smg_empty_alarm.ogg"); - } + [DataField("soundBoltOpen")] + private string _soundBoltOpen = default; + [DataField("soundBoltClosed")] + private string _soundBoltClosed = default; + [DataField("soundRack")] + private string _soundRack = default; + [DataField("soundMagInsert")] + private string _soundMagInsert = default; + [DataField("soundMagEject")] + private string _soundMagEject = default; + [DataField("soundAutoEject")] + private string _soundAutoEject = "/Audio/Weapons/Guns/EmptyAlarm/smg_empty_alarm.ogg"; private List GetMagazineTypes() { @@ -535,7 +526,6 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels [Flags] public enum MagazineType { - Unspecified = 0, LPistol = 1 << 0, // Placeholder? Pistol = 1 << 1, diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerRangedBarrelComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerRangedBarrelComponent.cs index 5604a1fe77..fc0eed269d 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerRangedBarrelComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerRangedBarrelComponent.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -24,6 +24,7 @@ using Robust.Shared.Player; using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Timing; using Robust.Shared.Utility; @@ -33,7 +34,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels /// All of the ranged weapon components inherit from this to share mechanics like shooting etc. /// Only difference between them is how they retrieve a projectile to shoot (battery, magazine, etc.) /// - public abstract class ServerRangedBarrelComponent : SharedRangedBarrelComponent, IUse, IInteractUsing, IExamine + public abstract class ServerRangedBarrelComponent : SharedRangedBarrelComponent, IUse, IInteractUsing, IExamine, ISerializationHooks { // There's still some of py01 and PJB's work left over, especially in underlying shooting logic, // it's just when I re-organised it changed me as the contributor @@ -41,11 +42,17 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels [Dependency] private readonly IRobustRandom _robustRandom = default!; public override FireRateSelector FireRateSelector => _fireRateSelector; - private FireRateSelector _fireRateSelector; + + [DataField("currentSelector")] + private FireRateSelector _fireRateSelector = FireRateSelector.Safety; + public override FireRateSelector AllRateSelectors => _fireRateSelector; + + [DataField("allSelectors")] private FireRateSelector _allRateSelectors; - public override float FireRate => _fireRate; - private float _fireRate; + + [field: DataField("fireRate")] + public override float FireRate { get; } = 2f; // _lastFire is when we actually fired (so if we hold the button then recoil doesn't build up if we're not firing) private TimeSpan _lastFire; @@ -54,100 +61,76 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels public abstract IEntity TakeProjectile(EntityCoordinates spawnAt); // Recoil / spray control - private Angle _minAngle; - private Angle _maxAngle; + [DataField("minAngle")] + private float _minAngleDegrees; + + public Angle MinAngle { get; private set; } + + [DataField("maxAngle")] + private float _maxAngleDegrees = 45; + + public Angle MaxAngle { get; private set; } + private Angle _currentAngle = Angle.Zero; + + [DataField("angleDecay")] + private float _angleDecayDegrees = 20; + /// /// How slowly the angle's theta decays per second in radians /// - private float _angleDecay; + public float AngleDecay { get; private set; } + + [DataField("angleIncrease")] + private float? _angleIncreaseDegrees; + /// /// How quickly the angle's theta builds for every shot fired in radians /// - private float _angleIncrease; - // Multiplies the ammo spread to get the final spread of each pellet - private float _spreadRatio; + public float AngleIncrease { get; private set; } - public bool CanMuzzleFlash => _canMuzzleFlash; - private bool _canMuzzleFlash = true; + // Multiplies the ammo spread to get the final spread of each pellet + [DataField("ammoSpreadRatio")] + public float SpreadRatio { get; private set; } + + [field: DataField("canMuzzleFlash")] + public bool CanMuzzleFlash { get; } = true; // Sounds - public string SoundGunshot + [field: DataField("soundGunshot")] + public string SoundGunshot { get; set; } + + [field: DataField("soundEmpty")] + public string SoundEmpty { get; } = "/Audio/Weapons/Guns/Empty/empty.ogg"; + + void ISerializationHooks.BeforeSerialization() { - get => _soundGunshot; - set => _soundGunshot = value; + _minAngleDegrees = (float) (MinAngle.Degrees * 2); + _maxAngleDegrees = (float) (MaxAngle.Degrees * 2); + _angleIncreaseDegrees = MathF.Round(AngleIncrease / ((float) Math.PI / 180f), 2); + AngleDecay = MathF.Round(AngleDecay / ((float) Math.PI / 180f), 2); } - private string _soundGunshot; - public string SoundEmpty => _soundEmpty; - private string _soundEmpty; - public override void ExposeData(ObjectSerializer serializer) + void ISerializationHooks.AfterDeserialization() { - base.ExposeData(serializer); - - serializer.DataField(ref _fireRateSelector, "currentSelector", FireRateSelector.Safety); - serializer.DataField(ref _fireRate, "fireRate", 2.0f); - // This hard-to-read area's dealing with recoil // Use degrees in yaml as it's easier to read compared to "0.0125f" - serializer.DataReadWriteFunction( - "minAngle", - 0, - angle => _minAngle = Angle.FromDegrees(angle / 2f), - () => _minAngle.Degrees * 2); + MinAngle = Angle.FromDegrees(_minAngleDegrees / 2f); // Random doubles it as it's +/- so uhh we'll just half it here for readability - serializer.DataReadWriteFunction( - "maxAngle", - 45, - angle => _maxAngle = Angle.FromDegrees(angle / 2f), - () => _maxAngle.Degrees * 2); + MaxAngle = Angle.FromDegrees(_maxAngleDegrees / 2f); - serializer.DataReadWriteFunction( - "angleIncrease", - 40 / _fireRate, - angle => _angleIncrease = angle * (float) Math.PI / 180f, - () => MathF.Round(_angleIncrease / ((float) Math.PI / 180f), 2)); + _angleIncreaseDegrees ??= 40 / FireRate; + AngleIncrease = _angleIncreaseDegrees.Value * (float) Math.PI / 180f; - serializer.DataReadWriteFunction( - "angleDecay", - 20f, - angle => _angleDecay = angle * (float) Math.PI / 180f, - () => MathF.Round(_angleDecay / ((float) Math.PI / 180f), 2)); - - serializer.DataField(ref _spreadRatio, "ammoSpreadRatio", 1.0f); - - serializer.DataReadWriteFunction( - "allSelectors", - new List(), - selectors => selectors.ForEach(selector => _allRateSelectors |= selector), - () => - { - var types = new List(); - - foreach (FireRateSelector selector in Enum.GetValues(typeof(FireRateSelector))) - { - if ((_allRateSelectors & selector) != 0) - { - types.Add(selector); - } - } - - return types; - }); + AngleDecay = _angleDecayDegrees * (float) Math.PI / 180f; // For simplicity we'll enforce it this way; ammo determines max spread - if (_spreadRatio > 1.0f) + if (SpreadRatio > 1.0f) { Logger.Error("SpreadRatio must be <= 1.0f for guns"); throw new InvalidOperationException(); } - - serializer.DataField(ref _canMuzzleFlash, "canMuzzleFlash", true); - - // Sounds - serializer.DataField(ref _soundGunshot, "soundGunshot", null); - serializer.DataField(ref _soundEmpty, "soundEmpty", "/Audio/Weapons/Guns/Empty/empty.ogg"); } public override void OnAdd() @@ -176,7 +159,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels { var currentTime = _gameTiming.CurTime; var timeSinceLastFire = (currentTime - _lastFire).TotalSeconds; - var newTheta = MathHelper.Clamp(_currentAngle.Theta + _angleIncrease - _angleDecay * timeSinceLastFire, _minAngle.Theta, _maxAngle.Theta); + var newTheta = MathHelper.Clamp(_currentAngle.Theta + AngleIncrease - AngleDecay * timeSinceLastFire, MinAngle.Theta, MaxAngle.Theta); _currentAngle = new Angle(newTheta); var random = (_robustRandom.NextDouble() - 0.5) * 2; @@ -214,9 +197,9 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels { if (ShotsLeft == 0) { - if (_soundEmpty != null) + if (SoundEmpty != null) { - SoundSystem.Play(Filter.Broadcast(), _soundEmpty, Owner.Transform.Coordinates); + SoundSystem.Play(Filter.Broadcast(), SoundEmpty, Owner.Transform.Coordinates); } return; } @@ -225,7 +208,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels var projectile = TakeProjectile(shooter.Transform.Coordinates); if (projectile == null) { - SoundSystem.Play(Filter.Broadcast(), _soundEmpty, Owner.Transform.Coordinates); + SoundSystem.Play(Filter.Broadcast(), SoundEmpty, Owner.Transform.Coordinates); return; } @@ -266,7 +249,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels throw new InvalidOperationException(); } - SoundSystem.Play(Filter.Broadcast(), _soundGunshot, Owner.Transform.Coordinates); + SoundSystem.Play(Filter.Broadcast(), SoundGunshot, Owner.Transform.Coordinates); _lastFire = _gameTiming.CurTime; return; @@ -352,7 +335,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels List sprayAngleChange = null; if (count > 1) { - evenSpreadAngle *= _spreadRatio; + evenSpreadAngle *= SpreadRatio; sprayAngleChange = Linspace(-evenSpreadAngle / 2, evenSpreadAngle / 2, count); } diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/ServerRangedWeaponComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/ServerRangedWeaponComponent.cs index 1953361f91..296c586ede 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/ServerRangedWeaponComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/ServerRangedWeaponComponent.cs @@ -18,8 +18,8 @@ using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Network; using Robust.Shared.Players; -using Robust.Shared.Serialization; using Robust.Shared.Timing; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Weapon.Ranged @@ -33,9 +33,12 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged private TimeSpan _lastFireTime; [ViewVariables(VVAccess.ReadWrite)] - public bool ClumsyCheck { get; set; } + [DataField("clumsyCheck")] + public bool ClumsyCheck { get; set; } = true; + [ViewVariables(VVAccess.ReadWrite)] - public float ClumsyExplodeChance { get; set; } + [DataField("clumsyExplodeChance")] + public float ClumsyExplodeChance { get; set; } = 0.5f; public Func WeaponCanFireHandler; public Func UserCanFireHandler; @@ -70,14 +73,6 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged return (UserCanFireHandler == null || UserCanFireHandler(user)) && ActionBlockerSystem.CanAttack(user); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, p => p.ClumsyCheck, "clumsyCheck", true); - serializer.DataField(this, p => p.ClumsyExplodeChance, "clumsyExplodeChance", 0.5f); - } - /// public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession session = null) { diff --git a/Content.Server/GameObjects/Components/WindowComponent.cs b/Content.Server/GameObjects/Components/WindowComponent.cs index d7902c03b6..6d7707ef98 100644 --- a/Content.Server/GameObjects/Components/WindowComponent.cs +++ b/Content.Server/GameObjects/Components/WindowComponent.cs @@ -13,8 +13,10 @@ using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; using Robust.Shared.Timing; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -28,17 +30,11 @@ namespace Content.Server.GameObjects.Components [ViewVariables(VVAccess.ReadWrite)] private TimeSpan _lastKnockTime; - [ViewVariables(VVAccess.ReadWrite)] private TimeSpan _knockDelay; + [DataField("knockDelay")] [ViewVariables(VVAccess.ReadWrite)] + private TimeSpan _knockDelay = TimeSpan.FromSeconds(0.5); - [ViewVariables(VVAccess.ReadWrite)] private bool _rateLimitedKnocking; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _knockDelay, "knockDelay", TimeSpan.FromSeconds(0.5)); - serializer.DataField(ref _rateLimitedKnocking, "rateLimitedKnocking", true); - } + [DataField("rateLimitedKnocking")] + [ViewVariables(VVAccess.ReadWrite)] private bool _rateLimitedKnocking = true; public override void HandleMessage(ComponentMessage message, IComponent? component) { diff --git a/Content.Server/GameObjects/Components/WiresComponent.cs b/Content.Server/GameObjects/Components/WiresComponent.cs index e06fe4c022..8bc9c36ec7 100644 --- a/Content.Server/GameObjects/Components/WiresComponent.cs +++ b/Content.Server/GameObjects/Components/WiresComponent.cs @@ -20,8 +20,10 @@ using Robust.Server.Player; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; +using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -130,16 +132,20 @@ namespace Content.Server.GameObjects.Components private readonly List _availableLetters = new((WireLetter[]) Enum.GetValues(typeof(WireLetter))); - private string _boardName = default!; + [DataField("BoardName")] + private string _boardName = "Wires"; + [DataField("SerialNumber")] private string? _serialNumber; // Used to generate wire appearance randomization client side. // We honestly don't care what it is or such but do care that it doesn't change between UI re-opens. [ViewVariables] + [DataField("WireSeed")] private int _wireSeed; [ViewVariables] - private string? _layoutId; + [DataField("LayoutId")] + private string? _layoutId = default; [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(WiresUiKey.Key); @@ -469,16 +475,6 @@ namespace Content.Server.GameObjects.Components _wireSeed)); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _boardName, "BoardName", "Wires"); - serializer.DataField(ref _serialNumber, "SerialNumber", null); - serializer.DataField(ref _wireSeed, "WireSeed", 0); - serializer.DataField(ref _layoutId, "LayoutId", null); - } - async Task IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs) { if (!eventArgs.Using.TryGetComponent(out var tool)) diff --git a/Content.Server/Holiday/Greet/Custom.cs b/Content.Server/Holiday/Greet/Custom.cs index bf28cc72a0..2013ea8d7f 100644 --- a/Content.Server/Holiday/Greet/Custom.cs +++ b/Content.Server/Holiday/Greet/Custom.cs @@ -1,18 +1,14 @@ using Content.Server.Holiday.Interfaces; using JetBrains.Annotations; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Holiday.Greet { [UsedImplicitly] + [DataDefinition] public class Custom : IHolidayGreet { - private string _greet; - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(ref _greet, "text", string.Empty); - } + [DataField("text")] private string _greet = string.Empty; public string Greet(HolidayPrototype holiday) { diff --git a/Content.Server/Holiday/HolidayPrototype.cs b/Content.Server/Holiday/HolidayPrototype.cs index 49750e717c..7d9ada4894 100644 --- a/Content.Server/Holiday/HolidayPrototype.cs +++ b/Content.Server/Holiday/HolidayPrototype.cs @@ -5,57 +5,54 @@ using Content.Server.Holiday.Greet; using Content.Server.Holiday.Interfaces; using Content.Server.Holiday.ShouldCelebrate; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; -using YamlDotNet.RepresentationModel; namespace Content.Server.Holiday { [Prototype("holiday")] public class HolidayPrototype : IPrototype { - [ViewVariables] public string Name { get; private set; } = string.Empty; - [ViewVariables] public string ID { get; private set; } = string.Empty; - [ViewVariables] public byte BeginDay { get; set; } = 1; - [ViewVariables] public Month BeginMonth { get; set; } = Month.Invalid; + [ViewVariables] [DataField("name")] public string Name { get; private set; } = string.Empty; + + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; + + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } + + [ViewVariables] + [DataField("beginDay")] + public byte BeginDay { get; set; } = 1; + + [ViewVariables] + [DataField("beginMonth")] + public Month BeginMonth { get; set; } = Month.Invalid; /// /// Day this holiday will end. Zero means it lasts a single day. /// - [ViewVariables] public byte EndDay { get; set; } = 0; + [ViewVariables] + [DataField("endDay")] + public byte EndDay { get; set; } /// /// Month this holiday will end in. Invalid means it lasts a single month. /// - [ViewVariables] public Month EndMonth { get; set; } = Month.Invalid; - [ViewVariables] - private IHolidayShouldCelebrate _shouldCelebrate = new DefaultHolidayShouldCelebrate(); + [DataField("endMonth")] + public Month EndMonth { get; set; } = Month.Invalid; - [ViewVariables] - private IHolidayGreet _greet = new DefaultHolidayGreet(); + [ViewVariables] [DataField("shouldCelebrate")] + private readonly IHolidayShouldCelebrate _shouldCelebrate = new DefaultHolidayShouldCelebrate(); - [ViewVariables] - private IHolidayCelebrate _celebrate = new DefaultHolidayCelebrate(); + [ViewVariables] [DataField("greet")] + private readonly IHolidayGreet _greet = new DefaultHolidayGreet(); - public void LoadFrom(YamlMappingNode mapping) - { - var serializer = YamlObjectSerializer.NewReader(mapping); - ExposeData(serializer); - } - - public void ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.ID, "id", string.Empty); - serializer.DataField(this, x => x.Name, "name", string.Empty); - serializer.DataField(this, x => x.BeginDay, "beginDay", (byte)1); - serializer.DataField(this, x => x.BeginMonth, "beginMonth", Month.Invalid); - serializer.DataField(this, x => x.EndDay, "endDay", (byte)0); - serializer.DataField(this, x => x.EndMonth, "endMonth", Month.Invalid); - serializer.DataField(ref _shouldCelebrate, "shouldCelebrate", new DefaultHolidayShouldCelebrate()); - serializer.DataField(ref _greet, "greet", new DefaultHolidayGreet()); - serializer.DataField(ref _celebrate, "celebrate", new DefaultHolidayCelebrate()); - } + [ViewVariables] [DataField("celebrate")] + private readonly IHolidayCelebrate _celebrate = new DefaultHolidayCelebrate(); public bool ShouldCelebrate(DateTime date) { diff --git a/Content.Server/Holiday/Interfaces/IHolidayCelebrate.cs b/Content.Server/Holiday/Interfaces/IHolidayCelebrate.cs index da6f15584c..415f37b508 100644 --- a/Content.Server/Holiday/Interfaces/IHolidayCelebrate.cs +++ b/Content.Server/Holiday/Interfaces/IHolidayCelebrate.cs @@ -1,11 +1,7 @@ -using Robust.Shared.Serialization; - namespace Content.Server.Holiday.Interfaces { - public interface IHolidayCelebrate : IExposeData + public interface IHolidayCelebrate { - void IExposeData.ExposeData(ObjectSerializer serializer) {} - /// /// This method is called before a round starts. /// Use it to do any fun festive modifications. diff --git a/Content.Server/Holiday/Interfaces/IHolidayGreet.cs b/Content.Server/Holiday/Interfaces/IHolidayGreet.cs index edd81abe68..8628eda705 100644 --- a/Content.Server/Holiday/Interfaces/IHolidayGreet.cs +++ b/Content.Server/Holiday/Interfaces/IHolidayGreet.cs @@ -1,10 +1,7 @@ -using Robust.Shared.Serialization; - namespace Content.Server.Holiday.Interfaces { - public interface IHolidayGreet : IExposeData + public interface IHolidayGreet { - void IExposeData.ExposeData(ObjectSerializer serializer) { } string Greet(HolidayPrototype holiday); } } diff --git a/Content.Server/Holiday/Interfaces/IHolidayShouldCelebrate.cs b/Content.Server/Holiday/Interfaces/IHolidayShouldCelebrate.cs index 99c0ddd120..cf1f249fe4 100644 --- a/Content.Server/Holiday/Interfaces/IHolidayShouldCelebrate.cs +++ b/Content.Server/Holiday/Interfaces/IHolidayShouldCelebrate.cs @@ -1,11 +1,11 @@ using System; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Holiday.Interfaces { - public interface IHolidayShouldCelebrate : IExposeData + [ImplicitDataDefinitionForInheritors] + public interface IHolidayShouldCelebrate { - void IExposeData.ExposeData(ObjectSerializer serializer) {} bool ShouldCelebrate(DateTime date, HolidayPrototype holiday); } } diff --git a/Content.Server/Holiday/ShouldCelebrate/Computus.cs b/Content.Server/Holiday/ShouldCelebrate/Computus.cs index a1c16cdb13..311807aae9 100644 --- a/Content.Server/Holiday/ShouldCelebrate/Computus.cs +++ b/Content.Server/Holiday/ShouldCelebrate/Computus.cs @@ -1,7 +1,7 @@ using System; using System.IO; using JetBrains.Annotations; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Holiday.ShouldCelebrate { @@ -9,16 +9,14 @@ namespace Content.Server.Holiday.ShouldCelebrate /// Computus for easter calculation. /// [UsedImplicitly] - public class Computus : DefaultHolidayShouldCelebrate, IExposeData + [DataDefinition] + public class Computus : DefaultHolidayShouldCelebrate { + [DataField("daysEarly")] private byte _daysEarly = 1; - private byte _daysExtra = 1; - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(ref _daysEarly, "daysEarly", (byte) 1); - serializer.DataField(ref _daysExtra, "daysExtra", (byte) 1); - } + [DataField("daysExtra")] + private byte _daysExtra = 1; public (int day, int month) DoComputus(DateTime date) { diff --git a/Content.Server/Holiday/ShouldCelebrate/DayOfYear.cs b/Content.Server/Holiday/ShouldCelebrate/DayOfYear.cs index 9b4cf49691..c62c56fb1d 100644 --- a/Content.Server/Holiday/ShouldCelebrate/DayOfYear.cs +++ b/Content.Server/Holiday/ShouldCelebrate/DayOfYear.cs @@ -1,7 +1,7 @@ using System; using Content.Server.Holiday.Interfaces; using JetBrains.Annotations; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Holiday.ShouldCelebrate { @@ -9,14 +9,11 @@ namespace Content.Server.Holiday.ShouldCelebrate /// For a holiday that occurs on a certain day of the year. /// [UsedImplicitly] + [DataDefinition] public class DayOfYear : IHolidayShouldCelebrate { - private uint _dayOfYear; - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(ref _dayOfYear, "dayOfYear", 1u); - } + [DataField("dayOfYear")] + private uint _dayOfYear = 1; public bool ShouldCelebrate(DateTime date, HolidayPrototype holiday) { diff --git a/Content.Server/Holiday/ShouldCelebrate/WeekdayInMonth.cs b/Content.Server/Holiday/ShouldCelebrate/WeekdayInMonth.cs index 660bdb4bc6..425e0ed2ed 100644 --- a/Content.Server/Holiday/ShouldCelebrate/WeekdayInMonth.cs +++ b/Content.Server/Holiday/ShouldCelebrate/WeekdayInMonth.cs @@ -1,7 +1,7 @@ using System; using System.Globalization; using JetBrains.Annotations; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Holiday.ShouldCelebrate { @@ -9,16 +9,11 @@ namespace Content.Server.Holiday.ShouldCelebrate /// For a holiday that happens the first instance of a weekday on a month. /// [UsedImplicitly] - public class WeekdayInMonth : DefaultHolidayShouldCelebrate, IExposeData + public class WeekdayInMonth : DefaultHolidayShouldCelebrate { - private DayOfWeek _weekday; - private uint _occurrence; + [DataField("weekday")] private DayOfWeek _weekday = DayOfWeek.Monday; - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(ref _weekday, "weekday", DayOfWeek.Monday); - serializer.DataField(ref _occurrence, "occurrence", 1u); - } + [DataField("occurrence")] private uint _occurrence = 1; public override bool ShouldCelebrate(DateTime date, HolidayPrototype holiday) { diff --git a/Content.Server/Interfaces/IGasReactionEffect.cs b/Content.Server/Interfaces/IGasReactionEffect.cs index 52fada8f21..7ca58d4342 100644 --- a/Content.Server/Interfaces/IGasReactionEffect.cs +++ b/Content.Server/Interfaces/IGasReactionEffect.cs @@ -2,11 +2,10 @@ using Content.Server.Atmos; using Content.Server.Atmos.Reactions; using Robust.Server.GameObjects; -using Robust.Shared.Serialization; namespace Content.Server.Interfaces { - public interface IGasReactionEffect : IExposeData + public interface IGasReactionEffect { ReactionResult React(GasMixture mixture, IGasMixtureHolder? holder, GridTileLookupSystem gridTileLookup); } diff --git a/Content.Server/Jobs/JanitorSpecial.cs b/Content.Server/Jobs/JanitorSpecial.cs index 225a7168e6..164188ea86 100644 --- a/Content.Server/Jobs/JanitorSpecial.cs +++ b/Content.Server/Jobs/JanitorSpecial.cs @@ -6,23 +6,16 @@ using Content.Shared.Roles; using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Jobs { [UsedImplicitly] + [DataDefinition] public class JanitorSpecial : JobSpecial { - private string _holiday = string.Empty; - private string _prototype = string.Empty; - - protected override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _holiday, "holiday", string.Empty); - serializer.DataField(ref _prototype, "prototype", string.Empty); - } + [DataField("holiday")] private readonly string _holiday = string.Empty; + [DataField("prototype")] private readonly string _prototype = string.Empty; public override void AfterEquip(IEntity mob) { diff --git a/Content.Server/Objectives/Conditions/DieCondition.cs b/Content.Server/Objectives/Conditions/DieCondition.cs index d6b198d581..46562820e5 100644 --- a/Content.Server/Objectives/Conditions/DieCondition.cs +++ b/Content.Server/Objectives/Conditions/DieCondition.cs @@ -4,11 +4,13 @@ using Content.Server.Objectives.Interfaces; using Content.Shared.GameObjects.Components.Mobs.State; using JetBrains.Annotations; using Robust.Shared.Localization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; namespace Content.Server.Objectives.Conditions { [UsedImplicitly] + [DataDefinition] public class DieCondition : IObjectiveCondition { private Mind? _mind; diff --git a/Content.Server/Objectives/Conditions/KillRandomPersonCondition.cs b/Content.Server/Objectives/Conditions/KillRandomPersonCondition.cs index 8e4d71c2f8..07b7c14d32 100644 --- a/Content.Server/Objectives/Conditions/KillRandomPersonCondition.cs +++ b/Content.Server/Objectives/Conditions/KillRandomPersonCondition.cs @@ -7,10 +7,12 @@ using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Random; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Objectives.Conditions { [UsedImplicitly] + [DataDefinition] public class KillRandomPersonCondition : KillPersonCondition { public override IObjectiveCondition GetAssigned(Mind mind) diff --git a/Content.Server/Objectives/Conditions/StayAliveCondition.cs b/Content.Server/Objectives/Conditions/StayAliveCondition.cs index b98cb88842..953d87a281 100644 --- a/Content.Server/Objectives/Conditions/StayAliveCondition.cs +++ b/Content.Server/Objectives/Conditions/StayAliveCondition.cs @@ -4,11 +4,13 @@ using Content.Server.Objectives.Interfaces; using Content.Shared.GameObjects.Components.Mobs.State; using JetBrains.Annotations; using Robust.Shared.Localization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; namespace Content.Server.Objectives.Conditions { [UsedImplicitly] + [DataDefinition] public class StayAliveCondition : IObjectiveCondition { private Mind? _mind; diff --git a/Content.Server/Objectives/Conditions/StealCondition.cs b/Content.Server/Objectives/Conditions/StealCondition.cs index c88fe3c941..a84b4f3bb6 100644 --- a/Content.Server/Objectives/Conditions/StealCondition.cs +++ b/Content.Server/Objectives/Conditions/StealCondition.cs @@ -10,16 +10,18 @@ using Robust.Shared.Localization; using Robust.Shared.Log; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; namespace Content.Server.Objectives.Conditions { [UsedImplicitly] - public class StealCondition : IObjectiveCondition + [DataDefinition] + public class StealCondition : IObjectiveCondition, ISerializationHooks { private Mind? _mind; - private string _prototypeId = default!; - private int _amount; + [DataField("prototype")] private string _prototypeId = string.Empty; + [DataField("amount")] private int _amount = 1; public IObjectiveCondition GetAssigned(Mind mind) { @@ -31,11 +33,8 @@ namespace Content.Server.Objectives.Conditions }; } - void IExposeData.ExposeData(ObjectSerializer serializer) + void ISerializationHooks.AfterDeserialization() { - serializer.DataField(ref _prototypeId, "prototype", ""); - serializer.DataField(ref _amount, "amount", 1); - if (_amount < 1) { Logger.Error("StealCondition has an amount less than 1 ({0})", _amount); @@ -65,8 +64,6 @@ namespace Content.Server.Objectives.Conditions } } - - public float Difficulty => 1f; public bool Equals(IObjectiveCondition? other) diff --git a/Content.Server/Objectives/Interfaces/IObjectiveCondition.cs b/Content.Server/Objectives/Interfaces/IObjectiveCondition.cs index 7ae83801c9..3af1087a0e 100644 --- a/Content.Server/Objectives/Interfaces/IObjectiveCondition.cs +++ b/Content.Server/Objectives/Interfaces/IObjectiveCondition.cs @@ -1,12 +1,11 @@ #nullable enable using System; using Content.Server.Mobs; -using Robust.Shared.Serialization; using Robust.Shared.Utility; namespace Content.Server.Objectives.Interfaces { - public interface IObjectiveCondition : IExposeData, IEquatable + public interface IObjectiveCondition : IEquatable { /// /// Returns a copy of the IObjectiveCondition which is assigned to the mind. @@ -40,7 +39,5 @@ namespace Content.Server.Objectives.Interfaces /// Returns a difficulty of the condition. /// float Difficulty { get; } - - void IExposeData.ExposeData(ObjectSerializer serializer){} } } diff --git a/Content.Server/Objectives/Interfaces/IObjectiveRequirement.cs b/Content.Server/Objectives/Interfaces/IObjectiveRequirement.cs index ede3737858..0f7b23a2bb 100644 --- a/Content.Server/Objectives/Interfaces/IObjectiveRequirement.cs +++ b/Content.Server/Objectives/Interfaces/IObjectiveRequirement.cs @@ -1,11 +1,9 @@ using Content.Server.Mobs; -using Robust.Shared.Serialization; namespace Content.Server.Objectives.Interfaces { - public interface IObjectiveRequirement : IExposeData + public interface IObjectiveRequirement { - /// /// Checks whether or not the entity & its surroundings are valid to be given the objective. /// diff --git a/Content.Server/Objectives/ObjectivePrototype.cs b/Content.Server/Objectives/ObjectivePrototype.cs index 712f098e43..e804fb9a53 100644 --- a/Content.Server/Objectives/ObjectivePrototype.cs +++ b/Content.Server/Objectives/ObjectivePrototype.cs @@ -1,11 +1,11 @@ -using System.Collections.Generic; +#nullable enable +using System.Collections.Generic; using System.Linq; using Content.Server.Mobs; using Content.Server.Objectives.Interfaces; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; -using YamlDotNet.RepresentationModel; namespace Content.Server.Objectives { @@ -13,27 +13,34 @@ namespace Content.Server.Objectives public class ObjectivePrototype : IPrototype { [ViewVariables] - public string ID { get; private set; } + [field: DataField("id", required: true)] + public string ID { get; } = default!; [ViewVariables] - public string Issuer { get; private set; } + [field: DataField("parent")] + public string? Parent { get; } - [ViewVariables] - public float Probability { get; private set; } + [ViewVariables] [DataField("issuer")] public string Issuer { get; private set; } = "Unknown"; + + [ViewVariables] [DataField("prob")] public float Probability { get; private set; } = 0.3f; [ViewVariables] public float Difficulty => _difficultyOverride ?? _conditions.Sum(c => c.Difficulty); + [DataField("conditions")] private List _conditions = new(); + [DataField("requirements")] private List _requirements = new(); [ViewVariables] public IReadOnlyList Conditions => _conditions; [ViewVariables] + [DataField("canBeDuplicate")] public bool CanBeDuplicateAssignment { get; private set; } [ViewVariables(VVAccess.ReadWrite)] + [DataField("difficultyOverride")] private float? _difficultyOverride = null; public bool CanBeAssigned(Mind mind) @@ -54,19 +61,6 @@ namespace Content.Server.Objectives return true; } - public void LoadFrom(YamlMappingNode mapping) - { - var ser = YamlObjectSerializer.NewReader(mapping); - - ser.DataField(this, x => x.ID, "id", string.Empty); - ser.DataField(this, x => x.Issuer, "issuer", "Unknown"); - ser.DataField(this, x => x.Probability, "prob", 0.3f); - ser.DataField(ref _conditions, "conditions", new List()); - ser.DataField(ref _requirements, "requirements", new List()); - ser.DataField(ref _difficultyOverride, "difficultyOverride", null); - ser.DataField(this, x => x.CanBeDuplicateAssignment, "canBeDuplicate", false); - } - public Objective GetObjective(Mind mind) { return new(this, mind); diff --git a/Content.Server/Objectives/Requirements/IncompatibleConditionsRequirement.cs b/Content.Server/Objectives/Requirements/IncompatibleConditionsRequirement.cs index dededce877..89b6a2c0a8 100644 --- a/Content.Server/Objectives/Requirements/IncompatibleConditionsRequirement.cs +++ b/Content.Server/Objectives/Requirements/IncompatibleConditionsRequirement.cs @@ -1,18 +1,15 @@ using System.Collections.Generic; using Content.Server.Mobs; using Content.Server.Objectives.Interfaces; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Objectives.Requirements { + [DataDefinition] public class IncompatibleConditionsRequirement : IObjectiveRequirement { - private List _incompatibleConditions = new(); - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x=>x._incompatibleConditions, "conditions", new List()); - } + [DataField("conditions")] + private readonly List _incompatibleConditions = new(); public bool CanBeAssigned(Mind mind) { diff --git a/Content.Server/Objectives/Requirements/IncompatibleObjectivesRequirement.cs b/Content.Server/Objectives/Requirements/IncompatibleObjectivesRequirement.cs index b9290adde0..0be82ef7c4 100644 --- a/Content.Server/Objectives/Requirements/IncompatibleObjectivesRequirement.cs +++ b/Content.Server/Objectives/Requirements/IncompatibleObjectivesRequirement.cs @@ -1,18 +1,15 @@ using System.Collections.Generic; using Content.Server.Mobs; using Content.Server.Objectives.Interfaces; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Objectives.Requirements { + [DataDefinition] public class IncompatibleObjectivesRequirement : IObjectiveRequirement { - private List _incompatibleObjectives = new(); - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x=>x._incompatibleObjectives, "objectives", new List()); - } + [DataField("objectives")] + private readonly List _incompatibleObjectives = new(); public bool CanBeAssigned(Mind mind) { diff --git a/Content.Server/Objectives/Requirements/TraitorRequirement.cs b/Content.Server/Objectives/Requirements/TraitorRequirement.cs index 307c8a5242..a8412040fb 100644 --- a/Content.Server/Objectives/Requirements/TraitorRequirement.cs +++ b/Content.Server/Objectives/Requirements/TraitorRequirement.cs @@ -2,15 +2,14 @@ using Content.Server.Mobs.Roles.Traitor; using Content.Server.Objectives.Interfaces; using JetBrains.Annotations; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Objectives.Requirements { [UsedImplicitly] + [DataDefinition] public class TraitorRequirement : IObjectiveRequirement { - void IExposeData.ExposeData(ObjectSerializer serializer){} - public bool CanBeAssigned(Mind mind) { return mind.HasRole(); diff --git a/Content.Shared/Access/AccessLevelPrototype.cs b/Content.Shared/Access/AccessLevelPrototype.cs index 55673f794c..9b2e3be96d 100644 --- a/Content.Shared/Access/AccessLevelPrototype.cs +++ b/Content.Shared/Access/AccessLevelPrototype.cs @@ -1,8 +1,8 @@ #nullable enable using Robust.Shared.Localization; using Robust.Shared.Prototypes; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; namespace Content.Shared.Access { @@ -12,26 +12,24 @@ namespace Content.Shared.Access [Prototype("accessLevel")] public class AccessLevelPrototype : IPrototype { - public void LoadFrom(YamlMappingNode mapping) - { - ID = mapping.GetNode("id").AsString(); - if (mapping.TryGetNode("name", out var nameNode)) - { - Name = nameNode.AsString(); - } - else - { - Name = ID; - } + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; - Name = Loc.GetString(Name); - } - - public string ID { get; private set; } = string.Empty; + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } /// /// The player-visible name of the access level, in the ID card console and such. /// - public string Name { get; private set; } = string.Empty; + [DataField("name")] + public string Name + { + get => _name ?? ID; + private set => _name = Loc.GetString(value); + } + + private string? _name; } } diff --git a/Content.Shared/Actions/ActionPrototype.cs b/Content.Shared/Actions/ActionPrototype.cs index b0b02669d4..fa710e3ebe 100644 --- a/Content.Shared/Actions/ActionPrototype.cs +++ b/Content.Shared/Actions/ActionPrototype.cs @@ -1,10 +1,10 @@ #nullable enable using Content.Shared.Interfaces; using Robust.Shared.IoC; +using Robust.Shared.Log; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; -using YamlDotNet.RepresentationModel; -using Robust.Shared.Log; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.Actions { @@ -13,12 +13,17 @@ namespace Content.Shared.Actions /// or skill). /// [Prototype("action")] - public class ActionPrototype : BaseActionPrototype + [DataDefinition] + public class ActionPrototype : BaseActionPrototype, ISerializationHooks { /// /// Type of action, no 2 action prototypes should have the same one. /// - public ActionType ActionType { get; private set; } + [DataField("actionType", required: true)] + public ActionType ActionType { get; set; } + + [DataField("behavior", serverOnly: true)] + private IActionBehavior? Behavior { get; set; } /// /// The IInstantAction that should be invoked when performing this @@ -48,23 +53,20 @@ namespace Content.Shared.Actions /// public ITargetPointAction TargetPointAction { get; private set; } = default!; - public override void LoadFrom(YamlMappingNode mapping) - { - base.LoadFrom(mapping); - var serializer = YamlObjectSerializer.NewReader(mapping); + public override string ID => ActionType.ToString(); + + void ISerializationHooks.AfterDeserialization() + { + base.AfterDeserialization(); - serializer.DataField(this, x => x.ActionType, "actionType", ActionType.Error); if (ActionType == ActionType.Error) { Logger.ErrorS("action", "missing or invalid actionType for action with name {0}", Name); } - // TODO: Split this class into server/client after RobustToolbox#1405 if (IoCManager.Resolve().IsClientModule) return; - IActionBehavior? behavior = null; - serializer.DataField(ref behavior, "behavior", null); - switch (behavior) + switch (Behavior) { case null: BehaviorType = BehaviorType.None; @@ -95,7 +97,6 @@ namespace Content.Shared.Actions Logger.ErrorS("action", "unrecognized behavior type for action with name {0}", Name); break; } - } } } diff --git a/Content.Shared/Actions/BaseActionPrototype.cs b/Content.Shared/Actions/BaseActionPrototype.cs index b39319c989..1102d35075 100644 --- a/Content.Shared/Actions/BaseActionPrototype.cs +++ b/Content.Shared/Actions/BaseActionPrototype.cs @@ -1,55 +1,65 @@ #nullable enable using System; using System.Collections.Generic; -using System.Linq; using Robust.Shared.Log; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; -using YamlDotNet.RepresentationModel; namespace Content.Shared.Actions { /// /// Base class for action prototypes. /// - public abstract class BaseActionPrototype : IPrototype + [ImplicitDataDefinitionForInheritors] + public abstract class BaseActionPrototype : IPrototype, ISerializationHooks { - public string ID { get; private set; } = string.Empty; + public abstract string ID { get; } + + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } /// /// Icon representing this action in the UI. /// [ViewVariables] - public SpriteSpecifier Icon { get; private set; } = SpriteSpecifier.Invalid; + [field: DataField("icon")] + public SpriteSpecifier Icon { get; } = SpriteSpecifier.Invalid; /// /// For toggle actions only, icon to show when toggled on. If omitted, /// the action will simply be highlighted when turned on. /// [ViewVariables] - public SpriteSpecifier IconOn { get; private set; } = SpriteSpecifier.Invalid; + [field: DataField("iconOn")] + public SpriteSpecifier IconOn { get; } = SpriteSpecifier.Invalid; /// /// Name to show in UI. Accepts formatting. /// + [DataField("name")] public FormattedMessage Name { get; private set; } = new(); /// /// Description to show in UI. Accepts formatting. /// - public FormattedMessage Description { get; private set; } = new(); + [field: DataField("description")] + public FormattedMessage Description { get; } = new(); /// /// Requirements message to show in UI. Accepts formatting, but generally should be avoided /// so the requirements message isn't too prominent in the tooltip. /// - public string Requires { get; private set; } = string.Empty; + [field: DataField("requires")] + public string Requires { get; } = string.Empty; /// /// The type of behavior this action has. This is valid clientside and serverside. /// + [DataField("behaviorType")] public BehaviorType BehaviorType { get; protected set; } = BehaviorType.None; /// @@ -57,29 +67,36 @@ namespace Content.Shared.Actions /// selected after it is used, so it can be continuously re-used. If this is false, /// the action will be deselected after one use. /// - public bool Repeat { get; private set; } + [field: DataField("repeat")] + public bool Repeat { get; } /// /// For TargetEntity/TargetPoint actions, should the action be de-selected if currently selected (choosing a target) /// when it goes on cooldown. Defaults to false. /// - public bool DeselectOnCooldown { get; private set; } + [field: DataField("deselectOnCooldown")] + public bool DeselectOnCooldown { get; } /// /// For TargetEntity actions, should the action be de-selected if the user doesn't click an entity when /// selecting a target. Defaults to false. /// - public bool DeselectWhenEntityNotClicked { get; private set; } + [field: DataField("deselectWhenEntityNotClicked")] + public bool DeselectWhenEntityNotClicked { get; } + + [DataField("filters")] private List _filters = new(); /// /// Filters that can be used to filter this item in action menu. /// - public IEnumerable Filters { get; private set; } = new List(); + public IEnumerable Filters => _filters; + + [DataField("keywords")] private List _keywords = new(); /// /// Keywords that can be used to search this item in action menu. /// - public IEnumerable Keywords { get; private set; } = new List(); + public IEnumerable Keywords => _keywords; /// /// True if this is an action that requires selecting a target @@ -87,27 +104,11 @@ namespace Content.Shared.Actions public bool IsTargetAction => BehaviorType == BehaviorType.TargetEntity || BehaviorType == BehaviorType.TargetPoint; - public virtual void LoadFrom(YamlMappingNode mapping) + public virtual void AfterDeserialization() { - var serializer = YamlObjectSerializer.NewReader(mapping); + Name = new FormattedMessage(); + Name.AddText(ID); - serializer.DataReadFunction("name", string.Empty, - s => - { - ID = s; - Name = FormattedMessage.FromMarkup(s); - }); - serializer.DataReadFunction("description", string.Empty, - s => Description = FormattedMessage.FromMarkup(s)); - - serializer.DataField(this, x => x.Requires,"requires", string.Empty); - serializer.DataField(this, x => x.Icon,"icon", SpriteSpecifier.Invalid); - serializer.DataField(this, x => x.IconOn,"iconOn", SpriteSpecifier.Invalid); - - // client needs to know what type of behavior it is even if the actual implementation is only - // on server side. If we wanted to avoid this we'd need to always add a shared or clientside interface - // for each action even if there was only server-side logic, which would be cumbersome - serializer.DataField(this, x => x.BehaviorType, "behaviorType", BehaviorType.None); if (BehaviorType == BehaviorType.None) { Logger.ErrorS("action", "Missing behaviorType for action with name {0}", Name); @@ -119,28 +120,12 @@ namespace Content.Shared.Actions " type was {1}. iconOn is only supported for Toggle behavior type.", Name); } - serializer.DataField(this, x => x.Repeat, "repeat", false); if (Repeat && BehaviorType != BehaviorType.TargetEntity && BehaviorType != BehaviorType.TargetPoint) { Logger.ErrorS("action", " action named {0} used repeat: true, but this is only supported for" + " TargetEntity and TargetPoint behaviorType and its behaviorType is {1}", Name, BehaviorType); } - - serializer.DataField(this, x => x.DeselectOnCooldown, "deselectOnCooldown", false); - serializer.DataField(this, x => x.DeselectWhenEntityNotClicked, "deselectWhenEntityNotClicked", false); - - serializer.DataReadFunction("filters", new List(), - rawTags => - { - Filters = rawTags.Select(rawTag => rawTag.Trim()).ToList(); - }); - - serializer.DataReadFunction("keywords", new List(), - rawTags => - { - Keywords = rawTags.Select(rawTag => rawTag.Trim()).ToList(); - }); } protected void ValidateBehaviorType(BehaviorType expected, Type actualInterface) diff --git a/Content.Shared/Actions/IActionBehavior.cs b/Content.Shared/Actions/IActionBehavior.cs index 674186620c..a082fd5047 100644 --- a/Content.Shared/Actions/IActionBehavior.cs +++ b/Content.Shared/Actions/IActionBehavior.cs @@ -2,7 +2,6 @@ using System; using Content.Shared.GameObjects.Components.Mobs; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; namespace Content.Shared.Actions { @@ -10,7 +9,9 @@ namespace Content.Shared.Actions /// Currently just a marker interface delineating the different possible /// types of action behaviors. /// - public interface IActionBehavior : IExposeData { } + public interface IActionBehavior + { + } /// /// Base class for all action event args diff --git a/Content.Shared/Actions/IItemActionBehavior.cs b/Content.Shared/Actions/IItemActionBehavior.cs index 844ad604bd..15d892cf3c 100644 --- a/Content.Shared/Actions/IItemActionBehavior.cs +++ b/Content.Shared/Actions/IItemActionBehavior.cs @@ -2,7 +2,6 @@ using System; using Content.Shared.GameObjects.Components.Mobs; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; namespace Content.Shared.Actions { @@ -10,7 +9,7 @@ namespace Content.Shared.Actions /// Currently just a marker interface delineating the different possible /// types of item action behaviors. /// - public interface IItemActionBehavior : IExposeData + public interface IItemActionBehavior { } diff --git a/Content.Shared/Actions/ItemActionPrototype.cs b/Content.Shared/Actions/ItemActionPrototype.cs index 4abe9b628f..83a61ce8a4 100644 --- a/Content.Shared/Actions/ItemActionPrototype.cs +++ b/Content.Shared/Actions/ItemActionPrototype.cs @@ -4,7 +4,7 @@ using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.Actions { @@ -12,15 +12,18 @@ namespace Content.Shared.Actions /// An action which is granted to an entity via an item (such as toggling a flashlight). /// [Prototype("itemAction")] - public class ItemActionPrototype : BaseActionPrototype + [DataDefinition] + public class ItemActionPrototype : BaseActionPrototype, ISerializationHooks { /// /// Type of item action, no 2 itemAction prototypes should have the same one. /// - public ItemActionType ActionType { get; private set; } + [DataField("actionType")] + public ItemActionType ActionType { get; private set; } = ItemActionType.Error; /// - public ItemActionIconStyle IconStyle { get; private set; } + [DataField("iconStyle")] + public ItemActionIconStyle IconStyle { get; private set; } = ItemActionIconStyle.BigItem; /// /// The IInstantItemAction that should be invoked when performing this @@ -50,25 +53,23 @@ namespace Content.Shared.Actions /// public ITargetPointItemAction TargetPointAction { get; private set; } = default!; - public override void LoadFrom(YamlMappingNode mapping) - { - base.LoadFrom(mapping); - var serializer = YamlObjectSerializer.NewReader(mapping); + [DataField("behavior", readOnly: true, serverOnly: true)] + public IItemActionBehavior? ItemActionBehavior { get; private set; } - serializer.DataField(this, x => x.ActionType, "actionType", ItemActionType.Error); + public override string ID => ActionType.ToString(); + + public override void AfterDeserialization() + { + base.AfterDeserialization(); if (ActionType == ItemActionType.Error) { Logger.ErrorS("action", "missing or invalid actionType for action with name {0}", Name); } - serializer.DataField(this, x => x.IconStyle, "iconStyle", ItemActionIconStyle.BigItem); - // TODO: Split this class into server/client after RobustToolbox#1405 if (IoCManager.Resolve().IsClientModule) return; - IItemActionBehavior? behavior = null; - serializer.DataField(ref behavior, "behavior", null); - switch (behavior) + switch (ItemActionBehavior) { case null: BehaviorType = BehaviorType.None; diff --git a/Content.Shared/Alert/AlertOrderPrototype.cs b/Content.Shared/Alert/AlertOrderPrototype.cs index f0ab7022b7..3618952589 100644 --- a/Content.Shared/Alert/AlertOrderPrototype.cs +++ b/Content.Shared/Alert/AlertOrderPrototype.cs @@ -1,9 +1,10 @@ #nullable enable +using System; using System.Collections.Generic; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; namespace Content.Shared.Alert { @@ -11,33 +12,60 @@ namespace Content.Shared.Alert /// Defines the order of alerts so they show up in a consistent order. /// [Prototype("alertOrder")] - public class AlertOrderPrototype : IPrototype, IComparer + [DataDefinition] + public class AlertOrderPrototype : IPrototype, IComparer, ISerializationHooks { - public string ID { get; private set; } = string.Empty; + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; + + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } + + [DataField("order")] private readonly List<(string type, string alert)> _order = new(); private readonly Dictionary _typeToIdx = new(); private readonly Dictionary _categoryToIdx = new(); - public void LoadFrom(YamlMappingNode mapping) + void ISerializationHooks.BeforeSerialization() { - var serializer = YamlObjectSerializer.NewReader(mapping); + _order.Clear(); - serializer.DataField(this, x => x.ID, "id", string.Empty); + var orderArray = new KeyValuePair[_typeToIdx.Count + _categoryToIdx.Count]; - if (!mapping.TryGetNode("order", out YamlSequenceNode? orderMapping)) return; - - var i = 0; - foreach (var entryYaml in orderMapping) + foreach (var (type, id) in _typeToIdx) { - var orderEntry = (YamlMappingNode) entryYaml; - var orderSerializer = YamlObjectSerializer.NewReader(orderEntry); - if (orderSerializer.TryReadDataField("category", out AlertCategory alertCategory)) + orderArray[id] = new KeyValuePair("alertType", type.ToString()); + } + + foreach (var (category, id) in _categoryToIdx) + { + orderArray[id] = new KeyValuePair("category", category.ToString()); + } + + foreach (var (type, alert) in orderArray) + { + _order.Add((type, alert)); + } + } + + void ISerializationHooks.AfterDeserialization() + { + var i = 0; + + foreach (var (type, alert) in _order) + { + switch (type) { - _categoryToIdx[alertCategory] = i++; - } - else if (orderSerializer.TryReadDataField("alertType", out AlertType alertType)) - { - _typeToIdx[alertType] = i++; + case "alertType": + _typeToIdx[Enum.Parse(alert)] = i++; + break; + case "category": + _categoryToIdx[Enum.Parse(alert)] = i++; + break; + default: + throw new ArgumentException(); } } } diff --git a/Content.Shared/Alert/AlertPrototype.cs b/Content.Shared/Alert/AlertPrototype.cs index c722a65ea3..27413be333 100644 --- a/Content.Shared/Alert/AlertPrototype.cs +++ b/Content.Shared/Alert/AlertPrototype.cs @@ -1,14 +1,13 @@ #nullable enable using System; using System.Globalization; -using Content.Shared.Interfaces; -using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; -using YamlDotNet.RepresentationModel; namespace Content.Shared.Alert { @@ -16,13 +15,19 @@ namespace Content.Shared.Alert /// An alert popup with associated icon, tooltip, and other data. /// [Prototype("alert")] - public class AlertPrototype : IPrototype + public class AlertPrototype : IPrototype, ISerializationHooks { - public string ID { get; private set; } = string.Empty; + [ViewVariables] + string IPrototype.ID => AlertType.ToString(); + + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } /// /// Type of alert, no 2 alert prototypes should have the same one. /// + [DataField("alertType")] public AlertType AlertType { get; private set; } /// @@ -32,16 +37,19 @@ namespace Content.Shared.Alert /// to get the correct icon path for a particular severity level. /// [ViewVariables] + [DataField("icon")] public SpriteSpecifier Icon { get; private set; } = SpriteSpecifier.Invalid; /// /// Name to show in tooltip window. Accepts formatting. /// + [DataField("name")] public FormattedMessage Name { get; private set; } = new(); /// /// Description to show in tooltip window. Accepts formatting. /// + [DataField("description")] public FormattedMessage Description { get; private set; } = new(); /// @@ -51,6 +59,7 @@ namespace Content.Shared.Alert /// replace each other and are mutually exclusive, for example lowpressure / highpressure, /// hot / cold. If left unspecified, the alert will not replace or be replaced by any other alerts. /// + [DataField("category")] public AlertCategory? Category { get; private set; } /// @@ -64,13 +73,14 @@ namespace Content.Shared.Alert /// public short MinSeverity => MaxSeverity == -1 ? (short) -1 : _minSeverity; - private short _minSeverity; + [DataField("minSeverity")] private short _minSeverity = 1; /// /// Maximum severity level supported by this state. -1 (default) indicates /// no severity levels are supported by the state. /// - public short MaxSeverity { get; private set; } + [DataField("maxSeverity")] + public short MaxSeverity = -1; /// /// Indicates whether this state support severity levels @@ -80,48 +90,23 @@ namespace Content.Shared.Alert /// /// Whether this alert is clickable. This is valid clientside. /// - public bool HasOnClick { get; private set; } + public bool HasOnClick => OnClick != null; /// /// Defines what to do when the alert is clicked. /// This will always be null on clientside. /// + [DataField("onClick", serverOnly: true)] public IAlertClick? OnClick { get; private set; } - public void LoadFrom(YamlMappingNode mapping) + void ISerializationHooks.AfterDeserialization() { - var serializer = YamlObjectSerializer.NewReader(mapping); - - serializer.DataField(this, x => x.Icon, "icon", SpriteSpecifier.Invalid); - serializer.DataField(this, x => x.MaxSeverity, "maxSeverity", (short) -1); - serializer.DataField(ref _minSeverity, "minSeverity", (short) 1); - - serializer.DataReadFunction("name", string.Empty, - s => - { - ID = s; - Name = FormattedMessage.FromMarkup(s); - }); - serializer.DataReadFunction("description", string.Empty, - s => Description = FormattedMessage.FromMarkup(s)); - - serializer.DataField(this, x => x.AlertType, "alertType", AlertType.Error); if (AlertType == AlertType.Error) { Logger.ErrorS("alert", "missing or invalid alertType for alert with name {0}", Name); } - if (serializer.TryReadDataField("category", out AlertCategory alertCategory)) - { - Category = alertCategory; - } - AlertKey = new AlertKey(AlertType, Category); - - HasOnClick = serializer.TryReadDataField("onClick", out string _); - - if (IoCManager.Resolve().IsClientModule) return; - serializer.DataField(this, x => x.OnClick, "onClick", null); } /// severity level, if supported by this alert @@ -174,9 +159,9 @@ namespace Content.Shared.Alert /// falls back to the id. /// [Serializable, NetSerializable] - public struct AlertKey + public struct AlertKey : ISerializationHooks, IPopulateDefaultValues { - public readonly AlertType? AlertType; + public AlertType? AlertType { get; private set; } public readonly AlertCategory? AlertCategory; /// NOTE: if the alert has a category you must pass the category for this to work @@ -211,6 +196,11 @@ namespace Content.Shared.Alert return AlertType.GetHashCode(); } + public void PopulateDefaultValues() + { + AlertType = Alert.AlertType.Error; + } + /// alert category, must not be null /// An alert key for the provided alert category. This must only be used for /// queries and never storage, as it is lacking an alert type. diff --git a/Content.Shared/Alert/IAlertClick.cs b/Content.Shared/Alert/IAlertClick.cs index 516da5df11..c11c52fde4 100644 --- a/Content.Shared/Alert/IAlertClick.cs +++ b/Content.Shared/Alert/IAlertClick.cs @@ -1,16 +1,14 @@ #nullable enable using System; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; namespace Content.Shared.Alert { /// /// Defines what should happen when an alert is clicked. /// - public interface IAlertClick : IExposeData + public interface IAlertClick { - /// /// Invoked on server side when user clicks an alert. /// diff --git a/Content.Shared/Atmos/GasPrototype.cs b/Content.Shared/Atmos/GasPrototype.cs index 57ee6dbcf8..c698db82af 100644 --- a/Content.Shared/Atmos/GasPrototype.cs +++ b/Content.Shared/Atmos/GasPrototype.cs @@ -1,41 +1,50 @@ -#nullable enable -using System; +#nullable enable using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; namespace Content.Shared.Atmos { [Prototype("gas")] public class GasPrototype : IPrototype { - public string Name { get; private set; } = string.Empty; + [field: DataField("name")] public string Name { get; } = string.Empty; // TODO: Control gas amount necessary for overlay to appear // TODO: Add interfaces for gas behaviours e.g. breathing, burning - public string ID { get; private set; } = string.Empty; + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; + + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } /// /// Specific heat for gas. /// + [DataField("specificHeat")] public float SpecificHeat { get; private set; } /// /// Heat capacity ratio for gas /// - public float HeatCapacityRatio { get; private set; } + [DataField("heatCapacityRatio")] + public float HeatCapacityRatio { get; private set; } = 1.4f; /// /// Molar mass of gas /// - public float MolarMass { get; set; } + [DataField("molarMass")] + public float MolarMass { get; set; } = 1f; /// /// Minimum amount of moles for this gas to be visible. /// - public float GasMolesVisible { get; private set; } + [field: DataField("gasMolesVisible")] + public float GasMolesVisible { get; } = 0.25f; /// /// Visibility for this gas will be max after this value. @@ -45,41 +54,27 @@ namespace Content.Shared.Atmos /// /// If this reagent is in gas form, this is the path to the overlay that will be used to make the gas visible. /// - public string GasOverlayTexture { get; private set; } = string.Empty; + [field: DataField("gasOverlayTexture")] + public string GasOverlayTexture { get; } = string.Empty; /// /// If this reagent is in gas form, this will be the path to the RSI sprite that will be used to make the gas visible. /// + [DataField("gasOverlayState")] public string GasOverlayState { get; set; } = string.Empty; /// /// State for the gas RSI overlay. /// + [DataField("gasOverlaySprite")] public string GasOverlaySprite { get; set; } = string.Empty; /// /// Path to the tile overlay used when this gas appears visible. /// - public string OverlayPath { get; private set; } = string.Empty; + [field: DataField("overlayPath")] + public string OverlayPath { get; } = string.Empty; - - public string Color { get; private set; } = string.Empty; - - public void LoadFrom(YamlMappingNode mapping) - { - var serializer = YamlObjectSerializer.NewReader(mapping); - - serializer.DataField(this, x => x.ID, "id", string.Empty); - serializer.DataField(this, x => x.Name, "name", string.Empty); - serializer.DataField(this, x => x.OverlayPath, "overlayPath", string.Empty); - serializer.DataField(this, x => x.SpecificHeat, "specificHeat", 0f); - serializer.DataField(this, x => x.HeatCapacityRatio, "heatCapacityRatio", 1.4f); - serializer.DataField(this, x => x.MolarMass, "molarMass", 1f); - serializer.DataField(this, x => x.GasMolesVisible, "gasMolesVisible", 0.25f); - serializer.DataField(this, x => x.GasOverlayTexture, "gasOverlayTexture", string.Empty); - serializer.DataField(this, x => x.GasOverlaySprite, "gasOverlaySprite", string.Empty); - serializer.DataField(this, x => x.GasOverlayState, "gasOverlayState", string.Empty); - serializer.DataField(this, x => x.Color, "color", string.Empty); - } + [field: DataField("color")] public string Color { get; } = string.Empty; } } diff --git a/Content.Shared/Audio/SoundCollectionPrototype.cs b/Content.Shared/Audio/SoundCollectionPrototype.cs index f8e5ea9388..780c40174b 100644 --- a/Content.Shared/Audio/SoundCollectionPrototype.cs +++ b/Content.Shared/Audio/SoundCollectionPrototype.cs @@ -1,29 +1,22 @@ #nullable enable using System.Collections.Generic; -using System.Data; using Robust.Shared.Prototypes; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; namespace Content.Shared.Audio { [Prototype("soundCollection")] public sealed class SoundCollectionPrototype : IPrototype { - public string ID { get; private set; } = string.Empty; - public List PickFiles { get; private set; } = new(); + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; - public void LoadFrom(YamlMappingNode mapping) - { - ID = mapping.GetNode("id").AsString(); + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } - // In the unlikely case the method gets called twice - PickFiles.Clear(); - - foreach (var file in mapping.GetNode("files")) - { - PickFiles.Add(file.AsString()); - } - } + [field: DataField("files")] public List PickFiles { get; } = new(); } } diff --git a/Content.Shared/Chemistry/DefaultMetabolizable.cs b/Content.Shared/Chemistry/DefaultMetabolizable.cs index bab24a5a20..1498b2fa47 100644 --- a/Content.Shared/Chemistry/DefaultMetabolizable.cs +++ b/Content.Shared/Chemistry/DefaultMetabolizable.cs @@ -1,21 +1,21 @@ #nullable enable using Content.Shared.Interfaces.Chemistry; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.Chemistry { - //Default metabolism for reagents. Metabolizes the reagent with no effects + /// + /// Default metabolism for reagents. Metabolizes the reagent with no effects + /// + [DataDefinition] public class DefaultMetabolizable : IMetabolizable { - //Rate of metabolism in units / second - private double _metabolismRate = 1; - public double MetabolismRate => _metabolismRate; - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(ref _metabolismRate, "rate", 1); - } + /// + /// Rate of metabolism in units / second + /// + [DataField("rate")] + public double MetabolismRate { get; set; } = 1; ReagentUnit IMetabolizable.Metabolize(IEntity solutionEntity, string reagentId, float tickTime) { diff --git a/Content.Shared/Chemistry/ReactionPrototype.cs b/Content.Shared/Chemistry/ReactionPrototype.cs index 558f5012c4..3952807bcc 100644 --- a/Content.Shared/Chemistry/ReactionPrototype.cs +++ b/Content.Shared/Chemistry/ReactionPrototype.cs @@ -1,12 +1,11 @@ #nullable enable -using System; using System.Collections.Generic; -using Content.Server.Interfaces.Chemistry; using Content.Shared.Interfaces; +using Content.Shared.Interfaces.Chemistry; using Robust.Shared.IoC; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; namespace Content.Shared.Chemistry { @@ -16,14 +15,21 @@ namespace Content.Shared.Chemistry [Prototype("reaction")] public class ReactionPrototype : IPrototype { - private string _id = default!; - private string _name = default!; - private Dictionary _reactants = default!; - private Dictionary _products = default!; - private IReactionEffect[] _effects = default!; + [DataField("reactants")] private Dictionary _reactants = new(); + [DataField("products")] private Dictionary _products = new(); + [DataField("effects", serverOnly: true)] private List _effects = new(); + + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; + + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } + + [field: DataField("name")] + public string Name { get; } = string.Empty; - public string ID => _id; - public string Name => _name; /// /// Reactants required for the reaction to occur. /// @@ -37,39 +43,19 @@ namespace Content.Shared.Chemistry /// public IReadOnlyList Effects => _effects; - public string? Sound { get; private set; } - - [Dependency] private readonly IModuleManager _moduleManager = default!; - - public void LoadFrom(YamlMappingNode mapping) - { - var serializer = YamlObjectSerializer.NewReader(mapping); - - serializer.DataField(ref _id, "id", string.Empty); - serializer.DataField(ref _name, "name", string.Empty); - serializer.DataField(ref _reactants, "reactants", new Dictionary()); - serializer.DataField(ref _products, "products", new Dictionary()); - serializer.DataField(this, x => x.Sound, "sound", "/Audio/Effects/Chemistry/bubbles.ogg"); - - if (_moduleManager.IsServerModule) - { - //TODO: Don't have a check for if this is the server - //Some implementations of IReactionEffect can't currently be moved to shared, so this is here to prevent the client from breaking when reading server-only IReactionEffects. - serializer.DataField(ref _effects, "effects", Array.Empty()); - } - else - { - _effects = Array.Empty(); //To ensure _effects isn't null since it is only serializable on the server right snow - } - } + // TODO SERV3: Empty on the client, (de)serialize on the server with module manager is server module + [DataField("sound", serverOnly: true)] public string? Sound { get; private set; } = "/Audio/Effects/Chemistry/bubbles.ogg"; } /// /// Prototype for chemical reaction reactants. /// - public class ReactantPrototype : IExposeData + [DataDefinition] + public class ReactantPrototype { - private ReagentUnit _amount; + [DataField("amount")] + private ReagentUnit _amount = ReagentUnit.New(1); + [DataField("catalyst")] private bool _catalyst; /// @@ -80,11 +66,5 @@ namespace Content.Shared.Chemistry /// Whether or not the reactant is a catalyst. Catalysts aren't removed when a reaction occurs. /// public bool Catalyst => _catalyst; - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(ref _amount, "amount", ReagentUnit.New(1)); - serializer.DataField(ref _catalyst, "catalyst", false); - } } } diff --git a/Content.Shared/Chemistry/ReagentPrototype.cs b/Content.Shared/Chemistry/ReagentPrototype.cs index 33fb91b09e..b2ded8b550 100644 --- a/Content.Shared/Chemistry/ReagentPrototype.cs +++ b/Content.Shared/Chemistry/ReagentPrototype.cs @@ -1,86 +1,72 @@ #nullable enable using System; using System.Collections.Generic; -using Content.Shared.Interfaces; using Content.Shared.Interfaces.Chemistry; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; -using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; namespace Content.Shared.Chemistry { [Prototype("reagent")] + [DataDefinition] public class ReagentPrototype : IPrototype { - [Dependency] private readonly IModuleManager _moduleManager = default!; + [DataField("metabolism", serverOnly: true)] + private readonly List _metabolism = new() {new DefaultMetabolizable()}; - private string _id = default!; - private string _name = default!; - private string _description = default!; - private string _physicalDescription = default!; - private Color _substanceColor; - private string _spritePath = default!; - private List _metabolism = default!; - private List _tileReactions = default!; - private List _plantMetabolism = default!; - private float _customPlantMetabolism; - private bool _toxin; - private int _boozePower; + [DataField("tileReactions", serverOnly: true)] + private readonly List _tileReactions = new(0); - public string ID => _id; - public string Name => _name; - public string Description => _description; - public string PhysicalDescription => _physicalDescription; - public Color SubstanceColor => _substanceColor; + [DataField("plantMetabolism", serverOnly: true)] + private readonly List _plantMetabolism = new(0); - public bool Toxin => _toxin; - public int BoozePower => _boozePower; + [DataField("customPlantMetabolism")] + private readonly float _customPlantMetabolism = 1f; + + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; + + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } + + [field: DataField("name")] + public string Name { get; } = string.Empty; + + [field: DataField("desc")] + public string Description { get; } = string.Empty; + + [field: DataField("physicalDesc")] + public string PhysicalDescription { get; } = string.Empty; + + [field: DataField("color")] + public Color SubstanceColor { get; } = Color.White; + + [field: DataField("toxin")] + public bool Toxin { get; } + + [field: DataField("boozePower")] + public int BoozePower { get; } + + [field: DataField("boilingPoint")] + public float? BoilingPoint { get; } + + [field: DataField("meltingPoint")] + public float? MeltingPoint { get; } + + [field: DataField("spritePath")] + public string SpriteReplacementPath { get; } = string.Empty; //List of metabolism effects this reagent has, should really only be used server-side. public IReadOnlyList Metabolism => _metabolism; public IReadOnlyList TileReactions => _tileReactions; public IReadOnlyList PlantMetabolism => _plantMetabolism; - public string SpriteReplacementPath => _spritePath; - - public ReagentPrototype() - { - IoCManager.InjectDependencies(this); - } - - public void LoadFrom(YamlMappingNode mapping) - { - var serializer = YamlObjectSerializer.NewReader(mapping); - - serializer.DataField(ref _id, "id", string.Empty); - serializer.DataField(ref _name, "name", string.Empty); - serializer.DataField(ref _description, "desc", string.Empty); - serializer.DataField(ref _physicalDescription, "physicalDesc", string.Empty); - serializer.DataField(ref _substanceColor, "color", Color.White); - serializer.DataField(ref _spritePath, "spritePath", string.Empty); - serializer.DataField(ref _customPlantMetabolism, "customPlantMetabolism", 1f); - serializer.DataField(ref _toxin, "toxin", false); - serializer.DataField(ref _boozePower, "boozePower", 0); - - if (_moduleManager.IsServerModule) - { - //Implementations of the needed interfaces are currently server-only, so they cannot be read on client - serializer.DataField(ref _metabolism, "metabolism", new List { new DefaultMetabolizable() }); - serializer.DataField(ref _tileReactions, "tileReactions", new List { }); - serializer.DataField(ref _plantMetabolism, "plantMetabolism", new List { }); - } - else - { - //ensure the following fields cannot null since they can only be serialized on server right now - _metabolism = new List { new DefaultMetabolizable() }; - _tileReactions = new(); - _plantMetabolism = new(); - } - } /// /// If the substance color is too dark we user a lighter version to make the text color readable when the user examines a solution. @@ -100,7 +86,7 @@ namespace Content.Shared.Chemistry return SubstanceColor; } - public ReagentUnit ReactionEntity(IEntity entity, ReactionMethod method, ReagentUnit reactVolume) + public ReagentUnit ReactionEntity(IEntity? entity, ReactionMethod method, ReagentUnit reactVolume) { var removed = ReagentUnit.Zero; @@ -153,7 +139,7 @@ namespace Content.Shared.Chemistry return removed; } - public void ReactionPlant(IEntity plantHolder) + public void ReactionPlant(IEntity? plantHolder) { if (plantHolder == null || plantHolder.Deleted) return; diff --git a/Content.Shared/Chemistry/Solution.cs b/Content.Shared/Chemistry/Solution.cs index 2afd5db7ef..87c1402045 100644 --- a/Content.Shared/Chemistry/Solution.cs +++ b/Content.Shared/Chemistry/Solution.cs @@ -10,6 +10,7 @@ using Robust.Shared.IoC; using Robust.Shared.Maths; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -19,10 +20,12 @@ namespace Content.Shared.Chemistry /// A solution of reagents. /// [Serializable, NetSerializable] - public class Solution : IExposeData, IEnumerable + [DataDefinition] + public class Solution : IEnumerable, ISerializationHooks { // Most objects on the station hold only 1 or 2 reagents [ViewVariables] + [DataField("reagents")] private List _contents = new(2); public IReadOnlyList Contents => _contents; @@ -50,19 +53,10 @@ namespace Content.Shared.Chemistry AddReagent(reagentId, quantity); } - /// - void IExposeData.ExposeData(ObjectSerializer serializer) + void ISerializationHooks.AfterDeserialization() { - serializer.DataReadWriteFunction( - "reagents", - new List(), - quantities => - { - _contents = quantities; - TotalVolume = ReagentUnit.New(0); - quantities.ForEach(reagent => TotalVolume += reagent.Quantity); - }, - () => _contents); + TotalVolume = ReagentUnit.Zero; + _contents.ForEach(reagent => TotalVolume += reagent.Quantity); } public bool ContainsReagent(string reagentId) @@ -333,9 +327,12 @@ namespace Content.Shared.Chemistry } [Serializable, NetSerializable] + [DataDefinition] public readonly struct ReagentQuantity: IComparable { + [DataField("ReagentId")] public readonly string ReagentId; + [DataField("Quantity")] public readonly ReagentUnit Quantity; public ReagentQuantity(string reagentId, ReagentUnit quantity) diff --git a/Content.Shared/Construction/ArbitraryInsertConstructionGraphStep.cs b/Content.Shared/Construction/ArbitraryInsertConstructionGraphStep.cs index 48ad9b7ce6..5418b55cfb 100644 --- a/Content.Shared/Construction/ArbitraryInsertConstructionGraphStep.cs +++ b/Content.Shared/Construction/ArbitraryInsertConstructionGraphStep.cs @@ -1,22 +1,15 @@ #nullable enable -using Robust.Shared.Localization; -using Robust.Shared.Serialization; +using Robust.Shared.Localization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; namespace Content.Shared.Construction { public abstract class ArbitraryInsertConstructionGraphStep : EntityInsertConstructionGraphStep { - public string Name { get; private set; } = string.Empty; - public SpriteSpecifier Icon { get; private set; } = SpriteSpecifier.Invalid; + [DataField("name")] public string Name { get; private set; } = string.Empty; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, x => x.Icon, "icon", SpriteSpecifier.Invalid); - serializer.DataField(this, x => x.Name, "name", string.Empty); - } + [DataField("icon")] public SpriteSpecifier Icon { get; private set; } = SpriteSpecifier.Invalid; public override void DoExamine(FormattedMessage message, bool inDetailsRange) { diff --git a/Content.Shared/Construction/ComponentConstructionGraphStep.cs b/Content.Shared/Construction/ComponentConstructionGraphStep.cs index 44e487e52c..1b1c62ff2e 100644 --- a/Content.Shared/Construction/ComponentConstructionGraphStep.cs +++ b/Content.Shared/Construction/ComponentConstructionGraphStep.cs @@ -1,21 +1,15 @@ #nullable enable using Robust.Shared.GameObjects; using Robust.Shared.Localization; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; namespace Content.Shared.Construction { + [DataDefinition] public class ComponentConstructionGraphStep : ArbitraryInsertConstructionGraphStep { - public string Component { get; private set; } = string.Empty; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, x => x.Component, "component", string.Empty); - } + [field: DataField("component")] public string Component { get; } = string.Empty; public override bool EntityValid(IEntity entity) { diff --git a/Content.Shared/Construction/ConstructionConditions/LowWallInTile.cs b/Content.Shared/Construction/ConstructionConditions/LowWallInTile.cs index 83b2ea3bed..838128a078 100644 --- a/Content.Shared/Construction/ConstructionConditions/LowWallInTile.cs +++ b/Content.Shared/Construction/ConstructionConditions/LowWallInTile.cs @@ -5,15 +5,14 @@ using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.Map; using Robust.Shared.Maths; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.Construction.ConstructionConditions { [UsedImplicitly] + [DataDefinition] public class LowWallInTile : IConstructionCondition { - void IExposeData.ExposeData(ObjectSerializer serializer) { } - public bool Condition(IEntity user, EntityCoordinates location, Direction direction) { var lowWall = false; diff --git a/Content.Shared/Construction/ConstructionConditions/NoWindowsInTile.cs b/Content.Shared/Construction/ConstructionConditions/NoWindowsInTile.cs index 9722d7e8b1..ee4a0652f4 100644 --- a/Content.Shared/Construction/ConstructionConditions/NoWindowsInTile.cs +++ b/Content.Shared/Construction/ConstructionConditions/NoWindowsInTile.cs @@ -5,15 +5,14 @@ using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.Map; using Robust.Shared.Maths; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.Construction.ConstructionConditions { [UsedImplicitly] + [DataDefinition] public class NoWindowsInTile : IConstructionCondition { - void IExposeData.ExposeData(ObjectSerializer serializer) { } - public bool Condition(IEntity user, EntityCoordinates location, Direction direction) { foreach (var entity in location.GetEntitiesInTile(true)) diff --git a/Content.Shared/Construction/ConstructionConditions/TileNotBlocked.cs b/Content.Shared/Construction/ConstructionConditions/TileNotBlocked.cs index ff9bfdf080..53adc4985e 100644 --- a/Content.Shared/Construction/ConstructionConditions/TileNotBlocked.cs +++ b/Content.Shared/Construction/ConstructionConditions/TileNotBlocked.cs @@ -4,21 +4,16 @@ using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.Map; using Robust.Shared.Maths; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.Construction.ConstructionConditions { [UsedImplicitly] + [DataDefinition] public class TileNotBlocked : IConstructionCondition { - private bool _filterMobs = false; - private bool _failIfSpace = true; - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(ref _filterMobs, "filterMobs", false); - serializer.DataField(ref _failIfSpace, "failIfSpace", true); - } + [DataField("filterMobs")] private bool _filterMobs = false; + [DataField("failIfSpace")] private bool _failIfSpace = true; public bool Condition(IEntity user, EntityCoordinates location, Direction direction) { diff --git a/Content.Shared/Construction/ConstructionConditions/TileType.cs b/Content.Shared/Construction/ConstructionConditions/TileType.cs index a2018cbcdc..23fb030c89 100644 --- a/Content.Shared/Construction/ConstructionConditions/TileType.cs +++ b/Content.Shared/Construction/ConstructionConditions/TileType.cs @@ -1,24 +1,19 @@ #nullable enable +using System.Collections.Generic; using Content.Shared.Maps; using JetBrains.Annotations; +using Robust.Shared.GameObjects; using Robust.Shared.Map; using Robust.Shared.Maths; -using Robust.Shared.Serialization; -using System.Collections.Generic; -using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.Construction.ConstructionConditions { [UsedImplicitly] + [DataDefinition] public class TileType : IConstructionCondition { - - public List TargetTiles { get; private set; } = new(); - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.TargetTiles, "targets", new List()); - } + [DataField("targets")] public List TargetTiles { get; private set; } = new(); public bool Condition(IEntity user, EntityCoordinates location, Direction direction) { diff --git a/Content.Shared/Construction/ConstructionConditions/WallmountCondition.cs b/Content.Shared/Construction/ConstructionConditions/WallmountCondition.cs index 80afe9976c..d183543c3d 100644 --- a/Content.Shared/Construction/ConstructionConditions/WallmountCondition.cs +++ b/Content.Shared/Construction/ConstructionConditions/WallmountCondition.cs @@ -1,22 +1,21 @@ #nullable enable +using System.Linq; using Content.Shared.GameObjects.Components.Tag; using Content.Shared.Physics; using JetBrains.Annotations; +using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Maths; -using Robust.Shared.Serialization; -using System.Linq; -using Robust.Shared.GameObjects; using Robust.Shared.Physics; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.Construction.ConstructionConditions { [UsedImplicitly] + [DataDefinition] public class WallmountCondition : IConstructionCondition { - void IExposeData.ExposeData(ObjectSerializer serializer) { } - public bool Condition(IEntity user, EntityCoordinates location, Direction direction) { var entManager = IoCManager.Resolve(); diff --git a/Content.Shared/Construction/ConstructionGraphEdge.cs b/Content.Shared/Construction/ConstructionGraphEdge.cs index b1b5004656..353ea65485 100644 --- a/Content.Shared/Construction/ConstructionGraphEdge.cs +++ b/Content.Shared/Construction/ConstructionGraphEdge.cs @@ -1,23 +1,26 @@ #nullable enable using System; using System.Collections.Generic; -using Content.Shared.Interfaces; -using Robust.Shared.IoC; -using Robust.Shared.Serialization; -using Robust.Shared.Utility; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; -using YamlDotNet.RepresentationModel; namespace Content.Shared.Construction { [Serializable] - public class ConstructionGraphEdge : IExposeData + [DataDefinition] + public class ConstructionGraphEdge { + [DataField("steps")] private List _steps = new(); + + [DataField("conditions", serverOnly: true)] private List _conditions = new(); + + [DataField("completed", serverOnly: true)] private List _completed = new(); [ViewVariables] + [DataField("to")] public string Target { get; private set; } = string.Empty; [ViewVariables] @@ -28,91 +31,5 @@ namespace Content.Shared.Construction [ViewVariables] public IReadOnlyList Steps => _steps; - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - InternalExposeData(serializer); - } - - private void InternalExposeData(ObjectSerializer serializer) - { - var moduleManager = IoCManager.Resolve(); - - serializer.DataField(this, x => x.Target, "to", string.Empty); - if (!moduleManager.IsServerModule) return; - serializer.DataField(ref _conditions, "conditions", new List()); - serializer.DataField(ref _completed, "completed", new List()); - } - - public void LoadFrom(YamlMappingNode mapping) - { - var serializer = YamlObjectSerializer.NewReader(mapping); - InternalExposeData(serializer); - - if (!mapping.TryGetNode("steps", out YamlSequenceNode? stepsMapping)) return; - - foreach (var yamlNode in stepsMapping) - { - var stepMapping = (YamlMappingNode) yamlNode; - _steps.Add(LoadStep(stepMapping)); - } - } - - public static ConstructionGraphStep LoadStep(YamlMappingNode mapping) - { - var stepSerializer = YamlObjectSerializer.NewReader(mapping); - - if (mapping.TryGetNode("material", out _)) - { - var material = new MaterialConstructionGraphStep(); - material.ExposeData(stepSerializer); - return material; - } - - if (mapping.TryGetNode("tool", out _)) - { - var tool = new ToolConstructionGraphStep(); - tool.ExposeData(stepSerializer); - return tool; - } - - if (mapping.TryGetNode("prototype", out _)) - { - var prototype = new PrototypeConstructionGraphStep(); - prototype.ExposeData(stepSerializer); - return prototype; - } - - if (mapping.TryGetNode("component", out _)) - { - var component = new ComponentConstructionGraphStep(); - component.ExposeData(stepSerializer); - return component; - } - - if (mapping.TryGetNode("tag", out _)) - { - var tags = new TagConstructionGraphStep(); - tags.ExposeData(stepSerializer); - return tags; - } - - if (mapping.TryGetNode("allTags", out _) || mapping.TryGetNode("anyTags", out _)) - { - var tags = new MultipleTagsConstructionGraphStep(); - tags.ExposeData(stepSerializer); - return tags; - } - - if(mapping.TryGetNode("steps", out _)) - { - var nested = new NestedConstructionGraphStep(); - nested.ExposeData(stepSerializer); - nested.LoadFrom(mapping); - return nested; - } - - throw new ArgumentException("Tried to convert invalid YAML node mapping to ConstructionGraphStep!"); - } } } diff --git a/Content.Shared/Construction/ConstructionGraphNode.cs b/Content.Shared/Construction/ConstructionGraphNode.cs index 8c0437a37f..9c86d7b3a2 100644 --- a/Content.Shared/Construction/ConstructionGraphNode.cs +++ b/Content.Shared/Construction/ConstructionGraphNode.cs @@ -1,22 +1,22 @@ using System; using System.Collections.Generic; -using Content.Shared.Interfaces; -using Robust.Shared.IoC; -using Robust.Shared.Serialization; -using Robust.Shared.Utility; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; -using YamlDotNet.RepresentationModel; -using ObjectSerializer = Robust.Shared.Serialization.ObjectSerializer; namespace Content.Shared.Construction { [Serializable] + [DataDefinition] public class ConstructionGraphNode { + [DataField("actions", serverOnly: true)] private List _actions = new(); + [DataField("edges")] private List _edges = new(); [ViewVariables] + [DataField("node")] public string Name { get; private set; } [ViewVariables] @@ -26,34 +26,9 @@ namespace Content.Shared.Construction public IReadOnlyList Actions => _actions; [ViewVariables] + [DataField("entity")] public string Entity { get; private set; } - public void ExposeData(ObjectSerializer serializer) - { - var moduleManager = IoCManager.Resolve(); - - serializer.DataField(this, x => x.Name, "node", string.Empty); - serializer.DataField(this, x => x.Entity, "entity",string.Empty); - if (!moduleManager.IsServerModule) return; - serializer.DataField(ref _actions, "actions", new List()); - } - - public void LoadFrom(YamlMappingNode mapping) - { - var serializer = YamlObjectSerializer.NewReader(mapping); - ExposeData(serializer); - - if (!mapping.TryGetNode("edges", out YamlSequenceNode edgesMapping)) return; - - foreach (var yamlNode in edgesMapping) - { - var edgeMapping = (YamlMappingNode) yamlNode; - var edge = new ConstructionGraphEdge(); - edge.LoadFrom(edgeMapping); - _edges.Add(edge); - } - } - public ConstructionGraphEdge GetEdge(string target) { foreach (var edge in _edges) diff --git a/Content.Shared/Construction/ConstructionGraphPrototype.cs b/Content.Shared/Construction/ConstructionGraphPrototype.cs index ccc8e541a3..0be4934790 100644 --- a/Content.Shared/Construction/ConstructionGraphPrototype.cs +++ b/Content.Shared/Construction/ConstructionGraphPrototype.cs @@ -3,43 +3,41 @@ using System.Collections.Generic; using System.IO; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; -using Robust.Shared.Utility; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; -using YamlDotNet.RepresentationModel; namespace Content.Shared.Construction { [Prototype("constructionGraph")] - public class ConstructionGraphPrototype : IPrototype + public class ConstructionGraphPrototype : IPrototype, ISerializationHooks { private readonly Dictionary _nodes = new(); private readonly Dictionary, ConstructionGraphNode[]> _paths = new(); private readonly Dictionary> _pathfinding = new(); [ViewVariables] - public string ID { get; private set; } + [field: DataField("id", required: true)] + public string ID { get; } = default!; + + [field: DataField("parent")] public string Parent { get; } [ViewVariables] - public string Start { get; private set; } + [field: DataField("start")] + public string Start { get; } + + [DataField("graph", priority: 0)] + private List _graph = new(); [ViewVariables] public IReadOnlyDictionary Nodes => _nodes; - public void LoadFrom(YamlMappingNode mapping) + void ISerializationHooks.AfterDeserialization() { - var serializer = YamlObjectSerializer.NewReader(mapping); + _nodes.Clear(); - serializer.DataField(this, x => x.ID, "id", string.Empty); - serializer.DataField(this, x => x.Start, "start", string.Empty); - - if (!mapping.TryGetNode("graph", out YamlSequenceNode graphMapping)) return; - - foreach (var yamlNode in graphMapping) + foreach (var graphNode in _graph) { - var childMapping = (YamlMappingNode) yamlNode; - var node = new ConstructionGraphNode(); - node.LoadFrom(childMapping); - _nodes[node.Name] = node; + _nodes[graphNode.Name] = graphNode; } if(string.IsNullOrEmpty(Start) || !_nodes.ContainsKey(Start)) diff --git a/Content.Shared/Construction/ConstructionGraphStep.cs b/Content.Shared/Construction/ConstructionGraphStep.cs index 7d00d147c0..8d81406f33 100644 --- a/Content.Shared/Construction/ConstructionGraphStep.cs +++ b/Content.Shared/Construction/ConstructionGraphStep.cs @@ -1,29 +1,21 @@ #nullable enable using System; using System.Collections.Generic; -using Content.Shared.Interfaces; -using Robust.Shared.IoC; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; namespace Content.Shared.Construction { [Serializable] - public abstract class ConstructionGraphStep : IExposeData + [ImplicitDataDefinitionForInheritors] + public abstract class ConstructionGraphStep { - private List _completed = new(); - public float DoAfter { get; private set; } + [DataField("completed", serverOnly: true)] private List _completed = new(); + + [DataField("doAfter")] public float DoAfter { get; private set; } + public IReadOnlyList Completed => _completed; - public virtual void ExposeData(ObjectSerializer serializer) - { - var moduleManager = IoCManager.Resolve(); - - serializer.DataField(this, x => x.DoAfter, "doAfter", 0f); - if (!moduleManager.IsServerModule) return; - serializer.DataField(ref _completed, "completed", new List()); - } - public abstract void DoExamine(FormattedMessage message, bool inDetailsRange); } } diff --git a/Content.Shared/Construction/ConstructionGraphStepTypeSerializer.cs b/Content.Shared/Construction/ConstructionGraphStepTypeSerializer.cs new file mode 100644 index 0000000000..cedb39a782 --- /dev/null +++ b/Content.Shared/Construction/ConstructionGraphStepTypeSerializer.cs @@ -0,0 +1,76 @@ +#nullable enable +using System; +using Robust.Shared.IoC; +using Robust.Shared.Serialization.Manager; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.Serialization.Manager.Result; +using Robust.Shared.Serialization.Markdown; +using Robust.Shared.Serialization.Markdown.Validation; +using Robust.Shared.Serialization.TypeSerializers.Interfaces; + +namespace Content.Shared.Construction +{ + [TypeSerializer] + public class ConstructionGraphStepTypeSerializer : ITypeReader + { + private Type? GetType(MappingDataNode node) + { + if (node.HasNode("material")) + { + return typeof(MaterialConstructionGraphStep); + } + else if (node.HasNode("tool")) + { + return typeof(ToolConstructionGraphStep); + } + else if (node.HasNode("prototype")) + { + return typeof(PrototypeConstructionGraphStep); + } + else if (node.HasNode("component")) + { + return typeof(ComponentConstructionGraphStep); + } + else if (node.HasNode("tag")) + { + return typeof(TagConstructionGraphStep); + } + else if (node.HasNode("allTags") || node.HasNode("anyTags")) + { + return typeof(MultipleTagsConstructionGraphStep); + } + else if (node.HasNode("steps")) + { + return typeof(NestedConstructionGraphStep); + } + else + { + return null; + } + } + + public DeserializationResult Read(ISerializationManager serializationManager, + MappingDataNode node, + IDependencyCollection dependencies, + bool skipHook, + ISerializationContext? context = null) + { + var type = GetType(node) ?? + throw new ArgumentException( + "Tried to convert invalid YAML node mapping to ConstructionGraphStep!"); + + return serializationManager.Read(type, node, context, skipHook); + } + + public ValidationNode Validate(ISerializationManager serializationManager, MappingDataNode node, + IDependencyCollection dependencies, + ISerializationContext? context = null) + { + var type = GetType(node); + + if (type == null) return new ErrorNode(node, "No construction graph step type found.", true); + + return serializationManager.ValidateNode(type, node, context); + } + } +} diff --git a/Content.Shared/Construction/ConstructionPrototype.cs b/Content.Shared/Construction/ConstructionPrototype.cs index 88bb63e84c..abb05b05e1 100644 --- a/Content.Shared/Construction/ConstructionPrototype.cs +++ b/Content.Shared/Construction/ConstructionPrototype.cs @@ -1,85 +1,81 @@ #nullable enable using System.Collections.Generic; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; +using Robust.Shared.ViewVariables; namespace Content.Shared.Construction { [Prototype("construction")] public class ConstructionPrototype : IPrototype { - private List _conditions = new(); + [DataField("conditions")] private List _conditions = new(); /// /// Friendly name displayed in the construction GUI. /// - public string Name { get; private set; } = string.Empty; + [field: DataField("name")] + public string Name { get; } = string.Empty; /// /// "Useful" description displayed in the construction GUI. /// - public string Description { get; private set; } = string.Empty; + [field: DataField("description")] + public string Description { get; } = string.Empty; /// /// The this construction will be using. /// - public string Graph { get; private set; } = string.Empty; + [field: DataField("graph")] + public string Graph { get; } = string.Empty; /// /// The target this construction will guide the user to. /// - public string TargetNode { get; private set; } = string.Empty; + [field: DataField("targetNode")] + public string TargetNode { get; } = string.Empty; /// /// The starting this construction will start at. /// - public string StartNode { get; private set; } = string.Empty; + [field: DataField("startNode")] + public string StartNode { get; } = string.Empty; /// /// Texture path inside the construction GUI. /// - public SpriteSpecifier Icon { get; private set; } = SpriteSpecifier.Invalid; + [field: DataField("icon")] + public SpriteSpecifier Icon { get; } = SpriteSpecifier.Invalid; /// /// If you can start building or complete steps on impassable terrain. /// + [DataField("canBuildInImpassable")] public bool CanBuildInImpassable { get; private set; } - public string Category { get; private set; } = string.Empty; + [DataField("category")] public string Category { get; private set; } = string.Empty; - public ConstructionType Type { get; private set; } = ConstructionType.Structure; + [DataField("objectType")] public ConstructionType Type { get; private set; } = ConstructionType.Structure; - public string ID { get; private set; } = string.Empty; + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; - public string PlacementMode { get; private set; } = "PlaceFree"; + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } + + [field: DataField("placementMode")] + public string PlacementMode { get; } = "PlaceFree"; /// /// Whether this construction can be constructed rotated or not. /// - public bool CanRotate { get; private set; } + [field: DataField("canRotate")] + public bool CanRotate { get; } = true; public IReadOnlyList Conditions => _conditions; - - public void LoadFrom(YamlMappingNode mapping) - { - var ser = YamlObjectSerializer.NewReader(mapping); - Name = ser.ReadDataField("name"); - - ser.DataField(this, x => x.ID, "id", string.Empty); - ser.DataField(this, x => x.Graph, "graph", string.Empty); - ser.DataField(this, x => x.TargetNode, "targetNode", string.Empty); - ser.DataField(this, x => x.StartNode, "startNode", string.Empty); - ser.DataField(this, x => x.Description, "description", string.Empty); - ser.DataField(this, x => x.Icon, "icon", SpriteSpecifier.Invalid); - ser.DataField(this, x => x.Type, "objectType", ConstructionType.Structure); - ser.DataField(this, x => x.PlacementMode, "placementMode", "PlaceFree"); - ser.DataField(this, x => x.CanBuildInImpassable, "canBuildInImpassable", false); - ser.DataField(this, x => x.Category, "category", string.Empty); - ser.DataField(this, x => x.CanRotate, "canRotate", true); - ser.DataField(ref _conditions, "conditions", new List()); - } } public enum ConstructionType diff --git a/Content.Shared/Construction/EntityInsertConstructionGraphStep.cs b/Content.Shared/Construction/EntityInsertConstructionGraphStep.cs index 00da4c757b..9d5fabb6d1 100644 --- a/Content.Shared/Construction/EntityInsertConstructionGraphStep.cs +++ b/Content.Shared/Construction/EntityInsertConstructionGraphStep.cs @@ -1,19 +1,13 @@ #nullable enable using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.Construction { + [ImplicitDataDefinitionForInheritors] public abstract class EntityInsertConstructionGraphStep : ConstructionGraphStep { - public string Store { get; private set; } = string.Empty; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, x => x.Store, "store", string.Empty); - } + [field: DataField("store")] public string Store { get; } = string.Empty; public abstract bool EntityValid(IEntity entity); } diff --git a/Content.Shared/Construction/IConstructionCondition.cs b/Content.Shared/Construction/IConstructionCondition.cs index 57cde5223c..0541448024 100644 --- a/Content.Shared/Construction/IConstructionCondition.cs +++ b/Content.Shared/Construction/IConstructionCondition.cs @@ -1,11 +1,10 @@ using Robust.Shared.GameObjects; using Robust.Shared.Map; using Robust.Shared.Maths; -using Robust.Shared.Serialization; namespace Content.Shared.Construction { - public interface IConstructionCondition : IExposeData + public interface IConstructionCondition { bool Condition(IEntity user, EntityCoordinates location, Direction direction); } diff --git a/Content.Shared/Construction/IEdgeCondition.cs b/Content.Shared/Construction/IEdgeCondition.cs index 8eb04370c1..9aa08ace13 100644 --- a/Content.Shared/Construction/IEdgeCondition.cs +++ b/Content.Shared/Construction/IEdgeCondition.cs @@ -1,12 +1,11 @@ #nullable enable using System.Threading.Tasks; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; using Robust.Shared.Utility; namespace Content.Shared.Construction { - public interface IEdgeCondition : IExposeData + public interface IEdgeCondition { Task Condition(IEntity entity); bool DoExamine(IEntity entity, FormattedMessage message, bool inExamineRange) { return false; } diff --git a/Content.Shared/Construction/IGraphAction.cs b/Content.Shared/Construction/IGraphAction.cs index e9dad57844..d9bbe30688 100644 --- a/Content.Shared/Construction/IGraphAction.cs +++ b/Content.Shared/Construction/IGraphAction.cs @@ -1,11 +1,10 @@ #nullable enable using System.Threading.Tasks; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; namespace Content.Shared.Construction { - public interface IGraphAction : IExposeData + public interface IGraphAction { Task PerformAction(IEntity entity, IEntity? user); } diff --git a/Content.Shared/Construction/MaterialConstructionGraphStep.cs b/Content.Shared/Construction/MaterialConstructionGraphStep.cs index ecdc86af81..56070e2a3e 100644 --- a/Content.Shared/Construction/MaterialConstructionGraphStep.cs +++ b/Content.Shared/Construction/MaterialConstructionGraphStep.cs @@ -1,37 +1,28 @@ #nullable enable using System.Diagnostics.CodeAnalysis; using Content.Shared.GameObjects.Components; -using Content.Shared.Materials; using Content.Shared.Stacks; -using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; namespace Content.Shared.Construction { + [DataDefinition] public class MaterialConstructionGraphStep : EntityInsertConstructionGraphStep { // TODO: Make this use the material system. // TODO TODO: Make the material system not shit. - private string MaterialPrototypeId { get; [UsedImplicitly] set; } = default!; + [field: DataField("material")] public string MaterialPrototypeId { get; } = "Steel"; + + [field: DataField("amount")] public int Amount { get; } = 1; public StackPrototype MaterialPrototype => IoCManager.Resolve().Index(MaterialPrototypeId); - public int Amount { get; private set; } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, x => x.MaterialPrototypeId, "material", "Steel"); - serializer.DataField(this, x => x.Amount, "amount", 1); - } - public override void DoExamine(FormattedMessage message, bool inDetailsRange) { message.AddMarkup(Loc.GetString("Next, add [color=yellow]{0}x[/color] [color=cyan]{1}[/color].", Amount, MaterialPrototype.Name)); diff --git a/Content.Shared/Construction/MultipleTagsConstructionGraphStep.cs b/Content.Shared/Construction/MultipleTagsConstructionGraphStep.cs index fd4bd220c6..a65f248ddf 100644 --- a/Content.Shared/Construction/MultipleTagsConstructionGraphStep.cs +++ b/Content.Shared/Construction/MultipleTagsConstructionGraphStep.cs @@ -1,24 +1,18 @@ #nullable enable -using System.Collections; using System.Collections.Generic; using Content.Shared.GameObjects.Components.Tag; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.Construction { public class MultipleTagsConstructionGraphStep : ArbitraryInsertConstructionGraphStep { - private List? _allTags = null; - private List? _anyTags = null; + [DataField("allTags")] + private List? _allTags; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _allTags, "allTags", null); - serializer.DataField(ref _anyTags, "anyTags", null); - } + [DataField("anyTags")] + private List? _anyTags; private static bool IsNullOrEmpty(ICollection? list) { diff --git a/Content.Shared/Construction/NestedConstructionGraphStep.cs b/Content.Shared/Construction/NestedConstructionGraphStep.cs index 25f8b14c33..75018d9b7a 100644 --- a/Content.Shared/Construction/NestedConstructionGraphStep.cs +++ b/Content.Shared/Construction/NestedConstructionGraphStep.cs @@ -1,36 +1,23 @@ #nullable enable using System.Collections.Generic; using System.IO; +using System.Linq; +using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; namespace Content.Shared.Construction { - public class NestedConstructionGraphStep : ConstructionGraphStep + [DataDefinition] + public class NestedConstructionGraphStep : ConstructionGraphStep, ISerializationHooks { - public List> Steps { get; private set; } = new(); + [DataField("steps")] public List> Steps { get; private set; } = new(); - public void LoadFrom(YamlMappingNode mapping) + void ISerializationHooks.AfterDeserialization() { - if (!mapping.TryGetNode("steps", out YamlSequenceNode? steps)) return; - - foreach (var node in steps) + if (Steps.Any(inner => inner.Any(step => step is NestedConstructionGraphStep))) { - var sequence = (YamlSequenceNode) node; - var list = new List(); - - foreach (var innerNode in sequence) - { - var stepNode = (YamlMappingNode) innerNode; - var step = ConstructionGraphEdge.LoadStep(stepNode); - - if(step is NestedConstructionGraphStep) - throw new InvalidDataException("Can't have nested construction steps inside nested construction steps!"); - - list.Add(step); - } - - Steps.Add(list); + throw new InvalidDataException("Can't have nested construction steps inside nested construction steps!"); } } diff --git a/Content.Shared/Construction/PrototypeConstructionGraphStep.cs b/Content.Shared/Construction/PrototypeConstructionGraphStep.cs index fcd713936e..6ea918a79d 100644 --- a/Content.Shared/Construction/PrototypeConstructionGraphStep.cs +++ b/Content.Shared/Construction/PrototypeConstructionGraphStep.cs @@ -1,21 +1,15 @@ #nullable enable using Robust.Shared.GameObjects; using Robust.Shared.Localization; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; namespace Content.Shared.Construction { + [DataDefinition] public class PrototypeConstructionGraphStep : ArbitraryInsertConstructionGraphStep { - public string Prototype { get; private set; } = string.Empty; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, x => x.Prototype, "prototype", string.Empty); - } + [field: DataField("prototype")] public string Prototype { get; } = string.Empty; public override bool EntityValid(IEntity entity) { diff --git a/Content.Shared/Construction/TagConstructionGraphStep.cs b/Content.Shared/Construction/TagConstructionGraphStep.cs index 4532598009..63d05a5b6b 100644 --- a/Content.Shared/Construction/TagConstructionGraphStep.cs +++ b/Content.Shared/Construction/TagConstructionGraphStep.cs @@ -1,22 +1,16 @@ #nullable enable -using System.Collections.Generic; using Content.Shared.GameObjects.Components.Tag; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.Construction { + [DataDefinition] public class TagConstructionGraphStep : ArbitraryInsertConstructionGraphStep { + [DataField("tag")] private string? _tag = null; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _tag, "tag", null); - } - public override bool EntityValid(IEntity entity) { return !string.IsNullOrEmpty(_tag) && entity.HasTag(_tag); diff --git a/Content.Shared/Construction/ToolConstructionGraphStep.cs b/Content.Shared/Construction/ToolConstructionGraphStep.cs index e513b6931b..e9b4e993b1 100644 --- a/Content.Shared/Construction/ToolConstructionGraphStep.cs +++ b/Content.Shared/Construction/ToolConstructionGraphStep.cs @@ -1,25 +1,19 @@ #nullable enable using Content.Shared.GameObjects.Components.Interactable; using Robust.Shared.Localization; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; namespace Content.Shared.Construction { + [DataDefinition] public class ToolConstructionGraphStep : ConstructionGraphStep { - public ToolQuality Tool { get; private set; } - public float Fuel { get; private set; } - public string ExamineOverride { get; private set; } = string.Empty; + [field: DataField("tool")] public ToolQuality Tool { get; } = ToolQuality.None; - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); + [field: DataField("fuel")] public float Fuel { get; } = 10; - serializer.DataField(this, x => x.Tool, "tool", ToolQuality.None); - serializer.DataField(this, x => x.Fuel, "fuel", 10f); // Default fuel cost. - serializer.DataField(this, x => x.ExamineOverride, "examine", string.Empty); - } + [field: DataField("examine")] public string ExamineOverride { get; } = string.Empty; public override void DoExamine(FormattedMessage message, bool inDetailsRange) { diff --git a/Content.Shared/Content.Shared.csproj b/Content.Shared/Content.Shared.csproj index da83e179b2..61e07381d0 100644 --- a/Content.Shared/Content.Shared.csproj +++ b/Content.Shared/Content.Shared.csproj @@ -32,4 +32,5 @@ + diff --git a/Content.Shared/Damage/DamageContainer/DamageContainerPrototype.cs b/Content.Shared/Damage/DamageContainer/DamageContainerPrototype.cs index 6c58ec2bf9..5a81827c88 100644 --- a/Content.Shared/Damage/DamageContainer/DamageContainerPrototype.cs +++ b/Content.Shared/Damage/DamageContainer/DamageContainerPrototype.cs @@ -3,8 +3,8 @@ using System; using System.Collections.Generic; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; -using YamlDotNet.RepresentationModel; namespace Content.Shared.Damage.DamageContainer { @@ -13,29 +13,27 @@ namespace Content.Shared.Damage.DamageContainer /// [Prototype("damageContainer")] [Serializable, NetSerializable] - public class DamageContainerPrototype : IPrototype + public class DamageContainerPrototype : IPrototype, ISerializationHooks { - private bool _supportAll; - private HashSet _supportedClasses = new(); - private HashSet _supportedTypes = new(); - private string _id = string.Empty; + [DataField("supportAll")] private bool _supportAll; + [DataField("supportedClasses")] private HashSet _supportedClasses = new(); + [DataField("supportedTypes")] private HashSet _supportedTypes = new(); // TODO NET 5 IReadOnlySet [ViewVariables] public IReadOnlyCollection SupportedClasses => _supportedClasses; [ViewVariables] public IReadOnlyCollection SupportedTypes => _supportedTypes; - [ViewVariables] public string ID => _id; + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; - public virtual void LoadFrom(YamlMappingNode mapping) + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } + + void ISerializationHooks.AfterDeserialization() { - var serializer = YamlObjectSerializer.NewReader(mapping); - - serializer.DataField(ref _id, "id", string.Empty); - serializer.DataField(ref _supportAll, "supportAll", false); - serializer.DataField(ref _supportedClasses, "supportedClasses", new HashSet()); - serializer.DataField(ref _supportedTypes, "supportedTypes", new HashSet()); - if (_supportAll) { _supportedClasses.UnionWith(Enum.GetValues()); diff --git a/Content.Shared/Damage/ResistanceSet/ResistanceSetPrototype.cs b/Content.Shared/Damage/ResistanceSet/ResistanceSetPrototype.cs index 24cbf524d4..13484c41c4 100644 --- a/Content.Shared/Damage/ResistanceSet/ResistanceSetPrototype.cs +++ b/Content.Shared/Damage/ResistanceSet/ResistanceSetPrototype.cs @@ -3,8 +3,8 @@ using System; using System.Collections.Generic; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; -using YamlDotNet.RepresentationModel; namespace Content.Shared.Damage.ResistanceSet { @@ -13,33 +13,34 @@ namespace Content.Shared.Damage.ResistanceSet /// [Prototype("resistanceSet")] [Serializable, NetSerializable] - public class ResistanceSetPrototype : IPrototype + public class ResistanceSetPrototype : IPrototype, ISerializationHooks { - private Dictionary _coefficients = new(); - private Dictionary _flatReductions = new(); - private string _id = string.Empty; + [ViewVariables] + [field: DataField("coefficients")] + public Dictionary Coefficients { get; } = new(); - [ViewVariables] public Dictionary Coefficients => _coefficients; + [ViewVariables] + [field: DataField("flatReductions")] + public Dictionary FlatReductions { get; } = new(); - [ViewVariables] public Dictionary FlatReductions => _flatReductions; + [ViewVariables] + public Dictionary Resistances { get; private set; } = new(); - [ViewVariables] public Dictionary Resistances { get; private set; } = new(); + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; - [ViewVariables] public string ID => _id; + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } - public virtual void LoadFrom(YamlMappingNode mapping) + void ISerializationHooks.AfterDeserialization() { - var serializer = YamlObjectSerializer.NewReader(mapping); - - serializer.DataField(ref _id, "id", string.Empty); - serializer.DataField(ref _coefficients, "coefficients", new Dictionary()); - serializer.DataField(ref _flatReductions, "flatReductions", new Dictionary()); - Resistances = new Dictionary(); foreach (var damageType in (DamageType[]) Enum.GetValues(typeof(DamageType))) { Resistances.Add(damageType, - new ResistanceSetSettings(_coefficients[damageType], _flatReductions[damageType])); + new ResistanceSetSettings(Coefficients[damageType], FlatReductions[damageType])); } } } diff --git a/Content.Shared/GameObjects/Components/Body/Behavior/IMechanismBehavior.cs b/Content.Shared/GameObjects/Components/Body/Behavior/IMechanismBehavior.cs index e5fb6f3c9f..c150a41c9c 100644 --- a/Content.Shared/GameObjects/Components/Body/Behavior/IMechanismBehavior.cs +++ b/Content.Shared/GameObjects/Components/Body/Behavior/IMechanismBehavior.cs @@ -2,14 +2,15 @@ using Content.Shared.GameObjects.Components.Body.Mechanism; using Content.Shared.GameObjects.Components.Body.Part; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.GameObjects.Components.Body.Behavior { /// /// Gives functionality to a when added to it. /// - public interface IMechanismBehavior : IExposeData + [ImplicitDataDefinitionForInheritors] + public interface IMechanismBehavior { /// /// The body that owns the in which the diff --git a/Content.Shared/GameObjects/Components/Body/Mechanism/SharedMechanismComponent.cs b/Content.Shared/GameObjects/Components/Body/Mechanism/SharedMechanismComponent.cs index bdcce7326d..a2f139a8ba 100644 --- a/Content.Shared/GameObjects/Components/Body/Mechanism/SharedMechanismComponent.cs +++ b/Content.Shared/GameObjects/Components/Body/Mechanism/SharedMechanismComponent.cs @@ -4,16 +4,16 @@ using System.Collections.Generic; using System.Linq; using Content.Shared.GameObjects.Components.Body.Behavior; using Content.Shared.GameObjects.Components.Body.Part; -using Content.Shared.Interfaces; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; namespace Content.Shared.GameObjects.Components.Body.Mechanism { - public abstract class SharedMechanismComponent : Component, IMechanism + public abstract class SharedMechanismComponent : Component, IMechanism, ISerializationHooks { public override string Name => "Mechanism"; @@ -22,6 +22,9 @@ namespace Content.Shared.GameObjects.Components.Body.Mechanism protected int IdHash; protected IEntity? PerformerCache; private IBodyPart? _part; + + [DataField("behaviors", serverOnly: true)] private HashSet _behaviorTypes = new(); + private readonly Dictionary _behaviors = new(); public IBody? Body => Part?.Body; @@ -67,65 +70,40 @@ namespace Content.Shared.GameObjects.Components.Body.Mechanism public IReadOnlyDictionary Behaviors => _behaviors; - public int MaxDurability { get; set; } + [DataField("maxDurability")] public int MaxDurability { get; set; } = 10; - public int CurrentDurability { get; set; } + [DataField("currentDurability")] public int CurrentDurability { get; set; } = 10; - public int DestroyThreshold { get; set; } + [DataField("destroyThreshold")] public int DestroyThreshold { get; set; } = -10; // TODO BODY: Surgery description and adding a message to the examine tooltip of the entity that owns this mechanism // TODO BODY - public int Resistance { get; set; } + [DataField("resistance")] public int Resistance { get; set; } = 0; // TODO BODY OnSizeChanged - public int Size { get; set; } + [DataField("size")] public int Size { get; set; } = 1; - public BodyPartCompatibility Compatibility { get; set; } + [DataField("compatibility")] + public BodyPartCompatibility Compatibility { get; set; } = BodyPartCompatibility.Universal; - public override void ExposeData(ObjectSerializer serializer) + void ISerializationHooks.BeforeSerialization() { - base.ExposeData(serializer); + _behaviorTypes = _behaviors.Values.ToHashSet(); + } - serializer.DataField(this, m => m.MaxDurability, "maxDurability", 10); - - serializer.DataField(this, m => m.CurrentDurability, "currentDurability", MaxDurability); - - serializer.DataField(this, m => m.DestroyThreshold, "destroyThreshold", -MaxDurability); - - serializer.DataField(this, m => m.Resistance, "resistance", 0); - - serializer.DataField(this, m => m.Size, "size", 1); - - serializer.DataField(this, m => m.Compatibility, "compatibility", BodyPartCompatibility.Universal); - - var moduleManager = IoCManager.Resolve(); - - if (moduleManager.IsServerModule) + void ISerializationHooks.AfterDeserialization() + { + foreach (var behavior in _behaviorTypes) { - serializer.DataReadWriteFunction( - "behaviors", - null!, - behaviors => - { - if (behaviors == null) - { - return; - } + var type = behavior.GetType(); - foreach (var behavior in behaviors) - { - var type = behavior.GetType(); + if (!_behaviors.TryAdd(type, behavior)) + { + Logger.Warning($"Duplicate behavior in {nameof(SharedMechanismComponent)}: {type}."); + continue; + } - if (!_behaviors.TryAdd(type, behavior)) - { - Logger.Warning($"Duplicate behavior in {nameof(SharedMechanismComponent)} for entity {Owner.Name}: {type}."); - continue; - } - - IoCManager.InjectDependencies(behavior); - } - }, - () => _behaviors.Values.ToList()); + IoCManager.InjectDependencies(behavior); } } diff --git a/Content.Shared/GameObjects/Components/Body/Part/Property/BodyPartPropertyComponent.cs b/Content.Shared/GameObjects/Components/Body/Part/Property/BodyPartPropertyComponent.cs index 1de5d0a53f..8736228b25 100644 --- a/Content.Shared/GameObjects/Components/Body/Part/Property/BodyPartPropertyComponent.cs +++ b/Content.Shared/GameObjects/Components/Body/Part/Property/BodyPartPropertyComponent.cs @@ -1,6 +1,6 @@ -#nullable enable +#nullable enable using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.GameObjects.Components.Body.Part.Property { @@ -15,13 +15,7 @@ namespace Content.Shared.GameObjects.Components.Body.Part.Property /// /// Whether this property is currently active. /// - public bool Active { get; set; } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, b => b.Active, "active", true); - } + [DataField("active")] + public bool Active { get; set; } = true; } } diff --git a/Content.Shared/GameObjects/Components/Body/Part/Property/ExtensionComponent.cs b/Content.Shared/GameObjects/Components/Body/Part/Property/ExtensionComponent.cs index bacd273839..e43554e103 100644 --- a/Content.Shared/GameObjects/Components/Body/Part/Property/ExtensionComponent.cs +++ b/Content.Shared/GameObjects/Components/Body/Part/Property/ExtensionComponent.cs @@ -1,6 +1,6 @@ -#nullable enable +#nullable enable using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.GameObjects.Components.Body.Part.Property { @@ -15,13 +15,7 @@ namespace Content.Shared.GameObjects.Components.Body.Part.Property /// /// Current distance in tiles. /// - public float Distance { get; set; } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, e => e.Distance, "distance", 3f); - } + [DataField("distance")] + public float Distance { get; set; } = 3f; } } diff --git a/Content.Shared/GameObjects/Components/Body/Part/Property/LegComponent.cs b/Content.Shared/GameObjects/Components/Body/Part/Property/LegComponent.cs index f94b84fe74..4e7213cdfd 100644 --- a/Content.Shared/GameObjects/Components/Body/Part/Property/LegComponent.cs +++ b/Content.Shared/GameObjects/Components/Body/Part/Property/LegComponent.cs @@ -1,6 +1,6 @@ -#nullable enable +#nullable enable using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.GameObjects.Components.Body.Part.Property { @@ -15,13 +15,7 @@ namespace Content.Shared.GameObjects.Components.Body.Part.Property /// /// Speed in tiles per second. /// - public float Speed { get; set; } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, l => l.Speed, "speed", 2.6f); - } + [DataField("speed")] + public float Speed { get; set; } = 2.6f; } } diff --git a/Content.Shared/GameObjects/Components/Body/Part/SharedBodyPartComponent.cs b/Content.Shared/GameObjects/Components/Body/Part/SharedBodyPartComponent.cs index 19eed73698..899d50c97e 100644 --- a/Content.Shared/GameObjects/Components/Body/Part/SharedBodyPartComponent.cs +++ b/Content.Shared/GameObjects/Components/Body/Part/SharedBodyPartComponent.cs @@ -9,6 +9,7 @@ using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Players; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -23,6 +24,7 @@ namespace Content.Shared.GameObjects.Components.Body.Part private IBody? _body; // TODO BODY Remove + [DataField("mechanisms")] private List _mechanismIds = new(); public IReadOnlyList MechanismIds => _mechanismIds; @@ -55,8 +57,11 @@ namespace Content.Shared.GameObjects.Components.Body.Part } } - [ViewVariables] public BodyPartType PartType { get; private set; } - [ViewVariables] public int Size { get; private set; } + [ViewVariables] + [DataField("partType")] + public BodyPartType PartType { get; private set; } = BodyPartType.Other; + + [ViewVariables] [DataField("size")] public int Size { get; private set; } = 1; [ViewVariables] public int SizeUsed { get; private set; } @@ -69,7 +74,8 @@ namespace Content.Shared.GameObjects.Components.Body.Part /// attach between types. /// [ViewVariables] - public BodyPartCompatibility Compatibility { get; private set; } + [DataField("compatibility")] + public BodyPartCompatibility Compatibility { get; private set; } = BodyPartCompatibility.Universal; /// /// Set of all currently inside this @@ -84,10 +90,12 @@ namespace Content.Shared.GameObjects.Components.Body.Part /// If the last vital body part is removed creature dies /// [ViewVariables] - public bool IsVital { get; private set; } + [DataField("vital")] + public bool IsVital { get; private set; } = false; [ViewVariables] - public BodyPartSymmetry Symmetry { get; private set; } + [DataField("symmetry")] + public BodyPartSymmetry Symmetry { get; private set; } = BodyPartSymmetry.None; [ViewVariables] public ISurgeryData? SurgeryDataComponent => Owner.GetComponentOrNull(); @@ -116,25 +124,6 @@ namespace Content.Shared.GameObjects.Components.Body.Part Dirty(); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - // TODO BODY serialize any changed properties? - - serializer.DataField(this, b => b.PartType, "partType", BodyPartType.Other); - - serializer.DataField(this, b => b.Size, "size", 1); - - serializer.DataField(this, b => b.Compatibility, "compatibility", BodyPartCompatibility.Universal); - - serializer.DataField(this, b => b.IsVital, "vital", false); - - serializer.DataField(this, b => b.Symmetry, "symmetry", BodyPartSymmetry.None); - - serializer.DataField(ref _mechanismIds, "mechanisms", new List()); - } - public override ComponentState GetComponentState(ICommonSession player) { var mechanismIds = new EntityUid[_mechanisms.Count]; diff --git a/Content.Shared/GameObjects/Components/Body/Preset/BodyPresetPrototype.cs b/Content.Shared/GameObjects/Components/Body/Preset/BodyPresetPrototype.cs index da410318db..996bb972ef 100644 --- a/Content.Shared/GameObjects/Components/Body/Preset/BodyPresetPrototype.cs +++ b/Content.Shared/GameObjects/Components/Body/Preset/BodyPresetPrototype.cs @@ -4,8 +4,8 @@ using System.Collections.Generic; using Content.Shared.GameObjects.Components.Body.Part; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; -using YamlDotNet.RepresentationModel; namespace Content.Shared.GameObjects.Components.Body.Preset { @@ -16,22 +16,21 @@ namespace Content.Shared.GameObjects.Components.Body.Preset [Serializable, NetSerializable] public class BodyPresetPrototype : IPrototype { - private string _id = string.Empty; - private string _name = string.Empty; + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; + + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } + + [DataField("partIDs")] private Dictionary _partIDs = new(); - [ViewVariables] public string ID => _id; - - [ViewVariables] public string Name => _name; + [ViewVariables] + [field: DataField("name")] + public string Name { get; } = string.Empty; [ViewVariables] public Dictionary PartIDs => new(_partIDs); - - public virtual void LoadFrom(YamlMappingNode mapping) - { - var serializer = YamlObjectSerializer.NewReader(mapping); - serializer.DataField(ref _id, "id", string.Empty); - serializer.DataField(ref _name, "name", string.Empty); - serializer.DataField(ref _partIDs, "partIDs", new Dictionary()); - } } } diff --git a/Content.Shared/GameObjects/Components/Body/SharedBodyComponent.cs b/Content.Shared/GameObjects/Components/Body/SharedBodyComponent.cs index 1140ac691e..24cfca38f8 100644 --- a/Content.Shared/GameObjects/Components/Body/SharedBodyComponent.cs +++ b/Content.Shared/GameObjects/Components/Body/SharedBodyComponent.cs @@ -16,13 +16,14 @@ using Robust.Shared.IoC; using Robust.Shared.Players; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; namespace Content.Shared.GameObjects.Components.Body { // TODO BODY Damage methods for collections of IDamageableComponents - public abstract class SharedBodyComponent : Component, IBody + public abstract class SharedBodyComponent : Component, IBody, ISerializationHooks { [Dependency] private readonly IPrototypeManager _prototypeManager = default!; @@ -30,15 +31,20 @@ namespace Content.Shared.GameObjects.Components.Body public override uint? NetID => ContentNetIDs.BODY; + [DataField("centerSlot", required: true)] private string? _centerSlot; private Dictionary _partIds = new(); private readonly Dictionary _parts = new(); - [ViewVariables] public string? TemplateName { get; private set; } + [ViewVariables] + [DataField("template", required: true)] + public string? TemplateName { get; private set; } - [ViewVariables] public string? PresetName { get; private set; } + [ViewVariables] + [DataField("preset", required: true)] + public string? PresetName { get; private set; } [ViewVariables] public Dictionary Slots { get; private set; } = new(); @@ -56,6 +62,62 @@ namespace Content.Shared.GameObjects.Components.Body [ViewVariables] public IReadOnlyDictionary PartIDs => _partIds; + public override void Initialize() + { + base.Initialize(); + + // TODO BODY BeforeDeserialization + // TODO BODY Move to template or somewhere else + if (TemplateName != null) + { + var template = _prototypeManager.Index(TemplateName); + + Connections = template.Connections; + Slots = template.Slots; + _centerSlot = template.CenterSlot; + } + + if (PresetName != null) + { + var preset = _prototypeManager.Index(PresetName); + + _partIds = preset.PartIDs; + } + + // Our prototypes don't force the user to define a BodyPart connection twice. E.g. Head: Torso v.s. Torso: Head. + // The user only has to do one. We want it to be that way in the code, though, so this cleans that up. + var cleanedConnections = new Dictionary>(); + + foreach (var targetSlotName in Slots.Keys) + { + var tempConnections = new List(); + foreach (var (slotName, slotConnections) in Connections) + { + if (slotName == targetSlotName) + { + foreach (var connection in slotConnections) + { + if (!tempConnections.Contains(connection)) + { + tempConnections.Add(connection); + } + } + } + else if (slotConnections.Contains(targetSlotName)) + { + tempConnections.Add(slotName); + } + } + + if (tempConnections.Count > 0) + { + cleanedConnections.Add(targetSlotName, tempConnections); + } + } + + Connections = cleanedConnections; + } + protected virtual bool CanAddPart(string slot, IBodyPart part) { if (!HasSlot(slot) || !_parts.TryAdd(slot, part)) @@ -537,122 +599,6 @@ namespace Content.Shared.GameObjects.Components.Body return Parts.ElementAt(index); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataReadWriteFunction( - "template", - null, - name => - { - if (string.IsNullOrEmpty(name)) - { - return; - } - - var template = _prototypeManager.Index(name); - - Connections = template.Connections; - Slots = template.Slots; - _centerSlot = template.CenterSlot; - - TemplateName = name; - }, - () => TemplateName); - - serializer.DataReadWriteFunction( - "preset", - null, - name => - { - if (string.IsNullOrEmpty(name)) - { - return; - } - - var preset = _prototypeManager.Index(name); - - _partIds = preset.PartIDs; - }, - () => PresetName); - - serializer.DataReadWriteFunction( - "connections", - new Dictionary>(), - connections => - { - foreach (var (from, to) in connections) - { - Connections.GetOrNew(from).AddRange(to); - } - }, - () => Connections); - - serializer.DataReadWriteFunction( - "slots", - new Dictionary(), - slots => - { - foreach (var (part, type) in slots) - { - Slots[part] = type; - } - }, - () => Slots); - - // TODO BODY Move to template or somewhere else - serializer.DataReadWriteFunction( - "centerSlot", - null, - slot => _centerSlot = slot, - () => _centerSlot); - - serializer.DataReadWriteFunction( - "partIds", - new Dictionary(), - partIds => - { - foreach (var (slot, part) in partIds) - { - _partIds[slot] = part; - } - }, - () => _partIds); - - // Our prototypes don't force the user to define a BodyPart connection twice. E.g. Head: Torso v.s. Torso: Head. - // The user only has to do one. We want it to be that way in the code, though, so this cleans that up. - var cleanedConnections = new Dictionary>(); - foreach (var targetSlotName in Slots.Keys) - { - var tempConnections = new List(); - foreach (var (slotName, slotConnections) in Connections) - { - if (slotName == targetSlotName) - { - foreach (var connection in slotConnections) - { - if (!tempConnections.Contains(connection)) - { - tempConnections.Add(connection); - } - } - } - else if (slotConnections.Contains(targetSlotName)) - { - tempConnections.Add(slotName); - } - } - - if (tempConnections.Count > 0) - { - cleanedConnections.Add(targetSlotName, tempConnections); - } - } - - Connections = cleanedConnections; - } - public override ComponentState GetComponentState(ICommonSession player) { var parts = new (string slot, EntityUid partId)[_parts.Count]; diff --git a/Content.Shared/GameObjects/Components/Body/Template/BodyTemplatePrototype.cs b/Content.Shared/GameObjects/Components/Body/Template/BodyTemplatePrototype.cs index cdd87846d2..e0a097f977 100644 --- a/Content.Shared/GameObjects/Components/Body/Template/BodyTemplatePrototype.cs +++ b/Content.Shared/GameObjects/Components/Body/Template/BodyTemplatePrototype.cs @@ -1,12 +1,11 @@ #nullable enable using System; using System.Collections.Generic; -using System.Linq; using Content.Shared.GameObjects.Components.Body.Part; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; -using YamlDotNet.RepresentationModel; namespace Content.Shared.GameObjects.Components.Body.Template { @@ -15,50 +14,58 @@ namespace Content.Shared.GameObjects.Components.Body.Template /// [Prototype("bodyTemplate")] [Serializable, NetSerializable] - public class BodyTemplatePrototype : IPrototype + public class BodyTemplatePrototype : IPrototype, ISerializationHooks { - private string _id = string.Empty; - private string _name = string.Empty; - private string _centerSlot = string.Empty; + [DataField("slots")] private Dictionary _slots = new(); - private Dictionary> _connections = new(); + + [DataField("connections")] + private Dictionary> _rawConnections = new(); + + [DataField("layers")] private Dictionary _layers = new(); + + [DataField("mechanismLayers")] private Dictionary _mechanismLayers = new(); - [ViewVariables] public string ID => _id; - - [ViewVariables] public string Name => _name; - - [ViewVariables] public string CenterSlot => _centerSlot; - - [ViewVariables] public Dictionary Slots => new(_slots); + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; [ViewVariables] - public Dictionary> Connections => - _connections.ToDictionary(x => x.Key, x => x.Value.ToList()); + [field: DataField("parent")] + public string? Parent { get; } - [ViewVariables] public Dictionary Layers => new(_layers); + [ViewVariables] + [field: DataField("name")] + public string Name { get; } = string.Empty; - [ViewVariables] public Dictionary MechanismLayers => new(_mechanismLayers); + [ViewVariables] + [field: DataField("centerSlot")] + public string CenterSlot { get; } = string.Empty; - public virtual void LoadFrom(YamlMappingNode mapping) + [ViewVariables] + public Dictionary Slots => new(_slots); + + [ViewVariables] + public Dictionary> Connections { get; set; } = new(); + + [ViewVariables] + public Dictionary Layers => new(_layers); + + [ViewVariables] + public Dictionary MechanismLayers => new(_mechanismLayers); + + void ISerializationHooks.AfterDeserialization() { - var serializer = YamlObjectSerializer.NewReader(mapping); - serializer.DataField(ref _id, "id", string.Empty); - serializer.DataField(ref _name, "name", string.Empty); - serializer.DataField(ref _centerSlot, "centerSlot", string.Empty); - serializer.DataField(ref _slots, "slots", new Dictionary()); - serializer.DataField(ref _connections, "connections", new Dictionary>()); - serializer.DataField(ref _layers, "layers", new Dictionary()); - serializer.DataField(ref _mechanismLayers, "mechanismLayers", new Dictionary()); - //Our prototypes don't force the user to define a BodyPart connection twice. E.g. Head: Torso v.s. Torso: Head. //The user only has to do one. We want it to be that way in the code, though, so this cleans that up. var cleanedConnections = new Dictionary>(); + foreach (var targetSlotName in _slots.Keys) { var tempConnections = new List(); - foreach (var (slotName, slotConnections) in _connections) + foreach (var (slotName, slotConnections) in _rawConnections) { if (slotName == targetSlotName) { @@ -82,7 +89,7 @@ namespace Content.Shared.GameObjects.Components.Body.Template } } - _connections = cleanedConnections; + Connections = cleanedConnections; } } } diff --git a/Content.Shared/GameObjects/Components/Buckle/SharedBuckleComponent.cs b/Content.Shared/GameObjects/Components/Buckle/SharedBuckleComponent.cs index 8d84a62345..42e8d4ecb7 100644 --- a/Content.Shared/GameObjects/Components/Buckle/SharedBuckleComponent.cs +++ b/Content.Shared/GameObjects/Components/Buckle/SharedBuckleComponent.cs @@ -8,6 +8,7 @@ using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; using Robust.Shared.Physics; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Shared.GameObjects.Components.Buckle @@ -24,14 +25,8 @@ namespace Content.Shared.GameObjects.Components.Buckle /// The range from which this entity can buckle to a . /// [ViewVariables] - public float Range { get; protected set; } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, x => x.Range, "range", SharedInteractionSystem.InteractionRange / 1.4f); - } + [DataField("range")] + public float Range { get; protected set; } = SharedInteractionSystem.InteractionRange / 1.4f; /// /// True if the entity is buckled, false otherwise. diff --git a/Content.Shared/GameObjects/Components/Cargo/SharedGalacticMarketComponent.cs b/Content.Shared/GameObjects/Components/Cargo/SharedGalacticMarketComponent.cs index 1b139ad8d3..2dfee6b1fc 100644 --- a/Content.Shared/GameObjects/Components/Cargo/SharedGalacticMarketComponent.cs +++ b/Content.Shared/GameObjects/Components/Cargo/SharedGalacticMarketComponent.cs @@ -7,21 +7,52 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.GameObjects.Components.Cargo { - public class SharedGalacticMarketComponent : Component, IEnumerable + public class SharedGalacticMarketComponent : Component, IEnumerable, ISerializationHooks { public sealed override string Name => "GalacticMarket"; public sealed override uint? NetID => ContentNetIDs.GALACTIC_MARKET; - protected List _products = new(); + [DataField("products")] + protected List _productIds = new(); + + protected readonly List _products = new(); /// /// A read-only list of products. /// public IReadOnlyList Products => _products; + void ISerializationHooks.AfterDeserialization() + { + var prototypeManager = IoCManager.Resolve(); + + _productIds.Clear(); + + foreach (var id in _productIds) + { + if (!prototypeManager.TryIndex(id, out CargoProductPrototype? product)) + { + continue; + } + + _products.Add(product); + } + } + + void ISerializationHooks.BeforeSerialization() + { + _productIds = new List(); + + foreach (var product in _products) + { + _productIds.Add(product.ID); + } + } + public IEnumerator GetEnumerator() { return _products.GetEnumerator(); @@ -52,7 +83,7 @@ namespace Content.Shared.GameObjects.Components.Cargo /// A list of product IDs public List GetProductIdList() { - List productIds = new List(); + var productIds = new List(); foreach (var product in _products) { @@ -61,31 +92,6 @@ namespace Content.Shared.GameObjects.Components.Cargo return productIds; } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataReadWriteFunction( - "products", - new List(), - products => - { - var prototypeManager = IoCManager.Resolve(); - - _products.Clear(); - foreach (var id in products) - { - if (!prototypeManager.TryIndex(id, out CargoProductPrototype? product)) - { - continue; - } - - _products.Add(product); - } - }, - GetProductIdList); - } } [Serializable, NetSerializable] diff --git a/Content.Shared/GameObjects/Components/Chemistry/ReagentDispenser/ReagentDispenserInventoryPrototype.cs b/Content.Shared/GameObjects/Components/Chemistry/ReagentDispenser/ReagentDispenserInventoryPrototype.cs index 850c23467e..8221a6982a 100644 --- a/Content.Shared/GameObjects/Components/Chemistry/ReagentDispenser/ReagentDispenserInventoryPrototype.cs +++ b/Content.Shared/GameObjects/Components/Chemistry/ReagentDispenser/ReagentDispenserInventoryPrototype.cs @@ -3,7 +3,8 @@ using System; using System.Collections.Generic; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; namespace Content.Shared.GameObjects.Components.Chemistry.ReagentDispenser { @@ -16,18 +17,17 @@ namespace Content.Shared.GameObjects.Components.Chemistry.ReagentDispenser [Serializable, NetSerializable, Prototype("reagentDispenserInventory")] public class ReagentDispenserInventoryPrototype : IPrototype { - private string _id = string.Empty; + [DataField("inventory")] private List _inventory = new(); - public string ID => _id; + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; + + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } + public List Inventory => _inventory; - - public void LoadFrom(YamlMappingNode mapping) - { - var serializer = YamlObjectSerializer.NewReader(mapping); - - serializer.DataField(ref _id, "id", string.Empty); - serializer.DataField(ref _inventory, "inventory", new List()); - } } } diff --git a/Content.Shared/GameObjects/Components/Chemistry/SharedSolutionContainerComponent.cs b/Content.Shared/GameObjects/Components/Chemistry/SharedSolutionContainerComponent.cs index 6bd6a1315a..160bc95eb4 100644 --- a/Content.Shared/GameObjects/Components/Chemistry/SharedSolutionContainerComponent.cs +++ b/Content.Shared/GameObjects/Components/Chemistry/SharedSolutionContainerComponent.cs @@ -11,6 +11,7 @@ using Robust.Shared.Maths; using Robust.Shared.Players; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -27,12 +28,14 @@ namespace Content.Shared.GameObjects.Components.Chemistry public sealed override uint? NetID => ContentNetIDs.SOLUTION; [ViewVariables] + [DataField("contents")] public Solution Solution { get; private set; } = new(); public IReadOnlyList ReagentList => Solution.Contents; [ViewVariables(VVAccess.ReadWrite)] - public ReagentUnit MaxVolume { get; set; } + [DataField("maxVol")] + public ReagentUnit MaxVolume { get; set; } = ReagentUnit.Zero; [ViewVariables] public ReagentUnit CurrentVolume => Solution.TotalVolume; @@ -50,9 +53,11 @@ namespace Content.Shared.GameObjects.Components.Chemistry /// If reactions will be checked for when adding reagents to the container. /// [ViewVariables(VVAccess.ReadWrite)] - public bool CanReact { get; set; } + [DataField("canReact")] + public bool CanReact { get; set; } = true; [ViewVariables(VVAccess.ReadWrite)] + [DataField("caps")] public SolutionContainerCaps Capabilities { get; set; } public bool CanExamineContents => Capabilities.HasCap(SolutionContainerCaps.CanExamine); @@ -65,17 +70,6 @@ namespace Content.Shared.GameObjects.Components.Chemistry public bool CanRefill => Capabilities.HasCap(SolutionContainerCaps.Refillable); public bool CanDrain => Capabilities.HasCap(SolutionContainerCaps.Drainable); - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, x => x.CanReact, "canReact", true); - serializer.DataField(this, x => x.MaxVolume, "maxVol", ReagentUnit.New(0)); - serializer.DataField(this, x => x.Solution, "contents", new Solution()); - serializer.DataField(this, x => x.Capabilities, "caps", SolutionContainerCaps.None); - serializer.DataField(this, x => x.MaxSpillRefill, "maxSpillRefill", MaxVolume / ReagentUnit.New(4)); - } - public void RemoveAllSolution() { if (CurrentVolume == 0) @@ -215,6 +209,8 @@ namespace Content.Shared.GameObjects.Components.Chemistry ReagentUnit ISolutionInteractionsComponent.InjectSpaceAvailable => EmptyVolume; ReagentUnit ISolutionInteractionsComponent.DrawAvailable => CurrentVolume; ReagentUnit ISolutionInteractionsComponent.DrainAvailable => CurrentVolume; + + [DataField("maxSpillRefill")] public ReagentUnit MaxSpillRefill { get; set; } void ISolutionInteractionsComponent.Refill(Solution solution) diff --git a/Content.Shared/GameObjects/Components/Damage/DamageableComponent.cs b/Content.Shared/GameObjects/Components/Damage/DamageableComponent.cs index acec7f81c4..c254389f94 100644 --- a/Content.Shared/GameObjects/Components/Damage/DamageableComponent.cs +++ b/Content.Shared/GameObjects/Components/Damage/DamageableComponent.cs @@ -12,6 +12,7 @@ using Robust.Shared.IoC; using Robust.Shared.Players; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Shared.GameObjects.Components.Damage @@ -22,27 +23,31 @@ namespace Content.Shared.GameObjects.Components.Damage /// [RegisterComponent] [ComponentReference(typeof(IDamageableComponent))] - public class DamageableComponent : Component, IDamageableComponent, IRadiationAct + public class DamageableComponent : Component, IDamageableComponent, IRadiationAct, ISerializationHooks { - [Dependency] private readonly IPrototypeManager _prototypeManager = default!; - - // TODO define these in yaml? - public const string DefaultDamageContainer = "metallicDamageContainer"; - public const string DefaultResistanceSet = "defaultResistances"; - public override string Name => "Damageable"; public override uint? NetID => ContentNetIDs.DAMAGEABLE; + // TODO define these in yaml? + public const string DefaultResistanceSet = "defaultResistances"; + public const string DefaultDamageContainer = "metallicDamageContainer"; + private readonly Dictionary _damageList = DamageTypeExtensions.ToNewDictionary(); + private readonly HashSet _supportedTypes = new(); + private readonly HashSet _supportedClasses = new(); + + [DataField("flags")] private DamageFlag _flags; - // TODO DAMAGE Use as default values, specify overrides in a separate property through yaml for better (de)serialization - [ViewVariables] public string DamageContainerId { get; set; } = default!; + [DataField("resistances")] public string ResistanceSetId = DefaultResistanceSet; - [ViewVariables] private ResistanceSet Resistances { get; set; } = default!; + // TODO DAMAGE Use as default values, specify overrides in a separate property through yaml for better (de)serialization + [ViewVariables] [DataField("damageContainer")] public string DamageContainerId { get; set; } = DefaultDamageContainer; + + [ViewVariables] private ResistanceSet Resistances { get; set; } = new(); // TODO DAMAGE Cache this [ViewVariables] public int TotalDamage => _damageList.Values.Sum(); @@ -93,70 +98,24 @@ namespace Content.Shared.GameObjects.Components.Damage return _supportedTypes.Contains(type); } - public override void ExposeData(ObjectSerializer serializer) + public override void Initialize() { - base.ExposeData(serializer); + base.Initialize(); - serializer.DataReadWriteFunction( - "flags", - new List(), - flags => - { - var result = DamageFlag.None; - - foreach (var flag in flags) - { - result |= flag; - } - - Flags = result; - }, - () => - { - var writeFlags = new List(); - - if (Flags == DamageFlag.None) - { - return writeFlags; - } - - foreach (var flag in (DamageFlag[]) Enum.GetValues(typeof(DamageFlag))) - { - if ((Flags & flag) == flag) - { - writeFlags.Add(flag); - } - } - - return writeFlags; - }); + var prototypeManager = IoCManager.Resolve(); // TODO DAMAGE Serialize damage done and resistance changes - serializer.DataReadWriteFunction( - "damageContainer", - DefaultDamageContainer, - prototype => - { - var damagePrototype = _prototypeManager.Index(prototype); + var damagePrototype = prototypeManager.Index(DamageContainerId); - _supportedClasses.Clear(); - _supportedTypes.Clear(); + _supportedClasses.Clear(); + _supportedTypes.Clear(); - DamageContainerId = damagePrototype.ID; - _supportedClasses.UnionWith(damagePrototype.SupportedClasses); - _supportedTypes.UnionWith(damagePrototype.SupportedTypes); - }, - () => DamageContainerId); + DamageContainerId = damagePrototype.ID; + _supportedClasses.UnionWith(damagePrototype.SupportedClasses); + _supportedTypes.UnionWith(damagePrototype.SupportedTypes); - serializer.DataReadWriteFunction( - "resistances", - DefaultResistanceSet, - prototype => - { - var resistancePrototype = _prototypeManager.Index(prototype); - Resistances = new ResistanceSet(resistancePrototype); - }, - () => Resistances.ID); + var resistancePrototype = prototypeManager.Index(ResistanceSetId); + Resistances = new ResistanceSet(resistancePrototype); } protected override void Startup() diff --git a/Content.Shared/GameObjects/Components/Doors/SharedDoorComponent.cs b/Content.Shared/GameObjects/Components/Doors/SharedDoorComponent.cs index bdfc58a0d3..00730eae8c 100644 --- a/Content.Shared/GameObjects/Components/Doors/SharedDoorComponent.cs +++ b/Content.Shared/GameObjects/Components/Doors/SharedDoorComponent.cs @@ -1,12 +1,13 @@ #nullable enable using System; +using System.Collections.Generic; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using Robust.Shared.Serialization; -using Robust.Shared.ViewVariables; using Robust.Shared.Physics; -using System.Collections.Generic; +using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Timing; +using Robust.Shared.ViewVariables; namespace Content.Shared.GameObjects.Components.Doors { @@ -52,19 +53,27 @@ namespace Content.Shared.GameObjects.Components.Doors /// /// Closing time until impassable. /// - protected TimeSpan CloseTimeOne; + [DataField("closeTimeOne")] + protected TimeSpan CloseTimeOne = TimeSpan.FromSeconds(0.4f); + /// /// Closing time until fully closed. /// - protected TimeSpan CloseTimeTwo; + [DataField("closeTimeTwo")] + protected TimeSpan CloseTimeTwo = TimeSpan.FromSeconds(0.2f); + /// /// Opening time until passable. /// - protected TimeSpan OpenTimeOne; + [DataField("openTimeOne")] + protected TimeSpan OpenTimeOne = TimeSpan.FromSeconds(0.4f); + /// /// Opening time until fully open. /// - protected TimeSpan OpenTimeTwo; + [DataField("openTimeTwo")] + protected TimeSpan OpenTimeTwo = TimeSpan.FromSeconds(0.2f); + /// /// Time to finish denying. /// @@ -85,42 +94,9 @@ namespace Content.Shared.GameObjects.Components.Doors /// protected List CurrentlyCrushing = new(); - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - - serializer.DataReadWriteFunction( - "closeTimeOne", - 0.4f, - seconds => CloseTimeOne = TimeSpan.FromSeconds(seconds), - () => CloseTimeOne.TotalSeconds); - - serializer.DataReadWriteFunction( - "closeTimeTwo", - 0.2f, - seconds => CloseTimeTwo = TimeSpan.FromSeconds(seconds), - () => CloseTimeTwo.TotalSeconds); - - serializer.DataReadWriteFunction( - "openTimeOne", - 0.4f, - seconds => OpenTimeOne = TimeSpan.FromSeconds(seconds), - () => OpenTimeOne.TotalSeconds); - - serializer.DataReadWriteFunction( - "openTimeTwo", - 0.2f, - seconds => OpenTimeTwo = TimeSpan.FromSeconds(seconds), - () => OpenTimeTwo.TotalSeconds); - } - protected void SetAppearance(DoorVisualState state) { - if (AppearanceComponent != null) - { - AppearanceComponent.SetData(DoorVisuals.VisualState, state); - } + AppearanceComponent?.SetData(DoorVisuals.VisualState, state); } // stops us colliding with people we're crushing, to prevent hitbox clipping and jank diff --git a/Content.Shared/GameObjects/Components/Inventory/SharedInventoryComponent.cs b/Content.Shared/GameObjects/Components/Inventory/SharedInventoryComponent.cs index a3fcf59b00..9f1f27d911 100644 --- a/Content.Shared/GameObjects/Components/Inventory/SharedInventoryComponent.cs +++ b/Content.Shared/GameObjects/Components/Inventory/SharedInventoryComponent.cs @@ -4,7 +4,9 @@ using Content.Shared.GameObjects.Components.Movement; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Reflection; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines; @@ -25,15 +27,9 @@ namespace Content.Shared.GameObjects.Components.Inventory protected Inventory InventoryInstance { get; private set; } [ViewVariables] + [DataField("Template")] private string _templateName = "HumanInventory"; //stored for serialization purposes - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _templateName, "Template", "HumanInventory"); - } - public override void Initialize() { base.Initialize(); diff --git a/Content.Shared/GameObjects/Components/Materials/MaterialComponent.cs b/Content.Shared/GameObjects/Components/Materials/MaterialComponent.cs index f1a26b9b09..e6dda66c49 100644 --- a/Content.Shared/GameObjects/Components/Materials/MaterialComponent.cs +++ b/Content.Shared/GameObjects/Components/Materials/MaterialComponent.cs @@ -5,7 +5,7 @@ using Robust.Shared.IoC; using Robust.Shared.Prototypes; using Robust.Shared.Reflection; using Robust.Shared.Serialization; -using Robust.Shared.Utility; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.GameObjects.Components.Materials { @@ -14,66 +14,51 @@ namespace Content.Shared.GameObjects.Components.Materials /// This is not a storage system for say smelteries. /// [RegisterComponent] - public class MaterialComponent : Component + public class MaterialComponent : Component, ISerializationHooks { + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + public const string SerializationCache = "mat"; + public override string Name => "Material"; - public Dictionary MaterialTypes => _materialTypes; - private Dictionary _materialTypes; + [DataField("materials")] private List _materials = new(); - public override void ExposeData(ObjectSerializer serializer) + public IEnumerable> MaterialTypes { - base.ExposeData(serializer); - - // TODO: Writing. - if (serializer.Writing) + get { - return; - } - - if (serializer.TryGetCacheData(SerializationCache, out Dictionary cached)) - { - _materialTypes = cached.ShallowClone(); - return; - } - - _materialTypes = new Dictionary(); - - if (serializer.TryReadDataField("materials", out List list)) - { - var protoMan = IoCManager.Resolve(); - foreach (var entry in list) + foreach (var entry in _materials) { - var proto = protoMan.Index(entry.Value); - _materialTypes[entry.Key] = proto.Material; + var prototype = _prototypeManager.Index(entry.Value); + + yield return new KeyValuePair(entry.Key, prototype); } } - - serializer.SetCacheData(SerializationCache, _materialTypes.ShallowClone()); } - class MaterialDataEntry : IExposeData + [DataDefinition] + public class MaterialDataEntry : ISerializationHooks { public object Key; + + [DataField("key")] + public string StringKey; + + [DataField("mat")] public string Value; - void IExposeData.ExposeData(ObjectSerializer serializer) + void ISerializationHooks.AfterDeserialization() { - if (serializer.Writing) - { - return; - } - var refl = IoCManager.Resolve(); - Value = serializer.ReadDataField("mat"); - var key = serializer.ReadDataField("key"); - if (refl.TryParseEnumReference(key, out var @enum)) + + if (refl.TryParseEnumReference(StringKey, out var @enum)) { Key = @enum; return; } - Key = key; + + Key = StringKey; } } } diff --git a/Content.Shared/GameObjects/Components/Medical/SharedCloningPodComponent.cs b/Content.Shared/GameObjects/Components/Medical/SharedCloningPodComponent.cs index db621e951b..f3efe7ec2d 100644 --- a/Content.Shared/GameObjects/Components/Medical/SharedCloningPodComponent.cs +++ b/Content.Shared/GameObjects/Components/Medical/SharedCloningPodComponent.cs @@ -6,7 +6,6 @@ using Robust.Shared.Serialization; namespace Content.Shared.GameObjects.Components.Medical { - public class SharedCloningPodComponent : Component { public override string Name => "CloningPod"; diff --git a/Content.Shared/GameObjects/Components/Mobs/ExaminerComponent.cs b/Content.Shared/GameObjects/Components/Mobs/ExaminerComponent.cs index 06afffaa54..d2943f6aef 100644 --- a/Content.Shared/GameObjects/Components/Mobs/ExaminerComponent.cs +++ b/Content.Shared/GameObjects/Components/Mobs/ExaminerComponent.cs @@ -1,6 +1,8 @@ #nullable enable using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Shared.GameObjects.Components.Mobs @@ -14,6 +16,7 @@ namespace Content.Shared.GameObjects.Components.Mobs public override string Name => "Examiner"; [ViewVariables(VVAccess.ReadWrite)] + [DataField("DoRangeCheck")] private bool _doRangeCheck = true; /// @@ -21,12 +24,5 @@ namespace Content.Shared.GameObjects.Components.Mobs /// If false, the user can theoretically examine from infinitely far away. /// public bool DoRangeCheck => _doRangeCheck; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _doRangeCheck, "DoRangeCheck", true); - } } } diff --git a/Content.Shared/GameObjects/Components/Mobs/ItemActionsComponent.cs b/Content.Shared/GameObjects/Components/Mobs/ItemActionsComponent.cs index 4e46912404..c67e312593 100644 --- a/Content.Shared/GameObjects/Components/Mobs/ItemActionsComponent.cs +++ b/Content.Shared/GameObjects/Components/Mobs/ItemActionsComponent.cs @@ -8,6 +8,7 @@ using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; using Robust.Shared.Log; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.GameObjects.Components.Mobs { @@ -50,23 +51,25 @@ namespace Content.Shared.GameObjects.Components.Mobs public IEntity? Holder { get; private set; } // cached actions component of the holder, since we'll need to access it frequently private SharedActionsComponent? _holderActionsComponent; - private List _actionConfigs = new(); - // State of all actions provided by this item. - private readonly Dictionary _actions = new(); - - public override void ExposeData(ObjectSerializer serializer) + [DataField("actions")] + private List _actionConfigs { - base.ExposeData(serializer); - - serializer.DataField(ref _actionConfigs,"actions", new List()); - - foreach (var actionConfig in _actionConfigs) + get => internalActionConfigs; + set { - GrantOrUpdate(actionConfig.ActionType, actionConfig.Enabled, false, null); + internalActionConfigs = value; + foreach (var actionConfig in value) + { + GrantOrUpdate(actionConfig.ActionType, actionConfig.Enabled, false, null); + } } } + // State of all actions provided by this item. + private readonly Dictionary _actions = new(); + private List internalActionConfigs = new (); + protected override void Startup() { base.Startup(); @@ -226,22 +229,23 @@ namespace Content.Shared.GameObjects.Components.Mobs /// /// Configuration for an item action provided by an item. /// - public class ItemActionConfig : IExposeData + [DataDefinition] + public class ItemActionConfig : ISerializationHooks { - public ItemActionType ActionType { get; private set; } + [DataField("actionType", required: true)] + public ItemActionType ActionType { get; private set; } = ItemActionType.Error; + /// /// Whether action is initially enabled on this item. Defaults to true. /// - public bool Enabled { get; private set; } + public bool Enabled { get; private set; } = true; - void IExposeData.ExposeData(ObjectSerializer serializer) + void ISerializationHooks.AfterDeserialization() { - serializer.DataField(this, x => x.ActionType, "actionType", ItemActionType.Error); if (ActionType == ItemActionType.Error) { Logger.ErrorS("action", "invalid or missing actionType"); } - serializer.DataField(this, x => x.Enabled, "enabled", true); } } } diff --git a/Content.Shared/GameObjects/Components/Mobs/SharedActionsComponent.cs b/Content.Shared/GameObjects/Components/Mobs/SharedActionsComponent.cs index 317bc284cb..ab4153c3ae 100644 --- a/Content.Shared/GameObjects/Components/Mobs/SharedActionsComponent.cs +++ b/Content.Shared/GameObjects/Components/Mobs/SharedActionsComponent.cs @@ -10,6 +10,7 @@ using Robust.Shared.Map; using Robust.Shared.Players; using Robust.Shared.Serialization; using Robust.Shared.Timing; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Shared.GameObjects.Components.Mobs @@ -46,7 +47,8 @@ namespace Content.Shared.GameObjects.Components.Mobs /// of the status of the entity. /// public IEnumerable InnateActions => _innateActions ?? Enumerable.Empty(); - private List? _innateActions; + [DataField("innateActions")] + private List? _innateActions = null; // entries are removed from this if they are at the initial state (not enabled, no cooldown, toggled off). @@ -63,11 +65,6 @@ namespace Content.Shared.GameObjects.Components.Mobs private Dictionary> _itemActions = new(); - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref _innateActions,"innateActions", null); - } protected override void Startup() { foreach (var actionType in InnateActions) diff --git a/Content.Shared/GameObjects/Components/Mobs/SharedStunnableComponent.cs b/Content.Shared/GameObjects/Components/Mobs/SharedStunnableComponent.cs index 5948ff0513..f38259cd0c 100644 --- a/Content.Shared/GameObjects/Components/Mobs/SharedStunnableComponent.cs +++ b/Content.Shared/GameObjects/Components/Mobs/SharedStunnableComponent.cs @@ -7,8 +7,10 @@ using Content.Shared.GameObjects.EntitySystems.ActionBlocker; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; using Robust.Shared.IoC; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; using Robust.Shared.Timing; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Shared.GameObjects.Components.Mobs @@ -31,17 +33,26 @@ namespace Content.Shared.GameObjects.Components.Mobs (TimeSpan.FromSeconds(Math.Max(StunnedTimer, Math.Max(KnockdownTimer, SlowdownTimer)))); private bool _canHelp = true; + + [DataField("stunCap")] protected float _stunCap = 20f; + + [DataField("knockdownCap")] protected float _knockdownCap = 20f; + + [DataField("slowdownCap")] protected float _slowdownCap = 20f; + private float _helpKnockdownRemove = 1f; + + [DataField("helpInterval")] private float _helpInterval = 1f; protected float StunnedTimer; protected float KnockdownTimer; protected float SlowdownTimer; - private string _stunAlertId = string.Empty; + [DataField("stunAlertId")] private string _stunAlertId = "stun"; protected CancellationTokenSource StatusRemoveCancellation = new(); @@ -203,19 +214,6 @@ namespace Content.Shared.GameObjects.Components.Mobs StatusRemoveCancellation = new CancellationTokenSource(); } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(ref _stunCap, "stunCap", 20f); - serializer.DataField(ref _knockdownCap, "knockdownCap", 20f); - serializer.DataField(ref _slowdownCap, "slowdownCap", 20f); - serializer.DataField(ref _helpInterval, "helpInterval", 1f); - serializer.DataField(ref _helpKnockdownRemove, "helpKnockdownRemove", 1f); - serializer.DataField(ref _stunAlertId, "stunAlertId", - "stun"); - } - protected virtual void OnInteractHand() { } bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs) diff --git a/Content.Shared/GameObjects/Components/Mobs/Speech/SharedEmotingComponent.cs b/Content.Shared/GameObjects/Components/Mobs/Speech/SharedEmotingComponent.cs index ec239db413..d5160e11eb 100644 --- a/Content.Shared/GameObjects/Components/Mobs/Speech/SharedEmotingComponent.cs +++ b/Content.Shared/GameObjects/Components/Mobs/Speech/SharedEmotingComponent.cs @@ -1,14 +1,14 @@ #nullable enable using Content.Shared.GameObjects.EntitySystems.ActionBlocker; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.GameObjects.Components.Mobs.Speech { [RegisterComponent] public class SharedEmotingComponent : Component, IActionBlocker { - private bool _enabled = true; + [DataField("enabled")] private bool _enabled = true; public override string Name => "Emoting"; public bool Enabled @@ -23,12 +23,5 @@ namespace Content.Shared.GameObjects.Components.Mobs.Speech } bool IActionBlocker.CanEmote() => Enabled; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, x => x.Enabled, "enabled", true); - } } } diff --git a/Content.Shared/GameObjects/Components/Mobs/Speech/SharedSpeechComponent.cs b/Content.Shared/GameObjects/Components/Mobs/Speech/SharedSpeechComponent.cs index 99e3ad8740..a828d93c4b 100644 --- a/Content.Shared/GameObjects/Components/Mobs/Speech/SharedSpeechComponent.cs +++ b/Content.Shared/GameObjects/Components/Mobs/Speech/SharedSpeechComponent.cs @@ -1,7 +1,7 @@ #nullable enable using Content.Shared.GameObjects.EntitySystems.ActionBlocker; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.GameObjects.Components.Mobs.Speech { @@ -11,9 +11,11 @@ namespace Content.Shared.GameObjects.Components.Mobs.Speech [RegisterComponent] public class SharedSpeechComponent : Component, IActionBlocker { - private bool _enabled = true; public override string Name => "Speech"; + [DataField("enabled")] + private bool _enabled = true; + public bool Enabled { get => _enabled; @@ -26,12 +28,5 @@ namespace Content.Shared.GameObjects.Components.Mobs.Speech } bool IActionBlocker.CanSpeak() => Enabled; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, x => x.Enabled, "enabled", true); - } } } diff --git a/Content.Shared/GameObjects/Components/Mobs/State/BaseMobState.cs b/Content.Shared/GameObjects/Components/Mobs/State/BaseMobState.cs index ee89d95091..c6b9889ea3 100644 --- a/Content.Shared/GameObjects/Components/Mobs/State/BaseMobState.cs +++ b/Content.Shared/GameObjects/Components/Mobs/State/BaseMobState.cs @@ -1,9 +1,10 @@ #nullable enable using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.GameObjects.Components.Mobs.State { + [ImplicitDataDefinitionForInheritors] public abstract class BaseMobState : IMobState { protected abstract DamageState DamageState { get; } @@ -34,8 +35,6 @@ namespace Content.Shared.GameObjects.Components.Mobs.State public virtual void UpdateState(IEntity entity, int threshold) { } - public virtual void ExposeData(ObjectSerializer serializer) { } - public virtual bool CanInteract() { return true; diff --git a/Content.Shared/GameObjects/Components/Mobs/State/IMobState.cs b/Content.Shared/GameObjects/Components/Mobs/State/IMobState.cs index 17c060ad0c..45390c3d8f 100644 --- a/Content.Shared/GameObjects/Components/Mobs/State/IMobState.cs +++ b/Content.Shared/GameObjects/Components/Mobs/State/IMobState.cs @@ -1,7 +1,6 @@ #nullable enable using Content.Shared.GameObjects.EntitySystems.ActionBlocker; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; namespace Content.Shared.GameObjects.Components.Mobs.State { @@ -10,7 +9,7 @@ namespace Content.Shared.GameObjects.Components.Mobs.State /// (i.e. Normal, Critical, Dead) and what effects to apply upon entering or /// exiting the state. /// - public interface IMobState : IExposeData, IActionBlocker + public interface IMobState : IActionBlocker { bool IsAlive(); diff --git a/Content.Shared/GameObjects/Components/Mobs/State/SharedMobStateComponent.cs b/Content.Shared/GameObjects/Components/Mobs/State/SharedMobStateComponent.cs index 7eea9f528f..790d481467 100644 --- a/Content.Shared/GameObjects/Components/Mobs/State/SharedMobStateComponent.cs +++ b/Content.Shared/GameObjects/Components/Mobs/State/SharedMobStateComponent.cs @@ -9,6 +9,7 @@ using Content.Shared.GameObjects.EntitySystems.ActionBlocker; using Robust.Shared.GameObjects; using Robust.Shared.Players; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Shared.GameObjects.Components.Mobs.State @@ -29,12 +30,12 @@ namespace Content.Shared.GameObjects.Components.Mobs.State /// States that this mapped to /// the amount of damage at which they are triggered. /// A threshold is reached when the total damage of an entity is equal - /// A threshold is reached when the total damage of an entity is equal /// to or higher than the int key, but lower than the next threshold. /// Ordered from lowest to highest. /// [ViewVariables] - private SortedDictionary _lowestToHighestStates = default!; + [DataField("thresholds")] + private readonly SortedDictionary _lowestToHighestStates = default!; // TODO Remove Nullability? [ViewVariables] @@ -45,20 +46,6 @@ namespace Content.Shared.GameObjects.Components.Mobs.State public IEnumerable> _highestToLowestStates => _lowestToHighestStates.Reverse(); - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataReadWriteFunction( - "thresholds", - new Dictionary(), - thresholds => - { - _lowestToHighestStates = new SortedDictionary(thresholds); - }, - () => new Dictionary(_lowestToHighestStates)); - } - protected override void Startup() { base.Startup(); diff --git a/Content.Shared/GameObjects/Components/Movement/MovementSpeedModifierComponent.cs b/Content.Shared/GameObjects/Components/Movement/MovementSpeedModifierComponent.cs index dfdb8ba440..f5c3a6d312 100644 --- a/Content.Shared/GameObjects/Components/Movement/MovementSpeedModifierComponent.cs +++ b/Content.Shared/GameObjects/Components/Movement/MovementSpeedModifierComponent.cs @@ -1,7 +1,9 @@ -#nullable enable +#nullable enable using Robust.Shared.Containers; using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Shared.GameObjects.Components.Movement @@ -37,9 +39,12 @@ namespace Content.Shared.GameObjects.Components.Movement } [ViewVariables(VVAccess.ReadWrite)] - public float BaseWalkSpeed { get; set; } + [DataField("baseWalkSpeed")] + public float BaseWalkSpeed { get; set; } = 4; + [ViewVariables(VVAccess.ReadWrite)] - public float BaseSprintSpeed { get; set; } + [DataField("baseSprintSpeed")] + public float BaseSprintSpeed { get; set; } = 7; [ViewVariables] public float CurrentWalkSpeed => WalkSpeedModifier * BaseWalkSpeed; @@ -65,14 +70,6 @@ namespace Content.Shared.GameObjects.Components.Movement } } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, p => p.BaseWalkSpeed, "baseWalkSpeed", 4); - serializer.DataField(this, p => p.BaseSprintSpeed, "baseSprintSpeed", 7); - } - /// /// Recalculate movement speed with current modifiers, or return early if no change /// diff --git a/Content.Shared/GameObjects/Components/Movement/SharedClimbableComponent.cs b/Content.Shared/GameObjects/Components/Movement/SharedClimbableComponent.cs index 09071f5b04..722dd8136e 100644 --- a/Content.Shared/GameObjects/Components/Movement/SharedClimbableComponent.cs +++ b/Content.Shared/GameObjects/Components/Movement/SharedClimbableComponent.cs @@ -2,12 +2,12 @@ using Content.Shared.GameObjects.EntitySystems; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Shared.GameObjects.Components.Movement { - public interface IClimbable { }; + public interface IClimbable { } public abstract class SharedClimbableComponent : Component, IClimbable, IDragDropOn { @@ -16,14 +16,7 @@ namespace Content.Shared.GameObjects.Components.Movement /// /// The range from which this entity can be climbed. /// - [ViewVariables] - protected float Range; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref Range, "range", SharedInteractionSystem.InteractionRange / 1.4f); - } + [ViewVariables] [DataField("range")] protected float Range = SharedInteractionSystem.InteractionRange / 1.4f; public virtual bool CanDragDropOn(DragDropEventArgs eventArgs) { diff --git a/Content.Shared/GameObjects/Components/Movement/SharedSlipperyComponent.cs b/Content.Shared/GameObjects/Components/Movement/SharedSlipperyComponent.cs index d8faed5fa3..97b34d7c48 100644 --- a/Content.Shared/GameObjects/Components/Movement/SharedSlipperyComponent.cs +++ b/Content.Shared/GameObjects/Components/Movement/SharedSlipperyComponent.cs @@ -8,13 +8,13 @@ using Content.Shared.Physics; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Shared.GameObjects.Components.Movement { public abstract class SharedSlipperyComponent : Component, ICollideBehavior { - public sealed override string Name => "Slippery"; /// @@ -27,31 +27,36 @@ namespace Content.Shared.GameObjects.Components.Movement /// How many seconds the mob will be paralyzed for. /// [ViewVariables(VVAccess.ReadWrite)] - public virtual float ParalyzeTime { get; set; } = 2f; + [DataField("paralyzeTime")] + public virtual float ParalyzeTime { get; set; } = 3f; /// /// Percentage of shape intersection for a slip to occur. /// [ViewVariables(VVAccess.ReadWrite)] + [DataField("intersectPercentage")] public virtual float IntersectPercentage { get; set; } = 0.3f; /// /// Entities will only be slipped if their speed exceeds this limit. /// [ViewVariables(VVAccess.ReadWrite)] - public virtual float RequiredSlipSpeed { get; set; } = 0f; + [DataField("requiredSlipSpeed")] + public virtual float RequiredSlipSpeed { get; set; } = 0.1f; /// /// The entity's speed will be multiplied by this to slip it forwards. /// [ViewVariables(VVAccess.ReadWrite)] + [DataField("launchForwardsMultiplier")] public virtual float LaunchForwardsMultiplier { get; set; } = 1f; /// /// Whether or not this component will try to slip entities. /// [ViewVariables(VVAccess.ReadWrite)] - public virtual bool Slippery { get; set; } + [DataField("slippery")] + public virtual bool Slippery { get; set; } = true; private bool TrySlip(IEntity entity) { @@ -140,17 +145,6 @@ namespace Content.Shared.GameObjects.Components.Movement shape.CollisionMask = (int) CollisionGroup.None; } } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, x => x.ParalyzeTime, "paralyzeTime", 3f); - serializer.DataField(this, x => x.IntersectPercentage, "intersectPercentage", 0.3f); - serializer.DataField(this, x => x.RequiredSlipSpeed, "requiredSlipSpeed", 0.1f); - serializer.DataField(this, x => x.LaunchForwardsMultiplier, "launchForwardsMultiplier", 1f); - serializer.DataField(this, x => x.Slippery, "slippery", true); - } } [Serializable, NetSerializable] diff --git a/Content.Shared/GameObjects/Components/Research/SharedLatheDatabaseComponent.cs b/Content.Shared/GameObjects/Components/Research/SharedLatheDatabaseComponent.cs index 659df1669b..eb15371cae 100644 --- a/Content.Shared/GameObjects/Components/Research/SharedLatheDatabaseComponent.cs +++ b/Content.Shared/GameObjects/Components/Research/SharedLatheDatabaseComponent.cs @@ -7,16 +7,44 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.GameObjects.Components.Research { - public class SharedLatheDatabaseComponent : Component, IEnumerable + public class SharedLatheDatabaseComponent : Component, IEnumerable, ISerializationHooks { public override string Name => "LatheDatabase"; public override uint? NetID => ContentNetIDs.LATHE_DATABASE; + [DataField("recipes")] private List _recipeIds = new(); + private readonly List _recipes = new(); + void ISerializationHooks.BeforeSerialization() + { + var list = new List(); + + foreach (var recipe in _recipes) + { + list.Add(recipe.ID); + } + + _recipeIds = list; + } + + void ISerializationHooks.AfterDeserialization() + { + var prototypeManager = IoCManager.Resolve(); + + foreach (var id in _recipeIds) + { + if (prototypeManager.TryIndex(id, out LatheRecipePrototype? recipe)) + { + _recipes.Add(recipe); + } + } + } + /// /// Removes all recipes from the database if it's not static. /// @@ -33,7 +61,7 @@ namespace Content.Shared.GameObjects.Components.Research /// Whether it could be added or not public virtual void AddRecipe(LatheRecipePrototype recipe) { - if(!Contains(recipe)) + if (!Contains(recipe)) _recipes.Add(recipe); } @@ -71,29 +99,6 @@ namespace Content.Shared.GameObjects.Components.Research return false; } - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataReadWriteFunction( - "recipes", - new List(), - recipes => - { - var prototypeManager = IoCManager.Resolve(); - - foreach (var id in recipes) - { - if (prototypeManager.TryIndex(id, out LatheRecipePrototype? recipe)) - { - _recipes.Add(recipe); - } - } - }, - GetRecipeIdList); - - } - public List GetRecipeIdList() { var list = new List(); diff --git a/Content.Shared/GameObjects/Components/Research/SharedMaterialStorageComponent.cs b/Content.Shared/GameObjects/Components/Research/SharedMaterialStorageComponent.cs index 7f92f2e414..cd984485a0 100644 --- a/Content.Shared/GameObjects/Components/Research/SharedMaterialStorageComponent.cs +++ b/Content.Shared/GameObjects/Components/Research/SharedMaterialStorageComponent.cs @@ -2,6 +2,7 @@ using System; using System.Collections; using System.Collections.Generic; +using Content.Shared.Materials; using Robust.Shared.GameObjects; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; @@ -10,11 +11,12 @@ namespace Content.Shared.GameObjects.Components.Research { public class SharedMaterialStorageComponent : Component, IEnumerable> { - [ViewVariables] - protected virtual Dictionary Storage { get; set; } = new(); public override string Name => "MaterialStorage"; public sealed override uint? NetID => ContentNetIDs.MATERIAL_STORAGE; + [ViewVariables] + protected virtual Dictionary Storage { get; set; } = new(); + public int this[string ID] { get @@ -25,6 +27,17 @@ namespace Content.Shared.GameObjects.Components.Research } } + public int this[MaterialPrototype material] + { + get + { + var ID = material.ID; + if (!Storage.ContainsKey(ID)) + return 0; + return Storage[ID]; + } + } + /// /// The total volume of material stored currently. /// diff --git a/Content.Shared/GameObjects/Components/Research/SharedProtolatheDatabaseComponent.cs b/Content.Shared/GameObjects/Components/Research/SharedProtolatheDatabaseComponent.cs index 221f9416ac..80abf5c2fe 100644 --- a/Content.Shared/GameObjects/Components/Research/SharedProtolatheDatabaseComponent.cs +++ b/Content.Shared/GameObjects/Components/Research/SharedProtolatheDatabaseComponent.cs @@ -6,59 +6,33 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.GameObjects.Components.Research { - [ComponentReference(typeof(SharedLatheDatabaseComponent))] - public class SharedProtolatheDatabaseComponent : SharedLatheDatabaseComponent + public class SharedProtolatheDatabaseComponent : SharedLatheDatabaseComponent, ISerializationHooks { + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + public override string Name => "ProtolatheDatabase"; + public sealed override uint? NetID => ContentNetIDs.PROTOLATHE_DATABASE; - private readonly List _protolatheRecipes = new(); + [DataField("protolatherecipes")] private List _recipeIds = new(); /// /// A full list of recipes this protolathe can print. /// - public List ProtolatheRecipes => _protolatheRecipes; - - public override void ExposeData(ObjectSerializer serializer) + public IEnumerable ProtolatheRecipes { - base.ExposeData(serializer); - - serializer.DataReadWriteFunction( - "protolatherecipes", - new List(), - recipes => - { - var prototypeManager = IoCManager.Resolve(); - - foreach (var id in recipes) - { - if (prototypeManager.TryIndex(id, out LatheRecipePrototype? recipe)) - { - _protolatheRecipes.Add(recipe); - } - } - }, - GetProtolatheRecipeIdList); - } - - /// - /// Returns a list of the allowed protolathe recipe IDs. - /// - /// A list of recipe IDs allowed - public List GetProtolatheRecipeIdList() - { - var list = new List(); - - foreach (var recipe in ProtolatheRecipes) + get { - list.Add(recipe.ID); + foreach (var id in _recipeIds) + { + yield return _prototypeManager.Index(id); + } } - - return list; } } diff --git a/Content.Shared/GameObjects/Components/Research/SharedTechnologyDatabaseComponent.cs b/Content.Shared/GameObjects/Components/Research/SharedTechnologyDatabaseComponent.cs index 24a77c3330..e1705d4e77 100644 --- a/Content.Shared/GameObjects/Components/Research/SharedTechnologyDatabaseComponent.cs +++ b/Content.Shared/GameObjects/Components/Research/SharedTechnologyDatabaseComponent.cs @@ -7,14 +7,17 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.GameObjects.Components.Research { - public class SharedTechnologyDatabaseComponent : Component, IEnumerable + public class SharedTechnologyDatabaseComponent : Component, IEnumerable, ISerializationHooks { public override string Name => "TechnologyDatabase"; public override uint? NetID => ContentNetIDs.TECHNOLOGY_DATABASE; + [DataField("technologies")] private List _technologyIds = new(); + protected List _technologies = new(); /// @@ -22,6 +25,31 @@ namespace Content.Shared.GameObjects.Components.Research /// public IReadOnlyList Technologies => _technologies; + void ISerializationHooks.BeforeSerialization() + { + var techIds = new List(); + + foreach (var tech in _technologies) + { + techIds.Add(tech.ID); + } + + _technologyIds = techIds; + } + + void ISerializationHooks.AfterDeserialization() + { + var prototypeManager = IoCManager.Resolve(); + + foreach (var id in _technologyIds) + { + if (prototypeManager.TryIndex(id, out TechnologyPrototype? tech)) + { + _technologies.Add(tech); + } + } + } + public IEnumerator GetEnumerator() { return Technologies.GetEnumerator(); @@ -79,27 +107,6 @@ namespace Content.Shared.GameObjects.Components.Research } return true; } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataReadWriteFunction( - "technologies", - new List(), - techs => - { - var prototypeManager = IoCManager.Resolve(); - - foreach (var id in techs) - { - if (prototypeManager.TryIndex(id, out TechnologyPrototype? tech)) - { - _technologies.Add(tech); - } - } - }, GetTechnologyIdList); - } } [Serializable, NetSerializable] diff --git a/Content.Shared/GameObjects/Components/SharedCrayonComponent.cs b/Content.Shared/GameObjects/Components/SharedCrayonComponent.cs index 593181efb7..44e4ce12d0 100644 --- a/Content.Shared/GameObjects/Components/SharedCrayonComponent.cs +++ b/Content.Shared/GameObjects/Components/SharedCrayonComponent.cs @@ -1,11 +1,12 @@ -#nullable enable +#nullable enable +using System; +using System.Collections.Generic; using Robust.Shared.GameObjects; using Robust.Shared.Maths; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; -using System; -using System.Collections.Generic; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; namespace Content.Shared.GameObjects.Components { @@ -15,6 +16,8 @@ namespace Content.Shared.GameObjects.Components public override uint? NetID => ContentNetIDs.CRAYONS; public string SelectedState { get; set; } = string.Empty; + + [DataField("color")] protected string _color = "white"; [Serializable, NetSerializable] @@ -74,21 +77,16 @@ namespace Content.Shared.GameObjects.Components [Serializable, NetSerializable, Prototype("crayonDecal")] public class CrayonDecalPrototype : IPrototype { - public string ID { get; private set; } = string.Empty; + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; - private string _spritePath = string.Empty; - public string SpritePath => _spritePath; + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } - private List _decals = new(); - public List Decals => _decals; + [field: DataField("spritePath")] public string SpritePath { get; } = string.Empty; - public void LoadFrom(YamlMappingNode mapping) - { - var serializer = YamlObjectSerializer.NewReader(mapping); - - serializer.DataField(this, x => x.ID, "id", string.Empty); - serializer.DataField(ref _spritePath, "spritePath", string.Empty); - serializer.DataField(ref _decals, "decals", new List()); - } + [field: DataField("decals")] public List Decals { get; } = new(); } } diff --git a/Content.Shared/GameObjects/Components/SharedExpendableLightComponent.cs b/Content.Shared/GameObjects/Components/SharedExpendableLightComponent.cs index 99d07aa7f7..dd558ed0cf 100644 --- a/Content.Shared/GameObjects/Components/SharedExpendableLightComponent.cs +++ b/Content.Shared/GameObjects/Components/SharedExpendableLightComponent.cs @@ -2,6 +2,7 @@ using System; using Robust.Shared.GameObjects; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Shared.GameObjects.Components @@ -29,53 +30,47 @@ namespace Content.Shared.GameObjects.Components protected ExpendableLightState CurrentState { get; set; } [ViewVariables] + [DataField("turnOnBehaviourID")] protected string TurnOnBehaviourID { get; set; } = string.Empty; [ViewVariables] + [DataField("fadeOutBehaviourID")] protected string FadeOutBehaviourID { get; set; } = string.Empty; [ViewVariables] - protected float GlowDuration { get; set; } + [DataField("glowDuration")] + protected float GlowDuration { get; set; } = 60 * 15f; [ViewVariables] - protected float FadeOutDuration { get; set; } + [DataField("fadeOutDuration")] + protected float FadeOutDuration { get; set; } = 60 * 5f; [ViewVariables] + [DataField("spentDesc")] protected string SpentDesc { get; set; } = string.Empty; [ViewVariables] + [DataField("spentName")] protected string SpentName { get; set; } = string.Empty; [ViewVariables] + [DataField("iconStateSpent")] protected string IconStateSpent { get; set; } = string.Empty; [ViewVariables] + [DataField("iconStateOn")] protected string IconStateLit { get; set; } = string.Empty; [ViewVariables] + [DataField("litSound")] protected string LitSound { get; set; } = string.Empty; [ViewVariables] + [DataField("loopedSound")] protected string LoopedSound { get; set; } = string.Empty; [ViewVariables] + [DataField("dieSound")] protected string DieSound { get; set; } = string.Empty; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, x => x.TurnOnBehaviourID, "turnOnBehaviourID", string.Empty); - serializer.DataField(this, x => x.FadeOutBehaviourID, "fadeOutBehaviourID", string.Empty); - serializer.DataField(this, x => x.GlowDuration, "glowDuration", 60 * 15f); - serializer.DataField(this, x => x.FadeOutDuration, "fadeOutDuration", 60 * 5f); - serializer.DataField(this, x => x.SpentName, "spentName", string.Empty); - serializer.DataField(this, x => x.SpentDesc, "spentDesc", string.Empty); - serializer.DataField(this, x => x.IconStateLit, "iconStateOn", string.Empty); - serializer.DataField(this, x => x.IconStateSpent, "iconStateSpent", string.Empty); - serializer.DataField(this, x => x.LitSound, "litSound", string.Empty); - serializer.DataField(this, x => x.LoopedSound, "loopedSound", string.Empty); - serializer.DataField(this, x => x.DieSound, "dieSound", string.Empty); - } } } diff --git a/Content.Shared/GameObjects/Components/SharedStackComponent.cs b/Content.Shared/GameObjects/Components/SharedStackComponent.cs index 6d73b68403..9671765e9d 100644 --- a/Content.Shared/GameObjects/Components/SharedStackComponent.cs +++ b/Content.Shared/GameObjects/Components/SharedStackComponent.cs @@ -6,11 +6,12 @@ using Robust.Shared.Log; using Robust.Shared.Players; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Shared.GameObjects.Components { - public abstract class SharedStackComponent : Component + public abstract class SharedStackComponent : Component, ISerializationHooks { [Dependency] private readonly IPrototypeManager _prototypeManager = default!; @@ -19,8 +20,11 @@ namespace Content.Shared.GameObjects.Components public sealed override string Name => "Stack"; public sealed override uint? NetID => ContentNetIDs.STACK; - private int _count; - private int _maxCount; + [DataField("count")] + private int _count = 30; + + [DataField("max")] + private int _maxCount = 30; [ViewVariables(VVAccess.ReadWrite)] public virtual int Count @@ -51,35 +55,12 @@ namespace Content.Shared.GameObjects.Components [ViewVariables] public int AvailableSpace => MaxCount - Count; - [ViewVariables] public string StackTypeId { get; private set; } = string.Empty; + [ViewVariables] + [field: DataField("stackType")] + public string StackTypeId { get; } = string.Empty; public StackPrototype StackType => _prototypeManager.Index(StackTypeId); - public override void ExposeData(ObjectSerializer serializer) - { - serializer.DataFieldCached(ref _maxCount, "max", 30); - serializer.DataFieldCached(ref _count, "count", MaxCount); - - if (serializer.Writing) - { - return; - } - - if (serializer.TryGetCacheData(SerializationCache, out string stackType)) - { - StackTypeId = stackType; - return; - } - - serializer.DataFieldCached(ref stackType, "stackType", string.Empty); - - if (!string.IsNullOrEmpty(stackType)) - { - serializer.SetCacheData(SerializationCache, stackType); - StackTypeId = stackType; - } - } - protected override void Startup() { base.Startup(); diff --git a/Content.Shared/GameObjects/Components/Sound/SharedLoopingSoundComponent.cs b/Content.Shared/GameObjects/Components/Sound/SharedLoopingSoundComponent.cs index bdf5247517..d18a2be12e 100644 --- a/Content.Shared/GameObjects/Components/Sound/SharedLoopingSoundComponent.cs +++ b/Content.Shared/GameObjects/Components/Sound/SharedLoopingSoundComponent.cs @@ -3,6 +3,7 @@ using System; using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.GameObjects.Components.Sound { @@ -73,49 +74,43 @@ namespace Content.Shared.GameObjects.Components.Sound } [Serializable, NetSerializable] - public class ScheduledSound : IExposeData + [DataDefinition] + public class ScheduledSound { - public string Filename = ""; + [DataField("fileName")] + public string Filename = string.Empty; /// /// The parameters to play the sound with. /// + [DataField("audioparams")] public AudioParams? AudioParams; /// /// Delay in milliseconds before playing the sound, /// and delay between repetitions if Times is not 0. /// - public uint Delay = 0; + [DataField("delay")] + public uint Delay; /// /// Maximum number of milliseconds to add to the delay randomly. /// Useful for random ambience noises. Generated value differs from client to client. /// - public uint RandomDelay = 0; + [DataField("randomdelay")] + public uint RandomDelay; /// /// How many times to repeat the sound. If it's 0, it will play the sound once. /// If it's less than 0, it will repeat the sound indefinitely. /// If it's greater than 0, it will play the sound n+1 times. /// - public int Times = 0; + [DataField("times")] + public int Times; /// /// Whether the sound will play or not. /// public bool Play = true; - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - if (serializer.Writing) - return; - - Filename = serializer.ReadDataField("filename", ""); - Delay = serializer.ReadDataField("delay", 0u); - RandomDelay = serializer.ReadDataField("randomdelay", 0u); - Times = serializer.ReadDataField("times", 0); - AudioParams = serializer.ReadDataField("audioparams", Robust.Shared.Audio.AudioParams.Default); - } } } diff --git a/Content.Shared/GameObjects/Components/Storage/SharedStorableComponent.cs b/Content.Shared/GameObjects/Components/Storage/SharedStorableComponent.cs index 652431c00f..31b749390d 100644 --- a/Content.Shared/GameObjects/Components/Storage/SharedStorableComponent.cs +++ b/Content.Shared/GameObjects/Components/Storage/SharedStorableComponent.cs @@ -1,7 +1,9 @@ #nullable enable using System; using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.GameObjects.Components.Storage { @@ -10,14 +12,7 @@ namespace Content.Shared.GameObjects.Components.Storage public override string Name => "Storable"; public override uint? NetID => ContentNetIDs.STORABLE; - public virtual int Size { get; set; } - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - - serializer.DataField(this, s => s.Size, "size", 1); - } + [DataField("size")] public virtual int Size { get; set; } = 1; } [Serializable, NetSerializable] diff --git a/Content.Shared/GameObjects/Components/Tag/TagComponent.cs b/Content.Shared/GameObjects/Components/Tag/TagComponent.cs index d4c2572eaf..3334607495 100644 --- a/Content.Shared/GameObjects/Components/Tag/TagComponent.cs +++ b/Content.Shared/GameObjects/Components/Tag/TagComponent.cs @@ -7,39 +7,30 @@ using Robust.Shared.IoC; using Robust.Shared.Players; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Shared.GameObjects.Components.Tag { [RegisterComponent] - public class TagComponent : Component + public class TagComponent : Component, ISerializationHooks { public override string Name => "Tag"; [ViewVariables] + [DataField("tags")] private readonly HashSet _tags = new(); public IReadOnlySet Tags => _tags; - public override void ExposeData(ObjectSerializer serializer) + public override void Initialize() { - base.ExposeData(serializer); + base.Initialize(); - serializer.DataReadWriteFunction( - "tags", - null!, - (ids) => - { - _tags.Clear(); - - if (ids == null) - { - return; - } - - AddTags(ids); - }, - () => _tags); + foreach (var tag in _tags) + { + GetTagOrThrow(tag); + } } public override ComponentState GetComponentState(ICommonSession player) diff --git a/Content.Shared/GameObjects/Components/Weapons/Melee/MeleeWeaponAnimationPrototype.cs b/Content.Shared/GameObjects/Components/Weapons/Melee/MeleeWeaponAnimationPrototype.cs index 1fb24206c2..db3057c275 100644 --- a/Content.Shared/GameObjects/Components/Weapons/Melee/MeleeWeaponAnimationPrototype.cs +++ b/Content.Shared/GameObjects/Components/Weapons/Melee/MeleeWeaponAnimationPrototype.cs @@ -2,57 +2,53 @@ using System; using Robust.Shared.Maths; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; -using YamlDotNet.RepresentationModel; namespace Content.Shared.GameObjects.Components.Weapons.Melee { [Prototype("MeleeWeaponAnimation")] public sealed class MeleeWeaponAnimationPrototype : IPrototype { - private string _prototype = "WeaponArc"; - private string _state = string.Empty; - private string _id = string.Empty; - private Vector4 _colorDelta; - private Vector4 _color; - private TimeSpan _length; - private float _speed; - private float _width; - private WeaponArcType _arcType; + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; - [ViewVariables] public string ID => _id; - [ViewVariables] public string State => _state; - [ViewVariables] public string Prototype => _prototype; - [ViewVariables] public TimeSpan Length => _length; - [ViewVariables] public float Speed => _speed; - [ViewVariables] public Vector4 Color => _color; - [ViewVariables] public Vector4 ColorDelta => _colorDelta; - [ViewVariables] public WeaponArcType ArcType => _arcType; - [ViewVariables] public float Width => _width; + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } - public void LoadFrom(YamlMappingNode mapping) - { - var serializer = YamlObjectSerializer.NewReader(mapping); + [ViewVariables] + [field: DataField("state")] + public string State { get; } = string.Empty; - serializer.DataField(ref _prototype, "prototype", "WeaponArc"); - serializer.DataField(ref _state, "state", string.Empty); - serializer.DataField(ref _id, "id", string.Empty); - serializer.DataField(ref _colorDelta, "colorDelta", Vector4.Zero); - serializer.DataField(ref _color, "color", new Vector4(1, 1, 1, 1)); - if (serializer.TryReadDataField("length", out float length)) - { - _length = TimeSpan.FromSeconds(length); - } - else - { - _length = TimeSpan.FromSeconds(0.5f); - } + [ViewVariables] + [field: DataField("prototype")] + public string Prototype { get; } = "WeaponArc"; - serializer.DataField(ref _speed, "speed", 1); - serializer.DataField(ref _arcType, "arcType", WeaponArcType.Slash); - serializer.DataField(ref _width, "width", 90); - } + [ViewVariables] + [field: DataField("length")] + public TimeSpan Length { get; } = TimeSpan.FromSeconds(0.5f); + + [ViewVariables] + [field: DataField("speed")] + public float Speed { get; } = 1; + + [ViewVariables] + [field: DataField("color")] + public Vector4 Color { get; } = new(1,1,1,1); + + [ViewVariables] + [field: DataField("colorDelta")] + public Vector4 ColorDelta { get; } = Vector4.Zero; + + [ViewVariables] + [field: DataField("arcType")] + public WeaponArcType ArcType { get; } = WeaponArcType.Slash; + + [ViewVariables] + [field: DataField("width")] + public float Width { get; } = 90; } public enum WeaponArcType diff --git a/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs b/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs index fdedca5578..681ee10333 100644 --- a/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs +++ b/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs @@ -8,6 +8,7 @@ using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Map; using Robust.Shared.Maths; +using Robust.Shared.Physics; using Robust.Shared.Utility; using static Content.Shared.GameObjects.EntitySystems.SharedInteractionSystem; diff --git a/Content.Shared/Interfaces/Chemistry/IMetabolizable.cs b/Content.Shared/Interfaces/Chemistry/IMetabolizable.cs index 382d17a330..70f155bb4a 100644 --- a/Content.Shared/Interfaces/Chemistry/IMetabolizable.cs +++ b/Content.Shared/Interfaces/Chemistry/IMetabolizable.cs @@ -1,14 +1,13 @@ #nullable enable using Content.Shared.Chemistry; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; namespace Content.Shared.Interfaces.Chemistry { /// /// Metabolism behavior for a reagent. /// - public interface IMetabolizable : IExposeData + public interface IMetabolizable { /// /// Metabolize the attached reagent. Return the amount of reagent to be removed from the solution. diff --git a/Content.Shared/Interfaces/Chemistry/IPlantMetabolizable.cs b/Content.Shared/Interfaces/Chemistry/IPlantMetabolizable.cs index 42e7a932ed..f85b95a1bb 100644 --- a/Content.Shared/Interfaces/Chemistry/IPlantMetabolizable.cs +++ b/Content.Shared/Interfaces/Chemistry/IPlantMetabolizable.cs @@ -1,10 +1,9 @@ -#nullable enable +#nullable enable using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; namespace Content.Shared.Interfaces.Chemistry { - public interface IPlantMetabolizable : IExposeData + public interface IPlantMetabolizable { /// /// Metabolize unit(s) of a reagent. diff --git a/Content.Shared/Interfaces/Chemistry/IReactionEffect.cs b/Content.Shared/Interfaces/Chemistry/IReactionEffect.cs index a3f98a2bb9..dd01e8b468 100644 --- a/Content.Shared/Interfaces/Chemistry/IReactionEffect.cs +++ b/Content.Shared/Interfaces/Chemistry/IReactionEffect.cs @@ -1,13 +1,12 @@ #nullable enable using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; -namespace Content.Server.Interfaces.Chemistry +namespace Content.Shared.Interfaces.Chemistry { /// /// Chemical reaction effect on the world such as an explosion, EMP, or fire. /// - public interface IReactionEffect : IExposeData + public interface IReactionEffect { void React(IEntity solutionEntity, double intensity); } diff --git a/Content.Shared/Interfaces/Chemistry/ITileReaction.cs b/Content.Shared/Interfaces/Chemistry/ITileReaction.cs index 65760a06ef..2e1208c334 100644 --- a/Content.Shared/Interfaces/Chemistry/ITileReaction.cs +++ b/Content.Shared/Interfaces/Chemistry/ITileReaction.cs @@ -1,11 +1,10 @@ #nullable enable using Content.Shared.Chemistry; using Robust.Shared.Map; -using Robust.Shared.Serialization; namespace Content.Shared.Interfaces.Chemistry { - public interface ITileReaction : IExposeData + public interface ITileReaction { ReagentUnit TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume); } diff --git a/Content.Shared/Kitchen/SharedKitchenSpikeComponent.cs b/Content.Shared/Kitchen/SharedKitchenSpikeComponent.cs index 7e4df97533..be66710245 100644 --- a/Content.Shared/Kitchen/SharedKitchenSpikeComponent.cs +++ b/Content.Shared/Kitchen/SharedKitchenSpikeComponent.cs @@ -1,25 +1,18 @@ #nullable enable using Content.Shared.GameObjects.Components.Mobs.State; -using Content.Shared.Interfaces.GameObjects.Components; using Content.Shared.GameObjects.EntitySystems.ActionBlocker; +using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; -namespace Content.Shared.GameObjects.Components.Kitchen +namespace Content.Shared.Kitchen { public abstract class SharedKitchenSpikeComponent : Component, IDragDropOn { public override string Name => "KitchenSpike"; - [ViewVariables] - protected float SpikeDelay; - - public override void ExposeData(ObjectSerializer serializer) - { - base.ExposeData(serializer); - serializer.DataField(ref SpikeDelay, "delay", 10.0f); - } + [ViewVariables] [DataField("delay")] protected float SpikeDelay = 10; bool IDragDropOn.CanDragDropOn(DragDropEventArgs eventArgs) { diff --git a/Content.Shared/Maps/ContentTileDefinition.cs b/Content.Shared/Maps/ContentTileDefinition.cs index 54938bc6c4..3f8b315b42 100644 --- a/Content.Shared/Maps/ContentTileDefinition.cs +++ b/Content.Shared/Maps/ContentTileDefinition.cs @@ -1,11 +1,10 @@ -#nullable enable +#nullable enable using System.Collections.Generic; -using System.Linq; using JetBrains.Annotations; using Robust.Shared.Map; using Robust.Shared.Prototypes; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; namespace Content.Shared.Maps { @@ -13,84 +12,40 @@ namespace Content.Shared.Maps [Prototype("tile")] public sealed class ContentTileDefinition : IPrototype, ITileDefinition { + [ViewVariables] string IPrototype.ID => Name; - public string Name { get; private set; } = string.Empty; + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } + + [field: DataField("name", required: true)] public string Name { get; } = string.Empty; + public ushort TileId { get; private set; } - public string DisplayName { get; private set; } = string.Empty; - public string SpriteName { get; private set; } = string.Empty; - public bool IsSubFloor { get; private set; } - public List BaseTurfs { get; private set; } = new(); - public bool CanCrowbar { get; private set; } - public string FootstepSounds { get; private set; } = string.Empty; - public float Friction { get; set; } - public float ThermalConductivity { get; set; } - public string ItemDropPrototypeName { get; private set; } = string.Empty; - public bool IsSpace { get; private set; } + + [field: DataField("display_name")] public string DisplayName { get; } = string.Empty; + + [field: DataField("texture")] public string SpriteName { get; } = string.Empty; + + [DataField("is_subfloor")] public bool IsSubFloor { get; private set; } + + [field: DataField("base_turfs")] public List BaseTurfs { get; } = new(); + + [DataField("can_crowbar")] public bool CanCrowbar { get; private set; } + + [field: DataField("footstep_sounds")] public string FootstepSounds { get; } = string.Empty; + + [DataField("friction")] public float Friction { get; set; } + + [DataField("thermalConductivity")] public float ThermalConductivity { get; set; } = 0.05f; + + [field: DataField("item_drop")] public string ItemDropPrototypeName { get; } = "FloorTileItemSteel"; + + [DataField("is_space")] public bool IsSpace { get; private set; } public void AssignTileId(ushort id) { TileId = id; } - - public void LoadFrom(YamlMappingNode mapping) - { - Name = mapping.GetNode("name").ToString(); - DisplayName = mapping.GetNode("display_name").ToString(); - SpriteName = mapping.GetNode("texture").ToString(); - - if (mapping.TryGetNode("is_subfloor", out var node)) - { - IsSubFloor = node.AsBool(); - } - - if (mapping.TryGetNode("base_turfs", out YamlSequenceNode? baseTurfNode)) - BaseTurfs = baseTurfNode.Select(i => i.ToString()).ToList(); - else - BaseTurfs = new List(); - - if (mapping.TryGetNode("is_space", out node)) - { - IsSpace = node.AsBool(); - } - - if (mapping.TryGetNode("can_crowbar", out node)) - { - CanCrowbar = node.AsBool(); - } - - if (mapping.TryGetNode("footstep_sounds", out node)) - { - FootstepSounds = node.AsString(); - } - - if (mapping.TryGetNode("friction", out node)) - { - Friction = node.AsFloat(); - } - else - { - Friction = 0; - } - - if (mapping.TryGetNode("thermalConductivity", out node)) - { - ThermalConductivity = node.AsFloat(); - } - else - { - ThermalConductivity = 0.05f; - } - - if (mapping.TryGetNode("item_drop", out node)) - { - ItemDropPrototypeName = node.ToString(); - } - else - { - ItemDropPrototypeName = "FloorTileItemSteel"; - } - } - } } diff --git a/Content.Shared/Materials/Material.cs b/Content.Shared/Materials/Material.cs index b330fd614a..ced689cfe3 100644 --- a/Content.Shared/Materials/Material.cs +++ b/Content.Shared/Materials/Material.cs @@ -1,10 +1,9 @@ #nullable enable -using Robust.Shared.IoC; using Robust.Shared.Maths; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; +using Robust.Shared.ViewVariables; namespace Content.Shared.Materials { @@ -12,120 +11,79 @@ namespace Content.Shared.Materials /// Materials are read-only storage for the properties of specific materials. /// Properties should be intrinsic (or at least as much is necessary for game purposes). /// - public class Material : IExposeData + [Prototype("material")] + [DataDefinition] + public class MaterialPrototype : IPrototype { - public string Name => _name; - private string _name = "unobtanium"; + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; - public Color Color => _color; - private Color _color = Color.Gray; + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } + + [DataField("name")] public string Name { get; private set; } = "unobtanium"; + + [DataField("color")] public Color Color { get; private set; } = Color.Gray; /// /// Volumetric mass density, in kg.m^-3. /// - public double Density => _density; - private double _density = 1; + [DataField("density")] + public double Density { get; private set; } = 1; /// /// Electrical resistivity, NOT resistance. /// Unit is ohm-meter (Ω⋅m). /// - public double ElectricResistivity => _electricResistivity; - private double _electricResistivity = 1; + [DataField("electricResistivity")] + public double ElectricResistivity { get; private set; } = 1; /// /// Thermal conductivity, in W.m-1.K-1 /// - public double ThermalConductivity => _thermalConductivity; - private double _thermalConductivity = 1; + [DataField("thermalConductivity")] + public double ThermalConductivity { get; private set; } = 1; /// /// Specific heat, in J.kg-1.K-1 /// - public double SpecificHeat => _specificHeat; - private double _specificHeat = 1; + [DataField("specificHeat")] + public double SpecificHeat { get; private set; } = 1; /// /// Controls how durable the material is. /// Basically how slowly it degrades. /// - public double Durability => _durability; - private double _durability = 1; + [DataField("durability")] + public double Durability { get; private set; } = 1; /// /// Multiplier for how much this resists damage. /// So higher means armor is more effective, for example. /// - public double Hardness => _hardness; - private double _hardness = 1; + [DataField("hardness")] + public double Hardness { get; private set; } = 1; /// /// Multiplier that determines damage on sharpness-based weapons like knives. /// Higher means more damage is done. /// - public double SharpDamage => _sharpDamage; - private double _sharpDamage = 1; + [DataField("sharpDamage")] + public double SharpDamage { get; private set; } = 1; /// /// Multiplier that determines damage on blunt-based weapons like clubs. /// Higher means more damage is done. /// - public double BluntDamage => _bluntDamage; - private double _bluntDamage = 1; + [DataField("bluntDamage")] + public double BluntDamage { get; private set; } = 1; /// /// An icon used to represent the material in graphic interfaces. /// - public SpriteSpecifier Icon => _icon; - private SpriteSpecifier _icon = SpriteSpecifier.Invalid; - - public string? ID - { - get - { - var prototypeManager = IoCManager.Resolve(); - foreach (var prototype in prototypeManager.EnumeratePrototypes()) - { - if (prototype.Material == this) return prototype.ID; - } - - return null; - } - } - - void IExposeData.ExposeData(ObjectSerializer serializer) - { - serializer.DataField(ref _name, "name", "unobtanium", alwaysWrite: true); - serializer.DataField(ref _color, "color", Color.Gray, alwaysWrite: true); - - // All default material params are initialized to 1 because - // I'm too lazy to figure out for which that's necessary to prevent divisions by zero in case left out. - serializer.DataField(ref _density, "density", 1, alwaysWrite: true); - serializer.DataField(ref _electricResistivity, "electricResistivity", 1, alwaysWrite: true); - serializer.DataField(ref _thermalConductivity, "thermalConductivity", 1, alwaysWrite: true); - serializer.DataField(ref _specificHeat, "specificHeat", 1, alwaysWrite: true); - serializer.DataField(ref _durability, "durability", 1, alwaysWrite: true); - serializer.DataField(ref _hardness, "hardness", 1, alwaysWrite: true); - serializer.DataField(ref _sharpDamage, "sharpDamage", 1, alwaysWrite: true); - serializer.DataField(ref _bluntDamage, "bluntDamage", 1, alwaysWrite: true); - serializer.DataField(ref _icon, "icon", SpriteSpecifier.Invalid, alwaysWrite: true); - } - } - - [Prototype("material")] - public class MaterialPrototype : IPrototype - { - public string ID { get; private set; } = string.Empty; - - public Material Material { get; private set; } = new(); - - public void LoadFrom(YamlMappingNode mapping) - { - ID = mapping["id"].AsString(); - - var ser = YamlObjectSerializer.NewReader(mapping); - Material = new Material(); - ((IExposeData) Material).ExposeData(ser); - } + [DataField("icon")] + public SpriteSpecifier Icon { get; private set; } = SpriteSpecifier.Invalid; } } diff --git a/Content.Shared/Prototypes/Cargo/CargoProductPrototype.cs b/Content.Shared/Prototypes/Cargo/CargoProductPrototype.cs index 7f71e96bc5..bd25f1a33d 100644 --- a/Content.Shared/Prototypes/Cargo/CargoProductPrototype.cs +++ b/Content.Shared/Prototypes/Cargo/CargoProductPrototype.cs @@ -3,26 +3,26 @@ using System; using Robust.Shared.IoC; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; -using YamlDotNet.RepresentationModel; namespace Content.Shared.Prototypes.Cargo { [NetSerializable, Serializable, Prototype("cargoProduct")] public class CargoProductPrototype : IPrototype { - private string _id = string.Empty; - private string _name = string.Empty; - private string _description = string.Empty; - private SpriteSpecifier _icon = SpriteSpecifier.Invalid; - private string _product = string.Empty; - private int _pointCost; - private string _category = string.Empty; - private string _group = string.Empty; + [DataField("name")] private string _name = string.Empty; + + [DataField("description")] private string _description = string.Empty; [ViewVariables] - public string ID => _id; + [field: DataField("id", required: true)] + public string ID { get; } = default!; + + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } /// /// Product name. @@ -35,7 +35,7 @@ namespace Content.Shared.Prototypes.Cargo if (_name.Trim().Length != 0) return _name; - if (IoCManager.Resolve().TryIndex(_product, out EntityPrototype? prototype)) + if (IoCManager.Resolve().TryIndex(Product, out EntityPrototype? prototype)) { _name = prototype.Name; } @@ -55,7 +55,7 @@ namespace Content.Shared.Prototypes.Cargo if (_description.Trim().Length != 0) return _description; - if (IoCManager.Resolve().TryIndex(_product, out EntityPrototype? prototype)) + if (IoCManager.Resolve().TryIndex(Product, out EntityPrototype? prototype)) { _description = prototype.Description; } @@ -68,49 +68,40 @@ namespace Content.Shared.Prototypes.Cargo /// Texture path used in the CargoConsole GUI. /// [ViewVariables] - public SpriteSpecifier Icon => _icon; + [field: DataField("icon")] + public SpriteSpecifier Icon { get; } = SpriteSpecifier.Invalid; /// /// The prototype name of the product. /// [ViewVariables] - public string Product => _product; + [field: DataField("product")] + public string Product { get; } = string.Empty; /// /// The point cost of the product. /// [ViewVariables] - public int PointCost => _pointCost; + [field: DataField("cost")] + public int PointCost { get; } /// /// The prototype category of the product. (e.g. Engineering, Medical) /// [ViewVariables] - public string Category => _category; + [field: DataField("category")] + public string Category { get; } = string.Empty; /// /// The prototype group of the product. (e.g. Contraband) /// [ViewVariables] - public string Group => _group; + [field: DataField("group")] + public string Group { get; } = string.Empty; public CargoProductPrototype() { IoCManager.InjectDependencies(this); } - - public void LoadFrom(YamlMappingNode mapping) - { - var serializer = YamlObjectSerializer.NewReader(mapping); - - serializer.DataField(ref _name, "name", string.Empty); - serializer.DataField(ref _id, "id", string.Empty); - serializer.DataField(ref _description, "description", string.Empty); - serializer.DataField(ref _icon, "icon", SpriteSpecifier.Invalid); - serializer.DataField(ref _product, "product", string.Empty); - serializer.DataField(ref _pointCost, "cost", 0); - serializer.DataField(ref _category, "category", string.Empty); - serializer.DataField(ref _group, "group", string.Empty); - } } } diff --git a/Content.Shared/Prototypes/DatasetPrototype.cs b/Content.Shared/Prototypes/DatasetPrototype.cs index 9f7e260daa..7b0ad3798f 100644 --- a/Content.Shared/Prototypes/DatasetPrototype.cs +++ b/Content.Shared/Prototypes/DatasetPrototype.cs @@ -1,26 +1,22 @@ #nullable enable using System.Collections.Generic; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; namespace Content.Shared.Prototypes { [Prototype("dataset")] public class DatasetPrototype : IPrototype { - private string _id = string.Empty; - public string ID => _id; + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; - private List _values = new(); - public IReadOnlyList Values => _values; + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } - public void LoadFrom(YamlMappingNode mapping) - { - var ser = YamlObjectSerializer.NewReader(mapping); - - ser.DataField(ref _id, "id", string.Empty); - ser.DataField(ref _values, "values", new List()); - } + [field: DataField("values")] public IReadOnlyList Values { get; } = new List(); } } diff --git a/Content.Shared/Prototypes/Kitchen/MicrowaveMealRecipePrototype.cs b/Content.Shared/Prototypes/Kitchen/MicrowaveMealRecipePrototype.cs index 9ee2ee992f..35ed37c532 100644 --- a/Content.Shared/Prototypes/Kitchen/MicrowaveMealRecipePrototype.cs +++ b/Content.Shared/Prototypes/Kitchen/MicrowaveMealRecipePrototype.cs @@ -2,8 +2,8 @@ using System.Collections.Generic; using Robust.Shared.Localization; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; namespace Content.Shared.Prototypes.Kitchen { @@ -13,31 +13,32 @@ namespace Content.Shared.Prototypes.Kitchen [Prototype("microwaveMealRecipe")] public class FoodRecipePrototype : IPrototype { - private string _id = string.Empty; - private string _name = string.Empty; - private string _result = string.Empty; - private int _cookTime; + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; - private Dictionary _ingsReagents = new(); - private Dictionary _ingsSolids = new(); + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } + + [DataField("name")] + private string _name = string.Empty; + + [DataField("reagents")] + private readonly Dictionary _ingsReagents = new(); + + [DataField("solids")] + private readonly Dictionary _ingsSolids = new (); + + [field: DataField("result")] + public string Result { get; } = string.Empty; + + [field: DataField("time")] + public int CookTime { get; } = 5; public string Name => Loc.GetString(_name); - public string ID => _id; - public string Result => _result; - public int CookTime => _cookTime; + public IReadOnlyDictionary IngredientsReagents => _ingsReagents; public IReadOnlyDictionary IngredientsSolids => _ingsSolids; - - public void LoadFrom(YamlMappingNode mapping) - { - var serializer = YamlObjectSerializer.NewReader(mapping); - - serializer.DataField(ref _id, "id", string.Empty); - serializer.DataField(ref _name, "name", string.Empty); - serializer.DataField(ref _result, "result", string.Empty); - serializer.DataField(ref _ingsReagents, "reagents", new Dictionary()); - serializer.DataField(ref _ingsSolids, "solids", new Dictionary()); - serializer.DataField(ref _cookTime, "time", 5); - } } } diff --git a/Content.Shared/Prototypes/PDA/UplinkStoreListingPrototype.cs b/Content.Shared/Prototypes/PDA/UplinkStoreListingPrototype.cs index ed80b2b303..01788120d4 100644 --- a/Content.Shared/Prototypes/PDA/UplinkStoreListingPrototype.cs +++ b/Content.Shared/Prototypes/PDA/UplinkStoreListingPrototype.cs @@ -1,38 +1,35 @@ #nullable enable using Content.Shared.GameObjects.Components.PDA; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; namespace Content.Shared.Prototypes.PDA { [Prototype("uplinkListing")] public class UplinkStoreListingPrototype : IPrototype { - private string _id = string.Empty; - private string _itemId = string.Empty; - private int _price; - private UplinkCategory _category; - private string _desc = string.Empty; - private string _name = string.Empty; + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; - public string ID => _id; + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } - public string ItemId => _itemId; - public int Price => _price; - public UplinkCategory Category => _category; - public string Description => _desc; - public string ListingName => _name; + [field: DataField("itemId")] + public string ItemId { get; } = string.Empty; - public void LoadFrom(YamlMappingNode mapping) - { - var serializer = YamlObjectSerializer.NewReader(mapping); - serializer.DataField(ref _id, "id", string.Empty); - serializer.DataField(ref _itemId, "itemId", string.Empty); - serializer.DataField(ref _price, "price", 5); - serializer.DataField(ref _category, "category", UplinkCategory.Utility); - serializer.DataField(ref _desc, "description", string.Empty); - serializer.DataField(ref _name, "listingName", string.Empty); - } + [field: DataField("price")] + public int Price { get; } = 5; + + [field: DataField("category")] + public UplinkCategory Category { get; } = UplinkCategory.Utility; + + [field: DataField("description")] + public string Description { get; } = string.Empty; + + [field: DataField("listingName")] + public string ListingName { get; } = string.Empty; } } diff --git a/Content.Shared/Prototypes/Tag/TagPrototype.cs b/Content.Shared/Prototypes/Tag/TagPrototype.cs index 23cb70786c..0cb3676657 100644 --- a/Content.Shared/Prototypes/Tag/TagPrototype.cs +++ b/Content.Shared/Prototypes/Tag/TagPrototype.cs @@ -1,8 +1,7 @@ #nullable enable -using JetBrains.Annotations; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; namespace Content.Shared.Prototypes.Tag { @@ -14,17 +13,12 @@ namespace Content.Shared.Prototypes.Tag [Prototype("Tag")] public class TagPrototype : IPrototype { - public string ID { get; [UsedImplicitly] private set; } = default!; + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; - private void ExposeData(ObjectSerializer serializer) - { - serializer.DataField(this, x => x.ID, "id", ""); - } - - public void LoadFrom(YamlMappingNode mapping) - { - var serializer = YamlObjectSerializer.NewReader(mapping); - ExposeData(serializer); - } + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } } } diff --git a/Content.Shared/Research/LatheRecipePrototype.cs b/Content.Shared/Research/LatheRecipePrototype.cs index 31756aa614..8a6217b1b0 100644 --- a/Content.Shared/Research/LatheRecipePrototype.cs +++ b/Content.Shared/Research/LatheRecipePrototype.cs @@ -4,25 +4,40 @@ using System.Collections.Generic; using Robust.Shared.IoC; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; -using YamlDotNet.RepresentationModel; namespace Content.Shared.Research { [NetSerializable, Serializable, Prototype("latheRecipe")] public class LatheRecipePrototype : IPrototype { - private string _name = string.Empty; - private string _id = string.Empty; - private SpriteSpecifier _icon = SpriteSpecifier.Invalid; - private string _description = string.Empty; - private string _result = string.Empty; - private int _completeTime; - private Dictionary _requiredMaterials = new(); + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; [ViewVariables] - public string ID => _id; + [field: DataField("parent")] + public string? Parent { get; } + + [DataField("name")] + private string _name = string.Empty; + + [DataField("icon")] + private SpriteSpecifier _icon = SpriteSpecifier.Invalid; + + [DataField("description")] + private string _description = string.Empty; + + [DataField("result")] + private string _result = string.Empty; + + [DataField("completetime")] + private int _completeTime = 2500; + + [DataField("materials")] + private Dictionary _requiredMaterials = new(); /// /// Name displayed in the lathe GUI. @@ -90,18 +105,5 @@ namespace Content.Shared.Research /// [ViewVariables] public int CompleteTime => _completeTime; - - public void LoadFrom(YamlMappingNode mapping) - { - var serializer = YamlObjectSerializer.NewReader(mapping); - - serializer.DataField(ref _name, "name", string.Empty); - serializer.DataField(ref _id, "id", string.Empty); - serializer.DataField(ref _description, "description", string.Empty); - serializer.DataField(ref _icon, "icon", SpriteSpecifier.Invalid); - serializer.DataField(ref _result, "result", string.Empty); - serializer.DataField(ref _completeTime, "completetime", 2500); - serializer.DataField(ref _requiredMaterials, "materials", new Dictionary()); - } } } diff --git a/Content.Shared/Research/TechnologyPrototype.cs b/Content.Shared/Research/TechnologyPrototype.cs index b4051733ad..4c81b05861 100644 --- a/Content.Shared/Research/TechnologyPrototype.cs +++ b/Content.Shared/Research/TechnologyPrototype.cs @@ -3,75 +3,65 @@ using System; using System.Collections.Generic; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; -using YamlDotNet.RepresentationModel; namespace Content.Shared.Research { [NetSerializable, Serializable, Prototype("technology")] public class TechnologyPrototype : IPrototype { - private string _name = string.Empty; - private string _id = string.Empty; - private SpriteSpecifier _icon = SpriteSpecifier.Invalid; - private string _description = string.Empty; - private int _requiredPoints; - private List _requiredTechnologies = new(); - private List _unlockedRecipes = new(); - /// /// The ID of this technology prototype. /// [ViewVariables] - public string ID => _id; + [field: DataField("id", required: true)] + public string ID { get; } = default!; + + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } /// /// The name this technology will have on user interfaces. /// [ViewVariables] - public string Name => _name; + [field: DataField("name")] + public string Name { get; } = string.Empty; /// /// An icon that represent this technology. /// - public SpriteSpecifier Icon => _icon; + [field: DataField("icon")] + public SpriteSpecifier Icon { get; } = SpriteSpecifier.Invalid; /// /// A short description of the technology. /// [ViewVariables] - public string Description => _description; + [field: DataField("description")] + public string Description { get; } = string.Empty; /// /// The required research points to unlock this technology. /// [ViewVariables] - public int RequiredPoints => _requiredPoints; + [field: DataField("requiredPoints")] + public int RequiredPoints { get; } /// /// A list of technology IDs required to unlock this technology. /// [ViewVariables] - public List RequiredTechnologies => _requiredTechnologies; + [field: DataField("requiredTechnologies")] + public List RequiredTechnologies { get; } = new(); /// /// A list of recipe IDs this technology unlocks. /// [ViewVariables] - public List UnlockedRecipes => _unlockedRecipes; - - public void LoadFrom(YamlMappingNode mapping) - { - var serializer = YamlObjectSerializer.NewReader(mapping); - - serializer.DataField(ref _name, "name", string.Empty); - serializer.DataField(ref _id, "id", string.Empty); - serializer.DataField(ref _description, "description", string.Empty); - serializer.DataField(ref _icon, "icon", SpriteSpecifier.Invalid); - serializer.DataField(ref _requiredPoints, "requiredPoints", 0); - serializer.DataField(ref _requiredTechnologies, "requiredTechnologies", new List()); - serializer.DataField(ref _unlockedRecipes, "unlockedRecipes", new List()); - } + [field: DataField("unlockedRecipes")] + public List UnlockedRecipes { get; } = new(); } } diff --git a/Content.Shared/Roles/AntagPrototype.cs b/Content.Shared/Roles/AntagPrototype.cs index cfa1e49c20..440b3e4f97 100644 --- a/Content.Shared/Roles/AntagPrototype.cs +++ b/Content.Shared/Roles/AntagPrototype.cs @@ -1,8 +1,8 @@ #nullable enable using Robust.Shared.Localization; using Robust.Shared.Prototypes; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; namespace Content.Shared.Roles { @@ -12,35 +12,36 @@ namespace Content.Shared.Roles [Prototype("antag")] public class AntagPrototype : IPrototype { - public string ID { get; private set; } = string.Empty; + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; + + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } /// /// The name of this antag as displayed to players. /// - public string Name { get; private set; } = string.Empty; + [field: DataField("name")] + public string Name { get; } = string.Empty; /// /// The antag's objective, displayed at round-start to the player. /// + [DataField("objective")] public string Objective { get; private set; } = string.Empty; /// /// Whether or not the antag role is one of the bad guys. /// + [DataField("antagonist")] public bool Antagonist { get; private set; } /// /// Whether or not the player can set the antag role in antag preferences. /// + [DataField("setPreference")] public bool SetPreference { get; private set; } - - public void LoadFrom(YamlMappingNode mapping) - { - ID = mapping.GetNode("id").AsString(); - Name = Loc.GetString(mapping.GetNode("name").ToString()); - Objective = mapping.GetNode("objective").ToString(); - Antagonist = mapping.GetNode("antagonist").AsBool(); - SetPreference = mapping.GetNode("setPreference").AsBool(); - } } } diff --git a/Content.Shared/Roles/JobPrototype.cs b/Content.Shared/Roles/JobPrototype.cs index b26ca1cfb6..c5eeab079f 100644 --- a/Content.Shared/Roles/JobPrototype.cs +++ b/Content.Shared/Roles/JobPrototype.cs @@ -1,10 +1,9 @@ #nullable enable using System; using System.Collections.Generic; -using Robust.Shared.Localization; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; namespace Content.Shared.Roles { @@ -14,52 +13,55 @@ namespace Content.Shared.Roles [Prototype("job")] public class JobPrototype : IPrototype { - public string ID { get; private set; } = string.Empty; + private string _name = string.Empty; + + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; + + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } /// /// The name of this job as displayed to players. /// - public string Name { get; private set; } = string.Empty; + [field: DataField("name")] + public string Name { get; } = string.Empty; /// /// Whether this job is a head. /// The job system will try to pick heads before other jobs on the same priority level. /// + [DataField("head")] public bool IsHead { get; private set; } /// /// The total amount of people that can start with this job round-start. /// - public int SpawnPositions { get; private set; } + public int SpawnPositions => _spawnPositions ?? TotalPositions; + + [DataField("spawnPositions")] + private int? _spawnPositions; /// /// The total amount of positions available. /// + [DataField("positions")] public int TotalPositions { get; private set; } - public string StartingGear { get; private set; } = string.Empty; + [DataField("startingGear")] + public string? StartingGear { get; private set; } - public string Icon { get; private set; } = string.Empty; + [field: DataField("icon")] public string Icon { get; } = string.Empty; - public JobSpecial? Special { get; private set; } = null; + [DataField("special")] + public JobSpecial? Special { get; private set; } - public IReadOnlyCollection Departments { get; private set; } = Array.Empty(); - public IReadOnlyCollection Access { get; private set; } = Array.Empty(); + [field: DataField("departments")] + public IReadOnlyCollection Departments { get; } = Array.Empty(); - public void LoadFrom(YamlMappingNode mapping) - { - var srz = YamlObjectSerializer.NewReader(mapping); - ID = srz.ReadDataField("id"); - Name = Loc.GetString(srz.ReadDataField("name")); - StartingGear = srz.ReadDataField("startingGear"); - Departments = srz.ReadDataField>("departments"); - TotalPositions = srz.ReadDataField("positions"); - - srz.DataField(this, p => p.SpawnPositions, "spawnPositions", TotalPositions); - srz.DataField(this, p => p.IsHead, "head", false); - srz.DataField(this, p => p.Access, "access", Array.Empty()); - srz.DataField(this, p => p.Icon, "icon", string.Empty); - srz.DataField(this, p => p.Special, "special", null); - } + [field: DataField("access")] + public IReadOnlyCollection Access { get; } = Array.Empty(); } } diff --git a/Content.Shared/Roles/JobSpecial.cs b/Content.Shared/Roles/JobSpecial.cs index 5706a932f0..3d174466cc 100644 --- a/Content.Shared/Roles/JobSpecial.cs +++ b/Content.Shared/Roles/JobSpecial.cs @@ -1,23 +1,15 @@ #nullable enable using Robust.Shared.GameObjects; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.Roles { /// /// Provides special hooks for when jobs get spawned in/equipped. /// - public abstract class JobSpecial : IExposeData + [ImplicitDataDefinitionForInheritors] + public abstract class JobSpecial { - void IExposeData.ExposeData(ObjectSerializer serializer) - { - ExposeData(serializer); - } - - protected virtual void ExposeData(ObjectSerializer serializer) - { - } - public virtual void AfterEquip(IEntity mob) { diff --git a/Content.Shared/Roles/StartingGearPrototype.cs b/Content.Shared/Roles/StartingGearPrototype.cs index 23b2a7450f..9e3f1c0170 100644 --- a/Content.Shared/Roles/StartingGearPrototype.cs +++ b/Content.Shared/Roles/StartingGearPrototype.cs @@ -1,12 +1,9 @@ #nullable enable -using System; using System.Collections.Generic; -using System.Linq; -using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; -using Robust.Shared.ViewVariables; -using YamlDotNet.RepresentationModel; using Content.Shared.Preferences; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines; namespace Content.Shared.Roles @@ -14,48 +11,34 @@ namespace Content.Shared.Roles [Prototype("startingGear")] public class StartingGearPrototype : IPrototype { - private string _id = default!; - private Dictionary _equipment = default!; + [DataField("equipment")] private Dictionary _equipment = new(); /// /// if empty, there is no skirt override - instead the uniform provided in equipment is added. /// + [DataField("innerclothingskirt")] private string _innerClothingSkirt = default!; - private string _satchel = default!; - private string _duffelbag = default!; + + [DataField("satchel")] + private string _satchel = string.Empty; + + [DataField("duffelbag")] + private string _duffelbag = string.Empty; public IReadOnlyDictionary Inhand => _inHand; /// /// hand index, item prototype /// - private Dictionary _inHand = default!; + [DataField("inhand")] + private Dictionary _inHand = new(0); - [ViewVariables] public string ID => _id; + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; - public void LoadFrom(YamlMappingNode mapping) - { - var serializer = YamlObjectSerializer.NewReader(mapping); - - serializer.DataField(ref _id, "id", string.Empty); - serializer.DataField(ref _inHand, "inhand", new Dictionary(0)); - - var equipment = serializer.ReadDataField>("equipment"); - - _equipment = equipment.ToDictionary(slotStr => - { - var (key, _) = slotStr; - if (!Enum.TryParse(key, true, out Slots slot)) - { - throw new Exception($"{key} is an invalid equipment slot."); - } - - return slot; - }, type => type.Value); - - serializer.DataField(ref _innerClothingSkirt, "innerclothingskirt", string.Empty); - serializer.DataField(ref _satchel, "satchel", string.Empty); - serializer.DataField(ref _duffelbag, "duffelbag", string.Empty); - } + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } public string GetGear(Slots slot, HumanoidCharacterProfile? profile) { diff --git a/Content.Shared/Stacks/StackPrototype.cs b/Content.Shared/Stacks/StackPrototype.cs index d3d3b06ffa..0d35c0e027 100644 --- a/Content.Shared/Stacks/StackPrototype.cs +++ b/Content.Shared/Stacks/StackPrototype.cs @@ -1,33 +1,32 @@ #nullable enable using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; +using Robust.Shared.ViewVariables; namespace Content.Shared.Stacks { [Prototype("stack")] public class StackPrototype : IPrototype { - public string ID { get; private set; } = string.Empty; + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; - public string Name { get; private set; } = string.Empty; + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } - public SpriteSpecifier? Icon { get; private set; } + [field: DataField("name")] + public string Name { get; } = string.Empty; + + [field: DataField("icon")] + public SpriteSpecifier? Icon { get; } /// /// The entity id that will be spawned by default from this stack. /// - public string? Spawn { get; private set; } - - public void LoadFrom(YamlMappingNode mapping) - { - var reader = YamlObjectSerializer.NewReader(mapping); - - reader.DataField(this, x => x.ID, "id", string.Empty); - reader.DataField(this, x => x.Name, "name", string.Empty); - reader.DataField(this, x => x.Icon, "icon", null); - reader.DataField(this, x => x.Spawn, "spawn", null); - } + [field: DataField("spawn")] + public string? Spawn { get; } } } diff --git a/Content.Shared/Utility/EntityPrototypeHelpers.cs b/Content.Shared/Utility/EntityPrototypeHelpers.cs index 5982788e73..4957e91633 100644 --- a/Content.Shared/Utility/EntityPrototypeHelpers.cs +++ b/Content.Shared/Utility/EntityPrototypeHelpers.cs @@ -33,7 +33,7 @@ namespace Content.Shared.Utility { prototypeManager ??= IoCManager.Resolve(); - return prototypeManager.TryIndex(prototype, out EntityPrototype? proto) && proto.HasComponent(component, componentFactory); + return prototypeManager.TryIndex(prototype, out EntityPrototype? proto) && proto!.HasComponent(component, componentFactory); } } } diff --git a/Content.Shared/VendingMachines/VendingMachineInventoryPrototype.cs b/Content.Shared/VendingMachines/VendingMachineInventoryPrototype.cs index 560d0b77b6..66f9967945 100644 --- a/Content.Shared/VendingMachines/VendingMachineInventoryPrototype.cs +++ b/Content.Shared/VendingMachines/VendingMachineInventoryPrototype.cs @@ -3,37 +3,35 @@ using System; using System.Collections.Generic; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; -using YamlDotNet.RepresentationModel; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; namespace Content.Shared.VendingMachines { [Serializable, NetSerializable, Prototype("vendingMachineInventory")] public class VendingMachineInventoryPrototype : IPrototype { - private string _id = string.Empty; - private string _name = string.Empty; - private string _description = string.Empty; - private double _animationDuration; - private string _spriteName = string.Empty; - private Dictionary _startingInventory = new(); + [ViewVariables] + [field: DataField("id", required: true)] + public string ID { get; } = default!; - public string ID => _id; - public string Name => _name; - public string Description => _description; - public double AnimationDuration => _animationDuration; - public string SpriteName => _spriteName; - public Dictionary StartingInventory => _startingInventory; + [ViewVariables] + [field: DataField("parent")] + public string? Parent { get; } - public void LoadFrom(YamlMappingNode mapping) - { - var serializer = YamlObjectSerializer.NewReader(mapping); + [field: DataField("name")] + public string Name { get; } = string.Empty; - serializer.DataField(ref _id, "id", string.Empty); - serializer.DataField(ref _name, "name", string.Empty); - serializer.DataField(ref _description, "description", string.Empty); - serializer.DataField(ref _animationDuration, "animationDuration", 0); - serializer.DataField(ref _spriteName, "spriteName", string.Empty); - serializer.DataField(ref _startingInventory, "startingInventory", new Dictionary()); - } + [field: DataField("description")] + public string Description { get; } = string.Empty; + + [field: DataField("animationDuration")] + public double AnimationDuration { get; } + + [field: DataField("spriteName")] + public string SpriteName { get; } = string.Empty; + + [field: DataField("startingInventory")] + public Dictionary StartingInventory { get; } = new(); } } diff --git a/Content.Tests/Content.Tests.csproj b/Content.Tests/Content.Tests.csproj index 6483b9758d..6733051ad8 100644 --- a/Content.Tests/Content.Tests.csproj +++ b/Content.Tests/Content.Tests.csproj @@ -28,4 +28,5 @@ + diff --git a/Content.Tests/Server/GameObjects/Components/Mobs/ServerAlertsComponentTests.cs b/Content.Tests/Server/GameObjects/Components/Mobs/ServerAlertsComponentTests.cs index 195cfaf29b..969e687e68 100644 --- a/Content.Tests/Server/GameObjects/Components/Mobs/ServerAlertsComponentTests.cs +++ b/Content.Tests/Server/GameObjects/Components/Mobs/ServerAlertsComponentTests.cs @@ -6,6 +6,7 @@ using NUnit.Framework; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.Manager; namespace Content.Tests.Server.GameObjects.Components.Mobs { @@ -34,6 +35,7 @@ namespace Content.Tests.Server.GameObjects.Components.Mobs // but wanted to keep it anyway to see what's possible w.r.t. testing components // in a unit test + IoCManager.Resolve().Initialize(); var prototypeManager = IoCManager.Resolve(); var factory = IoCManager.Resolve(); factory.RegisterClass(); diff --git a/Content.Tests/Server/Preferences/ServerDbSqliteTests.cs b/Content.Tests/Server/Preferences/ServerDbSqliteTests.cs index 0857b2e983..cb439563d4 100644 --- a/Content.Tests/Server/Preferences/ServerDbSqliteTests.cs +++ b/Content.Tests/Server/Preferences/ServerDbSqliteTests.cs @@ -9,12 +9,12 @@ using Content.Shared.Preferences; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; using NUnit.Framework; -using Robust.Shared; using Robust.Shared.Enums; using Robust.Shared.IoC; using Robust.Shared.Maths; using Robust.Shared.Network; using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.Manager; namespace Content.Tests.Server.Preferences { @@ -97,6 +97,7 @@ namespace Content.Tests.Server.Preferences { var db = GetDb(); var username = new NetUserId(new Guid("640bd619-fc8d-4fe2-bf3c-4a5fb17d6ddd")); + IoCManager.Resolve().Initialize(); IoCManager.Resolve().LoadFromStream(new StringReader(Prototypes)); await db.InitPrefsAsync(username, HumanoidCharacterProfile.Default()); await db.SaveCharacterSlotAsync(username, CharlieCharlieson(), 1); diff --git a/Content.Tests/Shared/Alert/AlertManagerTests.cs b/Content.Tests/Shared/Alert/AlertManagerTests.cs index 796b71c432..9f24c9a74a 100644 --- a/Content.Tests/Shared/Alert/AlertManagerTests.cs +++ b/Content.Tests/Shared/Alert/AlertManagerTests.cs @@ -3,6 +3,7 @@ using Content.Shared.Alert; using NUnit.Framework; using Robust.Shared.IoC; using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.Manager; using Robust.Shared.Utility; namespace Content.Tests.Shared.Alert @@ -25,6 +26,7 @@ namespace Content.Tests.Shared.Alert [Test] public void TestAlertManager() { + IoCManager.Resolve().Initialize(); var prototypeManager = IoCManager.Resolve(); prototypeManager.LoadFromStream(new StringReader(PROTOTYPES)); var alertManager = IoCManager.Resolve(); diff --git a/Content.Tests/Shared/Alert/AlertOrderPrototypeTests.cs b/Content.Tests/Shared/Alert/AlertOrderPrototypeTests.cs index dca7c0d2c8..a2dbb052b3 100644 --- a/Content.Tests/Shared/Alert/AlertOrderPrototypeTests.cs +++ b/Content.Tests/Shared/Alert/AlertOrderPrototypeTests.cs @@ -5,6 +5,7 @@ using Content.Shared.Alert; using NUnit.Framework; using Robust.Shared.IoC; using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.Manager; namespace Content.Tests.Shared.Alert { @@ -13,6 +14,7 @@ namespace Content.Tests.Shared.Alert { const string PROTOTYPES = @" - type: alertOrder + id: testAlertOrder order: - alertType: Handcuffed - category: Pressure @@ -72,8 +74,10 @@ namespace Content.Tests.Shared.Alert [Test] public void TestAlertOrderPrototype() { + IoCManager.Resolve().Initialize(); var prototypeManager = IoCManager.Resolve(); prototypeManager.LoadFromStream(new StringReader(PROTOTYPES)); + prototypeManager.Resync(); var alertOrder = prototypeManager.EnumeratePrototypes().FirstOrDefault(); diff --git a/Content.Tests/Shared/Alert/AlertPrototypeTests.cs b/Content.Tests/Shared/Alert/AlertPrototypeTests.cs index 038a72d6f5..5691fd097a 100644 --- a/Content.Tests/Shared/Alert/AlertPrototypeTests.cs +++ b/Content.Tests/Shared/Alert/AlertPrototypeTests.cs @@ -2,6 +2,9 @@ using System.IO; using Content.Shared.Alert; using NUnit.Framework; +using Robust.Shared.IoC; +using Robust.Shared.Serialization.Manager; +using Robust.Shared.Serialization.Markdown; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; @@ -20,6 +23,12 @@ namespace Content.Tests.Shared.Alert minSeverity: 0 maxSeverity: 6"; + [OneTimeSetUp] + public void OneTimeSetUp() + { + IoCManager.Resolve().Initialize(); + } + [Test] public void TestAlertKey() { @@ -67,11 +76,9 @@ namespace Content.Tests.Shared.Alert var document = yamlStream.Documents[0]; var rootNode = (YamlSequenceNode) document.RootNode; var proto = (YamlMappingNode) rootNode[0]; + var serMan = IoCManager.Resolve(); - var newReagent = new AlertPrototype(); - newReagent.LoadFrom(proto); - - return newReagent; + return serMan.ReadValue(new MappingDataNode(proto)); } } } diff --git a/Content.Tests/Shared/Chemistry/ReagentPrototype_Tests.cs b/Content.Tests/Shared/Chemistry/ReagentPrototype_Tests.cs index b2f1133eff..ef5fc3764c 100644 --- a/Content.Tests/Shared/Chemistry/ReagentPrototype_Tests.cs +++ b/Content.Tests/Shared/Chemistry/ReagentPrototype_Tests.cs @@ -1,7 +1,10 @@ using System.IO; using Content.Shared.Chemistry; using NUnit.Framework; +using Robust.Shared.IoC; using Robust.Shared.Maths; +using Robust.Shared.Serialization.Manager; +using Robust.Shared.Serialization.Markdown; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; @@ -22,8 +25,10 @@ namespace Content.Tests.Shared.Chemistry var proto = (YamlMappingNode)rootNode[0]; var defType = proto.GetNode("type").AsString(); - var newReagent = new ReagentPrototype(); - newReagent.LoadFrom(proto); + var serializationManager = IoCManager.Resolve(); + serializationManager.Initialize(); + + var newReagent = serializationManager.ReadValue(new MappingDataNode(proto)); Assert.That(defType, Is.EqualTo("reagent")); Assert.That(newReagent.ID, Is.EqualTo("chem.H2")); diff --git a/Content.Tests/Shared/Utility/RandomExtensionsTests.cs b/Content.Tests/Shared/Utility/RandomExtensionsTests.cs index 1073799627..6db9a23bbd 100644 --- a/Content.Tests/Shared/Utility/RandomExtensionsTests.cs +++ b/Content.Tests/Shared/Utility/RandomExtensionsTests.cs @@ -1,11 +1,11 @@ using System.IO; -using System.Threading.Tasks; using Content.Shared.Prototypes; using Content.Shared.Utility; using NUnit.Framework; using Robust.Shared.IoC; using Robust.Shared.Prototypes; using Robust.Shared.Random; +using Robust.Shared.Serialization.Manager; namespace Content.Tests.Shared.Utility { @@ -24,6 +24,7 @@ namespace Content.Tests.Shared.Utility [Test] public void RandomDataSetValueTest() { + IoCManager.Resolve().Initialize(); var prototypeManager = IoCManager.Resolve(); prototypeManager.LoadFromStream(new StringReader(Prototypes)); diff --git a/Content.YAMLLinter/Content.YAMLLinter.csproj b/Content.YAMLLinter/Content.YAMLLinter.csproj new file mode 100644 index 0000000000..5ac8a6e866 --- /dev/null +++ b/Content.YAMLLinter/Content.YAMLLinter.csproj @@ -0,0 +1,20 @@ + + + + Exe + net5.0 + ..\bin\Content.YAMLLinter\ + false + + + + + + + + + + + + + diff --git a/Content.YAMLLinter/Program.cs b/Content.YAMLLinter/Program.cs new file mode 100644 index 0000000000..dbb3b9091b --- /dev/null +++ b/Content.YAMLLinter/Program.cs @@ -0,0 +1,107 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Content.IntegrationTests; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.Markdown.Validation; +using Robust.Shared.Timing; +using Robust.Shared.Utility; + +namespace Content.YAMLLinter +{ + internal class Program : ContentIntegrationTest + { + private static int Main(string[] args) + { + return new Program().Run(); + } + + private int Run() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + var errors = RunValidation().Result; + + if (errors.Count == 0) + { + Console.WriteLine($"No errors found in {(int) stopwatch.Elapsed.TotalMilliseconds} ms."); + return 0; + } + + foreach (var (file, errorHashset) in errors) + { + foreach (var errorNode in errorHashset) + { + Console.WriteLine($"({file} | (L:{errorNode.Node.Start.Line}-{errorNode.Node.End.Line} | C:{errorNode.Node.Start.Column}-{errorNode.Node.End.Column}): {errorNode.ErrorReason}"); + } + } + + Console.WriteLine($"{errors.Count} errors found in {(int) stopwatch.Elapsed.TotalMilliseconds} ms."); + return -1; + } + + private async Task>> ValidateClient() + { + var client = StartClient(); + + await client.WaitIdleAsync(); + + var cPrototypeManager = client.ResolveDependency(); + var clientErrors = new Dictionary>(); + + await client.WaitAssertion(() => + { + clientErrors = cPrototypeManager.ValidateDirectory(new ResourcePath("/Prototypes")); + }); + + client.Stop(); + + return clientErrors; + } + + private async Task>> ValidateServer() + { + var server = StartServer(); + + await server.WaitIdleAsync(); + + var sPrototypeManager = server.ResolveDependency(); + var serverErrors = new Dictionary>(); + + await server.WaitAssertion(() => + { + serverErrors = sPrototypeManager.ValidateDirectory(new ResourcePath("/Prototypes")); + }); + + server.Stop(); + + return serverErrors; + } + + public async Task>> RunValidation() + { + var allErrors = new Dictionary>(); + + var tasks = await Task.WhenAll(ValidateClient(), ValidateServer()); + var clientErrors = tasks[0]; + var serverErrors = tasks[1]; + + foreach (var (key, val) in serverErrors) + { + if (clientErrors.TryGetValue(key, out var clientVal)) + { + var newErrors = val.Intersect(clientVal).ToHashSet(); + newErrors.UnionWith(val.Where(n => n.AlwaysRelevant)); + newErrors.UnionWith(clientVal.Where(n => n.AlwaysRelevant)); + if (newErrors.Count == 0) continue; + + allErrors[key] = newErrors; + } + } + + return allErrors; + } + } +} diff --git a/Resources/Prototypes/Actions/actions.yml b/Resources/Prototypes/Actions/actions.yml index badf781f8f..09ad922719 100644 --- a/Resources/Prototypes/Actions/actions.yml +++ b/Resources/Prototypes/Actions/actions.yml @@ -48,7 +48,7 @@ - type: action actionType: DebugInstant - icon: Interface/Alerts/Human/human1.png + icon: Interface/Alerts/human_health.rsi/health1.png name: "[color=red]Debug Instant[/color]" description: "This is a [color=red]debug message[/color]." requires: "Requires blah blah" @@ -60,7 +60,7 @@ - type: action actionType: DebugToggle - icon: Interface/Alerts/Human/human3.png + icon: Interface/Alerts/human_health.rsi/health3.png name: "[color=red]Debug Toggle[/color]" description: "This is a [color=red]debug message[/color]." requires: "Requires blah blah" @@ -73,7 +73,7 @@ - type: action actionType: DebugTargetPoint - icon: Interface/Alerts/Human/human4.png + icon: Interface/Alerts/human_health.rsi/health4.png name: "[color=red]Debug Target Position[/color]" description: "This is a [color=red]debug message[/color]." filters: @@ -83,7 +83,7 @@ - type: action actionType: DebugTargetPointRepeat - icon: Interface/Alerts/Human/human2.png + icon: Interface/Alerts/human_health.rsi/health2.png name: "[color=red]Repeating Debug Target Position[/color]" description: "This is a [color=red]debug message[/color]." filters: @@ -94,7 +94,7 @@ - type: action actionType: DebugTargetEntity - icon: Interface/Alerts/Human/human6.png + icon: Interface/Alerts/human_health.rsi/health6.png name: "[color=red]Debug Target Entity[/color]" description: "This is a [color=red]debug message[/color]." filters: @@ -104,7 +104,7 @@ - type: action actionType: DebugTargetEntityRepeat - icon: Interface/Alerts/Human/human5.png + icon: Interface/Alerts/human_health.rsi/health5.png name: "[color=red]Repeating Debug Target Entity[/color]" description: "This is a [color=red]debug message[/color]." filters: diff --git a/Resources/Prototypes/Actions/item_actions.yml b/Resources/Prototypes/Actions/item_actions.yml index f5ea9a4766..e54e778be1 100644 --- a/Resources/Prototypes/Actions/item_actions.yml +++ b/Resources/Prototypes/Actions/item_actions.yml @@ -31,7 +31,7 @@ - type: itemAction actionType: DebugInstant - icon: Interface/Alerts/Human/human1.png + icon: Interface/Alerts/human_health.rsi/health1.png iconStyle: BigAction name: "[color=red]Debug Item Instant[/color]" description: "This is a [color=red]debug message[/color]." @@ -46,7 +46,7 @@ - type: itemAction actionType: DebugToggle iconStyle: BigItem - icon: Interface/Alerts/Human/human3.png + icon: Interface/Alerts/human_health.rsi/health3.png name: "[color=red]Debug Item Toggle[/color]" description: "This is a [color=red]debug message[/color]." requires: "Requires blah blah" @@ -60,7 +60,7 @@ - type: itemAction actionType: DebugTargetPoint iconStyle: NoItem - icon: Interface/Alerts/Human/human4.png + icon: Interface/Alerts/human_health.rsi/health4.png name: "[color=red]Debug Item Target Position[/color]" description: "This is a [color=red]debug message[/color]." filters: @@ -71,7 +71,7 @@ - type: itemAction actionType: DebugTargetPointRepeat iconStyle: BigAction - icon: Interface/Alerts/Human/human2.png + icon: Interface/Alerts/human_health.rsi/health2.png name: "[color=red]Repeating Debug Item Target Position[/color]" description: "This is a [color=red]debug message[/color]." filters: @@ -83,7 +83,7 @@ - type: itemAction actionType: DebugTargetEntity iconStyle: BigAction - icon: Interface/Alerts/Human/human6.png + icon: Interface/Alerts/human_health.rsi/health6.png name: "[color=red]Debug Item Target Entity[/color]" description: "This is a [color=red]debug message[/color]." filters: @@ -93,7 +93,7 @@ - type: itemAction actionType: DebugTargetEntityRepeat - icon: Interface/Alerts/Human/human5.png + icon: Interface/Alerts/human_health.rsi/health5.png name: "[color=red]Repeating Debug Item Target Entity[/color]" description: "This is a [color=red]debug message[/color]." filters: diff --git a/Resources/Prototypes/Alerts/alerts.yml b/Resources/Prototypes/Alerts/alerts.yml index 25a751d10f..402b232231 100644 --- a/Resources/Prototypes/Alerts/alerts.yml +++ b/Resources/Prototypes/Alerts/alerts.yml @@ -197,36 +197,36 @@ - type: alert alertType: Debug1 - icon: /Textures/Interface/Alerts/Human/human1.png + icon: /Textures/Interface/Alerts/human_health.rsi/health1.png name: Debug1 description: Debug - type: alert alertType: Debug2 - icon: /Textures/Interface/Alerts/Human/human2.png + icon: /Textures/Interface/Alerts/human_health.rsi/health2.png name: Debug2 description: Debug - type: alert alertType: Debug3 - icon: /Textures/Interface/Alerts/Human/human3.png + icon: /Textures/Interface/Alerts/human_health.rsi/health3.png name: Debug3 description: Debug - type: alert alertType: Debug4 - icon: /Textures/Interface/Alerts/Human/human4.png + icon: /Textures/Interface/Alerts/human_health.rsi/health4.png name: Debug4 description: Debug - type: alert alertType: Debug5 - icon: /Textures/Interface/Alerts/Human/human5.png + icon: /Textures/Interface/Alerts/human_health.rsi/health5.png name: Debug5 description: Debug - type: alert alertType: Debug6 - icon: /Textures/Interface/Alerts/Human/human6.png + icon: /Textures/Interface/Alerts/human_health.rsi/health6.png name: Debug6 description: Debug diff --git a/Resources/Prototypes/Body/Mechanisms/basic_human_organs.yml b/Resources/Prototypes/Body/Mechanisms/basic_human_organs.yml index 1b70ce6415..ddb67727f3 100644 --- a/Resources/Prototypes/Body/Mechanisms/basic_human_organs.yml +++ b/Resources/Prototypes/Body/Mechanisms/basic_human_organs.yml @@ -27,7 +27,6 @@ sprite: Mobs/Species/Human/organs.rsi state: brain - type: Mechanism - durability: 10 size: 1 compatibility: Biological behaviors: @@ -45,7 +44,6 @@ sprite: Mobs/Species/Human/organs.rsi state: eyeballs - type: Mechanism - durability: 10 size: 1 compatibility: Biological @@ -60,7 +58,6 @@ sprite: Mobs/Species/Human/organs.rsi state: heart-on - type: Mechanism - durability: 10 size: 1 compatibility: Biological behaviors: @@ -77,7 +74,6 @@ sprite: Mobs/Species/Human/organs.rsi state: lungs - type: Mechanism - durability: 13 size: 1 compatibility: Biological behaviors: @@ -94,7 +90,6 @@ sprite: Mobs/Species/Human/organs.rsi state: stomach - type: Mechanism - durability: 13 size: 1 compatibility: Biological behaviors: @@ -115,7 +110,6 @@ sprite: Mobs/Species/Human/organs.rsi state: liver - type: Mechanism - durability: 15 size: 1 compatibility: Biological behaviors: @@ -136,6 +130,5 @@ sprite: Mobs/Species/Human/organs.rsi state: kidneys - type: Mechanism - durability: 20 size: 1 compatibility: Biological diff --git a/Resources/Prototypes/Body/Mechanisms/basic_tests.yml b/Resources/Prototypes/Body/Mechanisms/basic_tests.yml index 46b41b3119..e0418aa779 100644 --- a/Resources/Prototypes/Body/Mechanisms/basic_tests.yml +++ b/Resources/Prototypes/Body/Mechanisms/basic_tests.yml @@ -7,12 +7,8 @@ - type: Sprite - type: Icon - type: Mechanism - durability: 80 size: 4 compatibility: Universal - implantableParts: - - Arm - - Hand - type: entity id: MechanismHonkModule @@ -23,6 +19,5 @@ - type: Sprite - type: Icon - type: Mechanism - durability: 50 size: 3 compatibility: Universal diff --git a/Resources/Prototypes/Body/Parts/human_parts.yml b/Resources/Prototypes/Body/Parts/human_parts.yml index ff6d7d18fd..8cb8d78ec4 100644 --- a/Resources/Prototypes/Body/Parts/human_parts.yml +++ b/Resources/Prototypes/Body/Parts/human_parts.yml @@ -52,7 +52,7 @@ partType: Head size: 7 compatibility: Biological - isVital: true + vital: true mechanisms: - BrainHuman - EyesHuman diff --git a/Resources/Prototypes/Body/Parts/slime_parts.yml b/Resources/Prototypes/Body/Parts/slime_parts.yml index 2cb3d15601..328bc45cdf 100644 --- a/Resources/Prototypes/Body/Parts/slime_parts.yml +++ b/Resources/Prototypes/Body/Parts/slime_parts.yml @@ -51,7 +51,7 @@ partType: Head size: 7 compatibility: Biological - isVital: true + vital: true mechanisms: - BrainHuman - EyesHuman diff --git a/Resources/Prototypes/Catalog/Fills/Boxes/food.yml b/Resources/Prototypes/Catalog/Fills/Boxes/food.yml index d46e1ec1fd..d25023a859 100644 --- a/Resources/Prototypes/Catalog/Fills/Boxes/food.yml +++ b/Resources/Prototypes/Catalog/Fills/Boxes/food.yml @@ -14,6 +14,5 @@ - type: Item color: "#951710" sprite: Objects/Storage/donkpocket.rsi - state: icon - type: Storage capacity: 30 diff --git a/Resources/Prototypes/Entities/Clothing/OuterClothing/hardsuits.yml b/Resources/Prototypes/Entities/Clothing/OuterClothing/hardsuits.yml index d155d9aced..7334eb7929 100644 --- a/Resources/Prototypes/Entities/Clothing/OuterClothing/hardsuits.yml +++ b/Resources/Prototypes/Entities/Clothing/OuterClothing/hardsuits.yml @@ -22,6 +22,7 @@ sprite: Clothing/OuterClothing/Hardsuits/capspace.rsi - type: Clothing sprite: Clothing/OuterClothing/Hardsuits/capspace.rsi + - type: PressureProtection highPressureMultiplier: 0.5 lowPressureMultiplier: 100 diff --git a/Resources/Prototypes/Entities/Constructible/Furniture/bookshelf.yml b/Resources/Prototypes/Entities/Constructible/Furniture/bookshelf.yml index 658e652990..b45865c372 100644 --- a/Resources/Prototypes/Entities/Constructible/Furniture/bookshelf.yml +++ b/Resources/Prototypes/Entities/Constructible/Furniture/bookshelf.yml @@ -36,10 +36,7 @@ max: 1 - !type:DoActsBehavior acts: ["Destruction"] - - type: Occluder - sizeX: 32 - sizeY: 32 - type: entity id: Bookshelf0 diff --git a/Resources/Prototypes/Entities/Constructible/Furniture/potted_plants.yml b/Resources/Prototypes/Entities/Constructible/Furniture/potted_plants.yml index 8272e0e572..701bae83c5 100644 --- a/Resources/Prototypes/Entities/Constructible/Furniture/potted_plants.yml +++ b/Resources/Prototypes/Entities/Constructible/Furniture/potted_plants.yml @@ -74,4 +74,3 @@ - type: PointLight radius: 2 color: "#2cb2e8" - power: 0.25 diff --git a/Resources/Prototypes/Entities/Constructible/Furniture/storage.yml b/Resources/Prototypes/Entities/Constructible/Furniture/storage.yml index 58a8b3aa35..24a72a3842 100644 --- a/Resources/Prototypes/Entities/Constructible/Furniture/storage.yml +++ b/Resources/Prototypes/Entities/Constructible/Furniture/storage.yml @@ -1,7 +1,7 @@ - type: entity id: Rack name: rack - desription: "A rack for storing things on." + description: "A rack for storing things on." placement: mode: SnapgridCenter components: diff --git a/Resources/Prototypes/Entities/Constructible/Piping/gascanisters.yml b/Resources/Prototypes/Entities/Constructible/Piping/gascanisters.yml index fbb0c2e5c3..cb908dc297 100644 --- a/Resources/Prototypes/Entities/Constructible/Piping/gascanisters.yml +++ b/Resources/Prototypes/Entities/Constructible/Piping/gascanisters.yml @@ -39,10 +39,11 @@ visuals: - type: GasCanisterVisualizer stateConnected: can-connector - stateO0: can-o0 - stateO1: can-o1 - stateO2: can-o2 - stateO3: can-o3 + pressureStates: + - can-o0 + - can-o1 + - can-o2 + - can-o3 - type: UserInterface interfaces: - key: enum.GasCanisterUiKey.Key diff --git a/Resources/Prototypes/Entities/Constructible/Power/cargo_console.yml b/Resources/Prototypes/Entities/Constructible/Power/cargo_console.yml index 29ee9a7827..1e9873bde9 100644 --- a/Resources/Prototypes/Entities/Constructible/Power/cargo_console.yml +++ b/Resources/Prototypes/Entities/Constructible/Power/cargo_console.yml @@ -12,7 +12,6 @@ - type: CargoConsole - type: CargoOrderDatabase - type: GalacticMarket - static: true products: - cargo.emergencyexplosive - cargo.emergencyfire diff --git a/Resources/Prototypes/Entities/Constructible/Power/wires.yml b/Resources/Prototypes/Entities/Constructible/Power/wires.yml index c348c4692a..32722b2ad0 100644 --- a/Resources/Prototypes/Entities/Constructible/Power/wires.yml +++ b/Resources/Prototypes/Entities/Constructible/Power/wires.yml @@ -33,7 +33,7 @@ parent: WireBase id: HVWire name: HV Wire - decription: "An orange high voltage power cable." + description: "An orange high voltage power cable." components: - type: Sprite sprite: Constructible/Power/Wires/hv_cable.rsi diff --git a/Resources/Prototypes/Entities/Constructible/Specific/Engines/PA/base.yml b/Resources/Prototypes/Entities/Constructible/Specific/Engines/PA/base.yml index d9278985f6..e9abf244e6 100644 --- a/Resources/Prototypes/Entities/Constructible/Specific/Engines/PA/base.yml +++ b/Resources/Prototypes/Entities/Constructible/Specific/Engines/PA/base.yml @@ -18,7 +18,6 @@ - Impassable - MobImpassable - VaultImpassable - IsScrapingFloor: true - type: SnapGrid offset: Center - type: Pullable diff --git a/Resources/Prototypes/Entities/Constructible/Specific/Engines/PA/particles.yml b/Resources/Prototypes/Entities/Constructible/Specific/Engines/PA/particles.yml index cfff7be603..06da36833b 100644 --- a/Resources/Prototypes/Entities/Constructible/Specific/Engines/PA/particles.yml +++ b/Resources/Prototypes/Entities/Constructible/Specific/Engines/PA/particles.yml @@ -5,9 +5,10 @@ parent: BulletBase components: - type: Sprite - sprite: Constructible/Specific/Engines/PA/particle.rsi - state: particle0 - shader: unshaded + layers: + - sprite: Constructible/Specific/Engines/PA/particle.rsi + state: particle0 + shader: unshaded - type: Projectile delete_on_collide: false soundHit: /Audio/Weapons/Guns/Hits/bullet_hit.ogg diff --git a/Resources/Prototypes/Entities/Constructible/Specific/gravity_generator.yml b/Resources/Prototypes/Entities/Constructible/Specific/gravity_generator.yml index ab834372f2..aed6a268f9 100644 --- a/Resources/Prototypes/Entities/Constructible/Specific/gravity_generator.yml +++ b/Resources/Prototypes/Entities/Constructible/Specific/gravity_generator.yml @@ -49,10 +49,11 @@ - type: Appearance visuals: - type: GravityGeneratorVisualizer - broken: "broken" - unpowered: "off" - off: "off" - on: "on" + spritemap: + broken: "broken" + unpowered: "off" + off: "off" + on: "on" placement: mode: AlignTileAny diff --git a/Resources/Prototypes/Entities/Effects/chemistry_effects.yml b/Resources/Prototypes/Entities/Effects/chemistry_effects.yml index d45f137062..0c242f2b3c 100644 --- a/Resources/Prototypes/Entities/Effects/chemistry_effects.yml +++ b/Resources/Prototypes/Entities/Effects/chemistry_effects.yml @@ -11,8 +11,6 @@ visuals: - type: SmokeVisualizer - type: Occluder - sizeX: 32 - sizeY: 32 - type: SnapGrid offset: Center - type: SmokeSolutionAreaEffect diff --git a/Resources/Prototypes/Entities/Mobs/NPCs/dummy_npcs.yml b/Resources/Prototypes/Entities/Mobs/NPCs/dummy_npcs.yml index 9c34ca0192..8793dce4e3 100644 --- a/Resources/Prototypes/Entities/Mobs/NPCs/dummy_npcs.yml +++ b/Resources/Prototypes/Entities/Mobs/NPCs/dummy_npcs.yml @@ -4,7 +4,6 @@ parent: BaseHumanMob_Content id: HumanMob_PathDummy description: A miserable pile of secrets. - drawdepth: Mobs suffix: AI components: - type: UtilityAI diff --git a/Resources/Prototypes/Entities/Mobs/NPCs/simplemob.yml b/Resources/Prototypes/Entities/Mobs/NPCs/simplemob.yml index 88422cd83e..4f0669d52e 100644 --- a/Resources/Prototypes/Entities/Mobs/NPCs/simplemob.yml +++ b/Resources/Prototypes/Entities/Mobs/NPCs/simplemob.yml @@ -2,7 +2,6 @@ save: false abstract: true id: SimpleMobBase - drawdepth: Mobs suffix: AI components: - type: Tag diff --git a/Resources/Prototypes/Entities/Mobs/Player/human.yml b/Resources/Prototypes/Entities/Mobs/Player/human.yml index 6f9e3adc25..1395b32226 100644 --- a/Resources/Prototypes/Entities/Mobs/Player/human.yml +++ b/Resources/Prototypes/Entities/Mobs/Player/human.yml @@ -4,7 +4,6 @@ parent: BaseHumanMob_Content id: HumanMob_Content description: A miserable pile of secrets. - drawdepth: Mobs components: - type: Mind showExamineInfo: true diff --git a/Resources/Prototypes/Entities/Mobs/Player/slime.yml b/Resources/Prototypes/Entities/Mobs/Player/slime.yml index 3b5a2615c1..88eb8129d1 100644 --- a/Resources/Prototypes/Entities/Mobs/Player/slime.yml +++ b/Resources/Prototypes/Entities/Mobs/Player/slime.yml @@ -4,7 +4,6 @@ parent: BaseSlimeMob_Content id: SlimeMob_Content description: A miserable pile of slime - drawdepth: Mobs components: - type: Mind showExamineInfo: true diff --git a/Resources/Prototypes/Entities/Mobs/Species/human.yml b/Resources/Prototypes/Entities/Mobs/Species/human.yml index b012d0ec83..595535889e 100644 --- a/Resources/Prototypes/Entities/Mobs/Species/human.yml +++ b/Resources/Prototypes/Entities/Mobs/Species/human.yml @@ -4,7 +4,6 @@ name: Urist McHands id: BaseHumanMob_Content description: A miserable pile of secrets. - drawdepth: Mobs abstract: true components: - type: Tag diff --git a/Resources/Prototypes/Entities/Mobs/Species/slime.yml b/Resources/Prototypes/Entities/Mobs/Species/slime.yml index ea18115d0d..fe10e531fc 100644 --- a/Resources/Prototypes/Entities/Mobs/Species/slime.yml +++ b/Resources/Prototypes/Entities/Mobs/Species/slime.yml @@ -5,7 +5,6 @@ name: Slime Person id: BaseSlimeMob_Content description: A miserable pile of slime. - drawdepth: Mobs abstract: true components: - type: Tag diff --git a/Resources/Prototypes/Entities/Objects/Consumable/Smokeables/Cigarettes/rolling_paper.yml b/Resources/Prototypes/Entities/Objects/Consumable/Smokeables/Cigarettes/rolling_paper.yml index f83cbb3b68..9a55077392 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/Smokeables/Cigarettes/rolling_paper.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/Smokeables/Cigarettes/rolling_paper.yml @@ -13,7 +13,6 @@ state: cigpapers - type: Item sprite: Objects/Consumable/Smokeables/Cigarettes/paper.rsi - state: cigpapers - type: entity id: PaperRolling @@ -30,7 +29,6 @@ state: cigpaper - type: Item sprite: Objects/Consumable/Smokeables/Cigarettes/paper.rsi - state: cigpaper - type: entity id: CigaretteFilter @@ -47,4 +45,3 @@ state: cigfilter - type: Item sprite: Objects/Consumable/Smokeables/Cigarettes/paper.rsi - state: cigfilter diff --git a/Resources/Prototypes/Entities/Objects/Consumable/drinks.yml b/Resources/Prototypes/Entities/Objects/Consumable/drinks.yml index 0d8bbde86e..c4838c0846 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/drinks.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/drinks.yml @@ -56,7 +56,6 @@ - type: Sprite sprite: Objects/Consumable/Drinks/glass_clear.rsi - type: SolutionContainer - fillingState: glass maxVol: 50 - type: SolutionTransfer transferAmount: 5 diff --git a/Resources/Prototypes/Entities/Objects/Consumable/food.yml b/Resources/Prototypes/Entities/Objects/Consumable/food.yml index 9c39045902..847ab7434a 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/food.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/food.yml @@ -53,7 +53,6 @@ reagents: - ReagentId: chem.Nutriment Quantity: 4 - trash: TrashSnackBowl - type: Sprite sprite: Objects/Consumable/Food/aesirsalad.rsi @@ -776,7 +775,7 @@ - type: Sprite sprite: Objects/Consumable/Food/donut2.rsi - type: Item - sprite: Objects/Consumable/Food/donut2.rsi.rsi + sprite: Objects/Consumable/Food/donut2.rsi - type: entity parent: FoodBase @@ -792,7 +791,7 @@ - type: Sprite sprite: Objects/Consumable/Food/egg-blue.rsi - type: Item - sprite: Objects/Consumable/Food/egg-blue.rsi.rsi + sprite: Objects/Consumable/Food/egg-blue.rsi - type: entity parent: FoodBase @@ -808,7 +807,7 @@ - type: Sprite sprite: Objects/Consumable/Food/egg-green.rsi - type: Item - sprite: Objects/Consumable/Food/egg-green.rsi.rsi + sprite: Objects/Consumable/Food/egg-green.rsi - type: entity parent: FoodBase @@ -824,7 +823,7 @@ - type: Sprite sprite: Objects/Consumable/Food/egg-mime.rsi - type: Item - sprite: Objects/Consumable/Food/egg-mime.rsi.rsi + sprite: Objects/Consumable/Food/egg-mime.rsi - type: entity parent: FoodBase @@ -840,7 +839,7 @@ - type: Sprite sprite: Objects/Consumable/Food/egg-orange.rsi - type: Item - sprite: Objects/Consumable/Food/egg-orange.rsi.rsi + sprite: Objects/Consumable/Food/egg-orange.rsi - type: entity parent: FoodBase @@ -856,7 +855,7 @@ - type: Sprite sprite: Objects/Consumable/Food/egg-purple.rsi - type: Item - sprite: Objects/Consumable/Food/egg-purple.rsi.rsi + sprite: Objects/Consumable/Food/egg-purple.rsi - type: entity parent: FoodBase @@ -872,7 +871,7 @@ - type: Sprite sprite: Objects/Consumable/Food/egg-rainbow.rsi - type: Item - sprite: Objects/Consumable/Food/egg-rainbow.rsi.rsi + sprite: Objects/Consumable/Food/egg-rainbow.rsi - type: entity parent: FoodBase @@ -888,8 +887,7 @@ - type: Sprite sprite: Objects/Consumable/Food/egg-red.rsi - type: Item - sprite: Objects/Consumable/Food/egg-red.rsi.rsi - + sprite: Objects/Consumable/Food/egg-red.rsi - type: entity parent: FoodBase @@ -1941,7 +1939,6 @@ - type: Food trash: TrashPopcorn - type: SolutionContainer - transfer_amount: 1 contents: reagents: - ReagentId: chem.Nutriment @@ -2173,7 +2170,6 @@ reagents: - ReagentId: chem.Nutriment Quantity: 4 - trash: TrashSOSJerky - type: Sprite sprite: Objects/Consumable/Food/sosjerky.rsi - type: Item diff --git a/Resources/Prototypes/Entities/Objects/Fun/instruments.yml b/Resources/Prototypes/Entities/Objects/Fun/instruments.yml index 30f4f73eaa..cde4c3474d 100644 --- a/Resources/Prototypes/Entities/Objects/Fun/instruments.yml +++ b/Resources/Prototypes/Entities/Objects/Fun/instruments.yml @@ -12,7 +12,7 @@ - key: enum.InstrumentUiKey.Key type: InstrumentBoundUserInterface - type: Item - Size: 24 + size: 24 - type: entity name: synthesizer diff --git a/Resources/Prototypes/Entities/Objects/Specific/chemistry.yml b/Resources/Prototypes/Entities/Objects/Specific/chemistry.yml index 3a2e69c3af..3125e36cd0 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/chemistry.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/chemistry.yml @@ -15,7 +15,6 @@ sprite: Objects/Specific/Chemistry/beakers.rsi HeldPrefix: beaker - type: SolutionContainer - fillingState: beaker maxVol: 50 caps: OpenContainer, FitsInDispenser # can add and remove solutions and fits in the chemmaster. - type: SolutionTransfer @@ -35,7 +34,6 @@ - type: Item HeldPrefix: beaker - type: SolutionContainer - fillingState: beakerlarge maxVol: 100 caps: OpenContainer, FitsInDispenser - type: SolutionTransfer @@ -54,8 +52,6 @@ sprite: Objects/Specific/Chemistry/dropper.rsi state: dropper - type: SolutionContainer - fillingState: dropper - fillingSteps: 2 maxVol: 5 - type: SolutionTransfer transferAmount: 5.0 @@ -71,8 +67,6 @@ sprite: Objects/Specific/Chemistry/syringe.rsi state: 0 - type: SolutionContainer - fillingState: syringe - fillingSteps: 5 maxVol: 15 - type: Injector injectOnly: false diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Shotgun/cartridges.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Shotgun/cartridges.yml index 723416c80c..4252beb65c 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Shotgun/cartridges.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Shotgun/cartridges.yml @@ -7,6 +7,7 @@ - type: Ammo caliber: Shotgun ammoSpread: 40 + projectilesFired: 6 soundCollectionEject: ShellEject - type: Sprite netsync: false @@ -53,7 +54,6 @@ sprite: Objects/Weapons/Guns/Ammunition/Casings/shotgun_shell.rsi - type: Ammo projectile: PelletShotgun - projectilesFired: 6 - type: entity id: ShellShotgunFlash @@ -64,7 +64,6 @@ sprite: Objects/Weapons/Guns/Ammunition/Casings/shotgun_shell_flash.rsi - type: Ammo projectile: PelletShotgunFlash - projectilesFired: 6 - type: entity id: ShellShotgunIncendiary @@ -75,7 +74,6 @@ sprite: Objects/Weapons/Guns/Ammunition/Casings/shotgun_shell_incendiary.rsi - type: Ammo projectile: PelletShotgun - projectilesFired: 6 - type: entity id: ShellShotgunPractice @@ -86,7 +84,6 @@ sprite: Objects/Weapons/Guns/Ammunition/Casings/shotgun_shell_practice.rsi - type: Ammo projectile: PelletShotgun - projectilesFired: 6 - type: entity id: ShellTranquilizer diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Toy/boxes.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Toy/boxes.yml index 2a340a32a2..5d3f26bdbd 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Toy/boxes.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Toy/boxes.yml @@ -22,7 +22,7 @@ - type: Sprite sprite: Objects/Fun/toys.rsi state: foambox - + - type: entity id: BoxCartridgeCap name: "cap gun cartridge box" @@ -32,5 +32,5 @@ capacity: 20 fillPrototype: CartridgeCap - type: Sprite - sprite: Objects\Storage\boxes.rsi + sprite: Objects/Storage/boxes.rsi state: box diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Toy/cartridges.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Toy/cartridges.yml index c6be701c77..8db47f1145 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Toy/cartridges.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Toy/cartridges.yml @@ -9,7 +9,7 @@ - type: Sprite netsync: false directional: true - sprite: Objects\Weapons\Guns\Ammunition\Casings\ammo_casing.rsi + sprite: Objects/Weapons/Guns/Ammunition/Casings/ammo_casing.rsi layers: - state: base map: ["enum.AmmoVisualLayers.Base"] @@ -21,4 +21,4 @@ parent: CartridgeCapBase components: - type: Ammo - projectile: BulletCap \ No newline at end of file + projectile: BulletCap diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Battery/battery_guns.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Battery/battery_guns.yml index 3652a0d0ee..5790c3141a 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Battery/battery_guns.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Battery/battery_guns.yml @@ -107,7 +107,7 @@ angleDecay: 45 powerCellPrototype: PowerCellSmallSuper powerCellRemovable: true - base_fire_cost: 600 + fireCost: 600 ammoPrototype: XrayLaser soundGunshot: /Audio/Weapons/Guns/Gunshots/laser3.ogg - type: Appearance diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/LMGs/lmgs.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/LMGs/lmgs.yml index fdf5f67b87..bb216bbad4 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/LMGs/lmgs.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/LMGs/lmgs.yml @@ -11,7 +11,6 @@ state: icon - type: Item size: 24 - state: icon - type: MagazineBarrel currentSelector: Automatic allSelectors: diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Launchers/launchers.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Launchers/launchers.yml index b8cd8d9c9d..c0cda2dbbd 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Launchers/launchers.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Launchers/launchers.yml @@ -9,7 +9,6 @@ netsync: false - type: Item size: 24 - state: icon - type: entity name: china lake diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Pistols/pistols.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Pistols/pistols.yml index 2494cb0f6c..401ce2a41d 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Pistols/pistols.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Pistols/pistols.yml @@ -18,7 +18,6 @@ state: icon - type: Item size: 12 - state: icon - type: MagazineBarrel caliber: Pistol magazineTypes: @@ -155,7 +154,6 @@ - Single magazineTypes: - Pistol - capacity: 1 fireRate: 8 minAngle: 10 maxAngle: 60 diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Projectiles/projectiles.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Projectiles/projectiles.yml index bd3d175dea..7b4a09a261 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Projectiles/projectiles.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Projectiles/projectiles.yml @@ -13,7 +13,6 @@ state: bullet - type: Physics anchored: false - edgeslide: false hard: false shapes: - !type:PhysShapeAabb @@ -98,7 +97,7 @@ shader: unshaded - type: Physics anchored: false - edgeslide: false + hard: false shapes: - !type:PhysShapeAabb @@ -119,7 +118,7 @@ state: frag - type: ExplosiveProjectile - type: Projectile - deleteOnCollide: false + delete_on_collide: false - type: Explosive devastationRange: 1 heavyImpactRange: 2 @@ -141,7 +140,7 @@ sprite: Objects/Weapons/Guns/Projectiles/grenade.rsi state: grenade - type: Projectile - deleteOnCollide: false + delete_on_collide: false soundHit: /Audio/Effects/gen_hit.ogg - type: StunnableProjectile paralyzeAmount: 8 @@ -158,7 +157,7 @@ state: grenade - type: ExplosiveProjectile - type: Projectile - deleteOnCollide: false + delete_on_collide: false - type: Explosive devastationRange: 1 heavyImpactRange: 2 @@ -176,7 +175,7 @@ sprite: Objects/Weapons/Guns/Projectiles/grenade.rsi state: grenade - type: Projectile - deleteOnCollide: false + delete_on_collide: false soundHit: /Audio/Effects/flash_bang.ogg - type: FlashProjectile range: 7 @@ -194,7 +193,7 @@ state: grenade - type: ExplosiveProjectile - type: Projectile - deleteOnCollide: false + delete_on_collide: false - type: Explosive devastationRange: 0 heavyImpactRange: 1 @@ -212,7 +211,7 @@ sprite: Objects/Fun/toys.rsi state: foamdart - type: Projectile - deleteOnCollide: true + delete_on_collide: true soundHit: /Audio/Guns/Hits/snap.ogg damages: Blunt: 2 @@ -228,6 +227,6 @@ sprite: Objects/Fun/toys.rsi state: capbullet - type: Projectile - deleteOnCollide: true + delete_on_collide: true damages: Piercing: 0 diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml index 161e87fa22..bab0492303 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml @@ -7,8 +7,6 @@ components: - type: Sprite netsync: false - - type: Icon - state: icon - type: Item size: 24 state: icon diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/SMGs/smgs.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/SMGs/smgs.yml index c150798c25..88a8167472 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/SMGs/smgs.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/SMGs/smgs.yml @@ -11,7 +11,6 @@ state: icon - type: Item size: 24 - state: icon - type: MagazineBarrel currentSelector: Automatic allSelectors: diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Shotguns/shotguns.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Shotguns/shotguns.yml index 9e43bdc4a0..aa7fd8de1e 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Shotguns/shotguns.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Shotguns/shotguns.yml @@ -92,7 +92,6 @@ - type: Item size: 24 sprite: Objects/Weapons/Guns/Shotguns/db_shotgun.rsi - state: icon - type: RangedWeapon - type: BoltActionBarrel caliber: Shotgun @@ -110,8 +109,8 @@ soundGunshot: /Audio/Weapons/Guns/Gunshots/shotgun.ogg soundEmpty: /Audio/Weapons/Guns/Empty/empty.ogg soundInsert: /Audio/Weapons/Guns/MagIn/shotgun_insert.ogg - sound_bolt_open: /Audio/Weapons/Guns/Cock/shotgun_open.ogg - sound_bolt_closed: /Audio/Weapons/Guns/Cock/shotgun_close.ogg + soundBoltOpen: /Audio/Weapons/Guns/Cock/shotgun_open.ogg + soundBoltClosed: /Audio/Weapons/Guns/Cock/shotgun_close.ogg - type: Appearance visuals: - type: BarrelBoltVisualizer @@ -216,7 +215,6 @@ - type: Item size: 24 sprite: Objects/Weapons/Guns/Shotguns/sawn.rsi - state: icon - type: RangedWeapon - type: BoltActionBarrel caliber: Shotgun diff --git a/Resources/Prototypes/Reagents/Materials/glass.yml b/Resources/Prototypes/Reagents/Materials/glass.yml index 9a09fc1a73..32f34622db 100644 --- a/Resources/Prototypes/Reagents/Materials/glass.yml +++ b/Resources/Prototypes/Reagents/Materials/glass.yml @@ -29,7 +29,7 @@ - type: material id: rpglass name: reinforced plasma glass - icon: Objects/Materials/Sheets/glass.rsi/prglass.png + icon: Objects/Materials/Sheets/glass.rsi/rpglass.png parent: GlassMaterialBase - type: material diff --git a/Resources/Prototypes/Reagents/Materials/materials.yml b/Resources/Prototypes/Reagents/Materials/materials.yml index 5bcc49178a..7ad318ed04 100644 --- a/Resources/Prototypes/Reagents/Materials/materials.yml +++ b/Resources/Prototypes/Reagents/Materials/materials.yml @@ -35,7 +35,7 @@ - type: material id: wood name: wood - icon: Objects/Materials/materials.rsi/wood_plank.png + icon: Objects/Materials/materials.rsi/wood.png density: 6000 electricResistivity: 1.0e+13 thermalConductivity: 1.5 diff --git a/Resources/Prototypes/Reagents/Materials/metals.yml b/Resources/Prototypes/Reagents/Materials/metals.yml index e1bdfc3e99..6c5426129b 100644 --- a/Resources/Prototypes/Reagents/Materials/metals.yml +++ b/Resources/Prototypes/Reagents/Materials/metals.yml @@ -14,19 +14,19 @@ - type: material id: adamantine name: adamantine - icon: Objects/Materials/Ingots/adamantine.png + icon: Objects/Materials/ingots.rsi/adamantine.png parent: MetalMaterialBase - type: material id: copper name: copper - icon: Objects/Materials/Ingots/copper.png + icon: Objects/Materials/ingots.rsi/copper.png parent: MetalMaterialBase - type: material id: gold name: gold - icon: Objects/Materials/Ingots/gold.png + icon: Objects/Materials/ingots.rsi/gold.png density: 10000 electricResistivity: 8.0e-9 thermalConductivity: 30 @@ -35,19 +35,19 @@ - type: material id: hydrogen name: hydrogen - icon: Objects/Materials/Ingots/hydrogen.png + icon: Objects/Materials/ingots.rsi/hydrogen.png parent: MetalMaterialBase - type: material id: iron name: iron - icon: Objects/Materials/Ingots/iron.png + icon: Objects/Materials/ingots.rsi/iron.png parent: MetalMaterialBase - type: material id: silver name: silver - icon: Objects/Materials/Ingots/silver.png + icon: Objects/Materials/ingots.rsi/silver.png parent: MetalMaterialBase - type: material diff --git a/Resources/Prototypes/Reagents/chemicals.yml b/Resources/Prototypes/Reagents/chemicals.yml index b742d8ecfb..56b07fe3b1 100644 --- a/Resources/Prototypes/Reagents/chemicals.yml +++ b/Resources/Prototypes/Reagents/chemicals.yml @@ -130,7 +130,7 @@ id: chem.FluorosulfuricAcid name: fluorosulfuric acid desc: An extremely corrosive chemical substance. - physicalDecs: strong-smelling + physicalDesc: strong-smelling color: "#5050ff" boilingPoint: 165 meltingPoint: -87 diff --git a/Resources/Prototypes/Recipes/Construction/Graphs/low_wall.yml b/Resources/Prototypes/Recipes/Construction/Graphs/low_wall.yml index 3926d23f98..a6a5aefb1c 100644 --- a/Resources/Prototypes/Recipes/Construction/Graphs/low_wall.yml +++ b/Resources/Prototypes/Recipes/Construction/Graphs/low_wall.yml @@ -3,10 +3,6 @@ start: start graph: - node: start - conditions: - - !type:ComponentInTile - value: false - component: Window actions: - !type:SpawnPrototype prototype: SheetSteel1 @@ -14,6 +10,10 @@ - !type:DeleteEntity { } edges: - to: lowWall + conditions: + - !type:ComponentInTile + value: false + component: Window steps: - material: Steel amount: 3 diff --git a/Resources/Prototypes/Recipes/Lathes/sheet.yml b/Resources/Prototypes/Recipes/Lathes/sheet.yml index 7de60af797..b54f04d04c 100644 --- a/Resources/Prototypes/Recipes/Lathes/sheet.yml +++ b/Resources/Prototypes/Recipes/Lathes/sheet.yml @@ -1,8 +1,8 @@ - type: latheRecipe id: SheetSteel icon: - sprite: Objects/Materials/sheets.rsi - state: metal + sprite: Objects/Materials/Sheets/metal.rsi + state: steel result: SheetSteel1 completetime: 500 materials: @@ -11,7 +11,7 @@ - type: latheRecipe id: GlassStack icon: - sprite: Objects/Materials/sheets.rsi + sprite: Objects/Materials/Sheets/glass.rsi state: glass result: SheetGlass1 completetime: 500 diff --git a/Resources/Prototypes/Recipes/Lathes/tools.yml b/Resources/Prototypes/Recipes/Lathes/tools.yml index dce6ba041f..0be5d9d6ed 100644 --- a/Resources/Prototypes/Recipes/Lathes/tools.yml +++ b/Resources/Prototypes/Recipes/Lathes/tools.yml @@ -37,7 +37,7 @@ - type: latheRecipe id: CableStack name: cable coil - icon: /Textures/Objects/Tools/cables.rsi/coil-30.png + icon: /Textures/Objects/Tools/cable-coils.rsi/coil-30.png result: ApcExtensionCableStack1 completetime: 500 materials: diff --git a/Resources/Prototypes/Roles/Jobs/Command/head_of_personnel.yml b/Resources/Prototypes/Roles/Jobs/Command/head_of_personnel.yml index 70dc494506..48104883eb 100644 --- a/Resources/Prototypes/Roles/Jobs/Command/head_of_personnel.yml +++ b/Resources/Prototypes/Roles/Jobs/Command/head_of_personnel.yml @@ -1,7 +1,6 @@ - type: job id: HeadOfPersonnel name: "head of personnel" - head: true positions: 1 startingGear: HoPGear departments: diff --git a/Resources/Prototypes/Stacks/Materials/materials.yml b/Resources/Prototypes/Stacks/Materials/materials.yml index adbe69a432..3aac2aadfd 100644 --- a/Resources/Prototypes/Stacks/Materials/materials.yml +++ b/Resources/Prototypes/Stacks/Materials/materials.yml @@ -1,7 +1,7 @@ - type: stack id: Banananium name: banananium - icon: /Textures/Objects/Materials/materials.rsi/banananium.png + icon: /Textures/Objects/Materials/materials.rsi/bananium.png spawn: MaterialBanananium1 - type: stack diff --git a/Resources/Prototypes/Stacks/power_stacks.yml b/Resources/Prototypes/Stacks/power_stacks.yml index 9caa19748c..b72177af1a 100644 --- a/Resources/Prototypes/Stacks/power_stacks.yml +++ b/Resources/Prototypes/Stacks/power_stacks.yml @@ -1,7 +1,7 @@ - type: stack id: Cable name: cable - icon: "/Textures/Objects/Tools/cables.rsi/coil-30.png" + icon: "/Textures/Objects/Tools/cable-coils.rsi/coil-30.png" spawn: ApcExtensionCableStack1 - type: stack diff --git a/SpaceStation14.sln b/SpaceStation14.sln index 00ce147df8..aa4fa420a9 100644 --- a/SpaceStation14.sln +++ b/SpaceStation14.sln @@ -93,6 +93,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Content.Tools", "Content.To EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Robust.Analyzers", "RobustToolbox\Robust.Analyzers\Robust.Analyzers.csproj", "{88B0FC0F-7209-40E2-AF16-EB90AF727C5B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Content.YAMLLinter", "Content.YAMLLinter\Content.YAMLLinter.csproj", "{A59E2FCC-93CF-4886-8EA7-94F021A7475D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -205,6 +207,10 @@ Global {88B0FC0F-7209-40E2-AF16-EB90AF727C5B}.Debug|Any CPU.Build.0 = Debug|Any CPU {88B0FC0F-7209-40E2-AF16-EB90AF727C5B}.Release|Any CPU.ActiveCfg = Release|Any CPU {88B0FC0F-7209-40E2-AF16-EB90AF727C5B}.Release|Any CPU.Build.0 = Release|Any CPU + {A59E2FCC-93CF-4886-8EA7-94F021A7475D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A59E2FCC-93CF-4886-8EA7-94F021A7475D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A59E2FCC-93CF-4886-8EA7-94F021A7475D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A59E2FCC-93CF-4886-8EA7-94F021A7475D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE