Skip to content
This repository has been archived by the owner on Feb 27, 2022. It is now read-only.

Commit

Permalink
WIP -> Begin of the Item Editor work.
Browse files Browse the repository at this point in the history
*This is currently just an Player Bag Item Viewer yet.*
  • Loading branch information
SuperSaiyajinStackZ committed Oct 28, 2019
1 parent 33d5211 commit c26790e
Show file tree
Hide file tree
Showing 40 changed files with 44,889 additions and 358 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ endif
#---------------------------------------------------------------------------------
TARGET := LeafEdit
BUILD := build
SOURCES := source source/common source/core source/core/save source/gui source/gui/screens source/lang
SOURCES := source source/common source/core source/core/management source/core/save source/gui source/gui/screens source/lang
DATA := data
INCLUDES := include include/common include/core include/core/save include/gui include/gui/screens include/lang
INCLUDES := include include/common include/core include/core/management include/core/save include/gui include/gui/screens include/lang
GRAPHICS := assets/gfx
#GFXBUILD := $(BUILD)
ROMFS := romfs
Expand Down
1 change: 1 addition & 0 deletions assets/gfx/sprites.t3s
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ sprites/back.png
sprites/button.png
sprites/card.png
sprites/helperBox.png
sprites/itemHole.png
sprites/search.png

sprites/credits/discord.png
Expand Down
Binary file added assets/gfx/sprites/itemHole.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
147 changes: 147 additions & 0 deletions include/common/file.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
MIT License
This file is part of NLTK
Copyright (c) 2018-2019 Slattz, Cuyler
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#pragma once

#ifndef FILE_HPP
#define FILE_HPP

#include <string>
#include <fstream>
#include <3ds.h>

/*
File Class
=> Class for all file operations.
This class is based on CTRPluginFramework::File from Nanquitas' CTRPluginFramework.
*/

class File {
public:

enum SeekPos
{
CUR, //Current Pos
SET, //Beginning
END //End
};

enum OpenMode
{
READ = 1, ///< Gives read permission
WRITE = 1 << 1, ///< Gives write permission
CREATE = 1 << 2, ///< The file will be created if it doesn't exist
APPEND = 1 << 3, ///< You'll be unable to overwrite the file, only append data to it
TRUNCATE = 1 << 4, ///< Will clear the file
SYNC = 1 << 5, ///< Will flush on each write
BINARY = 1 << 6, ///< Operations are performed in binary mode rather than text.

RW = READ | WRITE,
RB = READ | BINARY,
WB = WRITE | BINARY,
RWB = READ | WRITE | BINARY,
RWC = READ | WRITE | CREATE,
RWCB = READ | WRITE | CREATE | BINARY
};

enum OPResult
{
SUCCESS = 0, ///< Operation succeeded
FAILED = -1, ///< Generic Failed
FILE_NOT_OPEN = -2, ///< The File instance is not opened
INVALID_MODE = -3, ///< The mode passed when opened the file doesn't allow this operation
INVALID_ARG = -4, ///< One of the args passed to the operation is invalid (nullptr, etc)
UNEXPECTED_ERROR = -5 ///< An error occured
};

/* 'static' methods are functions which only use the class as a namespace, and do not require an instance. */
static int Create(std::string filePath);
static int Rename(std::string OldFilePath, std::string NewFilePath);
static int Remove(std::string filePath);
static bool Exists(std::string filePath);

static int Open(File &output, const std::string &filePath, int mode = READ | WRITE | SYNC);


File(void);
File(const std::string &filePath, int mode = READ | WRITE | SYNC);
~File(void);

//Returns OPResult or an error code from FS service
int Close(void);

int Read(void *buffer, u32 size); //Read data into buffer, with length being size to read in bytes
int Write(const void *data, u32 size); //Write data into buffer, with length being size to write in bytes
int Flush(void) const; //Flushes a file's content
u64 GetSize(void) const; //Get the size of the file
bool IsOpen(void) const; //Check if the file is open or not (true if open)

int Seek(s64 offset, SeekPos origin = SET); //Set the position in the file
u64 Tell(void) const; //Get current position in the file
void Rewind(void); //Set the position to the beginning of the file


template <typename T>
int Read(T &buffer) {
if (!m_FileIsOpen) return OPResult::FILE_NOT_OPEN;
if (!(m_Mode&File::READ)) return OPResult::INVALID_MODE;

T buf;
m_File->read((char *)&buf, sizeof(buf));
if (m_File->good()) {
buffer = buf;
return OPResult::SUCCESS;
}
return OPResult::FAILED;
}

template <typename T>
int Write(T data) {
if (!m_FileIsOpen) return OPResult::FILE_NOT_OPEN;
if (!(m_Mode&File::WRITE)) return OPResult::INVALID_MODE;

(*m_File) << data;
m_File->write((char *)&data, sizeof(data));
if (m_File->good()) {
if (m_Mode&File::SYNC) m_File->flush();
return OPResult::SUCCESS;
}
return OPResult::FAILED;
}


private:
static void PathFixups(std::string &filePath);

std::fstream *m_File;
std::string m_Path;
int m_Mode;
bool m_FileIsOpen;
};

namespace FS {
FS_Archive GetSDMCArchive(void);
}

#endif
5 changes: 4 additions & 1 deletion include/common/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

#include "common/archive.hpp"
#include "common/smdh.hpp"
#include "player.h"

#include "core/save/item.h"
#include "core/save/player.h"

#include <3ds.h>
#include <stdarg.h>
Expand All @@ -20,6 +22,7 @@ namespace StringUtils
namespace EditorUtils
{
std::vector<u32> findPlayerReferences(Player *player);
std::vector<std::pair<std::string, s32>> load_player_invitems(int selectedplayer);
}

u16 strToU16(std::string str);
Expand Down
39 changes: 39 additions & 0 deletions include/core/management/itemManagement.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* This file is part of LeafEdit
* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/

#ifndef ITEMMANAGEMENT_HPP
#define ITEMMANAGEMENT_HPP

#include <3ds.h>
#include <map>

namespace ItemManagement
{
void DrawItem(u8 ItemID, int x, int y, float ScaleX, float ScaleY); // Draw the Items.
void LoadDatabase(int lang); // Load Item Database.
}

#endif
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
/*
* This file is part of LeafEdit
* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/

#ifndef TOWNMANAGEMENT_HPP
#define TOWNMANAGEMENT_HPP

#include <3ds.h>
#include <stdio.h>
#include <string>

namespace TownManagement
{
Result BackupTown(u64 ID, FS_MediaType Media, u32 lowID, u32 highID);
Result CreateNewTown(FS_MediaType Media, u64 TID, u32 lowID, u32 highID, u32 uniqueID); // Doesn't really work yet.
Result LaunchTown(FS_MediaType Mediatype, u64 TID);
Result RestoreTown(u64 ID, FS_MediaType Media, u32 lowID, u32 highID, u32 uniqueID, std::string saveFolder);

void DeleteBackup(u64 ID, std::string backup);
}

/*
* This file is part of LeafEdit
* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/

#ifndef TOWNMANAGEMENT_HPP
#define TOWNMANAGEMENT_HPP

#include <3ds.h>
#include <stdio.h>
#include <string>

namespace TownManagement
{
Result BackupTown(u64 ID, FS_MediaType Media, u32 lowID, u32 highID);
Result CreateNewTown(FS_MediaType Media, u64 TID, u32 lowID, u32 highID, u32 uniqueID); // Doesn't really work yet.
Result LaunchTown(FS_MediaType Mediatype, u64 TID);
Result RestoreTown(u64 ID, FS_MediaType Media, u32 lowID, u32 highID, u32 uniqueID, std::string saveFolder);

void DeleteBackup(u64 ID, std::string backup);
}

#endif

0 comments on commit c26790e

Please sign in to comment.