-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_saver.cpp
96 lines (80 loc) · 2.7 KB
/
main_saver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "Pet.hpp"
#include <unistd.h>
#include <QApplication>
#include <QScreen>
#include <QGridLayout>
#include <QMainWindow>
#include "PetsWidget.hpp"
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <iostream>
#include <fstream>
#include "Inventory.hpp"
void loadInventoryFromFile(Inventory *inventory);
int main(int argc, char *argv[])
{
// write own pid into kernel module
pid_t pid = getpid();
std::cout << "my pid is " << pid << "\n";
int fd = open("/dev/kscreensaverlauncher", O_WRONLY);
if (fd < 0)
{
perror("kernel module not loaded to /dev/kscreensaverlauncher. exiting...");
return -1;
}
if (write(fd, &pid, sizeof(pid_t)) != sizeof(pid_t))
{
perror("pid write failed");
return -1;
}
close(fd);
// Set the random seed based on the current time
srand(time(NULL));
QApplication app(argc, argv);
// Create a container widget to hold the pet widgets
QWidget *containerWidget = new QWidget();
containerWidget->setContentsMargins(0, 0, 0, 0);
// containerWidget->setStyleSheet("background-image: url(:sprites/_background.png);");
// containerWidget->setMinimumSize(480, 272);
// Create a grid layout to arrange the pet widgets
QGridLayout *layout = new QGridLayout(containerWidget);
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
// Create the widget
std::vector<Pet> pets = generatePets();
std::vector<Pet> user_list = {};
QObject* nothing = new QObject;
Inventory *inventory = new Inventory(nothing, 10, 7, user_list);
loadInventoryFromFile(inventory);
PetsWidget barn(containerWidget, inventory);
layout->addWidget(&barn);
QMainWindow mainWindow;
mainWindow.setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
mainWindow.setWindowState(Qt::WindowFullScreen);
mainWindow.setCentralWidget(containerWidget);
mainWindow.show();
// Get the available geometry of the primary screen
QScreen *screen = QGuiApplication::primaryScreen();
QRect availableGeometry = screen->availableGeometry();
mainWindow.setGeometry(availableGeometry);
return app.exec();
}
void loadInventoryFromFile(Inventory *inventory)
{
std::ifstream file("inventory.txt");
std::vector<Pet> pets = generatePets();
if (file.is_open())
{
int pet_count, egg_count, coin_count, pet_id;
file >> pet_count >> egg_count >> coin_count;
for (int i = 0; i < pet_count; i++)
{
file >> pet_id;
inventory->user_list.push_back(pets[pet_id]);
}
inventory->setEggCount(egg_count);
inventory->setCoinCount(coin_count);
file.close();
}
}