31 lines
1.2 KiB
C++
31 lines
1.2 KiB
C++
#pragma once
|
|
#include <cstdint>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <vector>
|
|
namespace ava2 {
|
|
// AVA2 MapManager::__LoadMapInfoVector and PythonBackground coordinate rules.
|
|
struct AtlasMap { std::string name; uint32_t x,y,endX,endY; };
|
|
class MapCoordinates {
|
|
public:
|
|
std::vector<AtlasMap> maps;
|
|
uint32_t baseX=0,baseY=0;
|
|
void load(const std::string& text) {
|
|
maps.clear(); std::istringstream input(text); std::string line;
|
|
while(std::getline(input,line)) {
|
|
std::istringstream row(line); std::string name; uint32_t x,y,w,h;
|
|
if(row>>name>>x>>y>>w>>h) maps.push_back({name,x,y,x+w*25600u,y+h*25600u});
|
|
}
|
|
}
|
|
const AtlasMap* find(uint32_t x,uint32_t y) const {
|
|
for(const auto& map:maps) if(x>=map.x && x<map.endX && y>=map.y && y<map.endY) return ↦
|
|
return nullptr;
|
|
}
|
|
static int32_t signedBits(uint32_t n) {
|
|
return n<=0x7fffffffu?static_cast<int32_t>(n):static_cast<int32_t>(int64_t(n)-0x100000000ll);
|
|
}
|
|
void toLocal(int32_t& x,int32_t& y) const { x=signedBits(uint32_t(x)-baseX); y=signedBits(uint32_t(y)-baseY); }
|
|
void toGlobal(int32_t& x,int32_t& y) const { x=signedBits(uint32_t(x)+baseX); y=signedBits(uint32_t(y)+baseY); }
|
|
};
|
|
}
|