void frmMain::_onSaveMenuSave(wxCommandEvent& evt) { if(m_sFilename.empty()) { _onSaveMenuSaveAs(evt); return; } map_save_t oSave; if(oSave.fFile.Open(m_sFilename, wxFile::write)) { lua_State* L = m_pGamePanel->getLua(); luaT_execute(L, "return TheApp.world.map.th"); THMap *pMap = reinterpret_cast<THMap*>(lua_touserdata(L, -1)); lua_pop(L, 1); THMapWrapper::autoSetHelipad(pMap); luaT_execute(L, "return TheApp.ui:ScreenToWorld(...)", m_pGamePanel->GetSize().GetWidth() / 2, m_pGamePanel->GetSize().GetHeight() / 2); int iCameraX = (int)lua_tointeger(L, -2); int iCameraY = (int)lua_tointeger(L, -1); lua_pop(L, 2); pMap->setPlayerCameraTile(0, iCameraX, iCameraY); pMap->save(map_save_t::writer, reinterpret_cast<void*>(&oSave)); ::wxMessageBox(wxT("Map saved."), wxT("Save"), wxOK | wxCENTER | wxICON_INFORMATION, this); } }
static int l_map_save(lua_State *L) { THMap *pMap = luaT_testuserdata<THMap>(L); std::string filename(luaL_checkstring(L, 2)); pMap->save(filename); return 0; }