LiminaliaLiminalia
Technical docs: Sprite position adjustment screen

Sprite position adjustment screen

Open in Claude (new tab)
On this page

A page in the lim dev dev server for editing the position and size (frame) of the sprites in cast.json on screen (the phone app serves the same code from its Service Worker; docs/studio-mobile.md). It works with the same controls and the same calculations as the TyranoBuilder adjustment screen of the sprite plugin Tyrano Tatie (tatie). It exists only on the dev server and isn’t included in what lim build exports.

lim dev [project]
# Player:                      http://localhost:5180/
# Sprite position adjustment:  http://localhost:5180/__liminalia/cast

Opening it from the sprite position link at the top right of the player (below the position display) opens it with the first sprite shown at that moment selected. You can also choose with ?who=<character>&appearance=<sprite set>&variant=<variant>&position=<position>&bg=<background> in the URL.

Screen

  • The preview shows an area the size of the game screen (screen in liminalia.json), scaled down. The scale is shown at the top of the page, and coordinates are always game screen coordinates (parts outside the screen are shown darkened, and their handles can still be grabbed)
  • Background: You can lay one of the project’s background images (assets/bgimage/) underneath. The first one in the list is used at first, and your choice is saved in the browser
  • Show game screen: Shows a sample of the message screen, reflecting the project’s settings and CSS, over the sprites, so you can check how they overlap. It uses the selected background and the position you’re editing, and you can keep dragging. “Hide outside the game screen” hides the parts that stick out of the screen
  • What you edit: character → sprite set → variant → standing position. The standing positions are the names in the variant’s frame (left / center / right always exist), and you can add more with +
  • For a variant without a position and size (shown at the image’s actual size at the bottom center of the screen; these come from TyranoScript’s [chara_new]), moving it sets a position and size that match how it looks now

Controls

ControlWhat it does
DragMoves the left / top of the current standing position
Handles at the four corners and four sidesChange the size (the opposite side stays put). Lock aspect ratio is on by default
WheelScales around the center. With the lock off, the width only; with Shift, the height only
Arrow keysMove 1px (10px with Shift)
Finger drag, handlesThe same as with the mouse (handles can be grabbed over a wider area than they look)
Two-finger spread and pinchScale around the center (keeping the aspect ratio). The fingers can be outside the sprite
Number fieldsleft / top / width / height. With the lock on, width and height change together
OpacityOpacity of the sprite being edited (for display only)
Show all standing positionsOverlays the other standing positions of the same variant faintly
Compare withOverlays a character, sprite set, standing position (“same as the one being edited,” or a name) and variant (one, or “all variants”) semi-transparently. A color (none, red, blue, green, magenta, cyan, yellow, monochrome) and an opacity
Match all variantsApplies the current variant’s size ratio and vertical position to all variants of the same sprite set (asks first)
When saving center, match the size and vertical position of the other standing positionsWhen you save with center selected, aligns the vertical position of that variant’s other standing positions, and keeps each standing position’s horizontal center
+ for variantsDrop an image (or choose a file) → choose the folder, file name and variant name, save it under assets/fgimage/ and add the variant
+ / - for sprite setsAdd or delete a sprite set (the last one can’t be deleted; image files aren’t deleted)
+ for charactersAdd a character (a name that isn’t a speaker is fine)
ResetReturns the current variant’s position and size to how they were when the page was opened or last saved
Undo, redoCtrl / ⌘ + Z, Ctrl / ⌘ + Shift + Z (up to 100 steps)
SaveCtrl / ⌘ + S

While there are unsaved changes, this is shown at the top of the page, and leaving the page asks for confirmation.

On narrow touch screens (touch screens less than 1024px wide or 500px tall or less, and screens 640px wide or less), the three columns don’t fit, so the preview is fixed at the top and the fields scroll below it. In landscape, the preview is fixed on the right.

Calculations (the same as tatie)

  • Match all variants: The ratio is “the current size of the current variant ÷ the reference size” (the reference is the position and size when the page was opened or last saved; for variants added later, the position and size when they were added). Each variant’s reference size is multiplied by this ratio, and in every standing position, the center X is kept and the top is aligned to the top of the current standing position. Only the current standing position of the current variant keeps its current left. When the comparison overlays one variant of the same sprite set, that variant isn’t rewritten (with the “all variants” comparison, none is excluded). Variants without a position and size aren’t rewritten either
  • Matching when saving center: Aligns the top of the current variant’s other standing positions to the top of center, and sets left so the center X stays where it was in the reference position and size
  • Initial position and size when adding a variant: Compares the bounding boxes of the non-transparent parts of the reference sprite (when overwriting, that variant; when adding, the sprite set’s normal → default → first variant) and the new image. The ratio is “the reference body height ÷ the new body height” × 0.75 + “the width ratio” × 0.25. In each standing position, the center X and bottom edge of the bounding box are matched to the reference. Without a reference, the sprite is fit to the screen height, and left / center / right are placed at 1/4, 1/2 and 3/4 of the screen width

Saving

The dev server does the saving (POST /__liminalia/api/cast).

  • Before saving, it checks with castProblems (@liminalia/lang) and doesn’t save if there are errors
  • It replaces cast in cast.json (and speakers too, when Studio’s “Characters” screen also sends speakers) and leaves the other items as they are. Items inside characters that this page doesn’t handle (the sprite set’s label, the variant’s cacheKey, lip, blink, the character’s color, text, nameImage, windowImage and so on) are kept too
  • The content before saving is copied as change history to .liminalia/backups/cast-<date and time>.json in the project (the newest 20 are kept). The template’s .gitignore excludes .liminalia/
  • It writes to a temporary file and then renames it
  • If cast.json was rewritten elsewhere after the page was opened (by lim import and so on), it asks whether to overwrite it
  • Images for added variants are saved under assets/fgimage/ right away (it asks if the same name exists). Only when an image is overwritten with the same name is its cacheKey changed, so that open players don’t show the old image (exports add their own hash of each asset’s contents)

When you save, open players receive the Vite WebSocket custom event liminalia:cast, and the player reloads cast.json and redraws the sprites from the current state (without advancing the page).

The phone app has no import source folder, so it doesn’t write back (noWriteBack of casterServer). Change history stays in .liminalia/backups/ on the device and isn’t sent to GitHub.

cast.json made by import

In projects with import.tyrano in liminalia.json, lim import rebuilds cast.json, so as things stand, the next import would wipe out the adjustments. So when saving, the page also writes back to the import source.

  1. If the import settings ("./import" in import.tyrano.profile) have writeCast, it calls that

    import type { TyranoImportProfile } from "@liminalia/sdk/import";
    
    const profile: TyranoImportProfile = {
      // Write the saved characters back to the import source and return the files rewritten (shown on the page)
      writeCast({ source, cast }) {
        return [];
      },
    };
    export default profile;
  2. If not, and the import source has Tyrano Tatie settings (data/others/plugin/tatie/settings.js), it writes back to them (writeTatieSettings, @liminalia/ks-import/node)

    • settings.js isn’t executed. Its right-hand side is read as a literal (strings, numbers, booleans, null, arrays, objects) and written back as formatted JSON in an assignment of the same form (window.TYRANO_TATIE_SETTINGS = {…};). If it contains anything that isn’t a literal, such as a function call, it’s treated as unreadable and gives an error
    • Only the variants’ storage (= image) and frame are written. Characters, sprite sets and variants that are missing are added
    • Items in the settings it doesn’t know, defaultCharacter, frameReference, label and cacheKey are kept
    • Variants without a position and size can’t be written in tatie, so they aren’t written (the page tells you). Deleted sprite sets and variants aren’t deleted from the settings
    • Characters in the old format (variants only, without sprite sets) are written in the old format while they have only that one sprite set, and are moved to the appearances form when another sprite set is added, as tatie does when it saves
    • The settings before saving are backed up to .liminalia/backups/tatie-settings-<date and time>.js in the project (the newest 20)
  3. If neither exists, the top of the page shows “インポートで作成された cast.json です。書き戻す先がないため、次のインポートで上書きされます。” (the page is in Japanese; it says this cast.json was made by import and, since there’s nowhere to write back to, the next import will overwrite it).