{"id":15722612,"url":"https://github.com/whiteboxdev/library-defold-colors","last_synced_at":"2025-04-30T16:07:32.130Z","repository":{"id":64866990,"uuid":"279343611","full_name":"whiteboxdev/library-defold-colors","owner":"whiteboxdev","description":"Defold Colors provides customizable palettes and color utility features in a Defold game engine project.","archived":false,"fork":false,"pushed_at":"2024-05-24T16:21:16.000Z","size":258,"stargazers_count":18,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-22T16:05:15.394Z","etag":null,"topics":["defold","defold-library"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"zlib","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/whiteboxdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-13T15:38:44.000Z","updated_at":"2024-11-18T08:57:03.000Z","dependencies_parsed_at":"2024-10-24T16:51:02.213Z","dependency_job_id":"c954939e-1522-48ee-b0e8-631f20818b0c","html_url":"https://github.com/whiteboxdev/library-defold-colors","commit_stats":null,"previous_names":["whiteboxdev/library-defold-colors"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whiteboxdev%2Flibrary-defold-colors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whiteboxdev%2Flibrary-defold-colors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whiteboxdev%2Flibrary-defold-colors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whiteboxdev%2Flibrary-defold-colors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/whiteboxdev","download_url":"https://codeload.github.com/whiteboxdev/library-defold-colors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251738892,"owners_count":21635890,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["defold","defold-library"],"created_at":"2024-10-03T22:08:38.934Z","updated_at":"2025-04-30T16:07:32.090Z","avatar_url":"https://github.com/whiteboxdev.png","language":"Lua","funding_links":[],"categories":["Libraries"],"sub_categories":["Programming Language"],"readme":"# Defold Colors\n\nDefold Colors provides customizable palettes and color utility features to a Defold game engine project.\n\nPlease click the ☆ button on GitHub if this repository is useful or interesting. Thank you!\n\n![alt text](https://github.com/whiteboxdev/library-defold-colors/blob/master/assets/thumbnail.png?raw=true)\n\n## Installation\n\nAdd the latest version to your project's dependencies:  \nhttps://github.com/whiteboxdev/library-defold-colors/archive/master.zip\n\n## Configuration\n\nImport the dcolors Lua module into your relevant scripts:\n`local dcolors = require \"dcolors.dcolors\"`\n\nThe `dcolors.palette` property allows you to access the colors stored inside the loaded palette. A palette is structured as follows:\n\n```\nexample =\n{\n    white = vmath.vector4(1, 1, 1, 1),\n    black = vmath.vector4(0, 0, 0, 1),\n    yellow = vmath.vector4(1, 0, 1, 1),\n    ...\n}\n```\n\nIn this case, `example` is the name of the palette. Each color inside has a key of `name` and a value of `vector4`.\n\nTo access a color, use `dcolors.palette.COLOR_NAME`. To add or remove colors from a palette, use the [color-related functions](#dcolorscheck_colorpalette-color).\n\nTo add or remove palettes, use the [palette-related functions](#dcolorscheck_palettepalette). To change the palette which `dcolors.palette` refers to, call `dcolors.choose_palette()`.\n\nYou may also use dcolors for its utility features, separate from its palette service. For example, `dcolors.set_alpha()` modifies the `vector4` passed in, then returns the new color. This is useful for consolidating code. For example, let us assume you want to get the color of a gui node, modify its alpha value to `100`, then set the color of that gui node to the modified color. Normally, you could perform this task like so:\n\n```\nlocal color = gui.get_color(gui.get_node(\"node\"))\ncolor.w = 100\ngui.set_color(gui.get_node(\"node\"), color)\n```\n\nHowever, with the inline convenience of dcolors, you could perform this task like so:\n\n```\ngui.set_color(gui.get_node(\"node\"), dcolors.set_alpha(gui.get_color(gui.get_node(\"node\")), 100))\n```\n\nRGB, HSL, and Hex conversions are also supported.\n\n## API: Properties\n\n### dcolors.vault\n\nTable containing all registered palettes and colors. This may be traversed if you are saving or loading color data. You may also use `dcolors.vault.PALETTE_NAME.COLOR_NAME` to avoid switching palettes with `dcolors.choose_palette()`. The vault is structured as follows:\n\n```\ndcolors.vault =\n{\n\t\u003cpalette_name\u003e =\n\t{\n\t\t\u003ccolor_name\u003e = vmath.vector4( ... ),\n        \t...\n\t},\n\t...\n}\n```\n\n### dcolors.palette\n\nCurrently loaded palette. To access a color, use `dcolors.palette.COLOR_NAME`. A palette is structured as follows:\n\n```\n\u003cpalette_name\u003e =\n{\n    \u003ccolor_name\u003e = vmath.vector4( ... ),\n    ...\n}\n```\n\n## API: Functions\n\n### dcolors.set_red(color, red)\n\nSets the red component of a color.\n\n#### Parameters\n1. `color`: `vector4` to modify.\n2. `red`: Number denoting a new red value.\n\n#### Returns\n\nReturns a `vector4`.\n\n---\n\n### dcolors.set_green(color, green)\n\nSets the green component of a color.\n\n#### Parameters\n1. `color`: `vector4` to modify.\n2. `green`: Number denoting a new green value.\n\n#### Returns\n\nReturns a `vector4`.\n\n---\n\n### dcolors.set_blue(color, blue)\n\nSets the blue component of a color.\n\n#### Parameters\n1. `color`: `vector4` to modify.\n2. `blue`: Number denoting a new blue value.\n\n#### Returns\n\nReturns a `vector4`.\n\n---\n\n### dcolors.set_alpha(color, alpha)\n\nSets the alpha component of a color.\n\n#### Parameters\n1. `color`: `vector4` to modify.\n2. `alpha`: Number denoting a new alpha value.\n\n#### Returns\n\nReturns a `vector4`.\n\n---\n\n### dcolors.check_palette(palette_name)\n\nChecks if a palette exists.\n\n#### Parameters\n1. `palette_name`: Name of palette.\n\n#### Returns\n\nReturns `true` or `false`.\n\n---\n\n### dcolors.add_palette(palette_name)\n\nAdds an empty palette to the vault. If no palette is currently loaded, then `dcolors.palette` becomes `palette_name`. Does nothing if the palette already exists.\n\n#### Parameters\n1. `palette_name`: Name of palette.\n\n---\n\n### dcolors.remove_palette(palette_name)\n\nRemoves a palette from the vault. If the currently loaded palette is removed, then `dcolors.palette` becomes `nil`. Does nothing if the palette does not exist.\n\n#### Parameters\n1. `palette_name`: Name of palette.\n\n---\n\n### dcolors.clear_palette(palette_name)\n\nClears all colors from a palette. Does nothing if the palette does not exist.\n\n#### Parameters\n1. `palette_name`: Name of palette.\n\n---\n\n### dcolors.choose_palette(palette_name)\n\nPoints the `dcolors.palette` property to a palette. Does nothing if the palette does not exist.\n\n#### Parameters\n1. `palette_name`: Name of palette.\n\n---\n\n### dcolors.check_color(palette_name, color)\n\nChecks if a color exists within a palette.\n\n#### Parameters\n1. `palette_name`: Name of palette.\n2. `color`: `vector4` **or** name of color.\n\n#### Returns\n\nReturns `true` or `false`.\n\n---\n\n### dcolors.add_color(palette_name, color_name, color)\n\nAdds a color to a palette. Does nothing if the palette does not exist. If `color_name` already exists, its associated color value will be overwritten with `color`.\n\n#### Parameters\n1. `palette_name`: Name of palette.\n2. `color_name`: Name of color.\n3. `color`: `vector4` to add.\n\n---\n\n### dcolors.remove_color(palette_name, color)\n\nRemoves a color from a palette. Does nothing if the palette does not exist. Does nothing if the color does not exist.\n\n#### Parameters\n1. `palette`: Name of palette.\n2. `color`: `vector4` **or** name of color.\n\n---\n\n### dcolors.premultiply_alpha(color)\n\nApplies `color.w` to its other components.\n\n#### Parameters\n1. `color`: `vector4` to modify.\n\n#### Returns\n\nReturns a `vector4`.\n\n---\n\n### dcolors.is_scale_hex(color, lengths)\n\nChecks if a color is formatted in hexadecimal. Does not check for a preceding `#` symbol.\n\n#### Parameters\n1. `color`: String of color value.\n2. `lengths`: Map of acceptable string lengths, structured as follows:\n\n```\nlocal lengths =\n{\n    [3] = true, -- #ABC\n    [6] = true, -- #AABBCC\n    [8] = true  -- #AABBCCFF (alpha)\n}\n```\n\n#### Returns\n\nReturns `true` or `false`.\n\n---\n\n### dcolors.rgba_to_hsla(color)\n\nConverts an RGBA color to HSLA.\n\n#### Parameters\n1. `color`: `vector4` to convert.\n\n#### Returns\n\nReturns a `vector4`.\n\n---\n\n### dcolors.hsla_to_rgba(color)\n\nConverts an HSLA color to RGBA.\n\n#### Parameters\n1. `color`: `vector4` to convert.\n\n#### Returns\n\nReturns a `vector4`.\n\n---\n\n### dcolors.rgba_to_hex(color)\n\nConverts an RGBA color to Hex.\n\n#### Parameters\n1. `color`: `vector4` to convert.\n\n#### Returns\n\nReturns a `string`.\n\n---\n\n### dcolors.hex_to_rgba(color)\n\nConverts a Hex color to RGBA.\n\n#### Parameters\n1. `color`: `string` to convert. Do not include a prefix such as `0x` or `#`.\n\n#### Returns\n\nReturns a `vector4`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhiteboxdev%2Flibrary-defold-colors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwhiteboxdev%2Flibrary-defold-colors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhiteboxdev%2Flibrary-defold-colors/lists"}