import { WWA } from "./wwa_main" ; import { WWAConsts , WWASaveConsts , Coord , PartsType , Face , MacroType , MacroImgFrameIndex , macrotable , YesNoState , Position , DEVICE_TYPE , Direction , StatusSolutionKind } from "./wwa_data" ; import { Positioning as MPositioning } from "./wwa_message" ; import { Monster } from "./wwa_monster" ; import { WWAData } from "./wwa_data" ; import { WWASave , WWASaveData } from "./wwa_save" ; /**
 * 値が更新された時に、再評価されるべき値を返す関数の型。
 */ export type LazyEvaluateValue = ( ) => number ; /**
 * 通常のメッセージ文字列と LazyEvaluateValue が混在した配列の型。
 * 例: ["変数 10 番の値は", () => userVar[10], "です。\n文字列中に改行も入りえます。"]
 */ export type MessageSegments = ( string | LazyEvaluateValue ) [ ] ; /**
 * パース済メッセージ。
 * 通常のメッセージの他、マクロの情報などを持ちます。
 */ export class ParsedMessage { private messageArray : MessageSegments ; constructor ( textOrMessageSegments , public isSystemMessage , public isEndOfPartsEvent ? , public macro ? ) { this . messageArray = typeof textOrMessageSegments === "string" ? [ textOrMessageSegments ] : textOrMessageSegments ; if ( this . macro === void 0 ) { this . macro = [ ] ; } } /**
     * メッセージが空であれば true を返す。
     * 空配列の他、空文字列しかない1要素の配列を空とみなす。
     * マクロの有無は考慮しない。
     */ isEmpty ( ) { return ( this . messageArray . length === 0 || ( this . messageArray . length === 1 && this . messageArray [ 0 ] === "" ) ) ; } /**
     * LazyEvaluateValue を評価して、表示可能なメッセージを生成する。
     */ generatePrintableMessage ( ) { return this . messageArray . reduce < string > ( ( prevMessage , item ) => { const evaluatedItem = typeof item === "string" ? item : item ( ) ; return `${ prevMessage }${ evaluatedItem }` ; } , "" ) ; } } export class Macro { constructor ( private _wwa , private _triggerPartsID , private _triggerPartsType , private _triggerPartsPosition , public macroType , public macroArgs ) { } public execute ( ) { try { switch ( this . macroType ) { case MacroType . IMGPLAYER : this . _executeImgPlayerMacro ( ) ; break ; case MacroType . IMGYESNO : this . _executeImgYesNoMacro ( ) ; break ; case MacroType . HPMAX : this . _executeHPMaxMacro ( ) ; break ; case MacroType . SAVE : this . _executeSaveMacro ( ) ; break ; case MacroType . ITEM : this . _executeItemMacro ( ) ; break ; case MacroType . DEFAULT : this . _executeDefaultMacro ( ) ; break ; case MacroType . OLDMAP : this . _executeOldMapMacro ( ) ; break ; case MacroType . PARTS : this . _executePartsMacro ( ) ; break ; case MacroType . MOVE : this . _executeMoveMacro ( ) ; break ; case MacroType . MAP : this . _executeMapMacro ( ) ; break ; case MacroType . DIRMAP : this . _executeDirMapMacro ( ) ; break ; case MacroType . IMGFRAME : this . _executeImgFrameMacro ( ) ; break ; case MacroType . IMGBOM : this . _executeImgBomMacro ( ) ; break ; case MacroType . DELPLAYER : this . _executeDelPlayerMacro ( ) ; break ; case MacroType . FACE : this . _executeFaceMacro ( ) ; break ; case MacroType . EFFECT : this . _executeEffectMacro ( ) ; break ; case MacroType . GAMEOVER : this . _executeGameOverMacro ( ) ; break ; case MacroType . IMGCLICK : this . _executeImgClickMacro ( ) ; break ; case MacroType . STATUS : this . _executeStatusMacro ( ) ; break ; case MacroType . EFFITEM : this . _executeEffItemMacro ( ) ; break ; case MacroType . COLOR : this . _executeColorMacro ( ) ; break ; case MacroType . WAIT : this . _executeWaitMacro ( ) ; break ; case MacroType . SOUND : this . _executeSoundMacro ( ) ; break ; case MacroType . GAMEPAD_BUTTON : this . _executeGamePadButtonMacro ( ) ; break ; case MacroType . OLDMOVE : this . _executeOldMoveMacro ( ) ; break ; case MacroType . JUMPGATE : this . _executeJumpGateMacro ( ) ; break ; case MacroType . RECPOSITION : this . _executeRecPositionMacro ( ) ; break ; case MacroType . JUMPRECPOSITION : this . _executeJumpRecPositionMacro ( ) ; break ; case MacroType . CONSOLE_LOG : this . _executeConsoleLogMacro ( ) ; break ; case MacroType . COPY_HP_TO : this . _executeCopyHpToMacro ( ) ; break ; case MacroType . SET_HP : this . _executeSetHPMacro ( ) ; break ; case MacroType . COPY_HPMAX_TO : this . _executeCopyHpMaxToMacro ( ) ; break ; case MacroType . SET_HPMAX : this . _executeSetHpMaxMacro ( ) ; break ; case MacroType . COPY_AT_TO : this . _executeCopyAtToMacro ( ) ; break ; case MacroType . SET_AT : this . _executeSetAtMacro ( ) ; break ; case MacroType . COPY_DF_TO : this . _executeCopyDfToMacro ( ) ; break ; case MacroType . SET_DF : this . _executeSetDfMacro ( ) ; break ; case MacroType . COPY_MONEY_TO : this . _executeCopyMoneyToMacro ( ) ; break ; case MacroType . SET_MOENEY : this . _executeSetMoneyMacro ( ) ; break ; case MacroType . COPY_STEP_COUNT_TO : this . _executeSetStepCountMacro ( ) ; break ; case MacroType . VAR_SET_VAL : this . _executeVarSetValMacro ( ) ; break ; case MacroType . VAR_SET : this . _executeVarSetMacro ( ) ; break ; case MacroType . VAR_ADD : this . _executeVarAddMacro ( ) ; break ; case MacroType . VAR_SUB : this . _executeVarSubMacro ( ) ; break ; case MacroType . VAR_MUL : this . _executeVarMulMacro ( ) ; break ; case MacroType . VAR_DIV : this . _executeVarDivMacro ( ) ; break ; case MacroType . VAR_MOD : this . _executeVarModMacro ( ) ; break ; case MacroType . VAR_SET_RAND : this . _executeVarSetRandMacro ( ) ; break ; case MacroType . GAME_SPEED : this . _executeGameSpeedMacro ( ) ; break ; case MacroType . SHOW_STR : break ; case MacroType . IF : this . _executeIfMacro ( ) ; break ; case MacroType . SET_SPEED : this . _executeSetSpeedMacro ( ) ; break ; case MacroType . COPY_TIME_TO : this . _executeCopyTimeToMacro ( ) ; break ; case MacroType . HIDE_STATUS : this . _hideStatusMacro ( ) ; break ; case MacroType . VAR_MAP : this . _varMapMacro ( ) ; break ; default : console . log ( "不明なマクロIDが実行されました:" + this . macroType ) ; break ; } } catch ( e ) { } } private _concatEmptyArgs ( requiredLength ) { if ( this . macroArgs . length < requiredLength ) { var ap = new Array ( requiredLength - this . macroArgs . length ) ; for ( var i = 0 ; i < ap . length ; i ++ ) { ap [ i ] = "" ; } this . macroArgs = this . macroArgs . concat ( ap ) ; } } private _parseInt ( argIndex , fallback = 0 ) { var x = parseInt ( this . macroArgs [ argIndex ] ) ; if ( isNaN ( x ) ) { return fallback ; } return x ; } private _executeJumpGateMacro ( ) { this . _concatEmptyArgs ( 2 ) ; var x = this . _parseInt ( 0 ) ; var y = this . _parseInt ( 1 ) ; this . _wwa . forcedJumpGate ( x , y ) ; } private _executeRecPositionMacro ( ) { this . _concatEmptyArgs ( 2 ) ; var x = this . _parseInt ( 0 ) ; var y = this . _parseInt ( 1 ) ; this . _wwa . recUserPosition ( x , y ) ; } private _executeJumpRecPositionMacro ( ) { this . _concatEmptyArgs ( 2 ) ; var x = this . _parseInt ( 0 ) ; var y = this . _parseInt ( 1 ) ; this . _wwa . jumpRecUserPosition ( x , y ) ; } private _executeConsoleLogMacro ( ) { this . _concatEmptyArgs ( 1 ) ; var num = this . _parseInt ( 0 ) ; this . _wwa . outputUserVar ( num ) ; } private _executeCopyHpToMacro ( ) { this . _concatEmptyArgs ( 1 ) ; var num = this . _parseInt ( 0 ) ; this . _wwa . setUserVarHP ( num ) ; } private _executeCopyHpMaxToMacro ( ) { this . _concatEmptyArgs ( 1 ) ; var num = this . _parseInt ( 0 ) ; this . _wwa . setUserVarHPMAX ( num ) ; } private _executeCopyAtToMacro ( ) { this . _concatEmptyArgs ( 2 ) ; const num = this . _parseInt ( 0 ) ; const kind = this . _parseStatusKind ( this . _parseInt ( 1 ) ) ; this . _wwa . setUserVarAT ( num , kind ) ; } private _executeCopyDfToMacro ( ) { this . _concatEmptyArgs ( 2 ) ; const num = this . _parseInt ( 0 ) ; const kind = this . _parseStatusKind ( this . _parseInt ( 1 ) ) ; this . _wwa . setUserVarDF ( num , kind ) ; } private _parseStatusKind ( kind ) { switch ( kind ) { case 0 : return "all" ; case 1 : return "bare" ; case 2 : return "equipment" ; default : return "all" ; } } private _executeCopyMoneyToMacro ( ) { this . _concatEmptyArgs ( 1 ) ; var num = this . _parseInt ( 0 ) ; this . _wwa . setUserVarMONEY ( num ) ; } private _executeSetHPMacro ( ) { this . _concatEmptyArgs ( 1 ) ; var num = this . _parseInt ( 0 ) ; this . _wwa . setHPUserVar ( num ) ; } private _executeSetHpMaxMacro ( ) { this . _concatEmptyArgs ( 1 ) ; var num = this . _parseInt ( 0 ) ; this . _wwa . setHPMAXUserVar ( num ) ; } private _executeSetAtMacro ( ) { this . _concatEmptyArgs ( 1 ) ; var num = this . _parseInt ( 0 ) ; this . _wwa . setATUserVar ( num ) ; } private _executeSetDfMacro ( ) { this . _concatEmptyArgs ( 1 ) ; var num = this . _parseInt ( 0 ) ; this . _wwa . setDFUserVar ( num ) ; } private _executeSetMoneyMacro ( ) { this . _concatEmptyArgs ( 1 ) ; var num = this . _parseInt ( 0 ) ; this . _wwa . setMONEYUserVar ( num ) ; } private _executeSetStepCountMacro ( ) { this . _concatEmptyArgs ( 1 ) ; var num = this . _parseInt ( 0 ) ; this . _wwa . setUserVarStep ( num ) ; } private _executeVarSetValMacro ( ) { this . _concatEmptyArgs ( 2 ) ; var x = this . _parseInt ( 0 ) ; var num = this . _parseInt ( 1 ) ; this . _wwa . setUserVarVal ( x , num ) ; } private _executeVarSetMacro ( ) { this . _concatEmptyArgs ( 2 ) ; var x = this . _parseInt ( 0 ) ; var y = this . _parseInt ( 1 ) ; this . _wwa . setUserValOtherUserVal ( x , y ) ; } private _executeVarAddMacro ( ) { this . _concatEmptyArgs ( 2 ) ; var x = this . _parseInt ( 0 ) ; var y = this . _parseInt ( 1 ) ; this . _wwa . setUserValAdd ( x , y ) ; } private _executeVarSubMacro ( ) { this . _concatEmptyArgs ( 2 ) ; var x = this . _parseInt ( 0 ) ; var y = this . _parseInt ( 1 ) ; this . _wwa . setUserValSub ( x , y ) ; } private _executeVarMulMacro ( ) { this . _concatEmptyArgs ( 2 ) ; var x = this . _parseInt ( 0 ) ; var y = this . _parseInt ( 1 ) ; this . _wwa . setUserValMul ( x , y ) ; } private _executeVarDivMacro ( ) { this . _concatEmptyArgs ( 2 ) ; var x = this . _parseInt ( 0 ) ; var y = this . _parseInt ( 1 ) ; this . _wwa . setUserValDiv ( x , y ) ; } private _executeVarModMacro ( ) { this . _concatEmptyArgs ( 2 ) ; var x = this . _parseInt ( 0 ) ; var y = this . _parseInt ( 1 ) ; this . _wwa . setUserValMod ( x , y ) ; } private _executeVarSetRandMacro ( ) { this . _concatEmptyArgs ( 3 ) ; const x = this . _parseInt ( 0 ) ; const y = this . _parseInt ( 1 ) ; const n = this . _parseInt ( 2 , 0 ) ; this . _wwa . setUserValRandNum ( x , y , n ) ; } private _executeGameSpeedMacro ( ) { this . _concatEmptyArgs ( 1 ) ; var speedChangeFlag = ! ! this . _parseInt ( 0 ) ; this . _wwa . speedChangeJudge ( speedChangeFlag ) ; } private _executeIfMacro ( ) { var str = new Array ( 11 ) ; for ( var i = 0 ; i < 10 ; i ++ ) { str [ i ] = this . macroArgs [ i ] ; } this . _wwa . userVarUserIf ( this . _triggerPartsPosition , str ) ; } private _executeSetSpeedMacro ( ) { this . _concatEmptyArgs ( 1 ) ; var num = this . _parseInt ( 0 ) ; this . _wwa . setPlayerSpeedIndex ( num - 1 ) ; } private _executeCopyTimeToMacro ( ) { this . _concatEmptyArgs ( 1 ) ; var num = this . _parseInt ( 0 ) ; this . _wwa . setUserVarPlayTime ( num ) ; } private _hideStatusMacro ( ) { this . _concatEmptyArgs ( 2 ) ; var no = this . _parseInt ( 0 ) ; var isHideNumber = this . _parseInt ( 1 ) ; var isHide = ( isHideNumber === 0 ) ? false : true ; this . _wwa . hideStatus ( no , isHide ) ; } private _varMapMacro ( ) { this . _concatEmptyArgs ( 4 ) ; var partsID = this . _parseInt ( 0 ) ; var xstr = this . macroArgs [ 1 ] ; var ystr = this . macroArgs [ 2 ] ; var partsType = this . _parseInt ( 3 , PartsType . OBJECT ) ; if ( partsID < 0 ) { throw new Error ( "入力変数が不正です" ) ; } this . _wwa . varMap ( this . _triggerPartsPosition , xstr , ystr , partsID , partsType ) ; } private _executeImgPlayerMacro ( ) { this . _concatEmptyArgs ( 2 ) ; var x = this . _parseInt ( 0 ) ; var y = this . _parseInt ( 1 ) ; this . _wwa . setPlayerImgCoord ( new Coord ( x , y ) ) ; } private _executeImgYesNoMacro ( ) { this . _concatEmptyArgs ( 2 ) ; var x = this . _parseInt ( 0 ) ; var y = this . _parseInt ( 1 ) ; this . _wwa . setYesNoImgCoord ( new Coord ( x , y ) ) ; } private _executeHPMaxMacro ( ) { this . _concatEmptyArgs ( 1 ) ; var hpmax = Math . max ( 0 , this . _parseInt ( 0 ) ) ; this . _wwa . setPlayerEnergyMax ( hpmax ) ; } private _executeSaveMacro ( ) { this . _concatEmptyArgs ( 1 ) ; var disableSaveFlag = ! ! this . _parseInt ( 0 ) ; this . _wwa . disableSave ( disableSaveFlag ) ; } private _executeItemMacro ( ) { this . _concatEmptyArgs ( 2 ) ; var pos = this . _parseInt ( 0 ) ; var id = this . _parseInt ( 1 ) ; this . _wwa . setPlayerGetItem ( pos , id ) ; } private _executeDefaultMacro ( ) { this . _concatEmptyArgs ( 1 ) ; var defaultFlag = ! ! this . _parseInt ( 0 ) ; this . _wwa . setObjectNotCollapseOnPartsOnPlayer ( defaultFlag ) ; } private _executeOldMapMacro ( ) { this . _concatEmptyArgs ( 1 ) ; var oldMapFlag = ! ! this . _parseInt ( 0 ) ; this . _wwa . setOldMap ( oldMapFlag ) ; } private _executePartsMacro ( ) { this . _concatEmptyArgs ( 4 ) ; var srcID = this . _parseInt ( 0 ) ; var destID = this . _parseInt ( 1 ) ; var partsType = this . _parseInt ( 2 , PartsType . OBJECT ) ; var onlyThisSight = this . _parseInt ( 3 ) ; if ( partsType !== PartsType . OBJECT && partsType !== PartsType . MAP ) { throw new Error ( "パーツ種別が不明です" ) ; } if ( onlyThisSight !== 0 && onlyThisSight !== 1 ) { onlyThisSight = 1 ; } if ( srcID < 0 || destID < 0 ) { throw new Error ( "パーツ番号が不正です" ) ; } if ( partsType === PartsType . OBJECT ) { if ( srcID >= this . _wwa . getObjectPartsNum ( ) || destID >= this . _wwa . getObjectPartsNum ( ) ) { throw new Error ( "パーツ番号が不正です" ) ; } } else { if ( srcID >= this . _wwa . getMapPartsNum ( ) || destID >= this . _wwa . getMapPartsNum ( ) ) { throw new Error ( "パーツ番号が不正です" ) ; } } this . _wwa . replaceParts ( srcID , destID , partsType , ! ! onlyThisSight ) ; } private _executeMoveMacro ( ) { this . _concatEmptyArgs ( 1 ) ; var moveNum = this . _parseInt ( 0 ) ; this . _wwa . setMoveMacroWaitingToPlayer ( moveNum ) ; } private _executeMapMacro ( ) { this . _concatEmptyArgs ( 4 ) ; var partsID = this . _parseInt ( 0 ) ; var xstr = this . macroArgs [ 1 ] ; var ystr = this . macroArgs [ 2 ] ; var partsType = this . _parseInt ( 3 , PartsType . OBJECT ) ; if ( partsID < 0 ) { throw new Error ( "パーツ番号が不正です" ) ; } if ( partsType === PartsType . OBJECT ) { if ( partsID >= this . _wwa . getObjectPartsNum ( ) ) { throw new Error ( "パーツ番号が不正です" ) ; } } else { if ( partsID >= this . _wwa . getMapPartsNum ( ) ) { throw new Error ( "パーツ番号が不正です" ) ; } } this . _wwa . appearPartsEval ( this . _triggerPartsPosition , xstr , ystr , partsID , partsType ) ; } private _executeDirMapMacro ( ) { this . _concatEmptyArgs ( 3 ) ; var partsID = this . _parseInt ( 0 ) ; var dist = this . _parseInt ( 1 ) ; var partsType = this . _parseInt ( 2 , PartsType . OBJECT ) ; if ( isNaN ( partsID ) || isNaN ( dist ) || isNaN ( partsType ) ) { throw new Error ( "引数が整数ではありません" ) ; } if ( partsID < 0 ) { throw new Error ( "パーツ番号が不正です" ) ; } if ( partsType === PartsType . OBJECT ) { if ( partsID >= this . _wwa . getObjectPartsNum ( ) ) { throw new Error ( "パーツ番号が不正です" ) ; } } else { if ( partsID >= this . _wwa . getMapPartsNum ( ) ) { throw new Error ( "パーツ番号が不正です" ) ; } } this . _wwa . appearPartsByDirection ( dist , partsID , partsType ) ; } private _executeImgFrameMacro ( ) { this . _concatEmptyArgs ( 3 ) ; var type = this . _parseInt ( 0 ) ; var posX = this . _parseInt ( 1 ) ; var posY = this . _parseInt ( 2 ) ; if ( posX < 0 || posY < 0 ) { throw new Error ( "座標は正でなければなりません。" ) ; } if ( type === MacroImgFrameIndex . ENERGY || type === MacroImgFrameIndex . STRENGTH || type === MacroImgFrameIndex . DEFENCE || type === MacroImgFrameIndex . GOLD ) { this . _wwa . setStatusIconCoord ( type , new Coord ( posX , posY ) ) ; } else if ( type === MacroImgFrameIndex . WIDE_CELL_ROW ) { this . _wwa . setWideCellCoord ( new Coord ( posX , posY ) ) ; } else if ( type === MacroImgFrameIndex . ITEM_BG ) { this . _wwa . setItemboxBackgroundPosition ( { x : posX , y : posY } ) ; } else if ( type === MacroImgFrameIndex . MAIN_FRAME ) { this . _wwa . setFrameCoord ( new Coord ( posX , posY ) ) ; } else { throw new Error ( "種別が不正です。" ) ; } } private _executeImgBomMacro ( ) { this . _concatEmptyArgs ( 2 ) ; var posX = this . _parseInt ( 0 ) ; var posY = this . _parseInt ( 1 ) ; if ( posX < 0 || posY < 0 ) { throw new Error ( "座標は正でなければなりません。" ) ; } this . _wwa . setBattleEffectCoord ( new Coord ( posX , posY ) ) ; } private _executeDelPlayerMacro ( ) { this . _concatEmptyArgs ( 1 ) ; var flag = parseInt ( this . macroArgs [ 0 ] ) ; this . _wwa . setDelPlayer ( ! ! flag ) ; } private _executeFaceMacro ( ) { this . _concatEmptyArgs ( 6 ) ; var destPosX = this . _parseInt ( 0 ) ; var destPosY = this . _parseInt ( 1 ) ; var srcPosX = this . _parseInt ( 2 ) ; var srcPosY = this . _parseInt ( 3 ) ; var srcWidth = this . _parseInt ( 4 ) ; var srcHeight = this . _parseInt ( 5 ) ; var face ; if ( destPosX < 0 || destPosY < 0 || srcPosX < 0 || srcPosY < 0 || srcWidth < 0 || srcHeight < 0 ) { throw new Error ( "各引数は0以上の整数でなければなりません。" ) ; } face = new Face ( new Coord ( destPosX , destPosY ) , new Coord ( srcPosX , srcPosY ) , new Coord ( srcWidth , srcHeight ) ) ; this . _wwa . addFace ( face ) ; } private _executeEffectMacro ( ) { this . _concatEmptyArgs ( 1 ) ; var waitTime = this . _parseInt ( 0 ) ; if ( waitTime < 0 ) { throw new Error ( "待ち時間は0以上の整数でなければなりません。" ) ; } if ( waitTime === 0 ) { this . _wwa . stopEffect ( ) ; return ; } var coords = [ ] ; for ( var i = 1 ; i < this . macroArgs . length ; i += 2 ) { var cropX = this . _parseInt ( i ) ; var cropY = 0 ; if ( cropX < 0 ) { throw new Error ( "画像のパーツ座標指定は0以上の整数でなければなりません。" ) ; } if ( i + 1 === this . macroArgs . length ) { throw new Error ( "画像のパーツ座標指定で、Y座標が指定されていません。" ) ; } cropY = this . _parseInt ( i + 1 ) ; if ( cropY < 0 ) { throw new Error ( "画像のパーツ座標指定は0以上の整数でなければなりません。" ) ; } coords . push ( new Coord ( cropX , cropY ) ) ; } this . _wwa . setEffect ( waitTime , coords ) ; } private _executeGameOverMacro ( ) { this . _concatEmptyArgs ( 2 ) ; var x = this . _parseInt ( 0 ) ; var y = this . _parseInt ( 1 ) ; if ( x < 0 || x >= this . _wwa . getMapWidth ( ) || y < 0 || y >= this . _wwa . getMapWidth ( ) ) { throw new Error ( "マップの範囲外が指定されています!" ) ; } this . _wwa . setGameOverPosition ( new Coord ( x , y ) ) ; } private _executeImgClickMacro ( ) { this . _concatEmptyArgs ( 2 ) ; if ( this . macroArgs . length < 1 ) { throw new Error ( "引数が少なすぎます" ) ; } var x = this . _parseInt ( 0 ) ; var y = this . _parseInt ( 1 ) ; if ( x < 0 || y < 0 ) { throw new Error ( "引数が0以上の整数ではありません" ) ; } this . _wwa . setImgClick ( new Coord ( x , y ) ) ; } private _executeEffItemMacro ( ) { if ( this . macroArgs . length < 1 ) { throw new Error ( "引数が少なすぎます" ) ; } var mode = this . _parseInt ( 0 ) ; this . _wwa . updateItemEffectEnabled ( ! ! mode ) ; } private _executeStatusMacro ( ) { this . _concatEmptyArgs ( 2 ) ; var type = this . _parseInt ( 0 ) ; var value = this . _parseInt ( 1 ) ; if ( type < 0 || 4 < type ) { throw new Error ( "ステータス種別が範囲外です。" ) ; } this . _wwa . setPlayerStatus ( type , value ) ; } private _executeColorMacro ( ) { this . _concatEmptyArgs ( 4 ) ; var type = this . _parseInt ( 0 ) ; var r = this . _parseInt ( 1 ) ; var g = this . _parseInt ( 2 ) ; var b = this . _parseInt ( 3 ) ; if ( type < 0 || type > 5 ) { throw new Error ( "種別は0から5までです" ) ; } if ( r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255 ) { throw new Error ( "色が範囲外です" ) ; } this . _wwa . changeStyleRule ( type , r , g , b ) ; } private _executeWaitMacro ( ) { throw new Error ( "Not implemented!" ) ; } private _executeSoundMacro ( ) { this . _concatEmptyArgs ( 1 ) ; var id = parseInt ( this . macroArgs [ 0 ] ) ; this . _wwa . playSound ( id ) ; } private _executeGamePadButtonMacro ( ) { this . _concatEmptyArgs ( 2 ) ; var buttonID = this . _parseInt ( 0 ) ; var itemNo = this . _parseInt ( 1 ) ; if ( buttonID < 0 || itemNo < 0 ) { throw new Error ( "各引数は0以上の整数でなければなりません。" ) ; } if ( itemNo > WWAConsts . ITEMBOX_SIZE ) { throw new Error ( "アイテムボックス上限を超えた数値が指定されました。" ) ; } this . _wwa . setGamePadButtonItemTable ( buttonID , itemNo ) ; } private _executeOldMoveMacro ( ) { this . _concatEmptyArgs ( 1 ) ; const oldMoveFlag = ! ! this . _parseInt ( 0 ) ; this . _wwa . setOldMove ( oldMoveFlag ) ; } } export function parseMacro ( wwa , partsID , partsType , position , macroStr ) { var matchInfo = macroStr . match ( /^\$([a-zA-Z_][a-zA-Z0-9_]*)\=(.*)$/ ) ; if ( matchInfo === null || matchInfo . length !== 3 ) { throw new Error ( "マクロではありません" ) ; } var macroType = matchInfo [ 1 ] ; var macroIndex = macrotable [ "$" + macroType . toLowerCase ( ) ] ; if ( macroIndex === void 0 ) { return new Macro ( wwa , partsID , partsType , position , MacroType . UNDEFINED , matchInfo [ 2 ] . split ( "," ) ) ; } return new Macro ( wwa , partsID , partsType , position , macroIndex , matchInfo [ 2 ] . split ( "," ) . map ( ( e ) => { return e . trim ( ) ; } ) ) ; } export class TextWindow { protected _element : HTMLElement ; constructor ( protected _wwa , protected _coord , protected _width , protected _height , protected _isVisible , protected _parentElement , zIndex ) { this . _element = document . createElement ( "div" ) ; this . _element . style . position = "absolute" ; this . _element . style . borderWidth = "2px" ; this . _element . style . borderStyle = "solid" ; if ( _wwa . isClassicMode ( ) ) { this . _element . style . borderRadius = "15px" ; } else { this . _element . style . borderRadius = "10px" ; } this . _element . classList . add ( "wwa-message-window" ) ; this . _element . style . zIndex = zIndex + "" ; this . _element . style . left = this . _coord . x + "px" ; this . _element . style . top = this . _coord . y + "px" ; this . _element . style . width = this . _width + "px" ; this . _element . style . height = this . _height + "px" ; this . _parentElement . appendChild ( this . _element ) ; } public update ( a ? ) { } public show ( ) { this . _isVisible = true ; this . _element . style . display = "block" ; this . update ( ) ; this . _wwa . wwaCustomEvent ( 'wwa_window_show' , { name : this . windowName , element : this . _element , text : this . _element . textContent } ) ; } public hide ( ) { this . _isVisible = false ; this . _element . style . display = "none" ; this . update ( ) ; this . _wwa . wwaCustomEvent ( 'wwa_window_hide' , { name : this . windowName } ) ; } public isVisible ( ) { return this . _isVisible ; } protected get windowName ( ) : string { return "TextWindow" ; } } export class MonsterWindow extends TextWindow { protected _monsterBox : HTMLDivElement ; protected _energyBox : HTMLDivElement ; protected _strengthBox : HTMLDivElement ; protected _defenceBox : HTMLDivElement ; constructor ( wwa , coord , width , height , isVisible , parentElement , protected _cgFileName ) { super ( wwa , new Coord ( coord . x , coord . y ) , width , height , isVisible , parentElement , 201 ) ; this . _monsterBox = document . createElement ( "div" ) ; this . _monsterBox . style . width = WWAConsts . CHIP_SIZE + "px" ; this . _monsterBox . style . height = WWAConsts . CHIP_SIZE + "px" ; this . _monsterBox . style . position = "absolute" ; this . _monsterBox . style . left = "10px" ; this . _monsterBox . style . top = "10px" ; this . _monsterBox . style . backgroundImage = "url(" + this . _cgFileName . replace ( "(" , "\\(" ) . replace ( ")" , "\\)" ) + ")" ; this . _monsterBox . style . backgroundPosition = "0 0" ; this . _element . appendChild ( this . _monsterBox ) ; this . _energyBox = document . createElement ( "div" ) ; this . _energyBox . style . position = "absolute" ; this . _energyBox . style . left = "80px" ; this . _energyBox . style . top = "10px" ; this . _energyBox . textContent = "生命力 0" ; this . _element . appendChild ( this . _energyBox ) ; this . _strengthBox = document . createElement ( "div" ) ; this . _strengthBox . style . position = "absolute" ; this . _strengthBox . style . left = "80px" ; this . _strengthBox . style . top = "30px" ; this . _strengthBox . textContent = "攻撃力 0" ; this . _element . appendChild ( this . _strengthBox ) ; this . _defenceBox = document . createElement ( "div" ) ; this . _defenceBox . style . position = "absolute" ; this . _defenceBox . style . left = "180px" ; this . _defenceBox . style . top = "30px" ; this . _defenceBox . textContent = "防御力 0" ; this . _element . appendChild ( this . _defenceBox ) ; if ( this . _isVisible ) { this . _element . style . display = "block" ; } else { this . _element . style . display = "none" ; } } public update ( monster ? ) { if ( monster !== void 0 ) { this . _monsterBox . style . backgroundPosition = "-" + monster . imgCoord . x + "px -" + monster . imgCoord . y + "px" ; this . _energyBox . textContent = "生命力 " + monster . status . energy ; this . _strengthBox . textContent = "攻撃力 " + monster . status . strength ; this . _defenceBox . textContent = "防御力 " + monster . status . defence ; } } protected get windowName ( ) : string { return "MonsterWindow" ; } } export class ScoreWindow extends TextWindow { protected static WINDOW_NAME : string = "ScoreWindow" ; constructor ( wwa , coord , isVisible , parentElement ) { if ( wwa . isClassicMode ( ) ) { super ( wwa , new Coord ( WWAConsts . CHIP_SIZE * 2 , 30 ) , WWAConsts . CHIP_SIZE * 7 , 40 , isVisible , parentElement , 202 ) ; this . _element . style . borderWidth = "0" ; this . _element . style . borderRadius = "4px" ; this . _element . style . fontSize = "20px" ; this . _element . style . lineHeight = "40px" ; } else { super ( wwa , new Coord ( coord . x , coord . y ) , 340 , 30 , isVisible , parentElement , 202 ) ; } this . _element . style . textAlign = "center" ; if ( this . _isVisible ) { this . _element . style . display = "block" ; } else { this . _element . style . display = "none" ; } this . update ( 0 ) ; } public update ( score ? ) { if ( score !== void 0 ) { this . _element . textContent = "Score: " + score ; } } protected get windowName ( ) : string { return "ScoreWindow" ; } } export enum Positioning { TOP , CENTER , BOTTOM , SCORE } export class MessageWindow { private _wwa : WWA ; private _x : number ; private _y : number ; private _width : number ; private _height : number ; private _message : ParsedMessage ; private _cgFileName : string ; private _isVisible : boolean ; private _isYesno : boolean ; private _isSave : boolean ; private _isItemMenu : boolean ; private _isInputDisable : boolean ; private _element : HTMLElement ; private _msgWrapperElement : HTMLElement ; private _dummyElement : HTMLElement ; private _saveElement : HTMLElement ; private _ynWrapperElement : HTMLElement ; private _divYesElement : HTMLElement ; private _divNoElement : HTMLElement ; private _parentElement : HTMLElement ; private _wwaSave : WWASave = void 0 ; private _save_select_id : number = 0 ; private _save_counter : number = 0 ; private _save_close : boolean = false ; constructor ( wwa , x , y , width , height , cgFileName , isVisible , isYesno , isItemMenu , parentElement ) { var thisA = this ; var escapedFilename = cgFileName . replace ( "(" , "\\(" ) . replace ( ")" , "\\)" ) ; this . _wwa = wwa ; this . _cgFileName = cgFileName ; this . _x = x ; this . _y = y ; this . _width = width ; this . _height = height ; this . _message = new ParsedMessage ( [ ] , false ) ; this . _isVisible = isVisible ; this . _isYesno = isYesno ; this . _isItemMenu = isItemMenu ; this . _element = document . createElement ( "div" ) ; this . _element . id = "wwa-text-message-window" ; this . _element . classList . add ( "wwa-message-window" ) ; this . _msgWrapperElement = document . createElement ( "div" ) ; this . _msgWrapperElement . style . textAlign = "left" ; this . _msgWrapperElement . style . wordWrap = "break-word" ; this . _msgWrapperElement . style . margin = wwa . isClassicMode ( ) ? "8px 0 8px 16px" : "0" ; this . _msgWrapperElement . style . padding = wwa . isClassicMode ( ) ? "0" : "7px" ; this . _element . appendChild ( this . _msgWrapperElement ) ; this . _saveElement = document . createElement ( "div" ) ; this . _saveElement . style . padding = "0" ; this . _saveElement . style . margin = "0" ; this . _element . appendChild ( this . _saveElement ) ; this . _dummyElement = document . createElement ( "div" ) ; this . _dummyElement . style . display = "none" ; this . _dummyElement . style . padding = "0" ; this . _dummyElement . style . margin = "0" ; this . _dummyElement . style . height = "55px" ; this . _element . appendChild ( this . _dummyElement ) ; this . _ynWrapperElement = document . createElement ( "div" ) ; this . _ynWrapperElement . classList . add ( "wwa-yesno-wrapper" ) ; this . _element . appendChild ( this . _ynWrapperElement ) ; this . _parentElement = parentElement ; this . _parentElement . appendChild ( this . _element ) ; todo this . _divYesElement = document . createElement ( "div" ) ; this . _divYesElement . classList . add ( "wwa-yes-button" ) ; this . _divYesElement . style . background = "url(" + escapedFilename + ")" ; this . _divYesElement . onclick = function ( ) { if ( ! thisA . _isInputDisable ) { wwa . setYesNoInput ( YesNoState . YES ) ; thisA . update ( ) ; } } ; this . _divYesElement . style . cursor = "pointer" ; this . _divNoElement = document . createElement ( "div" ) ; this . _divNoElement . classList . add ( "wwa-no-button" ) ; this . _divNoElement . style . background = "url(" + escapedFilename + ")" ; this . _divNoElement . onclick = function ( ) { if ( ! thisA . _isInputDisable ) { wwa . setYesNoInput ( YesNoState . NO ) ; thisA . update ( ) ; } } ; this . _ynWrapperElement . appendChild ( this . _divYesElement ) ; this . _ynWrapperElement . appendChild ( this . _divNoElement ) ; thisA . _isInputDisable = false ; switch ( wwa . userDevice . device ) { case DEVICE_TYPE . SP : case DEVICE_TYPE . VR : this . _parentElement . classList . add ( "useScaleUp" ) ; break ; } this . update ( ) ; } public setPosition ( x , y , width , height ) { this . _x = x ; this . _y = y ; this . _width = width ; this . _height = height ; this . update ( ) ; } public setPositionByPlayerPosition ( existsFaces , existsScoreWindow , displayCenter , playerPos , cameraPos ) { var playerInScreenY = playerPos . getPartsCoord ( ) . substract ( cameraPos . getPartsCoord ( ) ) . y ; var pos ; if ( existsFaces ) { pos = MPositioning . BOTTOM ; } else if ( existsScoreWindow ) { pos = MPositioning . SCORE ; } else if ( displayCenter ) { pos = MPositioning . CENTER ; } else if ( playerInScreenY >= Math . ceil ( WWAConsts . V_PARTS_NUM_IN_WINDOW / 2 ) ) { pos = MPositioning . TOP ; } else { pos = MPositioning . BOTTOM ; } this . setPositionEasy ( pos ) ; } public setPositionEasy ( pos ) { var centerPos = Math . floor ( this . _element . clientHeight / 2 ) ; if ( pos === Positioning . CENTER ) { this . _y = WWAConsts . MAP_WINDOW_HEIGHT / 2 - centerPos ; this . update ( ) ; return ; } if ( pos === Positioning . TOP ) { this . _y = Math . max ( 20 , WWAConsts . MAP_WINDOW_HEIGHT / 4 - centerPos ) + 10 ; this . update ( ) ; return ; } if ( pos === Positioning . BOTTOM ) { this . _y = Math . min ( WWAConsts . MAP_WINDOW_HEIGHT - 20 - this . _element . clientHeight , WWAConsts . MAP_WINDOW_HEIGHT * 3 / 4 - centerPos ) ; this . update ( ) ; return ; } if ( pos === Positioning . SCORE ) { this . _y = 80 ; this . update ( ) ; return ; } } public setParsedMessage ( message ) { this . _message = message ; this . update ( ) ; } public setYesNoChoice ( isYesNo ) { this . _isInputDisable = false ; this . _isYesno = isYesNo ; this . update ( ) ; return this . _isYesno ; } public isYesNoChoice ( ) { return this . _isYesno ; } public isSaveChoice ( ) { return this . _isSave ; } public setItemMenuChoice ( isItemMenu ) { this . _isInputDisable = false ; this . _isItemMenu = isItemMenu ; this . update ( ) ; return this . _isItemMenu ; } public isItemMenuChoice ( ) { return this . _isItemMenu ; } public setInputDisable ( ) { this . _isInputDisable = true ; } public isInputDisable ( ) { return this . _isInputDisable ; } public show ( ) { this . _isVisible = true ; this . update ( ) ; } public hide ( ) { this . _isVisible = false ; this . update ( ) ; } public isVisible ( ) { return this . _isVisible ; } private isWideChar ( char ) { return ( char . match ( /^[^\x01-\x7E\xA1-\xDF]+$/ ) !== null ) ; } param message returns { HTMLSpanElement } private createClassicTextElement ( message ) { var lsp = document . createElement ( "span" ) ; let count = 0 ; let lineStr = "" ; for ( let j = 0 ; j < message . length || count != 0 ; j ++ ) { if ( this . isWideChar ( message . charAt ( j ) ) ) { count += 2 ; } else { count += 1 ; } lineStr += message . charAt ( j ) ; if ( count + 1 > WWAConsts . MSG_STR_WIDTH * 2 ) { if ( message . charAt ( j + 1 ) === "。" || message . charAt ( j + 1 ) === "、" ) { lineStr += message . charAt ( j + 1 ) ; j ++ ; } var vsp = document . createElement ( "span" ) ; vsp . style . display = "inline-block" ; vsp . style . width = "100%" ; vsp . textContent = lineStr ; lsp . appendChild ( vsp ) ; count = 0 ; lineStr = "" ; } } return lsp ; } public update ( ) { var base = this . _wwa . getYesNoImgCoord ( ) ; if ( this . _isYesno ) { if ( this . _wwa . getYesNoState ( ) === YesNoState . YES ) { this . _divYesElement . style . backgroundPosition = "-" + ( base . x + WWAConsts . IMGRELPOS_YESNO_YESP_X ) * WWAConsts . CHIP_SIZE + "px " + "-" + ( base . y * WWAConsts . CHIP_SIZE ) + "px" ; this . _divNoElement . style . backgroundPosition = "-" + ( base . x + WWAConsts . IMGRELPOS_YESNO_NO_X ) * WWAConsts . CHIP_SIZE + "px " + "-" + ( base . y * WWAConsts . CHIP_SIZE ) + "px" ; } else if ( this . _wwa . getYesNoState ( ) === YesNoState . NO ) { this . _divYesElement . style . backgroundPosition = "-" + ( base . x + WWAConsts . IMGRELPOS_YESNO_YES_X ) * WWAConsts . CHIP_SIZE + "px " + "-" + ( base . y * WWAConsts . CHIP_SIZE ) + "px" ; this . _divNoElement . style . backgroundPosition = "-" + ( base . x + WWAConsts . IMGRELPOS_YESNO_NOP_X ) * WWAConsts . CHIP_SIZE + "px " + "-" + ( base . y * WWAConsts . CHIP_SIZE ) + "px" ; } else { this . _divYesElement . style . backgroundPosition = "-" + ( base . x + WWAConsts . IMGRELPOS_YESNO_YES_X ) * WWAConsts . CHIP_SIZE + "px " + "-" + ( base . y * WWAConsts . CHIP_SIZE ) + "px" ; this . _divNoElement . style . backgroundPosition = "-" + ( base . x + WWAConsts . IMGRELPOS_YESNO_NO_X ) * WWAConsts . CHIP_SIZE + "px " + "-" + ( base . y * WWAConsts . CHIP_SIZE ) + "px" ; } this . _ynWrapperElement . style . display = "block" ; } else { this . _ynWrapperElement . style . display = "none" ; } this . _msgWrapperElement . textContent = "" ; var mesArray = this . _message . generatePrintableMessage ( ) . split ( "\n" ) ; mesArray . forEach ( ( line , i ) => { let lsp ; if ( this . _wwa . isClassicMode ( ) ) { lsp = this . createClassicTextElement ( line ) ; } else { lsp = document . createElement ( "span" ) ; lsp . textContent = mesArray [ i ] ; } this . _msgWrapperElement . appendChild ( lsp ) ; this . _msgWrapperElement . appendChild ( document . createElement ( "br" ) ) ; } ) ; if ( this . _isVisible ) { this . _element . style . left = this . _x + "px" ; this . _element . style . top = this . _y + "px" ; } else { this . _element . style . left = "-999999px" ; this . _element . style . top = "-999999px" ; } if ( this . _isSave ) { this . _saveElement . style . display = "block" ; } else { this . _saveElement . style . display = "none" ; } this . _element . style . width = this . _width + "px" ; this . _element . style . minHeight = this . _height + "px" ; } setWWASave ( wwaSave ) { this . _wwaSave = wwaSave ; } createSaveDom ( ) { var loadWWAData ; var owner_div , savedata_main_div , ss_div , energy_div , span , energy_icon_div , energy_original_dom , energy_status_value_div , backgroundPositionText , backgroundImageText ; owner_div = document . createElement ( "div" ) ; energy_original_dom = document . getElementById ( "disp-energy" ) ; backgroundPositionText = energy_original_dom . style [ "backgroundPosition" ] ; backgroundImageText = energy_original_dom . style [ "backgroundImage" ] ; var len = this . _wwaSave . list . length ; for ( var i = 0 ; i < len ; i ++ ) { loadWWAData = this . _wwaSave . list [ i ] ; savedata_main_div = document . createElement ( "div" ) ; savedata_main_div . classList . add ( "savedata" ) ; savedata_main_div . setAttribute ( "save_id" , i ) ; savedata_main_div . addEventListener ( "click" , ( e ) : void => { this . setSaveID ( e . currentTarget . getAttribute ( "save_id" ) | 0 ) ; this . _save_close = true ; e . preventDefault ( ) ; } ) ; ss_div = document . createElement ( "div" ) ; ss_div . classList . add ( "ss" ) ; savedata_main_div . appendChild ( ss_div ) ; energy_div = document . createElement ( "div" ) ; energy_div . classList . add ( "wide-cell-row" ) ; energy_div . style [ "backgroundPosition" ] = backgroundPositionText ; energy_div . style [ "backgroundImage" ] = backgroundImageText ; savedata_main_div . appendChild ( energy_div ) ; owner_div . appendChild ( savedata_main_div ) ; if ( loadWWAData . flag ) { ss_div . appendChild ( loadWWAData . cvs ) ; span = document . createElement ( "span" ) ; span . textContent = loadWWAData . getDateText ( ) ; if ( loadWWAData . isLastSaveData ( ) ) { span . style . color = WWASaveConsts . DATE_LAST_SAVE_TEXT_COLOR ; } ss_div . appendChild ( span ) ; energy_icon_div = document . createElement ( "div" ) ; energy_icon_div . classList . add ( "status-icon" ) ; energy_icon_div . style [ "backgroundImage" ] = backgroundImageText ; energy_icon_div . style [ "backgroundPosition" ] = "-120px -80px" ; energy_div . appendChild ( energy_icon_div ) ; energy_status_value_div = document . createElement ( "div" ) ; energy_status_value_div . classList . add ( "status-value-box" ) ; energy_status_value_div . textContent = loadWWAData . getStatusEnergy ( ) ; energy_div . appendChild ( energy_status_value_div ) ; } } this . _saveElement . textContent = "" ; this . _saveElement . appendChild ( owner_div ) ; this . setSaveID ( this . _save_select_id ) ; this . _isSave = true ; this . _save_counter = 0 ; this . _save_close = false ; } deleteSaveDom ( ) { this . _saveElement . textContent = "" ; this . _isSave = false ; } setSaveID ( save_select_id ) { this . _save_select_id = save_select_id ; var domList = document . querySelectorAll ( ".savedata" ) ; var dom ; var len = domList . length ; for ( var i = 0 ; i < len ; i ++ ) { dom = domList [ i ] ; if ( save_select_id === i ) { dom . classList . add ( "select" ) ; } else { dom . classList . remove ( "select" ) ; } } } save ( gameCvs , _quickSaveData ) { return this . _wwaSave . save ( gameCvs , _quickSaveData , this . _save_select_id ) ; } load ( ) { return this . _wwaSave . load ( this . _save_select_id ) ; } public saveUpdate ( ) { if ( this . _save_counter > 0 ) { this . _save_counter -- ; } } public isSaveClose ( ) { return this . _save_close ; } private cursor_wait ( ) { this . _save_counter = WWAConsts . CONTROLL_WAIT_FRAME ; } public saveControll ( moveDir ) { if ( this . _save_counter > 0 ) { return ; } if ( this . _isInputDisable ) { return ; } switch ( moveDir ) { case Direction . DOWN : this . _save_select_id -= 2 ; this . cursor_wait ( ) ; break ; case Direction . UP : this . _save_select_id += 2 ; this . cursor_wait ( ) ; break ; case Direction . LEFT : this . _save_select_id -- ; this . cursor_wait ( ) ; break ; case Direction . RIGHT : this . _save_select_id ++ ; this . cursor_wait ( ) ; break ; } this . setSaveID ( ( this . _save_select_id + WWASaveConsts . QUICK_SAVE_MAX ) % WWASaveConsts . QUICK_SAVE_MAX ) ; } protected get windowName ( ) : string { return "MessageWindow" ; } }