Skip to content

Commit

Permalink
minimal global dictionary support
Browse files Browse the repository at this point in the history
  • Loading branch information
ericoporto committed Apr 17, 2024
1 parent 2b4d449 commit 7a76f77
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
15 changes: 15 additions & 0 deletions fancy_demo/fancy.asc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#define MAX_LINES 16
#define MAX_TAG_NEST 6

Dictionary* _tvdict;

#region TEXT_TOKEN_REG
enum TkType
{
Expand Down Expand Up @@ -131,6 +133,10 @@ int _get_tag_data(String tag, TagType tag_type)
if (p == 0) return -1;
String data = tag.Substring(p, tag.Length-p);
if (data.Chars[0] >= '0' && data.Chars[0] <= '9') return data.AsInt;
if (_tvdict.Contains(data)) {
String sval = _tvdict.Get(data);
return sval.AsInt;
}
return 0;
}

Expand Down Expand Up @@ -391,6 +397,10 @@ void _draw_tokens(FancyTextToken* tk_arr[], int tk_count, FancyState* fs, Drawin
// ---------------- fancy module public interface -----------------------
// ----------------------------------------------------------------------

static void Fancy::AddAlias(String key, int value)
{
_tvdict.Set(key, String.Format("%d", value));
}

static FancyDrawingConfig* FancyDrawingConfig::Create(FontType font, int color, int outline_color, int outline_width, Alignment align, int line_spacing)
{
Expand Down Expand Up @@ -520,3 +530,8 @@ void FancyTypedText::Start(String text)
this._typed_token_len = 0;
this._typed_token_count = 0;
}

void game_start()
{
_tvdict = Dictionary.Create(eSorted, eCaseInsensitive);
}
5 changes: 5 additions & 0 deletions fancy_demo/fancy.ash
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ managed struct FancyDrawingConfig {
static import FancyDrawingConfig* Create(FontType font, int color, int outline_color = COLOR_TRANSPARENT, int outline_width = 1, Alignment align = eAlignBottomLeft, int line_spacing = 0);
};

builtin managed struct Fancy {
// allows adding a global alias to a tag-value. Ex: AddAlias("red", 63488) allows using [c:red] instead of [c:63488].
import static void AddAlias(String key, int value);
};

struct FancyTextBase {
/// Setup text arrangement and display parameters
import void SetDrawingConfig(FancyDrawingConfig* config);
Expand Down
4 changes: 3 additions & 1 deletion fancy_demo/room1.asc
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ FancyTypedText fttb;

function room_AfterFadeIn()
{
Fancy.AddAlias("red", 64493);

// surface extension
DrawingSurface* surf = Room.GetDrawingSurfaceForBackground();
surf.DrawFancyTextWrapped(10, 170, 60, 65535, eFontSpeechWithoutOutline, "[c:61025]A [o:33153]key[/o] [s:2042][/c]!");

// using text base
fttb.SetDrawingConfig(FancyDrawingConfig.Create(eFontSpeechWithoutOutline, 22422));
fttb.SetDrawingArea(48, 48, 200);
fttb.Start("Hello!\n[o:8560]Can you find me the [c:27647]blue cup [s:2041][/c][/o]?\nI lost it in the [c:64493]dangerous [f:0]planet[/f][/c], somewhere.");
fttb.Start("Hello!\n[o:8560]Can you find me the [c:27647]blue cup [s:2041][/c][/o]?\nI lost it in the [c:red]dangerous [f:0]planet[/f][/c], somewhere.");
}

void repeatedly_execute_always()
Expand Down

0 comments on commit 7a76f77

Please sign in to comment.