Skip to content

Commit

Permalink
Profile Edits, Enable Backspace For Entity Deletion
Browse files Browse the repository at this point in the history
Quick upload.
  • Loading branch information
Gota7 committed May 30, 2022
1 parent d781a7c commit d825dae
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 59 deletions.
2 changes: 2 additions & 0 deletions src/bgm/bgm.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "bgm.h"
#include "../rlImGui/utils.h"

#include <bits/stdc++.h>

std::string BgmPlayer::rsc;
pxtnService BgmPlayer::pxtn;
FILE *BgmPlayer::handle = nullptr;
Expand Down
5 changes: 3 additions & 2 deletions src/ed/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "../rlImGui/utils.h"
#include "imgui.h"
#include "raylib.h"

#include <bits/stdc++.h>
#include <cmath>

void Editor::Init()
Expand Down Expand Up @@ -375,7 +377,6 @@ void Editor::InitSubeditors()

void Editor::LoadTileset(std::string tilesetName)
{
printf("%s\n", tilesetName.c_str());
Tileset t;
t.Load(rsc, tilesetName);
tilesets[tilesetName] = t;
Expand Down Expand Up @@ -1065,7 +1066,7 @@ void Editor::CheckZoom()

void Editor::CheckEntityDelete()
{
if (entityEditor.editingEntity && IsKeyPressed(KEY_DELETE))
if (entityEditor.editingEntity && (IsKeyPressed(KEY_DELETE) || IsKeyPressed(KEY_BACKSPACE)))
{
entityEditor.editingEntity->beingEdited = false;
Entity* e = entityEditor.editingEntity;
Expand Down
34 changes: 31 additions & 3 deletions src/ed/profileEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ void ProfileEditor::DrawGeneralSettings(int itemWidth)
profile->lastDay = time.tm_mday;
}
ImGuiTooltip("The date of when the user last played the game.");

// Last time.
ImGui::PushItemWidth(itemWidth);
ImGui::InputScalar("Last Play Hour", ImGuiDataType_U8, &profile->lastHour);
Expand Down Expand Up @@ -491,7 +491,35 @@ void ProfileEditor::DrawGameProfile(int itemWidth)
void ProfileEditor::DrawSaveInfo(int itemWidth, int save)
{

// Dummy.
ImGui::Text("Dummy");
// Setup.
ImGui::PushItemWidth(itemWidth);
ProfileSave& p = ed->profile.saves[save];

// Save date.
tm time;
time.tm_year = p.year - 1900;
time.tm_mon = p.month - 1;
time.tm_mday = p.day;
time.tm_hour = 0;
time.tm_min = 0;
time.tm_sec = 0;
if (ImGui::DateChooser("Save Date##GeneralSettings", time, "%m-%d-%Y"))
{
p.year = time.tm_year + 1900;
p.month = time.tm_mon + 1;
p.day = time.tm_mday;
}
ImGuiTooltip("The date of when the save was last modified.");

// Save time.
ImGui::InputScalar("Save Hour", ImGuiDataType_U8, &p.hour);
ImGuiTooltip("The hour when the game was saved.");
ImGui::InputScalar("Save Minute", ImGuiDataType_U8, &p.minute);
ImGuiTooltip("The minute when the game was saved.");
ImGui::InputScalar("Save Second", ImGuiDataType_U8, &p.second);
ImGuiTooltip("The second when the game was saved.");

// Finish.
ImGui::PopItemWidth();

}
2 changes: 1 addition & 1 deletion src/ed/toolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void Toolbar::DrawUI()
{
ed->isPlacingEntity = !ed->isPlacingEntity;
}
Tooltip("Click after hitting to place an entity or again to cancel.\nHolding shift while placing will allow you to place multiple.\nPressing the delete key will delete the selected entity.");
Tooltip("Click after hitting to place an entity or again to cancel.\nHolding shift while placing will allow you to place multiple.\nPressing the delete or backspace key will delete the selected entity.");
}
ImGui::End();

Expand Down
73 changes: 23 additions & 50 deletions src/px/profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,60 +142,33 @@ void Profile::SaveLastIdx(std::string rsc_k)
f.Close();
}

// TODO: GAME SAVE CODE!!!

void Profile::LoadProfileSave(std::string rsc_k, u8 num)
{

/*
00 - Header, 8
08 - Save year, 1
09 - Save month, 1
0A - Save day, 1
0B - Save hour, 1
0C - Save minute, 1
0D - Save second, 1
0E - Zeros, 2
10 - Profile icon, 4
14 - Total playtime in frames for menu, 4
18 - Display money, 4
1C - Display lives, 2
1E - Display hearts, 2
20 - UNKNOWN, is 2 in my Omake save but 0 for rest, 2
22 - Mission description, 82
A4 - Items to display, 4[8]
C4 - Total playtime in frames, 4
C8 - Number of flag bytes, 4
CC - Flags, 800
8CC - Items in hand, 4[4]
8DC - Currently held item, 1
8DD - Weapons in hand, Weapons[8]
8FD - Number of lives, 2
8FF - Money, 4
903 - UNKNOWN (0 or 2?), 2
905 - UNKNOWN (D, 4, 28, etc.), 2
907 - Current HP, 2
909 - Total HP, 2
90B - UNKNOWN (always 1?), 1
90C - On gameover level, 10
940 - Current level, C
94C - UNKNOWN (always 72?), 2
UNK
965 - X position of some kind, 4
969 - Y position of some kind, 4
96D - UNKNOWN (always 0?), 2
96F - Player facing right, 4
UNK
974 - Checkpoint stage, 10
984 - Shop teleporter string parameter, ?
UNK
// Setup.
if (!FileExists(rsc_k, "profile" + std::to_string(num))) return;
GFile f = GetGFile(rsc_k, "profile" + std::to_string(num));
ProfileSave p;

struct Weapons {
00 - Item ID, 1
01 - Item level, 1
02 - Zeroes, 2 (Last byte may be set sometimes, but idk what to?)
}
*/
// Read data.
f.ReadU64();
p.year = f.ReadU8();
p.month = f.ReadU8();
p.day = f.ReadU8();
p.hour = f.ReadU8();
p.minute = f.ReadU8();
p.second = f.ReadU8();
f.ReadU16();
p.profileIcon = f.ReadU32();
p.displayPlaytime = f.ReadU32();
p.displayMoney = f.ReadU32();
p.displayLives = f.ReadU16();
p.displayHearts = f.ReadU16();
p.unk1 = f.ReadU16();

// Set data.
saves[num] = p;
f.Close();

}

Expand Down
102 changes: 99 additions & 3 deletions src/px/profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,106 @@
#include "../gbin/gfile.h"
#include "raylib.h"

/*
00 - Header, 8
08 - Save year, 1
09 - Save month, 1
0A - Save day, 1
0B - Save hour, 1
0C - Save minute, 1
0D - Save second, 1
0E - Zeros, 2
10 - Profile icon, 4
14 - Total playtime in frames for menu, 4
18 - Display money, 4
1C - Display lives, 2
1E - Display hearts, 2
20 - UNKNOWN, is 2 in my Omake save but 0 for rest, 2
22 - Mission description, 82
A4 - Items to display, 4[8]
C4 - Total playtime in frames, 4
C8 - Number of flag bytes, 4
CC - Flags, 800
8CC - Items in hand, 4[4]
8DC - Currently held item, 1
8DD - Weapons in hand, Weapons[8]
8FD - Number of lives, 2
8FF - Money, 4
903 - UNKNOWN (0 or 2?), 2
905 - UNKNOWN (D, 4, 28, etc.), 2
907 - Current HP, 2
909 - Total HP, 2
90B - UNKNOWN (always 1?), 1
90C - On gameover level, 10
940 - Current level, C
94C - UNKNOWN (always 72?), 2
UNK
965 - X position of some kind, 4
969 - Y position of some kind, 4
96D - UNKNOWN (always 0?), 2
96F - Player facing right, 4
UNK
974 - Checkpoint stage, 10
984 - Shop teleporter string parameter, ?
UNK
struct Weapons {
00 - Item ID, 1
01 - Item level, 1
02 - Zeroes, 2 (Last byte may be set sometimes, but idk what to?)
}
*/

// A weapon.
struct Weapon
{
u8 itemId = 0;
u8 itemLevel = 0;
u8 unk1 = 0;
u8 unk2 = 0;
};

// Kero blaster save.
struct ProfileSave
{

u8 year;
u8 month;
u8 day;
u8 hour;
u8 minute;
u8 second;
u32 profileIcon;
u32 displayPlaytime;
u32 displayMoney;
u16 displayLives;
u16 displayHearts;
u16 unk1;
std::string missionDescription;
u32 displayItems[8];
u32 playtime;
u8 flags[0x800];
u32 itemsInHand[4];
u8 currWeapon;
Weapon weapons[8];
u16 lives;
u32 money;
u16 unk2;
u16 unk3;
u16 currentHp;
u16 totalHp;
u8 unk4;
std::string onGameoverLevel;
std::string currentLevel;
u16 unk5;
u8 unk6[0x19];
u32 xPos;
u32 yPos;
u16 unk7;
u32 facingDirection;
u8 unk8[5];
std::string checkpointStage;
std::string checkpointTeleporterParameter;
// TODO!!!
};

// Kero blaster profile.
Expand Down Expand Up @@ -50,7 +146,7 @@ struct Profile
u8 joystickWeaponSwitchRight = 4;
u8 joystickMenu = 2;
u8 gameProfile[NUM_GAME_FLAGS];
std::vector<ProfileSave> saves = std::vector<ProfileSave>();
ProfileSave saves[NUM_SAVES];

// If a file exists in the profile folder.
bool FileExists(std::string rsc_k, std::string name);
Expand Down Expand Up @@ -114,7 +210,7 @@ struct Profile

// Save the last time used.
void SaveLastTime(std::string rsc_k);

// Load the last key config used.
void LoadKeyConfig(std::string rsc_k);

Expand Down

0 comments on commit d825dae

Please sign in to comment.