mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2024-11-17 07:48:27 +01:00
PlayModel now uses a Move internally
This commit is contained in:
parent
8acebbc889
commit
8d85df630b
7 changed files with 51 additions and 31 deletions
|
@ -159,6 +159,12 @@ int PublicGame::play(const wstring &iWord, const wstring &iCoord)
|
|||
}
|
||||
|
||||
|
||||
int PublicGame::checkPlayedWord(const wstring &iWord, const wstring &iCoord, Move &oMove) const
|
||||
{
|
||||
return m_game.checkPlayedWord(iCoord, iWord, oMove, true);
|
||||
}
|
||||
|
||||
|
||||
int PublicGame::computePoints(const wstring &iWord, const wstring &iCoord) const
|
||||
{
|
||||
Move move;
|
||||
|
|
|
@ -158,6 +158,10 @@ public:
|
|||
*/
|
||||
int play(const wstring &iWord, const wstring &iCoord);
|
||||
|
||||
// TODO: doc
|
||||
int checkPlayedWord(const wstring &iWord, const wstring &iCoord,
|
||||
Move &oMove) const;
|
||||
|
||||
/**
|
||||
* Compute the points for playing the word iWord at coordinates iCoord.
|
||||
* A negative return value indicates an error (same codes as for the
|
||||
|
|
|
@ -161,8 +161,9 @@ MainWindow::MainWindow(QWidget *iParent)
|
|||
|
||||
// Rack widget below the board
|
||||
RackWidget *rackWidget = new RackWidget;
|
||||
QObject::connect(&m_playModel, SIGNAL(moveChanged(const wstring&, const Coord&)),
|
||||
rackWidget, SLOT(refresh()));
|
||||
// TODO
|
||||
// QObject::connect(&m_playModel, SIGNAL(moveChanged(const wstring&, const Coord&)),
|
||||
// rackWidget, SLOT(refresh()));
|
||||
rackWidget->setFrameStyle(QFrame::WinPanel | QFrame::Raised);
|
||||
QObject::connect(this, SIGNAL(gameChanged(const PublicGame*)),
|
||||
rackWidget, SLOT(setGame(const PublicGame*)));
|
||||
|
|
|
@ -20,23 +20,22 @@
|
|||
|
||||
#include "play_model.h"
|
||||
|
||||
#include "encoding.h"
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
INIT_LOGGER(qt, PlayModel);
|
||||
|
||||
|
||||
PlayModel::PlayModel()
|
||||
{
|
||||
QObject::connect(this, SIGNAL(coordChanged(const Coord&, const Coord&)),
|
||||
this, SLOT(onMoveChanged()));
|
||||
QObject::connect(this, SIGNAL(wordChanged(const wstring&, const wstring&)),
|
||||
this, SLOT(onMoveChanged()));
|
||||
}
|
||||
|
||||
|
||||
void PlayModel::clear()
|
||||
{
|
||||
setCoord(Coord());
|
||||
setWord(L"");
|
||||
setMove(Move());
|
||||
}
|
||||
|
||||
|
||||
|
@ -52,20 +51,20 @@ void PlayModel::setCoord(const Coord &iCoord)
|
|||
}
|
||||
|
||||
|
||||
void PlayModel::setWord(const wstring &iWord)
|
||||
void PlayModel::setMove(const Move &iMove)
|
||||
{
|
||||
ASSERT(iMove.isValid() || iMove.isInvalid() || iMove.isNull(),
|
||||
"Unexpected move type");
|
||||
|
||||
LOG_DEBUG("Setting PlayModel move to " << lfw(iMove.toString()));
|
||||
|
||||
// Avoid useless work
|
||||
if (iWord == m_currWord)
|
||||
return;
|
||||
// TODO
|
||||
//if (iMove == m_currMove)
|
||||
// return;
|
||||
|
||||
m_prevWord = m_currWord;
|
||||
m_currWord = iWord;
|
||||
emit wordChanged(iWord, m_prevWord);
|
||||
}
|
||||
|
||||
|
||||
void PlayModel::onMoveChanged()
|
||||
{
|
||||
emit moveChanged(m_currWord, m_currCoord);
|
||||
m_prevMove = m_currMove;
|
||||
m_currMove = iMove;
|
||||
emit moveChanged(iMove, m_prevMove);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <QObject>
|
||||
|
||||
#include "coord.h"
|
||||
#include "move.h"
|
||||
#include "logging.h"
|
||||
|
||||
using std::wstring;
|
||||
|
@ -58,24 +59,19 @@ public:
|
|||
void setCoord(const Coord &iCoord);
|
||||
const Coord & getCoord() const { return m_currCoord; }
|
||||
|
||||
void setWord(const wstring &iWord);
|
||||
const wstring & getWord() const { return m_currWord; }
|
||||
void setMove(const Move &iMove);
|
||||
const Move &getMove() const { return m_currMove; }
|
||||
|
||||
signals:
|
||||
void coordChanged(const Coord &iNewCoord, const Coord &iOldCoord);
|
||||
void wordChanged(const wstring &iNewWord, const wstring &iOldWord);
|
||||
/// Emitted whenever coordChanged() or wordChanged() is emitted
|
||||
void moveChanged(const wstring &iWord, const Coord &iCoord);
|
||||
|
||||
private slots:
|
||||
void onMoveChanged();
|
||||
void moveChanged(const Move &iMove, const Move &iOldMove);
|
||||
|
||||
private:
|
||||
Coord m_currCoord;
|
||||
Coord m_prevCoord;
|
||||
|
||||
wstring m_currWord;
|
||||
wstring m_prevWord;
|
||||
Move m_currMove;
|
||||
Move m_prevMove;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -54,7 +54,7 @@ PlayWordMediator::PlayWordMediator(QObject *parent, QLineEdit &iEditPlay,
|
|||
|
||||
// Set all the connections
|
||||
QObject::connect(&m_lineEditPlay, SIGNAL(textChanged(const QString&)),
|
||||
this, SLOT(updatePointsAndState()));
|
||||
this, SLOT(onWordChanged(const QString&)));
|
||||
QObject::connect(&m_lineEditPlay, SIGNAL(returnPressed()),
|
||||
this, SLOT(playWord()));
|
||||
QObject::connect(&m_lineEditCoord, SIGNAL(textChanged(const QString&)),
|
||||
|
@ -106,7 +106,8 @@ bool PlayWordMediator::GetPlayedWord(QLineEdit &iEditWord,
|
|||
{
|
||||
// Cannot parse the string...
|
||||
*oPlayedWord = wfq(word);
|
||||
*oProblemCause = _q("Cannot play word: misplaced parentheses");
|
||||
if (oProblemCause)
|
||||
*oProblemCause = _q("Cannot play word: misplaced parentheses");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -219,6 +220,18 @@ void PlayWordMediator::onCoordChanged(const QString &iText)
|
|||
}
|
||||
|
||||
|
||||
void PlayWordMediator::onWordChanged(const QString &iText)
|
||||
{
|
||||
wstring playedWord;
|
||||
GetPlayedWord(m_lineEditPlay, m_game->getDic(), &playedWord, NULL);
|
||||
|
||||
Move move;
|
||||
m_game->checkPlayedWord(playedWord, wfq(m_lineEditCoord.text()), move);
|
||||
m_playModel.setMove(move);
|
||||
updatePointsAndState();
|
||||
}
|
||||
|
||||
|
||||
void PlayWordMediator::updateCoord(const Coord &iNewCoord)
|
||||
{
|
||||
// Ignore updates to non-visible controls (which happens when there
|
||||
|
|
|
@ -91,6 +91,7 @@ private slots:
|
|||
void playWord();
|
||||
void updatePointsAndState();
|
||||
void onCoordChanged(const QString &iText);
|
||||
void onWordChanged(const QString &iText);
|
||||
void updateCoord(const Coord &iNewCoord);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in a new issue