EventPreviews class
Draws events as the level editor shows them.
An event is drawn as the object it spawns looks with its parameters (see ResolveEventPreview()), or as the catalog shows its type (see EventDescriptor::
Public static functions
-
static auto GetPreview(const Formats::
EventRecord& event, EventPreviewSpec& spec) -> bool - Returns how an event is drawn,
falseif it's drawn as a box. -
static void CollectLinks(const LevelDocument& document,
SmallVectorImpl<EventLink>& links,
ArrayView<const std::
uint32_t> onlyCells = {}, std:: size_t maxLinks = 4096) - Finds the lines between events linked by their parameters.
-
static void CollectRaceTrack(const LevelDocument& document,
SmallVectorImpl<EventLink>& links,
std::
size_t maxLinks = 4096) - Finds the arrows of the track of a race, from each race waypoint to the next one and from the last one to the finish.
-
static auto CollectDirections(const Formats::
EventRecord& event, EventDirection(&directions)[4]) -> std:: int32_t - Finds the arrows of an event, the values of its fields along their axes (see EventParamField::
Direction). -
static auto GetLight(const Formats::
EventRecord& event, EventLightShape& light) -> bool - Finds how a light event lights up its surroundings, returns
falseif it isn't a light. - static auto GetLightStrength(float distance, float radiusNear, float radiusFar) -> float
- Returns how much a light lights up a point at a distance, 0 to 1, as the game draws it.
- static auto GetLightPulse(const EventLightShape& light, float animTime) -> float
- Returns how much a pulsing light has grown at a time, in pixels, negative while it's smaller.
-
static auto GetAmbientLight(const Formats::
EventRecord& event, std:: uint8_t& intensity) -> bool - Finds the intensity an ambient light event sets, 0 dark to 255 fully lit, returns
falseif it isn't one. -
static auto CollectAmbientLight(const LevelDocument& document,
std::
int32_t step, Vector2i& size, SmallVectorImpl<std:: uint8_t>& intensities) -> bool - Finds how lit the level is around its ambient light events, in blocks of
steptiles. - static auto GetDirectionLength(float strength) -> float
- Returns the length of the arrow of a direction of a strength (see CollectDirections()), in pixels of the level.
- static auto GetDirectionTip(Vector2f center, Vector2f direction) -> Vector2f
- Returns where the arrow of a direction (see CollectDirections()) of an event at a position ends, in pixels of the level.
- static auto GetDirectionStrength(float length) -> float
- Returns the strength of a direction whose arrow is of a length in pixels of the level, the inverse of GetDirectionLength().
-
static auto DescribeDefaultLevel(const LevelDocument& document,
const Formats::
EventRecord& event, const EventParamField& field, String& text, bool brief = false) -> bool - Describes the level an exit goes to when it doesn't name one.
-
static auto GetUsedText(const LevelDocument& document,
const Formats::
EventRecord& event, const EventParamField& field, StringView& text) -> bool - Finds the part of a level text an event uses, as the game splits it by
|. -
static auto FindTextPartField(const EventDescriptor& descriptor,
std::
int32_t textField) -> std:: int32_t - Returns the index of the field that says which part of the text of a field is used, see GetUsedText(), or -1.
-
static auto HasSound(const Formats::
EventRecord& event) -> bool - Returns
trueif an event plays a sound that can be heard in the editor, see UpdateSound(). - static auto GetCategoryColor(EventCategory category) -> Colorf
- Returns the color of a category.
-
static auto GetEventName(std::
uint16_t type, const std:: uint8_t* params = nullptr) -> String - Returns the translated name of an event type, or its number if it isn't known.
Constructors, destructors, conversion operators
- EventPreviews()
- ~EventPreviews()
- EventPreviews(const EventPreviews&) deleted
Public functions
- auto operator=(const EventPreviews&) -> EventPreviews& deleted
-
void DrawPlaced(Painter& painter,
const Formats::
EventRecord& event, const Rectf& tileRect, float scale, float alpha, float animTime, Vector2f spawnPos, bool inScene = false, bool offGrid = false) - Draws an event placed at a tile.
-
auto DrawInScene(UI::
Canvas& canvas, const Formats:: EventRecord& event, Vector2f spawnPos, float alpha, float animTime, std:: uint16_t z) -> bool - Draws the sprite of an event placed in the level into a canvas of the level, in pixels of the level.
-
auto HasSceneSprite(const Formats::
EventRecord& event) -> bool - Returns
trueif the sprite of an event is drawn by DrawInScene(), a start of the level isn't. -
void DrawFitted(Painter& painter,
const Formats::
EventRecord& event, const Rectf& rect, float animTime, float alpha = 1.0f) - Draws an event fitted into a rectangle, as an item of a list.
-
void DrawFitted(Painter& painter,
std::
uint16_t type, const Rectf& rect, float animTime, float alpha = 1.0f) - Draws a new event of a type fitted into a rectangle.
- void Clear()
- Releases all loaded sprites.
-
void UpdateSound(const Formats::
EventRecord* event) - Plays the sound of an event over and over, as loud as the game plays it, or stops it with
nullptr. - void StopSound()
- Stops the sound played by UpdateSound(), as the level starts to be played.
Public variables
-
Death::
Containers:: Function<bool(const nCine::AABBf&)> IsAreaEmpty - Returns
trueif a rectangle of the level, in pixels, has no solid tile in it. -
Death::
Containers:: Function<GraphicResource*(const Formats:: EventRecord&, bool, bool)> ScriptSprite - Returns the sprite the script of the level gives the object of an event, animated or not, or
nullptr. -
Death::
Containers:: Function<GraphicResource*(std:: int32_t, bool)> ScriptWeaponIcon - Returns the sprite a weapon of the script of the level shows on the screen, usual or powered up, or
nullptr, see ScriptGraphics::FindWeaponIcon().
Function documentation
static void Jazz2:: Editor:: EventPreviews:: CollectLinks(const LevelDocument& document,
SmallVectorImpl<EventLink>& links,
ArrayView<const std:: uint32_t> onlyCells = {},
std:: size_t maxLinks = 4096)
Finds the lines between events linked by their parameters.
Events whose fields of the same channel (see EventParamField::
With onlyCells, sorted tiles of the event grid, only the links of the events on them are found. At most maxLinks links are found, a level linking everything to everything would draw too many lines.
static void Jazz2:: Editor:: EventPreviews:: CollectRaceTrack(const LevelDocument& document,
SmallVectorImpl<EventLink>& links,
std:: size_t maxLinks = 4096)
Finds the arrows of the track of a race, from each race waypoint to the next one and from the last one to the finish.
The waypoints of a group are run in ascending order, those of the same order and group are one, as the game merges them into their center, see MpLevelHandler::ConsolidateOrderedRaceCheckpoints(). An order that's skipped breaks the track there, as on the minimap of the game. The last waypoint of each group leads to what ends a lap — a warp or a coin warp with Set Lap, or a level exit, the game counts a lap at each; those on tiles next to each other are one end. Off-grid waypoints are at their own position. The links are of the channel "Race" with the group as EventLink::maxLinks are found.
static std:: int32_t Jazz2:: Editor:: EventPreviews:: CollectDirections(const Formats:: EventRecord& event,
EventDirection(&directions)[4])
Finds the arrows of an event, the values of its fields along their axes (see EventParamField::
Returns how many arrows there are, at most 4; an arrow of no strength isn't counted. The parameters of an event the game knows that is described from outside of the game point as its description says.
static float Jazz2:: Editor:: EventPreviews:: GetLightStrength(float distance,
float radiusNear,
float radiusFar)
Returns how much a light lights up a point at a distance, 0 to 1, as the game draws it.
Full up to the near radius, then falling off with the cube of the distance left to the far one, see the LightingFs.inc shader.
static float Jazz2:: Editor:: EventPreviews:: GetLightPulse(const EventLightShape& light,
float animTime)
Returns how much a pulsing light has grown at a time, in pixels, negative while it's smaller.
Both of its radii grow by it, as the game pulses it, see EventLightShape::animTime is the time of the animations of the interface, as sprites are drawn at. A light that doesn't pulse doesn't grow.
static bool Jazz2:: Editor:: EventPreviews:: CollectAmbientLight(const LevelDocument& document,
std:: int32_t step,
Vector2i& size,
SmallVectorImpl<std:: uint8_t>& intensities)
Finds how lit the level is around its ambient light events, in blocks of step tiles.
A block takes the intensity of the nearest event. Between events of different intensities, it goes from one to the other, half-way at the same distance from both. One value per block row by row into intensities, 0 dark to 255 fully lit, with the number of blocks in size. Returns false if the level has no ambient light event.
static float Jazz2:: Editor:: EventPreviews:: GetDirectionLength(float strength)
Returns the length of the arrow of a direction of a strength (see CollectDirections()), in pixels of the level.
Longer for a stronger one, but less and less, so a strong one doesn't reach far across the level. Its tip is where it's dragged by, see EventGizmoKind::Direction.
static Vector2f Jazz2:: Editor:: EventPreviews:: GetDirectionTip(Vector2f center,
Vector2f direction)
Returns where the arrow of a direction (see CollectDirections()) of an event at a position ends, in pixels of the level.
The arrow starts at center, the position of the event in the level, not the middle of its tile as the sprite layer shows it, and its handle is at the tip (see EventGizmoKind::Direction), so both are found here. A direction of no strength ends at center.
static bool Jazz2:: Editor:: EventPreviews:: DescribeDefaultLevel(const LevelDocument& document,
const Formats:: EventRecord& event,
const EventParamField& field,
String& text,
bool brief = false)
Describes the level an exit goes to when it doesn't name one.
The next level of an exit of the game is a text, 0 goes to the next level of the properties of the level, a bonus exit to the secret level, see LevelHandler::ResolveNextLevelName(). Returns false if field of the event isn't such a name, or a text is given. With brief, it's short enough to fit under the field.
static bool Jazz2:: Editor:: EventPreviews:: GetUsedText(const LevelDocument& document,
const Formats:: EventRecord& event,
const EventParamField& field,
StringView& text)
Finds the part of a level text an event uses, as the game splits it by |.
An exit takes the part its Part parameter says as the name of the next level, a text area shows one part or the whole text. Any other text is used whole. Returns false if field of the event refers to no text or an empty one, text is empty if the text has no such part.
void Jazz2:: Editor:: EventPreviews:: DrawPlaced(Painter& painter,
const Formats:: EventRecord& event,
const Rectf& tileRect,
float scale,
float alpha,
float animTime,
Vector2f spawnPos,
bool inScene = false,
bool offGrid = false)
Draws an event placed at a tile.
| Parameters | |
|---|---|
| painter | Painter |
| event | The event, unknown types are drawn too |
| tileRect | Rectangle the tile takes on the screen |
| scale | Pixels of the screen a pixel of the level takes |
| alpha | Opacity |
| animTime | Time for animated sprites |
| spawnPos | Where the object is spawned in the level, some objects face the way their position says |
| inScene | Whether its sprite is drawn in the level instead (see DrawInScene()), only the mark of the tile it's at is drawn then |
| offGrid | Whether it's an event off the grid, centered in tileRect, its mark is a triangle instead of a square then |
bool Jazz2:: Editor:: EventPreviews:: DrawInScene(UI:: Canvas& canvas,
const Formats:: EventRecord& event,
Vector2f spawnPos,
float alpha,
float animTime,
std:: uint16_t z)
Draws the sprite of an event placed in the level into a canvas of the level, in pixels of the level.
It's drawn at z among the layers of the level, so layers in front of it cover it as they cover the objects of the game. Returns false for an event that has no sprite there, see HasSceneSprite().
void Jazz2:: Editor:: EventPreviews:: UpdateSound(const Formats:: EventRecord* event)
Plays the sound of an event over and over, as loud as the game plays it, or stops it with nullptr.
Called every frame with the event that's heard. The sound already playing goes on, it's changed as soon as the event plays another one or at another volume. Only an ambient sound has one, nothing is played while sounds are muted in the options of the game.
Variable documentation
Death:: Containers:: Function<bool(const nCine::AABBf&)> Jazz2:: Editor:: EventPreviews:: IsAreaEmpty
Returns true if a rectangle of the level, in pixels, has no solid tile in it.
Some objects turn by the tiles around them when they're spawned, a horizontal spring away from a wall. Without it, the tiles are taken as empty.
Death:: Containers:: Function<GraphicResource*(const Formats:: EventRecord&, bool, bool)> Jazz2:: Editor:: EventPreviews:: ScriptSprite
Returns the sprite the script of the level gives the object of an event, animated or not, or nullptr.
It's drawn instead of the sprite of the game, as it is, with no parts of the object around it. Only objects have one, the events that change tiles share the numbers of the original with the bullets. The last argument tells whether the sprite of the game animates, see ScriptGraphics::