diff --git a/cf-lib/changelog.txt b/cf-lib/changelog.txt index db76d84..f658edc 100644 --- a/cf-lib/changelog.txt +++ b/cf-lib/changelog.txt @@ -1,4 +1,9 @@ --------------------------------------------------------------------------------------------------- +Version: 1.4.0 +Date: 10.01.2026 + Changes: + - Add Entity.setFilename +--------------------------------------------------------------------------------------------------- Version: 1.3.0 Date: 24.12.2025 Changes: diff --git a/cf-lib/data/Entity.lua b/cf-lib/data/Entity.lua index 4a21072..10172ad 100644 --- a/cf-lib/data/Entity.lua +++ b/cf-lib/data/Entity.lua @@ -26,4 +26,21 @@ Entity.collisionBox = function(width, height, margin) } end +--- Sets the file name on a picture considering various formats. +--- If sheets or layers are found, use the optional param to select the right one. +--- @param sprite table The sprite to replace the filename in +--- @param filename string The new filename +--- @param sheetLayer number The sheet or layer index to use. Defaults to 1. +Entity.setFilename = function(sprite, filename, sheetLayer) + if sprite.filename then + sprite.filename = filename + elseif sprite.sheet then + sprite.sheet.filename = filename + elseif sprite.sheets then + sprite.sheets[sheetLayer or 1].filename = filename + elseif sprite.layers then + sprite.layers[sheetLayer or 1].filename = filename + end +end + return Entity \ No newline at end of file diff --git a/cf-lib/info.json b/cf-lib/info.json index 4191509..77044a6 100644 --- a/cf-lib/info.json +++ b/cf-lib/info.json @@ -1,6 +1,6 @@ { "name": "cf-lib", - "version": "1.3.0", + "version": "1.4.0", "title": "cackling fiends library", "description": "Because I'd like to have my own library :-)", "author": "cackling fiend",