Something like this json config manager useful to anyone as a module?

About Monkey 2 Forums Monkey 2 Development Something like this json config manager useful to anyone as a module?

This topic contains 5 replies, has 3 voices, and was last updated by  skn3 2 years, 5 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #4798

    skn3
    Participant

    This is just a little class I wrote for my app. It lets you define a a config structure at the start of your app and then then lets you Get or Set various value types. The class deals with loading, merging and saving with/from/to a json file. It also lets you add save hooks that get triggered when saving.

    Let me know if this is of any use to you, and I will investigate how to make my first module in monkey2!

    An example:

    The class:

    #4805

    nerobot
    Participant

    This helper looked useful.

    About code – what about using Variant type to store values instead of few vars int/bool/string/float/etc? It will reduce similar code parts, I think.

    #4810

    skn3
    Participant

    I was tempted but didn’t know if it was safe to use the Reflection stuff yet. Also what overhead does using monkey2 reflection bring? I already noticed someone mentioning that their file size had increased dramatically.

    #4812

    nerobot
    Participant

    Hm. If we look into

    we’ll see that base class Object also contains reflection data – TypeInfo.

    Therefore it’s not a problem (no overhead?) to use Variant. Or even ‘Object’ type to boxing.

    Also I heard that reflection now working only if we import <reflection> module.

    #4820

    Mark Sibly
    Keymaster

    The current state of reflection is that, yes, it does add some overhead to an app so it’s now optional – you need to use #Import “<reflection>” to activate it. This is currentlyall or nothing. Eventually, reflection will be selectable on a module by module basis. I’ve reduced reflection overhead a bit and will be reducing it further in future, but reflection will never be ‘free’.

    Without reflection, you can still use Variants and Typeinfo should work for built-ins types. However, all objects will always return ‘Class Object’ for typeinfo. It should be possible to add ‘minimal’ type info for all classes eventually too, even with reflection off, so you can at least inspect class names.

    #4821

    skn3
    Participant

    Ok that’s good to know!

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.