Scripts refactoring
Currently, scripts uses mostly delegates in order to give the scripts access to some data from the simulator. This is inefficient and a bit annoying to maintain.
The idea is to convert every script classes to the same design pattern as for the C# signal scripts:
- The script class contains an internal reference to the script host object.
- This reference is set at initialization through an internal method.
- This reference is used in the script class functions to get access to the information need by those functions.
The internal reference can not be accessed from the script since it can only be accessed from the same assembly (Orts.Simulation in that case). The script doesn't have access to the rest of the objects of the simulator.
It can be reinforced by setting this reference as private but, to me, internal is enough.
This change is compatible with all of the scripts that have been coded until now: we replace delegates by functions that does have the same signature.
For example:
public Func<bool> Something;
public Action<bool> SetSomething;
becomes
public bool Something() { return <something>; }
public void SetSomething(bool value) { <something> = value; }
This will also allow us to create properties instead of getter and setter functions (so cleaner code).
Blueprint information
- Status:
- Started
- Approver:
- James Ross
- Priority:
- Low
- Drafter:
- Cédric GNIEWEK
- Direction:
- Approved
- Assignee:
- Cédric GNIEWEK
- Definition:
- Approved
- Series goal:
- None
- Implementation:
- Good progress
- Milestone target:
- 1.x
- Started by
- Cédric GNIEWEK
- Completed by
Related branches
Related bugs
Sprints
Whiteboard
Work Items
Work items:
TCS: INPROGRESS
Brake controller: DONE
Circuit breaker and traction cut-off relay: DONE
Power supplies: DONE
Abstract scritpt class: TODO