Jazz2::Scripting::LevelScriptLoader class

Binds an AngelScript script file to LevelHandler and executes the script.

Base classes

class ScriptLoader
Generic AngelScript script loader with #include and #pragma directive support.

Constructors, destructors, conversion operators

LevelScriptLoader(LevelHandler* levelHandler, StringView scriptPath)
Creates a new instance and binds the specified script to the level handler.
~LevelScriptLoader()

Public functions

auto GetLevelHandler() const -> LevelHandler*
Returns the level handler this script is bound to.
auto PlaySample(const Vector2f& pos, std::int32_t sampleId, std::int32_t volume, std::int32_t frequency, bool sourceRelative, std::int32_t loopChannel) -> std::shared_ptr<AudioBufferPlayer>
Plays a sound sample by its original sample index (see SOUND::Sample).
auto IsSampleLoaded(std::int32_t sampleId) -> bool
Returns true if the given built-in sample is available (loading it on first query).
auto LoadSample(std::int32_t sampleId, StringView path) -> bool
Loads a custom sample from the given content path, overriding the sample at the given index.
auto ResolveSpriteGraphic(std::int32_t setID, std::int32_t animation) -> Resources::GenericGraphicResource*
Resolves the graphic resource for an original JJ2 animation set and animation index.
auto AddObjectFromEvent(std::uint8_t eventId, float xPixel, float yPixel) -> std::int32_t
Spawns an object from an original JJ2 event ID at the given pixel position.
auto GetScriptObject(std::int32_t objectId) -> Actors::ActorBase*
Returns the live actor for a script object ID previously returned by AddObjectFromEvent.
auto AddScriptControlledObject(std::uint8_t eventId, float xPixel, float yPixel, asIScriptFunction* behaviorFunc) -> std::int32_t
Spawns a script-controlled object whose behavior function drives it each frame.
auto GetLayerProxy(std::int32_t index) -> Legacy::jjLAYER*
Returns the persistent jjLAYER proxy bound to the given level layer index.
auto GetPlayers() const -> ArrayView<Actors::Player* const>
Returns list of players.
auto GetPlayerBackingStore(Actors::Player* player) -> jjPLAYER*
Returns script backing store for specified player.
auto GetPlayerBackingStore(std::int32_t playerIndex) -> jjPLAYER*
void OnLevelLoad()
Called when a level is loaded.
void OnLevelBegin()
Called when a level begins.
void OnLevelReload()
Called when a level reloads.
void OnLevelUpdate(float timeMult)
Called when a level updates (on the beginning of each frame).
void OnLevelCallback(Actors::ActorBase* initiator, std::uint8_t* eventParams)
Called when a level callback is triggered.
auto OnDraw(UI::HUD* hud, Actors::Player* player, const Rectf& view, DrawType type) -> bool
Called when a part of viewport or HUD is drawn.
void OnPlayerDied(Actors::Player* player, Actors::ActorBase* collider)
Called when a player dies.

Protected functions

auto OnProcessInclude(StringView includePath, StringView scriptPath) -> String override
Called when #include directive is encountered in a script file.
void OnProcessPragma(StringView content, ScriptContextType& contextType) override
Called when #pragma directive is encountered in a script file.
void OnBeforeScriptCall()
Called before a script function is called.
void OnAfterScriptCall()
Called after a script function is called.

Function documentation

Jazz2::Scripting::LevelScriptLoader::LevelScriptLoader(LevelHandler* levelHandler, StringView scriptPath)

Creates a new instance and binds the specified script to the level handler.

Parameters
levelHandler Level handler the script is bound to
scriptPath Path to the script file to load

std::shared_ptr<AudioBufferPlayer> Jazz2::Scripting::LevelScriptLoader::PlaySample(const Vector2f& pos, std::int32_t sampleId, std::int32_t volume, std::int32_t frequency, bool sourceRelative, std::int32_t loopChannel)

Plays a sound sample by its original sample index (see SOUND::Sample).

Loads and caches the sample on first use. Returns the player, or nullptr if the sample couldn't be played.

Resources::GenericGraphicResource* Jazz2::Scripting::LevelScriptLoader::ResolveSpriteGraphic(std::int32_t setID, std::int32_t animation)

Resolves the graphic resource for an original JJ2 animation set and animation index.

Goes through the anim mapping and the converted assets, loading and caching on first use. Returns nullptr if unavailable. Used by the canvas sprite-drawing functions.

std::int32_t Jazz2::Scripting::LevelScriptLoader::AddObjectFromEvent(std::uint8_t eventId, float xPixel, float yPixel)

Spawns an object from an original JJ2 event ID at the given pixel position.

Converts the event to a native type, registers it, and returns a script object ID (or 0 on failure). Used by jjAddObject.

Actors::ActorBase* Jazz2::Scripting::LevelScriptLoader::GetScriptObject(std::int32_t objectId)

Returns the live actor for a script object ID previously returned by AddObjectFromEvent.

Returns nullptr if it no longer exists. Used by jjObjects.

std::int32_t Jazz2::Scripting::LevelScriptLoader::AddScriptControlledObject(std::uint8_t eventId, float xPixel, float yPixel, asIScriptFunction* behaviorFunc)

Spawns a script-controlled object whose behavior function drives it each frame.

A host actor applies its velocity, calls the behavior over the jjOBJ, and syncs the position back. Returns a script object ID. Used by jjAddObject when a custom behavior function is supplied.

Legacy::jjLAYER* Jazz2::Scripting::LevelScriptLoader::GetLayerProxy(std::int32_t index)

Returns the persistent jjLAYER proxy bound to the given level layer index.

Creates and populates it from the engine layer on first access (or returns nullptr if the index is out of range). The returned handle is AddRef'd for the caller. Used by jjLayers.

jjPLAYER* Jazz2::Scripting::LevelScriptLoader::GetPlayerBackingStore(std::int32_t playerIndex)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.