Console::Assets

console 0.2.0 · app/console/assets.rb · 108 lines · view source

Console::Assets -- where a cart's files actually live.

A cart is a directory, and it owns everything it needs:

carts/space/
  app/space.rb        the cart itself, plus any code files beside it
  sprites/            its own art
  sounds/
  maps/
  data/

A cart writes plain paths -- 'sprites/hero.png', 'maps/Level_0.ldtk' -- and they mean "somewhere inside my cart". The console rewrites them into real, game-relative paths ('carts/space/sprites/hero.png') on the way out to DragonRuby. Only this module has to know where the cart directory sits; the sprite index, audio, maps and the draw helpers just hand paths over.

Resolution is cart-first, with exactly one fallback: the console's own root. A file inside the cart wins; a file that exists only at the console root still resolves, so the console can ship starter art for a brand-new cart. Each fallback is logged, because a published cart stages its cart directory alone (see ./bin/publish-cart) and anything it borrows from the console root is missing from the build. A cart that owns its assets has no fallbacks.

def boot(cart_root)

Point the console at a cart directory. nil means "no cart is booted", and every path resolves against the console root -- which is what the console needs when it is not running a cart at all.

def scoped?
line 48
def cart_root

The cart directory in scope, or nil.

def resolve(path)

Rewrite a cart-relative path into a real one.

Cart copy first, then the console root, and when neither exists it returns the cart-relative path anyway: that is where the file belongs, and it is what a "not found" warning should name.

def shared?(path)

True when path came from the console root rather than the cart. Used by the tests, and by anything that wants to warn about an unowned asset.

def shared_assets

Every asset this cart is borrowing from the console root.

def scoped_inside?(path)

A path already pointing inside the cart is left alone, so resolving is idempotent -- a path can pass through resolve twice without being nested.

def note_fallback(path)
line 100