How to use timer method in tracetest

Best JavaScript code snippet using tracetest

OriginalTimer.js

Source:OriginalTimer.js Github

copy

Full Screen

1//=============================================================================2// OriginalTimer.js3// ----------------------------------------------------------------------------4// Copyright (c) 2016 fftfantt5// This software is released under the MIT License.6// http://opensource.org/licenses/mit-license.php7// ----------------------------------------------------------------------------8// Version9// 0.1.0 2016/2/15 β版10// 1.0.0 2016/2/21 初版11// 1.0.1 2016/2/21 TimerSaveがYESでも再実行されない不具合修正12// 1.0.2 2016/2/21 初期化関連の処理の見直し13// 1.0.3 2016/3/26 タイマースタート時に即時でカウントしないよう変更14// 1.0.4 2016/4/03 戦闘終了後にエラーになってしまう不具合を解消15// 1.1.0 2016/4/03 タイマーの終了後に指定のスイッチをONにするコマンド追加16// 1.2.0 2016/4/03 タイマーのカウントをリセットするコマンド追加17// 1.2.1 2016/4/03 タイマー値の取得で設定値が取れない不具合修正18// 1.3.0 2016/6/09 設定時間操作、実時間操作のコマンド追加19// ----------------------------------------------------------------------------20// [HomePage]: https://googledrive.com/host/0BxiSZT-B8lvFOUFhVTF6VjNnUGc/index.html 21// [Twitter] : https://twitter.com/fftfantt/22// [GitHub] : https://github.com/fftfantt/23//=============================================================================24/*:25 * @plugindesc オリジナルタイマー26 * @author fftfantt27 *28 * @param TimerSave29 * @desc タイマーの値をセーブデータに含めるか YES or NO30 * @default NO31 * @help32 * 33 * ■説明34 * このプラグインは1日から1/100秒単位でカウントできるオリジナルタイマーを実装します。35 * カウントダウンのほか、カウントアップにも対応しています。36 * 動的テキスト表示部分のロジックについては、トリアコンタン様の「DTextPicture.js」37 * を参考にさせていただいております。この場をお借りして感謝申し上げます。38 *39 * ■利用規約40 * 当プラグインはMITライセンスのもとで公開されています。41 * https://osdn.jp/projects/opensource/wiki/licenses%2FMIT_license42 * ヘッダーのライセンス表記のみ残してください。43 * 商用利用、年齢制限のあるゲームへの使用、改変が可能です。44 * クレジットは不要です。45 * 当プラグインの不具合に損害の責任についても、MITライセンスの表記どおりです。46 *47 * ■使い方の概要48 * イベントのコマンド追加からプラグインコマンドを選択し、以下のようなプラグイン49 * コマンドでタイマーを設定後開始してください。50 * こちらにも詳しい使い方が記載されています。51 * https://github.com/fftfantt/RPGMakerMV/wiki/OriginalTimer.js52 * 53 * ■タイマーの設定54 *  ◆パラメータ55 *   引数1:タイマーの設定を行う場合の引数 [設定 or SET]56 *   引数2:タイマーの種類[アップ or ダウン or UP or DOWN] 57 *   引数3:設定時間 (1d1h1m1s1x1c のように記載)[日 or d 時間 or h 分 or m 秒 or s x(1/10秒) c(1/100秒)]58 *   引数4:ピクチャ番号[1~100]59 *   引数5:フォントサイズ60 *   引数6:画面X61 *   引数7:画面Y62 *   引数8:表示モード[表示 or 非表示 or DISPLAY or HIDE]63 *   引数9:表示形式[D日 HH時MM分SS.XC秒 や HH:MM:SS:XC で自由に]64 *  ◆コマンド例65 *   オリジナルタイマー 設定 ダウン 2d1h30m 99 24 10 10 表示 D日 HH時MM分SS.XC秒66 *   ORIGINALTIMER SET DOWN 1h30m 99 24 10 10 DISPLAY HH:MM:SS:XC67 *   オリジナルタイマー 設定 アップ 1h30m 10 24 630 10 非表示 HH:MM:SS.XC68 *   ORIGINALTIMER SET UP 1h30m 10 24 630 10 HIDE HH:MM:SS.XC69 * 70 * ■タイマーの開始71 *  ◆パラメータ72 *   引数1:タイマーを開始もしくは再開する場合の引数 [開始 or 再開 or START]73 *  ◆コマンド例74 *   オリジナルタイマー 開始75 *   ORIGINALTIMER START76 * 77 * ■タイマーの停止78 *  ◆パラメータ79 *   引数1:タイマーを停止する場合の引数 [停止 or STOP]80 *  ◆コマンド例81 *   オリジナルタイマー 停止82 *   ORIGINALTIMER STOP83 * 84 * ■タイマーの表示85 *  ◆パラメータ86 *   引数1:タイマーを表示する場合の引数 [表示 or DISPLAY]87 *  ◆コマンド例88 *   オリジナルタイマー 表示89 *   ORIGINALTIMER DISPLAY90 * 91 * ■タイマーの非表示92 *  ◆パラメータ93 *   引数1:タイマーを非表示にする場合の引数 [非表示 or HIDE]94 *  ◆コマンド例95 *   オリジナルタイマー 非表示96 *   ORIGINALTIMER HIDE97 * 98 * ■タイマーの初期化99 *   引数1:タイマーを初期化する場合の引数 [初期化 or INITIALIZE]100 *  ◆コマンド例101 *   オリジナルタイマー 初期化102 *   ORIGINALTIMER INITIALIZE103 * 104 * ■タイマー値の取得105 *   引数1:タイマーに関する値を取得する場合の引数 [取得 or GET]106 *   引数2:取得する値の種類 [状態 or STATE or 値 or VALUE etc]107 *   引数3:値を格納する変数108 *  ◆コマンド例109 *   オリジナルタイマー 取得 状態 1110 *   ORIGINALTIMER GET STATE 1111 *   オリジナルタイマー 取得 値 1112 *   ORIGINALTIMER GET VALUE 1113 *   オリジナルタイマー 取得 日 1114 *   ORIGINALTIMER GET DAY 1115 *   オリジナルタイマー 取得 時 1116 *   ORIGINALTIMER GET HR 1117 *   オリジナルタイマー 取得 分 1118 *   ORIGINALTIMER GET MIN 1119 *   オリジナルタイマー 取得 秒 1120 *   ORIGINALTIMER GET SEC 1121 *   オリジナルタイマー 取得 コンマ秒 1122 *   ORIGINALTIMER GET HSEC 1123 * 124 * ■タイマー終了後のスイッチ操作125 *   引数1:タイマー終了後にスイッチを操作する場合の引数 [スイッチ or SWITCH]126 *   引数2:操作の種類 [オン or ON or オフ or OFF or リバース or REVERSE]127 *   引数3:操作するスイッチ番号128 *  ◆コマンド例129 *   オリジナルタイマー スイッチ オン 1130 *   ORIGINALTIMER SWITCH ON 1131 *   オリジナルタイマー スイッチ オフ 2132 *   ORIGINALTIMER SWITCH OFF 2133 *   オリジナルタイマー スイッチ リバース 3134 *   ORIGINALTIMER SWITCH REVERSE 3135 * 136 * ■タイマーカウントのリセット137 *   引数1:タイマーカウントのリセットを行う場合の引数 [リセット or RESET]138 *  ◆コマンド例139 *   オリジナルタイマー リセット140 *   ORIGINALTIMER RESET141 * 142 *143 * ■タイマー設定時間の操作144 * 引数1:タイマー設定時間の操作を行う場合の引数 [設定時間操作 or LIMITCHANGE]145 * 引数2:設定時間の増減[増加 or 減少 or UP or DOWN] 146 * 引数3:設定時間 (1d1h1m1s1x1c のように記載)[日 or d 時間 or h 分 or m 秒 or s x(1/10秒) c(1/100秒)]147 *  ◆コマンド例148 * オリジナルタイマー 設定時間操作 増加 3m149 * オリジナルタイマー 設定時間操作 減少 10s150 *   ORIGINALTIMER LIMITCHANGE UP 3m151 *   ORIGINALTIMER LIMITCHANGE DOWN 3m152 * 153 * ■タイマー実時間の操作154 * 引数1:タイマー実時間の操作を行う場合の引数 [実時間操作 or TIMECHANGE]155 * 引数2:実時間の増減[進行 or 逆行 or UP or DOWN] 156 * 引数3:設定時間 (1d1h1m1s1x1c のように記載)[日 or d 時間 or h 分 or m 秒 or s x(1/10秒) c(1/100秒)]157 *  ◆コマンド例158 * オリジナルタイマー 実時間操作 進行 3m159 * オリジナルタイマー 実時間操作 逆行 10s160 *   ORIGINALTIMER TIMECHANGE UP 3m161 *   ORIGINALTIMER TIMECHANGE DOWN 3m162 * 163 */164(function () {165 166 var parameters = PluginManager.parameters('OriginalTimer');167 var TimerSave = parameters['TimerSave'].toUpperCase();168 169 var OriginalTimer = null;170 var SetFlag = false;171 var RunFlag = false;172 var DisplayMode = '';173 var Count = 0;174 var CountUnit = 0;175 var CountTime = 0;176 var CommndType = '';177 var TimerType = '';178 var TimerLimit = 0;179 var day = 0;180 var hr = 0;181 var min = 0;182 var sec = 0;183 var Hsec = 0;184 var TimerText = '';185 var ShowText = '';186 187 var pictureId = 0;188 var fontsize = 32; 189 var name = '';190 var origin = 0;191 var x = 0;192 var y = 0;193 var scaleX = 100;194 var scaleY = 100;195 var opacity = 255;196 var blendMode = 0;197 198 var SwitchState = '';199 var SwitchNumber = 0;200 var prevMsec = 0;201 function getCurrentMsec(){202 return SceneManager._currentTime || Date.now();203 }204 //=============================================================================205 // Game_Interpreter_pluginCommand206 // プラグインコマンドが実行されたときに処理されます207 //=============================================================================208 209 var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;210 Game_Interpreter.prototype.pluginCommand = function(command, args) {211 _Game_Interpreter_pluginCommand.call(this, command, args);212 213 if (command === "オリジナルタイマー" || command.toUpperCase() === "ORIGINALTIMER" ) {214 if ($gameTimer !== null){215 if (!Object.prototype.hasOwnProperty.call($gameTimer, '_fftfanttOriginalTimer_Run')){216 if (TimerSave == 'YES') Game_Timer.prototype.fftfanttOriginalTimer_Initialize();217 }218 }219 CommndType = args[0];220 221 if (CommndType == '設定' || CommndType.toUpperCase() == 'SET'){222 if (RunFlag){223 console.log('オリジナルタイマーは実行中です');224 return;225 }226 SetFlag = true;227 if (TimerSave == 'YES'){228 Game_Timer.prototype.fftfanttOriginalTimer_Initialize();229 $gameTimer._fftfanttOriginalTimer_Set = true;230 }231 TimerSet(args);232 }233 if (CommndType == '開始' || CommndType == '再開' || CommndType.toUpperCase() == 'START'){234 if (RunFlag){235 if ($gameTemp.isPlaytest()) console.log('オリジナルタイマーは実行中です');236 return;237 }238 if (!SetFlag){239 if (!$gameTemp.isPlaytest()) console.log('タイマーが設定されていません');240 return;241 }242 RunFlag = true;243 if (TimerSave == 'YES') $gameTimer._fftfanttOriginalTimer_Run = true;244 prevMsec = getCurrentMsec();245 TimerRun();246 OriginalTimer = setInterval(TimerRun,CountUnit);247 }248 249 if (CommndType == '停止' || CommndType.toUpperCase() == 'STOP'){250 clearInterval(OriginalTimer);251 RunFlag = false;252 if (TimerSave == 'YES') $gameTimer._fftfanttOriginalTimer_Run = false;253 }254 255 if (CommndType == '表示' || CommndType.toUpperCase() == 'DISPLAY'){256 opacity = 255257 if (TimerSave == 'YES') $gameTimer._fftfanttOriginalTimer_DisplayMode = '表示';258 return;259 }260 261 if (CommndType == '非表示' || CommndType.toUpperCase() == 'HIDE'){262 opacity = 0;263 if (TimerSave == 'YES') $gameTimer._fftfanttOriginalTimer_DisplayMode = '非表示';264 return;265 }266 267 if (CommndType == '初期化' || CommndType.toUpperCase() == 'INITIALIZE'){268 if (TimerSave == 'YES'){269 Game_Timer.prototype.fftfanttOriginalTimer_Initialize();270 }271 TimerInitialize();272 return;273 }274 if (CommndType == '取得' || CommndType.toUpperCase() == 'GET'){275 TimerGet(args);276 }277 278 if (CommndType == 'スイッチ' || CommndType.toUpperCase() == 'SWITCH'){279 if (!SetFlag){280 if (!$gameTemp.isPlaytest()) console.log('タイマーが設定されていません');281 return;282 }283 SwitchState =args[1]284 switch (args[1]) {285 case 'オン':286 SwitchState = 'ON';287 break;288 case 'オフ':289 SwitchState = 'OFF';290 break;291 case 'リバース':292 SwitchState = 'REVERSE';293 break;294 }295 SwitchNumber = parseInt(args[2], 10);296 if (TimerSave == 'YES'){297 $gameTimer._fftfanttOriginalTimer_SwitchState = SwitchState298 $gameTimer._fftfanttOriginalTimer_SwitchNumber = SwitchNumber299 }300 }301 302 if (CommndType == 'リセット' || CommndType.toUpperCase() == 'RESET'){303 if (!SetFlag){304 if (!$gameTemp.isPlaytest()) console.log('タイマーが設定されていません');305 return;306 }307 Count = 0;308 if (!RunFlag && pictureId !== 0) $gameScreen.erasePicture(pictureId);309 }310 311 if (CommndType == '設定時間操作' || CommndType.toUpperCase() == 'LIMITCHANGE'){312 if (!SetFlag){313 if (!$gameTemp.isPlaytest()) console.log('タイマーが設定されていません');314 return;315 }316 var timer_tmp_array = args[2].match(/((\d+)(d|日))?((\d+)(h|時間))?((\d+)(m|分間?))?((\d+)(s|秒間?))?((\d+)(x))?((\d+)(c))?/);317 if (args[1] == '増加' || args[1] == 'UP'){318 if (timer_tmp_array[2]) TimerLimit = TimerLimit + parseInt(timer_tmp_array[2],10) * 8640000;319 if (timer_tmp_array[5]) TimerLimit = TimerLimit + parseInt(timer_tmp_array[5],10) * 360000;320 if (timer_tmp_array[8]) TimerLimit = TimerLimit + parseInt(timer_tmp_array[8],10) * 6000;321 if (timer_tmp_array[11]) TimerLimit = TimerLimit + parseInt(timer_tmp_array[11],10) * 100;322 if (timer_tmp_array[14]) TimerLimit = TimerLimit + parseInt(timer_tmp_array[14],10) * 10;323 if (timer_tmp_array[17]) TimerLimit = TimerLimit + parseInt(timer_tmp_array[17],10);324 }325 else if (args[1] == '減少' || args[1] == 'DOWN'){326 if (timer_tmp_array[2]) TimerLimit = TimerLimit - parseInt(timer_tmp_array[2],10) * 8640000;327 if (timer_tmp_array[5]) TimerLimit = TimerLimit - parseInt(timer_tmp_array[5],10) * 360000;328 if (timer_tmp_array[8]) TimerLimit = TimerLimit - parseInt(timer_tmp_array[8],10) * 6000;329 if (timer_tmp_array[11]) TimerLimit = TimerLimit - parseInt(timer_tmp_array[11],10) * 100;330 if (timer_tmp_array[14]) TimerLimit = TimerLimit - parseInt(timer_tmp_array[14],10) * 10;331 if (timer_tmp_array[17]) TimerLimit = TimerLimit - parseInt(timer_tmp_array[17],10);332 if (TimerLimit < 0) TimerLimit = 0;333 }334 if (!RunFlag && pictureId !== 0) $gameScreen.erasePicture(pictureId); 335 }336 337 if (CommndType == '実時間操作' || CommndType.toUpperCase() == 'TIMECHANGE'){338 if (!SetFlag){339 if (!$gameTemp.isPlaytest()) console.log('タイマーが設定されていません');340 return;341 }342 var timer_tmp_array = args[2].match(/((\d+)(d|日))?((\d+)(h|時間))?((\d+)(m|分間?))?((\d+)(s|秒間?))?((\d+)(x))?((\d+)(c))?/);343 if (args[1] == '進行' || args[1].toUpperCase() == 'UP'){344 if (timer_tmp_array[2]) Count = Count + parseInt(timer_tmp_array[2],10) * 8640000;345 if (timer_tmp_array[5]) Count = Count + parseInt(timer_tmp_array[5],10) * 360000;346 if (timer_tmp_array[8]) Count = Count + parseInt(timer_tmp_array[8],10) * 6000;347 if (timer_tmp_array[11]) Count = Count + parseInt(timer_tmp_array[11],10) * 100;348 if (timer_tmp_array[14]) Count = Count + parseInt(timer_tmp_array[14],10) * 10;349 if (timer_tmp_array[17]) Count = Count + parseInt(timer_tmp_array[17],10);350 if (Count > TimerLimit) Count = TimerLimit;351 }352 else if (args[1] == '逆行' || args[1].toUpperCase() == 'DOWN'){353 if (timer_tmp_array[2]) Count = Count - parseInt(timer_tmp_array[2],10) * 8640000;354 if (timer_tmp_array[5]) Count = Count - parseInt(timer_tmp_array[5],10) * 360000;355 if (timer_tmp_array[8]) Count = Count - parseInt(timer_tmp_array[8],10) * 6000;356 if (timer_tmp_array[11]) Count = Count - parseInt(timer_tmp_array[11],10) * 100;357 if (timer_tmp_array[14]) Count = Count - parseInt(timer_tmp_array[14],10) * 10;358 if (timer_tmp_array[17]) Count = Count - parseInt(timer_tmp_array[17],10);359 if (Count < 0) Count = 0;360 }361 if (!RunFlag && pictureId !== 0) $gameScreen.erasePicture(pictureId); 362 }363 364 }365 };366 //=============================================================================367 // TimerInitialize368 // プラグインコマンドで指定された値をセットします369 //=============================================================================370 371 function TimerInitialize(){372 OriginalTimer = null;373 SetFlag = false;374 RunFlag = false;375 DisplayMode = '';376 Count = 0;377 CountUnit = 0;378 CountTime = 0;379 CommndType = '';380 TimerType = '';381 TimerLimit = 0;382 day = 0;383 hr = 0;384 min = 0;385 sec = 0;386 Hsec = 0;387 TimerText = '';388 ShowText = '';389 pictureId = 0;390 fontsize = 32; 391 name = '';392 origin = 0;393 x = 0;394 y = 0;395 scaleX = 100;396 scaleY = 100;397 opacity = 255;398 blendMode = 0;399 SwitchState = '';400 SwitchNumber = 0;401 if (pictureId !== 0) $gameScreen.erasePicture(pictureId);402 };403 404 405 //=============================================================================406 // TimerSet407 // プラグインコマンドで指定された値をセットします408 //=============================================================================409 410 function TimerSet(args){411 if (pictureId !== 0) $gameScreen.erasePicture(pictureId);412 TimerType = args[1];413 var timer_tmp_array = args[2].match(/((\d+)(d|日))?((\d+)(h|時間))?((\d+)(m|分間?))?((\d+)(s|秒間?))?((\d+)(x))?((\d+)(c))?/);414 TimerLimit = 0;415 if (timer_tmp_array[2]) TimerLimit = TimerLimit + parseInt(timer_tmp_array[2],10) * 8640000;416 if (timer_tmp_array[5]) TimerLimit = TimerLimit + parseInt(timer_tmp_array[5],10) * 360000;417 if (timer_tmp_array[8]) TimerLimit = TimerLimit + parseInt(timer_tmp_array[8],10) * 6000;418 if (timer_tmp_array[11]) TimerLimit = TimerLimit + parseInt(timer_tmp_array[11],10) * 100;419 if (timer_tmp_array[14]) TimerLimit = TimerLimit + parseInt(timer_tmp_array[14],10) * 10;420 if (timer_tmp_array[17]) TimerLimit = TimerLimit + parseInt(timer_tmp_array[17],10);421 pictureId = parseInt(args[3],10);422 fontsize = parseInt(args[4],10);423 x = parseInt(args[5],10);424 y = parseInt(args[6],10);425 DisplayMode = args[7];426 if (DisplayMode == '非表示' || DisplayMode.toUpperCase() == 'HIDE'){427 opacity = 0;428 if (TimerSave == 'YES') $gameTimer._fftfanttOriginalTimer_DisplayMode = '非表示';429 }else{430 opacity = 255;431 if (TimerSave == 'YES') $gameTimer._fftfanttOriginalTimer_DisplayMode = '表示';432 }433 TimerText = args[8];434 if (args.length > 8){435 for (var i=9;i<args.length; i++) {436 TimerText = TimerText + ' ' + args[i];437 }438 }439 TimerText = TimerText.toUpperCase();440 Count = 0;441 CountUnit = 1000;442 if (~TimerText.indexOf('X') || ~args[2].indexOf('x')) CountUnit = 100;443 if (~TimerText.indexOf('C') || ~args[2].indexOf('x')) CountUnit = 10;444 if (TimerSave == 'YES'){445 $gameTimer._fftfanttOriginalTimer_TimerType = TimerType;446 $gameTimer._fftfanttOriginalTimer_TimerLimit = args[2];447 $gameTimer._fftfanttOriginalTimer_TimerText = TimerText;448 $gameTimer._fftfanttOriginalTimer_PctureId = pictureId;449 $gameTimer._fftfanttOriginalTimer_FontSize = fontsize;450 $gameTimer._fftfanttOriginalTimer_X = x;451 $gameTimer._fftfanttOriginalTimer_Y = y;452 $gameTimer._fftfanttOriginalTimer_DisplayMode = DisplayMode;453 $gameTimer._fftfanttOriginalTimer_TimerText = TimerText;454 $gameTimer._fftfanttOriginalTimer_Set = true;455 }456 }457 //=============================================================================458 // TimerRun459 // タイマー実行時の処理460 //=============================================================================461 462 function TimerRun(){463 if (Count >= TimerLimit) {464 RunFlag = false;465 if (SwitchNumber > 0){466 if (SwitchState = 'ON') SwitchState = true;467 if (SwitchState = 'OFF') SwitchState = false;468 if (SwitchState = 'REVERSE'){469 console.log(SwitchState)470 if ($gameSwitches._data[SwitchNumber] == null) SwitchState = false;471 SwitchState = !$gameSwitches._data[SwitchNumber]472 }473 $gameSwitches.setValue(SwitchNumber,SwitchState);474 }475 if (pictureId !== 0) $gameScreen.erasePicture(pictureId);476 if (TimerSave == 'YES') $gameTimer._fftfanttOriginalTimer_Run = false;477 }478 if (!RunFlag){479 clearInterval(OriginalTimer);480 return;481 }482 var now = getCurrentMsec();483 // NB: SceneManager.updateMain と同じ判定である事484 var fTime = (now - prevMsec) / 1000;485 if (fTime > 0.25) fTime = 0.25;486 Count = Count + Math.max(0, fTime * 100);487 prevMsec = now;488 if (TimerType == 'アップ' || TimerType.toUpperCase() == 'UP'){489 CountTime = Math.round(Count);490 }else{491 CountTime = TimerLimit - Math.round(Count);492 }493 day = parseInt(Math.floor(CountTime / 8640000),10);494 hr = parseInt((CountTime % 8640000) / 360000,10);495 min = parseInt((CountTime % 360000) / 6000,10);496 sec = parseInt((CountTime % 6000)/100,10);497 Hsec = CountTime % 100;498 ShowText = TimerText;499 ShowText = ShowText.replace("D",day);500 ShowText = ShowText.replace("HH",("0"+hr).slice(-2));501 ShowText = ShowText.replace("H",hr);502 ShowText = ShowText.replace("MM",("0"+min).slice(-2));503 ShowText = ShowText.replace("M",min);504 ShowText = ShowText.replace("SS",("0"+sec).slice(-2));505 ShowText = ShowText.replace("S",sec);506 ShowText = ShowText.replace("X",("0"+Hsec).slice(-2).substr(0,1));507 ShowText = ShowText.replace("C",("0"+Hsec).slice(-2).substr(1,1));508 name = 'OriginalTimer' + Date.now().toString();509 $gameScreen.showPicture(pictureId, name, origin, x, y, scaleX, scaleY, opacity, blendMode);510 if (TimerSave == 'YES') $gameTimer._fftfanttOriginalTimer_Count = Count;511 };512 //=============================================================================513 // TimerGet514 // プラグインコマンドで指定されたタイマーの値を取得します515 //=============================================================================516 function TimerGet(args){517 var GetType = args[1].toUpperCase518 if (args[1] == '表示値' || args[1].toUpperCase() == 'DISPLAYVALUE'){519 $gameVariables._data[parseInt(args[2],10)] = ShowText;520 return;521 }522 if (args[1] == '値' || args[1].toUpperCase() == 'VALUE'){523 $gameVariables._data[parseInt(args[2],10)] = parseInt(CountTime,10);524 return;525 }526 if (args[1] == 'セット値' || args[1].toUpperCase() == 'SETVALUE'){527 $gameVariables._data[parseInt(args[2],10)] = parseInt(TimerLimit,10);528 return;529 }530 if (args[1] == '日' || args[1].toUpperCase() == 'DAY' || args[1].toUpperCase() == 'D'){531 $gameVariables._data[parseInt(args[2],10)] = parseInt(day,10);532 return;533 }534 if (args[1] == '時' || args[1].toUpperCase() == 'HR' || args[1].toUpperCase() == 'H'){535 $gameVariables._data[parseInt(args[2],10)] = parseInt(hr,10);536 return;537 }538 if (args[1]== '分' || args[1].toUpperCase() == 'MIN' || args[1].toUpperCase() == 'M'){539 $gameVariables._data[parseInt(args[2],10)] = parseInt(min,10);540 return;541 }542 if (args[1] == '秒' || args[1].toUpperCase() == 'SEC' || args[1].toUpperCase() == 'S'){543 $gameVariables._data[parseInt(args[2],10)] = parseInt(sec,10);544 return;545 }546 if (args[1] == 'コンマ秒' || args[1].toUpperCase() == 'HSEC' || args[1].toUpperCase() == 'XC'){547 $gameVariables._data[parseInt(args[2],10)] = parseInt(Hsec,10);548 return;549 }550 if (args[1] == '状態'){551 if (RunFlag) {552 $gameVariables._data[parseInt(args[2],10)] = '実行中';553 } else {554 $gameVariables._data[parseInt(args[2],10)] = '停止中'555 }556 return;557 }558 if (args[1].toUpperCase() == 'STATE'){559 if (RunFlag) {560 $gameVariables._data[parseInt(args[2],10)] = 'RUN';561 } else {562 $gameVariables._data[parseInt(args[2],10)] = 'STOP';563 }564 return;565 }566 }567 //=============================================================================568 // Sprite_Picture569 // 画像の動的生成を追加定義します。570 //=============================================================================571 var _Sprite_Picture_loadBitmap = Sprite_Picture.prototype.loadBitmap;572 Sprite_Picture.prototype.loadBitmap = function() {573 if (this.picture()._name == name) {574 this.fftfanttOriginalTimer_UpdateShowText();575 } else {576 _Sprite_Picture_loadBitmap.call(this);577 }578 };579 Sprite_Picture.prototype.fftfanttOriginalTimer_UpdateShowText = function(bitmap) {580 this.bitmap = new Bitmap(ShowText.length * fontsize + x ,(fontsize + y) *1.0 ) ;581 this.bitmap.fontSize = fontsize;582 this.bitmap.clear();583 this.bitmap.drawText(ShowText, x, y,0 ,0, "left");584 };585 //=============================================================================586 // Scene_Save587 // TimerSaveがNOの場合、セーブ前にオリジナルタイマーのオブジェクトを削除します588 //=============================================================================589 590 var _Scene_Save_onSavefileOk = Scene_Save.prototype.onSavefileOk;591 Scene_Save.prototype.onSavefileOk = function() {592 if (pictureId !== 0) $gameScreen.erasePicture(pictureId);593 if (TimerSave !== 'YES'){594 delete $gameTimer._fftfanttOriginalTimer_Count;595 delete $gameTimer._fftfanttOriginalTimer_Set;596 delete $gameTimer._fftfanttOriginalTimer_Run;597 delete $gameTimer._fftfanttOriginalTimer_Display;598 delete $gameTimer._fftfanttOriginalTimer_TimerType;599 delete $gameTimer._fftfanttOriginalTimer_TimerLimit;600 delete $gameTimer._fftfanttOriginalTimer_PctureId;601 delete $gameTimer._fftfanttOriginalTimer_FontSize;602 delete $gameTimer._fftfanttOriginalTimer_X;603 delete $gameTimer._fftfanttOriginalTimer_Y;604 delete $gameTimer._fftfanttOriginalTimer_DisplayMode;605 delete $gameTimer._fftfanttOriginalTimer_TimerText;606 delete $gameTimer._fftfanttOriginalTimer_SwitchState;607 delete $gameTimer._fftfanttOriginalTimer_SwitchNumber;608 }609 _Scene_Save_onSavefileOk.call(this);610 };611 //=============================================================================612 // Scene_Base613 // 戦闘終了後にピクチャが呼び出せないエラーを回避します614 //=============================================================================615 var _Scene_Base_prototype_isReady = Scene_Base.prototype.isReady;616 Scene_Base.prototype.isReady = function() {617 if (pictureId !== 0) $gameScreen.erasePicture(pictureId);618 return _Scene_Base_prototype_isReady.call(this);619 };620 //=============================================================================621 // Scene_Load622 // ロード時にタイマーを再実行するための処理追加定義します623 //=============================================================================624 var _Scene_Load_onLoadSuccess = Scene_Load.prototype.onLoadSuccess;625 Scene_Load.prototype.onLoadSuccess = function() {626 _Scene_Load_onLoadSuccess.call(this);627 Game_Timer.prototype.fftfanttOriginalTimer_Reinitiation();628 };629 630 //=============================================================================631 // Game_Timer632 // オリジナルタイマー用のメソッドを追加定義します633 //=============================================================================634 635 Game_Timer.prototype.fftfanttOriginalTimer_Initialize = function() {636 if (TimerSave !== 'YES') return;637 if (pictureId !== 0) $gameScreen.erasePicture(pictureId);638 this._fftfanttOriginalTimer_Count = 0;639 this._fftfanttOriginalTimer_Set = false;640 this._fftfanttOriginalTimer_Run = false;641 this._fftfanttOriginalTimer_TimerType = '';642 this._fftfanttOriginalTimer_TimerLimit = 0;643 this._fftfanttOriginalTimer_PctureId = 0;644 this._fftfanttOriginalTimer_FontSize = 0;645 this._fftfanttOriginalTimer_X = 0;646 this._fftfanttOriginalTimer_Y = 0;647 this._fftfanttOriginalTimer_DisplayMode = '';648 this._fftfanttOriginalTimer_TimerText = '';649 this._fftfanttOriginalTimer_SwitchNumber = 0;650 this._fftfanttOriginalTimer_SwitchState = '';651 };652 653 Game_Timer.prototype.fftfanttOriginalTimer_Reinitiation = function() {654 if (TimerSave !== 'YES') return;655 if ($gameTimer == null) return;656 if (!Object.prototype.hasOwnProperty.call($gameTimer, '_fftfanttOriginalTimer_Set')) return;657 if (!$gameTimer._fftfanttOriginalTimer_Set) return;658 var args = [];659 args[0] = '設定';660 args[1] = $gameTimer._fftfanttOriginalTimer_TimerType;661 args[2] = $gameTimer._fftfanttOriginalTimer_TimerLimit;662 args[3] = $gameTimer._fftfanttOriginalTimer_PctureId;663 args[4] = $gameTimer._fftfanttOriginalTimer_FontSize;664 args[5] = $gameTimer._fftfanttOriginalTimer_X;665 args[6] = $gameTimer._fftfanttOriginalTimer_Y;666 args[7] = $gameTimer._fftfanttOriginalTimer_DisplayMode;667 args[8] = $gameTimer._fftfanttOriginalTimer_TimerText;668 SetFlag = $gameTimer._fftfanttOriginalTimer_Set669 RunFlag = $gameTimer._fftfanttOriginalTimer_Run670 SwitchState = $gameTimer._fftfanttOriginalTimer_SwitchState671 SwitchNumber = $gameTimer._fftfanttOriginalTimer_SwitchNumber672 TimerSet(args);673 Count = $gameTimer._fftfanttOriginalTimer_Count674 if (!RunFlag) return;675 clearInterval(OriginalTimer);676 prevMsec = getCurrentMsec();677 OriginalTimer = setInterval(TimerRun,CountUnit);678 };679 ...

Full Screen

Full Screen

timer.js

Source:timer.js Github

copy

Full Screen

1var today = new Date();2var timer = function() {};3timer.countdownDate = new Date();4// set date to 10 days in the future for testing purposes5timer.countdownDate.setDate( timer.countdownDate.getDate() + 10 );6/*7* Get thing started8*/9timer.init = function() {10 timer.getReferences();11 12 13 timer.getTimes();14 setInterval(function() { timer.update() }, 1000);15}16/*17* Save references of timer section18*/19timer.getReferences = function() {20 timer.timer = document.getElementById("timer");21 timer.days = timer.timer.querySelectorAll(".days .timer__number")[0];22 timer.hours = timer.timer.querySelectorAll(".hours .timer__number")[0];23 timer.minutes = timer.timer.querySelectorAll(".minutes .timer__number")[0];24 timer.seconds = timer.timer.querySelectorAll(".seconds .timer__number")[0];25}26/*27* remember time units for later use28*/29timer.getTimes = function() {30 timer.times = {};31 timer.times.second = 1000;32 timer.times.minute = timer.times.second * 60;33 timer.times.hour = timer.times.minute * 60;34 timer.times.day = timer.times.hour * 24;35}36/*37* Update the countdown38*/39timer.update = function() {40 if ( timer.timer.style.opacity !== 1 ) {41 timer.timer.style.opacity = 1;42 }43 44 timer.currentDate = new Date();45 timer.difference = timer.countdownDate - timer.currentDate;46 47 timer.days.innerHTML = timer.getTimeRemaining(timer.times.day, 1);48 timer.hours.innerHTML = timer.getTimeRemaining(timer.times.hour, 24);49 timer.minutes.innerHTML = timer.getTimeRemaining(timer.times.minute, 60);50 timer.seconds.innerHTML = timer.getTimeRemaining(timer.times.second, 60);51}52/*53* calculate remaining time based on a unit of time54*/55timer.getTimeRemaining = function( timeUnit, divisor ) {56 var n;57 if ( divisor == 1 ) {58 n = Math.floor(timer.difference / timeUnit );59 }60 else {61 n = Math.floor((timer.difference / timeUnit) % divisor );62 }63 64 if ( String(n).length < 2 ) {65 n = "0" + n;66 }67 68 return n;69}70window.addEventListener("load", function() {71 timer.init();...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var trace = require('tracetest').trace;2var timer = require('tracetest').timer;3var fs = require('fs');4var t = timer('test');5fs.readFile('./test.js', function(err, data) {6 t.stop();7 console.log('test');8 console.log(data);9});

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('./tracetest');2var trace = new tracetest();3trace.timer('test');4setTimeout(function(){5 trace.timer('test');6}, 1000);7setTimeout(function(){8 trace.timer('test');9}, 2000);10setTimeout(function(){11 trace.timer('test');12}, 3000);13var util = require('util');14var EventEmitter = require('events').EventEmitter;15var TraceTest = function(){16 EventEmitter.call(this);17 this.count = 0;18 this.times = [];19};20util.inherits(TraceTest, EventEmitter);21TraceTest.prototype.timer = function(name){22 var time = new Date().getTime();23 this.times.push(time);24 this.count++;25 if(this.count == 1){26 this.emit(name, 'start');27 }28 else if(this.count == 2){29 this.emit(name, 'lap', time - this.times[0]);30 }31 else if(this.count == 3){32 this.emit(name, 'lap', time - this.times[1]);33 }34 else if(this.count == 4){35 this.emit(name, 'end', time - this.times[2]);36 }37 else{38 this.count = 0;39 this.times = [];40 }41};42module.exports = TraceTest;43var tracetest = require('./tracetest');44var trace = new tracetest();45trace.timer('test');46setTimeout(function(){47 trace.timer('test');48}, 1000);49setTimeout(function(){50 trace.timer('test');51}, 2000);52setTimeout(function(){53 trace.timer('test');54}, 3000);55var util = require('util');56var EventEmitter = require('events').EventEmitter;57var TraceTest = function(){58 EventEmitter.call(this);59 this.count = 0;60 this.times = [];61};62util.inherits(TraceTest, EventEmitter);63TraceTest.prototype.timer = function(name){64 var time = new Date().getTime();65 this.times.push(time);66 this.count++;67 if(this.count == 1){68 this.emit(name, 'start');69 }70 else if(this.count == 2){71 this.emit(name, 'lap', time - this.times[0]);72 }73 else if(this.count == 3){74 this.emit(name, 'lap

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('./tracetest.js');2var timer = tracetest.timer;3timer.start();4for (var i = 0; i < 1000000; i++) {5 var j = i * 2;6}7timer.stop();8timer.print();

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('tracetest');2var timer = tracetest.timer;3timer.start('test');4timer.stop('test');5timer.report('test');6var tracetest = require('tracetest');7var timer = tracetest.timer;8timer.start('test2');9timer.stop('test2');10timer.report('test2');

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('tracetest');2var time = tracetest.timer();3time.start();4time.stop();5console.log('elapsed time: ' + time.elapsed());6var tracetest = require('tracetest');7var time = tracetest.timer();8time.start();9time.stop();10console.log('elapsed time: ' + time.elapsed());11var tracetest = require('tracetest');12var trace = tracetest.trace('test');13function test() {14 console.log('in test');15 trace.end();16}17test();

Full Screen

Using AI Code Generation

copy

Full Screen

1var trace = require('tracetest');2var timer = trace.timer('test');3timer.end();4var trace = require('tracetest');5var timer = trace.timer('test');6timer.end();7var trace = require('tracetest');8var tracer = trace.tracer('test');9tracer.trace('trace');10var trace = require('tracetest');11trace.trace('test', 'trace');12var trace = require('tracetest');13var tracer = trace.tracer('test');14tracer.trace('trace');

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tracetest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful