[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdegames/kpat
From:       Parker Coates <parker.coates () kdemail ! net>
Date:       2012-02-15 4:45:23
Message-ID: 20120215044523.8EE94AC895 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1280171 by coates:

Store the game type by name instead of by numeric ID.

In addition to the history support, a major goal of the new save game
format is to be more human readable. And storing the game type as a
numeric ID is anything but human readable.

 M  +1 -1      dealer.cpp  
 M  +14 -4     mainwindow.cpp  


--- trunk/KDE/kdegames/kpat/dealer.cpp #1280170:1280171
@@ -432,7 +432,7 @@
     xml.writeStartDocument();
 
     xml.writeStartElement( "kpat-game" );
-    xml.writeAttribute( "game-type", QString::number( gameId() ) );
+    xml.writeAttribute( "game-type", m_di->baseIdString() );
     if ( !getGameOptions().isEmpty() )
         xml.writeAttribute( "game-type-options", getGameOptions() );
     xml.writeAttribute( "deal-number", QString::number( gameNumber() ) );
--- trunk/KDE/kdegames/kpat/mainwindow.cpp #1280170:1280171
@@ -841,27 +841,37 @@
         return false;
     }
 
-    bool idOk;
     int gameId = -1;
     bool isOldStyleFile;
 
     if ( xml.name() == "dealer" )
     {
         isOldStyleFile = true;
-        gameId = xml.attributes().value("id").toString().toInt( &idOk );
+        bool ok;
+        int id = xml.attributes().value("id").toString().toInt( &ok );
+        if ( ok )
+            gameId = id;
     }
     else if ( xml.name() == "kpat-game" )
     {
         isOldStyleFile = false;
-        gameId = xml.attributes().value("game-type").toString().toInt( &idOk );
+        QStringRef gameType = xml.attributes().value("game-type");
+        foreach ( const DealerInfo * di, DealerInfoList::self()->games() )
+        {
+            if ( di->baseIdString() == gameType )
+            {
+                gameId = di->baseId();
+                break;
     }
+        }
+    }
     else
     {
         KMessageBox::error( this, i18n("XML file is not a KPat save.") );
         return false;
     }
 
-    if ( !idOk || !m_dealer_map.contains( gameId ) )
+    if ( !m_dealer_map.contains( gameId ) )
     {
         KMessageBox::error( this, i18n("Unrecognized game id.") );
         return false;
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic