Linus045 / e2_vgui_core

Wiremod Expression 2 Extension to Create Vgui Elements
MIT License
8 stars 5 forks source link

Global methods have to be redefined many times across each specific object's client script #17

Open LoganDark opened 2 years ago

LoganDark commented 2 years ago

This is an internal maintainability issue but the E2Helper descriptions for the default methods should really be defined in one file. Once my PRs are merged I'll see if I can cook up a solution to this that doesn't require any hardcoding or server->client information transfer.

Linus045 commented 2 years ago

It might be possible to have some function that generates these description entries for every type on the client. We could add call kind of E2VguiLib.registerE2HelperDefaultFunctionsForType("xdf") function that will add the default function entries for that specific type.

e.g.

function E2VguiLib.registerE2HelperDefaultFunctionsForType(type)
    E2Helper.Descriptions["setPos(" .. type .. ":nn)"] = "Sets the position."
    E2Helper.Descriptions["setPos(" .. type .. ":xv2)"] = "Sets the position."
    E2Helper.Descriptions["getPos(" .. type .. ":e)"] = "Returns the position."
    E2Helper.Descriptions["setSize(" .. type .. ":nn)"] = "Sets the size."
    ...
end
LoganDark commented 2 years ago

Yeah absolutely, that was the plan. Either iterate through all custom types and add the e2helper descriptions for each of them, or have each type's file call a function to register its common methods.

Linus045 commented 2 years ago

I would prefer the calling method, since the vgui_types table is only available serverside (see E2VguiCore.RegisterVguiElementType) so copying/syncing it to the client would be redudant. This would also make it easier to add specific parameters later, if we need them, on a per-file/per-type basis.