Commit f537df3e authored by Yann Boucher's avatar Yann Boucher
Browse files

Fixed a bug in configuration loading, added the Bad Apple easter egg

parent a21ce971
This diff is collapsed.
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>1068</width>
<height>771</height>
<height>800</height>
</rect>
</property>
<property name="windowTitle">
......@@ -570,7 +570,7 @@ pattern recorded :</string>
<x>0</x>
<y>0</y>
<width>1068</width>
<height>22</height>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="menuFichier">
......@@ -592,8 +592,15 @@ pattern recorded :</string>
<addaction name="action_propos_de_Cellulut"/>
<addaction name="action_propos_de_Qt"/>
</widget>
<widget class="QMenu" name="menuBonus">
<property name="title">
<string>Bonus</string>
</property>
<addaction name="action_bad_apple"/>
</widget>
<addaction name="menuFichier"/>
<addaction name="menuEditer"/>
<addaction name="menuBonus"/>
<addaction name="menuA_propos"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
......@@ -620,6 +627,11 @@ pattern recorded :</string>
<string>Charger depuis une image...</string>
</property>
</action>
<action name="action_bad_apple">
<property name="text">
<string>Play &quot;Bad Apple!!&quot; animation</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
......
......@@ -138,6 +138,9 @@ private:
//! \brief Retourne la configuration par défaut à charger
QJsonObject default_configuration() const;
//! \brief Fonction secrète !
void play_bad_apple();
protected:
void closeEvent(QCloseEvent* e) override;
......
......@@ -18,6 +18,7 @@
#include <QTextStream>
#include <QInputDialog>
#include <QTimer>
#include <QMediaPlayer>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
......@@ -48,6 +49,7 @@ MainWindow::MainWindow(QWidget *parent)
});
connect(ui->transition_list, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int)
{ update_transition_settings(); });
connect(ui->action_bad_apple, &QAction::triggered, this, &MainWindow::play_bad_apple);
connect(ui->action_propos_de_Cellulut, &QAction::triggered, this, [this](bool)
{
QMessageBox::about(this, "À propos de Cellulut",
......@@ -573,8 +575,8 @@ void MainWindow::save_grid_configuration()
void MainWindow::load_grid_configuration(const QJsonObject& configuration)
{
Grid g(configuration.value("width").toInt(10),
configuration.value("height").toInt(10));
Grid g(configuration.value("height").toInt(10),
configuration.value("width").toInt(10));
Coord origin;
origin.x = configuration.value("left").toInt(0);
origin.y = configuration.value("top").toInt(0);
......@@ -629,6 +631,67 @@ QJsonObject MainWindow::default_configuration() const
return doc.object();
}
void MainWindow::play_bad_apple()
{
static QJsonArray bad_apple_frame_list;
static QTimer bad_apple_timer;
static bool bad_apple_connected;
static QMediaPlayer bad_apple_player;
QFile f("bad_apple.json");
if (!f.open(QFile::ReadOnly | QFile::Text))
throw ModelLoadingException("Impossible de lire le fichier");
QTextStream in(&f);
QJsonParseError parseError;
QJsonDocument jsonDoc = QJsonDocument::fromJson(in.readAll().toUtf8(), &parseError);
QJsonObject frames = jsonDoc.object();
bad_apple_timer.stop();
bad_apple_frame_list = frames["data"].toArray();
if (!bad_apple_connected)
{
bad_apple_timer.callOnTimeout([this]
{
if (bad_apple_player.mediaStatus() == QMediaPlayer::EndOfMedia)
return;
unsigned frame_idx = bad_apple_player.position()/(1000.f/30);
if ((int)frame_idx >= bad_apple_frame_list.size())
{
bad_apple_timer.stop();
return;
}
Grid grid(120, 160);
QJsonObject frame = bad_apple_frame_list[frame_idx].toObject();
Coord origin;
origin.x = frame.value("left").toInt();
origin.y = frame.value("top").toInt();
RLEStructureReader reader(frame.value("data").toString().toStdString());
Structure s = reader.read_structure();
s.top_left = origin;
for (auto cell : s)
{
grid.set_cell(cell.first + s.top_left, cell.second);
}
ui->grid_view->copy_grid(grid);
});
}
bad_apple_player.setMedia(QUrl::fromLocalFile("bad-apple.mp3"));
bad_apple_player.play();
;
bad_apple_timer.start(24);
statusBar()->showMessage("Original : \"Bad Apple!!\" feat. Nomico by Alstroemeria Records", 60000);
}
void MainWindow::closeEvent(QCloseEvent *e)
{
// Sauvegarder l'état actuel de l'application
......
QT += core gui
QT += core gui multimedia
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment