yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::core::AsmPatch Class Reference

Represents a ZScream-compatible ASM patch file. More...

#include <asm_patch.h>

Public Member Functions

 AsmPatch (const std::string &file_path, const std::string &folder)
 Construct a patch from a file path.
 
const std::string & name () const
 
const std::string & author () const
 
const std::string & version () const
 
const std::string & description () const
 
const std::string & folder () const
 
const std::string & filename () const
 
const std::string & file_path () const
 
bool enabled () const
 
void set_enabled (bool enabled)
 
const std::vector< PatchParameter > & parameters () const
 
std::vector< PatchParameter > & mutable_parameters ()
 
bool SetParameterValue (const std::string &define_name, int value)
 Set the value of a parameter by its define name.
 
PatchParameterGetParameter (const std::string &define_name)
 Get a parameter by its define name.
 
const PatchParameterGetParameter (const std::string &define_name) const
 
std::string GenerateContent () const
 Generate the patch file content with current parameter values.
 
absl::Status Save ()
 Save the patch to its original file location.
 
absl::Status SaveToPath (const std::string &output_path)
 Save the patch to a specific path.
 
bool is_valid () const
 Check if the patch was loaded successfully.
 

Private Member Functions

void ParseMetadata (const std::string &content)
 Parse metadata from the patch file content.
 

Static Private Member Functions

static PatchParameterType ParseType (const std::string &type_str)
 Parse a parameter type from a string.
 
static int ParseValue (const std::string &value_str)
 Parse an integer value from a string (handles $hex and decimal)
 
static void UpdateLine (std::string &content, const std::string &prefix, const std::string &new_value)
 Update a line in the content that starts with a prefix.
 
static void UpdateDefineLine (std::string &content, const std::string &define_name, int value)
 Update an Asar define line with a new value.
 

Private Attributes

std::string name_
 
std::string author_
 
std::string version_
 
std::string description_
 
std::string folder_
 
std::string filename_
 
std::string file_path_
 
std::string original_content_
 
bool enabled_ = true
 
bool is_valid_ = false
 
std::vector< PatchParameterparameters_
 

Detailed Description

Represents a ZScream-compatible ASM patch file.

ZScream uses comment-based metadata in ASM files to define patch properties and configurable parameters. This class parses that metadata and provides methods to modify parameter values and regenerate the file content.

Example patch file format:

;#PATCH_NAME=My Patch
;#PATCH_AUTHOR=Author Name
;#PATCH_VERSION=1.0
;#PATCH_DESCRIPTION
; Multi-line description
;#ENDPATCH_DESCRIPTION
;#ENABLED=true
;#DEFINE_START
;#name=My Value
;#type=byte
;#range=0,$FF
!MY_DEFINE = $10
;#DEFINE_END
lorom
; ASM code...

Definition at line 74 of file asm_patch.h.

Constructor & Destructor Documentation

◆ AsmPatch()

yaze::core::AsmPatch::AsmPatch ( const std::string & file_path,
const std::string & folder )

Construct a patch from a file path.

Parameters
file_pathFull path to the .asm file
folderCategory folder name (e.g., "Sprites", "Misc")

Definition at line 35 of file asm_patch.cc.

References file_path(), filename_, is_valid_, original_content_, and ParseMetadata().

Here is the call graph for this function:

Member Function Documentation

◆ name()

const std::string & yaze::core::AsmPatch::name ( ) const
inline

Definition at line 84 of file asm_patch.h.

References name_.

Referenced by yaze::editor::SettingsPanel::DrawPatchDetails().

◆ author()

const std::string & yaze::core::AsmPatch::author ( ) const
inline

Definition at line 85 of file asm_patch.h.

References author_.

Referenced by yaze::editor::SettingsPanel::DrawPatchDetails().

◆ version()

const std::string & yaze::core::AsmPatch::version ( ) const
inline

Definition at line 86 of file asm_patch.h.

References version_.

Referenced by yaze::editor::SettingsPanel::DrawPatchDetails().

◆ description()

const std::string & yaze::core::AsmPatch::description ( ) const
inline

Definition at line 87 of file asm_patch.h.

References description_.

Referenced by yaze::editor::SettingsPanel::DrawPatchDetails().

◆ folder()

const std::string & yaze::core::AsmPatch::folder ( ) const
inline

Definition at line 88 of file asm_patch.h.

References folder_.

◆ filename()

const std::string & yaze::core::AsmPatch::filename ( ) const
inline

Definition at line 89 of file asm_patch.h.

References filename_.

◆ file_path()

const std::string & yaze::core::AsmPatch::file_path ( ) const
inline

Definition at line 90 of file asm_patch.h.

References file_path_.

Referenced by AsmPatch().

◆ enabled()

bool yaze::core::AsmPatch::enabled ( ) const
inline

Definition at line 93 of file asm_patch.h.

References enabled_.

Referenced by set_enabled().

◆ set_enabled()

void yaze::core::AsmPatch::set_enabled ( bool enabled)
inline

Definition at line 94 of file asm_patch.h.

References enabled(), and enabled_.

Here is the call graph for this function:

◆ parameters()

const std::vector< PatchParameter > & yaze::core::AsmPatch::parameters ( ) const
inline

Definition at line 97 of file asm_patch.h.

References parameters_.

◆ mutable_parameters()

std::vector< PatchParameter > & yaze::core::AsmPatch::mutable_parameters ( )
inline

Definition at line 98 of file asm_patch.h.

References parameters_.

Referenced by yaze::editor::SettingsPanel::DrawPatchDetails().

◆ SetParameterValue()

bool yaze::core::AsmPatch::SetParameterValue ( const std::string & define_name,
int value )

Set the value of a parameter by its define name.

Parameters
define_nameThe Asar define name (e.g., "!MY_DEFINE")
valueThe new value to set
Returns
true if the parameter was found and updated

Definition at line 300 of file asm_patch.cc.

References parameters_.

◆ GetParameter() [1/2]

PatchParameter * yaze::core::AsmPatch::GetParameter ( const std::string & define_name)

Get a parameter by its define name.

Parameters
define_nameThe Asar define name
Returns
Pointer to the parameter, or nullptr if not found

Definition at line 310 of file asm_patch.cc.

References parameters_.

◆ GetParameter() [2/2]

const PatchParameter * yaze::core::AsmPatch::GetParameter ( const std::string & define_name) const

Definition at line 319 of file asm_patch.cc.

References parameters_.

◆ GenerateContent()

std::string yaze::core::AsmPatch::GenerateContent ( ) const

Generate the patch file content with current parameter values.

Returns
The complete .asm file content

Definition at line 329 of file asm_patch.cc.

References enabled_, original_content_, parameters_, UpdateDefineLine(), and UpdateLine().

Referenced by SaveToPath().

Here is the call graph for this function:

◆ Save()

absl::Status yaze::core::AsmPatch::Save ( )

Save the patch to its original file location.

Returns
Status indicating success or failure

Definition at line 375 of file asm_patch.cc.

References file_path_, and SaveToPath().

Here is the call graph for this function:

◆ SaveToPath()

absl::Status yaze::core::AsmPatch::SaveToPath ( const std::string & output_path)

Save the patch to a specific path.

Parameters
output_pathThe path to save to
Returns
Status indicating success or failure

Definition at line 379 of file asm_patch.cc.

References GenerateContent().

Referenced by Save().

Here is the call graph for this function:

◆ is_valid()

bool yaze::core::AsmPatch::is_valid ( ) const
inline

Check if the patch was loaded successfully.

Definition at line 138 of file asm_patch.h.

References is_valid_.

◆ ParseMetadata()

◆ ParseType()

PatchParameterType yaze::core::AsmPatch::ParseType ( const std::string & type_str)
staticprivate

Parse a parameter type from a string.

Parameters
type_strThe type string (e.g., "byte", "bool", "choice")
Returns
The corresponding PatchParameterType

Definition at line 247 of file asm_patch.cc.

References yaze::core::kBitfield, yaze::core::kBool, yaze::core::kByte, yaze::core::kChoice, yaze::core::kItem, yaze::core::kLong, and yaze::core::kWord.

Referenced by ParseMetadata().

◆ ParseValue()

int yaze::core::AsmPatch::ParseValue ( const std::string & value_str)
staticprivate

Parse an integer value from a string (handles $hex and decimal)

Parameters
value_strThe value string (e.g., "$10" or "16")
Returns
The parsed integer value

Definition at line 269 of file asm_patch.cc.

Referenced by ParseMetadata().

◆ UpdateLine()

void yaze::core::AsmPatch::UpdateLine ( std::string & content,
const std::string & prefix,
const std::string & new_value )
staticprivate

Update a line in the content that starts with a prefix.

Parameters
contentThe content to modify
prefixThe line prefix to find
new_valueThe new value to set after the '='

Definition at line 343 of file asm_patch.cc.

Referenced by GenerateContent().

◆ UpdateDefineLine()

void yaze::core::AsmPatch::UpdateDefineLine ( std::string & content,
const std::string & define_name,
int value )
staticprivate

Update an Asar define line with a new value.

Parameters
contentThe content to modify
define_nameThe define name to find
valueThe new value

Definition at line 358 of file asm_patch.cc.

Referenced by GenerateContent().

Member Data Documentation

◆ name_

std::string yaze::core::AsmPatch::name_
private

Definition at line 180 of file asm_patch.h.

Referenced by name(), and ParseMetadata().

◆ author_

std::string yaze::core::AsmPatch::author_
private

Definition at line 181 of file asm_patch.h.

Referenced by author(), and ParseMetadata().

◆ version_

std::string yaze::core::AsmPatch::version_
private

Definition at line 182 of file asm_patch.h.

Referenced by ParseMetadata(), and version().

◆ description_

std::string yaze::core::AsmPatch::description_
private

Definition at line 183 of file asm_patch.h.

Referenced by description(), and ParseMetadata().

◆ folder_

std::string yaze::core::AsmPatch::folder_
private

Definition at line 184 of file asm_patch.h.

Referenced by folder().

◆ filename_

std::string yaze::core::AsmPatch::filename_
private

Definition at line 185 of file asm_patch.h.

Referenced by AsmPatch(), filename(), and ParseMetadata().

◆ file_path_

std::string yaze::core::AsmPatch::file_path_
private

Definition at line 186 of file asm_patch.h.

Referenced by file_path(), and Save().

◆ original_content_

std::string yaze::core::AsmPatch::original_content_
private

Definition at line 187 of file asm_patch.h.

Referenced by AsmPatch(), and GenerateContent().

◆ enabled_

bool yaze::core::AsmPatch::enabled_ = true
private

Definition at line 188 of file asm_patch.h.

Referenced by enabled(), GenerateContent(), ParseMetadata(), and set_enabled().

◆ is_valid_

bool yaze::core::AsmPatch::is_valid_ = false
private

Definition at line 189 of file asm_patch.h.

Referenced by AsmPatch(), and is_valid().

◆ parameters_

std::vector<PatchParameter> yaze::core::AsmPatch::parameters_
private

The documentation for this class was generated from the following files: