167 lines
4.8 KiB
C++
167 lines
4.8 KiB
C++
#include "GraphApp.h"
|
|
#include "../Pieces/PiecesFiles.h"
|
|
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
|
|
|
|
void resetSettingsFile();
|
|
void resetKeybindFile(int layout);
|
|
|
|
|
|
int main() {
|
|
std::srand(std::time(NULL));
|
|
|
|
PiecesFiles pf;
|
|
for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) {
|
|
if (!std::filesystem::exists("data/pieces/" + std::to_string(i) + "minos.bin")) {
|
|
std::cout << "pieces files for size " << i << " not found, generating..." << std::endl;
|
|
pf.savePieces(i);
|
|
}
|
|
}
|
|
if (!std::filesystem::exists("data/config/settings.bin")) {
|
|
std::cout << "settings file not found, generating..." << std::endl;
|
|
resetSettingsFile();
|
|
}
|
|
for (int i = 0; i < NUMBER_OF_KEYBINDS; i++) {
|
|
if (!std::filesystem::exists("data/config/keybinds/layout" + std::to_string(i) + ".bin")) {
|
|
std::cout << "keybind file n°" << (i + 1) << "/" << NUMBER_OF_KEYBINDS << " not found, generating..." << std::endl;
|
|
resetKeybindFile(i);
|
|
}
|
|
}
|
|
|
|
GraphApp UI;
|
|
UI.run();
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
void resetSettingsFile() {
|
|
std::ofstream settingsFile("data/config/settings.bin", std::ios::trunc | std::ios::binary);
|
|
char byte;
|
|
|
|
Menu menu;
|
|
|
|
// keybind layout
|
|
byte = 0;
|
|
settingsFile.write(&byte, 1);
|
|
|
|
// DAS tuning
|
|
byte = menu.getPlayerControls().getDAS();
|
|
settingsFile.write(&byte, 1);
|
|
|
|
// ARR tuning
|
|
byte = menu.getPlayerControls().getARR();
|
|
settingsFile.write(&byte, 1);
|
|
|
|
// SDR tuning
|
|
byte = menu.getPlayerControls().getSDR();
|
|
settingsFile.write(&byte, 1);
|
|
|
|
// window size mode
|
|
byte = 2;
|
|
settingsFile.write(&byte, 1);
|
|
|
|
// start timer length
|
|
byte = 2;
|
|
settingsFile.write(&byte, 1);
|
|
|
|
// gamemode
|
|
byte = Gamemode(0);
|
|
settingsFile.write(&byte, 1);
|
|
|
|
// board width
|
|
byte = menu.getBoardWidth();
|
|
settingsFile.write(&byte, 1);
|
|
|
|
// board height
|
|
byte = menu.getBoardHeight();
|
|
settingsFile.write(&byte, 1);
|
|
|
|
// piece distribution
|
|
byte = DEFAULT;
|
|
settingsFile.write(&byte, 1);
|
|
for (int i = 1; i <= 15; i++) {
|
|
byte = 1;
|
|
settingsFile.write(&byte, 1);
|
|
}
|
|
|
|
// selected pieces
|
|
byte = ALL_PIECES;
|
|
settingsFile.write(&byte, 1);
|
|
byte = 4;
|
|
settingsFile.write(&byte, 1);
|
|
}
|
|
|
|
void resetKeybindFile(int layout) {
|
|
if (layout < 0 || layout > 4) return;
|
|
|
|
std::ofstream layoutFile("data/config/keybinds/layout" + std::to_string(layout) + ".bin", std::ios::trunc | std::ios::binary);
|
|
std::map<Action, sfKey> keybinds;
|
|
|
|
if (layout != 4) {
|
|
keybinds.insert({PAUSE, sfKey::P});
|
|
keybinds.insert({RETRY, sfKey::R});
|
|
}
|
|
|
|
if (layout == 0) {
|
|
keybinds.insert({MOVE_LEFT, sfKey::Left});
|
|
keybinds.insert({MOVE_RIGHT, sfKey::Right});
|
|
keybinds.insert({SOFT_DROP, sfKey::Down});
|
|
keybinds.insert({HARD_DROP, sfKey::Space});
|
|
keybinds.insert({ROTATE_CW, sfKey::Up});
|
|
keybinds.insert({ROTATE_CCW, sfKey::Z});
|
|
keybinds.insert({ROTATE_180, sfKey::X});
|
|
keybinds.insert({ROTATE_0, sfKey::LShift});
|
|
keybinds.insert({HOLD, sfKey::C});
|
|
}
|
|
if (layout == 1) {
|
|
keybinds.insert({MOVE_LEFT, sfKey::Z});
|
|
keybinds.insert({MOVE_RIGHT, sfKey::C});
|
|
keybinds.insert({SOFT_DROP, sfKey::X});
|
|
keybinds.insert({HARD_DROP, sfKey::S});
|
|
keybinds.insert({ROTATE_CW, sfKey::M});
|
|
keybinds.insert({ROTATE_CCW, sfKey::Comma});
|
|
keybinds.insert({ROTATE_180, sfKey::J});
|
|
keybinds.insert({ROTATE_0, sfKey::K});
|
|
keybinds.insert({HOLD, sfKey::LShift});
|
|
}
|
|
if (layout == 2) {
|
|
keybinds.insert({MOVE_LEFT, sfKey::A});
|
|
keybinds.insert({MOVE_RIGHT, sfKey::D});
|
|
keybinds.insert({SOFT_DROP, sfKey::W});
|
|
keybinds.insert({HARD_DROP, sfKey::S});
|
|
keybinds.insert({ROTATE_CW, sfKey::Left});
|
|
keybinds.insert({ROTATE_CCW, sfKey::Right});
|
|
keybinds.insert({ROTATE_180, sfKey::Up});
|
|
keybinds.insert({ROTATE_0, sfKey::Down});
|
|
keybinds.insert({HOLD, sfKey::RShift});
|
|
}
|
|
if (layout == 3) {
|
|
keybinds.insert({MOVE_LEFT, sfKey::Left});
|
|
keybinds.insert({MOVE_RIGHT, sfKey::Right});
|
|
keybinds.insert({SOFT_DROP, sfKey::Down});
|
|
keybinds.insert({HARD_DROP, sfKey::Up});
|
|
keybinds.insert({ROTATE_CW, sfKey::E});
|
|
keybinds.insert({ROTATE_CCW, sfKey::A});
|
|
keybinds.insert({ROTATE_180, sfKey::Num2});
|
|
keybinds.insert({ROTATE_0, sfKey::Tab});
|
|
keybinds.insert({HOLD, sfKey::Z});
|
|
}
|
|
|
|
char byte;
|
|
for (Action action : ACTION_LIST_IN_ORDER) {
|
|
byte = action;
|
|
layoutFile.write(&byte, 1);
|
|
|
|
if (keybinds.contains(action)) {
|
|
byte = (int) keybinds.at(action);
|
|
layoutFile.write(&byte, 1);
|
|
}
|
|
|
|
byte = 0xFF;
|
|
layoutFile.write(&byte, 1);
|
|
}
|
|
}
|