I have always wanted to make somehing relaxed and open source, I think this is it. All of your favourite mechanics in one place.

To begin I will be working on the power system, roughly every month (somethimes more or less) I will be working on something new, we don't want perfaction here, but we want modularity and possibility.

Feel free to look at the github repository and steal **Cough** **Cough** borrow, my code for use in your own project, and even expand upon it and make a contribution to the project.

Also if you want to support my work a link to all donation links are in the github repository, and on the S&Box game page.
You are probably wondering why PowerSpace, well all of the code is seperated into namespaces, the power system is under the Harmonie.PowerSpace namespace.

To use it just as any other namespace include this snippet at the top of your file:
using Harmonie.PowerSpace;
While creating the power system I needed a way to interact with different objects, the PlayerSpace will contain everything the player needs to interact with objects.

Hands This allows the player to look at an object and pick it up with left click, and freeze objects with right click, heavely inspired by gmod's physgun, but not destracting in any way. The objects you can pick up must hava the "solid" tag.

PlayerLookOutline When you look at an object it has an outline, that's about it. Add the "highlight" tag to your object, and a Hightlight outline component... voila, it just works! (as long as your camera has a highlight component too)
At the heart of the power system are four core components: batteries, devices, plugs and female plugs. Each plays a distinct role in simulating a modular, interactive electrical network.

Battery componetns act as energy sources, storing charge and providing power to connected devices. Each battery tracks its current charge, voltage, and can simulate both charging and discharging. The battery’s OnUpdate method manages the flow of energy, iterating through all connected plugs and updating the charge based on the power consumption of attached devices.

Devices are anything that consumes (or sometimes generates) power—like lamps or generators. Every device inherits from a common DeviceBase class, which exposes properties like IsActive, IsPowered, and PowerConsumption. Devices react to changes in their power state via the OnPowerChange() method, allowing for custom behaviors (such as turning on/off a light or playing a sound) when power is toggled.

Plugs serve as the physical connectors between batteries and devices. The FemalePlugDetector component handles plug-in and unplug events, manages references to connected batteries or devices, and ensures that only valid connections are made (e.g., you can’t plug a battery into another battery). When a plug is inserted, the system updates all relevant references and triggers the appropriate state changes in the battery, device, and the plug(s). The Plug component acts as a middle man between the devices and batteries to enable them to be plugged in.

This modular approach makes it easy to expand the system with new device types or power sources, and provides a solid foundation for simulating realistic electrical interactions in-game.
trophy 285
Aug 2022 6 posts
Harmonie's Lab v0.1 - Power & Player ⚡🧑‍🦯‍➡️ : harmonie/harmonies-lab/news/power-36d1730b
trophy 13363
Sep 2022 77 posts
Very very very very very cool.
trophy 285
Aug 2022 6 posts
Very very very very very cool.

Thanks tytimp4_
people
Log in to reply
You can't reply if you're not logged in. That would be crazy.