cmooref17 / ReservedItemSlotMods

https://thunderstore.io/c/lethal-company/p/FlipMods/ReservedItemSlotCore/
MIT License
1 stars 0 forks source link

[Request/Suggestion] Add comments to the code for better documentation #25

Open CatsArmy opened 3 months ago

CatsArmy commented 3 months ago

its pretty self explanatory I mean yeah if you never used the alright -ish c# /// type of comments with the of comments the here is a quick little ms learn if u need it(all though I don't think you will need it if you will add this): https://learn.microsoft.com/en-us/visualstudio/ide/reference/generate-xml-documentation-comments?view=vs-2022

my reasoning is that stuff like:

internal static List<ReservedItemSlotData>currentlyToggledItemSlots;

isn't that clear to understand. I mean what does currently toggled even mean in this context toggled as in unlocked active you see where I'm coming from I hope there's lots of these unclear naming of variables that makes it hard for me personally and I would assume for others with reading understanding and writing more code with your API.

don't get me wrong I love the mods you make the emotes and this one are great but I'm trying to just do a quick iteration on all slots locked or unlocked and have not been able to do so at the moment as Ive had trouble with understanding certain variables mostly lists and functions.

cmooref17 commented 3 months ago

The main parts of the API were originally in the ReservedItemSlotData class, and most of those functions have those same comments you're referring to. I've been trying to build this mod and API with the idea of encapsulation and polymorphism where I only give public access to the function and properties that devs will need to use, and hide the messy guts that make this mod work that are not meant to be used as part of the API. Anything marked as internal, or that are behind an internal class, are usually helper methods and properties for the core mod, and I wouldn't worry about them 90% of the time. By the way, that example you shared is a strange case, and I'm still not sure how that variable should be named, but that is a helper list for cases where a player may press a hotkey to swap/toggle to a specific reserved item slot (or multiple). For example, (this only exists in the reserved weapon slot mod right now) when players press the hotkey to toggle to the reserved weapon slot, they will swap to the reserved weapon slot, and stay toggled there until they scroll off of it. They will remain toggled there, even if they don't have the setting to normally toggle the reserved hotbar. In the case where players decide to have a separate ranged and melee weapon slot, that list will have both of those slots in it. Sorry for probably explaining what that is very terribly!

I do admit since this project is on github, you will be able to see all of the methods and properties that I don't intend to be used in the API, so it can be confusing, and it would be helpful to add more comments because of that. I am still working on the api, and making it friendlier.

If you would like to iterate over the unlocked slots, you can check out the SessionManager class. I actually have an example of how to iterate over the unlocked reserved item slots in the README. As for the locked slots, this hasn't been documented that well yet, but it's basically all in the SyncManager class. I guess I just realized I made this internal, but I might move these to the SessionManager class soon.

I will be going over most of the public functions first that devs might want to use, or are curious about, continue adding function definition/comments. I do appreciate the input, and I'd say continue shooting me input on how I can improve this, thanks!

CatsArmy commented 3 months ago

Np. btw to be fair to you I am using bepinex assembly publicizer on your mod lul

cmooref17 commented 3 months ago

Lmao, that makes sense now. But if there's something you're wanting to achieve with my mod, and you're unsure on how to do it, let me know! I might be able to help you, but it might also help me find flaws in the API, or make me aware of code that needs cleaned up or documented.

CatsArmy commented 3 months ago

Lmao, that makes sense now. But if there's something you're wanting to achieve with my mod, and you're unsure on how to do it, let me know! I might be able to help you, but it might also help me find flaws in the API, or make me aware of code that needs cleaned up or documented.

so the reason im trying to iterate over all reserved slots is because im trying to add the AC energy bar under those items too ive figured it all out but im for somereason just getting stuck

Init the hotbar energy bar step one

Init the hotbar step two

Update the energy bar

and so my plan is not too complex i though about patching the patches that AC patches but then i realized that is dumb and i should just patch the method it self and not become a "patch patch".

the plan:

//c# and some pseudocode or if you will pseudosharp`
[Plugin Awake]
add after patch all:
if(!AdvancedCompany_Patcher.Enabled)
this._harmony.Patch

create a class for the AC compatability:
private static GameObject EnergyPrefab= null;
private static GameObject[] EnergyBars = new GameObject[NUM_OF_RESERVED_INVENTORY_SLOTS];
private static RectTransform[] EnergyInnerBars = new RectTransform[NUM_OF_RESERVED_INVENTORY_SLOTS];
//on init hotbar the patch should do this: EnergyPrefab ??= AdvancedCompany.Patches.InventoryPatches.EnergyPrefab;
//now this is where i got confused and lost a bit in the init step one function he does some kinda funky stuff i would make a arr in the class for it but i couldnt figure out what to do as brain.exe has stopped responding

I will continue writing this comment later i have alot of stuff in the next few days and especially tomorrow but ill upload what im dojng on git later

CatsArmy commented 3 months ago

Lmao, that makes sense now. But if there's something you're wanting to achieve with my mod, and you're unsure on how to do it, let me know! I might be able to help you, but it might also help me find flaws in the API, or make me aware of code that needs cleaned up or documented.

so the reason im trying to iterate over all reserved slots is because im trying to add the AC energy bar under those items too ive figured it all out but im for somereason just getting stuck

Init the hotbar energy bar step one

Init the hotbar step two

Update the energy bar

and so my plan is not too complex i though about patching the patches that AC patches but then i realized that is dumb and i should just patch the method it self and not become a "patch patch".

the plan:

//c# and some pseudocode or if you will pseudosharp`
[Plugin Awake]
add after patch all:
if(!AdvancedCompany_Patcher.Enabled)
this._harmony.Patch

create a class for the AC compatability:
private static GameObject EnergyPrefab= null;
private static GameObject[] EnergyBars = new GameObject[NUM_OF_RESERVED_INVENTORY_SLOTS];
private static RectTransform[] EnergyInnerBars = new RectTransform[NUM_OF_RESERVED_INVENTORY_SLOTS];
//on init hotbar the patch should do this: EnergyPrefab ??= AdvancedCompany.Patches.InventoryPatches.EnergyPrefab;
//now this is where i got confused and lost a bit in the init step one function he does some kinda funky stuff i would make a arr in the class for it but i couldnt figure out what to do as brain.exe has stopped responding

I will continue writing this comment later i have alot of stuff in the next few days and especially tomorrow but ill upload what im dojng on git later

Ok still busy but the Plugin.PatchAll() should add the following logic: In the for each type in types Before _harmony.PatchAll(type) check if ( !AdvancedCompany_Patcher.Enabled && type == typeof(AdvancedCompany_Patcher)) { continue; }