Comparing version
@@ -131,2 +131,2 @@ declare enum EachStyle { | ||
export { MaiChart, Note, NoteAppearance, NoteCollection, NoteStyles, NoteType, SimaiConvert, SimaiFile, SlideMorph }; | ||
export { EachStyle, Location, MaiChart, Note, NoteAppearance, NoteCollection, NoteGroup, NoteStyles, NoteType, SimaiConvert, SimaiFile, SlideMorph, SlidePath, SlideSegment, SlideType }; |
@@ -1,10 +0,10 @@ | ||
"use strict";var z=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var X=Object.prototype.hasOwnProperty;var Y=(a,e)=>{for(var r in e)z(a,r,{get:e[r],enumerable:!0})},G=(a,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Q(e))!X.call(a,n)&&n!==r&&z(a,n,{get:()=>e[n],enumerable:!(i=j(e,n))||i.enumerable});return a};var ee=a=>G(z({},"__esModule",{value:!0}),a);var te={};Y(te,{MaiChart:()=>x,Note:()=>C,NoteAppearance:()=>v,NoteCollection:()=>b,NoteStyles:()=>S,NoteType:()=>f,SimaiConvert:()=>M,SimaiFile:()=>A,SlideMorph:()=>D});module.exports=ee(te);var m=class extends Error{constructor(r,i,n){super(n);this.name="SimaiException",this.character=i,this.line=r}};var l=class extends m{constructor(r,i,n,o){super(r,i,o);this.name="UnexpectedCharacterException",this.expected=n}};var u=class extends m{constructor(e,r,i){super(e,r,i),this.name="UnsupportedSyntaxException"}};var F=class extends m{constructor(e,r,i){super(e,r,i),this.name="UnterminatedSectionException"}};var N=class{constructor(e,r,i,n){this.type=e,this.lexeme=r,this.line=i,this.character=n}};var _=class a{constructor(e){this.space=String.fromCharCode(32);this.enSpace=String.fromCharCode(8194);this.punctuationSpace=String.fromCharCode(8200);this.ideographicSpace=String.fromCharCode(12288);this.lineSeparator=String.fromCharCode(8232);this.paragraphSeparator=String.fromCharCode(8233);this.endOfFileChar="E";this.eachDividerChars=new Set(["/","`"]);this.decoratorChars=new Set(["f","b","x","h","m","!","?","@","$"]);this.slideChars=new Set(["-",">","<","^","p","q","v","V","s","z","w"]);this.separatorChars=new Set(["\r"," ",this.lineSeparator,this.paragraphSeparator,this.space,this.enSpace,this.punctuationSpace,this.ideographicSpace]);this._current=0;this._charIndex=0;this._line=1;this._start=0;this._sequence=e}get isAtEnd(){return this._current>=this._sequence.length}*getTokens(){for(;!this.isAtEnd;){this._start=this._current;let e=this.scanToken();e!==void 0&&(yield e)}}scanToken(){this._charIndex++;let e=this.advance();if(this.decoratorChars.has(e))return this.compileToken(4);if(this.eachDividerChars.has(e))return this.compileToken(9);if(this.separatorChars.has(e))return;let[r,i]=this.tryScanLocationToken();if(r)return this._current+=i-1,this.compileToken(3);let[n,o]=this.isReadingSlideDeclaration();if(n)return this._current+=o-1,this.compileToken(5);switch(e){case",":return this.compileToken(8);case"(":return this.compileSectionToken(1,"(",")");case"{":return this.compileSectionToken(2,"{","}");case"[":return this.compileSectionToken(6,"[","]");case"*":return this.compileToken(7);case` | ||
`:this._line++,this._charIndex=0;return;case this.endOfFileChar:return this.compileToken(10);case"|":{if(this.peek()!=="|")throw new l(this._line,this._charIndex,"|");for(;this.peek()!==` | ||
`&&!this.isAtEnd;)this.advance();return}default:throw new u(this._line,this._charIndex)}}tryScanLocationToken(){let e=this.peekPrevious();if(a.isButtonLocation(e))return[!0,1];if(!a.isSensorLocation(e))return[!1,0];let r=this.peek();if(a.isButtonLocation(r))return[!0,2];if(e==="C")return[!0,1];let i=this.separatorChars.has(r)||r===` | ||
`||r==="\0";if(e===this.endOfFileChar&&i)return[!1,0];throw new l(this._line,this._charIndex,"1, 2, 3, 4, 5, 6, 7, 8")}isReadingSlideDeclaration(){if(!this.slideChars.has(this.peekPrevious()))return[!1,0];let e=this.peek();return[!0,e==="p"||e==="q"?2:1]}compileSectionToken(e,r,i){for(this._start++;this.peek()!==i;){if(this.isAtEnd||this.peek()===r)throw new F(this._line,this._charIndex);this.advance()}let n=this.compileToken(e);return this.advance(),n}compileToken(e){let r=this._sequence.substring(this._start,this._current);return new N(e,r,this._line,this._charIndex)}static isSensorLocation(e){return e.charCodeAt(0)>="A".charCodeAt(0)&&e.charCodeAt(0)<="E".charCodeAt(0)}static isButtonLocation(e){return e.charCodeAt(0)>="0".charCodeAt(0)&&e.charCodeAt(0)<="8".charCodeAt(0)}advance(){return this._sequence[this._current++]}peek(){return this.isAtEnd?"":this._sequence[this._current]}peekPrevious(){return this._current==0?"":this._sequence[this._current-1]}};var d=class{constructor(e,r){this.index=e,this.group=r}equals(e){return this.index===e.index&&this.group===e.group}toString(){return`index: ${this.index}, group: ${this.group.toString()}`}};var x=class{constructor(){this.noteCollections=[]}};var b=class extends Array{constructor(r){super();this.eachStyle=0;this.time=r}addNote(r){r.parentCollection=this,this.push(r)}};var E=(t=>(t[t.Tap=0]="Tap",t[t.ASensor=1]="ASensor",t[t.BSensor=2]="BSensor",t[t.CSensor=3]="CSensor",t[t.DSensor=4]="DSensor",t[t.ESensor=5]="ESensor",t))(E||{});var T=class{constructor(e){this._source=e;this._index=-1;this._done=!1}get current(){return this._current}get index(){return this._index}get done(){return this._done}moveNext(){let e=this._source[Symbol.iterator](),{value:r,done:i}=e.next();return this._current=r,this._done=!!i,this._index++,!i}reset(){this._index=-1,this._done=!1,this._current=void 0}};var h=class extends m{constructor(r,i,n,o){super(r,i,o);this.name="ScopeMismatchException",this.correctScope=n}};var v=(n=>(n[n.Default=0]="Default",n[n.ForceNormal=1]="ForceNormal",n[n.ForceStar=2]="ForceStar",n[n.ForceStarSpinning=3]="ForceStarSpinning",n))(v||{});var S=(t=>(t[t.None=0]="None",t[t.Ex=1]="Ex",t[t.Star=2]="Star",t[t.StarPower=4]="StarPower",t[t.Fireworks=5]="Fireworks",t[t.Mine=6]="Mine",t))(S||{});var f=(t=>(t[t.Tap=0]="Tap",t[t.Touch=1]="Touch",t[t.Hold=2]="Hold",t[t.Slide=3]="Slide",t[t.Break=4]="Break",t[t.ForceInvalidate=5]="ForceInvalidate",t))(f||{});var D=(r=>(r[r.FadeIn=0]="FadeIn",r[r.SuddenIn=1]="SuddenIn",r))(D||{});var C=class{constructor(e){this.location=new d(0,0);this.styles=0;this.appearance=0;this.type=0;this.slideMorph=0;this.slidePaths=[];this.parentCollection=e}get isEx(){return(this.styles&1)!=0}get isStar(){return this.appearance>=2||this.slidePaths.length>0&&this.appearance!==1}getVisibleDuration(){var r;var e=(r=this.length)!=null?r:0;return this.slidePaths.length>0&&(e=Math.max(...this.slidePaths.map(i=>i.delay+i.duration))),e}};var L=class extends m{constructor(e,r,i){super(e,r,i),this.name="InvalidSyntaxException"}};var w=class{get secondsPerBar(){return this.tempo===0?0:60/this.tempo}get secondsPerBeat(){return this.secondsPerBar/((this.subdivisions===0?4:this.subdivisions)/4)}constructor(e,r=4){this.tempo=e,this.subdivisions=r}explicitOverride(e){this.tempo=60/e,this.subdivisions=4}};var y=class{constructor(e){this.startLocation=new d(0,0);this.delay=0;this.duration=0;this.type=3;this.segments=e}};var k=class{constructor(e){this.vertices=e!=null?e:[],this.slideType=0}};var I=class a{static process(e,r,i,n){let o=new y([]);o.delay=n.secondsPerBeat,a.readSegment(e,i,r.location,o);let t=!0;for(;!e.endOfFile&&(t||e.moveNext());){var s=e.enumerator.current;switch(t=!1,s.type){case 1:case 2:throw new h(s.line,s.character,4);case 4:{a.decorateSlide(s,o);break}case 5:{let c=o.segments[o.segments.length-1];a.readSegment(e,s,c.vertices[c.vertices.length-1],o),t=!0;break}case 6:{a.readDuration(s,e.currentTiming,o);break}case 7:return e.moveNext(),o;case 8:case 9:case 10:case 3:return o;case 0:break;default:throw new u(s.line,s.character)}}return o}static readSegment(e,r,i,n){let o=new k([]),t=r.lexeme.length;a.assignVertices(e,r,o),o.slideType=a.identifySlideType(r,i,o,t),n.segments.push(o)}static decorateSlide(e,r){switch(e.lexeme[0]){case"b":r.type=4;return;default:throw new u(e.line,e.character)}}static identifySlideType(e,r,i,n){switch(e.lexeme[0]){case"-":return 0;case">":return p.determineRingType(r,i.vertices[0],1);case"<":return p.determineRingType(r,i.vertices[0],-1);case"^":return p.determineRingType(r,i.vertices[0]);case"q":return n===2&&e.lexeme[1]==="q"?9:4;case"p":return n===2&&e.lexeme[1]==="p"?10:5;case"v":return 3;case"V":return 8;case"s":return 6;case"z":return 7;case"w":return 11;default:throw new u(e.line,e.character)}}static assignVertices(e,r,i){do{if(!e.moveNext())throw new u(r.line,r.character);let n=e.enumerator.current,[o,t]=p.tryReadLocation(n);o&&i.vertices.push(t)}while(e.enumerator.current.type===3)}static readDuration(e,r,i){let o=r,t=e.lexeme.indexOf("#");if(t>-1){let $=e.lexeme.lastIndexOf("#")+1-1,K=e.lexeme.substring(0,t),W=t!==$,V=parseFloat(K);if(isNaN(V))throw new l(e.line,e.character,'0~9, or "."');W?i.delay=V:(o.tempo=V,i.delay=o.secondsPerBar)}let c=e.lexeme.substring(0),g=c.indexOf(":");if(g===-1){let R=parseFloat(c);if(isNaN(R))throw new l(e.line,e.character+0,'0~9, or "."');i.duration+=R;return}let U=parseFloat(c.substring(0,g));if(isNaN(U))throw new l(e.line,e.character+0,'0~9, or "."');let Z=parseFloat(c.substring(g+1));if(isNaN(Z))throw new u(e.line,e.character+0+g+1,'0~9, or "."');i.duration+=o.secondsPerBar/(U/4)*Z}};var O=class a{static process(e,r){let[i,n]=p.tryReadLocation(r);if(!i)throw new L(r.line,r.character);let o=new C(e.currentNoteCollection);o.location=n;let t=new w(e.currentNoteCollection.time);n.group!==0&&(o.type=1);let s=!1;for(;!e.endOfFile&&(s||e.moveNext());){let c=e.enumerator.current;switch(s=!1,c.type){case 1:case 2:throw new h(c.line,c.character,4);case 4:{a.decorateNote(c,o);break}case 5:{o.type===2&&(o.length=t.secondsPerBeat);let g=I.process(e,o,c,t);s=!0,o.slidePaths.push(g);break}case 6:{a.readDuration(c,e.currentTiming,o);break}case 7:throw new h(c.line,c.character,2);case 8:case 9:case 10:case 3:return o;case 0:break;default:throw new u(c.line,c.character)}}return o}static decorateNote(e,r){var i;switch(e.lexeme[0]){case"f":r.styles|=5;return;case"b":if(r.type===5)break;r.type=4;return;case"x":r.styles|=1;return;case"m":r.styles|=6;return;case"h":if(r.type===4||r.type===5)break;r.type=2,(i=r.length)!=null||(r.length=0);return;case"?":r.type=5,r.slideMorph=0;return;case"!":r.type=5,r.slideMorph=1;return;case"@":r.appearance=1;return;case"$":r.appearance=r.appearance===2?3:2;return}}static readDuration(e,r,i){if(i.type!==4&&(i.type=2),e.lexeme[0]==="#"){let s=parseFloat(e.lexeme.slice(1));if(isNaN(s))throw new l(e.line,e.character+1,'0~9, or "."');i.length=s;return}let n=e.lexeme.indexOf(":"),o=parseFloat(e.lexeme.slice(0,n)),t=parseFloat(e.lexeme.slice(n+1));if(isNaN(o)||isNaN(t))throw new l(e.line,e.character+1,'0~9, or "."');i.length=r.secondsPerBar/(o/4)*t}};var P=class{static process(e,r){if(r.lexeme[0]==="#"){let n=parseFloat(r.lexeme.slice(1));if(isNaN(n))throw new l(r.line,r.character+1,'0~9, or "."');e.currentTiming.explicitOverride(n);return}let i=parseFloat(r.lexeme);if(isNaN(i))throw new l(r.line,r.character,'0~9, or "."');e.currentTiming.subdivisions=i}};var B=class{static process(e,r){let i=parseFloat(r.lexeme);if(isNaN(i))throw new l(r.line,r.character,'0~9, or "."');e.currentTiming.tempo=i}};var p=class{constructor(e){this._chart=new x;this._maxFinishTime=0;this._currentTime=0;this.currentTiming=new w(0,0);this.endOfFile=!1;this.enumerator=new T(e)}getChart(){var i,n,o;let e=[],r=!1;for(;!this.endOfFile&&(r||this.moveNext());){let t=this.enumerator.current;switch(r=!1,t.type){case 1:{B.process(this,t);break}case 2:{P.process(this,t);break}case 3:{if((i=this.currentNoteCollection)!=null||(this.currentNoteCollection=new b(this._currentTime)),t.lexeme[0]==="0"){this.currentNoteCollection.eachStyle!==1&&(this.currentNoteCollection.eachStyle=2);break}let s=O.process(this,t);this.currentNoteCollection.addNote(s),r=!0,this._maxFinishTime=Math.max(this._maxFinishTime,this.currentNoteCollection.time+s.getVisibleDuration());break}case 8:this.currentNoteCollection!=null&&(e.push(this.currentNoteCollection),this.currentNoteCollection=void 0),this._currentTime+=this.currentTiming.secondsPerBeat;break;case 9:switch(t.lexeme[0]){case"/":break;case"`":this.currentNoteCollection!=null&&(this.currentNoteCollection.eachStyle=1);break}break;case 4:throw new h(t.line,t.character,1);case 5:throw new h(t.line,t.character,1);case 6:throw new h(t.line,t.character,3);case 7:throw new h(t.line,t.character,2);case 10:this._chart.finishTiming=this._currentTime;break;case 0:break;default:throw new u(t.line,t.character)}}return(o=(n=this._chart).finishTiming)!=null||(n.finishTiming=this._maxFinishTime),this.currentNoteCollection!==void 0&&(e.push(this.currentNoteCollection),this.currentNoteCollection=void 0),this._chart.noteCollections=e,this._chart}static determineRingType(e,r,i=0){switch(i){case 1:return(e.index+2)%8>=4?2:1;case-1:return(e.index+2)%8>=4?1:2;default:var n=r.index-e.index,o=n>=0?n>4?-1:1:n<-4?1:-1;return o>0?1:2}}static tryReadLocation(e){let r=e.lexeme[0].charCodeAt(0)>="A".charCodeAt(0)&&e.lexeme[0].charCodeAt(0)<="E".charCodeAt(0),i=r?e.lexeme.substring(1):e.lexeme.substring(0),n=0;if(r&&(n=E[e.lexeme[0].charCodeAt(0)-"A".charCodeAt(0)+1],n===3))return[!0,new d(0,n)];let o=parseInt(i);return o?[!0,new d(o-1,n)]:[!1,new d(0,0)]}moveNext(){return this.endOfFile=!this.enumerator.moveNext(),!this.endOfFile}};var M=class{static deserialize(e){let r=new _(e).getTokens();return new p(r).getChart()}};var A=class{constructor(e){this.data="";this.data=e}toKeyValuePairs(){let e="",r="",i=this.data.replace(`\r | ||
"use strict";var U=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var X=Object.prototype.hasOwnProperty;var Y=(a,e)=>{for(var r in e)U(a,r,{get:e[r],enumerable:!0})},ee=(a,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Q(e))!X.call(a,n)&&n!==r&&U(a,n,{get:()=>e[n],enumerable:!(t=G(e,n))||t.enumerable});return a};var re=a=>ee(U({},"__esModule",{value:!0}),a);var te={};Y(te,{EachStyle:()=>E,Location:()=>p,MaiChart:()=>b,Note:()=>v,NoteAppearance:()=>_,NoteCollection:()=>C,NoteGroup:()=>w,NoteStyles:()=>T,NoteType:()=>x,SimaiConvert:()=>V,SimaiFile:()=>z,SlideMorph:()=>L,SlidePath:()=>F,SlideSegment:()=>N,SlideType:()=>S});module.exports=re(te);var h=class extends Error{constructor(r,t,n){super(n);this.name="SimaiException",this.character=t,this.line=r}};var u=class extends h{constructor(r,t,n,o){super(r,t,o);this.name="UnexpectedCharacterException",this.expected=n}};var m=class extends h{constructor(e,r,t){super(e,r,t),this.name="UnsupportedSyntaxException"}};var y=class extends h{constructor(e,r,t){super(e,r,t),this.name="UnterminatedSectionException"}};var k=class{constructor(e,r,t,n){this.type=e,this.lexeme=r,this.line=t,this.character=n}};var I=class a{constructor(e){this.space=String.fromCharCode(32);this.enSpace=String.fromCharCode(8194);this.punctuationSpace=String.fromCharCode(8200);this.ideographicSpace=String.fromCharCode(12288);this.lineSeparator=String.fromCharCode(8232);this.paragraphSeparator=String.fromCharCode(8233);this.endOfFileChar="E";this.eachDividerChars=new Set(["/","`"]);this.decoratorChars=new Set(["f","b","x","h","m","!","?","@","$"]);this.slideChars=new Set(["-",">","<","^","p","q","v","V","s","z","w"]);this.separatorChars=new Set(["\r"," ",this.lineSeparator,this.paragraphSeparator,this.space,this.enSpace,this.punctuationSpace,this.ideographicSpace]);this._current=0;this._charIndex=0;this._line=1;this._start=0;this._sequence=e}get isAtEnd(){return this._current>=this._sequence.length}*getTokens(){for(;!this.isAtEnd;){this._start=this._current;let e=this.scanToken();e!==void 0&&(yield e)}}scanToken(){this._charIndex++;let e=this.advance();if(this.decoratorChars.has(e))return this.compileToken(4);if(this.eachDividerChars.has(e))return this.compileToken(9);if(this.separatorChars.has(e))return;let[r,t]=this.tryScanLocationToken();if(r)return this._current+=t-1,this.compileToken(3);let[n,o]=this.isReadingSlideDeclaration();if(n)return this._current+=o-1,this.compileToken(5);switch(e){case",":return this.compileToken(8);case"(":return this.compileSectionToken(1,"(",")");case"{":return this.compileSectionToken(2,"{","}");case"[":return this.compileSectionToken(6,"[","]");case"*":return this.compileToken(7);case` | ||
`:this._line++,this._charIndex=0;return;case this.endOfFileChar:return this.compileToken(10);case"|":{if(this.peek()!=="|")throw new u(this._line,this._charIndex,"|");for(;this.peek()!==` | ||
`&&!this.isAtEnd;)this.advance();return}default:throw new m(this._line,this._charIndex)}}tryScanLocationToken(){let e=this.peekPrevious();if(a.isButtonLocation(e))return[!0,1];if(!a.isSensorLocation(e))return[!1,0];let r=this.peek();if(a.isButtonLocation(r))return[!0,2];if(e==="C")return[!0,1];let t=this.separatorChars.has(r)||r===` | ||
`||r==="\0";if(e===this.endOfFileChar&&t)return[!1,0];throw new u(this._line,this._charIndex,"1, 2, 3, 4, 5, 6, 7, 8")}isReadingSlideDeclaration(){if(!this.slideChars.has(this.peekPrevious()))return[!1,0];let e=this.peek();return[!0,e==="p"||e==="q"?2:1]}compileSectionToken(e,r,t){for(this._start++;this.peek()!==t;){if(this.isAtEnd||this.peek()===r)throw new y(this._line,this._charIndex);this.advance()}let n=this.compileToken(e);return this.advance(),n}compileToken(e){let r=this._sequence.substring(this._start,this._current);return new k(e,r,this._line,this._charIndex)}static isSensorLocation(e){return e.charCodeAt(0)>="A".charCodeAt(0)&&e.charCodeAt(0)<="E".charCodeAt(0)}static isButtonLocation(e){return e.charCodeAt(0)>="0".charCodeAt(0)&&e.charCodeAt(0)<="8".charCodeAt(0)}advance(){return this._sequence[this._current++]}peek(){return this.isAtEnd?"":this._sequence[this._current]}peekPrevious(){return this._current==0?"":this._sequence[this._current-1]}};var E=(t=>(t[t.Default=0]="Default",t[t.ForceBroken=1]="ForceBroken",t[t.ForceEach=2]="ForceEach",t))(E||{});var p=class{constructor(e,r){this.index=e,this.group=r}equals(e){return this.index===e.index&&this.group===e.group}toString(){return`index: ${this.index}, group: ${this.group.toString()}`}};var b=class{constructor(){this.noteCollections=[]}};var C=class extends Array{constructor(r){super();this.eachStyle=0;this.time=r}addNote(r){r.parentCollection=this,this.push(r)}};var w=(i=>(i[i.Tap=0]="Tap",i[i.ASensor=1]="ASensor",i[i.BSensor=2]="BSensor",i[i.CSensor=3]="CSensor",i[i.DSensor=4]="DSensor",i[i.ESensor=5]="ESensor",i))(w||{});var S=(s=>(s[s.StraightLine=0]="StraightLine",s[s.RingCw=1]="RingCw",s[s.RingCcw=2]="RingCcw",s[s.Fold=3]="Fold",s[s.CurveCw=4]="CurveCw",s[s.CurveCcw=5]="CurveCcw",s[s.ZigZagS=6]="ZigZagS",s[s.ZigZagZ=7]="ZigZagZ",s[s.EdgeFold=8]="EdgeFold",s[s.EdgeCurveCw=9]="EdgeCurveCw",s[s.EdgeCurveCcw=10]="EdgeCurveCcw",s[s.Fan=11]="Fan",s))(S||{});var O=class{constructor(e){this._source=e;this._index=-1;this._done=!1}get current(){return this._current}get index(){return this._index}get done(){return this._done}moveNext(){let e=this._source[Symbol.iterator](),{value:r,done:t}=e.next();return this._current=r,this._done=!!t,this._index++,!t}reset(){this._index=-1,this._done=!1,this._current=void 0}};var d=class extends h{constructor(r,t,n,o){super(r,t,o);this.name="ScopeMismatchException",this.correctScope=n}};var _=(n=>(n[n.Default=0]="Default",n[n.ForceNormal=1]="ForceNormal",n[n.ForceStar=2]="ForceStar",n[n.ForceStarSpinning=3]="ForceStarSpinning",n))(_||{});var T=(i=>(i[i.None=0]="None",i[i.Ex=1]="Ex",i[i.Star=2]="Star",i[i.StarPower=4]="StarPower",i[i.Fireworks=5]="Fireworks",i[i.Mine=6]="Mine",i))(T||{});var x=(i=>(i[i.Tap=0]="Tap",i[i.Touch=1]="Touch",i[i.Hold=2]="Hold",i[i.Slide=3]="Slide",i[i.Break=4]="Break",i[i.ForceInvalidate=5]="ForceInvalidate",i))(x||{});var L=(r=>(r[r.FadeIn=0]="FadeIn",r[r.SuddenIn=1]="SuddenIn",r))(L||{});var v=class{constructor(e){this.location=new p(0,0);this.styles=0;this.appearance=0;this.type=0;this.slideMorph=0;this.slidePaths=[];this.parentCollection=e}get isEx(){return(this.styles&1)!=0}get isStar(){return this.appearance>=2||this.slidePaths.length>0&&this.appearance!==1}getVisibleDuration(){var r;var e=(r=this.length)!=null?r:0;return this.slidePaths.length>0&&(e=Math.max(...this.slidePaths.map(t=>t.delay+t.duration))),e}};var P=class extends h{constructor(e,r,t){super(e,r,t),this.name="InvalidSyntaxException"}};var D=class{get secondsPerBar(){return this.tempo===0?0:60/this.tempo}get secondsPerBeat(){return this.secondsPerBar/((this.subdivisions===0?4:this.subdivisions)/4)}constructor(e,r=4){this.tempo=e,this.subdivisions=r}explicitOverride(e){this.tempo=60/e,this.subdivisions=4}};var F=class{constructor(e){this.startLocation=new p(0,0);this.delay=0;this.duration=0;this.type=3;this.segments=e}};var N=class{constructor(e){this.vertices=e!=null?e:[],this.slideType=0}};var B=class a{static process(e,r,t,n){let o=new F([]);o.delay=n.secondsPerBeat,a.readSegment(e,t,r.location,o);let i=!0;for(;!e.endOfFile&&(i||e.moveNext());){var c=e.enumerator.current;switch(i=!1,c.type){case 1:case 2:throw new d(c.line,c.character,4);case 4:{a.decorateSlide(c,o);break}case 5:{let l=o.segments[o.segments.length-1];a.readSegment(e,c,l.vertices[l.vertices.length-1],o),i=!0;break}case 6:{a.readDuration(c,e.currentTiming,o);break}case 7:return e.moveNext(),o;case 8:case 9:case 10:case 3:return o;case 0:break;default:throw new m(c.line,c.character)}}return o}static readSegment(e,r,t,n){let o=new N([]),i=r.lexeme.length;a.assignVertices(e,r,o),o.slideType=a.identifySlideType(r,t,o,i),n.segments.push(o)}static decorateSlide(e,r){switch(e.lexeme[0]){case"b":r.type=4;return;default:throw new m(e.line,e.character)}}static identifySlideType(e,r,t,n){switch(e.lexeme[0]){case"-":return 0;case">":return f.determineRingType(r,t.vertices[0],1);case"<":return f.determineRingType(r,t.vertices[0],-1);case"^":return f.determineRingType(r,t.vertices[0]);case"q":return n===2&&e.lexeme[1]==="q"?9:4;case"p":return n===2&&e.lexeme[1]==="p"?10:5;case"v":return 3;case"V":return 8;case"s":return 6;case"z":return 7;case"w":return 11;default:throw new m(e.line,e.character)}}static assignVertices(e,r,t){do{if(!e.moveNext())throw new m(r.line,r.character);let n=e.enumerator.current,[o,i]=f.tryReadLocation(n);o&&t.vertices.push(i)}while(e.enumerator.current.type===3)}static readDuration(e,r,t){let o=r,i=e.lexeme.indexOf("#");if(i>-1){let K=e.lexeme.lastIndexOf("#")+1-1,W=e.lexeme.substring(0,i),j=i!==K,q=parseFloat(W);if(isNaN(q))throw new u(e.line,e.character,'0~9, or "."');j?t.delay=q:(o.tempo=q,t.delay=o.secondsPerBar)}let l=e.lexeme.substring(0),g=l.indexOf(":");if(g===-1){let s=parseFloat(l);if(isNaN(s))throw new u(e.line,e.character+0,'0~9, or "."');t.duration+=s;return}let H=parseFloat(l.substring(0,g));if(isNaN(H))throw new u(e.line,e.character+0,'0~9, or "."');let J=parseFloat(l.substring(g+1));if(isNaN(J))throw new m(e.line,e.character+0+g+1,'0~9, or "."');t.duration+=o.secondsPerBar/(H/4)*J}};var M=class a{static process(e,r){let[t,n]=f.tryReadLocation(r);if(!t)throw new P(r.line,r.character);let o=new v(e.currentNoteCollection);o.location=n;let i=new D(e.currentNoteCollection.time);n.group!==0&&(o.type=1);let c=!1;for(;!e.endOfFile&&(c||e.moveNext());){let l=e.enumerator.current;switch(c=!1,l.type){case 1:case 2:throw new d(l.line,l.character,4);case 4:{a.decorateNote(l,o);break}case 5:{o.type===2&&(o.length=i.secondsPerBeat);let g=B.process(e,o,l,i);c=!0,o.slidePaths.push(g);break}case 6:{a.readDuration(l,e.currentTiming,o);break}case 7:throw new d(l.line,l.character,2);case 8:case 9:case 10:case 3:return o;case 0:break;default:throw new m(l.line,l.character)}}return o}static decorateNote(e,r){var t;switch(e.lexeme[0]){case"f":r.styles|=5;return;case"b":if(r.type===5)break;r.type=4;return;case"x":r.styles|=1;return;case"m":r.styles|=6;return;case"h":if(r.type===4||r.type===5)break;r.type=2,(t=r.length)!=null||(r.length=0);return;case"?":r.type=5,r.slideMorph=0;return;case"!":r.type=5,r.slideMorph=1;return;case"@":r.appearance=1;return;case"$":r.appearance=r.appearance===2?3:2;return}}static readDuration(e,r,t){if(t.type!==4&&(t.type=2),e.lexeme[0]==="#"){let c=parseFloat(e.lexeme.slice(1));if(isNaN(c))throw new u(e.line,e.character+1,'0~9, or "."');t.length=c;return}let n=e.lexeme.indexOf(":"),o=parseFloat(e.lexeme.slice(0,n)),i=parseFloat(e.lexeme.slice(n+1));if(isNaN(o)||isNaN(i))throw new u(e.line,e.character+1,'0~9, or "."');t.length=r.secondsPerBar/(o/4)*i}};var A=class{static process(e,r){if(r.lexeme[0]==="#"){let n=parseFloat(r.lexeme.slice(1));if(isNaN(n))throw new u(r.line,r.character+1,'0~9, or "."');e.currentTiming.explicitOverride(n);return}let t=parseFloat(r.lexeme);if(isNaN(t))throw new u(r.line,r.character,'0~9, or "."');e.currentTiming.subdivisions=t}};var R=class{static process(e,r){let t=parseFloat(r.lexeme);if(isNaN(t))throw new u(r.line,r.character,'0~9, or "."');e.currentTiming.tempo=t}};var f=class{constructor(e){this._chart=new b;this._maxFinishTime=0;this._currentTime=0;this.currentTiming=new D(0,0);this.endOfFile=!1;this.enumerator=new O(e)}getChart(){var t,n,o;let e=[],r=!1;for(;!this.endOfFile&&(r||this.moveNext());){let i=this.enumerator.current;switch(r=!1,i.type){case 1:{R.process(this,i);break}case 2:{A.process(this,i);break}case 3:{if((t=this.currentNoteCollection)!=null||(this.currentNoteCollection=new C(this._currentTime)),i.lexeme[0]==="0"){this.currentNoteCollection.eachStyle!==1&&(this.currentNoteCollection.eachStyle=2);break}let c=M.process(this,i);this.currentNoteCollection.addNote(c),r=!0,this._maxFinishTime=Math.max(this._maxFinishTime,this.currentNoteCollection.time+c.getVisibleDuration());break}case 8:this.currentNoteCollection!=null&&(e.push(this.currentNoteCollection),this.currentNoteCollection=void 0),this._currentTime+=this.currentTiming.secondsPerBeat;break;case 9:switch(i.lexeme[0]){case"/":break;case"`":this.currentNoteCollection!=null&&(this.currentNoteCollection.eachStyle=1);break}break;case 4:throw new d(i.line,i.character,1);case 5:throw new d(i.line,i.character,1);case 6:throw new d(i.line,i.character,3);case 7:throw new d(i.line,i.character,2);case 10:this._chart.finishTiming=this._currentTime;break;case 0:break;default:throw new m(i.line,i.character)}}return(o=(n=this._chart).finishTiming)!=null||(n.finishTiming=this._maxFinishTime),this.currentNoteCollection!==void 0&&(e.push(this.currentNoteCollection),this.currentNoteCollection=void 0),this._chart.noteCollections=e,this._chart}static determineRingType(e,r,t=0){switch(t){case 1:return(e.index+2)%8>=4?2:1;case-1:return(e.index+2)%8>=4?1:2;default:var n=r.index-e.index,o=n>=0?n>4?-1:1:n<-4?1:-1;return o>0?1:2}}static tryReadLocation(e){let r=e.lexeme[0].charCodeAt(0)>="A".charCodeAt(0)&&e.lexeme[0].charCodeAt(0)<="E".charCodeAt(0),t=r?e.lexeme.substring(1):e.lexeme.substring(0),n=0;if(r&&(n=w[e.lexeme[0].charCodeAt(0)-"A".charCodeAt(0)+1],n===3))return[!0,new p(0,n)];let o=parseInt(t);return o?[!0,new p(o-1,n)]:[!1,new p(0,0)]}moveNext(){return this.endOfFile=!this.enumerator.moveNext(),!this.endOfFile}};var V=class{static deserialize(e){let r=new I(e).getTokens();return new f(r).getChart()}};var z=class{constructor(e){this.data="";this.data=e}toKeyValuePairs(){let e="",r="",t=this.data.replace(`\r | ||
`,` | ||
`).split(` | ||
`),n=new Map;for(let o of i)if(o.startsWith("&")){e!=""&&(n.set(e,r.trim()),r="");let t=o.split("=",2);e=t[0].substring(1),r+=t[1]+` | ||
`),n=new Map;for(let o of t)if(o.startsWith("&")){e!=""&&(n.set(e,r.trim()),r="");let i=o.split("=",2);e=i[0].substring(1),r+=i[1]+` | ||
`}else r+=o+` | ||
`;return e&&n.set(e,r.trim()),n}getValue(e){var r;return(r=this.toKeyValuePairs().get(e))!=null?r:""}};0&&(module.exports={MaiChart,Note,NoteAppearance,NoteCollection,NoteStyles,NoteType,SimaiConvert,SimaiFile,SlideMorph}); | ||
`;return e&&n.set(e,r.trim()),n}getValue(e){var r;return(r=this.toKeyValuePairs().get(e))!=null?r:""}};0&&(module.exports={EachStyle,Location,MaiChart,Note,NoteAppearance,NoteCollection,NoteGroup,NoteStyles,NoteType,SimaiConvert,SimaiFile,SlideMorph,SlidePath,SlideSegment,SlideType}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "simai.js", | ||
"version": "1.0.5", | ||
"version": "1.0.7", | ||
"description": "A serializer(wip)/deserializer for the rhythm game chart format simai.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -1,8 +0,16 @@ | ||
<!-- TODO: Rework README --> | ||
 | ||
 | ||
<!-- markdownlint-disable --> | ||
<div align="center"> | ||
<p> | ||
<a href="https://www.npmjs.com/package/simai.js" target="_blank"><img src="https://img.shields.io/npm/v/simai.js.svg" alt="npm version"/></a> | ||
<a href="https://discord.gg/6fpETgpvjZ" target="_blank"><img src="https://img.shields.io/discord/892807792996536453.svg" alt="discord"/></a> | ||
<a href="https://github.com/reflektone-games/simai.js/blob/main/LICENSE" target="_blank"><img src="https://img.shields.io/github/license/reflektone-games/simai.js.svg" alt="license"/></a> | ||
</p> | ||
</div> | ||
<!-- markdownlint-enable --> | ||
# simaisharp.js | ||
# simai.js | ||
simaisharp.js is an interpreter and serializer for [simai](https://w.atwiki.jp/simai/), | ||
simai.js is an interpreter and serializer for [simai](https://w.atwiki.jp/simai/), | ||
a custom chart format for the arcade rhythm game [maimai](https://maimai.sega.jp/), | ||
@@ -13,4 +21,10 @@ written in [Typescript](https://www.typescriptlang.org/). | ||
To use simaisharp.js in your own project, | ||
To use simai.js in your own project, install it via [npm](https://www.npmjs.com/package/simai.js) | ||
```bash | ||
pnpm add simai.js | ||
yarn install simai.js | ||
npm install simai.js | ||
``` | ||
Then, use the following method to deserialize a chart: | ||
@@ -17,0 +31,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
218878
1.76%244
2.52%48
41.18%