Skip to content

Commit

Permalink
Added add_text_label_formatted opcode (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
MiranDMC authored Dec 29, 2024
1 parent aa3d078 commit f63f366
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
- new opcode **2606 ([load_fxt](https://library.sannybuilder.com/#/sa/text/2606))**
- new opcode **2607 ([unload_fxt](https://library.sannybuilder.com/#/sa/text/2607))**
- new opcode **2608 ([get_text_length](https://library.sannybuilder.com/#/sa/text/2608))**
- new opcode **2609 ([add_text_label_formatted](https://library.sannybuilder.com/#/sa/text/2609))**
- new and updated opcodes
- implemented support for **memory pointer string** arguments for all game's native opcodes
- **0B1E ([sign_extend](https://library.sannybuilder.com/#/sa/bitwise/0B1E))**
Expand Down
12 changes: 12 additions & 0 deletions cleo_plugins/Text/Text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Text
CLEO_RegisterOpcode(0x2606, opcode_2606); // load_fxt
CLEO_RegisterOpcode(0x2607, opcode_2607); // unload_fxt
CLEO_RegisterOpcode(0x2608, opcode_2608); // get_text_length
CLEO_RegisterOpcode(0x2609, opcode_2609); // add_text_label_formatted

// register event callbacks
CLEO_RegisterCallback(eCallbackId::GameBegin, OnGameBegin);
Expand Down Expand Up @@ -522,6 +523,17 @@ class Text
OPCODE_WRITE_PARAM_INT(result);
return OR_CONTINUE;
}

//2609=-1,add_text_label_formatted %1d% args %2d%
static OpcodeResult __stdcall opcode_2609(CLEO::CRunningScript* thread)
{
OPCODE_READ_PARAM_STRING_LEN(gxt, 7); // GXT labels can be max 7 character long
OPCODE_READ_PARAM_STRING_FORMATTED(str);

textManager.AddFxt(gxt, str);

return OR_CONTINUE;
}
} textInstance;

CTextManager Text::textManager;
Expand Down
23 changes: 23 additions & 0 deletions tests/cleo_tests/Text/2609.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{$CLEO .s}
{$INCLUDE_ONCE ../cleo_tester.inc}

script_name '2609'
test("2609 (add_text_label_formatted)", tests)
terminate_this_custom_script

function tests
it("should add dynamic GXT", test1)
return

function test1
// gxt entry not present yet
0@v = get_text_label_string {key} 'CLE2609'
assert_eqs(0@v, "")

add_text_label_formatted {dynamicKey} 'CLE2609' {format} "cleo %s %d" {args} "test" 42
0@v = get_text_label_string {key} 'CLE2609'
assert_eqs(0@v, "cleo test 42")

remove_text_label {key} 'CLE2609' // cleanup
end
end

0 comments on commit f63f366

Please sign in to comment.