Compare commits
8 Commits
release-d2
...
release-d2
Author | SHA1 | Date | |
---|---|---|---|
fd2fb6e0c1 | |||
449022f9ae | |||
6898f8eda1 | |||
1f5c5a72ef | |||
a18c5d9294 | |||
c753881747 | |||
ba1bf950a8 | |||
95950441d1 |
6
deps/ox/src/ox/model/typestore.hpp
vendored
6
deps/ox/src/ox/model/typestore.hpp
vendored
@ -58,7 +58,11 @@ class TypeStore {
|
|||||||
if (!std::is_constant_evaluated()) {
|
if (!std::is_constant_evaluated()) {
|
||||||
OX_REQUIRE_M(dt, loadDescriptor(typeId));
|
OX_REQUIRE_M(dt, loadDescriptor(typeId));
|
||||||
for (auto &f : dt->fieldList) {
|
for (auto &f : dt->fieldList) {
|
||||||
OX_RETURN_ERROR(this->getLoad(f.typeId).moveTo(f.type));
|
if (typeId == f.typeId) {
|
||||||
|
f.type = dt.get();
|
||||||
|
} else {
|
||||||
|
OX_RETURN_ERROR(this->getLoad(f.typeId).moveTo(f.type));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
auto &out = m_cache[typeId];
|
auto &out = m_cache[typeId];
|
||||||
out = std::move(dt);
|
out = std::move(dt);
|
||||||
|
132
deps/ox/src/ox/std/hashmap.hpp
vendored
132
deps/ox/src/ox/std/hashmap.hpp
vendored
@ -11,6 +11,7 @@
|
|||||||
#include "algorithm.hpp"
|
#include "algorithm.hpp"
|
||||||
#include "hash.hpp"
|
#include "hash.hpp"
|
||||||
#include "ignore.hpp"
|
#include "ignore.hpp"
|
||||||
|
#include "optional.hpp"
|
||||||
#include "stringview.hpp"
|
#include "stringview.hpp"
|
||||||
#include "strops.hpp"
|
#include "strops.hpp"
|
||||||
#include "vector.hpp"
|
#include "vector.hpp"
|
||||||
@ -26,11 +27,12 @@ class HashMap {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
struct Pair {
|
struct Pair {
|
||||||
|
UPtr<Pair> next;
|
||||||
K key = {};
|
K key = {};
|
||||||
T value{};
|
T value{};
|
||||||
};
|
};
|
||||||
Vector<K> m_keys;
|
Vector<K> m_keys;
|
||||||
Vector<Pair*> m_pairs;
|
Vector<UPtr<Pair>> m_pairs;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit constexpr HashMap(std::size_t size = 127);
|
explicit constexpr HashMap(std::size_t size = 127);
|
||||||
@ -73,10 +75,10 @@ class HashMap {
|
|||||||
constexpr void expand();
|
constexpr void expand();
|
||||||
|
|
||||||
template<typename KK>
|
template<typename KK>
|
||||||
constexpr Pair *const&access(Vector<Pair*> const&pairs, KK const&key) const;
|
constexpr UPtr<Pair> const &access(Vector<UPtr<Pair>> const &pairs, KK const &key) const;
|
||||||
|
|
||||||
template<typename KK>
|
template<typename KK>
|
||||||
constexpr Pair *&access(Vector<Pair*> &pairs, KK const&key);
|
constexpr UPtr<Pair> &access(Vector<UPtr<Pair>> &pairs, KK const &key);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -85,14 +87,13 @@ constexpr HashMap<K, T>::HashMap(std::size_t size): m_pairs(size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename K, typename T>
|
template<typename K, typename T>
|
||||||
constexpr HashMap<K, T>::HashMap(HashMap<K, T> const&other) {
|
constexpr HashMap<K, T>::HashMap(HashMap const &other) {
|
||||||
m_pairs = other.m_pairs;
|
operator=(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename K, typename T>
|
template<typename K, typename T>
|
||||||
constexpr HashMap<K, T>::HashMap(HashMap<K, T> &&other) noexcept {
|
constexpr HashMap<K, T>::HashMap(HashMap &&other) noexcept {
|
||||||
m_keys = std::move(other.m_keys);
|
operator=(std::move(other));
|
||||||
m_pairs = std::move(other.m_pairs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename K, typename T>
|
template<typename K, typename T>
|
||||||
@ -101,7 +102,7 @@ constexpr HashMap<K, T>::~HashMap() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename K, typename T>
|
template<typename K, typename T>
|
||||||
constexpr bool HashMap<K, T>::operator==(HashMap const&other) const {
|
constexpr bool HashMap<K, T>::operator==(HashMap const &other) const {
|
||||||
if (m_keys != other.m_keys) {
|
if (m_keys != other.m_keys) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -115,19 +116,25 @@ constexpr bool HashMap<K, T>::operator==(HashMap const&other) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename K, typename T>
|
template<typename K, typename T>
|
||||||
constexpr HashMap<K, T> &HashMap<K, T>::operator=(HashMap<K, T> const&other) {
|
constexpr HashMap<K, T> &HashMap<K, T>::operator=(HashMap const &other) {
|
||||||
if (this != &other) {
|
if (this != &other) {
|
||||||
clear();
|
clear();
|
||||||
m_keys = other.m_keys;
|
m_keys = other.m_keys;
|
||||||
m_pairs = other.m_pairs;
|
m_pairs.resize(other.m_pairs.size());
|
||||||
|
for (auto const&k : m_keys) {
|
||||||
|
auto const &src = access(other.m_pairs, k);
|
||||||
|
auto &dst = access(m_pairs, k);
|
||||||
|
dst = ox::make_unique<Pair>();
|
||||||
|
dst->key = src->key;
|
||||||
|
dst->value = src->value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename K, typename T>
|
template<typename K, typename T>
|
||||||
constexpr HashMap<K, T> &HashMap<K, T>::operator=(HashMap<K, T> &&other) noexcept {
|
constexpr HashMap<K, T> &HashMap<K, T>::operator=(HashMap &&other) noexcept {
|
||||||
if (this != &other) {
|
if (this != &other) {
|
||||||
clear();
|
|
||||||
m_keys = std::move(other.m_keys);
|
m_keys = std::move(other.m_keys);
|
||||||
m_pairs = std::move(other.m_pairs);
|
m_pairs = std::move(other.m_pairs);
|
||||||
}
|
}
|
||||||
@ -135,60 +142,52 @@ constexpr HashMap<K, T> &HashMap<K, T>::operator=(HashMap<K, T> &&other) noexcep
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename K, typename T>
|
template<typename K, typename T>
|
||||||
constexpr T &HashMap<K, T>::operator[](MaybeView_t<K> const&k) {
|
constexpr T &HashMap<K, T>::operator[](MaybeView_t<K> const &key) {
|
||||||
auto p = &access(m_pairs, k);
|
auto p = &access(m_pairs, key);
|
||||||
if (*p == nullptr) {
|
if (*p == nullptr) {
|
||||||
if (static_cast<double>(m_pairs.size()) * 0.7 <
|
if (static_cast<double>(m_pairs.size()) * 0.7 <
|
||||||
static_cast<double>(m_keys.size())) {
|
static_cast<double>(m_keys.size())) {
|
||||||
expand();
|
expand();
|
||||||
p = &access(m_pairs, k);
|
p = &access(m_pairs, key);
|
||||||
}
|
}
|
||||||
*p = new Pair;
|
*p = ox::make_unique<Pair>();
|
||||||
(*p)->key = k;
|
(*p)->key = key;
|
||||||
m_keys.emplace_back(k);
|
m_keys.emplace_back(key);
|
||||||
}
|
}
|
||||||
return (*p)->value;
|
return (*p)->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename K, typename T>
|
template<typename K, typename T>
|
||||||
constexpr Result<T*> HashMap<K, T>::at(MaybeView_t<K> const&k) noexcept {
|
constexpr Result<T*> HashMap<K, T>::at(MaybeView_t<K> const &key) noexcept {
|
||||||
auto p = access(m_pairs, k);
|
auto &p = access(m_pairs, key);
|
||||||
if (!p) {
|
if (!p) {
|
||||||
return {nullptr, ox::Error(1, "value not found for given key")};
|
return ox::Error{1, "value not found for given key"};
|
||||||
}
|
}
|
||||||
return &p->value;
|
return &p->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename K, typename T>
|
template<typename K, typename T>
|
||||||
constexpr Result<const T*> HashMap<K, T>::at(MaybeView_t<K> const&k) const noexcept {
|
constexpr Result<const T*> HashMap<K, T>::at(MaybeView_t<K> const &key) const noexcept {
|
||||||
auto p = access(m_pairs, k);
|
auto &p = access(m_pairs, key);
|
||||||
if (!p) {
|
if (!p) {
|
||||||
return {nullptr, ox::Error(1, "value not found for given key")};
|
return ox::Error{1, "value not found for given key"};
|
||||||
}
|
}
|
||||||
return &p->value;
|
return &p->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename K, typename T>
|
template<typename K, typename T>
|
||||||
constexpr void HashMap<K, T>::erase(MaybeView_t<K> const&k) {
|
constexpr void HashMap<K, T>::erase(MaybeView_t<K> const &key) {
|
||||||
if (!contains(k)) {
|
if (!contains(key)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto h = ox::hash<MaybeView_t<K>>{}(k) % m_pairs.size();
|
auto &c = access(m_pairs, key);
|
||||||
while (true) {
|
c = std::move(c->next);
|
||||||
const auto &p = m_pairs[h];
|
std::ignore = m_keys.erase(ox::find(m_keys.begin(), m_keys.end(), key));
|
||||||
if (p == nullptr || p->key == k) {
|
|
||||||
std::ignore = m_pairs.erase(h);
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
h = ox::hash<MaybeView_t<K>>{}(k) % m_pairs.size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::ignore = m_keys.erase(ox::find(m_keys.begin(), m_keys.end(), k));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename K, typename T>
|
template<typename K, typename T>
|
||||||
constexpr bool HashMap<K, T>::contains(MaybeView_t<K> const&k) const noexcept {
|
constexpr bool HashMap<K, T>::contains(MaybeView_t<K> const &key) const noexcept {
|
||||||
return access(m_pairs, k) != nullptr;
|
return access(m_pairs, key).get() != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename K, typename T>
|
template<typename K, typename T>
|
||||||
@ -204,27 +203,26 @@ constexpr Vector<K> const&HashMap<K, T>::keys() const noexcept {
|
|||||||
template<typename K, typename T>
|
template<typename K, typename T>
|
||||||
constexpr Vector<T> HashMap<K, T>::values() const noexcept {
|
constexpr Vector<T> HashMap<K, T>::values() const noexcept {
|
||||||
Vector<T> out;
|
Vector<T> out;
|
||||||
out.reserve(m_pairs.size());
|
out.reserve(m_keys.size());
|
||||||
for (auto const&p : m_pairs) {
|
for (auto const &p : m_pairs) {
|
||||||
out.emplace_back(p->value);
|
if (out) {
|
||||||
|
out.emplace_back(p->value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename K, typename T>
|
template<typename K, typename T>
|
||||||
constexpr void HashMap<K, T>::clear() {
|
constexpr void HashMap<K, T>::clear() {
|
||||||
for (std::size_t i = 0; i < m_pairs.size(); i++) {
|
|
||||||
delete m_pairs[i];
|
|
||||||
}
|
|
||||||
m_pairs.clear();
|
m_pairs.clear();
|
||||||
m_pairs.resize(127);
|
m_pairs.resize(127);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename K, typename T>
|
template<typename K, typename T>
|
||||||
constexpr void HashMap<K, T>::expand() {
|
constexpr void HashMap<K, T>::expand() {
|
||||||
Vector<Pair*> r(m_pairs.size() * 2);
|
Vector<UPtr<Pair>> r{m_pairs.size() * 2};
|
||||||
for (std::size_t i = 0; i < m_keys.size(); ++i) {
|
for (std::size_t i = 0; i < m_keys.size(); ++i) {
|
||||||
auto const&k = m_keys[i];
|
auto const &k = m_keys[i];
|
||||||
access(r, k) = std::move(access(m_pairs, k));
|
access(r, k) = std::move(access(m_pairs, k));
|
||||||
}
|
}
|
||||||
m_pairs = std::move(r);
|
m_pairs = std::move(r);
|
||||||
@ -232,29 +230,39 @@ constexpr void HashMap<K, T>::expand() {
|
|||||||
|
|
||||||
template<typename K, typename T>
|
template<typename K, typename T>
|
||||||
template<typename KK>
|
template<typename KK>
|
||||||
constexpr typename HashMap<K, T>::Pair *const&HashMap<K, T>::access(Vector<Pair*> const&pairs, KK const&k) const {
|
constexpr UPtr<typename HashMap<K, T>::Pair> const &HashMap<K, T>::access(
|
||||||
auto h = static_cast<std::size_t>(ox::hash<KK>{}(k) % pairs.size());
|
Vector<UPtr<Pair>> const& pairs,
|
||||||
|
KK const &key) const {
|
||||||
|
auto const h = static_cast<std::size_t>(ox::hash<KK>{}(key) % pairs.size());
|
||||||
|
auto const &p = *pairs.at(h).unwrap();
|
||||||
|
if (p == nullptr || p->key == key) {
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
auto c = &p->next;
|
||||||
while (true) {
|
while (true) {
|
||||||
auto const&p = *pairs.at(h).unwrap();
|
if (*c == nullptr || (*c)->key == key) {
|
||||||
if (p == nullptr || p->key == k) {
|
return *c;
|
||||||
return p;
|
|
||||||
} else {
|
|
||||||
h = (h + 1) % pairs.size();
|
|
||||||
}
|
}
|
||||||
|
c = &(*c)->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename K, typename T>
|
template<typename K, typename T>
|
||||||
template<typename KK>
|
template<typename KK>
|
||||||
constexpr typename HashMap<K, T>::Pair *&HashMap<K, T>::access(Vector<Pair*> &pairs, KK const&k) {
|
constexpr UPtr<typename HashMap<K, T>::Pair> &HashMap<K, T>::access(
|
||||||
auto h = static_cast<std::size_t>(ox::hash<KK>{}(k) % pairs.size());
|
Vector<UPtr<Pair>> &pairs,
|
||||||
|
KK const &key) {
|
||||||
|
auto const h = static_cast<std::size_t>(ox::hash<KK>{}(key) % pairs.size());
|
||||||
|
auto &p = *pairs.at(h).unwrap();
|
||||||
|
if (p == nullptr || p->key == key) {
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
auto c = &p->next;
|
||||||
while (true) {
|
while (true) {
|
||||||
auto &p = *pairs.at(h).unwrap();
|
if (*c == nullptr || (*c)->key == key) {
|
||||||
if (p == nullptr || p->key == k) {
|
return *c;
|
||||||
return p;
|
|
||||||
} else {
|
|
||||||
h = (h + 1) % pairs.size();
|
|
||||||
}
|
}
|
||||||
|
c = &(*c)->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
deps/ox/src/ox/std/memory.hpp
vendored
4
deps/ox/src/ox/std/memory.hpp
vendored
@ -260,12 +260,12 @@ constexpr bool operator==(const UniquePtr<T> &p1, const UniquePtr<T> &p2) noexce
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr bool operator==(const UniquePtr<T> &p1, std::nullptr_t) noexcept {
|
constexpr bool operator==(const UniquePtr<T> &p1, std::nullptr_t) noexcept {
|
||||||
return p1.get();
|
return p1.get() == nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr bool operator==(std::nullptr_t, const UniquePtr<T> &p2) noexcept {
|
constexpr bool operator==(std::nullptr_t, const UniquePtr<T> &p2) noexcept {
|
||||||
return p2.get();
|
return p2.get() == nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
8
deps/ox/src/ox/std/string.hpp
vendored
8
deps/ox/src/ox/std/string.hpp
vendored
@ -392,7 +392,7 @@ template<std::size_t SmallStringSize_v>
|
|||||||
constexpr BasicString<SmallStringSize_v> BasicString<SmallStringSize_v>::operator+(const char *str) const noexcept {
|
constexpr BasicString<SmallStringSize_v> BasicString<SmallStringSize_v>::operator+(const char *str) const noexcept {
|
||||||
const std::size_t strLen = ox::strlen(str);
|
const std::size_t strLen = ox::strlen(str);
|
||||||
const auto currentLen = len();
|
const auto currentLen = len();
|
||||||
BasicString<SmallStringSize_v> cpy(currentLen + strLen);
|
BasicString<SmallStringSize_v> cpy;
|
||||||
cpy.m_buff.resize(m_buff.size() + strLen);
|
cpy.m_buff.resize(m_buff.size() + strLen);
|
||||||
ox::listcpy(&cpy.m_buff[0], m_buff.data(), currentLen);
|
ox::listcpy(&cpy.m_buff[0], m_buff.data(), currentLen);
|
||||||
ox::listcpy(&cpy.m_buff[currentLen], str, strLen);
|
ox::listcpy(&cpy.m_buff[currentLen], str, strLen);
|
||||||
@ -425,7 +425,8 @@ constexpr BasicString<SmallStringSize_v> BasicString<SmallStringSize_v>::operato
|
|||||||
BasicString<SmallStringSize_v> cpy(currentLen + strLen);
|
BasicString<SmallStringSize_v> cpy(currentLen + strLen);
|
||||||
cpy.m_buff.resize(m_buff.size() + strLen);
|
cpy.m_buff.resize(m_buff.size() + strLen);
|
||||||
ox::listcpy(&cpy.m_buff[0], m_buff.data(), currentLen);
|
ox::listcpy(&cpy.m_buff[0], m_buff.data(), currentLen);
|
||||||
ox::listcpy(&cpy.m_buff[currentLen], src.data(), strLen + 1);
|
ox::listcpy(&cpy.m_buff[currentLen], src.data(), strLen);
|
||||||
|
cpy.m_buff[cpy.m_buff.size() - 1] = 0;
|
||||||
return cpy;
|
return cpy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -436,7 +437,8 @@ constexpr BasicString<SmallStringSize_v> BasicString<SmallStringSize_v>::operato
|
|||||||
BasicString<SmallStringSize_v> cpy(currentLen + strLen);
|
BasicString<SmallStringSize_v> cpy(currentLen + strLen);
|
||||||
cpy.m_buff.resize(m_buff.size() + strLen);
|
cpy.m_buff.resize(m_buff.size() + strLen);
|
||||||
ox::listcpy(&cpy.m_buff[0], m_buff.data(), currentLen);
|
ox::listcpy(&cpy.m_buff[0], m_buff.data(), currentLen);
|
||||||
ox::listcpy(&cpy.m_buff[currentLen], src.data(), strLen + 1);
|
ox::listcpy(&cpy.m_buff[currentLen], src.data(), strLen);
|
||||||
|
cpy.m_buff[cpy.m_buff.size() - 1] = 0;
|
||||||
return cpy;
|
return cpy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
deps/ox/src/ox/std/test/tests.cpp
vendored
10
deps/ox/src/ox/std/test/tests.cpp
vendored
@ -273,6 +273,16 @@ OX_CLANG_NOWARN_END
|
|||||||
si["aoeu"] = 100;
|
si["aoeu"] = 100;
|
||||||
oxAssert(si["asdf"] == 42, "asdf != 42");
|
oxAssert(si["asdf"] == 42, "asdf != 42");
|
||||||
oxAssert(si["aoeu"] == 100, "aoeu != 100");
|
oxAssert(si["aoeu"] == 100, "aoeu != 100");
|
||||||
|
si.erase("asdf");
|
||||||
|
oxAssert(!si.contains("asdf"), "wrongly contains asdf");
|
||||||
|
oxAssert(si.contains("aoeu"), "does not contains aoeu");
|
||||||
|
oxAssert(!si.at("asdf").ok(), "asdf != 0");
|
||||||
|
oxExpect(si["asdf"], 0);
|
||||||
|
oxAssert(si["aoeu"] == 100, "aoeu != 100");
|
||||||
|
auto si2 = si;
|
||||||
|
oxDebugf("{}", si2["asdf"]);
|
||||||
|
oxExpect(si2["asdf"], 0);
|
||||||
|
oxAssert(si2["aoeu"] == 100, "aoeu != 100");
|
||||||
ox::HashMap<int, int> ii;
|
ox::HashMap<int, int> ii;
|
||||||
ii[4] = 42;
|
ii[4] = 42;
|
||||||
ii[5] = 100;
|
ii[5] = 100;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
target_sources(
|
target_sources(
|
||||||
NostalgiaCore-Studio PRIVATE
|
NostalgiaCore-Studio PRIVATE
|
||||||
commands/addcolorcommand.cpp
|
commands/addcolorcommand.cpp
|
||||||
|
commands/addpagecommand.cpp
|
||||||
commands/applycolorallpagescommand.cpp
|
commands/applycolorallpagescommand.cpp
|
||||||
commands/duplicatepagecommand.cpp
|
commands/duplicatepagecommand.cpp
|
||||||
commands/movecolorcommand.cpp
|
commands/movecolorcommand.cpp
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "commands.hpp"
|
||||||
|
|
||||||
|
#include "addpagecommand.hpp"
|
||||||
|
|
||||||
|
namespace nostalgia::core {
|
||||||
|
|
||||||
|
AddPageCommand::AddPageCommand(Palette &pal) noexcept:
|
||||||
|
m_pal(pal) {}
|
||||||
|
|
||||||
|
int AddPageCommand::commandId() const noexcept {
|
||||||
|
return static_cast<int>(PaletteEditorCommandId::AddPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
ox::Error AddPageCommand::redo() noexcept {
|
||||||
|
m_pal.pages.emplace_back(ox::sfmt("Page {}", m_pal.pages.size() + 1), ox::Vector<PaletteColor>{});
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
ox::Error AddPageCommand::undo() noexcept {
|
||||||
|
m_pal.pages.pop_back();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <studio/studio.hpp>
|
||||||
|
|
||||||
|
#include <nostalgia/core/palette.hpp>
|
||||||
|
|
||||||
|
namespace nostalgia::core {
|
||||||
|
|
||||||
|
class AddPageCommand: public studio::UndoCommand {
|
||||||
|
private:
|
||||||
|
Palette &m_pal;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit AddPageCommand(Palette &pal) noexcept;
|
||||||
|
|
||||||
|
~AddPageCommand() noexcept override = default;
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
int commandId() const noexcept final;
|
||||||
|
|
||||||
|
ox::Error redo() noexcept final;
|
||||||
|
|
||||||
|
ox::Error undo() noexcept final;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
@ -9,6 +9,7 @@ namespace nostalgia::core {
|
|||||||
enum class PaletteEditorCommandId {
|
enum class PaletteEditorCommandId {
|
||||||
ApplyColorAllPages,
|
ApplyColorAllPages,
|
||||||
RenamePage,
|
RenamePage,
|
||||||
|
AddPage,
|
||||||
DuplicatePage,
|
DuplicatePage,
|
||||||
RemovePage,
|
RemovePage,
|
||||||
AddColor,
|
AddColor,
|
||||||
|
@ -23,7 +23,7 @@ int DuplicatePageCommand::commandId() const noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ox::Error DuplicatePageCommand::redo() noexcept {
|
ox::Error DuplicatePageCommand::redo() noexcept {
|
||||||
m_pal.pages.emplace(m_dstIdx, "", std::move(m_page));
|
m_pal.pages.emplace(m_dstIdx, ox::sfmt("Page {}", m_pal.pages.size() + 1), std::move(m_page));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <keel/media.hpp>
|
#include <keel/media.hpp>
|
||||||
|
|
||||||
#include "commands/addcolorcommand.hpp"
|
#include "commands/addcolorcommand.hpp"
|
||||||
|
#include "commands/addpagecommand.hpp"
|
||||||
#include "commands/applycolorallpagescommand.hpp"
|
#include "commands/applycolorallpagescommand.hpp"
|
||||||
#include "commands/duplicatepagecommand.hpp"
|
#include "commands/duplicatepagecommand.hpp"
|
||||||
#include "commands/movecolorcommand.hpp"
|
#include "commands/movecolorcommand.hpp"
|
||||||
@ -196,7 +197,11 @@ void PaletteEditorImGui::drawPagesEditor() noexcept {
|
|||||||
constexpr auto toolbarHeight = 40;
|
constexpr auto toolbarHeight = 40;
|
||||||
auto const btnSz = ImVec2{paneSz.x / 4 - 5.5f, 24};
|
auto const btnSz = ImVec2{paneSz.x / 4 - 5.5f, 24};
|
||||||
if (ImGui::Button("Add", btnSz)) {
|
if (ImGui::Button("Add", btnSz)) {
|
||||||
std::ignore = pushCommand<DuplicatePageCommand>(m_pal, 0u, m_pal.pages.size());
|
if (m_pal.pages.empty()) {
|
||||||
|
std::ignore = pushCommand<AddPageCommand>(m_pal);
|
||||||
|
} else {
|
||||||
|
std::ignore = pushCommand<DuplicatePageCommand>(m_pal, 0u, m_pal.pages.size());
|
||||||
|
}
|
||||||
m_page = m_pal.pages.size() - 1;
|
m_page = m_pal.pages.size() - 1;
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
@ -234,7 +234,7 @@ void TileSheetEditorImGui::draw(studio::StudioContext&) noexcept {
|
|||||||
ImGui::BeginChild("SubSheets", {s_palViewWidth - 24, ySize / 2.f}, true);
|
ImGui::BeginChild("SubSheets", {s_palViewWidth - 24, ySize / 2.f}, true);
|
||||||
{
|
{
|
||||||
static constexpr auto btnHeight = ig::BtnSz.y;
|
static constexpr auto btnHeight = ig::BtnSz.y;
|
||||||
auto const btnSize = ImVec2{btnHeight, btnHeight};
|
auto constexpr btnSize = ImVec2{btnHeight, btnHeight};
|
||||||
if (ig::PushButton("+", btnSize)) {
|
if (ig::PushButton("+", btnSize)) {
|
||||||
auto insertOnIdx = m_model.activeSubSheetIdx();
|
auto insertOnIdx = m_model.activeSubSheetIdx();
|
||||||
auto const&parent = m_model.activeSubSheet();
|
auto const&parent = m_model.activeSubSheet();
|
||||||
@ -258,16 +258,19 @@ void TileSheetEditorImGui::draw(studio::StudioContext&) noexcept {
|
|||||||
m_exportMenu.show();
|
m_exportMenu.show();
|
||||||
}
|
}
|
||||||
TileSheet::SubSheetIdx path;
|
TileSheet::SubSheetIdx path;
|
||||||
static constexpr auto flags = ImGuiTableFlags_RowBg | ImGuiTableFlags_NoBordersInBody;
|
static constexpr auto flags =
|
||||||
if (ImGui::BeginTable("Subsheets", 4, flags)) {
|
ImGuiTableFlags_RowBg |
|
||||||
ImGui::TableSetupColumn("Subsheet", ImGuiTableColumnFlags_NoHide);
|
ImGuiTableFlags_NoBordersInBody |
|
||||||
ImGui::TableSetupColumn("ID", ImGuiTableColumnFlags_WidthFixed, 25);
|
ImGuiTableFlags_ScrollY;
|
||||||
ImGui::TableSetupColumn("Columns", ImGuiTableColumnFlags_WidthFixed, 50);
|
if (ImGui::BeginTable("Subsheets", 4, flags)) {
|
||||||
ImGui::TableSetupColumn("Rows", ImGuiTableColumnFlags_WidthFixed, 50);
|
ImGui::TableSetupColumn("Subsheet", ImGuiTableColumnFlags_NoHide);
|
||||||
ImGui::TableHeadersRow();
|
ImGui::TableSetupColumn("ID", ImGuiTableColumnFlags_WidthFixed, 25);
|
||||||
drawSubsheetSelector(m_view.img().subsheet, path);
|
ImGui::TableSetupColumn("Columns", ImGuiTableColumnFlags_WidthFixed, 50);
|
||||||
ImGui::EndTable();
|
ImGui::TableSetupColumn("Rows", ImGuiTableColumnFlags_WidthFixed, 50);
|
||||||
}
|
ImGui::TableHeadersRow();
|
||||||
|
drawSubsheetSelector(m_view.img().subsheet, path);
|
||||||
|
ImGui::EndTable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
}
|
}
|
||||||
@ -462,8 +465,12 @@ void TileSheetEditorImGui::drawPaletteMenu() noexcept {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// header
|
// header
|
||||||
|
auto constexpr palTblFlags =
|
||||||
|
ImGuiTableFlags_RowBg |
|
||||||
|
ImGuiTableFlags_SizingStretchProp |
|
||||||
|
ImGuiTableFlags_ScrollY;
|
||||||
if (ImGui::BeginTable(
|
if (ImGui::BeginTable(
|
||||||
"PaletteTable", 4, ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingStretchProp)) {
|
"PaletteTable", 4, palTblFlags)) {
|
||||||
ImGui::TableSetupColumn("Idx", 0, 0.6f);
|
ImGui::TableSetupColumn("Idx", 0, 0.6f);
|
||||||
ImGui::TableSetupColumn("", 0, 0.22f);
|
ImGui::TableSetupColumn("", 0, 0.22f);
|
||||||
ImGui::TableSetupColumn("Name", 0, 3);
|
ImGui::TableSetupColumn("Name", 0, 3);
|
||||||
|
@ -11,7 +11,7 @@ target_link_libraries(
|
|||||||
|
|
||||||
target_compile_definitions(
|
target_compile_definitions(
|
||||||
NostalgiaStudio PUBLIC
|
NostalgiaStudio PUBLIC
|
||||||
OLYMPIC_APP_VERSION="d2024.12.3"
|
OLYMPIC_APP_VERSION="d2024.12.4"
|
||||||
)
|
)
|
||||||
|
|
||||||
install(
|
install(
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<string>APPL</string>
|
<string>APPL</string>
|
||||||
|
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>0.0.0</string>
|
<string>d2024.12.4</string>
|
||||||
|
|
||||||
<key>LSMinimumSystemVersion</key>
|
<key>LSMinimumSystemVersion</key>
|
||||||
<string>12.0.0</string>
|
<string>12.0.0</string>
|
||||||
@ -30,6 +30,6 @@
|
|||||||
<string>True</string>
|
<string>True</string>
|
||||||
|
|
||||||
<key>NSHumanReadableCopyright</key>
|
<key>NSHumanReadableCopyright</key>
|
||||||
<string>Copyright (c) 2016-2023 Gary Talent <gary@drinkingtea.net></string>
|
<string>Copyright (c) 2016-2025 Gary Talent <gary@drinkingtea.net></string>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
Reference in New Issue
Block a user