20 #include <QTranslator>
24 #include <QCommandLineParser>
33 #include <QCoreApplication>
37 #include "screens/TextScreen.h"
38 #include <QCoreApplication>
41 #include <QApplication>
53 int main(
int argc,
char ** argv) {
54 setlocale(LC_CTYPE,
"C-UTF-8");
55 if ( not QDir::home().mkpath(
".freg") ) {
56 puts(qPrintable( QObject::tr(
"Error creating game home directory") ));
59 if (freopen(qPrintable(
home_path +
"err.txt"),
"wt", stderr) ==
nullptr) {
60 puts(qPrintable( QObject::tr(
61 "Error opening errors.txt, writing errors to standard out.") ));
65 QCoreApplication::setOrganizationName(
"freg-team");
66 QCoreApplication::setApplicationName(
"freg");
67 QCoreApplication::setApplicationVersion(VER);
69 QTranslator translator;
70 translator.load(QString(
":/freg_") +
locale);
71 freg.installTranslator(&translator);
74 QCommandLineParser parser;
75 parser.setApplicationDescription(QObject::tr(
"freg - 3d open world game"));
76 parser.addHelpOption();
77 parser.addVersionOption();
78 const QCommandLineOption ascii(QStringList() <<
"a" <<
"ascii",
79 QObject::tr(
"Use ASCII-characters only and don't animate things."));
80 parser.addOption(ascii);
81 const QCommandLineOption world_argument(QStringList() <<
"w" <<
"world",
82 QObject::tr(
"Specify world."),
83 QObject::tr(
"world_name"));
84 parser.addOption(world_argument);
85 const QCommandLineOption generate(QStringList() <<
"g" <<
"generate",
86 QObject::tr(
"Generate new map."));
87 parser.addOption(generate);
88 const QCommandLineOption map_size(QStringList() <<
"s" <<
"size",
89 QObject::tr(
"Generated map size. Works only with -g."),
91 parser.addOption(map_size);
92 const QCommandLineOption map_outer(QStringList() <<
"o" <<
"outer",
93 QObject::tr(
"Generated map outer shred. Works only with -g."),
95 parser.addOption(map_outer);
96 const QCommandLineOption map_seed(QStringList() <<
"d" <<
"seed",
97 QObject::tr(
"Seed to generate map. Works only with -g."),
98 QObject::tr(
"map_seed"), QString::number(0));
99 parser.addOption(map_seed);
100 parser.process(freg);
102 QSettings::setDefaultFormat(QSettings::IniFormat);
103 QSettings sett(
home_path +
".freg/freg.ini", QSettings::IniFormat);
104 const QString worldName = parser.isSet(world_argument) ?
105 parser.value(world_argument) :
106 sett.value(
"current_world",
"mu").toString();
107 sett.setValue(
"current_world", worldName);
108 if ( not QDir(
home_path).mkpath(worldName) ) {
109 puts(qPrintable(QObject::tr(
"Error generating world.")));
113 if ( parser.isSet(generate) ) {
116 parser.value(map_size).toUShort(),
117 parser.value(map_outer).at(0).toLatin1(),
118 parser.value(map_seed).toInt());
119 puts(qPrintable(QObject::tr(
"Map generated successfully.")));
126 qsrand(QTime::currentTime().msec());
127 bool world_error =
false;
130 puts(qPrintable(QObject::tr(
"Error loading world.")));
133 QLockFile lock_file(
home_path + worldName +
"/lock");
134 if ( not lock_file.tryLock() ) {
136 QObject::tr(
"World \"%1\" is used by another instance of freg.")
143 const Screen screen(&world, &player, error,
true);
145 const Screen screen(&world, &player, error, parser.isSet(ascii));
148 if ( error )
return EXIT_FAILURE;
150 QObject::connect(&screen, SIGNAL(ExitReceived()), &freg, SLOT(quit()),
151 Qt::DirectConnection);
152 QObject::connect(&world, SIGNAL(ExitReceived()), &freg, SLOT(quit()),
153 Qt::DirectConnection);
int main(int argc, char **argv)
World provides global physics and shred connection.
Provides curses (text-based graphics interface) screen for freg.
static void GenerateMap(QString world_name, int size, char outer, int seed)
const CraftManager * craft_manager
This class contains information specific to player and interface for manipulating him...