Move palettes to extensions (#1403)

master
David Capello 2017-06-10 16:44:19 -03:00
parent 199f56a5ad
commit b7b69ce538
69 changed files with 271 additions and 45 deletions

View File

@ -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" }
]
}
}

View File

@ -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" }
]
}
}

View File

@ -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" }
]
}
}

View File

@ -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" }
]
}
}

View File

@ -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" }
]
}
}

View File

@ -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" }
]
}
}

View File

@ -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" }
]
}
}

View File

@ -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" }
]
}
}

View File

@ -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" }
]
}
}

View File

@ -113,6 +113,11 @@ std::string Extensions::themePath(const std::string& themeId)
return std::string();
}
const std::map<std::string, std::string>& 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();

View File

@ -67,6 +67,7 @@ namespace app {
void installCompressedExtension(const std::string& zipFn);
std::string themePath(const std::string& themeId);
const std::map<std::string, std::string>& palettes() const;
private:
Extension* loadExtension(const std::string& path,
@ -78,6 +79,8 @@ namespace app {
// Key=theme id, Value=theme path
std::map<std::string, std::string> m_builtinThemes;
std::map<std::string, std::string> m_userThemes;
std::map<std::string, std::string> m_palettes;
};
} // namespace app

View File

@ -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

View File

@ -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<std::string, std::string>& 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

View File

@ -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<std::string, std::string>& extensionResources() const override;
virtual Resource* loadResource(const std::string& id,
const std::string& path) override;
};
} // namespace app

View File

@ -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

View File

@ -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);
}

View File

@ -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 <map>
#include <string>
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<std::string, std::string>& extensionResources() const = 0;
virtual Resource* loadResource(const std::string& id,
const std::string& path) = 0;
};
} // namespace app

View File

@ -29,7 +29,7 @@ using namespace skin;
// ResourceListItem
ResourceListItem::ResourceListItem(Resource* resource)
: ListItem(resource->name()), m_resource(resource)
: ListItem(resource->id()), m_resource(resource)
{
}