diff --git a/data/palettes/a64.gpl b/data/extensions/arne-palettes/a64.gpl similarity index 100% rename from data/palettes/a64.gpl rename to data/extensions/arne-palettes/a64.gpl diff --git a/data/palettes/arne-paldac.gpl b/data/extensions/arne-palettes/arne-paldac.gpl similarity index 100% rename from data/palettes/arne-paldac.gpl rename to data/extensions/arne-palettes/arne-paldac.gpl diff --git a/data/palettes/arne16.gpl b/data/extensions/arne-palettes/arne16.gpl similarity index 100% rename from data/palettes/arne16.gpl rename to data/extensions/arne-palettes/arne16.gpl diff --git a/data/palettes/arne32.gpl b/data/extensions/arne-palettes/arne32.gpl similarity index 100% rename from data/palettes/arne32.gpl rename to data/extensions/arne-palettes/arne32.gpl diff --git a/data/palettes/cg-arne.gpl b/data/extensions/arne-palettes/cg-arne.gpl similarity index 100% rename from data/palettes/cg-arne.gpl rename to data/extensions/arne-palettes/cg-arne.gpl diff --git a/data/palettes/copper-tech.gpl b/data/extensions/arne-palettes/copper-tech.gpl similarity index 100% rename from data/palettes/copper-tech.gpl rename to data/extensions/arne-palettes/copper-tech.gpl diff --git a/data/palettes/cpc-boy.gpl b/data/extensions/arne-palettes/cpc-boy.gpl similarity index 100% rename from data/palettes/cpc-boy.gpl rename to data/extensions/arne-palettes/cpc-boy.gpl diff --git a/data/palettes/eroge-copper.gpl b/data/extensions/arne-palettes/eroge-copper.gpl similarity index 100% rename from data/palettes/eroge-copper.gpl rename to data/extensions/arne-palettes/eroge-copper.gpl diff --git a/data/palettes/jmp.gpl b/data/extensions/arne-palettes/jmp.gpl similarity index 100% rename from data/palettes/jmp.gpl rename to data/extensions/arne-palettes/jmp.gpl diff --git a/data/extensions/arne-palettes/package.json b/data/extensions/arne-palettes/package.json new file mode 100644 index 000000000..11ac832fc --- /dev/null +++ b/data/extensions/arne-palettes/package.json @@ -0,0 +1,24 @@ +{ + "name": "arne-palettes", + "displayName": "Arne Niklas Jansson Palettes", + "version": "1.0", + "author": { "name": "Arne Niklas Jansson", "url": "https://androidarts.com/" }, + "publisher": "aseprite", + "categories": [ + "Palettes" + ], + "contributes": { + "palettes": [ + { "id": "a64", "path": "./a64.gpl" }, + { "id": "arne-paldac", "path": "./arne-paldac.gpl" }, + { "id": "arne16", "path": "./arne16.gpl" }, + { "id": "arne32", "path": "./arne32.gpl" }, + { "id": "cg-arne", "path": "./cg-arne.gpl" }, + { "id": "copper-tech", "path": "./copper-tech.gpl" }, + { "id": "cpc-boy", "path": "./cpc-boy.gpl" }, + { "id": "eroge-copper", "path": "./eroge-copper.gpl" }, + { "id": "jmp", "path": "./jmp.gpl" }, + { "id": "psygnork", "path": "./psygnork.gpl" } + ] + } +} diff --git a/data/palettes/psygnork.gpl b/data/extensions/arne-palettes/psygnork.gpl similarity index 100% rename from data/palettes/psygnork.gpl rename to data/extensions/arne-palettes/psygnork.gpl diff --git a/data/palettes/matriax8c.gpl b/data/extensions/davitmasia-palettes/matriax8c.gpl similarity index 100% rename from data/palettes/matriax8c.gpl rename to data/extensions/davitmasia-palettes/matriax8c.gpl diff --git a/data/extensions/davitmasia-palettes/package.json b/data/extensions/davitmasia-palettes/package.json new file mode 100644 index 000000000..dfdfeacfe --- /dev/null +++ b/data/extensions/davitmasia-palettes/package.json @@ -0,0 +1,16 @@ +{ + "name": "davitmasia-palettes", + "displayName": "Davit Masia Palettes", + "description": "Palettes contributed by Davit Masia", + "version": "1.0", + "author": { "name": "Davit Masia", "url": "https://twitter.com/DavitMasia" }, + "publisher": "aseprite", + "categories": [ + "Palettes" + ], + "contributes": { + "palettes": [ + { "id": "matriax8c", "path": "./matriax8c.gpl" } + ] + } +} diff --git a/data/palettes/db16.gpl b/data/extensions/dawnbringer-palettes/db16.gpl similarity index 100% rename from data/palettes/db16.gpl rename to data/extensions/dawnbringer-palettes/db16.gpl diff --git a/data/palettes/db32.gpl b/data/extensions/dawnbringer-palettes/db32.gpl similarity index 100% rename from data/palettes/db32.gpl rename to data/extensions/dawnbringer-palettes/db32.gpl diff --git a/data/extensions/dawnbringer-palettes/package.json b/data/extensions/dawnbringer-palettes/package.json new file mode 100644 index 000000000..e68dd8b6f --- /dev/null +++ b/data/extensions/dawnbringer-palettes/package.json @@ -0,0 +1,17 @@ +{ + "name": "dawnbringer-palettes", + "displayName": "Richard \"DawnBringer\" Fhager Palettes", + "description": "Palettes created by Richard \"DawnBringer\" Fhager", + "version": "1.0", + "author": { "name": "Richard Fhager", "url": "http://hem.fyristorg.com/dawnbringer/" }, + "publisher": "aseprite", + "categories": [ + "Palettes" + ], + "contributes": { + "palettes": [ + { "id": "db16", "path": "./db16.gpl" }, + { "id": "db32", "path": "./db32.gpl" } + ] + } +} diff --git a/data/palettes/arq4.gpl b/data/extensions/endesga-palettes/arq4.gpl similarity index 100% rename from data/palettes/arq4.gpl rename to data/extensions/endesga-palettes/arq4.gpl diff --git a/data/palettes/edg16.gpl b/data/extensions/endesga-palettes/edg16.gpl similarity index 100% rename from data/palettes/edg16.gpl rename to data/extensions/endesga-palettes/edg16.gpl diff --git a/data/palettes/edg32.gpl b/data/extensions/endesga-palettes/edg32.gpl similarity index 100% rename from data/palettes/edg32.gpl rename to data/extensions/endesga-palettes/edg32.gpl diff --git a/data/palettes/edg8.gpl b/data/extensions/endesga-palettes/edg8.gpl similarity index 100% rename from data/palettes/edg8.gpl rename to data/extensions/endesga-palettes/edg8.gpl diff --git a/data/palettes/en4.gpl b/data/extensions/endesga-palettes/en4.gpl similarity index 100% rename from data/palettes/en4.gpl rename to data/extensions/endesga-palettes/en4.gpl diff --git a/data/palettes/enos16.gpl b/data/extensions/endesga-palettes/enos16.gpl similarity index 100% rename from data/palettes/enos16.gpl rename to data/extensions/endesga-palettes/enos16.gpl diff --git a/data/extensions/endesga-palettes/package.json b/data/extensions/endesga-palettes/package.json new file mode 100644 index 000000000..faa0dbcf8 --- /dev/null +++ b/data/extensions/endesga-palettes/package.json @@ -0,0 +1,21 @@ +{ + "name": "endesga-palettes", + "displayName": "ENDESGA Studios Palettes", + "description": "Palettes contributed by ENDESGA Studios", + "version": "1.0", + "author": { "name": "ENDESGA Studios", "url": "https://twitter.com/ENDESGA" }, + "publisher": "aseprite", + "categories": [ + "Palettes" + ], + "contributes": { + "palettes": [ + { "id": "arq4", "path": "./arq4.gpl" }, + { "id": "edg16", "path": "./edg16.gpl" }, + { "id": "edg32", "path": "./edg32.gpl" }, + { "id": "edg8", "path": "./edg8.gpl" }, + { "id": "en4", "path": "./en4.gpl" }, + { "id": "enos16", "path": "./enos16.gpl" } + ] + } +} diff --git a/data/palettes/apple-ii.gpl b/data/extensions/hardware-palettes/apple-ii.gpl similarity index 100% rename from data/palettes/apple-ii.gpl rename to data/extensions/hardware-palettes/apple-ii.gpl diff --git a/data/palettes/atari2600-ntsc.gpl b/data/extensions/hardware-palettes/atari2600-ntsc.gpl similarity index 100% rename from data/palettes/atari2600-ntsc.gpl rename to data/extensions/hardware-palettes/atari2600-ntsc.gpl diff --git a/data/palettes/atari2600-pal.gpl b/data/extensions/hardware-palettes/atari2600-pal.gpl similarity index 100% rename from data/palettes/atari2600-pal.gpl rename to data/extensions/hardware-palettes/atari2600-pal.gpl diff --git a/data/palettes/cga.gpl b/data/extensions/hardware-palettes/cga.gpl similarity index 100% rename from data/palettes/cga.gpl rename to data/extensions/hardware-palettes/cga.gpl diff --git a/data/palettes/cga0.gpl b/data/extensions/hardware-palettes/cga0.gpl similarity index 100% rename from data/palettes/cga0.gpl rename to data/extensions/hardware-palettes/cga0.gpl diff --git a/data/palettes/cga0hi.gpl b/data/extensions/hardware-palettes/cga0hi.gpl similarity index 100% rename from data/palettes/cga0hi.gpl rename to data/extensions/hardware-palettes/cga0hi.gpl diff --git a/data/palettes/cga1.gpl b/data/extensions/hardware-palettes/cga1.gpl similarity index 100% rename from data/palettes/cga1.gpl rename to data/extensions/hardware-palettes/cga1.gpl diff --git a/data/palettes/cga1hi.gpl b/data/extensions/hardware-palettes/cga1hi.gpl similarity index 100% rename from data/palettes/cga1hi.gpl rename to data/extensions/hardware-palettes/cga1hi.gpl diff --git a/data/palettes/cga3rd.gpl b/data/extensions/hardware-palettes/cga3rd.gpl similarity index 100% rename from data/palettes/cga3rd.gpl rename to data/extensions/hardware-palettes/cga3rd.gpl diff --git a/data/palettes/cga3rdhi.gpl b/data/extensions/hardware-palettes/cga3rdhi.gpl similarity index 100% rename from data/palettes/cga3rdhi.gpl rename to data/extensions/hardware-palettes/cga3rdhi.gpl diff --git a/data/palettes/commodore-plus4.gpl b/data/extensions/hardware-palettes/commodore-plus4.gpl similarity index 100% rename from data/palettes/commodore-plus4.gpl rename to data/extensions/hardware-palettes/commodore-plus4.gpl diff --git a/data/palettes/commodore-vic20.gpl b/data/extensions/hardware-palettes/commodore-vic20.gpl similarity index 100% rename from data/palettes/commodore-vic20.gpl rename to data/extensions/hardware-palettes/commodore-vic20.gpl diff --git a/data/palettes/commodore64.gpl b/data/extensions/hardware-palettes/commodore64.gpl similarity index 100% rename from data/palettes/commodore64.gpl rename to data/extensions/hardware-palettes/commodore64.gpl diff --git a/data/palettes/cpc.gpl b/data/extensions/hardware-palettes/cpc.gpl similarity index 100% rename from data/palettes/cpc.gpl rename to data/extensions/hardware-palettes/cpc.gpl diff --git a/data/palettes/gameboy-color-type1.gpl b/data/extensions/hardware-palettes/gameboy-color-type1.gpl similarity index 100% rename from data/palettes/gameboy-color-type1.gpl rename to data/extensions/hardware-palettes/gameboy-color-type1.gpl diff --git a/data/palettes/gameboy.gpl b/data/extensions/hardware-palettes/gameboy.gpl similarity index 100% rename from data/palettes/gameboy.gpl rename to data/extensions/hardware-palettes/gameboy.gpl diff --git a/data/palettes/master-system.gpl b/data/extensions/hardware-palettes/master-system.gpl similarity index 100% rename from data/palettes/master-system.gpl rename to data/extensions/hardware-palettes/master-system.gpl diff --git a/data/palettes/nes-ntsc.gpl b/data/extensions/hardware-palettes/nes-ntsc.gpl similarity index 100% rename from data/palettes/nes-ntsc.gpl rename to data/extensions/hardware-palettes/nes-ntsc.gpl diff --git a/data/palettes/nes.gpl b/data/extensions/hardware-palettes/nes.gpl similarity index 100% rename from data/palettes/nes.gpl rename to data/extensions/hardware-palettes/nes.gpl diff --git a/data/extensions/hardware-palettes/package.json b/data/extensions/hardware-palettes/package.json new file mode 100644 index 000000000..4ff009d7d --- /dev/null +++ b/data/extensions/hardware-palettes/package.json @@ -0,0 +1,36 @@ +{ + "name": "harware-palettes", + "displayName": "Hardware Palettes", + "description": "Well-known palettes from old computer hardware", + "version": "1.0", + "publisher": "aseprite", + "categories": [ + "Palettes" + ], + "contributes": { + "palettes": [ + { "id": "apple-ii", "path": "./apple-ii.gpl" }, + { "id": "atari2600-ntsc", "path": "./atari2600-ntsc.gpl" }, + { "id": "atari2600-pal", "path": "./atari2600-pal.gpl" }, + { "id": "cga", "path": "./cga.gpl" }, + { "id": "cga0", "path": "./cga0.gpl" }, + { "id": "cga0hi", "path": "./cga0hi.gpl" }, + { "id": "cga1", "path": "./cga1.gpl" }, + { "id": "cga1hi", "path": "./cga1hi.gpl" }, + { "id": "cga3rd", "path": "./cga3rd.gpl" }, + { "id": "cga3rdhi", "path": "./cga3rdhi.gpl" }, + { "id": "commodore-plus4", "path": "./commodore-plus4.gpl" }, + { "id": "commodore-vic20", "path": "./commodore-vic20.gpl" }, + { "id": "commodore64", "path": "./commodore64.gpl" }, + { "id": "cpc", "path": "./cpc.gpl" }, + { "id": "gameboy-color-type1", "path": "./gameboy-color-type1.gpl" }, + { "id": "gameboy", "path": "./gameboy.gpl" }, + { "id": "master-system", "path": "./master-system.gpl" }, + { "id": "nes-ntsc", "path": "./nes-ntsc.gpl" }, + { "id": "nes", "path": "./nes.gpl" }, + { "id": "teletext", "path": "./teletext.gpl" }, + { "id": "vga-13h", "path": "./vga-13h.gpl" }, + { "id": "zx-spectrum", "path": "./zx-spectrum.gpl" } + ] + } +} diff --git a/data/palettes/teletext.gpl b/data/extensions/hardware-palettes/teletext.gpl similarity index 100% rename from data/palettes/teletext.gpl rename to data/extensions/hardware-palettes/teletext.gpl diff --git a/data/palettes/vga-13h.gpl b/data/extensions/hardware-palettes/vga-13h.gpl similarity index 100% rename from data/palettes/vga-13h.gpl rename to data/extensions/hardware-palettes/vga-13h.gpl diff --git a/data/palettes/zx-spectrum.gpl b/data/extensions/hardware-palettes/zx-spectrum.gpl similarity index 100% rename from data/palettes/zx-spectrum.gpl rename to data/extensions/hardware-palettes/zx-spectrum.gpl diff --git a/data/palettes/mail24.gpl b/data/extensions/hyohnoo-palettes/mail24.gpl similarity index 100% rename from data/palettes/mail24.gpl rename to data/extensions/hyohnoo-palettes/mail24.gpl diff --git a/data/extensions/hyohnoo-palettes/package.json b/data/extensions/hyohnoo-palettes/package.json new file mode 100644 index 000000000..3e0fbd5ac --- /dev/null +++ b/data/extensions/hyohnoo-palettes/package.json @@ -0,0 +1,16 @@ +{ + "name": "hyohnoo-palettes", + "displayName": "Hyohnoo Palettes", + "description": "Palettes contributed by Hyohnoo", + "version": "1.0", + "author": { "name": "Hyohnoo", "url": "https://twitter.com/Hyohnoo" }, + "publisher": "aseprite", + "categories": [ + "Palettes" + ], + "contributes": { + "palettes": [ + { "id": "mail24", "path": "./mail24.gpl" } + ] + } +} diff --git a/data/palettes/nyx8.gpl b/data/extensions/javierguerrero-palettes/nyx8.gpl similarity index 100% rename from data/palettes/nyx8.gpl rename to data/extensions/javierguerrero-palettes/nyx8.gpl diff --git a/data/extensions/javierguerrero-palettes/package.json b/data/extensions/javierguerrero-palettes/package.json new file mode 100644 index 000000000..0ec1c37db --- /dev/null +++ b/data/extensions/javierguerrero-palettes/package.json @@ -0,0 +1,16 @@ +{ + "name": "javierguerrero-palettes", + "displayName": "Javier Guerrero Palettes", + "description": "Palettes contributed by Javier Guerrero", + "version": "1.0", + "author": { "name": "Javier Guerrero", "url": "https://twitter.com/Xavier_Gd" }, + "publisher": "aseprite", + "categories": [ + "Palettes" + ], + "contributes": { + "palettes": [ + { "id": "nyx8", "path": "./nyx8.gpl" } + ] + } +} diff --git a/data/extensions/pico8-palette/package.json b/data/extensions/pico8-palette/package.json new file mode 100644 index 000000000..435c73c72 --- /dev/null +++ b/data/extensions/pico8-palette/package.json @@ -0,0 +1,16 @@ +{ + "name": "pico8-palettes", + "displayName": "PICO-8 Palette", + "description": "Palettes from PICO-8 created by Joseph White", + "version": "1.0", + "author": { "name": "Joseph White", "url": "http://www.pico-8.com/" }, + "publisher": "aseprite", + "categories": [ + "Palettes" + ], + "contributes": { + "palettes": [ + { "id": "pico-8", "path": "./pico-8.gpl" } + ] + } +} diff --git a/data/palettes/pico-8.gpl b/data/extensions/pico8-palette/pico-8.gpl similarity index 100% rename from data/palettes/pico-8.gpl rename to data/extensions/pico8-palette/pico-8.gpl diff --git a/data/palettes/google-ui.gpl b/data/extensions/software-palettes/google-ui.gpl similarity index 100% rename from data/palettes/google-ui.gpl rename to data/extensions/software-palettes/google-ui.gpl diff --git a/data/palettes/monokai.gpl b/data/extensions/software-palettes/monokai.gpl similarity index 100% rename from data/palettes/monokai.gpl rename to data/extensions/software-palettes/monokai.gpl diff --git a/data/extensions/software-palettes/package.json b/data/extensions/software-palettes/package.json new file mode 100644 index 000000000..d98c065bd --- /dev/null +++ b/data/extensions/software-palettes/package.json @@ -0,0 +1,21 @@ +{ + "name": "software-palettes", + "displayName": "Software Palettes", + "description": "Well-known palettes from software developers", + "version": "1.0", + "publisher": "aseprite", + "categories": [ + "Palettes" + ], + "contributes": { + "palettes": [ + { "id": "google-ui", "path": "./google-ui.gpl" }, + { "id": "monokai", "path": "./monokai.gpl" }, + { "id": "smile-basic", "path": "./smile-basic.gpl" }, + { "id": "solarized", "path": "./solarized.gpl" }, + { "id": "web-safe-colors", "path": "./web-safe-colors.gpl" }, + { "id": "win16", "path": "./win16.gpl" }, + { "id": "x11", "path": "./x11.gpl" } + ] + } +} diff --git a/data/palettes/smile-basic.gpl b/data/extensions/software-palettes/smile-basic.gpl similarity index 100% rename from data/palettes/smile-basic.gpl rename to data/extensions/software-palettes/smile-basic.gpl diff --git a/data/palettes/solarized.gpl b/data/extensions/software-palettes/solarized.gpl similarity index 100% rename from data/palettes/solarized.gpl rename to data/extensions/software-palettes/solarized.gpl diff --git a/data/palettes/web-safe-colors.gpl b/data/extensions/software-palettes/web-safe-colors.gpl similarity index 100% rename from data/palettes/web-safe-colors.gpl rename to data/extensions/software-palettes/web-safe-colors.gpl diff --git a/data/palettes/win16.gpl b/data/extensions/software-palettes/win16.gpl similarity index 100% rename from data/palettes/win16.gpl rename to data/extensions/software-palettes/win16.gpl diff --git a/data/palettes/x11.gpl b/data/extensions/software-palettes/x11.gpl similarity index 100% rename from data/palettes/x11.gpl rename to data/extensions/software-palettes/x11.gpl diff --git a/src/app/extensions.cpp b/src/app/extensions.cpp index 1e3adc196..1b85bacd8 100644 --- a/src/app/extensions.cpp +++ b/src/app/extensions.cpp @@ -113,6 +113,11 @@ std::string Extensions::themePath(const std::string& themeId) return std::string(); } +const std::map& Extensions::palettes() const +{ + return m_palettes; +} + Extension* Extensions::loadExtension(const std::string& path, const std::string& fullPackageFilename, const bool isBuiltinExtension) @@ -132,39 +137,46 @@ Extension* Extensions::loadExtension(const std::string& path, auto contributes = json["contributes"]; if (contributes.is_object()) { + // Themes auto themes = contributes["themes"]; if (themes.is_array()) { for (const auto& theme : themes.get_array()) { - auto jsonThemeId = theme.at("id"); - auto jsonThemePath = theme.at("path"); + std::string themeId = theme.at("id").get_string(); + std::string themePath = theme.at("path").get_string(); - if (!jsonThemeId.is_string()) { - LOG("EXT: A theme doesn't have 'id' property\n"); - } - else if (!jsonThemePath.is_string()) { - LOG("EXT: Theme '%s' doesn't have 'path' property\n", - jsonThemeId.get_string().c_str()); + // The path must be always relative to the extension + themePath = base::join_path(path, themePath); + + LOG("EXT: New theme '%s' in '%s'\n", + themeId.c_str(), + themePath.c_str()); + + if (isBuiltinExtension) { + m_builtinThemes[themeId] = themePath; } else { - std::string themeId = jsonThemeId.get_string(); - std::string themePath = jsonThemePath.get_string(); - - // The path must be always relative to the extension - themePath = base::join_path(path, themePath); - - LOG("EXT: New theme '%s' in '%s'\n", - themeId.c_str(), - themePath.c_str()); - - if (isBuiltinExtension) { - m_builtinThemes[themeId] = themePath; - } - else { - m_userThemes[themeId] = themePath; - } + m_userThemes[themeId] = themePath; } } } + + // Palettes + auto palettes = contributes["palettes"]; + if (palettes.is_array()) { + for (const auto& palette : palettes.get_array()) { + std::string palId = palette.at("id").get_string(); + std::string palPath = palette.at("path").get_string(); + + // The path must be always relative to the extension + palPath = base::join_path(path, palPath); + + LOG("EXT: New palette '%s' in '%s'\n", + palId.c_str(), + palPath.c_str()); + + m_palettes[palId] = palPath; + } + } } return extension.release(); diff --git a/src/app/extensions.h b/src/app/extensions.h index 7b29f27c9..3f3044bdf 100644 --- a/src/app/extensions.h +++ b/src/app/extensions.h @@ -67,6 +67,7 @@ namespace app { void installCompressedExtension(const std::string& zipFn); std::string themePath(const std::string& themeId); + const std::map& palettes() const; private: Extension* loadExtension(const std::string& path, @@ -78,6 +79,8 @@ namespace app { // Key=theme id, Value=theme path std::map m_builtinThemes; std::map m_userThemes; + + std::map m_palettes; }; } // namespace app diff --git a/src/app/res/palette_resource.h b/src/app/res/palette_resource.h index bcc4adfff..d2e778468 100644 --- a/src/app/res/palette_resource.h +++ b/src/app/res/palette_resource.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2015 David Capello +// Copyright (C) 2001-2017 David Capello // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -18,17 +18,17 @@ namespace app { class PaletteResource : public Resource { public: - PaletteResource(doc::Palette* palette, const std::string& name) - : m_palette(palette) - , m_name(name) { + PaletteResource(const std::string& id, doc::Palette* palette) + : m_id(id) + , m_palette(palette) { } virtual ~PaletteResource() { } + virtual const std::string& id() const override { return m_id; } virtual doc::Palette* palette() { return m_palette; } - virtual const std::string& name() const override { return m_name; } private: + std::string m_id; doc::Palette* m_palette; - std::string m_name; }; } // namespace app diff --git a/src/app/res/palettes_loader_delegate.cpp b/src/app/res/palettes_loader_delegate.cpp index b8eb65752..521710b1f 100644 --- a/src/app/res/palettes_loader_delegate.cpp +++ b/src/app/res/palettes_loader_delegate.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2016 David Capello +// Copyright (C) 2001-2017 David Capello // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -10,6 +10,8 @@ #include "app/res/palettes_loader_delegate.h" +#include "app/app.h" +#include "app/extensions.h" #include "app/file/palette_file.h" #include "app/file_system.h" #include "app/res/palette_resource.h" @@ -35,13 +37,19 @@ std::string PalettesLoaderDelegate::resourcesLocation() const return base::fix_path_separators(path); } -Resource* PalettesLoaderDelegate::loadResource(const std::string& filename) +const std::map& PalettesLoaderDelegate::extensionResources() const { - doc::Palette* palette = load_palette(filename.c_str()); - if (!palette) - return NULL; + return App::instance()->extensions().palettes(); +} - return new PaletteResource(palette, base::get_file_title(filename)); +Resource* PalettesLoaderDelegate::loadResource(const std::string& id, + const std::string& path) +{ + doc::Palette* palette = load_palette(path.c_str()); + if (palette) + return new PaletteResource(id, palette); + else + return nullptr; } } // namespace app diff --git a/src/app/res/palettes_loader_delegate.h b/src/app/res/palettes_loader_delegate.h index e38a38fd9..202d6d1d6 100644 --- a/src/app/res/palettes_loader_delegate.h +++ b/src/app/res/palettes_loader_delegate.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2015 David Capello +// Copyright (C) 2001-2017 David Capello // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -16,7 +16,9 @@ namespace app { public: // ResourcesLoaderDelegate impl virtual std::string resourcesLocation() const override; - virtual Resource* loadResource(const std::string& filename) override; + virtual const std::map& extensionResources() const override; + virtual Resource* loadResource(const std::string& id, + const std::string& path) override; }; } // namespace app diff --git a/src/app/res/resource.h b/src/app/res/resource.h index 8853157ad..fa7bbb372 100644 --- a/src/app/res/resource.h +++ b/src/app/res/resource.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2015 David Capello +// Copyright (C) 2001-2017 David Capello // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -13,7 +13,7 @@ namespace app { class Resource { public: virtual ~Resource() { } - virtual const std::string& name() const = 0; + virtual const std::string& id() const = 0; }; } // namespace app diff --git a/src/app/res/resources_loader.cpp b/src/app/res/resources_loader.cpp index 760f1d7d6..c1f839cf8 100644 --- a/src/app/res/resources_loader.cpp +++ b/src/app/res/resources_loader.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2016 David Capello +// Copyright (C) 2001-2017 David Capello // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -65,12 +65,27 @@ void ResourcesLoader::threadLoadResources() if (!item) return; + // Load resources from a fixed location FileItemList list = item->children(); for (auto child : list) { if (m_cancel) break; - Resource* resource = m_delegate->loadResource((child)->fileName()); + Resource* resource = + m_delegate->loadResource(base::get_file_title(child->fileName()), + child->fileName()); + if (resource) + m_queue.push(resource); + } + + // Load resources from extensions + for (const auto& idAndPath : m_delegate->extensionResources()) { + if (m_cancel) + break; + + Resource* resource = + m_delegate->loadResource(idAndPath.first, + idAndPath.second); if (resource) m_queue.push(resource); } diff --git a/src/app/res/resources_loader_delegate.h b/src/app/res/resources_loader_delegate.h index bd535aefe..3ee29dcab 100644 --- a/src/app/res/resources_loader_delegate.h +++ b/src/app/res/resources_loader_delegate.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2015 David Capello +// Copyright (C) 2001-2017 David Capello // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -8,6 +8,7 @@ #define APP_RES_RESOURCES_LOADER_DELEGATE_H_INCLUDED #pragma once +#include #include namespace app { @@ -18,7 +19,9 @@ namespace app { public: virtual ~ResourcesLoaderDelegate() { } virtual std::string resourcesLocation() const = 0; - virtual Resource* loadResource(const std::string& filename) = 0; + virtual const std::map& extensionResources() const = 0; + virtual Resource* loadResource(const std::string& id, + const std::string& path) = 0; }; } // namespace app diff --git a/src/app/ui/resources_listbox.cpp b/src/app/ui/resources_listbox.cpp index 52ee7b935..5ab66da9b 100644 --- a/src/app/ui/resources_listbox.cpp +++ b/src/app/ui/resources_listbox.cpp @@ -29,7 +29,7 @@ using namespace skin; // ResourceListItem ResourceListItem::ResourceListItem(Resource* resource) - : ListItem(resource->name()), m_resource(resource) + : ListItem(resource->id()), m_resource(resource) { }