Skip to content

Commit

Permalink
more code reduction
Browse files Browse the repository at this point in the history
  • Loading branch information
ericoporto committed Apr 21, 2024
1 parent 47eacee commit 1987e5b
Showing 1 changed file with 14 additions and 34 deletions.
48 changes: 14 additions & 34 deletions fancy_demo/fancy.asc
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,8 @@ int StackOfInt::Pop()
}
#endregion // STACK_OF_INT_REG

FancyState* NewState(int x, int y) {
FancyState* NewState() {
FancyState* fs = new FancyState;
fs.X = x;
fs.Y = y;
return fs;
}

Expand Down Expand Up @@ -648,13 +646,6 @@ int _process_fancy_string(FancyTextToken* tk_arr[], FancyState* fs, String text,
return tk_count;
}

struct FancyStart {
FancyTextToken* tk_arr[];
FancyState* fs;
FancyConfig* config;
import void Init(FancyConfig* config);
};

// ----------------------------------------------------------------------
// ---------------- fancy module public interface -----------------------
// ----------------------------------------------------------------------
Expand Down Expand Up @@ -689,15 +680,6 @@ FancyConfig* FancyConfig::Clone()
return cfg;
}

void FancyStart::Init(FancyConfig* config)
{
this.tk_arr = _NewTxtTok();
this.fs = NewState(0, 0);
this.config = config;
if(config == null)
this.config = _default_cfg.Clone();
}

FancyConfig* _get_speech_config(Character* c, FancyConfig* config)
{
if(config == null) {
Expand Down Expand Up @@ -821,12 +803,12 @@ Fancy9Piece* Fancy9Piece::Clone()
}

void DrawFancyString(this DrawingSurface*, int x, int y, const string text, FancyConfig* config, int width)
{
FancyTextToken* tk_arr[]; FancyState* fs;
{
FancyStart ft; ft.Init(config);
config = ft.config; fs = ft.fs; tk_arr = ft.tk_arr;
}
{
FancyTextToken* tk_arr[] = _NewTxtTok();
FancyState* fs = NewState();
if(config == null)
config = _default_cfg.Clone();


fs.X = x; fs.Y = y;

Expand All @@ -838,17 +820,15 @@ void DrawFancyString(this DrawingSurface*, int x, int y, const string text, Fanc

DynamicSprite* CreateFromFancyString(static DynamicSprite, const string text, FancyConfig* config, int width)
{
FancyTextToken* tk_arr[]; FancyState* fs;
{
FancyStart ft; ft.Init(config);
config = ft.config; fs = ft.fs; tk_arr = ft.tk_arr;
}
FancyTextToken* tk_arr[] = _NewTxtTok();
FancyState* fs = NewState();
if(config == null)
config = _default_cfg.Clone();

int tk_count = _process_fancy_string(tk_arr, fs, text, width, config);
if(tk_count <= 0) return null;

DynamicSprite* spr = _create_text_sprite(tk_arr, tk_count, fs, text, -1, width, config);
return spr;
return _create_text_sprite(tk_arr, tk_count, fs, text, -1, width, config);
}

DynamicSprite* CreateFromFancyTextBox(static DynamicSprite, const string text, FancyConfig* config, int width, Fancy9Piece* f9p)
Expand Down Expand Up @@ -953,7 +933,7 @@ void FancyTextBase::set_FancyConfig(FancyConfig* value)
void FancyTextBase::SetDrawingArea(int x, int y, int width)
{
if(this._fs == null)
this._fs = NewState(x, y);
this._fs = NewState();

this._fs.X = x;
this._fs.Y = y;
Expand All @@ -965,7 +945,7 @@ protected void FancyTextBase::_set_text(String text)
{
if(this._cfg == null) { this._cfg = _default_cfg.Clone(); }
if(this._width <= 0) { this._width = FANCY_INFINITE_WIDTH; }
if(this._fs == null) { this._fs = NewState(0, 0); }
if(this._fs == null) { this._fs = NewState(); }
if(String.IsNullOrEmpty(text)) {
this._text = "";
this._tk_arr = null;
Expand Down

0 comments on commit 1987e5b

Please sign in to comment.