Skip to content

Complete TMPE API #685

@kianzarrin

Description

@kianzarrin

from #678

@krzychu124 Also we should update API project interfaces and make strong version instead of [1.0.*]
Probably then we'll need to log changes in separate section of Changelog , maybe even export whole project as a new repository and release each version separately (it still could be linked as submodule in main repo).
Any mod dev could download API lib and import it in his mod source code and relay on provided interfaces when he/she want to make changes to TM:PE settings.
Still thinking how to expose manager instances reliably (return interface instance instead of using it directly) :/

@aubergine10 If someone can provide brain dump of basics of using the API I'll tidy it in to markdown and we can add some docs to the relevant folder and maybe link from contributing guide or something.
I assume it just spits out a DLL that devs can reference from their projects to interface to TMPE at runtime?

@krzychu124 The missing part is: reliable source of instances, since Managers in TM:PE are static.
Probably we would need class in API which would act as container to provide instances or we could use some IoC container like Unity
Quick example of usage:

public class InstanceProvider {
   public ITrafficPriorityManager GetPriorityManager() {
      return TrafficPriorityManager.instance;
   }
}

then other mods could use it as follows (it's only example):

bool hasNode = InstanceProvider.GetPriorityManager().HasNodePrioritySign(1234);
//TrafficPriorityManager has declaration of bool HasNodePrioritySign(ushort nodeId);

I think it's pretty standard Plug-in architecture.
Having instance provider in API you get ability to modify everything in main project without breaking other mods. You can change everything, class/property names, types, the only thing that should stay intact is API call. It should always return instance compatible with interface. In my opinion strong versioning is important for maintaining compatibility. You can add more declarations but you shouldn't change existing, since it will cause breaking change. Say mod x use API v1 and wants to call some method, it shouldn't break anything when we update API to v2 with new method declarations unless we remove/change any old declarations.
The only thing which might cause issues I can imagine is hot-reload, but we would need to test out it.
I suggest reading about extern keyword, as some way to resolve runtime versioning issues :)
I'm not C# dev so I might be completely wrong with this approach. I'm open on other ideas.

Metadata

Metadata

Assignees

No one assigned

    Labels

    APIAPI for external modsdocsDocumentationhelp wantedSeeking assistancemetaBuild environment, github environment, etc.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions