diff --git a/blueprint.cpp b/blueprint.cpp index 59537b4..35e4a11 100644 --- a/blueprint.cpp +++ b/blueprint.cpp @@ -199,3 +199,56 @@ void Blueprint::generateBlueprintString () const { bpString_ = "VCB+AAAA" + QString::fromLatin1(hashBase64) + QString::fromLatin1(rawBase64); } + + +QString Blueprint::toDiscordEmoji () const { + + static const QMap EmojiMap = { + { And, "and" }, + { Annotation, "ann" }, + { Buffer, "bfr" }, + { Cross, "crs" }, + { Filler, "fil" }, + { LED, "led" }, + { LatchOff, "lt0" }, + { LatchOn, "lt1" }, + { Nand, "nan" }, + { Nor, "nor" }, + { Not, "not" }, + { Or, "or" }, + { Read, "rd" }, + { Write, "wr" }, + { Xnor, "xnr" }, + { Xor, "xor" }, + { Trace1, "t00" }, + { Trace2, "t01" }, + { Trace3, "t02" }, + { Trace4, "t03" }, + { Trace5, "t04" }, + { Trace6, "t05" }, + { Trace7, "t06" }, + { Trace8, "t07" }, + { Trace9, "t08" }, + { Trace10, "t09" }, + { Trace11, "t10" }, + { Trace12, "t11" }, + { Trace13, "t12" }, + { Trace14, "t13" }, + { Trace15, "t14" }, + { Trace16, "t15" }, + { Empty, "pd" } + }; + + QString emojistr = ":pd:\n"; + for (int y = 0; y < height(); ++ y) { + for (int x = 0; x < width(); ++ x) { + Ink ink = get(x, y); + emojistr += ":" + EmojiMap.value(ink, "vcb") + ":"; + } + emojistr += "\n"; + } + + return emojistr; + +} + diff --git a/blueprint.h b/blueprint.h index 9d8cb28..2ce6419 100644 --- a/blueprint.h +++ b/blueprint.h @@ -76,10 +76,25 @@ class Blueprint : public QObject { int height () const { return layers_.first().height(); } Ink getPixel (Layer which, int x, int y) const; Ink get (int x, int y) const { return getPixel(Logic, x, y); } + // utilities + QString toDiscordEmoji () const; private: mutable QString bpString_; QMap layers_; void generateBlueprintString () const; }; +inline bool operator < (const Blueprint::Ink &a, const Blueprint::Ink &b) { + if (a.red() != b.red()) + return a.red() < b.red(); + else if (a.green() != b.green()) + return a.green() < b.green(); + else if (a.blue() != b.blue()) + return a.blue() < b.blue(); + else if (a.alpha() != b.alpha()) + return a.alpha() < b.alpha(); + else + return false; +} + #endif // BLUEPRINT_H diff --git a/compiler.cpp b/compiler.cpp index 56c2998..7092e17 100644 --- a/compiler.cpp +++ b/compiler.cpp @@ -286,19 +286,6 @@ void Compiler::compileBlueprint (const Blueprint *bp) { } -static bool operator < (const QColor &a, const QColor &b) { - if (a.red() != b.red()) - return a.red() < b.red(); - else if (a.green() != b.green()) - return a.green() < b.green(); - else if (a.blue() != b.blue()) - return a.blue() < b.blue(); - else if (a.alpha() != b.alpha()) - return a.alpha() < b.alpha(); - else - return false; -} - Compiler::Component Compiler::Comp (Blueprint::Ink ink) { static const QMap m = { diff --git a/mainwindow.cpp b/mainwindow.cpp index 8994cc7..1663c73 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -110,6 +110,18 @@ void MainWindow::on_btnConvertBP_clicked() } +void MainWindow::on_btnConvertEmoji_clicked() +{ + try { + Blueprint bp(ui_->txtConvertedBP->toPlainText()); + QString emoji = bp.toDiscordEmoji(); + QGuiApplication::clipboard()->setText(emoji); + } catch (const std::exception &x) { + QMessageBox::critical(this, "Error", x.what()); + } +} + + void MainWindow::on_btnLoadROMFile_clicked() { try { diff --git a/mainwindow.h b/mainwindow.h index b53cfef..5d9ae20 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -47,6 +47,8 @@ private slots: void on_btnMiscX11_clicked(); + void on_btnConvertEmoji_clicked(); + private: struct FontDesc { diff --git a/mainwindow.ui b/mainwindow.ui index 66ed674..f655010 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -18,7 +18,7 @@ - 3 + 0 @@ -48,6 +48,13 @@ + + + + Copy As Discord Emoji + + + diff --git a/vcbtool.pro b/vcbtool.pro index e4a7c53..4339bde 100644 --- a/vcbtool.pro +++ b/vcbtool.pro @@ -1,5 +1,5 @@ QMAKE_TARGET_DESCRIPTION = "VCB Tool" -VERSION = 1.7.0 +VERSION = 1.7.1 DEFINES += VCBTOOL_VERSION='\\"$$VERSION\\"' QT += core gui