ScriptingScope

object ScriptingScope

Holds references to all internal game data that scripting backends have access to.

Also where to put any future PlayerAPI, CheatAPI, ModAPI, etc.

For LuaScriptingBackend, UpyScriptingBackend, QjsScriptingBackend, etc, the hierarchy of data under this class definition should probably directly mirror the wrappers in the namespace exposed to running scripts.

WorldScreen gives access to UnitTable.selectedUnit, MapHolder.selectedTile, etc. Useful for contextual operations.

The members of this class and its nested classes should be designed for use by running scripts, not for implementing the protocol or API of scripting backends. E.G.: If you need access to a file to build the scripting environment, then add it to ScriptingEngineConstants.json instead of using apiHelpers.assetFileB64. If you need access to some new type of property, then geneneralize it as much as possible and add an IPC request type for it in ScriptingProtocol.kt or add support for it in Reflection.kt. In Python terms, that means that magic methods all directly send and parse IPC packets, while running scripts transparently use those magic methods to access the functions here. API calls are for running scripts, and may be less stable. Building the scripting environment itself should be done directly using the IPC protocol and other lower-level constructs.

To reduce the chance of E.G. name collisions in .apiHelpers.registeredInstances, or one misbehaving mod breaking everything by unassigning .gameInfo, different ScriptingState()s should each have their own ScriptingScope().

Functions

equals
Link copied to clipboard
open operator fun equals(other: Any?): Boolean
hashCode
Link copied to clipboard
open fun hashCode(): Int
toString
Link copied to clipboard
open fun toString(): String

Properties

apiExecutionContext
Link copied to clipboard
val apiExecutionContext: ScriptingApiExecutionContext
apiHelpers
Link copied to clipboard
val apiHelpers: ScriptingApiHelpers
civInfo
Link copied to clipboard
var civInfo: CivilizationInfo? = null
gameInfo
Link copied to clipboard
var gameInfo: GameInfo? = null
mapEditorScreen
Link copied to clipboard
var mapEditorScreen: MapEditorScreen? = null
modApiHelpers
Link copied to clipboard
val modApiHelpers: ScriptingModApiHelpers
Unciv
Link copied to clipboard
val Unciv: ScriptingApiUnciv
uncivGame
Link copied to clipboard
var uncivGame: UncivGame? = null
worldScreen
Link copied to clipboard
var worldScreen: WorldScreen? = null

Sources

jvm source
Link copied to clipboard