mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-08-20 09:57:10 +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; }
|
bool UIScene::isReadyToDelete() { return true; }
|
||||||
|
|
||||||
int UIScene::parseSlotId(const char16_t* s) {
|
int UIScene::parseSlotId(const char16_t* s) {
|
||||||
// must be nonnull, must start with 'slot_', first char after the underscore
|
if (s == nullptr ||
|
||||||
// must be a digit
|
std::char_traits<char16_t>::compare(s, u"slot_", 5) != 0) {
|
||||||
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')) {
|
|
||||||
return -1;
|
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 i = 5;
|
||||||
int id = 0;
|
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') {
|
while (s[i] >= u'0' && s[i] <= u'9') {
|
||||||
id = id * 10 + (s[i] - u'0');
|
id = id * 10 + (s[i] - u'0');
|
||||||
i++;
|
i++;
|
||||||
|
|
|
||||||
|
|
@ -595,11 +595,22 @@ void UIScene_SkinSelectMenu::InputActionOK(unsigned int iPad) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIScene_SkinSelectMenu::customDraw(IggyCustomDrawCallbackRegion* region) {
|
void UIScene_SkinSelectMenu::customDraw(IggyCustomDrawCallbackRegion* region) {
|
||||||
// int characterId = -1;
|
// 4jcraft: fuck wchar_t
|
||||||
// swscanf((wchar_t*)region->name,L"Character%d",&characterId);
|
int characterId = -1;
|
||||||
// 4jcraft: fuck wchar_t
|
if (region->name != nullptr &&
|
||||||
int characterId =region->name[9] - '0' < 0 ? -1 : region->name[9] - '0';
|
std::char_traits<char16_t>::length(region->name) > 9 &&
|
||||||
if (characterId == -1) {
|
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");
|
app.DebugPrintf("Invalid character to render found\n");
|
||||||
} else {
|
} else {
|
||||||
// Setup GDraw, normal game render states and matrices
|
// Setup GDraw, normal game render states and matrices
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue