Pārlūkot izejas kodu

Minor code updates to use UTF-8 in text files

Ivan Arkhipov 6 gadi atpakaļ
vecāks
revīzija
b9e30aea39
3 mainītis faili ar 11 papildinājumiem un 1 dzēšanām
  1. 4 0
      source/race.cpp
  2. 1 0
      source/racemanager.cpp
  3. 6 1
      source/units/unit.cpp

+ 4 - 0
source/race.cpp

@@ -25,6 +25,7 @@ Race::Race(QString race_name, QObject *parent) : QObject(parent)
     QFile file(":/assets/units/" + race_name + "/units.txt");
     file.open(QIODevice::ReadOnly);
     QTextStream in(&file);
+    in.setCodec("UTF-8");
     QString unit_name = in.readLine();
 
     while (!in.atEnd()) {
@@ -41,11 +42,13 @@ Race::Race(QString race_name, QObject *parent) : QObject(parent)
     QFile file0(":/assets/units/" + race_name + "/racename.txt");
     file0.open(QIODevice::ReadOnly);
     QTextStream in0(&file0);
+    in0.setCodec("UTF-8");
     race_name_ = in0.readLine();
 
     QFile file1(":/assets/units/" + race_name + "/descr.txt");
     file1.open(QIODevice::ReadOnly);
     QTextStream in1(&file1);
+    in1.setCodec("UTF-8");
     race_descr_ = in1.readAll();
 
     race_icon_.load(":/assets/units/" + race_name + "/icon.png");
@@ -72,6 +75,7 @@ Unit* Race::createUnit(QString unit_name) {
     QFile file(":/assets/units/" + race_id_ + "/" + unit_name + "/baseclass.txt");
     file.open(QIODevice::ReadOnly);
     QTextStream in(&file);
+    in.setCodec("UTF-8");
     QString class_id = in.readLine();
     qDebug() << "Creating unit of base class " << class_id << " and major class" <<  race_id_ + "|" + unit_name;
     return units_factory_.createObject<QString>(class_id, race_id_ + "|" + unit_name);

+ 1 - 0
source/racemanager.cpp

@@ -11,6 +11,7 @@ RaceManager::RaceManager(QObject *parent) : QObject(parent)
     QFile file(":/assets/units/races.txt");
     file.open(QIODevice::ReadOnly);
     QTextStream in(&file);
+    in.setCodec("UTF-8");
     QString race_name = in.readLine();
 
     while(!in.atEnd()) {

+ 6 - 1
source/units/unit.cpp

@@ -33,6 +33,7 @@ void Unit::loadUnitName(QString unit_folder) {
     QFile file(unit_folder + "unitname.txt");
     file.open(QIODevice::ReadOnly);
     QTextStream in(&file);
+    in.setCodec("UTF-8");
     unit_name_ = in.readLine();
 }
 
@@ -40,6 +41,7 @@ void Unit::loadUnitDescr(QString unit_folder) {
     QFile file(unit_folder + "descr.txt");
     file.open(QIODevice::ReadOnly);
     QTextStream in(&file);
+    in.setCodec("UTF-8");
     unit_descr_ = in.readAll();
 }
 
@@ -47,6 +49,7 @@ void Unit::loadUnitBaseClass(QString unit_folder) {
     QFile file(unit_folder + "baseclass.txt");
     file.open(QIODevice::ReadOnly);
     QTextStream in(&file);
+    in.setCodec("UTF-8");
     base_class_id_ = in.readLine();
 }
 
@@ -66,6 +69,7 @@ void Unit::loadUnitPrevSpecs(QString unit_folder) {
     QFile file(unit_folder + "prevgrades.txt");
     file.open(QIODevice::ReadOnly);
     QTextStream in(&file);
+    in.setCodec("UTF-8");
     QString line = in.readLine();
     while (!in.atEnd()) {
         parent_specs_.push_back(line);
@@ -80,6 +84,7 @@ void Unit::loadUnitUpgradeSpecs(QString unit_folder) {
     QFile file(unit_folder + "nextgrades.txt");
     file.open(QIODevice::ReadOnly);
     QTextStream in(&file);
+    in.setCodec("UTF-8");
     QString line = in.readLine();
     while (!in.atEnd()) {
         upgrade_specs_.push_back(line);
@@ -195,7 +200,7 @@ void Unit::calculateDamagePerHit() {
 
 double Unit::reduceIncomingDamage(std::string damageType, int damage) { //returns damage after reducing by defence
 	assert("Incorrect damage type in call reduceIncomingDamage(), expected" &&
-		damageType[0] == 'p' || damageType[0] == 'P' || damageType[0] == 'm' || damageType[0] == 'M');
+        (damageType[0] == 'p' || damageType[0] == 'P' || damageType[0] == 'm' || damageType[0] == 'M'));
 	assert("Magic defence of unit is incorrectly high (>40), but must be" && magic_defence_ <= 40);
 	assert("Physic defence of unit is incorrectly high (>40), but must be" && physic_defence_ <= 40);
 	if (damageType[0] == 'p' || damageType[0] == 'P') {