mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-04-29 01:03:35 +00:00
refactor: cleanup UTF-16 digit parsing functionality
This commit is contained in:
parent
1fcd456c30
commit
a29b6ad45d
|
|
@ -1235,21 +1235,16 @@ std::size_t UIScene::GetCallbackUniqueId() {
|
|||
bool UIScene::isReadyToDelete() { return true; }
|
||||
|
||||
int UIScene::parseSlotId(const char16_t* s) {
|
||||
// must be nonnull, must start with 'slot_', first char after the underscore
|
||||
// must be a digit
|
||||
if (!s ||
|
||||
(s[0] != u's' || s[1] != u'l' || s[2] != u'o' || s[3] != u't' ||
|
||||
s[4] != u'_') ||
|
||||
(s[5] < u'0' || s[5] > u'9')) {
|
||||
if (s == nullptr ||
|
||||
std::char_traits<char16_t>::compare(s, u"slot_", 5) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// keep consuming digits until we reach a non-digit. each digit scales the
|
||||
// existing id value by 10 plus the actual digit value. (this is called a
|
||||
// 'number' by the way)
|
||||
int i = 5;
|
||||
int id = 0;
|
||||
|
||||
// keep consuming digits until we reach a non-digit. each digit scales the
|
||||
// existing id value by 10 plus the actual digit value. (this is referred to
|
||||
// as a 'number' by the way)
|
||||
while (s[i] >= u'0' && s[i] <= u'9') {
|
||||
id = id * 10 + (s[i] - u'0');
|
||||
i++;
|
||||
|
|
|
|||
|
|
@ -595,11 +595,22 @@ void UIScene_SkinSelectMenu::InputActionOK(unsigned int iPad) {
|
|||
}
|
||||
|
||||
void UIScene_SkinSelectMenu::customDraw(IggyCustomDrawCallbackRegion* region) {
|
||||
// int characterId = -1;
|
||||
// swscanf((wchar_t*)region->name,L"Character%d",&characterId);
|
||||
// 4jcraft: fuck wchar_t
|
||||
int characterId =region->name[9] - '0' < 0 ? -1 : region->name[9] - '0';
|
||||
if (characterId == -1) {
|
||||
// 4jcraft: fuck wchar_t
|
||||
int characterId = -1;
|
||||
if (region->name != nullptr &&
|
||||
std::char_traits<char16_t>::length(region->name) > 9 &&
|
||||
std::char_traits<char16_t>::compare(region->name, u"Character", 9) ==
|
||||
0) {
|
||||
int i = 9;
|
||||
characterId = 0;
|
||||
|
||||
while (region->name[i] >= u'0' && region->name[i] <= u'9') {
|
||||
characterId = characterId * 10 + (region->name[i] - u'0');
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (characterId == -1) {
|
||||
app.DebugPrintf("Invalid character to render found\n");
|
||||
} else {
|
||||
// Setup GDraw, normal game render states and matrices
|
||||
|
|
|
|||
Loading…
Reference in a new issue