Skip to content

Commit

Permalink
番数数据类型改为uint16_t
Browse files Browse the repository at this point in the history
  • Loading branch information
summerinsects committed Dec 24, 2017
1 parent 04763aa commit 810606b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Classes/RecordSystem/Record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ void JsonToRecord(const rapidjson::Value &json, Record &record) {

it = detail_json.FindMember("fan");
if (it != detail_json.MemberEnd() && it->value.IsUint()) {
detail_data.fan = it->value.GetUint();
detail_data.fan = static_cast<uint16_t>(it->value.GetUint());
}

// 兼容旧的key
it = detail_json.FindMember("score");
if (it != detail_json.MemberEnd() && it->value.IsUint()) {
detail_data.fan = it->value.GetUint();
detail_data.fan = static_cast<uint16_t>(it->value.GetUint());
}

it = detail_json.FindMember("fan_flag");
Expand Down Expand Up @@ -298,7 +298,7 @@ void ModifyRecordInHistory(std::vector<Record> &records, const Record *r) {

void TranslateDetailToScoreTable(const Record::Detail &detail, int (&scoreTable)[4]) {
memset(scoreTable, 0, sizeof(scoreTable));
int fan = detail.fan;
int fan = static_cast<int>(detail.fan);
if (fan >= 8 && !!(detail.win_claim & 0xF0)) {
uint8_t wc = detail.win_claim;
int winIndex = WIN_INDEX(wc);
Expand Down
4 changes: 2 additions & 2 deletions Classes/RecordSystem/Record.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ struct Record {
struct Detail {
uint8_t win_claim; // 和牌标记(4567bit)/点炮标记(0123bit)
uint8_t packed_fan; // 小番组合
uint32_t fan; // 番数
uint64_t fan_flag; // 标记番种
uint16_t fan; // 番数
int16_t penalty_scores[4]; // 处罚分
uint64_t fan_flag; // 标记番种

struct WinHand {
char tiles[64]; //
Expand Down
6 changes: 3 additions & 3 deletions Classes/RecordSystem/RecordScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ void RecordScene::refresh() {
uint8_t wc = _detail.win_claim;
if (_detail.fan >= 8) {
char str[32];
snprintf(str, sizeof(str), "%d", _detail.fan);
snprintf(str, sizeof(str), "%hu", _detail.fan);
_editBox->setText(str);
}

Expand Down Expand Up @@ -531,7 +531,7 @@ void RecordScene::updateScoreLabel() {
int claimIndex = -1;
if (_winIndex != -1) { // 有人和牌
int fan = atoi(_editBox->getText()); // 获取输入框里所填番数
_detail.fan = std::max(8, fan);
_detail.fan = std::max<uint16_t>(8, fan);
claimIndex = _claimGroup->getSelectedButtonIndex();

// 记录和牌和点炮
Expand Down Expand Up @@ -999,7 +999,7 @@ void RecordScene::calculate(TilePickWidget *tilePicker, ExtraInfoWidget *extraIn
}

AlertView::showWithNode("记录和牌", innerNode, [this, temp, fan, fanFlag, packedFan]() {
_detail.fan = std::max(fan, 8);
_detail.fan = std::max<uint16_t>(fan, 8);
_detail.fan_flag = fanFlag;
_detail.packed_fan = packedFan;

Expand Down
4 changes: 2 additions & 2 deletions Classes/RecordSystem/ScoreSheetScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,10 +584,10 @@ static std::string stringifyDetail(const Record *record, size_t handIdx) {
int winIndex = WIN_INDEX(wc);
int claimIndex = CLAIM_INDEX(wc);
if (winIndex == claimIndex) {
ret.append(Common::format("「%s」自摸%s%d番\n", record->name[winIndex], fanText.c_str(), detail.fan));
ret.append(Common::format("「%s」自摸%s%hu番\n", record->name[winIndex], fanText.c_str(), detail.fan));
}
else {
ret.append(Common::format("「%s」和%s%d番,「%s」点炮。\n", record->name[winIndex], fanText.c_str(), detail.fan, record->name[claimIndex]));
ret.append(Common::format("「%s」和%s%hu番,「%s」点炮。\n", record->name[winIndex], fanText.c_str(), detail.fan, record->name[claimIndex]));
}

return ret;
Expand Down

0 comments on commit 810606b

Please sign in to comment.