1+ // / @func concat(val1[, val2, ...])
2+ // / @desc Concatenates a bunch of arguments into a string
3+ // / @param {*} value1
4+ // / @param {*} [value2]
5+ // / ...
6+ function concat () {
7+ var _str = " " ;
8+
9+ for (var i=0 ; i<argument_count; i++) {
10+ _str += string (argument[i]);
11+ }
12+
13+ return _str;
14+ }
15+
16+
17+ // / @func dialogue_line_breaker(str, max_width, font)
18+ // / @desc Formats a long string so that it doesn't exceed max_width
19+ // / @arg {string} str
20+ // / @arg {real} max_width
21+ // / @arg {Font} font
22+ function dialogue_line_breaker (_str, _max_width, _font) {
23+ var _old_font = draw_get_font ();
24+ draw_set_font (_font);
25+
26+ // check to see if the string is already short enough to fit on one line.
27+ if (string_width (_str) <= _max_width)
28+ return _str;
29+
30+ var _out_str = " " ;
31+ var _in_str_len = string_length (_str);
32+ var _line_buffer = " " ;
33+ var _word_buffer = " " ;
34+ var _cur_char = " " ;
35+
36+ // break up string into lines
37+ for (var i=1 ; i<=_in_str_len; i++) {
38+ _cur_char = string_char_at (_str,i);
39+
40+ // manual line break
41+ if (_cur_char == " \n " ) {
42+ // if current line is too long, break it
43+ if (string_width (_line_buffer + _word_buffer) > _max_width) {
44+ _out_str += _line_buffer + " \n " + _word_buffer + " \n " ;
45+ } else {
46+ _out_str += _line_buffer + _word_buffer + " \n " ;
47+ }
48+
49+ _line_buffer = " " ;
50+ _word_buffer = " " ;
51+ } else if (_cur_char == " " ) { // space
52+ if (string_width (_line_buffer + _word_buffer + _cur_char) > _max_width) {
53+ _out_str += _line_buffer + _word_buffer + " \n " ;
54+ _line_buffer = " " ;
55+ _word_buffer = " " ;
56+ } else {
57+ _line_buffer += _word_buffer + _cur_char;
58+ _word_buffer = " " ;
59+ }
60+ } else { // others
61+ if (string_width (_line_buffer + _word_buffer + _cur_char) > _max_width) {
62+ _out_str += _line_buffer + " \n " ;
63+ _line_buffer = " " ;
64+ _word_buffer += _cur_char;
65+ } else {
66+ _word_buffer += _cur_char;
67+ }
68+ }
69+
70+ // end of line
71+ if (i == _in_str_len) {
72+ _out_str += _line_buffer + _word_buffer;
73+ }
74+ }
75+
76+ draw_set_font (_old_font);
77+
78+ return _out_str;
79+ }
80+
81+ // / @func pad_string(str, char, position, width)
82+ // / @desc Pads a string with char until it is a certain width
83+ // / @arg {string} str
84+ // / @arg {string} char
85+ // / @arg {integer} position
86+ // / @arg {real} width
87+ function pad_string (_str, _char, _position, _width) {
88+ while (string_width (_str + _char) < _width) {
89+ _str = string_insert (_char, _str, _position);
90+ }
91+
92+ return _str;
93+ }
0 commit comments