diff --git a/src/compiler/index.js b/src/compiler/index.js index d216303..c6e1607 100755 --- a/src/compiler/index.js +++ b/src/compiler/index.js @@ -13,6 +13,7 @@ export function compile(text, options = {}) { info: tree.info, width: tree.info.PlayResX * 1 || null, height: tree.info.PlayResY * 1 || null, + wrapStyle: /^[0-3]$/.test(tree.info.WrapStyle) ? tree.info.WrapStyle * 1 : 2, collisions: tree.info.Collisions || 'Normal', styles, dialogues: compileDialogues({ diff --git a/src/compiler/styles.js b/src/compiler/styles.js index 50f83cc..aa8815f 100755 --- a/src/compiler/styles.js +++ b/src/compiler/styles.js @@ -92,6 +92,7 @@ export function compileStyles({ info, style, defaultStyle }) { xshad: s.Shadow, yshad: s.Shadow, fe: s.Encoding, + // TODO: [breaking change] remove `q` from style q: /^[0-3]$/.test(info.WrapStyle) ? info.WrapStyle * 1 : 2, }; result[s.Name] = { style: s, tag }; diff --git a/src/compiler/text.js b/src/compiler/text.js index 1a9a825..ea43b08 100644 --- a/src/compiler/text.js +++ b/src/compiler/text.js @@ -20,6 +20,7 @@ function inheritTag(pTag) { export function compileText({ styles, style, parsed, start, end }) { let alignment; + let q = { q: styles[style].tag.q }; let pos; let org; let move; @@ -43,6 +44,7 @@ export function compileText({ styles, style, parsed, start, end }) { for (let j = 0; j < tags.length; j++) { const tag = tags[j]; alignment = alignment || a2an[tag.a || 0] || tag.an; + q = compileTag(tag, 'q') || q; pos = pos || compileTag(tag, 'pos'); org = org || compileTag(tag, 'org'); move = move || compileTag(tag, 'move'); @@ -79,5 +81,5 @@ export function compileText({ styles, style, parsed, start, end }) { } slices.push(slice); - return Object.assign({ alignment, slices }, pos, org, move, fade, clip); + return Object.assign({ alignment, slices }, q, pos, org, move, fade, clip); } diff --git a/test/compiler/dialogues.js b/test/compiler/dialogues.js index 8548406..d2971b0 100644 --- a/test/compiler/dialogues.js +++ b/test/compiler/dialogues.js @@ -74,6 +74,7 @@ describe('dialogues compiler', () => { }, effect: null, alignment: 2, + q: 0, slices: [{ style: 'Default', fragments: [{ diff --git a/test/compiler/text.js b/test/compiler/text.js index 848f779..3820689 100644 --- a/test/compiler/text.js +++ b/test/compiler/text.js @@ -95,6 +95,12 @@ describe('text compiler', () => { drawing: null, dots: { x1: 1, y1: 2, x2: 3, y2: 4 }, }); + const test1 = compileText({ styles, style, parsed: parseText('bla bla').parsed }); + expect(test1.q).to.equal(0); + const test2 = compileText({ styles, style, parsed: parseText('{\\q1}bla bla').parsed }); + expect(test2.q).to.equal(1); + const test3 = compileText({ styles, style, parsed: parseText('{\\q1}bla {\\q2}bla').parsed }); + expect(test3.q).to.equal(2); }); it('should compile text with \\r', () => { diff --git a/types/index.d.ts b/types/index.d.ts index 1129eb1..d0e0683 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -128,6 +128,7 @@ export interface CompiledASSStyleTag { xshad: number; yshad: number; fe: number; + // TODO: [breaking change] delete `q` q: 0 | 1 | 2 | 3; } @@ -201,6 +202,7 @@ export interface Dialogue { } effect?: EffectBanner | EffectScroll | EffectUnknown; alignment: number; + q: 0 | 1 | 2 | 3; slices: DialogueSlice[]; pos?: { x: number; @@ -250,6 +252,7 @@ export interface CompiledASS { width: number; height: number; collisions: 'Normal' | 'Reverse'; + wrapStyle: 0 | 1 | 2 | 3; styles: { [styleName: string]: CompiledASSStyle }; dialogues: Dialogue[]; }