mirror of
https://github.com/electronicarts/CNC_TS_and_RA2_Mission_Editor.git
synced 2025-07-18 04:06:42 -04:00
refactored serde between waypoint number and 26 radix string . (#122)
This commit is contained in:
parent
cace9efd2a
commit
f0f2439be0
6 changed files with 74 additions and 70 deletions
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include <afx.h>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
|
||||
// coordinate functions
|
||||
inline void PosToXY(const char* pos, int* X, int* Y)
|
||||
|
@ -89,4 +90,48 @@ inline std::array<unsigned char, 3> HSVToRGB(const unsigned char hsv[3])
|
|||
std::array<unsigned char, 3> ret;
|
||||
HSVToRGB(hsv, ret.data());
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline int letter2number(char let) {
|
||||
int reply = let - 'A';
|
||||
return reply;
|
||||
|
||||
}
|
||||
|
||||
inline char number2letter(int let) {
|
||||
int reply = let + 'A';
|
||||
return reply;
|
||||
|
||||
}
|
||||
|
||||
inline int StringToWaypoint(const CString& str)
|
||||
{
|
||||
if (str.IsEmpty()) {
|
||||
return -1;
|
||||
}
|
||||
int num = 0;
|
||||
for (auto idx = 0; idx < str.GetLength(); ++idx) {
|
||||
auto const ch = str[idx];
|
||||
num = (num + idx) * 26 + letter2number(ch);
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
// Serialize waypoint, will be renamed later
|
||||
inline CString WaypointToString(int num)
|
||||
{
|
||||
if (num < 0) {
|
||||
return {};
|
||||
}
|
||||
char secondChar = number2letter(num % 26);
|
||||
char carry = num / 26;
|
||||
if (!carry) {
|
||||
return secondChar;
|
||||
}
|
||||
|
||||
char firstChar = number2letter(carry - 1);
|
||||
CString ret;
|
||||
ret += firstChar;
|
||||
ret += secondChar;
|
||||
return ret;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue