Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug with not saving unlocked tracks and levels #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 75 additions & 84 deletions src/MenuManager.cpp

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions src/MenuManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class IGameMenuElement;

class MenuManager : public IMenuManager {
private:
std::vector<int8_t> field_278;
std::vector<int8_t> savedData;
Micro* micro;
RecordManager* recordManager;
Command* commandOk;
Expand Down Expand Up @@ -82,11 +82,11 @@ class MenuManager : public IMenuManager {
int field_338;
int field_339;
std::string field_340;
char* field_341;
char field_342[4];
char defaultInputString[4] = "AAA";
char* playerName;
char availableTracks[4];
char defaultName[4] = "AAA";
int8_t availableLeagues = 0;
int8_t field_344 = 0;
int8_t availableLevels = 0;
std::vector<int> field_345 = { 0, 0, 0 };
std::vector<std::vector<std::string>> levelNames;
std::vector<std::string> leagueNames = std::vector<std::string>(3);
Expand Down Expand Up @@ -123,8 +123,8 @@ class MenuManager : public IMenuManager {
void fillCanvasWithImage(Graphics* graphics);
void processNonFireKeyCode(int keyCode);
std::vector<int8_t> method_216(int var1, int8_t var2);
int8_t method_217(int var1, int8_t var2);
void copyThreeBytesFromArr(int var1, char* var2);
int8_t getSettingOrDefault(int var1, int8_t var2);
// void copyThreeBytesFromArr(int var1, char* var2);
std::string timeToString(int64_t time);
void setValue(int pos, int8_t value);
void exit();
Expand Down
7 changes: 6 additions & 1 deletion src/RecordManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ void RecordManager::method_8(int var1, int var2)
}

loadRecordInfo(var4);
recordEnum->destroy();
}
}

Expand Down Expand Up @@ -161,13 +160,17 @@ void RecordManager::writeRecordInfo()
try {
packedRecordInfoRecordId = recordStore->addRecord(packedRecordInfo, 0, 96);
} catch (RecordStoreNotOpenException& var1) {
return;
} catch (RecordStoreException& var2) {
return;
}
} else {
try {
recordStore->setRecord(packedRecordInfoRecordId, packedRecordInfo, 0, 96);
} catch (RecordStoreNotOpenException& var3) {
return;
} catch (RecordStoreException& var4) {
return;
}
}
}
Expand Down Expand Up @@ -220,6 +223,7 @@ void RecordManager::deleteRecordStores()
// RecordStore *var10000 = recordStore;
RecordStore::deleteRecordStore(names[i]);
} catch (RecordStoreException& var3) {
return;
}
}
}
Expand All @@ -232,6 +236,7 @@ void RecordManager::closeRecordStore()
recordStore->closeRecordStore();
return;
} catch (RecordStoreException& var1) {
return;
}
}
}
18 changes: 13 additions & 5 deletions src/lcdui/CanvasImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ CanvasImpl::CanvasImpl(Canvas* canvas)
0,
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
width, height,
defaultWidth, defaultHeight,
SDL_WINDOW_SHOWN);

if (!window) {
throw std::runtime_error(SDL_GetError());
}

renderer = SDL_CreateRenderer(
window, -1, SDL_RENDERER_ACCELERATED);
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);

if (!renderer) {
throw std::runtime_error(SDL_GetError());
}

SDL_GetRendererOutputSize(renderer, &windowWidth, &windowHeight);
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderClear(renderer);
}
Expand All @@ -62,12 +62,20 @@ void CanvasImpl::repaint()

int CanvasImpl::getWidth()
{
return width;
if (windowWidth < 0) {
return defaultWidth;
}

return windowWidth;
}

int CanvasImpl::getHeight()
{
return height;
if (windowHeight < 0) {
return defaultHeight;
}

return windowHeight;
}

SDL_Renderer* CanvasImpl::getRenderer()
Expand Down
9 changes: 6 additions & 3 deletions src/lcdui/CanvasImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ class Canvas;

class CanvasImpl {
private:
const int defaultWidth = 640;
const int defaultHeight = 480;

int windowWidth = -1;
int windowHeight = -1;

Canvas* canvas;

SDL_Window* window;
SDL_Renderer* renderer;

const int width = 640;
const int height = 480;

static int convertKeyCharToKeyCode(SDL_Keycode keyCode);

public:
Expand Down
4 changes: 4 additions & 0 deletions src/rms/RecordEnumerationImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void RecordEnumerationImpl::setRecord(int index, std::vector<int8_t> bytes)
if (static_cast<int>(data.size()) <= index) {
throw RecordStoreException();
}

data[index] = bytes;
}

Expand All @@ -49,6 +50,7 @@ int RecordEnumerationImpl::nextRecordId()
if (currentPos >= static_cast<int>(data.size())) {
throw RecordStoreException();
}

return currentPos;
}

Expand All @@ -65,6 +67,7 @@ void RecordEnumerationImpl::serialize(FileStream* outStream)

for (auto i = data.cbegin(); i != data.cend(); i++) {
outStream->writeVariable(&(temp = i->size()));

for (auto j = i->cbegin(); j != i->cend(); j++) {
int8_t buffer;
outStream->writeVariable(&(buffer = *j));
Expand All @@ -82,6 +85,7 @@ void RecordEnumerationImpl::deserialize(FileStream* inStream)
for (size_t i = 0; i < data.size(); ++i) {
inStream->readVariable(&temp);
data[i].resize(temp);

for (size_t j = 0; j < data[i].size(); ++j) {
inStream->readVariable(&data[i][j]);
}
Expand Down
6 changes: 5 additions & 1 deletion src/rms/RecordStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ void RecordStore::closeRecordStore()

int RecordStore::addRecord(std::vector<int8_t> arr, int offset, int numBytes)
{
log("addRecord()");
log("addRecord(" + std::to_string(arr.size()) + "," + std::to_string(offset) + "," + std::to_string(numBytes) + ")");
assert(static_cast<int>(arr.size()) == numBytes);
assert(offset == 0);
int id = records->addRecord(arr);
log("record id = " + std::to_string(id));
save();
return id;
}
Expand Down Expand Up @@ -72,6 +73,8 @@ RecordEnumerationImpl* RecordStore::load(std::filesystem::path filePath)

RecordStore* RecordStore::openRecordStore(std::string name, bool createIfNecessary)
{
log("openRecordStore(" + name + ", " + std::to_string(createIfNecessary) + ")");

if (opened.find(name) == opened.end()) {
opened[name] = createRecordStore(name, createIfNecessary);
}
Expand All @@ -95,6 +98,7 @@ std::unique_ptr<RecordStore> RecordStore::createRecordStore(std::string name, bo
rs->save();
return rs;
} else {
log("can't create record, file is missing");
throw RecordStoreException();
}
}
Expand Down