1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Fix creation of new title sequences

This commit is contained in:
Ted John
2016-11-29 13:42:24 +00:00
parent a66ce50db8
commit 975cb43137
7 changed files with 50 additions and 3 deletions

View File

@@ -111,7 +111,6 @@ public:
{
zip_replace(_zip, index, source);
}
zip_source_free(source);
}
};

View File

@@ -30,6 +30,13 @@ interface IZipArchive
virtual const uint64 GetFileSize(size_t index) const abstract;
virtual void * GetFileData(const utf8 * path, size_t * outSize) const abstract;
/**
* Creates or overwrites a file within the zip archive to the given data buffer.
* @param path The path of the file within the zip.
* @param data The data to write, this buffer must not be mutated or disposed until
* the zip archive has been disposed.
* @param dataSize The size of the data in bytes.
*/
virtual void SetFileData(const utf8 * path, void * data, size_t dataSize) abstract;
};

View File

@@ -39,6 +39,13 @@ static utf8 * LegacyScriptWrite(TitleSequence * seq);
extern "C"
{
TitleSequence * CreateTitleSequence()
{
TitleSequence * seq = Memory::Allocate<TitleSequence>();
Memory::Set(seq, 0, sizeof(TitleSequence));
return seq;
}
TitleSequence * LoadTitleSequence(const utf8 * path)
{
size_t scriptLength;
@@ -87,7 +94,7 @@ extern "C"
std::vector<TitleCommand> commands = LegacyScriptRead(script, scriptLength, saves);
TitleSequence * seq = Memory::Allocate<TitleSequence>();
TitleSequence * seq = CreateTitleSequence();
seq->Name = Path::GetFileNameWithoutExtension(path);
seq->Path = String::Duplicate(path);
seq->NumSaves = saves.size();

View File

@@ -84,6 +84,7 @@ constexpr const utf8 * TITLE_SEQUENCE_EXTENSION = ".parkseq";
extern "C"
{
#endif
TitleSequence * CreateTitleSequence();
TitleSequence * LoadTitleSequence(const utf8 * path);
void FreeTitleSequence(TitleSequence * seq);

View File

@@ -142,6 +142,31 @@ namespace TitleSequenceManager
return index;
}
size_t CreateItem(const utf8 * name)
{
utf8 path[MAX_PATH];
GetUserSequencesPath(path, sizeof(path));
Path::Append(path, sizeof(path), name);
String::Append(path, sizeof(path), TITLE_SEQUENCE_EXTENSION);
TitleSequence * seq = CreateTitleSequence();
seq->Name = String::Duplicate(name);
seq->Path = String::Duplicate(path);
seq->IsZip = true;
bool success = TileSequenceSave(seq);
FreeTitleSequence(seq);
size_t index = SIZE_MAX;
if (success)
{
AddSequence(path);
SortSequences();
index = FindItemIndexByPath(path);
}
return success;
}
static const uint16 GetPredefinedIndex(const std::string &path)
{
const utf8 * filename = Path::GetFileName(path.c_str());
@@ -346,4 +371,9 @@ extern "C"
{
return TitleSequenceManager::DuplicateItem(i, name);
}
size_t title_sequence_manager_create(const utf8 * name)
{
return TitleSequenceManager::CreateItem(name);
}
}

View File

@@ -37,6 +37,7 @@ namespace TitleSequenceManager
void DeleteItem(size_t i);
size_t RenameItem(size_t i, const utf8 * name);
size_t DuplicateItem(size_t i, const utf8 * name);
size_t CreateItem(const utf8 * name);
}
constexpr uint16 PREDEFINED_INDEX_CUSTOM = UINT16_MAX;
@@ -55,6 +56,7 @@ extern "C" {
void title_sequence_manager_delete(size_t i);
size_t title_sequence_manager_rename(size_t i, const utf8 * name);
size_t title_sequence_manager_duplicate(size_t i, const utf8 * name);
size_t title_sequence_manager_create(const utf8 * name);
#ifdef __cplusplus
}

View File

@@ -609,7 +609,8 @@ static void window_title_editor_textinput(rct_window *w, int widgetIndex, char *
if (filename_valid_characters(text)) {
if (title_sequence_manager_get_index_for_name(text) == SIZE_MAX) {
if (widgetIndex == WIDX_TITLE_EDITOR_NEW_BUTTON) {
title_sequence_create_preset(text);
size_t newIndex = title_sequence_manager_create(text);
window_title_editor_load_sequence(newIndex);
} else if (widgetIndex == WIDX_TITLE_EDITOR_DUPLICATE_BUTTON) {
size_t newIndex = title_sequence_manager_duplicate(_selectedTitleSequence, text);
window_title_editor_load_sequence(newIndex);