@@ -2034,7 +2034,12 @@ class ScriptBuilder {
2034
2034
this . _string ( text ) ;
2035
2035
} ;
2036
2036
2037
- _loadStructuredText = ( inputText : string ) => {
2037
+ // @deprecated Replace with _loadAndDisplayText which supports wait codes
2038
+ _loadStructuredText = (
2039
+ inputText : string ,
2040
+ avatarIndex ?: number ,
2041
+ scrollHeight ?: number
2042
+ ) => {
2038
2043
const { fonts, defaultFontId } = this . options ;
2039
2044
let font = fonts . find ( ( f ) => f . id === defaultFontId ) ;
2040
2045
@@ -2118,6 +2123,18 @@ class ScriptBuilder {
2118
2123
}
2119
2124
} ) ;
2120
2125
2126
+ // Replace newlines with scroll code if larger than max dialogue size
2127
+ if ( scrollHeight ) {
2128
+ let numNewlines = 0 ;
2129
+ text = text . replace ( / \\ 0 1 2 / g, ( newline ) => {
2130
+ numNewlines ++ ;
2131
+ if ( numNewlines > scrollHeight - 1 ) {
2132
+ return "\\015" ;
2133
+ }
2134
+ return newline ;
2135
+ } ) ;
2136
+ }
2137
+
2121
2138
if ( indirectVars . length > 0 ) {
2122
2139
for ( const indirectVar of indirectVars ) {
2123
2140
this . _getInd ( indirectVar . local , indirectVar . arg ) ;
@@ -2130,6 +2147,23 @@ class ScriptBuilder {
2130
2147
this . _dw ( ...usedVariableAliases ) ;
2131
2148
}
2132
2149
2150
+ // Add avatar
2151
+ if ( avatarIndex !== undefined ) {
2152
+ const { fonts } = this . options ;
2153
+ const avatarFontSize = 16 ;
2154
+ const fontIndex = fonts . length + Math . floor ( avatarIndex / avatarFontSize ) ;
2155
+ const baseCharCode = ( ( avatarIndex * 4 ) % ( avatarFontSize * 4 ) ) + 64 ;
2156
+ text = `${ textCodeSetSpeed ( 0 ) } ${ textCodeSetFont (
2157
+ fontIndex
2158
+ ) } ${ String . fromCharCode ( baseCharCode ) } ${ String . fromCharCode (
2159
+ baseCharCode + 1
2160
+ ) } \\n${ String . fromCharCode ( baseCharCode + 2 ) } ${ String . fromCharCode (
2161
+ baseCharCode + 3
2162
+ ) } ${ textCodeSetSpeed ( 2 ) } ${ textCodeGotoRel ( 1 , - 1 ) } ${ textCodeSetFont (
2163
+ 0
2164
+ ) } ${ text } `;
2165
+ }
2166
+
2133
2167
this . _string ( text ) ;
2134
2168
} ;
2135
2169
0 commit comments