Exemple #1
0
bool KMapDataManager::deleteMap(const char* mapName)
{
	this->closeMap(mapName);
	JG_C::KString<512> filepath = this->_getFilePath(mapName);
	JG_F::KFileUtil::deleteFile(filepath.c_str());
	return true;
}
Exemple #2
0
bool KMapDataManager::createMap(const char* mapName, int width, int height)
{
	KMapData* mapData = this->getMapData(mapName);
	if(mapData) return false;

	JG_C::KString<512> filepath = this->_getFilePath(mapName);
	FILE* f = JG_F::KFileUtil::OpenFileForce(filepath.c_str(), "r+b");
	if(!f) return false;

	KOutputFileStream fo(f);

	KMapData mdt;
	if(!mdt.initialize(width, height))
	{
		fclose(f);
		return false;
	}

	if(!mdt.save(fo))
	{
		fclose(f);
		return false;
	}

	DWORD size = fo.tell();
	JG_F::KFileUtil::SetFileSize(f, size);
	fclose(f);

	MapDesc desc;
	desc.mapName = KBuffer64k::WriteData(mapName, strlen(mapName)+1);
	desc.mapData = mdt;
	m_mapByName[desc.mapName] = desc;

	return true;
}
Exemple #3
0
static const char* time2str(int t)
{
	static char buf[32];
	KDatetime dt(t);
	JG_C::KString<32> s = dt.ToString();
	sprintf_k(buf, sizeof(buf), "%s", s.c_str());
	return buf;
}
Exemple #4
0
BOOL KStringManager::Init(const char* filename)
{
	int lang = this->_getLangFromFilename(filename);
	if(lang)
	{
		if(!JG_F::KFileUtil::IsDir(filename))
			return this->loadFileList(lang, filename);
		JG_C::KString<512> resPath = this->_getResourceDir(filename);
		return this->loadForLanguage(resPath.c_str(), lang);
	}
	else
	{
		if(!JG_F::KFileUtil::IsDir(filename))
			return this->loadFileList(m_language, filename);
		JG_C::KString<512> resPath = this->_getResourceDir(filename);
		return this->loadAll(resPath.c_str());
	}
}
Exemple #5
0
bool KCoordinateTable::Reload(const char * szFilePath)
{
	ASSERT_RETURN(szFilePath, false);		
	KTabfileLoader& loader = KTabfileLoader::GetInstance();
	JG_C::KString<MAX_PATH> lFullPath = loader.GetBaseFilepath(szFilePath).c_str();
	JG_F::KTabFile2 * fileReader = loader.GetFileReader(lFullPath.c_str());

	if(!fileReader )
	{
		AssertFile(szFilePath);
		return false;
	}

	m_map.clear();

	int rowNo = 2;
	KCoordinatePoint point;

	while(TRUE)
	{
		int nRet = fileReader->ReadLine();
		if(nRet == -1) { loader.CloseFileReader(fileReader); return FALSE; }
		if(nRet == 0) break;

		if(!fileReader->GetInteger("Id", 0, &point.m_Id)) break;
		if(point.m_Id == 0) return FALSE;

		if(!fileReader->GetInteger("MapId", 0, &point.m_MapID)) return FALSE;
		if(!fileReader->GetInteger("Xaxis", 0, &point.m_Xaxis)) return FALSE;
		if(!fileReader->GetInteger("Yaxis", 0, &point.m_Yaxis)) return FALSE;
		if(!fileReader->GetInteger("CDirection", 0, &point.m_CDirection)) return FALSE;

		if(!fileReader->GetInteger("CAngle", 0, &point.m_CAngle)) return FALSE;
		if(!fileReader->GetInteger("CFaces", 0, &point.m_CFaces)) return FALSE;
		if(!fileReader->GetInteger("RDirection", 0, &point.m_RDirection)) return FALSE;
		if(!fileReader->GetString("Type", "", point.m_desc, sizeof(point.m_desc))) return FALSE;

		this->Add(point);
		rowNo += 1;
	}

	loader.CloseFileReader(fileReader);
	return TRUE;
}
Exemple #6
0
bool KMapDataManager::openMap(const char* mapName)
{
	KMapData* mapData = this->getMapData(mapName);
	if(mapData) return true;

	JG_C::KString<512> filepath = this->_getFilePath(mapName);

	KInputFileStream fi;
	if(!fi.Open(filepath.c_str()))
		return false;

	KMapData mdt;
	if(!mdt.initialize(fi))
		return false;

	MapDesc mapDesc;
	mapDesc.mapName = KBuffer64k::WriteData(mapName, strlen(mapName)+1);
	mapDesc.mapData = mdt;
	m_mapByName[mapDesc.mapName] = mapDesc;

	return true;
}