{"author_link":"\/users\/eidolon","author_name":"Eidolon","author_uid":"eidolon","comments":[],"epoch":1543626911,"event":"LD43","format":"md","ldjam_node_id":128742,"likes":6,"metadata":{"p_key":"123058","p_author":"Eidolon","p_authorkey":"1002350","p_urlkey":"339145","p_title":"the final stretch: a hot reloading asset manager for vore","p_cat":"LDJam ","p_event":"LD43","p_time":"1543626911","p_likes":"6","p_comments":"0","p_status":"WAYBACK","us_key":"1002350","us_name":"Eidolon","us_username":"eidolon","event_start":"1543536000","event_key":"71","event_name":"LD 43"},"node":{"_collation":{"body_sanitizer":"TextUtils::SanitizeHTML via existing importer","event":"LD43","removed_author":false},"_superparent":120415,"_trust":1,"author":2350,"body":"https:\/\/github.com\/HybridEidolon\/love2d-vore-template\n\nonce more doing some groundwork to save some time, and sharing the code.\n\nvore is a love2d game template leveraging the gulp build tool from the node ecosystem to watch your game source for changes and recompile and bake your assets automatically. accompanying it are extensions for tiny-ecs and (now) an asset manager that both fit well into this watch-reload pattern, allowing you to reload both system code and assets at runtime simply by saving them in your editor. vore also automatically packages and uploads your game to itch.io through butler. it supports moonscript, aseprite, and tiled compilation to loadable assets built-in, and is relatively easy to extend.\n\nper the documentation:\n\n# Asset Manager\n\nAssetManager is a stateful object that combines a few functions:\n\n- Loading and caching of various asset types by string path\n- Storage of runtime-generated assets by a unique transient index object\n- Retrieval of cached assets (assuming they are already loaded)\n- Reloading of loaded assets\n\n## Examples (Moonscript)\n\nConstruct a new instance:\n\n    import AssetManager from require 'AssetManager'\n\n    manager = AssetManager!\n\nAdd an extension-based loader. The return value of the loader func will be stored in the cache.\n\n    manager\\setLoader 'png', love.graphics.newImage\n    manager\\setLoader 'wav', (path) -> love.audio.newSource path, 'static'\n    manager\\setLoader 'lua', love.filesystem.load\n    manager\\setLoader 'json', myJsonLoader\n\nLoad an asset (for later retrieval). The loader used will be based on the extension.\n\n    manager\\load 'sprite.png'\n\nRetrieve an asset and use it\n\n    sprite = manager\\get 'sprite.png'\n\n    love.graphics.draw sprite, 0, 0\n\nInsert a dynamic asset into the cache and create an opaque index key for it. Store the key\nif you want to reference the asset later. (Note: if you need to e.g. serialize entity state,\nyou'll need to delete this from the output)\n\n    image = love.image.newImageData 512, 512\n    key = manager\\insert image\n\nRetrieve a dynamic asset from the cache. You should not store this reference; keep it only\nfor as long as you need it, because you can retrieve it later. Holding onto the asset\nwill just make hot reloading not work.\n\n    dynamicImage = manager\\get key\n\nReplace a dynamic asset in the cache, reusing the key. `release` will **NOT** be called on the object.\nYou can replace an asset with `nil` to fully remove it from the cache.\n\n    anotherImage = love.image.newImageData 128, 128\n    oldImage = manager\\replace key, anotherImage\n    oldImage\\release!\n\n    -- remove it\n    oldImage = manager\\replace key, nil\n    oldImage\\release!\n\nCheck and reload updated assets. `release` will be called on the values if it exists.\nIf a file is removed, it will not be removed from the cache, but obviously it won't\nbe present in future runs.\n\n    manager\\update!\n\n## Usage in ECS\n\nStore the AssetManager on your World. Use a System to first gather all of the asset references\nin your scene that need to be loaded, and load them. For example:\n\n    tiny = require 'tiny'\n    ProcessingSystem = require 'tinyx.ProcessingSystem'\n\n    class LoadSpriteImages extends ProcessingSystem\n      new: =>\n        super!\n    \n      filter: tiny.filter 'sprite'\n\n      process: (e, dt) =>\n        if not @world.assetManager\\get e.sprite.imageKey and type(e.sprite.imageKey) == 'string'\n          @world.assetManager\\load e.sprite.imageKey\n    \n    LoadSpriteImages\n\nIf you want to periodically hot reload all your assets (almost certainly why you're using this):\n\n    tiny = require 'tiny'\n    System = require 'tinyx.System'\n\n    class ReloadAssets extends System\n      new: (reloadInterval) =>\n        super!\n        @interval = reloadInterval\n    \n      update: (dt) =>\n        @world.assetManager\\update!\n    \n    ReloadAssets\n\nOf course, you can `get` the assets you need in the systems e.g. responsible for drawing or starting\nsound sources.\n","comments":0,"created":"2018-12-01T01:11:12Z","files":[],"files-timestamp":0,"id":128742,"love":6,"love-timestamp":"2018-12-01T01:42:15Z","meta":[],"modified":"2018-12-01T01:42:15Z","name":"the final stretch: a hot reloading asset manager for vore","node-timestamp":"2018-12-01T01:15:11Z","parent":125683,"parents":[1,5,9,120415,125683],"path":"\/events\/ludum-dare\/43\/$125683\/the-final-stretch-a-hot-reloading-asset-manager-for-vore","published":"2018-12-01T01:15:11Z","scope":"public","slug":"the-final-stretch-a-hot-reloading-asset-manager-for-vore","subsubtype":"","subtype":"","type":"post","version":372101},"node_metadata":{"n_key":"128742","n_urlkey":"339145","n_parent":"125683","n_path":"\/events\/ludum-dare\/43\/$125683\/the-final-stretch-a-hot-reloading-asset-manager-for-vore","n_slug":"the-final-stretch-a-hot-reloadin","n_type":"post","n_subtype":"","n_subsubtype":"","n_author":"2350","n_created":"1543626672","n_modified":"1543628535","n_version":"372101","n_status":"WAYBACK"},"source_url":"https:\/\/ldjam.com\/events\/ludum-dare\/43\/$125683\/the-final-stretch-a-hot-reloading-asset-manager-for-vore","text":"https:\/\/github.com\/HybridEidolon\/love2d-vore-template\n\nonce more doing some groundwork to save some time, and sharing the code.\n\nvore is a love2d game template leveraging the gulp build tool from the node ecosystem to watch your game source for changes and recompile and bake your assets automatically. accompanying it are extensions for tiny-ecs and (now) an asset manager that both fit well into this watch-reload pattern, allowing you to reload both system code and assets at runtime simply by saving them in your editor. vore also automatically packages and uploads your game to itch.io through butler. it supports moonscript, aseprite, and tiled compilation to loadable assets built-in, and is relatively easy to extend.\n\nper the documentation:\n\n# Asset Manager\n\nAssetManager is a stateful object that combines a few functions:\n\n- Loading and caching of various asset types by string path\n- Storage of runtime-generated assets by a unique transient index object\n- Retrieval of cached assets (assuming they are already loaded)\n- Reloading of loaded assets\n\n## Examples (Moonscript)\n\nConstruct a new instance:\n\n    import AssetManager from require 'AssetManager'\n\n    manager = AssetManager!\n\nAdd an extension-based loader. The return value of the loader func will be stored in the cache.\n\n    manager\\setLoader 'png', love.graphics.newImage\n    manager\\setLoader 'wav', (path) -> love.audio.newSource path, 'static'\n    manager\\setLoader 'lua', love.filesystem.load\n    manager\\setLoader 'json', myJsonLoader\n\nLoad an asset (for later retrieval). The loader used will be based on the extension.\n\n    manager\\load 'sprite.png'\n\nRetrieve an asset and use it\n\n    sprite = manager\\get 'sprite.png'\n\n    love.graphics.draw sprite, 0, 0\n\nInsert a dynamic asset into the cache and create an opaque index key for it. Store the key\nif you want to reference the asset later. (Note: if you need to e.g. serialize entity state,\nyou'll need to delete this from the output)\n\n    image = love.image.newImageData 512, 512\n    key = manager\\insert image\n\nRetrieve a dynamic asset from the cache. You should not store this reference; keep it only\nfor as long as you need it, because you can retrieve it later. Holding onto the asset\nwill just make hot reloading not work.\n\n    dynamicImage = manager\\get key\n\nReplace a dynamic asset in the cache, reusing the key. `release` will **NOT** be called on the object.\nYou can replace an asset with `nil` to fully remove it from the cache.\n\n    anotherImage = love.image.newImageData 128, 128\n    oldImage = manager\\replace key, anotherImage\n    oldImage\\release!\n\n    -- remove it\n    oldImage = manager\\replace key, nil\n    oldImage\\release!\n\nCheck and reload updated assets. `release` will be called on the values if it exists.\nIf a file is removed, it will not be removed from the cache, but obviously it won't\nbe present in future runs.\n\n    manager\\update!\n\n## Usage in ECS\n\nStore the AssetManager on your World. Use a System to first gather all of the asset references\nin your scene that need to be loaded, and load them. For example:\n\n    tiny = require 'tiny'\n    ProcessingSystem = require 'tinyx.ProcessingSystem'\n\n    class LoadSpriteImages extends ProcessingSystem\n      new: =>\n        super!\n    \n      filter: tiny.filter 'sprite'\n\n      process: (e, dt) =>\n        if not @world.assetManager\\get e.sprite.imageKey and type(e.sprite.imageKey) == 'string'\n          @world.assetManager\\load e.sprite.imageKey\n    \n    LoadSpriteImages\n\nIf you want to periodically hot reload all your assets (almost certainly why you're using this):\n\n    tiny = require 'tiny'\n    System = require 'tinyx.System'\n\n    class ReloadAssets extends System\n      new: (reloadInterval) =>\n        super!\n        @interval = reloadInterval\n    \n      update: (dt) =>\n        @world.assetManager\\update!\n    \n    ReloadAssets\n\nOf course, you can `get` the assets you need in the systems e.g. responsible for drawing or starting\nsound sources.\n","title":"the final stretch: a hot reloading asset manager for vore","wayback_source":[]}