mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-04 20:43:54 -07:00
Split trice_limits.h into dedicated headers (#7025)
Some checks failed
Build Desktop / Configure (push) Has been cancelled
Build Docker Image / amd64 & arm64 (push) Has been cancelled
Build Desktop / Debian 13 (push) Has been cancelled
Build Desktop / Debian 12 (push) Has been cancelled
Build Desktop / Fedora 44 (push) Has been cancelled
Build Desktop / Fedora 43 (push) Has been cancelled
Build Desktop / Servatrice_Debian 12 (push) Has been cancelled
Build Desktop / Ubuntu 26.04 (push) Has been cancelled
Build Desktop / Ubuntu 24.04 (push) Has been cancelled
Build Desktop / Arch (push) Has been cancelled
Build Desktop / macOS 14 (push) Has been cancelled
Build Desktop / macOS 15 (push) Has been cancelled
Build Desktop / macOS 13 Intel (push) Has been cancelled
Build Desktop / macOS 15 Debug (push) Has been cancelled
Build Desktop / Windows 10 (push) Has been cancelled
Some checks failed
Build Desktop / Configure (push) Has been cancelled
Build Docker Image / amd64 & arm64 (push) Has been cancelled
Build Desktop / Debian 13 (push) Has been cancelled
Build Desktop / Debian 12 (push) Has been cancelled
Build Desktop / Fedora 44 (push) Has been cancelled
Build Desktop / Fedora 43 (push) Has been cancelled
Build Desktop / Servatrice_Debian 12 (push) Has been cancelled
Build Desktop / Ubuntu 26.04 (push) Has been cancelled
Build Desktop / Ubuntu 24.04 (push) Has been cancelled
Build Desktop / Arch (push) Has been cancelled
Build Desktop / macOS 14 (push) Has been cancelled
Build Desktop / macOS 15 (push) Has been cancelled
Build Desktop / macOS 13 Intel (push) Has been cancelled
Build Desktop / macOS 15 Debug (push) Has been cancelled
Build Desktop / Windows 10 (push) Has been cancelled
* Split trice_limits.h into dedicated headers * Updated docstrings
This commit is contained in:
parent
4a384f2a75
commit
18b23b19a7
43 changed files with 103 additions and 84 deletions
|
|
@ -15,7 +15,9 @@ set(UTILITY_HEADERS
|
|||
libcockatrice/utility/levenshtein.h
|
||||
libcockatrice/utility/macros.h
|
||||
libcockatrice/utility/passwordhasher.h
|
||||
libcockatrice/utility/trice_limits.h
|
||||
libcockatrice/utility/string_limits.h
|
||||
libcockatrice/utility/dice_limits.h
|
||||
libcockatrice/utility/counter_limits.h
|
||||
libcockatrice/utility/clamped_arithmetic.h
|
||||
libcockatrice/utility/zone_names.h
|
||||
libcockatrice/utility/days_years_between.h
|
||||
|
|
|
|||
17
libcockatrice_utility/libcockatrice/utility/counter_limits.h
Normal file
17
libcockatrice_utility/libcockatrice/utility/counter_limits.h
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef COUNTER_LIMITS_H
|
||||
#define COUNTER_LIMITS_H
|
||||
|
||||
/**
|
||||
* @brief Upper bound for a bounded counter's value: [0, MAX_COUNTER_VALUE].
|
||||
*
|
||||
* Caps an individual counter's VALUE (e.g. a +1/+1 counter at 999), not how many counters
|
||||
* something holds. Applies to counters that are constrained to a non-negative display range,
|
||||
* such as card counters and commander tax. Unbounded counters (e.g. a player's life total)
|
||||
* do not use this limit and may go negative, saturating only at the int range.
|
||||
*
|
||||
* The max of 999 is a display constraint (3-digit rendering) and a reasonable gameplay limit.
|
||||
* The server enforces these bounds; the client may also check them for UX optimization.
|
||||
*/
|
||||
constexpr int MAX_COUNTER_VALUE = 999;
|
||||
|
||||
#endif // COUNTER_LIMITS_H
|
||||
15
libcockatrice_utility/libcockatrice/utility/dice_limits.h
Normal file
15
libcockatrice_utility/libcockatrice/utility/dice_limits.h
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef DICE_LIMITS_H
|
||||
#define DICE_LIMITS_H
|
||||
|
||||
#include <QtGlobal> // for uint
|
||||
|
||||
/** @brief Fewest sides a rollable die may have. */
|
||||
constexpr uint MINIMUM_DIE_SIDES = 2;
|
||||
/** @brief Most sides a rollable die may have. */
|
||||
constexpr uint MAXIMUM_DIE_SIDES = 1000000;
|
||||
/** @brief Fewest dice that may be rolled at once. */
|
||||
constexpr uint MINIMUM_DICE_TO_ROLL = 1;
|
||||
/** @brief Most dice that may be rolled at once. */
|
||||
constexpr uint MAXIMUM_DICE_TO_ROLL = 100;
|
||||
|
||||
#endif // DICE_LIMITS_H
|
||||
31
libcockatrice_utility/libcockatrice/utility/string_limits.h
Normal file
31
libcockatrice_utility/libcockatrice/utility/string_limits.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#ifndef STRING_LIMITS_H
|
||||
#define STRING_LIMITS_H
|
||||
|
||||
#include <QString>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
/** @brief Max size for short strings, like names and things that are generally a single phrase. */
|
||||
constexpr int MAX_NAME_LENGTH = 0xff;
|
||||
/** @brief Max size for chat messages and text contents. */
|
||||
constexpr int MAX_TEXT_LENGTH = 0xfff;
|
||||
/** @brief Max size for deck files and pictures (about 2 megabytes). */
|
||||
constexpr int MAX_FILE_LENGTH = 0x1fffff;
|
||||
|
||||
/** @brief Returns a QString from a std::string, truncated to at most MAX_NAME_LENGTH bytes. */
|
||||
inline QString nameFromStdString(const std::string &_string)
|
||||
{
|
||||
return QString::fromUtf8(_string.data(), std::min(int(_string.size()), MAX_NAME_LENGTH));
|
||||
}
|
||||
/** @brief Returns a QString from a std::string, truncated to at most MAX_TEXT_LENGTH bytes. */
|
||||
inline QString textFromStdString(const std::string &_string)
|
||||
{
|
||||
return QString::fromUtf8(_string.data(), std::min(int(_string.size()), MAX_TEXT_LENGTH));
|
||||
}
|
||||
/** @brief Returns a QString from a std::string, truncated to at most MAX_FILE_LENGTH bytes. */
|
||||
inline QString fileFromStdString(const std::string &_string)
|
||||
{
|
||||
return QString::fromUtf8(_string.data(), std::min(int(_string.size()), MAX_FILE_LENGTH));
|
||||
}
|
||||
|
||||
#endif // STRING_LIMITS_H
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
#ifndef TRICE_LIMITS_H
|
||||
#define TRICE_LIMITS_H
|
||||
|
||||
//! \todo Split trice_limits.h into focused single-purpose headers: string_limits.h,
|
||||
//! dice_limits.h, counter_limits.h.
|
||||
|
||||
#include <QString>
|
||||
|
||||
// max size for short strings, like names and things that are generally a single phrase
|
||||
constexpr int MAX_NAME_LENGTH = 0xff;
|
||||
// max size for chat messages and text contents
|
||||
constexpr int MAX_TEXT_LENGTH = 0xfff;
|
||||
// max size for deck files and pictures
|
||||
constexpr int MAX_FILE_LENGTH = 0x1fffff; // about 2 megabytes
|
||||
|
||||
constexpr uint MINIMUM_DIE_SIDES = 2;
|
||||
constexpr uint MAXIMUM_DIE_SIDES = 1000000;
|
||||
constexpr uint MINIMUM_DICE_TO_ROLL = 1;
|
||||
constexpr uint MAXIMUM_DICE_TO_ROLL = 100;
|
||||
|
||||
/**
|
||||
* @brief Upper bound for a bounded counter's value: [0, MAX_COUNTER_VALUE].
|
||||
*
|
||||
* Caps an individual counter's VALUE (e.g. a +1/+1 counter at 999), not how many counters
|
||||
* something holds. Applies to counters that are constrained to a non-negative display range,
|
||||
* such as card counters and commander tax. Unbounded counters (e.g. a player's life total)
|
||||
* do not use this limit and may go negative, saturating only at the int range.
|
||||
*
|
||||
* The max of 999 is a display constraint (3-digit rendering) and a reasonable gameplay limit.
|
||||
* The server enforces these bounds; the client may also check them for UX optimization.
|
||||
*/
|
||||
constexpr int MAX_COUNTER_VALUE = 999;
|
||||
|
||||
// optimized functions to get qstrings that are at most that long
|
||||
static inline QString nameFromStdString(const std::string &_string)
|
||||
{
|
||||
return QString::fromUtf8(_string.data(), std::min(int(_string.size()), MAX_NAME_LENGTH));
|
||||
}
|
||||
static inline QString textFromStdString(const std::string &_string)
|
||||
{
|
||||
return QString::fromUtf8(_string.data(), std::min(int(_string.size()), MAX_TEXT_LENGTH));
|
||||
}
|
||||
static inline QString fileFromStdString(const std::string &_string)
|
||||
{
|
||||
return QString::fromUtf8(_string.data(), std::min(int(_string.size()), MAX_FILE_LENGTH));
|
||||
}
|
||||
|
||||
#endif // TRICE_LIMITS_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue