1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-02 19:13:31 +02:00
VVVVVV/desktop_version/src/UtilityClass.h
Dav999 f4bdea7d6d Add a system for selecting between wordy/wordy2
Some languages have different spellings of wordy numbers based on the
gender of the things they're counting (uno crewmate versus una trinket)
or what a number's role is in the sentence (e.g. twenta out of twentu).
We've always had the idea we couldn't support such complex differences
though, because the game can't be adapted to know what gender each
object will have and what word classes might exist in other languages,
so translators would in those cases just have to forgo the wordy
numbers and just let the game use "20 out of 20".

A solution we came up semi-recently though (after all translations were
finished except for Arabic), was to allow the translator to define
however many classes of wordy numbers they need, and fill them all out.
This would not need the game to be *adapted* for every language's
specific grammar and word genders/classes. Instead, the translator
would just choose their correct self-defined class at the time they use
`wordy` in the VFormat placeholder. Something like
{n|wordy|class=feminine}, or {n|wordy_feminine}.

So this would benefit several languages, but we came up with the
solution a little late for all languages to benefit from it. The Arabic
translators asked for two separate classes of wordy numbers though, so
my plan is to first just have a second list of wordy numbers
(translation2 in numbers.xml), which can be accessed by passing the
`wordy2` flag to VFormat, instead of `wordy`.

Once 2.4 is released, we can take our time to do it properly. This
would involve the ability for translators to define however many
classes they need, to name them what they want, and this name would
then be useable in VFormat placeholders. We can convert all existing
translations to have one class defined by default, such as "wordy", or
"translation" depending on implementation, but there's not so much
concern for maintaining backwards compatibility here, so we can do a
mass-switchover for all language files. That said, it wouldn't be too
hard to add a special case for "translation" being "wordy" either.
We can then ask translators if they would like to change anything with
the new system in place.

For now, we can use this system for Arabic, maybe Spanish since there
were complaints about uno/una, and *maybe* Dutch (it has a thing where
the number "one" is often capitalized differently, but it's not
mandatory per se)
2024-01-06 14:11:40 -08:00

127 lines
2.7 KiB
C++

#ifndef UTILITYCLASS_H
#define UTILITYCLASS_H
#include <SDL.h>
#include <string>
int ss_toi(const std::string& str);
bool next_split(
size_t* start,
size_t* len,
const char* str,
const char delim
);
bool next_split_s(
char buffer[],
const size_t buffer_size,
size_t* start,
const char* str,
const char delim
);
bool is_number(const char* str);
bool is_positive_num(const char* str, const bool hex);
bool endsWith(const char* str, const char* suffix);
void VVV_fillstring(
char* buffer,
const size_t buffer_size,
const char fillchar
);
#define INBOUNDS_VEC(index, vector) ((int) index >= 0 && (int) index < (int) vector.size())
#define INBOUNDS_ARR(index, array) ((int) index >= 0 && (int) index < (int) SDL_arraysize(array))
#define WHINE_ONCE(message) \
static bool whine = true; \
if (whine) \
{ \
whine = false; \
vlog_error(message); \
} \
do { } while (false)
#define WHINE_ONCE_ARGS(args) \
static bool whine = true; \
if (whine) \
{ \
whine = false; \
vlog_error args; \
} \
do { } while (false)
/* Don't call this directly; use the VVV_between macro. */
void _VVV_between(
const char* original,
const size_t left_length,
char* middle,
const size_t right_length,
const size_t middle_size
);
/* If original is "LEFTMIDDLERIGHT", VVV_between(original, "LEFT", buffer, "RIGHT")
* will put "MIDDLE" into buffer - assuming that sizeof(buffer) refers to length
* of buffer and not length of pointer to buffer.
*/
#define VVV_between(original, left, middle, right) \
_VVV_between( \
original, \
SDL_arraysize(left) - 1, \
middle, \
SDL_arraysize(right) - 1, \
sizeof(middle) \
)
#define MAYBE_FAIL(expr) \
do \
{ \
if (!expr) \
{ \
goto fail; \
} \
} \
while (false)
/* Positive modulo, because C/C++'s modulo operator sucks and is negative given
* negative divisors.
* WARNING! This double- and triple- evaluates. */
#define POS_MOD(a, b) (((a) % (b) + (b)) % (b))
//helperClass
class UtilityClass
{
public:
UtilityClass(void);
static std::string String(int _v);
static int Int(const char* str, int fallback = 0);
int hms_to_seconds(int h, int m, int s);
void format_time(char* buffer, const size_t buffer_size, int seconds, int frames, bool always_minutes);
std::string timestring(int t);
std::string number_words(int _t, const char* number_class);
static bool intersects( SDL_Rect A, SDL_Rect B );
void updateglow(void);
int glow;
int slowsine;
int glowdir;
};
#ifndef HELP_DEFINITION
extern UtilityClass help;
#endif
#endif /* UTILITYCLASS_H */