diff --git a/DKTools.js b/DKTools.js index 57d6d16..11f665f 100644 --- a/DKTools.js +++ b/DKTools.js @@ -3,8 +3,8 @@ Title: DKTools Author: DK (Denis Kuznetsov) Site: https://dk-plugins.ru E-mail: kuznetsovdenis96@gmail.com -Version: 2.0.1 -Release: 13.05.2018 +Version: 3.0.0 +Release: 02.06.2018 First release: 13.01.2016 Supported languages: Russian, English */ @@ -14,14 +14,14 @@ Supported languages: Russian, English Автор: DK (Денис Кузнецов) Сайт: https://dk-plugins.ru E-mail: kuznetsovdenis96@gmail.com -Версия: 2.0.1 -Релиз: 13.05.2018 +Версия: 3.0.0 +Релиз: 02.06.2018 Первый релиз: 13.01.2016 Поддерживаемые языки: Русский, Английский */ /*: -* @plugindesc v.2.0.1 Library for RPG Maker. Made with ♥ by DKPlugins +* @plugindesc v.3.0.0 Library for RPG Maker. Made with ♥ by DKPlugins * @author DK (Denis Kuznetsov) * @help @@ -29,8 +29,8 @@ E-mail: kuznetsovdenis96@gmail.com Title: DKTools Author: DK (Denis Kuznetsov) Site: https://dk-plugins.ru - Version: 2.0.1 - Release: 13.05.2018 + Version: 3.0.0 + Release: 02.06.2018 First release: 13.01.2016 Supported languages: Russian, English Thank you for your support: https://dk-plugins.ru/donate @@ -47,12 +47,9 @@ E-mail: kuznetsovdenis96@gmail.com ### Requirements and dependencies ### Version of RPG Maker 1.5+ - ### 1 ### Installation ### - 1. Copy DKTools.js to the js/plugins/ of your project - 2. Enable DKTools in the plugin manager - 3. Add at least one game language in the parameters of the DKTools + ### Instructions ### - ### 2 ### Templates for the filename of the screenshot ### + ### 1 ### Templates for the filename of the screenshot ### %year - Year %month - Month %day - Day @@ -70,18 +67,26 @@ E-mail: kuznetsovdenis96@gmail.com DKTools.Utils.Random DKTools.Utils.Sequence DKTools.Utils.Sequence.Alphabet - DKTools.ParameterManager - DKTools.PluginManager + DKTools.Utils.Event DKTools.IO DKTools.IO.Entity DKTools.IO.File DKTools.IO.Directory DKTools.IO.WebStorage - DKTools.Localization + DKTools.ParameterManager + DKTools.PluginManager + DKTools.PluginCommandManager + DKTools.PreloadManager DKTools.Audio DKTools.Event DKTools.Animation DKTools.Animation.Action + DKTools.OptionManager + DKTools.EventManager + DKTools.Unit + DKTools.Unit.Property + DKTools.Unit.Properties + DKTools.Unit.Function DKTools.Base DKTools.Sprite DKTools.Sprite.Button @@ -111,82 +116,70 @@ E-mail: kuznetsovdenis96@gmail.com You can't: -Delete or change any information about plugin (Title, authorship, contact information, version and release) - * @param Localization - * @text Localization - * @default --------------------------------- - - * @param Languages - * @text Game languages - * @parent Localization - * @desc List of game languages - * @type struct[] - * @default ["{\"Language\":\"English\",\"Locale\":\"en\",\"Primary\":\"true\"}"] - - * @param Local Path - * @text Local path - * @parent Localization - * @desc Local path to save the language of the game - * @default save/ - - * @param Local Filename - * @text Local filename - * @parent Localization - * @desc The name of the local file to save the language of the game - * @default locale.rpgsave - - * @param Web Filename - * @text Web filename - * @parent Localization - * @desc The name of the web file to save the language of the game - * @default RPG Locale - - * @param Debug - * @text Debug + * @param Debugging * @default --------------------------------- * @param Open Console - * @text Debug console * @parent Debug - * @desc Open the debug console when the game starts? + * @text Debug console + * @desc Open the debug console when the game test starts ? * @type boolean * @default false * @param Show FPS * @parent Debug - * @desc Show the FPS counter when the game starts? + * @desc Show the FPS counter when the game starts ? * @type boolean * @default false * @param Functions * @default --------------------------------- - * @param Screen + * @param Check Updates + * @parent Functions + * @desc Check updates + * @type struct + * @default {"Enabled":"false"} + + * @param Screen Resolution * @parent Functions * @desc Screen settings - * @type struct - * @default {"Screen Resolution":"false","Screen Width":"816","Screen Height":"624"} + * @type struct + * @default {"Enabled":"false","Screen Width":"816","Screen Height":"624"} * @param Quick Start * @parent Functions - * @desc Quick Start + * @desc Quick start * @type struct - * @default {"Quick Start":"false","Scene Name":"Scene_Map","Skip Saves":"false"} + * @default {"Enabled":"false","Scene Name":"Scene_Map","Skip Saves":"false"} + + * @param Quick Load + * @parent Functions + * @desc Quick load + * @type struct + * @default {"Enabled":"false","Key Code":"114"} + + * @param Preload Manager + * @parent Functions + * @desc Preloading resources + * @type struct + * @default {"Enabled":"false","Debugging":"false","Images":"[]"} * @param Screenshots * @parent Functions * @desc Screenshots * @type struct - * @default {"Take Screenshot":"false","Screenshot Key Code":"44","Screenshot Path":"screenshots/","Screenshot Filename":"%year_%month_%day_%hours_%minutes_%seconds.png"} + * @default {"Enabled":"false","Key Code":"44","Screenshot Path":"screenshots/","Screenshot Filename":"%year_%month_%day_%hours_%minutes_%seconds.png"} * @param Errors Log * @parent Functions * @type struct - * @default {"Errors Log":"None","Filename":"errors_log.txt","File Size":"10"} + * @default {"Enabled":"None","Filename":"errors_log.txt","File Size":"10"} */ /*:ru -* @plugindesc v.2.0.1 Библиотека для RPG Maker. Сделано с ♥ от DKPlugins +* @plugindesc v.3.0.0 Библиотека для RPG Maker. Сделано с ♥ от DKPlugins * @author DK (Денис Кузнецов) * @help @@ -194,8 +187,8 @@ E-mail: kuznetsovdenis96@gmail.com Название: DKTools Автор: DK (Денис Кузнецов) Сайт: https://dk-plugins.ru - Версия: 2.0.1 - Релиз: 13.05.2018 + Версия: 3.0.0 + Релиз: 02.06.2018 Первый релиз: 13.01.2016 Поддерживаемые языки: Русский, Английский Спасибо за Вашу поддержку: https://dk-plugins.ru/donate @@ -212,12 +205,9 @@ E-mail: kuznetsovdenis96@gmail.com ### Требования и зависимости ### Версия мейкера 1.5+ - ### 1 ### Установка ### - 1. Скопировать DKTools.js в папку js/plugins/ вашего проекта - 2. Включить плагин DKTools в менеджере плагинов - 3. Добавить хотя бы один язык игры в параметрах плагина DKTools + ### Инструкции ### - ### 2 ### Шаблоны для названия файла скриншота ### + ### 1 ### Шаблоны для названия файла скриншота ### %year - Год %month - Месяц %day - День @@ -235,18 +225,26 @@ E-mail: kuznetsovdenis96@gmail.com DKTools.Utils.Random DKTools.Utils.Sequence DKTools.Utils.Sequence.Alphabet - DKTools.ParameterManager - DKTools.PluginManager + DKTools.Utils.Event DKTools.IO DKTools.IO.Entity DKTools.IO.File DKTools.IO.Directory DKTools.IO.WebStorage - DKTools.Localization + DKTools.ParameterManager + DKTools.PluginManager + DKTools.PluginCommandManager + DKTools.PreloadManager DKTools.Audio DKTools.Event DKTools.Animation DKTools.Animation.Action + DKTools.OptionManager + DKTools.EventManager + DKTools.Unit + DKTools.Unit.Property + DKTools.Unit.Properties + DKTools.Unit.Function DKTools.Base DKTools.Sprite DKTools.Sprite.Button @@ -276,50 +274,21 @@ E-mail: kuznetsovdenis96@gmail.com Вы не можете: -Убирать или изменять любую информацию о плагине (Название, авторство, контактная информация, версия и дата релиза) - * @param Localization - * @text Локализация - * @default --------------------------------- - - * @param Languages - * @text Языки игры - * @parent Localization - * @desc Список языков игры - * @type struct[] - * @default ["{\"Language\":\"Русский\",\"Locale\":\"ru\",\"Primary\":\"true\"}"] - - * @param Local Path - * @text Локальный путь - * @parent Localization - * @desc Локальный путь для сохранения языка игры - * @default save/ - - * @param Local Filename - * @text Название локального файла - * @parent Localization - * @desc Название локального файла для сохранения языка игры - * @default locale.rpgsave - - * @param Web Filename - * @text Название веб-файла - * @parent Localization - * @desc Название веб-файла для сохранения языка игры - * @default RPG Locale - - * @param Debug + * @param Debugging * @text Отладка * @default --------------------------------- * @param Open Console * @text Отладочная консоль - * @parent Debug - * @desc Открыть отладочную консоль при запуске игры? + * @parent Debugging + * @desc Открыть отладочную консоль при запуске теста игры ? * @type boolean * @default false * @param Show FPS * @text Отобразить FPS - * @parent Debug - * @desc Показать счетчик FPS при запуске игры? + * @parent Debugging + * @desc Показать счетчик FPS при запуске теста игры ? * @type boolean * @default false @@ -327,76 +296,80 @@ E-mail: kuznetsovdenis96@gmail.com * @text Функции * @default --------------------------------- - * @param Screen + * @param Check Updates + * @text Проверка обновлений * @parent Functions - * @text Экран - * @desc Настройки экрана - * @type struct - * @default {"Screen Resolution":"false","Screen Width":"816","Screen Height":"624"} + * @desc Проверка обновлений + * @type struct + * @default {"Enabled":"false"} - * @param Quick Start + * @param Screen Resolution + * @text Разрешение экрана * @parent Functions + * @desc Настройки разрешения экрана + * @type struct + * @default {"Enabled":"false","Screen Width":"816","Screen Height":"624"} + + * @param Quick Start * @text Быстрый старт + * @parent Functions * @desc Быстрый старт * @type struct - * @default {"Quick Start":"false","Scene Name":"Scene_Map","Skip Saves":"false"} + * @default {"Enabled":"false","Scene Name":"Scene_Map","Skip Saves":"false"} - * @param Screenshots + * @param Quick Load + * @text Быстрая загрузка + * @parent Functions + * @desc Быстрая загрузка игры + * @type struct + * @default {"Enabled":"false","Key Code":"114"} + + * @param Preload Manager + * @text Предзагрузка ресурсов * @parent Functions + * @desc Предварительная загрузка ресурсов + * @type struct + * @default {"Enabled":"false","Debugging":"false","Images":"[]"} + + * @param Screenshots * @text Скриншоты + * @parent Functions * @desc Скриншоты * @type struct - * @default {"Take Screenshot":"false","Screenshot Key Code":"44","Screenshot Path":"screenshots/","Screenshot Filename":"%year_%month_%day_%hours_%minutes_%seconds.png"} + * @default {"Enabled":"false","Key Code":"44","Screenshot Path":"screenshots/","Screenshot Filename":"%year_%month_%day_%hours_%minutes_%seconds.png"} * @param Errors Log - * @parent Functions * @text Логирование ошибок + * @parent Functions * @desc Логирование ошибок * @type struct - * @default {"Errors Log":"None","Filename":"errors_log.txt","File Size":"10"} + * @default {"Enabled":"None","Filename":"errors_log.txt","File Size":"10"} */ -/*~struct~Language: - - * @param Language - * @text Language name - * @desc Language name +/*~struct~CheckUpdates: - * @param Locale - * @text Short language name - * @desc Short language name (locale) - - * @param Primary - * @text Primary language - * @desc Is this the primary language of the game ? + * @param Enabled + * @desc Enable automatic update checking ? Information is displayed in the console during the game test * @type boolean * @default false */ -/*~struct~Language:ru - - * @param Language - * @text Название языка - * @desc Название языка +/*~struct~CheckUpdates:ru - * @param Locale - * @text Короткое название языка - * @desc Короткое название языка (локаль) - - * @param Primary - * @text Основной язык - * @desc Это основной язык игры ? + * @param Enabled + * @text Проверка обновлений + * @desc Включить автоматическую проверку обновлений ? Информация выводится в консоль при тесте игры * @type boolean * @default false */ -/*~struct~Screen: +/*~struct~ScreenResolution: - * @param Screen Resolution - * @desc Enable the Screen Resolution function? + * @param Enabled + * @desc Enable the Screen Resolution function ? * @type boolean * @default false @@ -414,11 +387,11 @@ E-mail: kuznetsovdenis96@gmail.com */ -/*~struct~Screen:ru +/*~struct~ScreenResolution:ru - * @param Screen Resolution - * @text Разрешение экрана - * @desc Включить функцию изменения разрешения экрана? + * @param Enabled + * @text Включено + * @desc Включить функцию изменения разрешения экрана ? * @type boolean * @default false @@ -440,8 +413,8 @@ E-mail: kuznetsovdenis96@gmail.com /*~struct~QuickStart: - * @param Quick Start - * @desc Enable the Quick Start function? + * @param Enabled + * @desc Enable the Quick Start function ? * @type boolean * @default false @@ -458,9 +431,9 @@ E-mail: kuznetsovdenis96@gmail.com /*~struct~QuickStart:ru - * @param Quick Start - * @text Быстрый старт - * @desc Включить функцию быстрого старта? + * @param Enabled + * @text Включено + * @desc Включить функцию быстрого старта ? * @type boolean * @default false @@ -477,14 +450,136 @@ E-mail: kuznetsovdenis96@gmail.com */ +/*~struct~QuickLoad: + + * @param Enabled + * @desc Enable the Quick Load function ? + * @type boolean + * @default false + + * @param Key Code + * @desc The key code that is responsible for the quick loading. 114 - F3 + * @type number + * @default 114 + + * @param Savefile ID + * @desc Savefile number for quick loading. Specify 0 to show the load scene + * @type number + * @default 0 + + */ + +/*~struct~QuickLoad:ru + + * @param Enabled + * @text Включено + * @desc Включить функцию быстрой загрузки ? + * @type boolean + * @default false + + * @param Key Code + * @text Код клавиши + * @desc Код клавиши, которая отвечает за быструю загрузку. 114 - F3 + * @default 114 + + * @param Savefile ID + * @text Файл сохранения + * @desc Номер файла сохранения для быстрой загрузки. Укажите 0, чтобы показывать экран загрузки + * @type number + * @default 0 + + */ + +/*~struct~PreloadManager: + + * @param Enabled + * @desc Enable the images preloading function ? + * @type boolean + * @default false + + * @param Debugging + * @desc Display preload information in the console ? + * @type boolean + * @default false + + * @param Images + * @desc Preloading images + * @type struct[] + * @default [] + + */ + +/*~struct~PreloadManager:ru + + * @param Enabled + * @text Включено + * @desc Включить функцию предзагрузки изображений ? + * @type boolean + * @default false + + * @param Debugging + * @text Отладка + * @desc Выводить информацию о предзагрузке в консоль ? + * @type boolean + * @default false + + * @param Images + * @text Изображения + * @desc Предзагрузка изображений + * @type struct[] + * @default [] + + */ + +/*~struct~PreloadManagerImage: + + * @param Path + * @desc Path to the file (with extension) or directory. For example, img/system/Window.png for file or img/system/ for directory + + * @param Hue + * @desc Hue + * @type number + * @min 0 + * @max 360 + * @default 0 + + * @param Caching + * @desc Image caching + * @type boolean + * @default false + + */ + +/*~struct~PreloadManagerImage:ru + + * @param Path + * @text Путь + * @desc Путь к файлу (с расширением) или директории. Например, img/system/Window.png для файла или img/system/ для директории + + * @param Hue + * @text Оттенок + * @desc Оттенок + * @type number + * @min 0 + * @max 360 + * @default 0 + + * @param Caching + * @text Кэширование + * @desc Кэширование изображений + * @type boolean + * @default false + + */ + /*~struct~Screenshots: - * @param Take Screenshot - * @desc Enable the Take Screenshot function? + * @param Enabled + * @desc Enable the Take Screenshot function ? * @type boolean * @default false - * @param Screenshot Key Code + * @param Key Code * @text Key Code * @desc The key code that is responsible for saving the screenshot. 44 - PrintScreen * @type number @@ -496,20 +591,20 @@ E-mail: kuznetsovdenis96@gmail.com * @default screenshots/ * @param Screenshot Filename - * @desc The entire list of templates is given in the help (2) + * @desc The entire list of templates is given in the help (1) * @default %year_%month_%day_%hours_%minutes_%seconds.png */ /*~struct~Screenshots:ru - * @param Take Screenshot - * @text Сделать скриншот - * @desc Включить функцию сохранения скриншота? + * @param Enabled + * @text Включено + * @desc Включить функцию сохранения скриншота ? * @type boolean * @default false - * @param Screenshot Key Code + * @param Key Code * @text Код клавиши * @desc Код клавиши, которая отвечает за сохранение скриншота. 44 - PrintScreen * @type number @@ -522,15 +617,15 @@ E-mail: kuznetsovdenis96@gmail.com * @param Screenshot Filename * @text Название файла скриншота - * @desc Весь список шаблонов приведен в справке (2) + * @desc Весь список шаблонов приведен в справке (1) * @default %year_%month_%day_%hours_%minutes_%seconds.png */ /*~struct~ErrorsLog: - * @param Errors Log - * @desc Errors Log + * @param Enabled + * @desc Enable error logging ? * @type select * @option None * @option Only Test @@ -539,7 +634,7 @@ E-mail: kuznetsovdenis96@gmail.com * @default None * @param Filename - * @desc File name + * @desc Filename * @default errors_log.txt * @param File Size @@ -550,9 +645,9 @@ E-mail: kuznetsovdenis96@gmail.com /*~struct~ErrorsLog:ru - * @param Errors Log - * @text Логирование ошибок - * @desc Логирование ошибок + * @param Enabled + * @text Включено + * @desc Включить функцию логирования ошибок ? * @type select * @option Никогда * @value None @@ -733,517 +828,598 @@ E-mail: kuznetsovdenis96@gmail.com * @type {Object} */ var Imported = Imported || {}; -Imported.DKTools = '2.0.1'; - - - - - -//=========================================================================== -// window -//=========================================================================== - -const DKTools_window_onload = window.onload; -window.onload = function() { - DKTools.Utils.initialize(); - DKTools.IO.initialize(); - DKTools.Localization.initialize(); - DKTools_window_onload.call(this); - DKTools.PluginManager.initialize(); -}; +Imported.DKTools = '3.0.0'; //=========================================================================== -// Graphics -//=========================================================================== - -const DKTools_Graphics_initialize = Graphics.initialize; -Graphics.initialize = function(width, height, type) { - DKTools_Graphics_initialize.apply(this, arguments); - - if (Utils.isOptionValid('test') && DKToolsParam.get('Show FPS')) { - this.showFps(); - } -}; - -const DKTools_Graphics_printLoadingError = Graphics.printLoadingError; -Graphics.printLoadingError = function(url) { - DKTools_Graphics_printLoadingError.call(this, url); - SceneManager._logError(`Failed to load: ${url}`); -}; - - - - - -//=========================================================================== -// Input +// DKTools //=========================================================================== -const DKTools_Input_onKeyUp = Input._onKeyUp; -Input._onKeyUp = function(event) { - DKTools_Input_onKeyUp.call(this, event); - - if (DKToolsParam.get('Screenshots', 'Take Screenshot') && - event.keyCode === DKToolsParam.get('Screenshots', 'Screenshot Key Code')) { - DKTools.Utils.makeScreenshot(); - } -}; - - - - - -//=========================================================================== -// TouchInput -//=========================================================================== +/** + * @namespace DKTools + * @type {Object} + */ +const DKTools = {}; // properties -Object.defineProperties(TouchInput, { - - /** - * The X coordinate of the mouse - * - * @readonly - * @type {Number} - * @memberOf TouchInput - */ - mouseX: { - get: function() { - return this._mouseX; - }, - configurable: true - }, +Object.defineProperties(DKTools, { /** - * The Y coordinate of the mouse + * Version of DKTools * * @readonly * @type {Number} - * @memberOf TouchInput + * @memberof DKTools */ - mouseY: { - get: function() { - return this._mouseY; - }, - configurable: true - } + version: { value: Imported.DKTools } }); -// methods +// classes -const DKTools_TouchInput_clear = TouchInput.clear; -TouchInput.clear = function() { - DKTools_TouchInput_clear.call(this); +/** + * Sprite class + * + * @class DKTools.Sprite + * @extends DKTools.Base + * + * @override + * @constructor + * + * @memberof DKTools + * + * @see DKTools.Sprite.prototype.initialize + */ +DKTools.Sprite = function(object, y, width, height) { + this.initialize.apply(this, arguments); +}; - /** - * @private - * @readonly - * @type {Boolean} - */ - this._mouseMoved = false; +/** + * Button class + * + * @class DKTools.Sprite.Button + * @extends DKTools.Sprite + * + * @override + * @constructor + * + * @memberof DKTools.Sprite + * + * @see DKTools.Sprite.Button.prototype.initialize + */ +DKTools.Sprite.Button = function(object, y, width, height) { + this.initialize.apply(this, arguments); +}; - /** - * @private - * @readonly - * @type {Boolean} - */ - this._leftButtonPressed = false; +/** + * Cursor class + * + * @class DKTools.Sprite.Cursor + * @extends DKTools.Sprite + * + * @override + * @constructor + * + * @memberof DKTools.Sprite + * + * @see DKTools.Sprite.Cursor.prototype.initialize + */ +DKTools.Sprite.Cursor = function(object, y, width, height) { + this.initialize.apply(this, arguments); +}; - /** - * @private - * @readonly - * @type {Boolean} - */ - this._middleButtonPressed = false; - - /** - * @private - * @readonly - * @type {Boolean} - */ - this._rightButtonPressed = false; - - /** - * @private - * @readonly - * @type {Boolean} - */ - this._leftButtonReleased = false; - - /** - * @private - * @readonly - * @type {Boolean} - */ - this._middleButtonReleased = false; - - /** - * @private - * @readonly - * @type {Boolean} - */ - this._rightButtonReleased = false; - - /** - * @private - * @readonly - * @type {Number} - */ - this._mouseX = 0; - - /** - * @private - * @readonly - * @type {Number} - */ - this._mouseY = 0; - - this._events.mouseMoved = false; - - this._events.leftButtonPressed = false; - this._events.middleButtonPressed = false; - this._events.rightButtonPressed = false; - - this._events.leftButtonReleased = false; - this._events.middleButtonReleased = false; - this._events.rightButtonReleased = false; +/** + * Arrow class + * + * @class DKTools.Sprite.Arrow + * @extends DKTools.Sprite.Button + * + * @override + * @constructor + * + * @memberof DKTools.Sprite + * + * @see DKTools.Sprite.Arrow.prototype.initialize + */ +DKTools.Sprite.Arrow = function(object, y) { + this.initialize.apply(this, arguments); }; -const DKTools_TouchInput_update = TouchInput.update; -TouchInput.update = function() { - this._mouseMoved = this._events.mouseMoved; - - this._leftButtonPressed = this._events.leftButtonPressed; - this._middleButtonPressed = this._events.middleButtonPressed; - this._rightButtonPressed = this._events.rightButtonPressed; - - this._leftButtonReleased = this._events.leftButtonReleased; - this._middleButtonReleased = this._events.middleButtonReleased; - this._rightButtonReleased = this._events.rightButtonReleased; - - this._events.mouseMoved = false; - - this._events.leftButtonReleased = false; - this._events.middleButtonReleased = false; - this._events.rightButtonReleased = false; - - DKTools_TouchInput_update.call(this); +/** + * Selectable class + * + * @class DKTools.Sprite.Selectable + * @extends DKTools.Sprite.Button + * + * @override + * @constructor + * + * @memberof DKTools.Sprite + * + * @see DKTools.Sprite.Selectable.prototype.initialize + */ +DKTools.Sprite.Selectable = function(object, y, width, height) { + this.initialize.apply(this, arguments); }; -// is methods +/** + * Progress bar class + * + * @class DKTools.Sprite.ProgressBar + * @extends DKTools.Sprite + * + * @override + * @constructor + * + * @memberof DKTools.Sprite + * + * @see DKTools.Sprite.ProgressBar.prototype.initialize + */ +DKTools.Sprite.ProgressBar = function(object, y, width, height) { + this.initialize.apply(this, arguments); +}; /** - * Returns true if the mouse is moving + * Progress bar class * - * @static - * @returns {Boolean} Mouse is moving + * @class DKTools.Sprite.ProgressBar.Rectangle + * @extends DKTools.Sprite.ProgressBar + * + * @override + * @constructor + * + * @memberof DKTools.Sprite.ProgressBar + * + * @see DKTools.Sprite.ProgressBar.Rectangle.prototype.initialize */ -TouchInput.isMouseMoved = function() { - return this._mouseMoved; +DKTools.Sprite.ProgressBar.Rectangle = function(object, y, width, height) { + this.initialize.apply(this, arguments); }; /** - * Returns true if the mouse is pressed (left, middle or right button) + * Progress bar class * - * @static - * @returns {Boolean} Mouse is pressed (left, middle or right button) + * @class DKTools.Sprite.ProgressBar.Circle + * @extends DKTools.Sprite.ProgressBar + * + * @override + * @constructor + * + * @memberof DKTools.Sprite.ProgressBar + * + * @see DKTools.Sprite.ProgressBar.Circle.prototype.initialize */ -TouchInput.isMousePressed = function() { - return this.isLeftButtonPressed() || this.isMiddleButtonPressed() || this.isRightButtonPressed(); +DKTools.Sprite.ProgressBar.Circle = function(object, y, width, height) { + this.initialize.apply(this, arguments); }; /** - * Returns true if the mouse is released (left, middle or right button is released) + * Progress bar class * - * @static - * @returns {Boolean} Mouse is released (left, middle or right button is released) + * @class DKTools.Sprite.ProgressBar.SemiCircle + * @extends DKTools.Sprite.ProgressBar.Circle + * + * @override + * @constructor + * + * @memberof DKTools.Sprite.ProgressBar + * + * @see DKTools.Sprite.ProgressBar.SemiCircle.prototype.initialize */ -TouchInput.isMouseReleased = function() { - return this.isLeftButtonReleased() || this.isMiddleButtonReleased() || this.isRightButtonReleased(); +DKTools.Sprite.ProgressBar.SemiCircle = function(object, y, width, height) { + this.initialize.apply(this, arguments); }; /** - * Returns true if the left mouse button is pressed + * Checkbox class * - * @static - * @returns {Boolean} Left mouse button is pressed + * @class DKTools.Sprite.CheckBox + * @extends DKTools.Sprite.Button + * + * @override + * @constructor + * + * @memberof DKTools.Sprite + * + * @see DKTools.Sprite.CheckBox.prototype.initialize */ -TouchInput.isLeftButtonPressed = function() { - return this._leftButtonPressed; +DKTools.Sprite.CheckBox = function(object, y) { + this.initialize.apply(this, arguments); }; /** - * Returns true if the left mouse button is released + * Viewport class * - * @static - * @returns {Boolean} Left mouse button is released + * @class DKTools.Viewport + * @extends DKTools.Sprite + * + * @override + * @constructor + * + * @memberof DKTools + * + * @see DKTools.Viewport.prototype.initialize */ -TouchInput.isLeftButtonReleased = function() { - return this._leftButtonReleased; +DKTools.Viewport = function(object, y, width, height) { + this.initialize.apply(this, arguments); }; /** - * Returns true if the middle mouse button is pressed + * Layout class * - * @static - * @returns {Boolean} Middle mouse button is pressed + * @class DKTools.Layout + * @extends DKTools.Sprite + * + * @override + * @constructor + * + * @memberof DKTools + * + * @see DKTools.Layout.prototype.initialize */ -TouchInput.isMiddleButtonPressed = function() { - return this._middleButtonPressed; +DKTools.Layout = function(object, y) { + this.initialize.apply(this, arguments); }; /** - * Returns true if the middle mouse button is released + * Window class * - * @static - * @returns {Boolean} Middle mouse button is released + * @class DKTools.Window + * @extends DKTools.Base + * + * @override + * @constructor + * + * @memberof DKTools + * + * @see DKTools.Window.prototype.initialize */ -TouchInput.isMiddleButtonReleased = function() { - return this._middleButtonReleased; +DKTools.Window = function(object, y, width, height) { + this.initialize.apply(this, arguments); }; /** - * Returns true if the right mouse button is pressed + * Window selectable class * - * @static - * @returns {Boolean} Right mouse button is pressed + * @class DKTools.Window.Selectable + * @extends DKTools.Window + * + * @override + * @constructor + * + * @memberof DKTools.Window + * + * @see DKTools.Window.Selectable.prototype.initialize */ -TouchInput.isRightButtonPressed = function() { - return this._rightButtonPressed; +DKTools.Window.Selectable = function(object, y, width, height) { + this.initialize.apply(this, arguments); }; /** - * Returns true if the right mouse button is released + * Scene class * - * @static - * @returns {Boolean} Right mouse button is released + * @class DKTools.Scene + * @extends Scene_Base + * + * @constructor + * + * @memberof DKTools */ -TouchInput.isRightButtonReleased = function() { - return this._rightButtonReleased; +DKTools.Scene = function() { + this.initialize.apply(this, arguments); }; -// event methods -const DKTools_TouchInput_onLeftButtonDown = TouchInput._onLeftButtonDown; -TouchInput._onLeftButtonDown = function(event) { - const x = Graphics.pageToCanvasX(event.pageX); - const y = Graphics.pageToCanvasY(event.pageY); - - DKTools_TouchInput_onLeftButtonDown.call(this, event); - - if (Graphics.isInsideCanvas(x, y)) { - this._events.leftButtonPressed = true; - } -}; -const DKTools_TouchInput_onMiddleButtonDown = TouchInput._onMiddleButtonDown; -TouchInput._onMiddleButtonDown = function(event) { - const x = Graphics.pageToCanvasX(event.pageX); - const y = Graphics.pageToCanvasY(event.pageY); - DKTools_TouchInput_onMiddleButtonDown.call(this, event); - if (Graphics.isInsideCanvas(x, y)) { - this._events.middleButtonPressed = true; - } -}; +//=========================================================================== +// DKTools.Utils +//=========================================================================== -const DKTools_TouchInput_onRightButtonDown = TouchInput._onRightButtonDown; -TouchInput._onRightButtonDown = function(event) { - const x = Graphics.pageToCanvasX(event.pageX); - const y = Graphics.pageToCanvasY(event.pageY); +/** + * The static class that defines utility methods + * + * @class DKTools.Utils + * @memberof DKTools + */ +DKTools.Utils = class { - DKTools_TouchInput_onRightButtonDown.call(this, event); + constructor() { + return DKTools.Utils; + }; - if (Graphics.isInsideCanvas(x, y)) { - this._events.rightButtonPressed = true; - } -}; + /** + * Initializes the utils + * + * @version 3.0.0 + * @static + */ + static initialize() { -const DKTools_TouchInput_onMouseMove = TouchInput._onMouseMove; -TouchInput._onMouseMove = function(event) { - const x = Graphics.pageToCanvasX(event.pageX); - const y = Graphics.pageToCanvasY(event.pageY); + /** + * @private + * @readonly + * @type {Boolean} + */ + this._saidHello = false; - DKTools_TouchInput_onMouseMove.call(this, event); + /** + * @private + * @readonly + * @type {Boolean} + */ + this._isNwjs = Utils.isNwjs(); - if (this._mouseX !== x || this._mouseY !== y) { - this._events.mouseMoved = true; - this._mouseX = x; - this._mouseY = y; - } -}; + /** + * @private + * @readonly + * @type {Boolean} + */ + this._isMobileDevice = Utils.isMobileDevice(); -const DKTools_TouchInput_onMouseUp = TouchInput._onMouseUp; -TouchInput._onMouseUp = function(event) { - const x = Graphics.pageToCanvasX(event.pageX); - const y = Graphics.pageToCanvasY(event.pageY); + /** + * @private + * @readonly + * @type {Boolean} + */ + this._isMobileSafari = Utils.isMobileSafari(); - DKTools_TouchInput_onMouseUp.call(this, event); + /** + * @private + * @readonly + * @type {Boolean} + */ + this._isAndroidChrome = Utils.isAndroidChrome(); - this._events.leftButtonPressed = false; - this._events.middleButtonPressed = false; - this._events.rightButtonPressed = false; + this._sayHello(); - if (Graphics.isInsideCanvas(x, y)) { - if (event.button === 0) { // left button - this._events.leftButtonReleased = true; - } else if (event.button === 1) { // middle button - this._events.middleButtonReleased = true; - } else if (event.button === 2) { // right button - this._events.rightButtonReleased = true; + if (DKToolsParam.get('Open Console')) { + this.openConsole(); } - } -}; - - - + if (DKToolsParam.get('Check Updates', 'Enabled')) { + this._checkUpdates(); + } + }; -//=========================================================================== -// SceneManager -//=========================================================================== + /** + * Displays information about the plugin in the debug console + * + * @private + * @static + */ + static _sayHello() { + if (this._saidHello) { + return; + } -const DKTools_SceneManager_initGraphics = SceneManager.initGraphics; -SceneManager.initGraphics = function() { - const param = DKToolsParam.get('Screen'); - const width = param['Screen Width']; - const height = param['Screen Height']; + if (navigator.userAgent.toLowerCase().indexOf('chrome') >= 0) { + const args = [`%c %c %c DKTools.js ${DKTools.version} %c %c https://www.dk-plugins.ru/ %c \n`, + 'background: #279EE8; padding:5px 0;', + 'background: #279EE8; padding:5px 0;', + 'color: #4CCBF5; background: #030307; padding:5px 0;', + 'background: #279EE8; padding:5px 0;', + 'background: #BDE5F2; padding:5px 0;', + 'background: #279EE8; padding:5px 0;']; - if (param['Screen Resolution']) { - this._boxWidth = width; - this._screenWidth = width; - this._boxHeight = height; - this._screenHeight = height; + console.log.apply(console, args); + } else if (window.console) { + console.log('DKTools.js ' + DKTools.version + ' - https://www.dk-plugins.ru/'); + } - DKTools_SceneManager_initGraphics.call(this); + this._saidHello = true; + }; - if (DKTools.Utils.isNwjs()) { - this.updateResolution(); + /** + * Checks the updates + * + * @since 3.0.0 + * @private + * @static + */ + static _checkUpdates() { + if (!this.isNwjs() || !Utils.isOptionValid('test')) { + return; } - } else { - DKTools_SceneManager_initGraphics.call(this); - } -}; - -SceneManager.updateResolution = function() { - const resizeWidth = this._screenWidth - window.innerWidth; - const resizeHeight = this._screenHeight - window.innerHeight; - if (!Imported.ScreenResolution && resizeWidth && resizeHeight) { - window.moveBy(-1 * resizeWidth / 2, -1 * resizeHeight / 2); - window.resizeBy(resizeWidth, resizeHeight); - } -}; + const xhr = new XMLHttpRequest(); + xhr.open('GET', 'https://api.github.com/repos/DKPlugins/DKTools/releases'); + xhr.overrideMimeType('application/json'); + xhr.onload = function() { + if (xhr.status < 400) { + const response = JSON.parse(xhr.responseText); -SceneManager._logError = function(e) { - if (!e || !DKTools.Utils.isNwjs()) { - return; - } + if (response) { + const data = response[0]; + const newestVersion = data['tag_name']; - const param = DKToolsParam.get('Errors Log'); - const logErrors = param['Errors Log']; + if (newestVersion > DKTools.version) { + const args = [`Available a new version of DKTools: ${newestVersion} \n`, + `Changelog: ${data['html_url']} \n`, + 'Download: http://dk-plugins.ru/download/DKTools.js']; - if (logErrors === 'None' || - logErrors === 'Only Game' && Utils.isOptionValid('test') || - logErrors === 'Only Test' && !Utils.isOptionValid('test')) { - return; - } + console.log.apply(console, args); + } + } + } + }; + xhr.send(); + }; - const fs = DKTools.IO.fs; - const os = require('os'); + /** + * Copies properties of one object to another. + * Handles get/set properties correctly. + * Doesn't clone sub-objects + * + * @static + * @param {Object} target - A target to copy properties + * @param {Object} source - The source of properties + */ + static mixin(target, source) { + const properties = Object.getOwnPropertyNames(source); - if (!fs || !os) { - return; - } + _.forEach(properties, function(property) { + const descriptor = Object.getOwnPropertyDescriptor(source, property); - const fileSize = param['File Size'] * 1024 * 1024; - const filename = param['Filename']; - const file = new DKTools.IO.File('', filename); - const stats = file.getStats({ sync: true }).data; - let fileDescription = fs.openSync(filename, 'a'); + Object.defineProperty(target, property, descriptor); + }); + }; - if (stats && stats.size > fileSize) { - fs.closeSync(fileDescription); - file.remove({ sync: true }); - fileDescription = fs.openSync(filename, 'a'); - } + /** + * Opens the console + * + * @static + */ + static openConsole() { + if (!this.isNwjs() || !Utils.isOptionValid('test')) { + return; + } - if (e instanceof Error) { - let data = `Date: ${new Date().toString()}` + os.EOL + - `Name: ${e.name}` + os.EOL + - `Message: ${e.message}` + os.EOL; + try { + const window = require('nw.gui').Window.get(); - if (e.filename != undefined) { - data += `Filename: ${e.filename}` + os.EOL; + window.showDevTools(null, function() { + window.focus(); + }); + } catch(e) { + console.error('DKTools can not open the console'); } + }; - if (e.lineNumber !== undefined) { - data += `Line: ${e.lineNumber}` + os.EOL; + /** + * Makes a screenshot + * + * @static + */ + static makeScreenshot() { + if (!DKTools.Utils.isNwjs()) { + return; } - if (e.columnNumber !== undefined) { - data += `Column: ${e.columnNumber}` + os.EOL; - } + const date = new Date(); + const snap = SceneManager.snap(); + const urlData = snap._canvas.toDataURL(); + const data = urlData.replace(/^data:image\/png;base64,/, ''); + const path = DKToolsParam.get('Screenshots', 'Screenshot Path'); - data += `Stack: ${e.stack}` + os.EOL + os.EOL; + let filename = DKToolsParam.get('Screenshots', 'Screenshot Filename'); + filename = filename.replace(/%year/gi, date.getFullYear()); + filename = filename.replace(/%month/gi, date.getMonth() + 1); + filename = filename.replace(/%day/gi, date.getDate()); + filename = filename.replace(/%hours/gi, date.getHours()); + filename = filename.replace(/%minutes/gi, date.getMinutes()); + filename = filename.replace(/%seconds/gi, date.getSeconds()); - fs.writeSync(fileDescription, data); - } else { - const data = `Date: ${new Date().toString()}` + os.EOL + - `Error: ${e}` + os.EOL; + const fullPath = DKTools.IO.normalizePath(path + '/' + filename); - fs.writeSync(fileDescription, data); - } + const file = new DKTools.IO.File(fullPath); - fs.closeSync(fileDescription); -}; + file.save(data, { + createDirectory: true, + options: 'base64', + callback: function() { + console.log('The screenshot is saved with the name: ' + filename); + } + }); + }; -const DKTools_SceneManager_catchException = SceneManager.catchException; -SceneManager.catchException = function(e) { - DKTools_SceneManager_catchException.call(this, e); - this._logError(e); -}; + /** + * Checks whether the platform is NW.js + * + * @static + * @returns {Boolean} The platform is NW.js + */ + static isNwjs() { + return this._isNwjs; + }; -const DKTools_SceneManager_onError = SceneManager.onError; -SceneManager.onError = function(e) { - DKTools_SceneManager_onError.call(this, e); - this._logError(e); -}; + /** + * Checks whether the platform is a mobile device. + * + * @static + * @returns {Boolean} The platform is a mobile device + */ + static isMobileDevice() { + return this._isMobileDevice; + }; + /** + * Checks whether the browser is Mobile Safari + * + * @static + * @returns {Boolean} The browser is Mobile Safari + */ + static isMobileSafari() { + return this._isMobileSafari; + }; + /** + * Checks whether the browser is Android Chrome + * + * @static + * @returns {Boolean} The browser is Android Chrome + */ + static isAndroidChrome() { + return this._isAndroidChrome; + }; + /** + * Returns true if the value is array or object Arguments + * + * @since 1.1.0 + * @static + * @param {*} value - Value + * @returns {Boolean} Value is array or object Arguments + */ + static isArrayLike(value) { + if (Array.isArray(value)) { + return true; + } + return String(value) === '[object Arguments]'; + }; -//=========================================================================== -// Scene_Boot -//=========================================================================== + /** + * Returns true if the value is string + * + * @since 1.1.0 + * @static + * @param {*} value - Value + * @returns {Boolean} Value is string + */ + static isString(value) { + return !!value && typeof value === 'string'; + }; -const DKTools_Scene_Boot_start = Scene_Boot.prototype.start; -Scene_Boot.prototype.start = function() { - const quickStart = DKToolsParam.get('Quick Start'); - const saveExists = DataManager.isAnySavefileExists(); + /** + * Returns true if the value is boolean + * + * @since 1.1.0 + * @static + * @param {*} value - Value + * @returns {Boolean} Value is boolean + */ + static isBoolean(value) { + return typeof value === 'boolean'; + }; - if (quickStart['Quick Start']) { - DKTools_Scene_Boot_start.call(this); + /** + * Returns true if the value is function + * + * @since 1.1.0 + * @static + * @param {*} value - Value + * @returns {Boolean} Value is function + */ + static isFunction(value) { + return typeof value === 'function'; + }; - if (!DataManager.isBattleTest() && !DataManager.isEventTest() && (quickStart['Skip Saves']) || !saveExists) { - Scene_Base.prototype.start.call(this); - SoundManager.preloadImportantSounds(); - this.checkPlayerLocation(); - DataManager.setupNewGame(); - this.updateDocumentTitle(); - SceneManager.goto(window[quickStart['Scene Name']]); - } - } else { - DKTools_Scene_Boot_start.call(this); - } }; @@ -1251,634 +1427,411 @@ Scene_Boot.prototype.start = function() { //=========================================================================== -// DKTools +// DKTools.Utils.String //=========================================================================== /** - * @namespace DKTools - * @type {Object} + * The static class that defines utility methods for String class + * + * @class DKTools.Utils.String + * @memberof DKTools.Utils */ -const DKTools = {}; - -// properties +DKTools.Utils.String = class { -Object.defineProperties(DKTools, { + constructor() { + return DKTools.Utils.String; + }; /** - * Version of DKTools + * Splits a string by commas into an array of string * - * @readonly - * @type {Number} - * @memberOf DKTools + * @static + * @param {String} string - String + * + * @example + * var array = DKTools.Utils.String.toStringArray('1, 2, 3'); + * => ['1', '2', '3'] + * + * var array = DKTools.Utils.String.toStringArray('1,2,3'); + * => ['1', '2', '3'] + * + * @returns {String[]} Array of strings */ - version: { - value: Imported.DKTools - } + static toStringArray(string) { + return string.replace(/\s*\,\s*/g, ',').split(','); + }; -}); + /** + * Splits a string by commas into an array of numbers + * + * @static + * @param {String} string - String + * + * @example + * var array = DKTools.Utils.String.toNumberArray('1, 2, 3'); + * => [1, 2, 3] + * + * var array = DKTools.Utils.String.toNumberArray('1,2,3'); + * => [1, 2, 3] + * + * @see DKTools.Utils.String.toStringArray + * @returns {Number[]} Array of numbers + */ + static toNumberArray(string) { + return _.map(this.toStringArray(string), Number); + }; -// classes + /** + * Splits a string by commas into an array of booleans + * + * @static + * @param {String} string - String + * + * @example + * var array = DKTools.Utils.String.toBooleanArray('1, 2, 3'); + * => [true, true, true] + * + * var array = DKTools.Utils.String.toBooleanArray('1,2,'); + * => [true, true, false] + * + * @see DKTools.Utils.String.toStringArray + * @returns {Boolean[]} Array of booleans + */ + static toBooleanArray(string) { + return _.map(this.toStringArray(string), Boolean); + }; -/** - * Sprite class - * - * @class DKTools.Sprite - * @extends DKTools.Base - * - * @override - * @constructor - * - * @memberOf DKTools - * - * @see DKTools.Sprite.prototype.initialize - */ -DKTools.Sprite = function(object, y, width, height) { - this.initialize.apply(this, arguments); }; -/** - * Button class - * - * @class DKTools.Sprite.Button - * @extends DKTools.Sprite - * - * @override - * @constructor - * - * @memberOf DKTools.Sprite - * - * @see DKTools.Sprite.Button.prototype.initialize - */ -DKTools.Sprite.Button = function(object, y, width, height) { - this.initialize.apply(this, arguments); -}; -/** - * Cursor class - * - * @class DKTools.Sprite.Cursor - * @extends DKTools.Sprite - * - * @override - * @constructor - * - * @memberOf DKTools.Sprite - * - * @see DKTools.Sprite.Cursor.prototype.initialize - */ -DKTools.Sprite.Cursor = function(object, y, width, height) { - this.initialize.apply(this, arguments); -}; + + + +//=========================================================================== +// DKTools.Utils.Array +//=========================================================================== /** - * Arrow class - * - * @class DKTools.Sprite.Arrow - * @extends DKTools.Sprite.Button - * - * @override - * @constructor - * - * @memberOf DKTools.Sprite + * The static class that defines utility methods for Array class * - * @see DKTools.Sprite.Arrow.prototype.initialize + * @class DKTools.Utils.Array + * @memberof DKTools.Utils */ -DKTools.Sprite.Arrow = function(object, y) { - this.initialize.apply(this, arguments); -}; - -/** - * - * - * @class DKTools.Sprite.Selectable - * @extends DKTools.Sprite.Button - * - * @override - * @constructor - * - * @memberOf DKTools.Sprite - * - * @see DKTools.Sprite.Selectable.prototype.initialize - */ -DKTools.Sprite.Selectable = function(object, y, width, height) { - this.initialize.apply(this, arguments); -}; - -/** - * Progress bar class - * - * @class DKTools.Sprite.ProgressBar - * @extends DKTools.Sprite - * - * @override - * @constructor - * - * @memberOf DKTools.Sprite - * - * @see DKTools.Sprite.ProgressBar.prototype.initialize - */ -DKTools.Sprite.ProgressBar = function(object, y, width, height) { - this.initialize.apply(this, arguments); -}; - -/** - * - * - * @class DKTools.Sprite.ProgressBar.Rectangle - * @extends DKTools.Sprite.ProgressBar - * - * @override - * @constructor - * - * @memberOf DKTools.Sprite.ProgressBar - * - * @see DKTools.Sprite.ProgressBar.Rectangle.prototype.initialize - */ -DKTools.Sprite.ProgressBar.Rectangle = function(object, y, width, height) { - this.initialize.apply(this, arguments); -}; - -/** - * - * - * @class DKTools.Sprite.ProgressBar.Circle - * @extends DKTools.Sprite.ProgressBar - * - * @override - * @constructor - * - * @memberOf DKTools.Sprite.ProgressBar - * - * @see DKTools.Sprite.ProgressBar.Circle.prototype.initialize - */ -DKTools.Sprite.ProgressBar.Circle = function(object, y, width, height) { - this.initialize.apply(this, arguments); -}; - -/** - * - * - * @class DKTools.Sprite.ProgressBar.SemiCircle - * @extends DKTools.Sprite.ProgressBar.Circle - * - * @override - * @constructor - * - * @memberOf DKTools.Sprite.ProgressBar - * - * @see DKTools.Sprite.ProgressBar.SemiCircle.prototype.initialize - */ -DKTools.Sprite.ProgressBar.SemiCircle = function(object, y, width, height) { - this.initialize.apply(this, arguments); -}; - -/** - * - * - * @class DKTools.Sprite.CheckBox - * @extends DKTools.Sprite.Button - * - * @override - * @constructor - * - * @memberOf DKTools.Sprite - * - * @see DKTools.Sprite.CheckBox.prototype.initialize - */ -DKTools.Sprite.CheckBox = function(object, y) { - this.initialize.apply(this, arguments); -}; - -/** - * Viewport class - * - * @class DKTools.Viewport - * @extends DKTools.Sprite - * - * @override - * @constructor - * - * @memberOf DKTools - * - * @see DKTools.Viewport.prototype.initialize - */ -DKTools.Viewport = function(object, y, width, height) { - this.initialize.apply(this, arguments); -}; - -/** - * Layout class - * - * @class DKTools.Layout - * @extends DKTools.Sprite - * - * @override - * @constructor - * - * @memberOf DKTools - * - * @see DKTools.Layout.prototype.initialize - */ -DKTools.Layout = function(object, y) { - this.initialize.apply(this, arguments); -}; - -/** - * Window class - * - * @class DKTools.Window - * @extends DKTools.Base - * - * @override - * @constructor - * - * @memberOf DKTools - * - * @see DKTools.Window.prototype.initialize - */ -DKTools.Window = function(object, y, width, height) { - this.initialize.apply(this, arguments); -}; - -/** - * - * - * @class DKTools.Window.Selectable - * @extends DKTools.Window - * - * @override - * @constructor - * - * @memberOf DKTools.Window - * - * @see DKTools.Window.Selectable.prototype.initialize - */ -DKTools.Window.Selectable = function(object, y, width, height) { - this.initialize.apply(this, arguments); -}; - -/** - * Scene class - * - * @class DKTools.Scene - * @extends Scene_Base - * - * @constructor - * - * @memberOf DKTools - */ -DKTools.Scene = function() { - this.initialize.apply(this, arguments); -}; - - - - - -//=========================================================================== -// DKTools.Utils -//=========================================================================== - -/** - * The static class that defines utility methods - * - * @class DKTools.Utils - * @memberOf DKTools - */ -DKTools.Utils = class { +DKTools.Utils.Array = class { - /** - * @constructor - * @returns {DKTools.Utils} - */ constructor() { - return DKTools.Utils; - }; - - /** - * @static - */ - static initialize() { - - /** - * @private - * @readonly - * @type {Boolean} - */ - this._saidHello = false; - - /** - * @private - * @readonly - * @type {Boolean} - */ - this._isNwjs = Utils.isNwjs(); - - /** - * @private - * @readonly - * @type {Boolean} - */ - this._isMobileDevice = Utils.isMobileDevice(); - - /** - * @private - * @readonly - * @type {Boolean} - */ - this._isMobileSafari = Utils.isMobileSafari(); - - /** - * @private - * @readonly - * @type {Boolean} - */ - this._isAndroidChrome = Utils.isAndroidChrome(); - - this._sayHello(); - - if (Utils.isOptionValid('test') && DKToolsParam.get('Open Console')) { - this.openConsole(); - } + return DKTools.Utils.Array; }; /** - * Displays information about the plugin in the debug console + * Checks whether the array contains a given item * - * @private * @static - */ - static _sayHello() { - if (this._saidHello) { - return; - } - - if (navigator.userAgent.toLowerCase().indexOf('chrome') >= 0) { - const args = ['\n %c %c %c DKTools.js ' + DKTools.version + ' %c %c https://www.dk-plugins.ru/ %c \n\n', - 'background: #279EE8; padding:5px 0;', - 'background: #279EE8; padding:5px 0;', - 'color: #4CCBF5; background: #030307; padding:5px 0;', - 'background: #279EE8; padding:5px 0;', - 'background: #BDE5F2; padding:5px 0;', - 'background: #279EE8; padding:5px 0;']; - - console.log.apply(console, args); - } else if (window.console) { - console.log('DKTools.js ' + DKTools.version + ' - https://www.dk-plugins.ru/'); - } - - this._saidHello = true; - }; - - /** - * Copies properties of one object to another. - * Handles get/set properties correctly. - * Doesn't clone sub-objects * - * @static - * @param {Object} target - A target to copy properties - * @param {Object} source - The source of properties + * @param {Array} array - The array in which the search is performed + * @param {*} item - The item to search + * + * @example + * var array = [1, 2]; + * DKTools.Utils.Array.contains(array, 1); + * => true + * + * var array = [1, 2]; + * DKTools.Utils.Array.contains(array, 3); + * => false + * + * @returns {Boolean} Array contains a given item */ - static mixin(target, source) { - const properties = Object.getOwnPropertyNames(source); - - _.forEach(properties, function(property) { - const descriptor = Object.getOwnPropertyDescriptor(source, property); - Object.defineProperty(target, property, descriptor); - }); + static contains(array, item) { + return _.includes(array, item); }; /** - * Opens the console + * Returns the number of item in the array * * @static + * + * @param {Array} array - The array in which the search is performed + * @param {*} item - The item to search + * + * @example + * var array = [1, 1, 2]; + * DKTools.Utils.Array.contains(array, 1); + * => 2 + * + * @example + * var array = [1, 1, 2]; + * DKTools.Utils.Array.contains(array, 2); + * => 1 + * + * @returns {Number} Number of item in the array */ - static openConsole() { - if (this.isNwjs() && Utils.isOptionValid('test')) { - const window = require('nw.gui').Window.get(); - - if (window) { - try { - window.showDevTools(null, function() { - window.focus(); - }); - } catch(e) { - console.error('DKTools can not open the console'); - } - } - } + static count(array, item) { + return _.size(array) - _.size(_.without(array, item)); }; /** - * Makes a screenshot + * Returns the sum of the number of items in the array * * @static + * + * @param {Array} array - The array in which the search is performed + * @param {Array} items - The items to search + * + * @example + * var array1 = [1, 1, 2]; + * var array2 = [1, 2]; + * DKTools.Utils.Array.counts(array1, array2); + * => 3 + * + * @returns {Number} Sum of the number of items in the array */ - static makeScreenshot() { - if (!DKTools.Utils.isNwjs()) { - return; - } - - const path = DKToolsParam.get('Screenshots', 'Screenshot Path'); - - const date = new Date(); - let filename = DKToolsParam.get('Screenshots', 'Screenshot Filename'); - filename = filename.replace(/%year/gi, date.getFullYear()); - filename = filename.replace(/%month/gi, date.getMonth() + 1); - filename = filename.replace(/%day/gi, date.getDate()); - filename = filename.replace(/%hours/gi, date.getHours()); - filename = filename.replace(/%minutes/gi, date.getMinutes()); - filename = filename.replace(/%seconds/gi, date.getSeconds()); - - const snap = SceneManager.snap(); - const urlData = snap._canvas.toDataURL(); - const data = urlData.replace(/^data:image\/png;base64,/, ''); - - const file = new DKTools.IO.File(path, filename); - file.save(data, { - createDirectory: true, - options: 'base64', - callback: function() { - console.log('The screenshot is saved with the name: ' + filename); - } - }); + static counts(array, items) { + return _.size(array) - _.size(_.difference(array, items)); }; /** - * Checks whether the platform is NW.js + * Removes '', null, undefined and NaN from the array. + * This method mutates array * * @static - * @returns {Boolean} The platform is NW.js + * @param {Array} array - The array to compact + * + * @example + * var array = [null, 1, undefined]; + * DKTools.Utils.Array.compact(array); + * => [1]; + * + * @returns {Array} Mutated array */ - static isNwjs() { - return this._isNwjs; + static compact(array) { + return _.pull(array, '', null, undefined, Number.NaN); }; /** - * Checks whether the platform is a mobile device. + * Removes item from the array. + * This method mutates array * * @static - * @returns {Boolean} The platform is a mobile device + * + * @param {Array} array - The array to remove + * @param {*} item - The item to remove + * + * @example + * var array = [1, 2, 3]; + * DKTools.Utils.Array.remove(array, 1); + * => [2, 3]; + * + * @returns {Array} Mutated array */ - static isMobileDevice() { - return this._isMobileDevice; + static remove(array, item) { + return _.pull(array, item); }; /** - * Checks whether the browser is Mobile Safari + * Inserts the item into the array. + * This method mutates array * * @static - * @returns {Boolean} The browser is Mobile Safari + * + * @param {Array} array - The array to insert + * @param {*} item - The item to insert + * @param {Number} [index=0] - The index to insert + * + * @example + * var array = [1, 2, 4]; + * DKTools.Utils.Array.insert(array, 3, 2); + * => [1, 2, 3, 4]; */ - static isMobileSafari() { - return this._isMobileSafari; + static insert(array, item, index) { + array.splice(index || 0, 0, item); }; /** - * Checks whether the browser is Android Chrome + * Checks whether the array is empty * + * @version 2.0.0 * @static - * @returns {Boolean} The browser is Android Chrome + * @param {Array} array - The array to check + * @returns {Boolean} Array is empty */ - static isAndroidChrome() { - return this._isAndroidChrome; + static isEmpty(array) { + return _.isEmpty(array); }; /** - * Returns true if the value is array or object Arguments + * Checks whether all elements of the array are of type Number * - * @since 1.1.0 * @static - * @param {*} value - Value - * @returns {Boolean} Value is array or object Arguments + * @param {Array} array - The array to check + * + * @example + * var array = [1, 2]; + * DKTools.Utils.Array.isNumberArray(array); + * => true + * + * var array = ['1', 2]; + * DKTools.Utils.Array.isNumberArray(array); + * => false + * + * @returns {Boolean} All elements of the array are of type Number */ - static isArrayLike(value) { - if (Array.isArray(value)) { - return true; - } - - return String(value) === '[object Arguments]'; + static isNumberArray(array) { + return _.every(array, Number.isFinite); }; /** - * Returns true if the value is string + * Checks whether all elements of the array are of type Boolean * - * @since 1.1.0 * @static - * @param {*} value - Value - * @returns {Boolean} Value is string + * @param {Array} array - The array to check + * + * @example + * var array = [true, false]; + * DKTools.Utils.Array.isBooleanArray(array); + * => true + * + * var array = ['1', false]; + * DKTools.Utils.Array.isBooleanArray(array); + * => false + * + * @returns {Boolean} All elements of the array are of type Boolean */ - static isString(value) { - return typeof value === 'string'; + static isBooleanArray(array) { + return _.every(array, DKTools.Utils.isBoolean); }; /** - * Returns true if the value is boolean + * Checks whether all elements of the array are of type String * - * @since 1.1.0 + * @version 2.0.0 * @static - * @param {*} value - Value - * @returns {Boolean} Value is boolean + * @param {Array} array - The array to check + * + * @example + * var array = ['1', '2']; + * DKTools.Utils.Array.isStringArray(array); + * => true + * + * var array = ['1', 2]; + * DKTools.Utils.Array.isStringArray(array); + * => false + * + * @returns {Boolean} All elements of the array are of type String */ - static isBoolean(value) { - return typeof value === 'boolean'; + static isStringArray(array) { + return _.every(array, DKTools.Utils.isString); }; /** - * Returns true if the value is function + * Checks whether all elements of the array are of type Bitmap * - * @since 1.1.0 * @static - * @param {*} value - Value - * @returns {Boolean} Value is function + * @param {Array} array - The array to check + * + * @example + * var array = [new Bitmap()]; + * DKTools.Utils.Array.isBitmapArray(array); + * => true + * + * var array = [new Bitmap(), 2]; + * DKTools.Utils.Array.isBitmapArray(array); + * => false + * + * @returns {Boolean} All elements of the array are of type Bitmap */ - static isFunction(value) { - return typeof value === 'function'; + static isBitmapArray(array) { + return _.every(array, function(item) { + return item instanceof Bitmap; + }); }; -}; - - - - - -//=========================================================================== -// DKTools.Utils.String -//=========================================================================== - -/** - * The static class that defines utility methods for String class - * - * @class DKTools.Utils.String - * @memberOf DKTools.Utils - */ -DKTools.Utils.String = class { - /** - * @constructor - * @returns {DKTools.Utils.String} + * Checks whether all elements of the array are of type Sprite + * + * @static + * @param {Array} array - The array to check + * + * @example + * var array = [new Sprite()]; + * DKTools.Utils.Array.isSpriteArray(array); + * => true + * + * var array = [new Sprite(), 2]; + * DKTools.Utils.Array.isSpriteArray(array); + * => false + * + * @returns {Boolean} All elements of the array are of type Sprite */ - constructor() { - return DKTools.Utils.String; + static isSpriteArray(array) { + return _.every(array, function(item) { + return item instanceof Sprite; + }); }; /** - * Splits a string by commas into an array of string + * Checks whether all elements of the array are of type Window * * @static - * @param {String} string - String + * @param {Array} array - The array to check * * @example - * var array = DKTools.Utils.String.toStringArray('1, 2, 3'); - * => ['1', '2', '3'] + * var array = [new Window()]; + * DKTools.Utils.Array.isWindowArray(array); + * => true * - * var array = DKTools.Utils.String.toStringArray('1,2,3'); - * => ['1', '2', '3'] + * var array = [new Window(), 2]; + * DKTools.Utils.Array.isWindowArray(array); + * => false * - * @returns {String[]} Array of strings + * @returns {Boolean} All elements of the array are of type Window */ - static toStringArray(string) { - return string.replace(/\s*\,\s*/g, ',').split(','); + static isWindowArray(array) { + return _.every(array, function(item) { + return item instanceof Window; + }); }; /** - * Splits a string by commas into an array of numbers + * Performs a logical operation of the disjunction * * @static - * @param {String} string - String + * @param {Array} array - The array to perform * * @example - * var array = DKTools.Utils.String.toNumberArray('1, 2, 3'); - * => [1, 2, 3] + * var array = [true, false, false]; + * DKTools.Utils.Array.disjunction(array); + * => true * - * var array = DKTools.Utils.String.toNumberArray('1,2,3'); - * => [1, 2, 3] + * var array = [false, false]; + * DKTools.Utils.Array.disjunction(array); + * => false * - * @see DKTools.Utils.String.toStringArray - * @returns {Number[]} Array of numbers + * @returns {Boolean} Result of operation */ - static toNumberArray(string) { - return _.map(this.toStringArray(string), Number); + static disjunction(array) { + return _.some(array, _.isEqual.bind(this, true)); }; /** - * Splits a string by commas into an array of booleans + * Performs a logical operation of the conjunction * * @static - * @param {String} string - String + * @param {Array} array - The array to perform * * @example - * var array = DKTools.Utils.String.toBooleanArray('1, 2, 3'); - * => [true, true, true] + * var array = [true, true]; + * DKTools.Utils.Array.conjunction(array); + * => true * - * var array = DKTools.Utils.String.toBooleanArray('1,2,'); - * => [true, true, false] + * var array = [true, false]; + * DKTools.Utils.Array.conjunction(array); + * => false * - * @see DKTools.Utils.String.toStringArray - * @returns {Boolean[]} Array of booleans + * @returns {Boolean} Result of operation */ - static toBooleanArray(string) { - return _.map(this.toStringArray(string), Boolean); + static conjunction(array) { + return _.every(array, _.isEqual.bind(this, true)); }; }; @@ -1888,334 +1841,500 @@ DKTools.Utils.String = class { //=========================================================================== -// DKTools.Utils.Array +// DKTools.Utils.Bitmap //=========================================================================== /** - * The static class that defines utility methods for Array class + * The static class that defines utility methods for Bitmap class * - * @class DKTools.Utils.Array - * @memberOf DKTools.Utils + * @class DKTools.Utils.Bitmap + * @memberof DKTools.Utils */ -DKTools.Utils.Array = class { +DKTools.Utils.Bitmap = class { - /** - * @constructor - * @returns {DKTools.Utils.Array} - */ constructor() { - return DKTools.Utils.Array; + return DKTools.Utils.Bitmap; }; + // load methods + /** - * Checks whether the array contains a given item + * Loads and returns a bitmap * + * @version 3.0.0 * @static * - * @param {Array} array - The array in which the search is performed - * @param {*} item - The item to search + * @param {String | Bitmap | Array | Object} object - Path to file or Bitmap or array with parameters or object with parameters + * @param {String | Object} filename - Name of file (if object is String) + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) * - * @example - * var array = [1, 2]; - * DKTools.Utils.Array.contains(array, 1); - * => true + * @param {String} object.folder - Path to file + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap * - * var array = [1, 2]; - * DKTools.Utils.Array.contains(array, 3); - * => false + * @see Bitmap.prototype.addLoadListener * - * @returns {Boolean} Array contains a given item + * @returns {Bitmap | null} Bitmap or null */ - static contains(array, item) { - return _.includes(array, item); + static load(object, filename, listener, hue, smooth) { + if (!object) { + return null; + } else if (object instanceof Bitmap) { + return object; + } else if (DKTools.Utils.isArrayLike(object)) { + return this.load.apply(this, object); + } else if (object instanceof Object) { + return this.load(object.folder, object.filename, object.listener, object.hue, object.smooth); + } else if (!DKTools.Utils.isString(object)) { + return null; + } + + // object - String (folder) + const folder = DKTools.IO.normalizePath(object + '/'); + const bitmap = ImageManager.loadBitmap(folder, filename, hue, smooth); + + if (DKTools.Utils.isFunction(listener)) { + bitmap.addLoadListener(listener); + } + + return bitmap; }; /** - * Returns the number of item in the array + * Loads the bitmaps and call the callback function when all bitmaps are ready * + * @version 3.0.0 * @static * - * @param {Array} array - The array in which the search is performed - * @param {*} item - The item to search + * @param {Bitmap[] | Object[]} bitmaps - Bitmaps to load + * @param {Function} onLoadAllBitmaps - Function that is called when all bitmaps are loaded and ready + * @param {Function} [onLoadSomeBitmaps] - Function that is called when some bitmaps are loaded and ready * * @example - * var array = [1, 1, 2]; - * DKTools.Utils.Array.contains(array, 1); - * => 2 + * var bitmaps = []; + * bitmaps[0] = ImageManager.loadSystem('Window'); + * bitmaps[1] = { + * folder: 'img/system/', + * filename: 'IconSet' + * }; * - * @example - * var array = [1, 1, 2]; - * DKTools.Utils.Array.contains(array, 2); - * => 1 + * DKTools.Utils.Bitmap.loadBitmaps(bitmaps, function(loadedBitmap, loadedBitmaps, allBitmaps) { + * // all loaded bitmaps + * }); * - * @returns {Number} Number of item in the array + * @see DKTools.Utils.Bitmap.load */ - static count(array, item) { - return _.size(array) - _.size(_.without(array, item)); - }; + static loadBitmaps(bitmaps, onLoadAllBitmaps, onLoadSomeBitmaps) { + if (!DKTools.Utils.isFunction(onLoadAllBitmaps)) { + return; + } - /** - * Returns the sum of the number of items in the array - * - * @static - * - * @param {Array} array - The array in which the search is performed - * @param {Array} items - The items to search - * - * @example - * var array1 = [1, 1, 2]; - * var array2 = [1, 2]; - * DKTools.Utils.Array.counts(array1, array2); - * => 3 - * - * @returns {Number} Sum of the number of items in the array - */ - static counts(array, items) { - return _.size(array) - _.size(_.difference(array, items)); - }; + bitmaps = _.map(bitmaps, this.load.bind(this)); - /** - * Removes '', null, undefined and NaN from the array. - * This method mutates array - * - * @static - * @param {Array} array - The array to compact - * - * @example - * var array = [null, 1, undefined]; - * DKTools.Utils.Array.compact(array); - * => [1]; - * - * @returns {Array} Mutated array - */ - static compact(array) { - return _.pull(array, '', null, undefined, Number.NaN); + const loadedBitmaps = []; + let loaded = 0; + + const loadListener = function(index, loadedBitmap) { + if (!onLoadAllBitmaps) { + return; + } + + loadedBitmaps[index] = loadedBitmap; + loaded++; + + if (DKTools.Utils.isFunction(onLoadSomeBitmaps)) { + onLoadSomeBitmaps(loadedBitmap, loadedBitmaps, bitmaps); + } + + if (bitmaps.length === loaded) { + onLoadAllBitmaps(bitmaps); + onLoadAllBitmaps = null; + } + }; + + _.forEach(bitmaps, function(bitmap, index) { + if (bitmap instanceof Bitmap) { + bitmap.addLoadListener(loadListener.bind(this, index)); + } else { + loadListener(index, bitmap); + } + }.bind(this)); }; + // reserve methods + /** - * Removes item from the array. - * This method mutates array + * Loads and reserves the bitmap * + * @since 3.0.0 * @static * - * @param {Array} array - The array to remove - * @param {*} item - The item to remove + * @param {String | Bitmap | Array | Object} object - Path to file or Bitmap or array with parameters or object with parameters + * @param {String | Object} filename - Name of file (if object is String) + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) * - * @example - * var array = [1, 2, 3]; - * DKTools.Utils.Array.remove(array, 1); - * => [2, 3]; + * @param {String} object.folder - Path to file + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID * - * @returns {Array} Mutated array + * @returns {Bitmap | null} Bitmap or null */ - static remove(array, item) { - return _.pull(array, item); + static reserve(object, filename, listener, hue, smooth, reservationId) { + if (!object) { + return null; + } else if (object instanceof Bitmap) { + return object; + } else if (DKTools.Utils.isArrayLike(object)) { + return this.reserve.apply(this, object); + } else if (object instanceof Object) { + return this.reserve(object.folder, object.filename, object.listener, object.hue, object.smooth, object.reservationId); + } else if (!DKTools.Utils.isString(object)) { + return null; + } + + // object - String (folder) + const folder = DKTools.IO.normalizePath(object + '/'); + const bitmap = ImageManager.reserveBitmap(folder, filename, hue, smooth, reservationId); + + if (DKTools.Utils.isFunction(listener)) { + bitmap.addLoadListener(listener); + } + + return bitmap; }; /** - * Inserts the item into the array. - * This method mutates array + * Loads and reserves the bitmaps and call the callback function when all bitmaps are ready * + * @since 3.0.0 * @static * - * @param {Array} array - The array to insert - * @param {*} item - The item to insert - * @param {Number} [index=0] - The index to insert + * @param {Bitmap[] | Object[]} bitmaps - Bitmaps to load + * @param {Function} onLoadAllBitmaps - Function that is called when all bitmaps are loaded and ready + * @param {Function} [onLoadSomeBitmaps] - Function that is called when some bitmaps are loaded and ready * * @example - * var array = [1, 2, 4]; - * DKTools.Utils.Array.insert(array, 3, 2); - * => [1, 2, 3, 4]; + * var bitmaps = []; + * bitmaps[0] = ImageManager.reserveSystem('Window'); + * bitmaps[1] = { + * folder: 'img/system/', + * filename: 'IconSet' + * }; + * + * DKTools.Utils.Bitmap.reserveBitmaps(bitmaps, function(loadedBitmap, loadedBitmaps, allBitmaps) { + * // your code here + * }); + * + * @see DKTools.Utils.Bitmap.reserve */ - static insert(array, item, index) { - array.splice(index || 0, 0, item); + static reserveBitmaps(bitmaps, onLoadAllBitmaps, onLoadSomeBitmaps) { + if (!DKTools.Utils.isFunction(onLoadAllBitmaps)) { + return; + } + + bitmaps = _.map(bitmaps, this.reserve.bind(this)); + + const loadedBitmaps = []; + let loaded = 0; + + const loadListener = function(index, loadedBitmap) { + if (!onLoadAllBitmaps) { + return; + } + + loadedBitmaps[index] = loadedBitmap; + loaded++; + + if (DKTools.Utils.isFunction(onLoadSomeBitmaps)) { + onLoadSomeBitmaps(loadedBitmap, loadedBitmaps, bitmaps); + } + + if (bitmaps.length === loaded) { + onLoadAllBitmaps(bitmaps); + onLoadAllBitmaps = null; + } + }; + + _.forEach(bitmaps, function(bitmap, index) { + if (bitmap instanceof Bitmap) { + bitmap.addLoadListener(loadListener.bind(this, index)); + } else { + loadListener(index, bitmap); + } + }.bind(this)); }; + // draw methods + /** - * Checks whether the array is empty + * Draws the line to the bitmap * - * @version 2.0.0 * @static - * @param {Array} array - The array to check - * @returns {Boolean} Array is empty + * + * @param {Bitmap} bitmap - Bitmap + * @param {Number} x1 - The X coordinate of start of the line + * @param {Number} y1 - The Y coordinate of start of the line + * @param {Number} x2 - The X coordinate of end of the line + * @param {Number} y2 - The Y coordinate of end of the line + * @param {String} [color='white'] - Line color + * @param {Number} [lineWidth=1] - Line width + * + * @see CanvasRenderingContext2D.lineTo */ - static isEmpty(array) { - return _.isEmpty(array); + static drawLine(bitmap, x1, y1, x2, y2, color, lineWidth) { + const context = bitmap._context; + context.save(); + context.strokeStyle = color || 'white'; + context.lineWidth = lineWidth || 1; + context.beginPath(); + context.moveTo(x1, y1); + context.lineTo(x2, y2); + context.stroke(); + context.restore(); + bitmap._setDirty(); }; /** - * Checks whether all elements of the array are of type Number + * Draws a rectangle without fill * * @static - * @param {Array} array - The array to check - * - * @example - * var array = [1, 2]; - * DKTools.Utils.Array.isNumberArray(array); - * => true * - * var array = ['1', 2]; - * DKTools.Utils.Array.isNumberArray(array); - * => false + * @param {Bitmap} bitmap - Bitmap + * @param {Number} x - The X coordinate + * @param {Number} y - The Y coordinate + * @param {Number} width - Width of the rectangle + * @param {Number} height - Height of the rectangle + * @param {String} [color='white'] - Line color + * @param {Number} [lineWidth=1] - Line width * - * @returns {Boolean} All elements of the array are of type Number + * @see CanvasRenderingContext2D.strokeRect */ - static isNumberArray(array) { - return _.every(array, Number.isFinite); + static strokeRect(bitmap, x, y, width, height, color, lineWidth) { + const context = bitmap._context; + context.save(); + context.strokeStyle = color || 'white'; + context.lineWidth = lineWidth || 1; + context.strokeRect(x, y, width, height); + context.restore(); + bitmap._setDirty(); }; /** - * Checks whether all elements of the array are of type Boolean + * Draws an arc and fills it with color * * @static - * @param {Array} array - The array to check - * - * @example - * var array = [true, false]; - * DKTools.Utils.Array.isBooleanArray(array); - * => true * - * var array = ['1', false]; - * DKTools.Utils.Array.isBooleanArray(array); - * => false + * @param {Bitmap} bitmap - Bitmap + * @param {Number} x - The X coordinate + * @param {Number} y - The Y coordinate + * @param {Number} radius - Radius of the arc + * @param {Number} startAngle - Starting angle + * @param {Number} endAngle - End angle + * @param {String} [color='white'] - Fill color + * @param {Boolean} [anticlockwise=false] - Anticlockwise * - * @returns {Boolean} All elements of the array are of type Boolean + * @see CanvasRenderingContext2D.arc */ - static isBooleanArray(array) { - return _.every(array, DKTools.Utils.isBoolean); + static fillArc(bitmap, x, y, radius, startAngle, endAngle, color, anticlockwise) { + const context = bitmap._context; + context.save(); + context.fillStyle = color || 'white'; + context.beginPath(); + context.arc(x, y, radius, startAngle, endAngle, anticlockwise); + context.fill(); + context.restore(); + bitmap._setDirty(); }; /** - * Checks whether all elements of the array are of type String + * Draws an arc without fill * - * @version 2.0.0 * @static - * @param {Array} array - The array to check - * - * @example - * var array = ['1', '2']; - * DKTools.Utils.Array.isStringArray(array); - * => true * - * var array = ['1', 2]; - * DKTools.Utils.Array.isStringArray(array); - * => false + * @param {Bitmap} bitmap - Bitmap + * @param {Number} x - The X coordinate + * @param {Number} y - The Y coordinate + * @param {Number} radius - Radius of the arc + * @param {Number} startAngle - Starting angle + * @param {Number} endAngle - End angle + * @param {String} [color='white'] - Line color + * @param {Number} [lineWidth=1] - Line width + * @param {Boolean} [anticlockwise=false] - Anticlockwise * - * @returns {Boolean} All elements of the array are of type String + * @see CanvasRenderingContext2D.arc */ - static isStringArray(array) { - return _.every(array, DKTools.Utils.isString); + static strokeArc(bitmap, x, y, radius, startAngle, endAngle, color, lineWidth, anticlockwise) { + const context = bitmap._context; + context.save(); + context.strokeStyle = color || 'white'; + context.lineWidth = lineWidth || 1; + context.beginPath(); + context.arc(x, y, radius, startAngle, endAngle, anticlockwise); + context.stroke(); + context.restore(); + bitmap._setDirty(); }; + // other methods + /** - * Checks whether all elements of the array are of type Bitmap + * Clones the bitmap * * @static - * @param {Array} array - The array to check - * - * @example - * var array = [new Bitmap()]; - * DKTools.Utils.Array.isBitmapArray(array); - * => true - * - * var array = [new Bitmap(), 2]; - * DKTools.Utils.Array.isBitmapArray(array); - * => false - * - * @returns {Boolean} All elements of the array are of type Bitmap + * @param {Bitmap} bitmap - The bitmap to be cloned + * @returns {Bitmap | null} Cloned bitmap */ - static isBitmapArray(array) { - return _.every(array, function(item) { - return item instanceof Bitmap; - }); + static clone(bitmap) { + if (!bitmap || bitmap.url) { + return bitmap; + } + + const canvas = bitmap.canvas; + const newBitmap = new Bitmap(canvas.width, canvas.height); + const newContext = newBitmap.context; + + newContext.drawImage(canvas, 0, 0); + + return newBitmap; + }; + +}; + + + + + +//=========================================================================== +// DKTools.Utils.Point +//=========================================================================== + +/** + * The static class that defines utility methods for Point class + * + * @class DKTools.Utils.Point + * @memberof DKTools.Utils + */ +DKTools.Utils.Point = class { + + constructor() { + return DKTools.Utils.Point; }; /** - * Checks whether all elements of the array are of type Sprite + * Converts arguments to Point, if possible * + * @since 2.0.0 * @static - * @param {Array} array - The array to check * - * @example - * var array = [new Sprite()]; - * DKTools.Utils.Array.isSpriteArray(array); - * => true + * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} object - The X coordinate or Point or object with parameters + * @param {Number} [y] - The Y coordinate (if object is Number) * - * var array = [new Sprite(), 2]; - * DKTools.Utils.Array.isSpriteArray(array); - * => false + * @param {Number} object.x - The X coordinate + * @param {Number} object.y - The Y coordinate * - * @returns {Boolean} All elements of the array are of type Sprite + * @example + * var point = DKTools.Utils.Point.toPoint(0, 0); + * => Point + * + * @example + * var point = DKTools.Utils.Point.toPoint(new Point(0, 0)); + * => Point + * + * @example + * var point = DKTools.Utils.Point.toPoint({ x: 0, y: 0 }); + * => Point + * + * @example + * var point = DKTools.Utils.Point.toPoint(); + * => null + * + * @returns {Point | null} Point or null */ - static isSpriteArray(array) { - return _.every(array, function(item) { - return item instanceof Sprite; - }); + static toPoint(object, y) { + let pointX, pointY; + + if (object instanceof Object) { + pointX = object.x; + pointY = object.y; + } else { // object - Number + pointX = object; + pointY = y; + } + + if (DKTools.Utils.Array.isNumberArray([pointX, pointY])) { + return new Point(pointX, pointY); + } + + return null; }; /** - * Checks whether all elements of the array are of type Window + * Converts the point into an array * + * @since 2.0.0 * @static - * @param {Array} array - The array to check * - * @example - * var array = [new Window()]; - * DKTools.Utils.Array.isWindowArray(array); - * => true + * @param {PIXI.Point | PIXI.ObservablePoint | Point} point - The point to convert * - * var array = [new Window(), 2]; - * DKTools.Utils.Array.isWindowArray(array); - * => false + * @example + * var point = new Point(0, 0); + * DKTools.Utils.Point.toArray(point); + * => [0, 0] * - * @returns {Boolean} All elements of the array are of type Window + * @returns {Number[]} Array with coordinates */ - static isWindowArray(array) { - return _.every(array, function(item) { - return item instanceof Window; - }); + static toArray(point) { + return [point.x, point.y]; }; /** - * Performs a logical operation of the disjunction + * Compares the coordinates of the points * * @static - * @param {Array} array - The array to perform + * + * @param {PIXI.Point | PIXI.ObservablePoint | Point} point1 - The first point to compare + * @param {PIXI.Point | PIXI.ObservablePoint | Point} point2 - The second point to compare * * @example - * var array = [true, false, false]; - * DKTools.Utils.Array.disjunction(array); + * var point1 = new Point(0, 0); + * var point2 = new Point(0, 0); + * DKTools.Utils.Point.equals(point1, point2); * => true * - * var array = [false, false]; - * DKTools.Utils.Array.disjunction(array); + * var point1 = new Point(0, 0); + * var point2 = new Point(0, 1); + * DKTools.Utils.Point.equals(point1, point2); * => false * - * @returns {Boolean} Result of operation + * @returns {Boolean} Comparison result */ - static disjunction(array) { - return _.some(array, _.isEqual.bind(this, true)); + static equals(point1, point2) { + return point1.x === point2.x && point1.y === point2.y; }; /** - * Performs a logical operation of the conjunction + * Clones the point * * @static - * @param {Array} array - The array to perform - * - * @example - * var array = [true, true]; - * DKTools.Utils.Array.conjunction(array); - * => true - * - * var array = [true, false]; - * DKTools.Utils.Array.conjunction(array); - * => false - * - * @returns {Boolean} Result of operation + * @param {PIXI.Point | PIXI.ObservablePoint | Point} point - The point to be cloned + * @returns {Point} Cloned point */ - static conjunction(array) { - return _.every(array, _.isEqual.bind(this, true)); + static clone(point) { + const newPoint = new Point(); + + newPoint.copy(point); + + return newPoint; }; }; @@ -2225,244 +2344,242 @@ DKTools.Utils.Array = class { //=========================================================================== -// DKTools.Utils.Bitmap +// DKTools.Utils.Rectangle //=========================================================================== /** - * The static class that defines utility methods for Bitmap class + * The static class that defines utility methods for Rectangle class * - * @class DKTools.Utils.Bitmap - * @memberOf DKTools.Utils + * @class DKTools.Utils.Rectangle + * @memberof DKTools.Utils */ -DKTools.Utils.Bitmap = class { +DKTools.Utils.Rectangle = class { - /** - * @constructor - * @returns {DKTools.Utils.Bitmap} - */ constructor() { - return DKTools.Utils.Bitmap; + return DKTools.Utils.Rectangle; }; /** - * Loads and returns the bitmap + * Converts arguments to Rectangle, if possible * + * @since 2.0.0 * @static * - * @param {String | Bitmap | DKTools.Sprite | Object} object - Path to file or Bitmap or sprite based on DKTools.Sprite or object with parameters - * @param {String | Object} filename - Name of file - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Number | PIXI.Rectangle | Rectangle | Object} object - The X coordinate or Object + * @param {Number} [y] - The Y coordinate (if object is Number) + * @param {Number} [width] - The rectangle width (if object is Number) + * @param {Number} [height] - ВThe rectangle height (if object is Number) * - * @param {String} object.folder - Path to file - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} object.x - The X coordinate + * @param {Number} object.y - The Y coordinate + * @param {Number} object.width - The rectangle width + * @param {Number} object.height - The rectangle height * - * @see Bitmap.prototype.addLoadListener + * @example + * var rect = DKTools.Utils.Rectangle.toRectangle(0, 0, 0, 0); + * => Rectangle + * + * @example + * var rect = DKTools.Utils.Rectangle.toRectangle(new Rectangle(0, 0, 0, 0)); + * => Rectangle + * + * @example + * var rect = DKTools.Utils.Rectangle.toRectangle({ x: 0, y: 0, width: 0, height: 0}); + * => Rectangle + * + * @example + * var rect = DKTools.Utils.Rectangle.toRectangle(); + * => null * - * @returns {Bitmap | null} Bitmap or null + * @returns {Rectangle | null} Rectangle or null */ - static load(object, filename, listener, hue, smooth) { - if (!object || _.isEmpty(object) || Array.isArray(object)) { - return null; - } else if (object instanceof Bitmap) { - return object; - } else if (object instanceof Object) { - return this.load(object.folder, object.filename, object.listener, object.hue, object.smooth); - } + static toRectangle(object, y, width, height) { + let frameX, frameY, frameWidth, frameHeight; - // object - String (folder) - const bitmap = ImageManager.loadBitmap(object, filename, hue, smooth); + if (object instanceof Object) { + frameX = object.x; + frameY = object.y; + frameWidth = object.width; + frameHeight = object.height; + } else { // object - Number + frameX = object; + frameY = y; + frameWidth = width; + frameHeight = height; + } - if (listener) { - bitmap.addLoadListener(listener); + if (DKTools.Utils.Array.isNumberArray([frameX, frameY, frameWidth, frameHeight])) { + return new Rectangle(frameX, frameY, frameWidth, frameHeight); } - return bitmap; + return null; + }; + + /** + * Converts the rect into an array + * + * @since 2.0.0 + * @static + * + * @param {PIXI.Rectangle | Rectangle} rect - The rectangle to convert + * + * @example + * var rect = new Rectangle(0, 0, 0, 0); + * DKTools.Utils.Rectangle.toArray(rect); + * => [0, 0, 0, 0] + * + * @returns {Number[]} Array with coordinates, width and height of the rect + */ + static toArray(rect) { + return [rect.x, rect.y, rect.width, rect.height]; + }; + + /** + * Compares the coordinates, width and height of the rectangles + * + * @static + * + * @param {PIXI.Rectangle | Rectangle} rect1 - The first rectangle to compare + * @param {PIXI.Rectangle | Rectangle} rect2 - The first rectangle to compare + * + * @example + * var rect1 = new Rectangle(0, 0, 0, 0); + * var rect2 = new Rectangle(0, 0, 0, 0); + * DKTools.Utils.Rectangle.equals(rect1, rect2); + * => true + * + * var rect1 = new Rectangle(0, 0, 0, 0); + * var rect2 = new Rectangle(0, 0, 0, 1); + * DKTools.Utils.Rectangle.equals(rect1, rect2); + * => false + * + * @returns {Boolean} Comparison result + */ + static equals(rect1, rect2) { + return rect1.x === rect2.x && rect1.y === rect2.y && + rect1.width === rect2.width && rect1.height === rect2.height; + }; + + /** + * Checks whether the rect is empty (0, 0, 0, 0) + * + * @static + * @param {PIXI.Rectangle | Rectangle} rect - Rectangle to check + * + * @example + * var rect = new Rectangle(0, 0, 100, 100); + * DKTools.Utils.Rectangle.isEmpty(rect); + * => false + * + * var rect = new Rectangle(0, 0, 0, 0); + * DKTools.Utils.Rectangle.isEmpty(rect); + * => true + * + * @see DKTools.Utils.Rectangle.equals + * + * @returns {Boolean} The rect is empty + */ + static isEmpty(rect) { + return this.equals(rect, Rectangle.emptyRectangle); }; /** - * Loads the bitmaps and call the callback function when loading all bitmaps + * Clones the rect * - * @version 2.0.1 * @static - * - * @param {Bitmap[] | Object[]} bitmaps - Bitmaps to load - * @param {Function} onLoadAllBitmaps - Function that is called when all bitmaps are loaded - * @param {Function} onLoadSomeBitmaps - Function that is called when some bitmaps are loaded - * - * @example - * var bitmaps = []; - * bitmaps[0] = ImageManager.loadSystem('Window'); - * bitmaps[1] = { - * folder: 'img/system/', - * filename: 'IconSet' - * }; - * - * DKTools.Utils.Bitmap.loadBitmaps(bitmaps, function(bitmaps) { - * // all loaded bitmaps - * }); - * - * @see DKTools.Utils.Bitmap.load + * @param {PIXI.Rectangle | Rectangle} rect - The rect to be cloned + * @returns {Rectangle} Cloned rect */ - static loadBitmaps(bitmaps, onLoadAllBitmaps, onLoadSomeBitmaps) { - if (!DKTools.Utils.isFunction(onLoadAllBitmaps)) { - return; - } + static clone(rect) { + const newRect = new Rectangle(); - bitmaps = _.map(bitmaps, this.load); + newRect.copy(rect); - const loadedBitmaps = []; + return newRect; + }; - _.forEach(bitmaps, function(bitmap, index) { - bitmap.addLoadListener(function(bitmap, index) { - if (!onLoadAllBitmaps) { - return; - } +}; - loadedBitmaps[index] = bitmap; - if (loadedBitmaps.length === bitmaps.length) { - onLoadAllBitmaps(bitmaps); - onLoadAllBitmaps = null; - } else if (DKTools.Utils.isFunction(onLoadSomeBitmaps)) { - onLoadSomeBitmaps(loadedBitmaps, bitmaps); - } - }.bind(this, bitmap, index)); - }); + + + +//=========================================================================== +// DKTools.Utils.Random +//=========================================================================== + +/** + * The static class that defines the functions for a random + * + * @class DKTools.Utils.Random + * @memberof DKTools.Utils + */ +DKTools.Utils.Random = class { + + constructor() { + return DKTools.Utils.Random; }; /** - * Draws the line to the bitmap + * Returns a random integer not exceeding max * * @static - * - * @param {Bitmap} bitmap - Bitmap - * @param {Number} x1 - The X coordinate of start of the line - * @param {Number} y1 - The Y coordinate of start of the line - * @param {Number} x2 - The X coordinate of end of the line - * @param {Number} y2 - The Y coordinate of end of the line - * @param {String} [color='white'] - Line color - * @param {Number} [lineWidth=1] - Line width - * - * @see CanvasRenderingContext2D.lineTo + * @param {Number} [max=1] - The maximum value of an integer + * @returns {Number} Random integer not exceeding max */ - static drawLine(bitmap, x1, y1, x2, y2, color, lineWidth) { - const context = bitmap._context; - context.save(); - context.strokeStyle = color || 'white'; - context.lineWidth = lineWidth || 1; - context.beginPath(); - context.moveTo(x1, y1); - context.lineTo(x2, y2); - context.stroke(); - context.restore(); - bitmap._setDirty(); + static getInt(max) { + return _.random(0, max || 1); }; /** - * Draws a rectangle without fill + * Returns a random float number not exceeding max * * @static - * - * @param {Bitmap} bitmap - Bitmap - * @param {Number} x - The X coordinate - * @param {Number} y - The Y coordinate - * @param {Number} width - Width of the rectangle - * @param {Number} height - Height of the rectangle - * @param {String} [color='white'] - Line color - * @param {Number} [lineWidth=1] - Line width - * - * @see CanvasRenderingContext2D.strokeRect + * @param {Number} [max=1] - The maximum value of a float number + * @returns {Number} Random float number not exceeding max */ - static strokeRect(bitmap, x, y, width, height, color, lineWidth) { - const context = bitmap._context; - context.save(); - context.strokeStyle = color || 'white'; - context.lineWidth = lineWidth || 1; - context.strokeRect(x, y, width, height); - context.restore(); - bitmap._setDirty(); + static getFloat(max) { + return _.random(0, max || 1, true); }; /** - * Draws an arc and fills it with color + * Returns a random boolean * * @static - * - * @param {Bitmap} bitmap - Bitmap - * @param {Number} x - The X coordinate - * @param {Number} y - The Y coordinate - * @param {Number} radius - Radius of the arc - * @param {Number} startAngle - Starting angle - * @param {Number} endAngle - End angle - * @param {String} [color='white'] - Fill color - * @param {Boolean} [anticlockwise=false] - Anticlockwise - * - * @see CanvasRenderingContext2D.arc + * @returns {Boolean} Random boolean */ - static fillArc(bitmap, x, y, radius, startAngle, endAngle, color, anticlockwise) { - const context = bitmap._context; - context.save(); - context.fillStyle = color || 'white'; - context.beginPath(); - context.arc(x, y, radius, startAngle, endAngle, anticlockwise); - context.fill(); - context.restore(); - bitmap._setDirty(); + static getBoolean() { + return this.getInt(1) % 2 === 0; }; /** - * Draws an arc without fill + * Returns a random color in rgba format * * @static - * - * @param {Bitmap} bitmap - Bitmap - * @param {Number} x - The X coordinate - * @param {Number} y - The Y coordinate - * @param {Number} radius - Radius of the arc - * @param {Number} startAngle - Starting angle - * @param {Number} endAngle - End angle - * @param {String} [color='white'] - Line color - * @param {Number} [lineWidth=1] - Line width - * @param {Boolean} [anticlockwise=false] - Anticlockwise - * - * @see CanvasRenderingContext2D.arc + * @param {Number} [alpha=1] - The color opacity + * @returns {String} Random color in rgba format */ - static strokeArc(bitmap, x, y, radius, startAngle, endAngle, color, lineWidth, anticlockwise) { - const context = bitmap._context; - context.save(); - context.strokeStyle = color || 'white'; - context.lineWidth = lineWidth || 1; - context.beginPath(); - context.arc(x, y, radius, startAngle, endAngle, anticlockwise); - context.stroke(); - context.restore(); - bitmap._setDirty(); + static getRgbaColor(alpha) { + const r = this.getInt(255); + const g = this.getInt(255); + const b = this.getInt(255); + let a = 1; + + if (alpha !== undefined) { + a = alpha; + } + + return 'rgba(%1, %2, %3, %4)'.format(r, g, b, a); }; /** - * Clones the bitmap + * Returns a random color in hex format * * @static - * @param {Bitmap} bitmap - The bitmap to be cloned - * @returns {Bitmap | null} Cloned bitmap + * @returns {String} Random color in hex format */ - static clone(bitmap) { - if (!bitmap || bitmap.url) { - return bitmap; - } - - const canvas = bitmap.canvas; - const newBitmap = new Bitmap(canvas.width, canvas.height); - const newContext = newBitmap.context; - - newContext.drawImage(canvas, 0, 0); - - return newBitmap; + static getHexColor() { + return '#' + (Math.random() * 0xFFFFFF << 0).toString(16); }; }; @@ -2472,130 +2589,103 @@ DKTools.Utils.Bitmap = class { //=========================================================================== -// DKTools.Utils.Point +// DKTools.Utils.Sequence //=========================================================================== /** - * The static class that defines utility methods for Point class + * The static class that defines the functions for a sequence * - * @class DKTools.Utils.Point - * @memberOf DKTools.Utils + * @class DKTools.Utils.Sequence + * @memberof DKTools.Utils */ -DKTools.Utils.Point = class { +DKTools.Utils.Sequence = class { - /** - * @constructor - * @returns {DKTools.Utils.Point} - */ constructor() { - return DKTools.Utils.Point; + return DKTools.Utils.Sequence; }; /** - * Converts arguments to Point, if possible - * - * @since 2.0.0 - * @static - * - * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} object - The X coordinate or Point or Object with parameters - * @param {Number} [y] - The Y coordinate (if object is Number) - * - * @param {Number} object.x - The X coordinate - * @param {Number} object.y - The Y coordinate + * Generator. Generates a sequence of integers. The number of values is limited by max. * - * @example - * var point = DKTools.Utils.Point.toPoint(0, 0); - * => Point - * - * @example - * var point = DKTools.Utils.Point.toPoint(new Point(0, 0)); - * => Point - * - * @example - * var point = DKTools.Utils.Point.toPoint({ x: 0, y: 0 }); - * => Point - * - * @example - * var point = DKTools.Utils.Point.toPoint(); - * => null + * @param {Number} [max=Number.MAX_SAFE_INTEGER] - Number of sequence elements + * @returns {Number} The next value of the sequence + */ + static *Number(max) { + max = max || Number.MAX_SAFE_INTEGER; + let count = 0; + + while (count <= max) { + yield count++; + } + }; + + /** + * Generator. Generates a sequence of booleans. * - * @returns {Point | null} Point or null + * @param [Boolean} [start=false] - The initial value of the sequence + * @returns {Boolean} The next value of the sequence */ - static toPoint(object, y) { - let pointX, pointY; + static *Boolean(start) { + let value = start || false; - if (object instanceof Object) { - pointX = object.x; - pointY = object.y; - } else { // object - Number - pointX = object; - pointY = y; + while (true) { + value = !value; + yield value; } + }; + +}; - if (DKTools.Utils.Array.isNumberArray([pointX, pointY])) { - return new Point(pointX, pointY); - } - return null; - }; - /** - * Converts the point into an array - * - * @since 2.0.0 - * @static - * - * @param {PIXI.Point | PIXI.ObservablePoint | Point} point - The point to convert - * - * @example - * var point = new Point(0, 0); - * DKTools.Utils.Point.toArray(point); - * => [0, 0] - * - * @returns {Number[]} Array with coordinates - */ - static toArray(point) { - return [point.x, point.y]; + + +//=========================================================================== +// DKTools.Utils.Sequence.Alphabet +//=========================================================================== + +/** + * The static class that defines the functions for a sequence of alphabet + * + * @class DKTools.Utils.Sequence.Alphabet + * @memberof DKTools.Utils.Sequence + */ +DKTools.Utils.Sequence.Alphabet = class { + + constructor() { + return DKTools.Utils.Sequence.Alphabet; }; /** - * Compares the coordinates of the points - * - * @static - * - * @param {PIXI.Point | PIXI.ObservablePoint | Point} point1 - The first point to compare - * @param {PIXI.Point | PIXI.ObservablePoint | Point} point2 - The second point to compare - * - * @example - * var point1 = new Point(0, 0); - * var point2 = new Point(0, 0); - * DKTools.Utils.Point.equals(point1, point2); - * => true - * - * var point1 = new Point(0, 0); - * var point2 = new Point(0, 1); - * DKTools.Utils.Point.equals(point1, point2); - * => false + * Generator. Generates a sequence of characters of the Russian alphabet * - * @returns {Boolean} Comparison result + * @param {Boolean} [upper] - Characters in uppercase + * @returns {String} The next value of the sequence */ - static equals(point1, point2) { - return point1.x === point2.x && point1.y === point2.y; + static *ru(upper) { + let alphabet = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'; + + if (upper) { + alphabet = alphabet.toUpperCase(); + } + + yield* alphabet; }; /** - * Clones the point + * Generator. Generates a sequence of characters of the English alphabet * - * @static - * @param {PIXI.Point | PIXI.ObservablePoint | Point} point - The point to be cloned - * @returns {Point} Cloned point + * @param {Boolean} [upper] - Characters in uppercase + * @returns {String} The next value of the sequence */ - static clone(point) { - const newPoint = new Point(); + static *en(upper) { + let alphabet = 'abcdefghijklmnopqrstuvwxyz'; - newPoint.copy(point); + if (upper) { + alphabet = alphabet.toUpperCase(); + } - return newPoint; + yield* alphabet; }; }; @@ -2605,639 +2695,752 @@ DKTools.Utils.Point = class { //=========================================================================== -// DKTools.Utils.Rectangle +// DKTools.Utils.Event //=========================================================================== /** - * The static class that defines utility methods for Rectangle class + * The static class that defines the functions for an events * - * @class DKTools.Utils.Rectangle - * @memberOf DKTools.Utils + * @class DKTools.Utils.Event + * + * @since 3.0.0 + * @memberof DKTools */ -DKTools.Utils.Rectangle = class { +DKTools.Utils.Event = class { /** - * @constructor - * @returns {DKTools.Utils.Rectangle} + * Returns the comments of the current page + * + * @static + * + * @param {Number | Game_Event} event - Event ID or Game_Event + * + * @returns {String[]} Сomments of the current page */ - constructor() { - return DKTools.Utils.Rectangle; + static getComments(event) { + if (Number.isFinite(event)) { + event = $gameMap.events()[event]; + } + + if (!event) { + return []; + } + + return _.reduce(event.list(), function(comments, command) { + if (command.code === 108 || command.code === 408) { + comments.push(command.parameters[0]); + } + + return comments; + }, []); }; /** - * Converts arguments to Rectangle, if possible - * - * @since 2.0.0 - * @static - * - * @param {Number | PIXI.Rectangle | Rectangle | Object} object - The X coordinate or Object - * @param {Number} [y] - The Y coordinate (if object is Number) - * @param {Number} [width] - The rectangle width (if object is Number) - * @param {Number} [height] - ВThe rectangle height (if object is Number) - * - * @param {Number} object.x - The X coordinate - * @param {Number} object.y - The Y coordinate - * @param {Number} object.width - The rectangle width - * @param {Number} object.height - The rectangle height - * - * @example - * var rect = DKTools.Utils.Rectangle.toRectangle(0, 0, 0, 0); - * => Rectangle + * Returns the comments of the all pages * - * @example - * var rect = DKTools.Utils.Rectangle.toRectangle(new Rectangle(0, 0, 0, 0)); - * => Rectangle + * @static * - * @example - * var rect = DKTools.Utils.Rectangle.toRectangle({ x: 0, y: 0, width: 0, height: 0}); - * => Rectangle + * @param {Number | Game_Event} event - Event ID or Game_Event * - * @example - * var rect = DKTools.Utils.Rectangle.toRectangle(); - * => null - * - * @returns {Rectangle | null} Rectangle or null + * @returns {Object} Сomments of the all pages */ - static toRectangle(object, y, width, height) { - let frameX, frameY, frameWidth, frameHeight; + static getAllComments(event) { + if (Number.isFinite(event)) { + event = $gameMap.events()[event]; + } - if (object instanceof Object) { - frameX = object.x; - frameY = object.y; - frameWidth = object.width; - frameHeight = object.height; - } else { // object - Number - frameX = object; - frameY = y; - frameWidth = width; - frameHeight = height; + if (!event) { + return []; } - if (DKTools.Utils.Array.isNumberArray([frameX, frameY, frameWidth, frameHeight])) { - return new Rectangle(frameX, frameY, frameWidth, frameHeight); + if (event instanceof Game_Event) { + event = event.event(); } - return null; - }; + return _.reduce(event.pages, function(acc, page, index) { + acc[index + 1] = _.reduce(page.list, function(comments, command) { + if (command.code === 108 || command.code === 408) { + comments.push(command.parameters[0]); + } - /** - * Converts the rect into an array - * - * @since 2.0.0 - * @static - * - * @param {PIXI.Rectangle | Rectangle} rect - The rectangle to convert - * - * @example - * var rect = new Rectangle(0, 0, 0, 0); - * DKTools.Utils.Rectangle.toArray(rect); - * => [0, 0, 0, 0] - * - * @returns {Number[]} Array with coordinates, width and height of the rect - */ - static toArray(rect) { - return [rect.x, rect.y, rect.width, rect.height]; + return comments; + }, []); + + return acc; + }, {}); }; - /** - * Compares the coordinates, width and height of the rectangles - * - * @static - * - * @param {PIXI.Rectangle | Rectangle} rect1 - The first rectangle to compare - * @param {PIXI.Rectangle | Rectangle} rect2 - The first rectangle to compare - * - * @example - * var rect1 = new Rectangle(0, 0, 0, 0); - * var rect2 = new Rectangle(0, 0, 0, 0); - * DKTools.Utils.Rectangle.equals(rect1, rect2); - * => true - * - * var rect1 = new Rectangle(0, 0, 0, 0); - * var rect2 = new Rectangle(0, 0, 0, 1); - * DKTools.Utils.Rectangle.equals(rect1, rect2); - * => false - * - * @returns {Boolean} Comparison result - */ - static equals(rect1, rect2) { - return rect1.x === rect2.x && rect1.y === rect2.y && - rect1.width === rect2.width && rect1.height === rect2.height; +}; + + + + + +//=========================================================================== +// DKTools.IO +//=========================================================================== + +/** + * File system class + * + * @class DKTools.IO + * @memberof DKTools + */ +DKTools.IO = class { + + constructor() { + return DKTools.IO; }; + // initialize methods + /** - * Checks whether the rect is empty (0, 0, 0, 0) - * * @static - * @param {PIXI.Rectangle | Rectangle} rect - Rectangle to check - * - * @example - * var rect = new Rectangle(0, 0, 100, 100); - * DKTools.Utils.Rectangle.isEmpty(rect); - * => false - * - * var rect = new Rectangle(0, 0, 0, 0); - * DKTools.Utils.Rectangle.isEmpty(rect); - * => true - * - * @see DKTools.Utils.Rectangle.equals - * - * @returns {Boolean} The rect is empty */ - static isEmpty(rect) { - return this.equals(rect, Rectangle.emptyRectangle); + static initialize() { + if (!this.isLocalMode()) { + return; + } + + /** + * @private + * @readonly + * @type {Object} + */ + this._fs = require('fs'); + + /** + * @private + * @readonly + * @type {Object} + */ + this._path = require('path'); + + const projectPath = this._path.dirname(process.mainModule.filename); + + /** + * @private + * @readonly + * @type {String} + */ + this._projectPath = this._path.join(projectPath, '/'); }; + // is methods + /** - * Clones the rect + * Returns true if local mode is used * * @static - * @param {PIXI.Rectangle | Rectangle} rect - The rect to be cloned - * @returns {Rectangle} Cloned rect + * @returns {Boolean} Local mode is used */ - static clone(rect) { - const newRect = new Rectangle(); - - newRect.copy(rect); - - return newRect; + static isLocalMode() { + return DKTools.Utils.isNwjs(); }; -}; - - - - - -//=========================================================================== -// DKTools.Utils.Random -//=========================================================================== - -/** - * The static class that defines the functions for a random - * - * @class DKTools.Utils.Random - * @memberOf DKTools.Utils - */ -DKTools.Utils.Random = class { - /** - * @constructor - * @returns {DKTools.Utils.Random} + * Returns true if the full path is a file + * + * @version 3.0.0 + * @static + * + * @param {String} fullPath - Path to file + * + * @see DKTools.IO.getAbsolutePath + * @see DKTools.IO.absolutePathExists + * @see FileSystem.lstatSync + * + * @returns {Boolean} Full path is a file */ - constructor() { - return DKTools.Utils.Random; + static isFile(fullPath) { + const absolutePath = this.getAbsolutePath(fullPath); + + if (this.absolutePathExists(absolutePath)) { + return this._fs.lstatSync(absolutePath).isFile(); + } + + return false; }; /** - * Returns a random integer not exceeding max + * Returns true if the full path is a directory * + * @version 3.0.0 * @static - * @param {Number} [max=1] - The maximum value of an integer - * @returns {Number} Random integer not exceeding max + * + * @param {String} fullPath - Path to directory + * + * @see DKTools.IO.getAbsolutePath + * @see DKTools.IO.absolutePathExists + * @see FileSystem.lstatSync + * + * @returns {Boolean} Full path is a directory */ - static getInt(max) { - return _.random(0, max || 1); + static isDirectory(fullPath) { + const absolutePath = this.getAbsolutePath(fullPath); + + if (this.absolutePathExists(absolutePath)) { + return this._fs.lstatSync(absolutePath).isDirectory(); + } + + return false; }; + // other methods + /** - * Returns a random float number not exceeding max + * Returns a normalized path * * @static - * @param {Number} [max=1] - The maximum value of a float number - * @returns {Number} Random float number not exceeding max + * + * @param {String} path - Path for normalize + * + * @see Path.normalize + * + * @returns {String} Normalized path */ - static getFloat(max) { - return _.random(0, max || 1, true); + static normalizePath(path) { + return this._path.normalize(path); }; /** - * Returns a random boolean + * Returns the absolute path to file or directory * + * @since 3.0.0 * @static - * @returns {Boolean} Random boolean + * + * @param {String} [path] - Path + * + * @returns {String} Absolute path to file or directory */ - static getBoolean() { - return this.getInt(1) % 2 === 0; + static getAbsolutePath(path) { + return this.normalizePath(this._path.join(this._projectPath, (path || ''))); }; /** - * Returns a random color in rgba format + * Returns true if the absolute path exists * + * @since 3.0.0 * @static - * @param {Number} [alpha=1] - The color opacity - * @returns {String} Random color in rgba format + * + * @param {String} path - Path + * + * @see FileSystem.existsSync + * + * @returns {Boolean} Absolute path exists */ - static getRgbaColor(alpha) { - const r = this.getInt(255); - const g = this.getInt(255); - const b = this.getInt(255); - let a = 1; - - if (alpha !== undefined) { - a = alpha; - } - - return 'rgba(%1, %2, %3, %4)'.format(r, g, b, a); + static absolutePathExists(path) { + return this._fs.existsSync(path); }; /** - * Returns a random color in hex format + * Returns true if the path exists * + * @version 3.0.0 * @static - * @returns {String} Random color in hex format + * + * @param {String} path - Path + * + * @example + * DKTools.IO.pathExists('img/system/'); // => true + * + * @see DKTools.IO.getAbsolutePath + * @see DKTools.IO.absolutePathExists + * + * @returns {Boolean} Path exists */ - static getHexColor() { - return '#' + (Math.random() * 0xFFFFFF << 0).toString(16); + static pathExists(path) { + return this.absolutePathExists(this.getAbsolutePath(path)); }; }; +// properties - - - -//=========================================================================== -// DKTools.Utils.Sequence -//=========================================================================== - -/** - * The static class that defines the functions for a sequence - * - * @class DKTools.Utils.Sequence - * @memberOf DKTools.Utils - */ -DKTools.Utils.Sequence = class { +Object.defineProperties(DKTools.IO, { /** - * @constructor - * @returns {DKTools.Utils.Sequence} + * File system + * + * @readonly + * @type {FileSystem} + * @memberof DKTools.IO */ - constructor() { - return DKTools.Utils.Sequence; - }; + fs: { + get: function() { + return this._fs; + }, + configurable: true + }, /** - * Generator. Generates a sequence of integers. The number of values is limited by max. + * Path * - * @param {Number} [max=Number.MAX_SAFE_INTEGER] - Number of sequence elements - * @returns {Number} The next value of the sequence + * @readonly + * @type {Path} + * @memberof DKTools.IO */ - static *Number(max) { - max = max || Number.MAX_SAFE_INTEGER; - let count = 0; - - while (count <= max) { - yield count++; - } - }; + path: { + get: function() { + return this._path; + }, + configurable: true + }, /** - * Generator. Generates a sequence of booleans. + * Path to the project folder * - * @param [Boolean} [start=false] - The initial value of the sequence - * @returns {Boolean} The next value of the sequence + * @readonly + * @type {String} + * @memberof DKTools.IO */ - static *Boolean(start) { - let value = start || false; - - while (true) { - value = !value; - yield value; - } - }; - -}; - - - + projectPath: { + get: function() { + return this._projectPath; + }, + configurable: true + }, + /** + * Operation completed successfully + * + * @readonly + * @constant + * @type {Number} + * @memberof DKTools.IO + */ + OK: { value: 0 }, -//=========================================================================== -// DKTools.Utils.Sequence.Alphabet -//=========================================================================== + /** + * Wait until the asynchronous operation calls the callback function + * + * @readonly + * @constant + * @type {Number} + * @memberof DKTools.IO + */ + WAIT_FOR_ASYNC_OPERATION: { value: 1 }, -/** - * The static class that defines the functions for a sequence of alphabet - * - * @class DKTools.Utils.Sequence.Alphabet - * @memberOf DKTools.Utils.Sequence - */ -DKTools.Utils.Sequence.Alphabet = class { + /** + * Platform is not equal to NW.js + * + * @readonly + * @constant + * @type {Number} + * @memberof DKTools.IO + */ + ERROR_NOT_LOCAL_MODE: { value: 2 }, /** - * @constructor - * @returns {DKTools.Utils.Sequence.Alphabet} + * Path does not exist + * + * @readonly + * @constant + * @type {Number} + * @memberof DKTools.IO */ - constructor() { - return DKTools.Utils.Sequence.Alphabet; - }; + ERROR_PATH_DOES_NOT_EXIST: { value: 3 }, /** - * Generator. Generates a sequence of characters of the Russian alphabet + * The callback function is not available for an asynchronous operation * - * @param {Boolean} [upper] - Characters in uppercase - * @returns {String} The next value of the sequence + * @readonly + * @constant + * @type {Number} + * @memberof DKTools.IO */ - static *ru(upper) { - let alphabet = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'; + ERROR_CALLBACK_IS_NOT_AVAILABLE: { value: 4 }, - if (upper) { - alphabet = alphabet.toUpperCase(); - } + /** + * Directory already exists + * + * @readonly + * @constant + * @type {Number} + * @memberof DKTools.IO + */ + ERROR_DIRECTORY_ALREADY_EXISTS: { value: 5 }, - yield* alphabet; - }; + /** + * Directory is not empty + * + * @readonly + * @constant + * @type {Number} + * @memberof DKTools.IO + */ + ERROR_DIRECTORY_IS_NOT_EMPTY: { value: 6 }, /** - * Generator. Generates a sequence of characters of the English alphabet + * A new name is missing or a file with this name already exists * - * @param {Boolean} [upper] - Characters in uppercase - * @returns {String} The next value of the sequence + * @readonly + * @constant + * @type {Number} + * @memberof DKTools.IO */ - static *en(upper) { - let alphabet = 'abcdefghijklmnopqrstuvwxyz'; - - if (upper) { - alphabet = alphabet.toUpperCase(); - } + ERROR_NEW_NAME_IS_NOT_AVAILABLE: { value: 7 }, - yield* alphabet; - }; + /** + * A key is missing + * + * @readonly + * @constant + * @type {Number} + * @memberof DKTools.IO + */ + ERROR_KEY_IS_NOT_AVAILABLE: { value: 8 }, -}; +}); //=========================================================================== -// DKTools.ParameterManager +// DKTools.IO.Entity //=========================================================================== /** - * Class of plugin parameters. Manages plugin parameters (supports all types of parameters) - * - * @class DKTools.ParameterManager - * @constructor - * - * @memberOf DKTools - * - * @param {String} pluginName - Name of the plugin - * @param {Object[]} convertible - Parameters for converting - * + * Abstract class of entity (file or directory) + * + * @class DKTools.IO.Entity + * @memberof DKTools.IO + * * @example - * var params = new DKTools.ParameterManager('DKTools'); + * var file = new DKTools.IO.File('/index.html'); * * @example - * var params = new DKTools.ParameterManager('DKTools', [ - * { - * parameter: paramName, - * property: propertyName - * } - * ]); - * - * @see DKTools.ParameterManager.prototype.initialize - * @see DKTools.ParameterManager.prototype.convertParameters + * var directory = new DKTools.IO.Directory('img/system/'); */ -DKTools.ParameterManager = class { +DKTools.IO.Entity = class { - /** - * @constructor - */ constructor() { this.initialize.apply(this, arguments); }; - // static methods + // initialize /** - * Parse a string (supports escape characters of the RPG Maker 1.5+) + * Initializes the entity * - * @static - * @param {String} string - String to parse - * @returns {Object | String} Parsed string + * @since 3.0.0 + * @override + * + * @param {String} fullPath - Path to file */ - static parse(string) { - try { - return JSON.parse(string, function(key, value) { - try { - return this.parse(value); - } catch (e) { - return value; - } - }.bind(this)); - } catch(e) { - return string; - } + initialize(fullPath) { + const data = DKTools.IO.path.parse(fullPath); + + /** + * @private + * @readonly + * @type {String} + */ + this._path = DKTools.IO.normalizePath(data.dir + '/'); + + /** + * @private + * @readonly + * @type {String} + */ + this._name = data.name; + + /** + * @private + * @readonly + * @type {String} + */ + this._extension = data.ext; }; + // is methods + /** - * @private - * @static + * Returns true if the entity is a file * - * @param {Array} array + * @version 3.0.0 + * @since 2.0.0 * - * @returns {Object} + * @returns {Boolean} Entity is a file */ - static _getConvertedObject(array) { - const converted = {}; - - _.forEach(array, function(value) { - converted[value.Locale] = value.Data; - }); + isFile() { + if (this instanceof DKTools.IO.File) { + return DKTools.IO.isFile(this.getFullPath()); + } - return converted; + return false; }; - // methods - /** - * @param {String} pluginName - Name of the plugin - * @param {Object[]} [convertible] - Parameters for conversion + * Returns true if the entity is a directory * - * @see DKTools.ParameterManager.prototype.convertParameters + * @version 3.0.0 + * @since 2.0.0 + * + * @returns {Boolean} Entity is a directory */ - initialize(pluginName, convertible) { - this._pluginName = pluginName; - this._initialParams = PluginManager.parameters(pluginName); - this._params = {}; - - if (_.isEmpty(this._initialParams)) { - console.warn(`Plugin "${pluginName}" do not have a parameters`); + isDirectory() { + if (this instanceof DKTools.IO.Directory) { + return DKTools.IO.isDirectory(this.getFullPath()); } - this.initializeParams(); - this.initializeLocalization(); - this.convertParameters(convertible); + return false; }; + // get methods + /** - * Initializes plugin parameters + * Returns the path + * + * @since 3.0.0 + * + * @returns {String} Path */ - initializeParams() { - _.forEach(this._initialParams, function(value, key) { - this._params[key] = DKTools.ParameterManager.parse(value); - }.bind(this)); + getPath() { + return this._path; }; /** - * Initializes localization parameters + * Returns the name of the entity without an extension + * + * @since 3.0.0 + * + * @returns {String} Name of the entity without an extension */ - initializeLocalization() { - const localization = this.get('Localization'); + getName() { + return this._name; + }; - if (localization instanceof Object) { - _.forEach(localization, function(value, key) { - if (Array.isArray(value)) { - localization[key] = DKTools.ParameterManager._getConvertedObject(value); - } - }); - } + /** + * Returns the extension of the entity + * + * @since 3.0.0 + * + * @returns {String} Extension of the entity + */ + getExtension() { + return this._extension; }; /** - * Converts a parameters for localization + * Returns the full path * - * @param {Object[]} convertible + * @version 3.0.0 * - * @param {String} convertible.parameter - Name of parameter - * @param {String} convertible.property - Property of parameter + * @returns {String} Full Path */ - convertParameters(convertible) { - _.forEach(convertible, function(object) { - const parameter = object.parameter; - const property = object.property; + getFullPath() { + return DKTools.IO.path.join(this.getPath(), '/', this.getFullName()); + }; - _.forEach(this.get(parameter), function(obj) { - obj[property] = DKTools.ParameterManager._getConvertedObject(obj[property]); - }); - }.bind(this)); + /** + * Returns the full name + * + * @since 3.0.0 + * + * @returns {String} Full name + */ + getFullName() { + return this._name + this._extension; }; /** - * Returns a parameter by its name + * Returns the absolute path * - * @version 1.1.0 + * @since 3.0.0 * - * @param {String} parameterName - Name of parameter - * @param {Number | String | Object} [item] - Index (for an array) or property (for an object) or Object with properties to find - * @param {Object} [options] - Options for finded item (only if item is Object) + * @returns {String} Absolute path + */ + getAbsolutePath() { + return DKTools.IO.getAbsolutePath(this.getFullPath()); + }; + + /** + * Returns a stats * - * @param {String} [options.key] - Key (property) of item - * @param {Number} [options.index] - Index of item + * Returns an object with 2 properties: + * status - Result of an operation + * data - Loaded data (only if the status is equal to DKTools.IO.OK) + * if the status is not equal to DKTools.IO.OK then data will be null * - * @example - * var parameters = new DKTools.ParameterManager('DKTools'); - * var languages = parameters.get('Languages'); + * Possible results: + * DKTools.IO.OK + * DKTools.IO.WAIT_FOR_ASYNC_OPERATION + * DKTools.IO.ERROR_NOT_LOCAL_MODE + * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST + * DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE * - * @example - * var parameters = new DKTools.ParameterManager('DKTools'); - * var language = parameters.get('Languages', { Locale: 'en' }, { key: 'Locale' }); + * @version 3.0.0 + * @since 2.0.0 + * + * @param {Object} [object] - Options of an operation * - * @returns {* | undefined} Parameter by its name or null + * @param {Boolean} [object.sync] - Use synchronous version of stat + * @param {Function} [object.callback] - Callback function upon completion of an operation (only for object.sync == false) + * + * @see FileSystem.stat + * @see FileSystem.statSync + * + * @returns {Object} Loaded stats */ - get(parameterName, item, options) { - if (!DKTools.Utils.isString(parameterName)) { - console.error('Parameter name is not a string!', this._pluginName, parameterName, item, options); - return undefined; + getStats(object) { + if (!DKTools.IO.isLocalMode()) { + return { data: null, status: DKTools.IO.ERROR_NOT_LOCAL_MODE }; } - let param = this._params[parameterName]; + if (!this.exists()) { + return { data: null, status: DKTools.IO.ERROR_PATH_DOES_NOT_EXIST }; + } + + const fs = DKTools.IO.fs; + const absolutePath = this.getAbsolutePath(); + + if (object.sync) { + return { data: fs.statSync(absolutePath), status: DKTools.IO.OK }; + } else { + if (!DKTools.Utils.isFunction(object.callback)) { + return { data: null, status: DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE }; + } - if (param === undefined && parameterName !== 'Localization') { - const localization = this.get('Localization'); + fs.stat(absolutePath, function(error, stats) { + if (error) { + throw error; + } - if (localization) { - param = localization[parameterName]; + object.callback(stats, this); + }); - if (param) { - const locale = DKTools.Localization.locale; - const localizedParam = param[locale]; + return { data: null, status: DKTools.IO.WAIT_FOR_ASYNC_OPERATION }; + } + }; - if (localizedParam === undefined) { - throw new Error('Localized param is undefined for locale: ' + locale); - } + // other methods - param = localizedParam; - } - } + /** + * Returns true if the full path exists + * + * @version 3.0.0 + * + * @returns {Boolean} Full path exists + */ + exists() { + return DKTools.IO.absolutePathExists(this.getAbsolutePath()); + }; + + /** + * Renames the file + * + * Possible results: + * DKTools.IO.OK + * DKTools.IO.WAIT_FOR_ASYNC_OPERATION + * DKTools.IO.ERROR_NOT_LOCAL_MODE + * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST + * DKTools.IO.ERROR_NEW_NAME_IS_NOT_AVAILABLE + * + * @version 3.0.0 + * + * @param {Object} object - Options of an operation + * + * @param {String} object.newName - New name of file + * @param {Boolean} [object.sync] - Use synchronous version of rename + * @param {String | Object} [object.options] - Options for rename or renameSync + * @param {Function} [object.callback] - Callback function upon completion of an operation (only for object.sync == false) + * + * @see FileSystem.rename + * @see FileSystem.renameSync + * + * @returns {Number} Code of the result of an operation + */ + rename(object) { + if (!DKTools.IO.isLocalMode()) { + return DKTools.IO.ERROR_NOT_LOCAL_MODE; } - if (param === undefined) { - return undefined; + if (!object.newName) { + return DKTools.IO.ERROR_NEW_NAME_IS_NOT_AVAILABLE; } - if (item instanceof Object) { - param = _.find(param, item); + if (!this.exists()) { + return DKTools.IO.ERROR_PATH_DOES_NOT_EXIST; + } + + const fs = DKTools.IO.fs; + const newName = object.newName; + const oldAbsolutePath = this.getAbsolutePath(); + const newAbsolutePath = DKTools.IO.getAbsolutePath(this._basePath, newName); + + if (!DKTools.IO.absolutePathExists(newAbsolutePath)) { + if (object.sync) { + fs.renameSync(oldAbsolutePath, newAbsolutePath); + + this._name = newName; - if (param === undefined) { - return undefined; - } + return DKTools.IO.OK; + } else { + fs.rename(oldAbsolutePath, newAbsolutePath, function(error) { + if (error) { + throw error; + } + + this._name = newName; - if (options instanceof Object) { - if (options.key !== undefined) { - param = param[options.key]; - } + object.callback(this); + }.bind(this)); - if (options.index !== undefined) { - param = param[options.index]; - } - } else if (options !== undefined) { // number or string - param = param[options]; + return DKTools.IO.WAIT_FOR_ASYNC_OPERATION; } - - } else if (item !== undefined) { // number or string - param = param[item]; } - return param; + return DKTools.IO.ERROR_NEW_NAME_IS_NOT_AVAILABLE; }; }; // properties -Object.defineProperties(DKTools.ParameterManager.prototype, { +Object.defineProperties(DKTools.IO.Entity.prototype, { /** - * Name of the plugin + * Path of the entity * + * @since 3.0.0 * @readonly * @type {String} - * @memberOf DKTools.ParameterManager.prototype + * @memberof DKTools.IO.Entity.prototype */ - pluginName: { + path: { get: function() { - return this._pluginName; + return this._path; }, configurable: true }, /** - * Parameters obtained using PluginManager.parameters + * Name of the entity * * @readonly - * @type {Object} - * @memberOf DKTools.ParameterManager.prototype + * @type {String} + * @memberof DKTools.IO.Entity.prototype */ - initialParams: { + name: { get: function() { - return this._initialParams; + return this._name; }, configurable: true }, /** - * Parameters of the plugin + * Extension of the entity * + * @since 3.0.0 * @readonly - * @type {Object} - * @memberOf DKTools.ParameterManager.prototype + * @type {String} + * @memberof DKTools.IO.Entity.prototype */ - params: { + extension: { get: function() { - return this._params; + return this._extension; }, configurable: true } @@ -3249,669 +3452,450 @@ Object.defineProperties(DKTools.ParameterManager.prototype, { //=========================================================================== -// initialize parameters -//=========================================================================== - -/** - * @global - * @readonly - * @type {DKTools.ParameterManager} - */ -const DKToolsParam = new DKTools.ParameterManager('DKTools'); - - - - - -//=========================================================================== -// DKTools.PluginManager +// DKTools.IO.File //=========================================================================== /** - * Статический класс, который управляет плагинами + * File class + * + * @class DKTools.IO.File + * @extends DKTools.IO.Entity * - * @class DKTools.PluginManager - * @memberOf DKTools + * @override + * + * @memberof DKTools.IO */ -DKTools.PluginManager = class { - - /** - * @constructor - * @returns {DKTools.PluginManager} - */ - constructor() { - return DKTools.PluginManager; - }; - - // initialize methods - - /** - * Registers a plugins from Imported, which have a version and checks the requirements for the versions of plugins - * - * @static - */ - static initialize() { - this.registerPlugins(Imported); - this._checkRequirements(); - }; - - // _check methods - - /** - * Проверяет требования к версиям плагинов - * - * @private - * @static - */ - static _checkRequirements() { - _.forEach(this._requirements, function(pluginInfo, pluginName) { - const maxVersion = _.max(pluginInfo); - const pluginVersion = this.pluginVersion(pluginName); - - if (pluginVersion === undefined) { - const error = 'Required to install the plugin "%1". Minimal version: %2'.format(pluginName, maxVersion); - throw new Error(error); - } else if (pluginVersion < maxVersion) { - const error = 'Required to update the plugin "%1" to minimal version %2 (Installed: %3)'.format(pluginName, - maxVersion, pluginVersion); - throw new Error(error); - } - }.bind(this)); - }; +DKTools.IO.File = class extends DKTools.IO.Entity { // is methods /** - * Returns true if plugin is registered - * - * @example - * DKTools.PluginManager.isRegistered('DKTools'); // => true + * Returns true if an extension of the file is equal to .ogg or .m4a or .rpgmvo * - * @static - * @param {String} pluginName - Name of plugin - * @returns {Boolean} Plugin is registered + * @version 3.0.0 + * @returns {Boolean} Extension of the file is equal to .ogg or .m4a or .rpgmvo */ - static isRegistered(pluginName) { - return !!this._plugins[pluginName]; + isAudio() { + return this._extension === '.ogg' || this._extension === '.m4a' || this._extension === '.rpgmvo'; }; /** - * Returns true if plugin requirement is registered + * Returns true if an extension of the file is equal to .json * - * @static - * @param {String} pluginName - Name of plugin - * @returns {Boolean} Requirement is registered + * @returns {Boolean} Extension of the file is equal to .json */ - static isRequired(pluginName) { - return !!this._requirements[pluginName]; + isJson() { + return this._extension === '.json'; }; - // register methods - /** - * Registers a plugin + * Returns true if an extension of the file is equal to .png or .rpgmvp * - * @static - * @param {String} pluginName - Name of plugin - * @param {Number | String} version - Version of plugin + * @version 3.0.0 + * @returns {Boolean} Extension of the file is equal to .png or .rpgmvp */ - static registerPlugin(pluginName, version) { - if (!version || this.isRegistered(pluginName) || DKTools.Utils.isBoolean(version)) { - return; - } - - this._plugins[pluginName] = version; + isImage() { + return this._extension === '.png' || this._extension === '.rpgmvp'; }; /** - * Registers a several plugins - * - * @static - * @param {Object[]} plugins - Plugins + * Returns true if an extension of the file is equal to .js * - * @see DKTools.PluginManager.registerPlugin + * @returns {Boolean} Extension of the file is equal to .js */ - static registerPlugins(plugins) { - _.forEach(plugins, function(version, pluginName) { - this.registerPlugin(pluginName, version); - }.bind(this)); + isScript() { + return this._extension === '.js'; }; - // require methods - /** - * Registers a requirement of minimum version of plugin - * - * @example - * DKTools.PluginManager.requirePlugin('DKTools', '2.0.1'); + * Returns true if an extension of the file is equal to .mp4 or .webm * - * @static - * @param {String} pluginName - Name of plugin - * @param {Number | String} minVersion - Minimum version of plguin + * @returns {Boolean} Extension of the file is equal to .mp4 or .webm */ - static requirePlugin(pluginName, minVersion) { - if (!this._requirements[pluginName]) { - this._requirements[pluginName] = []; - } - - this._requirements[pluginName].push(minVersion); + isVideo() { + return this._extension === '.mp4' || this._extension === '.webm'; }; /** - * Registers a several requirements of minimum version of plugins - * - * @static - * @param {Object[]} plugins - Plugins + * Returns true if an extension of the file is equal to .rpgsave * - * @see DKTools.PluginManager.requirePlugin + * @returns {Boolean} Extension of the file is equal to .rpgsave */ - static requirePlugins(plugins) { - _.forEach(plugins, function(version, pluginName) { - this.requirePlugin(pluginName, version); - }.bind(this)); + isSave() { + return this._extension === '.rpgsave'; }; - // other methods + // get methods /** - * Returns a version of plugin - * - * @example - * DKTools.PluginManager.pluginVersion('DKTools'); // => '2.0.1' + * Returns the directory of the file * - * @static - * @param {String | String} pluginName - Name of plugin - * @returns {Number | String | undefined} Version of plugin + * @returns {DKTools.IO.Directory} Directory of the file */ - static pluginVersion(pluginName) { - return this._plugins[pluginName]; + getDirectory() { + return new DKTools.IO.Directory(this._path); }; -}; - -// properties - -Object.defineProperties(DKTools.PluginManager, { + // load methods /** - * List of registered plugins + * Loads a data * - * @private - * @readonly - * @type {Object} - * @memberOf DKTools.PluginManager - */ - _plugins: { - value: {} - }, - - /** - * List of registered requirements + * Returns an object with 2 properties: + * status - Result of an operation + * data - Loaded data (only if the status is equal to DKTools.IO.OK) + * if the status is not equal to DKTools.IO.OK then data will be null * - * @private - * @readonly - * @type {Object} - * @memberOf DKTools.PluginManager - */ - _requirements: { - value: {} - }, - - /** - * List of registered plugins + * Possible results: + * DKTools.IO.OK + * DKTools.IO.WAIT_FOR_ASYNC_OPERATION + * DKTools.IO.ERROR_NOT_LOCAL_MODE + * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST + * DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE * - * @readonly - * @type {Object} - * @memberOf DKTools.PluginManager - */ - plugins: { - get: function() { - return this._plugins; - }, - configurable: true - }, - - /** - * List of registered requirements + * @param {Object} object - Options of an operation * - * @readonly - * @type {Object} - * @memberOf DKTools.PluginManager - */ - requirements: { - get: function() { - return this._requirements; - }, - configurable: true - } + * @param {Boolean} [object.sync] - Use synchronous version of readFile + * @param {String | Object} [object.options] - Options for readFile or readFileSync + * @param {Function} [object.callback] - Callback function upon completion of an operation (only for object.sync == false) + * @param {Boolean} [object.decompress] - Use LZString.decompressFromBase64 for a data + * @param {Boolean} [object.parse] - Use JSON.parse for a data + * + * @see FileSystem.readFile + * @see FileSystem.readFileSync + * + * @returns {Object} Loaded data + */ + load(object) { + if (!DKTools.IO.isLocalMode()) { + return { data: null, status: DKTools.IO.ERROR_NOT_LOCAL_MODE }; + } -}); + if (!this.exists()) { + return { data: null, status: DKTools.IO.ERROR_PATH_DOES_NOT_EXIST }; + } + const fs = DKTools.IO.fs; + const absolutePath = this.getAbsolutePath(); + const options = object.options || { encoding: 'utf8' }; + const processData = function(data) { + if (data) { + if (object.decompress) { + data = LZString.decompressFromBase64(data); + } + if (object.parse) { + data = JSON.parse(data); + } + } + return data; + }; + if (object.sync) { + const data = fs.readFileSync(absolutePath, options); -//=========================================================================== -// DKTools.IO -//=========================================================================== + return { data: processData(data), status: DKTools.IO.OK }; + } else if (DKTools.Utils.isFunction(object.callback)) { + fs.readFile(absolutePath, options, function(error, data) { + if (error) { + throw error; + } -/** - * @class DKTools.IO - * @memberOf DKTools - */ -DKTools.IO = class { + object.callback(processData(data), this); + }); - /** - * @constructor - * @returns {DKTools.IO} - */ - constructor() { - return DKTools.IO; - }; + return { data: null, status: DKTools.IO.WAIT_FOR_ASYNC_OPERATION }; + } - // initialize methods + return {data: null, status: DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE}; + }; /** - * @static + * Loads the audio file + * + * @since 3.0.0 + * @returns {WebAudio | null} Audio file or null */ - static initialize() { - if (this.isLocalMode()) { - - /** - * @private - * @readonly - * @type {Object} - */ - this._fs = require('fs'); - - /** - * @private - * @readonly - * @type {Object} - */ - this._path = require('path'); - - const projectPath = this._path.dirname(process.mainModule.filename); - - /** - * @private - * @readonly - * @type {String} - */ - this._projectPath = this._path.join(projectPath, '/'); + loadAudio() { + if (!this.isAudio() || !this.exists()) { + return null; } - }; - // is methods + return AudioManager.createBuffer(this.getPath(), this.getName()); + }; /** - * Returns true if local mode is used - * - * @static - * @returns {Boolean} Local mode is used + * Loads the JSON file + * + * @since 3.0.0 + * @returns {Object | null} Object or null */ - static isLocalMode() { - return DKTools.Utils.isNwjs(); + loadJson() { + return this.load({ sync: true, parse: true }).data; }; /** - * Returns true if a full path contains the file - * - * @static - * - * @param {String | Object} object - Path to file - * @param {String} [name] - Name of file (only if object is String) - * - * @param {String} [object.basePath] - Path to file - * @param {String} [object.name] - Name of file - * - * @see DKTools.IO.makeFullPath - * @see DKTools.IO.pathExists - * @see FileSystem.lstatSync - * - * @returns {Boolean} Full path contains the file + * Loads and returns a bitmap + * + * @since 3.0.0 + * + * @param {Function | Object} object - + * @param {Number} [hue] - + * @param {Boolean} [smooth] - + * + * @param {Function} [object.listener] - + * @param {Number} [object.hue] - + * @param {Boolean} [object.smooth] - + * + * @returns {Bitmap | null} Bitmap or null */ - static isFile(object, name) { - if (object instanceof Object) { - return this.isFile(object.basePath, object.name); + loadBitmap(object, hue, smooth) { + if (!this.isImage() || !this.exists()) { + return null; } - // object - String (path) - const fs = this._fs; - const fullPath = this.makeFullPath(object, name); - - if (this.pathExists(fullPath)) { - return fs.lstatSync(fullPath).isFile(); + if (object instanceof Object) { + return this.loadBitmap(object.listener, object.hue, object.smooth); } - return false; + return DKTools.Utils.Bitmap.load({ + folder: this.getPath(), + filename: this.getName(), + listener: object, + hue, + smooth + }); }; + // reserve methods + /** - * Returns true if a full path contains the directory - * - * @static - * - * @param {String | Object} object - Path to file - * @param {String} [name] - Name of file (only if object is String) - * - * @param {String} [object.basePath] - Path to directory - * @param {String} [object.name] - Name of directory - * - * @see DKTools.IO.makeFullPath - * @see DKTools.IO.pathExists - * @see FileSystem.lstatSync + * Loads, reserves and returns a bitmap + * + * @since 3.0.0 + * + * @param {Function | Object} object - + * @param {Number} [hue] - + * @param {Boolean} [smooth] - + * @param {Number} [reservationId] - + * + * @param {Function} [object.listener] - + * @param {Number} [object.hue] - + * @param {Boolean} [object.smooth] - + * @param {Number} [object.reservationId] - * - * @returns {Boolean} Full path contains the directory + * @returns {Bitmap | null} Bitmap or null */ - static isDirectory(object, name) { - if (object instanceof Object) { - return this.isFile(object.basePath, object.name); + reserveBitmap(object, hue, smooth, reservationId) { + if (!this.isImage() || !this.exists()) { + return null; } - // object - String (path) - const fs = this._fs; - const fullPath = this.makeFullPath(object, name); - - if (this.pathExists(fullPath)) { - return fs.lstatSync(fullPath).isDirectory(); + if (object instanceof Object) { + return this.reserveBitmap(object.listener, object.hue, object.smooth, object.reservationId); } - return false; + return DKTools.Utils.Bitmap.reserve({ + folder: this.getPath(), + filename: this.getName(), + listener: object, + hue, + smooth, + reservationId + }); }; // other methods /** - * Returns a normalized path - * - * @static + * Saves the data + * Returns a code of the result of an operation * - * @param {String} path - Path for normalize + * Possible results: + * DKTools.IO.OK + * DKTools.IO.WAIT_FOR_ASYNC_OPERATION + * DKTools.IO.ERROR_NOT_LOCAL_MODE + * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST * - * @see Path.normalize + * @version 3.0.0 * - * @returns {String} Normalized path - */ - static normalizePath(path) { - return this._path.normalize(path); - }; - - /** - * Returns a full path to file or directory + * @param {*} data - Data to save + * @param {Object} object - Options of an operation * - * @static + * @param {Boolean} [object.stringify] - Use JSON.stringify for the data + * @param {Boolean} [object.compress] - Use LZString.compressToBase64 for the data + * @param {Boolean} [object.createDirectory] - Create a directory for the file + * @param {Boolean} [object.sync] - Use synchronous version of writeFile + * @param {String | Object} [object.options] - Options for writeFile or writeFileSync + * @param {Function} [object.callback] - Callback function upon completion of an operation (only for object.sync == false) * - * @param {String} [path] - Path to folder where file or directory is stored - * @param {String} [name] - Name of file or directory + * @see FileSystem.writeFile + * @see FileSystem.writeFileSync * - * @returns {String} Full path to file or directory + * @returns {Number} Code of the result of an operation */ - static makeFullPath(path, name) { - return this.normalizePath(this._path.join(this._projectPath, (path || ''), (name || ''))); - }; + save(data, object) { + if (!DKTools.IO.isLocalMode()) { + return DKTools.IO.ERROR_NOT_LOCAL_MODE; + } - /** - * Returns true if the path exists - * - * @static - * - * @param {String} path - Path - * - * @see FileSystem.existsSync - * - * @returns {Boolean} Path exists - */ - static pathExists(path) { - return this._fs.existsSync(path); - }; + const fs = DKTools.IO.fs; + const absolutePath = this.getAbsolutePath(); + const directory = this.getDirectory(); - /** - * Returns true if the path exists - * - * @static - * - * @param {String} path - Path to folder where file or directory is stored - * @param {String} [name] - Name of file or directory - * - * @see DKTools.IO.makeFullPath - * @see DKTools.IO.pathExists - * - * @returns {Boolean} Path exists - */ - static exists(path, name) { - return this.pathExists(this.makeFullPath(path, name)); - }; + object = object || {}; -}; + if (object.stringify) { + data = JSON.stringify(data); + } -// properties + if (object.compress) { + data = LZString.compressToBase64(data); + } -Object.defineProperties(DKTools.IO, { + if (object.createDirectory && !directory.exists()) { + directory.create(); + } - /** - * File system - * - * @readonly - * @type {FileSystem} - * @memberOf DKTools.IO - */ - fs: { - get: function() { - return this._fs; - }, - configurable: true - }, + if (!directory.exists()) { + return DKTools.IO.ERROR_PATH_DOES_NOT_EXIST; + } - /** - * Path - * - * @readonly - * @type {Path} - * @memberOf DKTools.IO - */ - path: { - get: function() { - return this._path; - }, - configurable: true - }, + if (object.sync) { + fs.writeFileSync(absolutePath, data, object.options); - /** - * Path to the project folder - * - * @readonly - * @type {String} - * @memberOf DKTools.IO - */ - projectPath: { - get: function() { - return this._projectPath; - }, - configurable: true - }, + return DKTools.IO.OK; + } else { + const callback = object.callback; - /** - * Operation completed successfully - * - * @readonly - * @constant - * @type {Number} - * @memberOf DKTools.IO - */ - OK: { value: 0 }, + fs.writeFile(absolutePath, data, object.options, function(error) { + if (error) { + throw error; + } + + if (DKTools.Utils.isFunction(callback)) { + callback(this); + } + }.bind(this)); + + return DKTools.IO.WAIT_FOR_ASYNC_OPERATION; + } + }; /** - * Wait until the asynchronous operation calls the callback function + * Removes the file + * Returns a code of the result of an operation + * + * Possible results: + * DKTools.IO.OK + * DKTools.IO.WAIT_FOR_ASYNC_OPERATION + * DKTools.IO.ERROR_NOT_LOCAL_MODE + * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST + * + * @version 3.0.0 + * + * @param {Object} [object] - Options of an operation + * + * @param {Boolean} [object.sync] - Use synchronous version of unlink + * @param {String | Object} [object.options] - Options for unlink or unlinkSync + * @param {Function} [object.callback] - Callback function upon completion of an operation (only for object.sync == false) + * + * @see FileSystem.unlink + * @see FileSystem.unlinkSync * - * @readonly - * @constant - * @type {Number} - * @memberOf DKTools.IO + * @returns {Number} Code of the result of an operation */ - WAIT_FOR_ASYNC_OPERATION: { value: 1 }, + remove(object) { + if (!DKTools.IO.isLocalMode()) { + return DKTools.IO.ERROR_NOT_LOCAL_MODE; + } - /** - * Platform is not equal to NW.js - * - * @readonly - * @constant - * @type {Number} - * @memberOf DKTools.IO - */ - ERROR_NOT_LOCAL_MODE: { value: 2 }, + if (!this.exists()) { + return DKTools.IO.ERROR_PATH_DOES_NOT_EXIST; + } - /** - * Path does not exist - * - * @readonly - * @constant - * @type {Number} - * @memberOf DKTools.IO - */ - ERROR_PATH_DOES_NOT_EXIST: { value: 3 }, + object = object || {}; - /** - * The callback function is not available for an asynchronous operation - * - * @readonly - * @constant - * @type {Number} - * @memberOf DKTools.IO - */ - ERROR_CALLBACK_IS_NOT_AVAILABLE: { value: 4 }, + const fs = DKTools.IO.fs; + const absolutePath = this.getAbsolutePath(); - /** - * Directory already exists - * - * @readonly - * @constant - * @type {Number} - * @memberOf DKTools.IO - */ - ERROR_DIRECTORY_ALREADY_EXISTS: { value: 5 }, + if (object.sync) { + fs.unlinkSync(absolutePath); - /** - * Directory is not empty - * - * @readonly - * @constant - * @type {Number} - * @memberOf DKTools.IO - */ - ERROR_DIRECTORY_IS_NOT_EMPTY: { value: 6 }, + return DKTools.IO.OK; + } else { + const callback = object.callback; - /** - * A new name is missing or a file with this name already exists - * - * @readonly - * @constant - * @type {Number} - * @memberOf DKTools.IO - */ - ERROR_NEW_NAME_IS_NOT_AVAILABLE: { value: 7 }, + fs.unlink(absolutePath, function(error) { + if (error) { + throw error; + } - /** - * A key is missing - * - * @readonly - * @constant - * @type {Number} - * @memberOf DKTools.IO - */ - ERROR_KEY_IS_NOT_AVAILABLE: { value: 8 }, + if (DKTools.Utils.isFunction(callback)) { + callback(this); + } + }.bind(this)); -}); + return DKTools.IO.WAIT_FOR_ASYNC_OPERATION; + } + }; + +}; //=========================================================================== -// DKTools.IO.Entity +// DKTools.IO.Directory //=========================================================================== /** - * @class DKTools.IO.Entity - * @memberOf DKTools.IO + * Directory class + * + * @class DKTools.IO.Directory + * @extends DKTools.IO.Entity + * + * @override + * + * @memberof DKTools.IO */ -DKTools.IO.Entity = class { - - /** - * @constructor - */ - constructor() { - this.initialize.apply(this, arguments); - }; - - // is methods +DKTools.IO.Directory = class extends DKTools.IO.Entity { - /** - * Returns true if the entity is a file - * - * @since 2.0.0 - * @returns {Boolean} Entity is a file - */ - isFile() { - return this instanceof DKTools.IO.File; - }; + // static methods /** - * Returns true if the entity is a directory + * Returns the project directory * - * @since 2.0.0 - * @returns {Boolean} Entity is a directory + * @static + * @returns {DKTools.IO.Directory} Project directory */ - isDirectory() { - return this instanceof DKTools.IO.Directory; + static getRootDirectory() { + return new DKTools.IO.Directory('/'); }; - // get methods - - /** - * Returns a base path - * - * @since 1.1.0 - * - * @returns {String} Base path - */ - getBasePath() { - return this._basePath; - }; + // is methods /** - * Returns a path + * Returns true if the directory does not contain files and other directories * - * @returns {String} Path + * @returns {Boolean} Directory does not contain files and other directories */ - getPath() { - return DKTools.IO.path.join(this._basePath, '/', this._name); - }; + isEmpty() { + const data = this.getAll({ sync: true }).data; - /** - * Returns a full path - * - * @returns {String} Full path - */ - getFullPath() { - return DKTools.IO.makeFullPath(this._basePath, this._name); + return !data || data.length === 0; }; - /** - * Returns a full name - * - * @returns {String} Full name - */ - getFullName() { - return this._name; - }; + // get methods /** - * Returns a stats + * Returns all files and directories * * Returns an object with 2 properties: * status - Result of an operation - * data - Loaded data (only if the status is equal to DKTools.IO.OK) + * data - Array with files and directories (only if the status is equal to DKTools.IO.OK) * if the status is not equal to DKTools.IO.OK then data will be null * * Possible results: @@ -3921,19 +3905,19 @@ DKTools.IO.Entity = class { * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST * DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE * - * @since 2.0.0 - * - * @param {Object} [object] - Options of an operation + * @param {Object} object - Options of an operation * - * @param {Boolean} [object.sync] - Use synchronous version of stat - * @param {Function [object.callback] - Callback function upon completion of an operation (only for object.sync == false) + * @param {Boolean} [object.sync] - Use synchronous version of readdir + * @param {String | Object} [object.options] - Options for readdir or readdirSync + * @param {RegExp} [object.template] - Template for filtering + * @param {Function} [object.callback] - Callback function upon completion of an operation (only for object.sync == false) * - * @see FileSystem.stat - * @see FileSystem.statSync + * @see FileSystem.readdir + * @see FileSystem.readdirSync * - * @returns {Object} Loaded stats + * @returns {Object} All files and directories */ - getStats(object) { + getAll(object) { if (!DKTools.IO.isLocalMode()) { return { data: null, status: DKTools.IO.ERROR_NOT_LOCAL_MODE }; } @@ -3942,276 +3926,275 @@ DKTools.IO.Entity = class { return { data: null, status: DKTools.IO.ERROR_PATH_DOES_NOT_EXIST }; } - object = object || {}; - const fs = DKTools.IO.fs; - const fullPath = this.getFullPath(); + const path = this.getFullPath(); + const absolutePath = this.getAbsolutePath(); + const processData = function(names) { + if (object.template instanceof RegExp) { + names = _.filter(names, function(name) { + return object.template.test(name); + }); + } + + return _.reduce(names, function(acc, name) { + const fullPath = DKTools.IO.normalizePath(path + '/' + name); + + if (DKTools.IO.isFile(fullPath)) { + acc.push(new DKTools.IO.File(fullPath)); + } else if (DKTools.IO.isDirectory(fullPath)) { + acc.push(new DKTools.IO.Directory(fullPath)); + } + + return acc; + }, []); + }; if (object.sync) { - return { data: fs.statSync(fullPath), status: DKTools.IO.OK }; - } else { - if (!DKTools.Utils.isFunction(object.callback)) { - return { data: null, status: DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE }; - } + const names = fs.readdirSync(absolutePath, object.options); - fs.stat(fullPath, function(error, stats) { - if (error) { - throw error; - } + return { data: processData(names) , status: DKTools.IO.OK }; - object.callback(stats); - }); + } else if (DKTools.Utils.isFunction(object.callback)) { + fs.readdir(absolutePath, object.options, function(error, names) { + if (error) { + throw error; + } + + object.callback(processData(names), this); + }.bind(this)); return { data: null, status: DKTools.IO.WAIT_FOR_ASYNC_OPERATION }; } - }; - // other methods + return { data: null, status: DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE }; + }; /** - * Returns true if the full path exists + * Returns all files * - * @returns {Boolean} Full path exists + * Returns an object with 2 properties: + * status - Result of an operation + * data - Array with files (only if the status is equal to DKTools.IO.OK) + * if the status is not equal to DKTools.IO.OK then data will be null + * + * Possible results: + * DKTools.IO.OK + * DKTools.IO.WAIT_FOR_ASYNC_OPERATION + * DKTools.IO.ERROR_NOT_LOCAL_MODE + * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST + * DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE + * + * @param {Object} object - Options of an operation + * + * @param {Boolean} [object.sync] - Use synchronous version of readdir + * @param {String | Object} [object.options] - Options for readdir or readdirSync + * @param {RegExp} [object.template] - Template for filtering + * @param {Function} [object.callback] - Callback function upon completion of an operation (only for object.sync == false) + * + * @see DKTools.IO.Directory.prototype.getAll + * @see FileSystem.readdir + * @see FileSystem.readdirSync + * + * @returns {Object} All files */ - exists() { - return DKTools.IO.pathExists(this.getFullPath()); + getFiles(object) { + const processData = function(entities) { + return _.filter(entities, function(entity) { + return entity.isFile(); + }); + }; + + if (object.sync) { + const result = this.getAll(object); + + if (result.status === DKTools.IO.OK) { + return { data: processData(result.data), status: DKTools.IO.OK }; + } + + return result; + } else if (DKTools.Utils.isFunction(object.callback)) { + const callback = object.callback; + + object.callback = function(data, directory) { + callback(processData(data), directory); + }; + + return this.getAll(object); + } + + return { data: null, status: DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE }; }; /** - * Renames the file + * Returns all directories + * + * Returns an object with 2 properties: + * status - Result of an operation + * data - Array with directories (only if the status is equal to DKTools.IO.OK) + * if the status is not equal to DKTools.IO.OK then data will be null * * Possible results: * DKTools.IO.OK * DKTools.IO.WAIT_FOR_ASYNC_OPERATION * DKTools.IO.ERROR_NOT_LOCAL_MODE * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST - * DKTools.IO.ERROR_NEW_NAME_IS_NOT_AVAILABLE + * DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE * * @param {Object} object - Options of an operation * - * @param {String} object.newName - New name of file - * @param {Boolean} [object.sync] - Use synchronous version of rename - * @param {String | Object} [object.options] - Options for rename or renameSync + * @param {Boolean} [object.sync] - Use synchronous version of readdir + * @param {String | Object} [object.options] - Options for readdir or readdirSync + * @param {RegExp} [object.template] - Template for filtering * @param {Function} [object.callback] - Callback function upon completion of an operation (only for object.sync == false) * - * @see FileSystem.rename - * @see FileSystem.renameSync + * @see DKTools.IO.Directory.prototype.getAll + * @see FileSystem.readdir + * @see FileSystem.readdirSync * - * @returns {Number} Code of the result of an operation + * @returns {Object} All directories */ - rename(object) { - if (!DKTools.IO.isLocalMode()) { - return DKTools.IO.ERROR_NOT_LOCAL_MODE; - } - - if (!object.newName) { - return DKTools.IO.ERROR_NEW_NAME_IS_NOT_AVAILABLE; - } + getDirectories(object) { + const processData = function(entities) { + return _.filter(entities, function(entity) { + return entity.isDirectory(); + }); + }; - if (!this.exists()) { - return DKTools.IO.ERROR_PATH_DOES_NOT_EXIST; - } + if (object.sync) { + const result = this.getAll(object); - const fs = DKTools.IO.fs; - const newName = object.newName; - const oldFullPath = this.getFullPath(); - const newFullPath = DKTools.IO.makeFullPath(this._basePath, newName); + if (result.status === DKTools.IO.OK) { + return { data: processData(result.data), status: DKTools.IO.OK }; + } - if (!DKTools.IO.pathExists(newFullPath)) { - if (object.sync) { - fs.renameSync(oldFullPath, newFullPath); - this._name = newName; + return result; + } else if (DKTools.Utils.isFunction(object.callback)) { + const callback = object.callback; - return DKTools.IO.OK; - } else { - fs.rename(oldFullPath, newFullPath, function(error) { - if (error) { - throw error; - } else { - this._name = newName; - } - object.callback(this); - }.bind(this)); + object.callback = function(data, directory) { + callback(processData(data), directory); + }; - return DKTools.IO.WAIT_FOR_ASYNC_OPERATION; - } + return this.getAll(object); } - return DKTools.IO.ERROR_NEW_NAME_IS_NOT_AVAILABLE; + return { data: null, status: DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE }; }; -}; - -Object.defineProperties(DKTools.IO.Entity.prototype, { - - /** - * @readonly - * @type {String} - * @memberOf DKTools.IO.Entity.prototype - */ - basePath: { - get: function() { - return this._basePath; - }, - configurable: true - }, - - /** - * @readonly - * @type {String} - * @memberOf DKTools.IO.Entity.prototype - */ - name: { - get: function() { - return this._name; - }, - configurable: true - } - -}); - - - - - -//=========================================================================== -// DKTools.IO.File -//=========================================================================== - -/** - * @class DKTools.IO.File - * @extends DKTools.IO.Entity - * - * @override - * @constructor - * - * @memberOf DKTools.IO - */ -DKTools.IO.File = class extends DKTools.IO.Entity { - - // initialize methods - /** - * @override + * Returns all audio files + * + * Returns an object with 2 properties: + * status - Result of an operation + * data - Array with files (only if the status is equal to DKTools.IO.OK) + * if the status is not equal to DKTools.IO.OK then data will be null + * + * Possible results: + * DKTools.IO.OK + * DKTools.IO.WAIT_FOR_ASYNC_OPERATION + * DKTools.IO.ERROR_NOT_LOCAL_MODE + * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST + * DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE + * + * @since 3.0.0 * - * @param {String} path - Path to file - * @param {String} name - Name of file + * @param {Object} object - Options of an operation * - * @example - * var file = new DKTools.IO.File('/', 'index.html'); - */ - initialize(path, name) { - /** - * @private - * @readonly - * @type {String} - */ - this._basePath = DKTools.IO.normalizePath(path + '/'); - - /** - * @private - * @readonly - * @type {String} - */ - this._name = name; + * @param {Boolean} [object.sync] - Use synchronous version of readdir + * @param {String | Object} [object.options] - Options for readdir or readdirSync + * @param {Function} [object.callback] - Callback function upon completion of an operation (only for object.sync == false) + * + * @see DKTools.IO.Directory.prototype.getFiles + * + * @returns {Object} All audio files + */ + getAudioFiles(object) { + return this.getFiles({ + sync: object.sync, + options: object.options, + template: /(.ogg|.m4a|.rpgmvo)/, + callback: object.callback + }); }; - // is methods - /** - * Returns true if an extension of the file is equal to .ogg or .m4a + * Returns all JSON files + * + * Returns an object with 2 properties: + * status - Result of an operation + * data - Array with files (only if the status is equal to DKTools.IO.OK) + * if the status is not equal to DKTools.IO.OK then data will be null + * + * Possible results: + * DKTools.IO.OK + * DKTools.IO.WAIT_FOR_ASYNC_OPERATION + * DKTools.IO.ERROR_NOT_LOCAL_MODE + * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST + * DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE + * + * @since 3.0.0 * - * @returns {Boolean} Extension of the file is equal to .ogg or .m4a - */ - isAudio() { - const extension = this.getExtension(); - return extension === '.ogg' || extension === '.m4a'; - }; - - /** - * Returns true if an extension of the file is equal to .png + * @param {Object} object - Options of an operation * - * @returns {Boolean} Extension of the file is equal to .png - */ - isImage() { - return this.getExtension() === '.png'; - }; - - /** - * Returns true if an extension of the file is equal to .js + * @param {Boolean} [object.sync] - Use synchronous version of readdir + * @param {String | Object} [object.options] - Options for readdir or readdirSync + * @param {Function} [object.callback] - Callback function upon completion of an operation (only for object.sync == false) * - * @returns {Boolean} Extension of the file is equal to .js - */ - isScript() { - return this.getExtension() === '.js'; - }; - - /** - * Returns true if an extension of the file is equal to .mp4 or .webm + * @see DKTools.IO.Directory.prototype.getFiles * - * @returns {Boolean} Extension of the file is equal to .mp4 or .webm + * @returns {Object} All JSON files */ - isVideo() { - const extension = this.getExtension(); - return extension === '.mp4' || extension === '.webm'; + getJsonFiles(object) { + return this.getFiles({ + sync: object.sync, + options: object.options, + template: /(.json)/, + callback: object.callback + }); }; /** - * Returns true if an extension of the file is equal to .rpgsave + * Returns all image files * - * @returns {Boolean} Extension of the file is equal to .rpgsave - */ - isSave() { - return this.getExtension() === '.rpgsave'; - }; - - /** - * Returns true if an extension of the file is equal to .json + * Returns an object with 2 properties: + * status - Result of an operation + * data - Array with files (only if the status is equal to DKTools.IO.OK) + * if the status is not equal to DKTools.IO.OK then data will be null * - * @returns {Boolean} Extension of the file is equal to .json - */ - isJson() { - return this.getExtension() === '.json'; - }; - - // get methods - - /** - * Returns a name of the file without an extension + * Possible results: + * DKTools.IO.OK + * DKTools.IO.WAIT_FOR_ASYNC_OPERATION + * DKTools.IO.ERROR_NOT_LOCAL_MODE + * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST + * DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE * - * @returns {String} Name of the file without an extension - */ - getBaseName() { - return DKTools.IO.path.basename(this.getFullName(), this.getExtension()); - }; - - /** - * Returns an extension of the file + * @since 3.0.0 * - * @returns {String} Extension of the file - */ - getExtension() { - return DKTools.IO.path.extname(this._name); - }; - - /** - * Returns a directory of the file + * @param {Object} object - Options of an operation * - * @returns {DKTools.IO.Directory} Directory of the file + * @param {Boolean} [object.sync] - Use synchronous version of readdir + * @param {String | Object} [object.options] - Options for readdir or readdirSync + * @param {Function} [object.callback] - Callback function upon completion of an operation (only for object.sync == false) + * + * @see DKTools.IO.Directory.prototype.getFiles + * + * @returns {Object} All image files */ - getDirectory() { - const path = DKTools.IO.path.dirname(this._basePath); - return new DKTools.IO.Directory(path, this._basePath); + getImageFiles(object) { + return this.getFiles({ + sync: object.sync, + options: object.options, + template: /(.png|.rpgmvp)/, + callback: object.callback + }); }; - // other methods - /** - * Loads a data + * Returns all video files * * Returns an object with 2 properties: * status - Result of an operation - * data - Loaded data (only if the status is equal to DKTools.IO.OK) + * data - Array with files (only if the status is equal to DKTools.IO.OK) * if the status is not equal to DKTools.IO.OK then data will be null * * Possible results: @@ -4220,144 +4203,158 @@ DKTools.IO.File = class extends DKTools.IO.Entity { * DKTools.IO.ERROR_NOT_LOCAL_MODE * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST * DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE + * + * @since 3.0.0 * * @param {Object} object - Options of an operation * - * @param {Boolean} [object.sync] - Use synchronous version of readFile - * @param {String | Object} [object.options] - Options for readFile or readFileSync + * @param {Boolean} [object.sync] - Use synchronous version of readdir + * @param {String | Object} [object.options] - Options for readdir or readdirSync * @param {Function} [object.callback] - Callback function upon completion of an operation (only for object.sync == false) - * @param {Boolean} [object.decompress] - Use LZString.decompressFromBase64 for a data - * @param {Boolean} [object.parse] - Use JSON.parse for a data * - * @see FileSystem.readFile - * @see FileSystem.readFileSync + * @see DKTools.IO.Directory.prototype.getFiles * - * @returns {Object} Loaded data + * @returns {Object} All video files */ - load(object) { - if (!DKTools.IO.isLocalMode()) { - return { data: null, status: DKTools.IO.ERROR_NOT_LOCAL_MODE }; + getVideoFiles(object) { + return this.getFiles({ + sync: object.sync, + options: object.options, + template: /(.webm|.mp4)/, + callback: object.callback + }); + }; + + // audio methods + + /** + * Loads the audio files + * + * @since 3.0.0 + * + * @see DKTools.IO.Directory.prototype.getAudioFiles + * + * @returns {WebAudio[]} Audio files + */ + loadAudioFiles() { + const result = this.getAudioFiles({ sync: true }); + + if (result.status !== DKTools.IO.OK) { + return []; } - if (!this.exists()) { - return { data: null, status: DKTools.IO.ERROR_PATH_DOES_NOT_EXIST }; + return _.map(result.data, function(file) { + return file.loadAudio(); + }); + }; + + // image methods + + /** + * Loads and returns a bitmaps + * + * @since 3.0.0 + * + * @param {Function | Object} [object] - Function of processing after loading a bitmap or object with parameter + * @param {Number} [hue] - Hue of bitmap (if object is Object) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is Object) + * + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see DKTools.IO.Directory.prototype.getImageFiles + * @see DKTools.Utils.Bitmap.load + * + * @returns {Bitmap[]} Bitmaps + */ + loadBitmaps(object, hue, smooth) { + if (object instanceof Object) { + return this.loadBitmaps(object.listener, object.hue, object.smooth); } - const fs = DKTools.IO.fs; - const fullPath = this.getFullPath(); - const options = object.options || { encoding: 'utf8' }; - let data = null; - - if (object.sync) { - data = fs.readFileSync(fullPath, options); - - if (data) { - if (object.decompress) { - data = LZString.decompressFromBase64(data); - } + const result = this.getImageFiles({ sync: true }); - if (object.parse) { - data = JSON.parse(data); - } - } + if (result.status !== DKTools.IO.OK) { + return []; + } - return { data, status: DKTools.IO.OK }; - } else if (DKTools.Utils.isFunction(object.callback)) { - fs.readFile(fullPath, options, function(error, data) { - if (error) { - throw error; - } + return _.map(result.data, function(file) { + return file.loadBitmap(object, hue, smooth); + }); + }; - if (data) { - if (object.decompress) { - data = LZString.decompressFromBase64(data); - } + /** + * Loads, reserves and returns a bitmaps + * + * @since 3.0.0 + * + * @param {Function | Object} [object] - Function of processing after loading a bitmap or object with parameter + * @param {Number} [hue] - Hue of bitmap (if object is Object) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is Object) + * @param {Number} [reservationId] - Reservation ID (if object is Object) + * + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see DKTools.IO.Directory.prototype.getImageFiles + * @see DKTools.Utils.Bitmap.reserve + * + * @returns {Bitmap[]} + */ + reserveBitmaps(object, hue, smooth, reservationId) { + if (object instanceof Object) { + return this.reserveBitmaps(object.listener, object.hue, object.smooth, object.reservationId); + } - if (object.parse) { - data = JSON.parse(data); - } - } + const result = this.getImageFiles({ sync: true }); - object.callback(data, this); - }); - return { data: null, status: DKTools.IO.WAIT_FOR_ASYNC_OPERATION }; + if (result.status !== DKTools.IO.OK) { + return []; } - return {data: null, status: DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE}; + return _.map(result.data, function(file) { + return file.reserveBitmap(object, hue, smooth, reservationId); + }); }; + // other methods + /** - * Saves the data + * Creates the directory * Returns a code of the result of an operation * * Possible results: * DKTools.IO.OK - * DKTools.IO.WAIT_FOR_ASYNC_OPERATION * DKTools.IO.ERROR_NOT_LOCAL_MODE - * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST - * - * @param {*} data - Data to save - * @param {Object} object - Options of an operation + * DKTools.IO.ERROR_DIRECTORY_ALREADY_EXISTS * - * @param {Boolean} [object.stringify] - Use JSON.stringify for the data - * @param {Boolean} [object.compress] - Use LZString.compressToBase64 for the data - * @param {Boolean} [object.createDirectory] - Create a directory for the file - * @param {Boolean} [object.sync] - Use synchronous version of writeFile - * @param {String | Object} [object.options] - Options for writeFile or writeFileSync - * @param {Function} [object.callback] - Callback function upon completion of an operation (only for object.sync == false) + * @example + * var directory = new DKTools.IO.Directory('/', 'saves/'); + * directory.create(); * - * @see FileSystem.writeFile - * @see FileSystem.writeFileSync + * @see FileSystem.mkdirSync * * @returns {Number} Code of the result of an operation */ - save(data, object) { + create() { if (!DKTools.IO.isLocalMode()) { return DKTools.IO.ERROR_NOT_LOCAL_MODE; } - const fs = DKTools.IO.fs; - const fullPath = this.getFullPath(); - const directory = this.getDirectory(); - - if (object.stringify) { - data = JSON.stringify(data); - } - - if (object.compress) { - data = LZString.compressToBase64(data); - } - - if (object.createDirectory && !directory.exists()) { - directory.create(); - } - - if (!directory.exists()) { - return DKTools.IO.ERROR_PATH_DOES_NOT_EXIST; + if (this.exists()) { + return DKTools.IO.ERROR_DIRECTORY_ALREADY_EXISTS; } - if (object.sync) { - fs.writeFileSync(fullPath, data, object.options); - return DKTools.IO.OK; - } else { - const callback = object.callback; - - fs.writeFile(fullPath, data, object.options, function(error) { - if (error) { - throw error; - } - - if (DKTools.Utils.isFunction(callback)) { - callback(this); - } - }.bind(this)); + DKTools.IO.fs.mkdirSync(this.getAbsolutePath()); - return DKTools.IO.WAIT_FOR_ASYNC_OPERATION; - } + return DKTools.IO.OK; }; /** - * Removes the file + * Removes the directory * Returns a code of the result of an operation * * Possible results: @@ -4365,15 +4362,15 @@ DKTools.IO.File = class extends DKTools.IO.Entity { * DKTools.IO.WAIT_FOR_ASYNC_OPERATION * DKTools.IO.ERROR_NOT_LOCAL_MODE * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST + * DKTools.IO.ERROR_DIRECTORY_IS_NOT_EMPTY * * @param {Object} [object] - Options of an operation * - * @param {Boolean} [object.sync] - Use synchronous version of unlink - * @param {String | Object} [object.options] - Options for unlink or unlinkSync + * @param {Boolean} [object.sync] - Use synchronous version of rmdir * @param {Function} [object.callback] - Callback function upon completion of an operation (only for object.sync == false) * - * @see FileSystem.unlink - * @see FileSystem.unlinkSync + * @see FileSystem.rmdir + * @see FileSystem.rmdirSync * * @returns {Number} Code of the result of an operation */ @@ -4386,23 +4383,27 @@ DKTools.IO.File = class extends DKTools.IO.Entity { return DKTools.IO.ERROR_PATH_DOES_NOT_EXIST; } + if (!this.isEmpty()) { + return DKTools.IO.ERROR_DIRECTORY_IS_NOT_EMPTY; + } + object = object || {}; + const fs = DKTools.IO.fs; - const fullPath = this.getFullPath(); + const absolutePath = this.getAbsolutePath(); if (object.sync) { - fs.unlinkSync(fullPath); + fs.rmdirSync(absolutePath); + return DKTools.IO.OK; } else { - const callback = object.callback; - - fs.unlink(fullPath, function(error) { + fs.rmdir(absolutePath, function(error) { if (error) { throw error; } - if (DKTools.Utils.isFunction(callback)) { - callback(this); + if (DKTools.Utils.isFunction(object.callback)) { + object.callback(this); } }.bind(this)); @@ -4417,985 +4418,1024 @@ DKTools.IO.File = class extends DKTools.IO.Entity { //=========================================================================== -// DKTools.IO.Directory +// DKTools.IO.WebStorage //=========================================================================== /** - * @class DKTools.IO.Directory - * @extends DKTools.IO.Entity - * - * @override - * @constructor - * - * @memberOf DKTools.IO + * Web storage class + * + * @class DKTools.IO.WebStorage + * @memberof DKTools.IO */ -DKTools.IO.Directory = class extends DKTools.IO.Entity { - - // static methods +DKTools.IO.WebStorage = class { /** - * Returns the project directory + * Returns true if the key exists * * @static - * @returns {DKTools.IO.Directory} The project directory - */ - getRootDirectory() { - return new DKTools.IO.Directory('/', '/'); - }; - - // initialize methods - - /** - * @override - * - * @param {String} [path] - Path to directory - * @param {String} [name] - Name of directory - * - * @example - * var directory = new DKTools.IO.Directory('/', 'save/'); - */ - initialize(path, name) { - - /** - * @private - * @readonly - * @type {String} - */ - this._basePath = DKTools.IO.normalizePath((path || '') + '/'); - - /** - * @private - * @readonly - * @type {String} - */ - this._name = DKTools.IO.normalizePath((name || '') + '/'); - }; - - // is methods - - /** - * Returns true if the directory does not contain files and other directories - * - * @returns {Boolean} Directory does not contain files and other directories - */ - isEmpty() { - const data = this.getAll({ sync: true }).data; - return !data || data.length === 0; - }; - - // get methods - - /** - * Returns all files and directories - * - * Returns an object with 2 properties: - * status - Result of an operation - * data - Array with files and directories (only if the status is equal to DKTools.IO.OK) - * if the status is not equal to DKTools.IO.OK then data will be null - * - * Possible results: - * DKTools.IO.OK - * DKTools.IO.WAIT_FOR_ASYNC_OPERATION - * DKTools.IO.ERROR_NOT_LOCAL_MODE - * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST - * DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE - * - * @param {Object} object - Options of an operation - * - * @param {Boolean} [object.sync] - Use synchronous version of readdir - * @param {String | Object} [object.options] - Options for readdir or readdirSync - * @param {Function} [object.callback] - Callback function upon completion of an operation (only for object.sync == false) - * @param {RegExp} [object.template] - Template for filtering - * - * @see FileSystem.readdir - * @see FileSystem.readdirSync - * - * @returns {Object} All files and directories + * @param {String} key - Key + * @returns {Boolean} Key exists */ - getAll(object) { - if (!DKTools.IO.isLocalMode()) { - return { data: null, status: DKTools.IO.ERROR_NOT_LOCAL_MODE }; - } - - if (!this.exists()) { - return { data: null, status: DKTools.IO.ERROR_PATH_DOES_NOT_EXIST }; - } - - const fs = DKTools.IO.fs; - const fullPath = this.getFullPath(); - - if (object.sync) { - let names = fs.readdirSync(fullPath, object.options); - - if (object.template instanceof RegExp) { - names = _.filter(names, function(name) { - return name.match(object.template); - }); - } - - const path = this.getPath(); - const data = _.map(names, function(name) { - if (DKTools.IO.isFile(path, name)) { - return new DKTools.IO.File(path, name); - } else if (DKTools.IO.isDirectory(path, name)) { - return new DKTools.IO.Directory(path, name); - } - - return null; - }); - - return { data: data, status: DKTools.IO.OK }; - - } else if (DKTools.Utils.isFunction(object.callback)) { - fs.readdir(fullPath, object.options, function(error, names) { - if (error) { - throw error; - } - - if (object.template instanceof RegExp) { - names = _.filter(names, function(name) { - return object.template.test(name); - }); - } - - const path = this.getPath(); - const data = _.map(names, function(name) { - if (DKTools.IO.isFile(path, name)) { - return new DKTools.IO.File(path, name); - } else if (DKTools.IO.isDirectory(path, name)) { - return new DKTools.IO.Directory(path, name); - } - - return null; - }); - - object.callback(data, this); - }.bind(this)); - - return { data: null, status: DKTools.IO.WAIT_FOR_ASYNC_OPERATION }; - } - - return { data: null, status: DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE }; + static exists(key) { + return localStorage.hasOwnProperty(key); }; /** - * Returns all files + * Loads a data * * Returns an object with 2 properties: * status - Result of an operation - * data - Array with files and directories (only if the status is equal to DKTools.IO.OK) + * data - Loaded data (only if the status is equal to DKTools.IO.OK) * if the status is not equal to DKTools.IO.OK then data will be null * * Possible results: * DKTools.IO.OK - * DKTools.IO.WAIT_FOR_ASYNC_OPERATION - * DKTools.IO.ERROR_NOT_LOCAL_MODE - * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST - * DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE + * DKTools.IO.ERROR_KEY_IS_NOT_AVAILABLE * - * @param {Object} object - Options of an operation + * @static * - * @param {Boolean} [object.sync] - Use synchronous version of readdir - * @param {String | Object} [object.options] - Options for readdir or readdirSync - * @param {Function} [object.callback] - Callback function upon completion of an operation (only for object.sync == false) - * @param {RegExp} [object.template] - Template for filtering + * @param {String} key - Key + * @param {Object} [options] - Options of an operation * - * @see DKTools.IO.Directory.prototype.getAll - * @see FileSystem.readdir - * @see FileSystem.readdirSync + * @param {Boolean} [options.decompress] - Use LZString.decompressFromBase64 for a data + * @param {Boolean} [options.parse] - Use JSON.parse for a data * - * @returns {Object} All files + * @returns {Object} Loded data */ - getFiles(object) { - if (!DKTools.IO.isLocalMode()) { - return { data: null, status: DKTools.IO.ERROR_NOT_LOCAL_MODE }; + static load(key, options) { + if (!this.exists(key)) { + return { data: null, status: DKTools.IO.ERROR_KEY_IS_NOT_AVAILABLE }; } - if (object.sync) { - const result = this.getAll(object); + options = options || {}; - if (result.status === DKTools.IO.OK) { - const files = _.filter(result.data, function(entity) { - return entity.isFile(); - }); + let data = localStorage.getItem(key); - return { data: files, status: DKTools.IO.OK }; + if (data) { + if (options.decompress) { + data = LZString.decompressFromBase64(data); } - return result; - } else if (DKTools.Utils.isFunction(object.callback)) { - const callback = object.callback; - - object.callback = function(data, directory) { - const files = _.filter(data, function(entity) { - return entity.isFile(); - }); - callback(files, directory); - }; - - return this.getAll(object); + if (options.parse) { + data = JSON.parse(data); + } } - return { data: null, status: DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE }; + return { data, status: DKTools.IO.OK }; }; /** - * Returns all directories - * - * Returns an object with 2 properties: - * status - Result of an operation - * data - Array with files and directories (only if the status is equal to DKTools.IO.OK) - * if the status is not equal to DKTools.IO.OK then data will be null + * Saves the data + * Returns a code of the result of an operation * * Possible results: * DKTools.IO.OK - * DKTools.IO.WAIT_FOR_ASYNC_OPERATION - * DKTools.IO.ERROR_NOT_LOCAL_MODE - * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST - * DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE + * DKTools.IO.ERROR_KEY_IS_NOT_AVAILABLE * - * @param {Object} object - Options of an operation + * @version 3.0.0 + * @static * - * @param {Boolean} [object.sync] - Use synchronous version of readdir - * @param {String | Object} [object.options] - Options for readdir or readdirSync - * @param {Function} [object.callback] - Callback function upon completion of an operation (only for object.sync == false) - * @param {RegExp} [object.template] - Template for filtering + * @param {String} key - Key + * @param {*} data - Data to save + * @param options - Options of an operation * - * @see DKTools.IO.Directory.prototype.getAll - * @see FileSystem.readdir - * @see FileSystem.readdirSync + * @param {Boolean} [options.stringify] - Use JSON.stringify for the data + * @param {Boolean} [options.compress] - Use LZString.compressToBase64 for the data * - * @returns {Object} All directories + * @returns {Number} Code of the result of an operation */ - getDirectories(object) { - if (!DKTools.IO.isLocalMode()) { - return { data: null, status: DKTools.IO.ERROR_NOT_LOCAL_MODE }; + static save(key, data, options) { + if (key == null || key === '') { + return DKTools.IO.ERROR_KEY_IS_NOT_AVAILABLE; } - if (object.sync) { - const result = this.getAll(object); - - if (result.status === DKTools.IO.OK) { - const directories = _.filter(result.data, function(entity) { - return entity.isDirectory(); - }); - - return { data: directories, status: DKTools.IO.OK }; - } + options = options || {}; - return result; - } else if (DKTools.Utils.isFunction(object.callback)) { - const callback = object.callback; - object.callback = function(data, directory) { - const directories = _.filter(data, function(entity) { - return entity.isDirectory(); - }); - callback(directories, directory); - }; + if (options.stringify) { + data = JSON.stringify(data); + } - return this.getAll(object); + if (options.compress) { + data = LZString.compressToBase64(data); } - return { data: null, status: DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE }; - }; + localStorage.setItem(key, data); - // other methods + return DKTools.IO.OK; + }; /** - * Creates the directory + * Removes a data * Returns a code of the result of an operation * * Possible results: * DKTools.IO.OK - * DKTools.IO.ERROR_NOT_LOCAL_MODE - * DKTools.IO.ERROR_DIRECTORY_ALREADY_EXISTS + * DKTools.IO.ERROR_KEY_IS_NOT_AVAILABLE * - * @example - * var directory = new DKTools.IO.Directory('/', 'saves/'); - * directory.create(); + * @static + * @param {String} key - Key + * @returns {Number} Code of the result of an operation + */ + static remove(key) { + if (!this.exists(key)) { + return DKTools.IO.ERROR_KEY_IS_NOT_AVAILABLE; + } + + localStorage.removeItem(key); + + return DKTools.IO.OK; + }; + + /** + * Renames a data + * Returns a code of the result of an operation * - * @see FileSystem.mkdirSync + * Possible results: + * DKTools.IO.OK + * DKTools.IO.ERROR_KEY_IS_NOT_AVAILABLE + * DKTools.IO.ERROR_NEW_NAME_IS_NOT_AVAILABLE * + * @static + * @param {String} oldkey - Old key + * @param {String} newkey - New key * @returns {Number} Code of the result of an operation */ - create() { - if (!DKTools.IO.isLocalMode()) { - return DKTools.IO.ERROR_NOT_LOCAL_MODE; + static rename(oldKey, newKey) { + if (!this.exists(oldKey)) { + return DKTools.IO.ERROR_KEY_IS_NOT_AVAILABLE; } - if (this.exists()) { - return DKTools.IO.ERROR_DIRECTORY_ALREADY_EXISTS; + if (this.exists(newKey) || newKey == null) { + return DKTools.IO.ERROR_NEW_NAME_IS_NOT_AVAILABLE; } - DKTools.IO.fs.mkdirSync(this.getFullPath()); + const data = localStorage.getItem(oldKey); + + localStorage.setItem(newKey, data); + localStorage.removeItem(oldKey); return DKTools.IO.OK; }; +}; + + + + + +//=========================================================================== +// DKTools.ParameterManager +//=========================================================================== + +/** + * Class of plugin parameters + * Manages plugin parameters (supports all types of parameters) + * + * @class DKTools.ParameterManager + * @memberof DKTools + * + * @param {String} pluginName - Name of the plugin + * + * @example + * var params = new DKTools.ParameterManager('DKTools'); + * + * @see DKTools.ParameterManager.prototype.initialize + */ +DKTools.ParameterManager = class { + + constructor() { + this.initialize.apply(this, arguments); + }; + + // static methods + /** - * Removes the directory - * Returns a code of the result of an operation + * Parse a string (supports escape characters of the RPG Maker 1.5+) * - * Possible results: - * DKTools.IO.OK - * DKTools.IO.WAIT_FOR_ASYNC_OPERATION - * DKTools.IO.ERROR_NOT_LOCAL_MODE - * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST - * DKTools.IO.ERROR_DIRECTORY_IS_NOT_EMPTY + * @static + * @param {String} string - String to parse + * @returns {Object | String} Parsed string + */ + static parse(string) { + try { + return JSON.parse(string, function(key, value) { + try { + return this.parse(value); + } catch (e) { + return value; + } + }.bind(this)); + } catch (e) { + return string; + } + }; + + // methods + + /** + * Initializes the manager + * + * @version 3.0.0 + * + * @param {String} pluginName - Name of the plugin + */ + initialize(pluginName) { + /** + * @private + * @readonly + * @type {String} + */ + this._pluginName = pluginName; + + /** + * @private + * @readonly + * @type {Object} + */ + this._initialParams = PluginManager.parameters(pluginName); + + /** + * @private + * @readonly + * @type {Object} + */ + this._params = {}; + + this.initializeParams(); + }; + + /** + * Initializes plugin parameters + */ + initializeParams() { + _.forEach(this._initialParams, function(value, key) { + this._params[key] = DKTools.ParameterManager.parse(value); + }.bind(this)); + }; + + /** + * Returns a parameter by its name * - * @param {Object} [object] - Options of an operation + * @version 3.0.0 * - * @param {Boolean} [object.sync] - Use synchronous version of rmdir - * @param {Function} [object.callback] - Callback function upon completion of an operation (only for object.sync == false) + * @param {String} parameterName - Name of parameter + * @param {Number | String | Object} [item] - Index (for an array) or property (for an object) or object with properties to find + * @param {Object} [options] - Options for finded item * - * @see FileSystem.rmdir - * @see FileSystem.rmdirSync + * @param {String} [options.key] - Key (property) of item + * @param {Number} [options.index] - Index of item * - * @returns {Number} Code of the result of an operation + * @returns {* | undefined} Parameter by its name or undefined */ - remove(object) { - if (!DKTools.IO.isLocalMode()) { - return DKTools.IO.ERROR_NOT_LOCAL_MODE; - } + get(parameterName, item, options) { + if (!DKTools.Utils.isString(parameterName)) { + console.error('Parameter name is not a string!', this._pluginName, parameterName, item, options); - if (!this.exists()) { - return DKTools.IO.ERROR_PATH_DOES_NOT_EXIST; + return undefined; } - if (!this.isEmpty()) { - return DKTools.IO.ERROR_DIRECTORY_IS_NOT_EMPTY; - } + let param = this._params[parameterName]; - object = object || {}; + if (param === undefined) { + return undefined; + } - const fs = DKTools.IO.fs; - const fullPath = this.getFullPath(); + if (item instanceof Object) { + param = _.find(param, item); + } else if (item !== undefined) { // number or string + param = param[item]; + } - if (object.sync) { - fs.rmdirSync(fullPath); - return DKTools.IO.OK; - } else { - fs.rmdir(fullPath, function(error) { - if (error) { - throw error; + if (param instanceof Object) { + if (options instanceof Object) { + if (options.key !== undefined) { + param = param[options.key]; } - if (DKTools.Utils.isFunction(object.callback)) { - object.callback(this); + if (options.index !== undefined) { + param = param[options.index]; } - }.bind(this)); - - return DKTools.IO.WAIT_FOR_ASYNC_OPERATION; + } else if (options !== undefined) { // number or string + param = param[options]; + } } + + return param; }; }; +// properties + +Object.defineProperties(DKTools.ParameterManager.prototype, { + + /** + * Name of the plugin + * + * @readonly + * @type {String} + * @memberof DKTools.ParameterManager.prototype + */ + pluginName: { + get: function() { + return this._pluginName; + }, + configurable: true + }, + + /** + * Parameters obtained using PluginManager.parameters + * + * @readonly + * @type {Object} + * @memberof DKTools.ParameterManager.prototype + */ + initialParams: { + get: function() { + return this._initialParams; + }, + configurable: true + }, + + /** + * Parameters of the plugin + * + * @readonly + * @type {Object} + * @memberof DKTools.ParameterManager.prototype + */ + params: { + get: function() { + return this._params; + }, + configurable: true + } + +}); + //=========================================================================== -// DKTools.IO.WebStorage +// DKTools.PluginManager //=========================================================================== /** - * @class DKTools.IO.WebStorage - * @constructor - * @memberOf DKTools.IO + * Plugin manager class + * + * @class DKTools.PluginManager + * @memberof DKTools */ -DKTools.IO.WebStorage = class { +DKTools.PluginManager = class { + + constructor() { + return DKTools.PluginManager; + }; + + // initialize methods /** - * Returns true if the key exists + * Registers a plugins from Imported, which have a version and checks the requirements for the versions of plugins * * @static - * @param {String} key - Key - * @returns {Boolean} Key exists */ - static exists(key) { - return localStorage.hasOwnProperty(key); + static initialize() { + this.registerPlugins(Imported); + this._checkRequirements(); }; + // _check methods + /** - * Loads a data - * - * Returns an object with 2 properties: - * status - Result of an operation - * data - Loaded data (only if the status is equal to DKTools.IO.OK) - * if the status is not equal to DKTools.IO.OK then data will be null - * - * Possible results: - * DKTools.IO.OK - * DKTools.IO.ERROR_KEY_IS_NOT_AVAILABLE + * Проверяет требования к версиям плагинов * + * @private * @static + */ + static _checkRequirements() { + _.forEach(this._requirements, function(pluginInfo, pluginName) { + const maxVersion = _.max(pluginInfo); + const pluginVersion = this.pluginVersion(pluginName); + + if (pluginVersion === undefined) { + const error = 'Required to install the plugin "%1". Minimal version: %2'.format(pluginName, maxVersion); + throw new Error(error); + } else if (pluginVersion < maxVersion) { + const error = 'Required to update the plugin "%1" to minimal version %2 (Installed: %3)'.format(pluginName, + maxVersion, pluginVersion); + throw new Error(error); + } + }.bind(this)); + }; + + // is methods + + /** + * Returns true if plugin is registered * - * @param {String} key - Key - * @param {Object} [options] - Options of an operation - * - * @param {Boolean} [options.decompress] - Use LZString.decompressFromBase64 for a data - * @param {Boolean} [options.parse] - Use JSON.parse for a data + * @example + * DKTools.PluginManager.isRegistered('DKTools'); // => true * - * @returns {Object} Loded data + * @static + * @param {String} pluginName - Name of plugin + * @returns {Boolean} Plugin is registered */ - static load(key, options) { - if (!this.exists(key)) { - return { data: null, status: DKTools.IO.ERROR_KEY_IS_NOT_AVAILABLE }; - } + static isRegistered(pluginName) { + return !!this._plugins[pluginName]; + }; - options = options || {}; - let data = localStorage.getItem(key); + /** + * Returns true if plugin requirement is registered + * + * @static + * @param {String} pluginName - Name of plugin + * @returns {Boolean} Requirement is registered + */ + static isRequired(pluginName) { + return !!this._requirements[pluginName]; + }; - if (data) { - if (options.decompress) { - data = LZString.decompressFromBase64(data); - } + // register methods - if (options.parse) { - data = JSON.parse(data); - } + /** + * Registers a plugin + * + * @static + * @param {String} pluginName - Name of plugin + * @param {Number | String} version - Version of plugin + */ + static registerPlugin(pluginName, version) { + if (!version || this.isRegistered(pluginName) || DKTools.Utils.isBoolean(version)) { + return; } - return { data: data, status: DKTools.IO.OK }; + this._plugins[pluginName] = version; }; /** - * Saves the data - * Returns a code of the result of an operation - * - * Possible results: - * DKTools.IO.OK - * DKTools.IO.ERROR_KEY_IS_NOT_AVAILABLE + * Registers a several plugins * * @static + * @param {Object[]} plugins - Plugins * - * @param {String} key - Key - * @param {*} data - Data to save - * @param options - Options of an operation - * - * @param {Boolean} [options.stringify] - Use JSON.stringify for the data - * @param {Boolean} [options.compress] - Use LZString.compressToBase64 for the data - * - * @returns {Number} Code of the result of an operation + * @see DKTools.PluginManager.registerPlugin */ - static save(key, data, options) { - if (key == null) { - return DKTools.IO.ERROR_KEY_IS_NOT_AVAILABLE; - } + static registerPlugins(plugins) { + _.forEach(plugins, function(version, pluginName) { + this.registerPlugin(pluginName, version); + }.bind(this)); + }; - options = options || {}; - if (options.stringify) { - data = JSON.stringify(data); - } + // require methods - if (options.compress) { - data = LZString.compressToBase64(data); + /** + * Registers a requirement of minimum version of plugin + * + * @example + * DKTools.PluginManager.requirePlugin('DKTools', '3.0.0'); + * + * @static + * @param {String} pluginName - Name of plugin + * @param {Number | String} minVersion - Minimum version of plguin + */ + static requirePlugin(pluginName, minVersion) { + if (!this._requirements[pluginName]) { + this._requirements[pluginName] = []; } - localStorage.setItem(key, data); + this._requirements[pluginName].push(minVersion); + }; - return DKTools.IO.OK; + /** + * Registers a several requirements of minimum version of plugins + * + * @static + * @param {Object[]} plugins - Plugins + * + * @see DKTools.PluginManager.requirePlugin + */ + static requirePlugins(plugins) { + _.forEach(plugins, function(version, pluginName) { + this.requirePlugin(pluginName, version); + }.bind(this)); }; + // other methods + /** - * Removes a data - * Returns a code of the result of an operation + * Returns a version of plugin * - * Possible results: - * DKTools.IO.OK - * DKTools.IO.ERROR_KEY_IS_NOT_AVAILABLE + * @example + * DKTools.PluginManager.pluginVersion('DKTools'); // => '3.0.0' * * @static - * @param {String} key - Key - * @returns {Number} Code of the result of an operation + * @param {String | String} pluginName - Name of plugin + * @returns {Number | String | undefined} Version of plugin */ - static remove(key) { - if (!this.exists(key)) { - return DKTools.IO.ERROR_KEY_IS_NOT_AVAILABLE; - } + static pluginVersion(pluginName) { + return this._plugins[pluginName]; + }; - localStorage.removeItem(key); +}; - return DKTools.IO.OK; - }; +// properties + +Object.defineProperties(DKTools.PluginManager, { /** - * Renames a data - * Returns a code of the result of an operation - * - * Possible results: - * DKTools.IO.OK - * DKTools.IO.ERROR_KEY_IS_NOT_AVAILABLE - * DKTools.IO.ERROR_NEW_NAME_IS_NOT_AVAILABLE + * List of registered plugins * - * @static - * @param {String} oldkey - Old key - * @param {String} newkey - New key - * @returns {Number} Code of the result of an operation + * @private + * @readonly + * @type {Object} + * @memberof DKTools.PluginManager */ - static rename(oldKey, newKey) { - if (!this.exists(oldKey)) { - return DKTools.IO.ERROR_KEY_IS_NOT_AVAILABLE; - } - - if (this.exists(newKey) || newKey == null) { - return DKTools.IO.ERROR_NEW_NAME_IS_NOT_AVAILABLE; - } + _plugins: { value: {} }, - const data = localStorage.getItem(oldKey); + /** + * List of registered requirements + * + * @private + * @readonly + * @type {Object} + * @memberof DKTools.PluginManager + */ + _requirements: { value: {} }, - localStorage.setItem(newKey, data); - localStorage.removeItem(oldKey); + /** + * List of registered plugins + * + * @readonly + * @type {Object} + * @memberof DKTools.PluginManager + */ + plugins: { + get: function() { + return this._plugins; + }, + configurable: true + }, - return DKTools.IO.OK; - }; + /** + * List of registered requirements + * + * @readonly + * @type {Object} + * @memberof DKTools.PluginManager + */ + requirements: { + get: function() { + return this._requirements; + }, + configurable: true + } -}; +}); //=========================================================================== -// DKTools.Localization +// DKTools.PluginCommandManager //=========================================================================== /** - * Static class of localization + * Plugin command manager class * - * @class DKTools.Localization - * @constructor - * @memberOf DKTools + * @since 3.0.0 + * @class DKTools.PluginCommandManager + * @memberof DKTools */ -DKTools.Localization = class { - - /** - * @constructor - * @returns {DKTools.Localization} - */ +DKTools.PluginCommandManager = class { + constructor() { - return DKTools.Localization; + return DKTools.PluginCommandManager; }; - // static properties - /** - * @private - * @readonly - * @type {String} + * Sets the handler of the plugin command + * + * @static + * + * @param {String} pluginCommand - Name of the command + * @param {Function} handler - Handler of the command */ - static get _localPath() { - return DKToolsParam.get('Local Path'); + static set(pluginCommand, handler) { + this._pluginCommands[pluginCommand.toLowerCase()] = handler; }; /** - * @private - * @readonly - * @type {String} + * Returns true if the command has the handler + * + * @static + * + * @param {String} pluginCommand - Name of the command + * + * @returns {Boolean} Command has the handler */ - static get _localFilename() { - return DKToolsParam.get('Local Filename'); + static has(pluginCommand) { + return !!this._pluginCommands[pluginCommand.toLowerCase()]; }; /** - * @private - * @readonly - * @type {String} + * Processes the handler of the command + * + * @static + * + * @param {Game_Interpreter} gameInterpreter - Interpreter + * @param {String} pluginCommand - Name of the command + * @param {Array} args - Arguments of the command */ - static get _webFilename() { - return DKToolsParam.get('Web Filename'); + static process(gameInterpreter, pluginCommand, args) { + const handler = this._pluginCommands[pluginCommand.toLowerCase()]; + + if (DKTools.Utils.isFunction(handler)) { + handler.call(gameInterpreter, args); + } }; - // initialize methods +}; + +// properties + +Object.defineProperties(DKTools.PluginCommandManager, { /** - * Initializes the Localization class (loads the game locale) + * Plugin commands * - * @static + * @private + * @readonly + * @type {Object} + * @memberof DKTools.PluginCommandManager */ - static initialize() { + _pluginCommands: { value: {} } - /** - * @private - * @readonly - * @type {String} - */ - this._locale = ''; +}); - /** - * @private - * @readonly - * @type {Object} - */ - this._languages = {}; - /** - * @private - * @readonly - * @type {Function[]} - */ - this._listeners = []; - _.forEach(DKToolsParam.get('Languages'), function(object) { - this._languages[object.Locale] = object.Language; - if (object.Primary) { - this._locale = object.Locale; - } - }.bind(this)); - const locales = this.locales; +//=========================================================================== +// DKTools.PreloadManager +//=========================================================================== - if (!DKTools.Utils.Array.isEmpty(locales)) { - this.loadLocale(); +/** + * Preload manager class + * + * @class DKTools.PreloadManager + * + * @since 3.0.0 + * @memberof DKTools + */ +DKTools.PreloadManager = class { - if (!this._locale) { - this._locale = locales[0]; - console.warn('You have not installed the primary language of the game! Automatically selected locale: ' + this._locale); - this.saveLocale(); - } - } else { - this.removeLocale(); - throw new Error('Add at least one language! See help of plugin: 1'); - } + constructor() { + return DKTools.PreloadManager; }; - // _get methods + // initialize methods /** - * @private + * Initializes the manager + * * @static - * @returns {DKTools.IO.File | null} */ - static _getFile() { - if (!DKTools.IO.isLocalMode()) { - return null; + static initialize() { + if (!DKToolsParam.get('Preload Manager', 'Enabled') || !DKTools.IO.isLocalMode()) { + return; } - const path = this._localPath; - const name = this._localFilename; + this.clearCache(); + + _.forEach(DKToolsParam.get('Preload Manager', 'Images'), function(data) { + this.preload({ + path: data.Path, + hue: data.Hue, + caching: data.Caching + }); + }.bind(this)); - return new DKTools.IO.File(path, name); + this.start(); }; - // get methods + // private methods /** - * Returns the previous locale from the list - * + * Logs the message in the console + * + * @private * @static - * @returns {String | null} Previous locale from the list + * + * @param {String} message - Message */ - static getPrevLocale() { - const locales = this.locales; - let index = _.indexOf(locales, this._locale); - - if (index >= 0) { - index--; - - if (index < 0) { - index = locales.length - 1; - } - - return locales[index]; + static _log(message) { + if (!DKToolsParam.get('Preload Manager', 'Enabled') || + !DKToolsParam.get('Preload Manager', 'Debugging') || + !Utils.isOptionValid('test') || !message) { + return; } - return null; + console.log(message); }; /** - * Returns the next locale from the list - * + * Generates a key + * + * @private * @static - * @returns {String | null} Next locale from the list or null + * + * @param {String} path - Path + * @param {Number} [hue=0] - Hue + * + * @see ImageManager._generateCacheKey + * + * @returns {String} Generated key */ - static getNextLocale() { - const locales = this.locales; - let index = _.indexOf(locales, this._locale); - - if (index >= 0) { - index++; - - if (index === locales.length) { - index = 0; - } - - return locales[index]; - } - - return null; + static _generateKey(path, hue) { + return ImageManager._generateCacheKey(path, hue || 0); }; + // clear methods + /** - * Returns the previous language from the list + * Clears the preload queue * * @static - * @returns {String | null} Previous language from the list or null */ - static getPrevLanguage() { - const locale = this.getPrevLocale(); - - if (locale) { - return this._languages[locale]; - } - - return null; + static clearQueue() { + /** + * @private + * @readonly + * @type {Object[]} + */ + this._queue = []; }; /** - * Returns the next language from the list - * + * Clears the cache + * * @static - * @returns {String | null} Next language from the list or null */ - static getNextLanguage() { - const locale = this.getNextLocale(); - - if (locale) { - return this._languages[locale]; - } - - return null; + static clearCache() { + /** + * @private + * @readonly + * @type {Object} + */ + this._cache = {}; }; + // get methods + /** - * Returns the language of the game by the locale of the game - * + * Returns a cached bitmap by key + * * @static - * - * @param {String} locale - Locale - * - * @returns {String | undefined} Language or undefined + * + * @param {String} key - Key of the cached bitmap + * + * @see DKTools.PreloadManager._generateCacheKey + * + * @returns {Bitmap | null} Cached bitmap or null */ - static getLanguageByLocale(locale) { - return this._languages[locale]; + static getCachedBitmapByKey(key) { + return this._cache[key] || null; }; /** - * Returns the locale of the game by the name of the language - * + * Returns a cached bitmap by path + * * @static - * - * @param {String} language - Language - * - * @returns {String | undefined} Locale or undefined + * + * @param {String} path - Path of the cached bitmap + * + * @see DKTools.PreloadManager.getCachedBitmapByKey + * + * @returns {Bitmap | null} Cached bitmap or null */ - static getLocaleByLanguage(language) { - const languages = _.reduce(this._languages, function(acc, value, key) { - acc[value] = key; - return acc; - }, {}); - - return languages[language]; + static getCachedBitmapByPath(path) { + return this.getCachedBitmapByKey(this._generateKey(path)); }; - // other methods + // is methods /** - * Saves the locale + * Returns true if the bitmap is cached by key * * @static + * + * @param {String} key - Key of the cached bitmap + * + * @see DKTools.PreloadManager._generateCacheKey + * + * @returns {Boolean} Bitmap is cached by key */ - static saveLocale() { - if (DKTools.IO.isLocalMode()) { - const file = this._getFile(); - file.save(this._locale, { sync: true }); - } else { - DKTools.IO.WebStorage.save(_webFilename, this._locale); - } + static isCachedByKey(key) { + return !!this._cache[key]; }; /** - * Loads the locale + * Returns true if the bitmap is cached by path * * @static - */ - static loadLocale() { - let locale; - - if (DKTools.IO.isLocalMode()) { - const file = this._getFile(); - - if (file) { - const result = file.load({ sync: true }); - locale = result.data; - } - } else { - const result = DKTools.IO.WebStorage.load(_webFilename); - locale = result.data; - } - - if (this.checkLocale(locale)) { - this._locale = locale; - } else { - this.removeLocale(); - } - }; - - /** - * Removes the locale * - * @static + * @param {String} path - Path of the cached bitmap + * @param {Number} [hue] - Hue + * + * @see DKTools.PreloadManager.isCachedByPath + * + * @returns {Boolean} Bitmap is cached by path */ - static removeLocale() { - if (DKTools.IO.isLocalMode()) { - const file = this._getFile(); - file.remove({ sync: true }); - } else { - DKTools.IO.WebStorage.remove(_webFilename); - } + static isCachedByPath(path, hue) { + return this.isCachedByKey(this._generateKey(path, hue)); }; + // release methods + /** - * Selects the previous locale from the list - * + * Releases the bitmap from a cache by key + * * @static + * + * @param {String} key - Key of the cached bitmap + * + * @see DKTools.PreloadManager._generateCacheKey */ - static selectPrevLocale() { - const locale = this.getPrevLocale(); - - if (locale) { - this._setLocale(locale); - } + static releaseBitmapByKey(key) { + this._cache[key] = null; }; /** - * Selects the next locale from the list + * Releases the bitmap from a cache by path * * @static + * + * @param {String} path - Path of the cached bitmap + * + * @see DKTools.PreloadManager.releaseByKey */ - static selectNextLocale() { - const locale = this.getNextLocale(); - - if (locale) { - this._setLocale(locale); - } + static releaseBitmapByPath(path, hue) { + this.releaseByKey(this._generateKey(path, hue)); }; + // other methods + /** - * Returns true if locale is valid + * Processes the loading of a bitmap * + * @private * @static - * @param {String} locale - Locale - * @returns {Boolean} Locale is valid + * @param {Bitmap} bitmap - Bitmap */ - static checkLocale(locale) { - return DKTools.Utils.Array.contains(this.locales, locale); + static _onBitmapLoad(bitmap) { + this._loaded++; + this._log('Loaded image: ' + bitmap.url); + Graphics.updateLoading(); }; /** - * Sets the game locale - * - * @private + * Adds the object to preload queue + * * @static - * - * @param {String} locale - Locale - * - * @see DKTools.Localization.checkLocale + * + * @param {Object} - Object with parameters + * + * @param {String} object.path - Path to file or directory + * @param {Number} [object.hue] - Hue + * @param {Boolean} [object.caching] - Caching */ - static _setLocale(locale) { - if (this.checkLocale(locale)) { - if (this._locale !== locale) { - const lastLocale = this._locale; - this._locale = locale; - this.saveLocale(); - this._onLocaleChange(lastLocale); + static preload(object) { + if (!DKToolsParam.get('Preload Manager', 'Enabled') || !DKTools.IO.isLocalMode()) { + return; + } + + if (object instanceof Object && DKTools.Utils.isString(object.path)) { + if (DKTools.IO.isDirectory(object.path)) { + const directory = new DKTools.IO.Directory(object.path); + const files = directory.getImageFiles({ sync: true }).data; + + _.forEach(files, function(file) { + this._queue.push({ + path: file.getFullPath(), + hue: object.hue, + caching: object.caching + }); + }.bind(this)); + } else { + this._queue.push(object); } - } else { - throw new Error('You are trying to establish a non-existent locale: ' + locale); } }; /** - * Handles the change of the game locale - * - * @private + * Starts the preloading + * * @static - * @param {String} previousLocale - Previous locale - * - * @see DKTools.Localization.addChangeLocaleListener */ - static _onLocaleChange(previousLocale) { - _.forEach(this._listeners, function(listener) { - listener(previousLocale); - }); + static start() { + this._loaded = 0; + this._skipped = 0; + this._total = this._queue.length; + this._startTime = new Date(); + + if (!DKToolsParam.get('Preload Manager', 'Enabled') || !DKTools.IO.isLocalMode()) { + this._finish(); + return; + } + + this._log('DKTools Preload Manager is running... \n' + + 'Total files to load: ' + this._total); + + const bitmaps = []; + + _.forEach(this._queue, function(data) { + if (DKTools.IO.isFile(data.path)) { + const file = new DKTools.IO.File(data.path); + + if (file.isImage()) { + const fullPath = file.getFullPath(); + + if (this.isCachedByPath(fullPath, data.hue)) { + this._skipped++; + this._log('Image already preloaded: ' + fullPath + '. Skipped...'); + return; + } + + const bitmap = DKTools.Utils.Bitmap.reserve({ + folder: file.getPath(), + filename: file.getName(), + hue: data.hue + }); + + if (bitmap) { + if (data.caching) { + this._cache[this._generateKey(bitmap.url, data.hue)] = bitmap; + } + + bitmaps.push(bitmap); + } else { + this._skipped++; + this._log('Cannot load an image: ' + fullPath + '. Skipped...'); + } + } else { + this._skipped++; + this._log('This is not an image: ' + file.getFullPath() + '. Skipped...'); + } + } else { + this._skipped++; + this._log('This is not a file: ' + data.path + '. Skipped...'); + } + }.bind(this)); + + DKTools.Utils.Bitmap.reserveBitmaps(bitmaps, this._finish.bind(this), this._onBitmapLoad.bind(this)); }; /** - * Adds a listener of change of the game locale + * Finishes the preloading * + * @private * @static - * @param {Function} listener - Listener + * + * @see DKTools.PreloadManager.clearQueue */ - static addChangeLocaleListener(listener) { - this._listeners.push(listener); + static _finish() { + this._finishTime = new Date(); + + this.clearQueue(); + this._log('Preloading complete! \n' + + 'Loaded/Skipped/Total: ' + this._loaded + '/' + this._skipped + '/' + this._total + '\n' + + 'Preloading time: ' + (this._finishTime - this._startTime) / 1000 + ' sec'); }; }; // properties -Object.defineProperties(DKTools.Localization, { - - /** - * Languages of the game - * - * @readonly - * @type {String[]} - * @memberOf DKTools.Localization - */ - languages: { - get: function() { - return Object.values(this._languages); - }, - configurable: true - }, +Object.defineProperties(DKTools.PreloadManager, { /** - * Locales of the game - * + * @private * @readonly - * @type {String[]} - * @memberOf DKTools.Localization - */ - locales: { - get: function() { - return Object.keys(this._languages); - }, - configurable: true - }, - - /** - * Locale of the game - * - * @type {String} - * @memberOf DKTools.Localization + * @type {Object[]} + * @memberof DKTools.PreloadManager */ - locale: { - get: function() { - return this._locale; - }, - set: function(value) { - if (value && this._locale !== value) { - this._setLocale(value); - } - }, - configurable: true + _queue: { + value: [], + writable: true }, /** - * Language of the game - * + * @private * @readonly - * @type {String} - * @memberOf DKTools.Localization + * @type {Object} + * @memberof DKTools.PreloadManager */ - language: { - get: function() { - return this._languages[this._locale]; - }, - configurable: true + _cache: { + value: {}, + writable: true } }); @@ -5412,9 +5452,8 @@ Object.defineProperties(DKTools.Localization, { * Audio file class * * @class DKTools.Audio - * @constructor * - * @memberOf DKTools + * @memberof DKTools * * @param {DKTools.Audio | Object} object - DKTools.Audio or object with parameters * @@ -5431,33 +5470,6 @@ DKTools.Audio = class { this.initialize.apply(this, arguments); }; - // static properties - - /** - * @private - * @readonly - * @type {String} - */ - static get _basePath() { - return AudioManager._basePath || 'audio/'; - }; - - // static methods - - /** - * Returns the extension of the audio file - * - * @static - * @returns {String} Extension of the audio file - */ - static audioFileExt() { - if (WebAudio.canPlayOgg() && !DKTools.Utils.isMobileDevice()) { - return '.ogg'; - } - - return '.m4a'; - }; - // initialize methods /** @@ -5688,8 +5700,12 @@ DKTools.Audio = class { * @private */ _updateBufferParameters() { - const configVolume = AudioManager[this._type + 'Volume']; const buffer = this._buffer; + let configVolume = AudioManager[this._type + 'Volume']; + + if (!Number.isFinite(configVolume)) { + configVolume = 100; + } buffer.volume = configVolume * this._volume / 10000; buffer.pitch = this._pitch / 100; @@ -5700,16 +5716,12 @@ DKTools.Audio = class { * Creates the audio buffer * Returns the created buffer * + * @version 3.0.0 * @private * @returns {WebAudio} Created buffer */ _createBuffer() { - const ext = DKTools.Audio.audioFileExt(); - const folder = this._type; - const name = this._name; - const url = DKTools.Audio._basePath + folder + '/' + encodeURIComponent(name) + ext; - - return new WebAudio(url); + return AudioManager.createBuffer(this._type, this._name); }; /** @@ -5747,7 +5759,7 @@ Object.defineProperties(DKTools.Audio.prototype, { * * @readonly * @type {String} - * @memberOf DKTools.Audio.prototype + * @memberof DKTools.Audio.prototype */ type: { get: function() { @@ -5761,7 +5773,7 @@ Object.defineProperties(DKTools.Audio.prototype, { * * @readonly * @type {String} - * @memberOf DKTools.Audio.prototype + * @memberof DKTools.Audio.prototype */ name: { get: function() { @@ -5774,7 +5786,7 @@ Object.defineProperties(DKTools.Audio.prototype, { * Volume of the audio file * * @type {Number} - * @memberOf DKTools.Audio.prototype + * @memberof DKTools.Audio.prototype */ volume: { get: function() { @@ -5794,7 +5806,7 @@ Object.defineProperties(DKTools.Audio.prototype, { * Pitch of the audio file * * @type {Number} - * @memberOf DKTools.Audio.prototype + * @memberof DKTools.Audio.prototype */ pitch: { get: function() { @@ -5813,7 +5825,7 @@ Object.defineProperties(DKTools.Audio.prototype, { * Panorama of the audio file * * @type {Number} - * @memberOf DKTools.Audio.prototype + * @memberof DKTools.Audio.prototype */ pan: { get: function() { @@ -5833,7 +5845,7 @@ Object.defineProperties(DKTools.Audio.prototype, { * * @readonly * @type {Boolean} - * @memberOf DKTools.Audio.prototype + * @memberof DKTools.Audio.prototype */ loop: { get: function() { @@ -5847,7 +5859,7 @@ Object.defineProperties(DKTools.Audio.prototype, { * * @readonly * @type {WebAudio} - * @memberOf DKTools.Audio.prototype + * @memberof DKTools.Audio.prototype */ buffer: { get: function() { @@ -5860,7 +5872,7 @@ Object.defineProperties(DKTools.Audio.prototype, { * Current position of the audio file * * @type {Number} - * @memberOf DKTools.Audio.prototype + * @memberof DKTools.Audio.prototype */ pos: { get: function() { @@ -5886,9 +5898,8 @@ Object.defineProperties(DKTools.Audio.prototype, { * Event class * * @class DKTools.Event - * @constructor * - * @memberOf DKTools + * @memberof DKTools * * @param {Object} [object] - Parameters * @@ -5916,6 +5927,8 @@ DKTools.Event = class { // initialize methods /** + * Initializes the event + * * @param {Object} [object] - Parameters * * @param {DKTools.Sprite | DKTools.Window | *} [object.target] - Target of the event @@ -6322,21 +6335,21 @@ DKTools.Event = class { }; /** - * Returns true if the event has the on failure handler + * Returns true if the event has the on success handler * - * @returns {Boolean} Event has the on failure handler + * @returns {Boolean} Event has the on success handler */ - hasonFailHandler() { - return !!this._onFail; + hasOnSuccessHandler() { + return !!this._onSuccess; }; /** - * Returns true if the event has the on success handler + * Returns true if the event has the on failure handler * - * @returns {Boolean} Event has the on success handler + * @returns {Boolean} Event has the on failure handler */ - hasOnSuccessHandler() { - return !!this._onSuccess; + hasonFailHandler() { + return !!this._onFail; }; // set methods @@ -6672,7 +6685,7 @@ Object.defineProperties(DKTools.Event.prototype, { * * @readonly * @type {DKTools.Sprite | DKTools.Window | *} - * @memberOf DKTools.Event.prototype + * @memberof DKTools.Event.prototype */ target: { get: function() { @@ -6686,7 +6699,7 @@ Object.defineProperties(DKTools.Event.prototype, { * * @readonly * @type {String} - * @memberOf DKTools.Event.prototype + * @memberof DKTools.Event.prototype */ type: { get: function() { @@ -6700,7 +6713,7 @@ Object.defineProperties(DKTools.Event.prototype, { * * @readonly * @type {Number} - * @memberOf DKTools.Event.prototype + * @memberof DKTools.Event.prototype */ repeatTime: { get: function() { @@ -6714,7 +6727,7 @@ Object.defineProperties(DKTools.Event.prototype, { * * @readonly * @type {Number} - * @memberOf DKTools.Event.prototype + * @memberof DKTools.Event.prototype */ repeats: { get: function() { @@ -6727,7 +6740,7 @@ Object.defineProperties(DKTools.Event.prototype, { * Remaining time of current repeat * * @type {Number} - * @memberOf DKTools.Event.prototype + * @memberof DKTools.Event.prototype */ remainingTime: { get: function() { @@ -6743,7 +6756,7 @@ Object.defineProperties(DKTools.Event.prototype, { * Remaining amount of repeats * * @type {Number} - * @memberOf DKTools.Event.prototype + * @memberof DKTools.Event.prototype */ remainingRepeats: { get: function() { @@ -6759,7 +6772,7 @@ Object.defineProperties(DKTools.Event.prototype, { * Remaining time of pause * * @type {Number} - * @memberOf DKTools.Event.prototype + * @memberof DKTools.Event.prototype */ remainingPauseTime: { get: function() { @@ -6776,7 +6789,7 @@ Object.defineProperties(DKTools.Event.prototype, { * * @readonly * @type {Function} - * @memberOf DKTools.Event.prototype + * @memberof DKTools.Event.prototype */ onStart: { get: function() { @@ -6790,7 +6803,7 @@ Object.defineProperties(DKTools.Event.prototype, { * * @readonly * @type {Function} - * @memberOf DKTools.Event.prototype + * @memberof DKTools.Event.prototype */ onUpdate: { get: function() { @@ -6804,7 +6817,7 @@ Object.defineProperties(DKTools.Event.prototype, { * * @readonly * @type {Function} - * @memberOf DKTools.Event.prototype + * @memberof DKTools.Event.prototype */ onPause: { get: function() { @@ -6818,7 +6831,7 @@ Object.defineProperties(DKTools.Event.prototype, { * * @readonly * @type {Function} - * @memberOf DKTools.Event.prototype + * @memberof DKTools.Event.prototype */ onReset: { get: function() { @@ -6832,7 +6845,7 @@ Object.defineProperties(DKTools.Event.prototype, { * * @readonly * @type {Function} - * @memberOf DKTools.Event.prototype + * @memberof DKTools.Event.prototype */ onRepeat: { get: function() { @@ -6846,7 +6859,7 @@ Object.defineProperties(DKTools.Event.prototype, { * * @readonly * @type {Function} - * @memberOf DKTools.Event.prototype + * @memberof DKTools.Event.prototype */ onSuccess: { get: function() { @@ -6860,7 +6873,7 @@ Object.defineProperties(DKTools.Event.prototype, { * * @readonly * @type {Function} - * @memberOf DKTools.Event.prototype + * @memberof DKTools.Event.prototype */ onFail: { get: function() { @@ -6887,9 +6900,8 @@ Object.defineProperties(DKTools.Event.prototype, { * @extends DKTools.Event * * @override - * @constructor * - * @memberOf DKTools + * @memberof DKTools * * @param {DKTools.Animation | Object} object - Animation or object with parameters * @@ -6913,7 +6925,7 @@ DKTools.Animation = class extends DKTools.Event { */ this._actions = []; - super.initialize.call(this, object); + DKTools.Event.prototype.initialize.call(this, object); }; // _can methods @@ -6959,7 +6971,7 @@ DKTools.Animation = class extends DKTools.Event { * @returns {Boolean} Animation if finished */ isFinished() { - return super.isFinished.call(this) || !this.hasActions(); + return DKTools.Event.prototype.isFinished.call(this) || !this.hasActions(); }; /** @@ -7002,7 +7014,7 @@ DKTools.Animation = class extends DKTools.Event { */ reset() { this.resetActions(); - super.reset.call(this); + DKTools.Event.prototype.reset.call(this); }; /** @@ -7012,7 +7024,7 @@ DKTools.Animation = class extends DKTools.Event { */ repeat() { this.repeatActions(); - super.repeat.call(this); + DKTools.Event.prototype.repeat.call(this); }; /** @@ -7101,7 +7113,7 @@ DKTools.Animation = class extends DKTools.Event { */ _update() { this._updateActions(); - super._update.call(this); + DKTools.Event.prototype._update.call(this); }; }; @@ -7115,7 +7127,7 @@ Object.defineProperties(DKTools.Animation.prototype, { * * @readonly * @type {Array} - * @memberOf DKTools.Animation.prototype + * @memberof DKTools.Animation.prototype */ actions: { get: function() { @@ -7135,13 +7147,12 @@ Object.defineProperties(DKTools.Animation.prototype, { //=========================================================================== /** - * Action class + * Animation action class * * @class DKTools.Animation.Action * @extends DKTools.Event * * @override - * @constructor * * @param {DKTools.Animation.Action | Object} object - Action or object with parameters * @@ -7616,7 +7627,7 @@ DKTools.Animation.Action = class extends DKTools.Event { */ this._data = object.data; - super.initialize.call(this, object); + DKTools.Event.prototype.initialize.call(this, object); }; // set methods @@ -7714,7 +7725,7 @@ Object.defineProperties(DKTools.Animation.Action.prototype, { * * @readonly * @type {DKTools.Animation} - * @memberOf DKTools.Animation.Action.prototype + * @memberof DKTools.Animation.Action.prototype */ animation: { get: function() { @@ -7727,7 +7738,7 @@ Object.defineProperties(DKTools.Animation.Action.prototype, { * Start time of the action * * @type {Number} - * @memberOf DKTools.Animation.Action.prototype + * @memberof DKTools.Animation.Action.prototype */ startTime: { get: function() { @@ -7743,7 +7754,7 @@ Object.defineProperties(DKTools.Animation.Action.prototype, { * End time of the action * * @type {Number} - * @memberOf DKTools.Animation.Action.prototype + * @memberof DKTools.Animation.Action.prototype */ endTime: { get: function() { @@ -7760,7 +7771,7 @@ Object.defineProperties(DKTools.Animation.Action.prototype, { * * @readonly * @type {*} - * @memberOf DKTools.Animation.Action.prototype + * @memberof DKTools.Animation.Action.prototype */ data: { get: function() { @@ -7780,22 +7791,17 @@ Object.defineProperties(DKTools.Animation.Action.prototype, { //=========================================================================== /** - * Option Manager class + * Option manager class * * @class DKTools.OptionManager * * @since 2.0.0 - * @memberOf DKTools + * @memberof DKTools * * @see DKTools.OptionManager.prototype.initialize */ DKTools.OptionManager = class { - /** - * @constructor - * - * @see DKTools.OptionManager.prototype.initialize - */ constructor() { this.initialize.apply(this, arguments); }; @@ -8098,7 +8104,7 @@ Object.defineProperties(DKTools.OptionManager, { * * @readonly * @type {String[]} - * @memberOf DKTools.OptionManager.prototype + * @memberof DKTools.OptionManager.prototype */ options: { get: function() { @@ -8118,22 +8124,17 @@ Object.defineProperties(DKTools.OptionManager, { //=========================================================================== /** - * Event Manager class + * Event manager class * * @class DKTools.EventManager * * @since 2.0.0 - * @memberOf DKTools + * @memberof DKTools * * @see DKTools.EventManager.prototype.initialize */ DKTools.EventManager = class { - /** - * @constructor - * - * @see DKTools.EventManager.prototype.initialize - */ constructor() { this.initialize.apply(this, arguments); }; @@ -8584,7 +8585,7 @@ Object.defineProperties(DKTools.EventManager, { * * @readonly * @type {Object} - * @memberOf DKTools.EventManager.prototype + * @memberof DKTools.EventManager.prototype */ events: { get: function() { @@ -8609,23 +8610,12 @@ Object.defineProperties(DKTools.EventManager, { * @class DKTools.Unit * * @since 2.0.0 - * @memberOf DKTools + * @memberof DKTools * * @see DKTools.Unit.prototype.initialize */ DKTools.Unit = class { - /** - * @constructor - * - * @param {DKTools.Unit | Object} [object={}] - Parameters - * - * @param {DKTools.Unit | Number} object.source - * @param {Number} [object.percents=100] - * @param {Function} [object.getValueHandler] - * - * @see DKTools.Unit.prototype.initialize - */ constructor(object) { this.initialize.apply(this, arguments); }; @@ -8919,7 +8909,7 @@ Object.defineProperties(DKTools.Unit.prototype, { * * @readonly * @type {DKTools.Unit | Number} - * @memberOf DKTools.Unit.prototype + * @memberof DKTools.Unit.prototype */ source: { get: function() { @@ -8933,7 +8923,7 @@ Object.defineProperties(DKTools.Unit.prototype, { * * @readonly * @type {Function | Number} - * @memberOf DKTools.Unit.prototype + * @memberof DKTools.Unit.prototype */ percents: { get: function() { @@ -8947,7 +8937,7 @@ Object.defineProperties(DKTools.Unit.prototype, { * * @readonly * @type {Function} - * @memberOf DKTools.Unit.prototype + * @memberof DKTools.Unit.prototype */ getValueHandler: { get: function() { @@ -8971,7 +8961,7 @@ Object.defineProperties(DKTools.Unit.prototype, { * @extends DKTools.Unit * * @since 2.0.0 - * @memberOf DKTools + * @memberof DKTools * * @see DKTools.Unit.Property.prototype.initialize */ @@ -8991,7 +8981,7 @@ DKTools.Unit.Property = class extends DKTools.Unit { initialize(object) { object = object || {}; - super.initialize.call(this, object); + DKTools.Unit.prototype.initialize.call(this, object); this.setProperty(object.property); }; @@ -9218,7 +9208,7 @@ Object.defineProperties(DKTools.Unit.Property.prototype, { * * @readonly * @type {String} - * @memberOf DKTools.Unit.Property.prototype + * @memberof DKTools.Unit.Property.prototype */ property: { get: function() { @@ -9242,7 +9232,7 @@ Object.defineProperties(DKTools.Unit.Property.prototype, { * @extends DKTools.Unit * * @since 2.0.0 - * @memberOf DKTools + * @memberof DKTools * * @see DKTools.Unit.Properties.initialize */ @@ -9262,7 +9252,7 @@ DKTools.Unit.Properties = class extends DKTools.Unit { initialize(object) { object = object || {}; - super.initialize.call(this, object); + DKTools.Unit.prototype.initialize.call(this, object); this.setProperties(object.properties); }; @@ -9595,7 +9585,7 @@ Object.defineProperties(DKTools.Unit.Properties.prototype, { * * @readonly * @type {Function | String[]} - * @memberOf DKTools.Unit.Properties.prototype + * @memberof DKTools.Unit.Properties.prototype */ properties: { get: function() { @@ -9619,7 +9609,7 @@ Object.defineProperties(DKTools.Unit.Properties.prototype, { * @extends DKTools.Unit * * @since 2.0.0 - * @memberOf DKTools + * @memberof DKTools * * @see DKTools.Unit.Function.initialize */ @@ -9697,26 +9687,23 @@ DKTools.Unit.Function = class extends DKTools.Unit { * * @class DKTools.Base * - * @memberOf DKTools + * @memberof DKTools * - * @param {Number | Rectangle | Object} [object] - The X coordinate or Rectangle or Object with parameters - * @param {Number} [y] - The Y coordinate - * @param {Number} [width] - Width - * @param {Number} [height] - Height + * @param {Number | Graphics | Object | *} [object] - The X coordinate or Graphics or object with parameters + * @param {Number} [y] - The Y coordinate (if object is Number) + * @param {Number} [width] - The width of the object (if object is Number) + * @param {Number} [height] -The height of the object (if object is Number) * * @param {Number} [object.x] - The X coordinate * @param {Number} [object.y] - The Y coordinate - * @param {Number} [object.width] - Width - * @param {Number} [object.height] - Height + * @param {Number} [object.width] - The width of the object + * @param {Number} [object.height] - The height of the object * + * @see DKTools.Base.prototype.initialize * @see DKTools.Base.prototype.setupAll */ DKTools.Base = class { - - /** - * @constructor - * @throws {Error} - */ + constructor() { throw new Error('This is a static class!'); }; @@ -9834,6 +9821,7 @@ DKTools.Base = class { /** * Clears time of mouse enter inside the object * + * @since 2.0.0 * @private */ _clearMouseEnterTime() { @@ -9851,7 +9839,7 @@ DKTools.Base = class { * Clears a rectangle * Returns true if bitmap exists * - * @param {Number | PIXI.Rectangle | Rectangle | Object} [object] - The X coordinate или Rectangle, или Объект типа {} + * @param {Number | PIXI.Rectangle | Rectangle | Object} [object] - The X coordinate or Rectangle or object with parameters * @param {Number} [y] - The Y coordinate * @param {Number} [width] - Width of the rectangle * @param {Number} [height] - Height of the rectangle @@ -9885,6 +9873,9 @@ DKTools.Base = class { * Clears a line in the bitmap * * @param {Number} line - Line to clear + * + * @see DKTools.Base.prototype.getLineRect + * @see DKTools.Base.prototype.clearRect */ clearLine(line) { this.clearRect(this.getLineRect(line)); @@ -9894,6 +9885,8 @@ DKTools.Base = class { * Clears the bitmap * Returns true if bitmap exists * + * @see DKTools.Base.prototype.clearRect + * * @returns {Boolean} Bitmap exists */ clear() { @@ -9921,6 +9914,8 @@ DKTools.Base = class { * * @since 2.0.0 * @private + * + * @see DKTools.OptionManager */ _createOptionManager() { /** @@ -9936,6 +9931,8 @@ DKTools.Base = class { * * @since 2.0.0 * @private + * + * @see DKTools.EventManager */ _createEventManager() { /** @@ -9952,6 +9949,10 @@ DKTools.Base = class { * Sets all data * * @private + * + * @see DKTools.Base.prototype._setupOptions + * @see DKTools.Base.prototype._setupEvents + * @see DKTools.Base.prototype._setupAnimations */ _setupAll() { this._setupOptions(); @@ -10197,7 +10198,7 @@ DKTools.Base = class { * Sets the scale of the object * * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object] - Scale of the object on X axis or object width parameters - * @param {Number} [y] - Scale of the object on Y axis + * @param {Number} [y] - Scale of the object on Y axis (if object is Number) * * @param {Number} [object.x] - Scale of the object on X axis * @param {Number} [object.y] - Scale of the object on Y axis @@ -10216,7 +10217,7 @@ DKTools.Base = class { * Sets the pivot of the object * * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object] - Pivot of the object on X axis or object with parameters - * @param {Number} [y] - Pivot of the object on Y axis + * @param {Number} [y] - Pivot of the object on Y axis (if object is Number) * * @param {Number} [object.x] - Pivot of the object on X axis * @param {Number} [object.y] - Pivot of the object on Y axis @@ -10235,7 +10236,7 @@ DKTools.Base = class { * Sets the skew of the object * * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object] - Skew of the object on X axis or object with parameters - * @param {Number} [y] - Skew of the object on Y axis + * @param {Number} [y] - Skew of the object on Y axis (if object is Number) * * @param {Number} [object.x] - Skew of the object on X axis * @param {Number} [object.y] - Skew of the object on Y axis @@ -10412,7 +10413,7 @@ DKTools.Base = class { * Returns true if the change occurred * * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object] - Scale of the object on X axis or object with parameters - * @param {Number} [y] - Scale of the object on Y axis + * @param {Number} [y] - Scale of the object on Y axis (if object is Number) * * @param {Number} [object.x] - Scale of the object on X axis * @param {Number} [object.y] - Scale of the object on Y axis @@ -10442,7 +10443,7 @@ DKTools.Base = class { * Returns true if the change occurred * * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object] - Pivot of the object on X axis or object with parameters - * @param {Number} [y] - Pivot of the object on Y axis + * @param {Number} [y] - Pivot of the object on Y axis (if object is Number) * * @param {Number} [object.x] - Pivot of the object on X axis * @param {Number} [object.y] - Pivot of the object on Y axis @@ -10472,7 +10473,7 @@ DKTools.Base = class { * Returns true if the change occurred * * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object] - Skew of the object on X axis or object with parameters - * @param {Number} [y] - Skew of the object on Y axis + * @param {Number} [y] - Skew of the object on Y axis (if object is Number) * * @param {Number} [object.x] - Skew of the object on X axis * @param {Number} [object.y] - Skew of the object on Y axis @@ -10639,13 +10640,17 @@ DKTools.Base = class { * Returns the normalized width of the object * * @private + * * @param {Number} width - Width of the object + * + * @see DKTools.Base.prototype.getMinWidth + * * @returns {Number} Normalized width of the object - * */ _checkWidth(width) { const minWidth = this.getMinWidth(); - return (width ? Math.max(minWidth, width) : minWidth); + + return width ? Math.max(minWidth, width) : minWidth; }; /** @@ -10653,13 +10658,17 @@ DKTools.Base = class { * Returns the normalized height of the object * * @private + * * @param {Number} height - Height of the object + * + * @see DKTools.Base.prototype.getMinHeight + * * @returns {Number} Normalized height of the object - * */ _checkHeight(height) { const minHeight = this.getMinHeight(); - return (height ? Math.max(minHeight, height) : minHeight); + + return height ? Math.max(minHeight, height) : minHeight; }; // check methods @@ -10668,6 +10677,9 @@ DKTools.Base = class { * Checks all * * @version 1.1.0 + * + * @see DKTools.Base.prototype.updateCheckAllEvents + * @see DKTools.Base.prototype.checkSize */ checkAll() { this.updateCheckAllEvents(); @@ -10714,7 +10726,10 @@ DKTools.Base = class { * * @version 1.1.0 * + * @see DKTools.Base.prototype.updateAll * @see DKTools.Base.prototype.canRedrawAll + * @see DKTools.Base.prototype.redrawAll + * @see DKTools.Base.prototype.updateRefreshAllEvents */ refreshAll() { this.updateAll(); @@ -10744,7 +10759,7 @@ DKTools.Base = class { * @returns {* | undefined} Child object */ getChildById(id) { - return _.find(this.children, { id: id }); + return _.find(this.children, { id }); }; /** @@ -10782,6 +10797,7 @@ DKTools.Base = class { return 0; } + text = String(text); options = options || {}; try { @@ -10792,14 +10808,6 @@ DKTools.Base = class { } catch(e) { } - try { - options.blockStart = false; - const clone = this.clone(options); - - return clone.drawTextEx(text, options); - } catch(e) { - } - return 0; }; @@ -10809,7 +10817,12 @@ DKTools.Base = class { * @param {String} text - Text * @param {Object} [options] - Options for drawing * - * @see DKTools.Base.prototype.drawTextEx + * @param {Number} [options.wrap.maxWidth] - Max width of a text line + * @param {Number} [options.wrap.maxLines] - Max lines + * @param {Boolean} [options.wrap.breakWords] - Breaks a words for the wrapping + * + * @see DKTools.Base.prototype.textWrap + * @see DKTools.Base.prototype.calcTextHeight * * @returns {Number} Height of the text */ @@ -10818,19 +10831,24 @@ DKTools.Base = class { return 0; } + text = String(text); options = options || {}; if (options.wrap) { text = this.textWrap(text, options.wrap); } - return this.calcTextHeight({ text: text, index: 0 }, true); + return this.calcTextHeight({ text, index: 0 }, true); }; /** * Returns the color from the windowskin * * @param {Number} n - Color number + * + * @see DKTools.Base.prototype.hasWindowskin + * @see DKTools.Base.prototype.standardWindowskin + * * @returns {String} Color from the windowskin */ getWindowskinTextColor(n) { @@ -10841,6 +10859,7 @@ DKTools.Base = class { return this.windowskin.getPixel(px, py); } else { const windowskin = ImageManager.loadSystem(this.standardWindowskin()); + return windowskin.getPixel(px, py); } }; @@ -10849,6 +10868,10 @@ DKTools.Base = class { * Returns the font height for the line height * * @param {Number} lineHeight - Line height + * + * @see DKTools.Base.prototype.getLineHeight + * @see DKTools.Base.prototype.hasBitmap + * * @returns {Number} Font height for the line height */ getFontHeight(lineHeight) { @@ -10925,6 +10948,8 @@ DKTools.Base = class { /** * Returns the maximum of lines * + * @see DKTools.Base.prototype.getLineHeight + * * @returns {Number} Maximum of lines */ getLines() { @@ -10935,8 +10960,12 @@ DKTools.Base = class { * Returns the number of lines of the text * * @param {String | Number} text - Text - * @param {Object} [wrap=undefined] - Wrap options + * @param {Object} [wrap] - Wrap options * + * @param {Number} [wrap.maxWidth] - Max width of a text line + * @param {Number} [wrap.maxLines] - Max lines + * @param {Boolean} [wrap.breakWords] - Breaks a words for the wrapping + * * @see DKTools.Base.prototype.textWrap * * @returns {Number} Number of lines of the text @@ -10945,6 +10974,7 @@ DKTools.Base = class { if (wrap) { text = this.textWrap(text, wrap); } + return text.split('\n').length; }; @@ -10954,6 +10984,10 @@ DKTools.Base = class { * @param {String | Number} text - Text * @param {Object} [wrap] - Wrap options * + * @param {Number} [wrap.maxWidth] - Max width of a text line + * @param {Number} [wrap.maxLines] - Max lines + * @param {Boolean} [wrap.breakWords] - Breaks a words for the wrapping + * * @see DKTools.Base.prototype.getTextLines * @see DKTools.Base.prototype.getLineHeight * @@ -10967,10 +11001,14 @@ DKTools.Base = class { * Returns a rectangle of the line * * @param {Number | String} line - Line number + * + * @see DKTools.Base.prototype.getLineHeight + * * @returns {Rectangle} Rectangle of the line */ getLineRect(line) { const lineHeight = this.getLineHeight(); + return new Rectangle(0, lineHeight * Number(line), this.realWidth, lineHeight); }; @@ -10978,6 +11016,9 @@ DKTools.Base = class { /** * Activates the object + * + * @see DKTools.Base.prototype.setActive + * @see DKTools.Base.prototype.updateActivateEvents */ activate() { if (this.setActive(true)) { @@ -10987,6 +11028,9 @@ DKTools.Base = class { /** * Deactivates the object + * + * @see DKTools.Base.prototype.setActive + * @see DKTools.Base.prototype.updateDeactivateEvents */ deactivate() { if (this.setActive(false)) { @@ -10999,30 +11043,40 @@ DKTools.Base = class { /** * Shows the object * + * @version 3.0.0 * @param {Boolean} [activate=false] - Activates the object + * + * @see DKTools.Base.prototype.setVisible + * @see DKTools.Base.prototype.updateShowEvents + * @see DKTools.Base.prototype.activate */ show(activate) { if (this.setVisible(true)) { this.updateShowEvents(); + } - if (activate) { - this.activate(); - } + if (activate) { + this.activate(); } }; /** * Hides the object * + * @version 3.0.0 * @param {Boolean} [blockDeactivate] - Blocking deactivates of the object + * + * @see DKTools.Base.prototype.setVisible + * @see DKTools.Base.prototype.updateHideEvents + * @see DKTools.Base.prototype.deactivate */ hide(blockDeactivate) { if (this.setVisible(false)) { this.updateHideEvents(); + } - if (!blockDeactivate) { - this.deactivate(); - } + if (!blockDeactivate) { + this.deactivate(); } }; @@ -11074,6 +11128,9 @@ DKTools.Base = class { * Returns true if the object can be updated and redrawn * * @since 1.1.0 + * + * @see DKTools.Base.prototype.hasBitmap + * * @returns {Boolean} Object can be updated and redrawn */ canRedrawAll() { @@ -11252,8 +11309,11 @@ DKTools.Base = class { }; /** - * ВReturns true if the object is visible and active + * Returns true if the object is visible and active * + * @see DKTools.Base.prototype.isVisible + * @see DKTools.Base.prototype.isActive + * * @returns {Boolean} Object is visible and active */ isVisibleAndActive() { @@ -11272,6 +11332,8 @@ DKTools.Base = class { /** * Returns true if the bitmap is ready * + * @see DKTools.Base.prototype.hasBitmap + * * @returns {Boolean} Bitmap is ready */ isReady() { @@ -11281,6 +11343,8 @@ DKTools.Base = class { /** * Returns true if the object is busy * + * @see DKTools.Base.prototype.isReady + * * @returns {Boolean} Object is busy */ isBusy() { @@ -11368,6 +11432,8 @@ DKTools.Base = class { * @param {Number} x - The X coordinate * @param {Number} y - The Y coordinate * + * @see DKTools.Base.prototype.isInside + * * @returns {Boolean} Coordinates are not inside the object */ isOutside(x, y) { @@ -11377,6 +11443,8 @@ DKTools.Base = class { /** * Returns true if the mouse is inside the object * + * @see DKTools.Base.prototype.isInside + * * @returns {Boolean} Mouse is inside the object */ isMouseInside() { @@ -11423,7 +11491,7 @@ DKTools.Base = class { * @param {Object} [options={}] - Options for drawing * * @param {Object} [options.wrap] - Options for text wrap - * @param {PIXI.Point | PIXI.ObservablePoint | Point | Object} [object.pos=undefined] - Position of the text + * @param {PIXI.Point | PIXI.ObservablePoint | Point | Object} [object.pos] - Position of the text * @param {Number} [options.x=0] - The X coordinate (if object.pos is undefined or null) * @param {Number | String} [options.y=0] - The Y coordinate or line number (String) (if object.pos is undefined or null) * @@ -11434,7 +11502,11 @@ DKTools.Base = class { * @param {Number} [object.pos.x=0] - The X coordinate * @param {Number | String} [object.pos.y=0] - The Y coordinate or line number (String) * + * @see DKTools.Base.prototype.hasBitmap * @see DKTools.Base.prototype.textWrap + * @see DKTools.Base.prototype.convertEscapeCharacters + * @see DKTools.Base.prototype.calcTextHeight + * @see DKTools.Base.prototype.processCharacter * * @returns {Number} Width of the text */ @@ -11495,6 +11567,8 @@ DKTools.Base = class { * @param {String} [object.color='white'] - Line color * @param {Number} [object.lineWidth=1] - Line width * + * @see DKTools.Base.prototype.hasBitmap + * * @returns {Boolean} Bitmap exists */ drawLine(object, y1, x2, y2, color, lineWidth) { @@ -11524,6 +11598,8 @@ DKTools.Base = class { * @param {Number} [object.x=0] - The X coordinate * @param {Number} [object.y=0] - The Y coordinate * + * @see DKTools.Base.prototype.hasBitmap + * * @returns {Boolean} Bitmap exists */ drawCircle(color, radius, object, y) { @@ -11568,6 +11644,24 @@ DKTools.Base = class { * @param {Number} [options.destination.width] - Width of the rectangle * @param {Number} [options.destination.height] - Height of the rectangle * + * @example + * Drawing half of the bitmap + * + * var sprite = new DKTools.Sprite(0, 0, 200, 200); + * sprite.start(); + * + * sprite.drawBitmap({ folder: 'img/system/', filename: 'Window' }, { + * callback: function(bitmap, sprite) { // loaded bitmap, sprite + * return { + * source: { + * width: bitmap.width / 2, + * height: bitmap.height / 2 + * } + * } + * } + * }); + * + * @see DKTools.Base.prototype.hasBitmap * @see DKTools.Utils.Bitmap.load * * @returns {Boolean} Bitmap exists @@ -11588,7 +11682,8 @@ DKTools.Base = class { let source, destination; if (DKTools.Utils.isFunction(options.callback)) { - const result = options.callback(bitmap, this); + const result = options.callback(bitmap, this) || {}; + source = result.source; destination = result.destination; } @@ -11639,6 +11734,8 @@ DKTools.Base = class { * @param {Number} [object.x=0] - The X coordinate * @param {Number} [object.y=0] - The Y coordinate * + * @see DKTools.Base.prototype.hasBitmap + * * @returns {Boolean} Bitmap exists */ drawIcon(iconIndex, object, y) { @@ -11676,6 +11773,8 @@ DKTools.Base = class { * @param {Number} [object.y=0] - The Y coordinate * @param {Number} [object.width=Window_Base._faceWidth] - Width of the face * @param {Number} [object.height=Window_Base._faceHeight] - Height of the face + * + * @see DKTools.Base.prototype.hasBitmap * * @returns {Boolean} Bitmap exists */ @@ -11718,6 +11817,8 @@ DKTools.Base = class { * @param {Number} [object.x=0] - The X coordinate * @param {Number} [object.y=0] - The Y coordinate * + * @see DKTools.Base.prototype.hasBitmap + * * @returns {Boolean} Bitmap exists */ drawCharacter(characterName, characterIndex, object, y) { @@ -11744,15 +11845,23 @@ DKTools.Base = class { /** * Draws the name of the item + * Returns true if bitmap exists * + * @version 3.0.0 + * * @param {Object} item - Item * @param {Number} [x=0] - The X coordinate * @param {Number} [y=0] - The Y coordinate * @param {Number} [width=312] - Width of the name + * + * @see DKTools.Base.prototype.drawIcon + * @see DKTools.Base.prototype.drawText + * + * @returns {Boolean} Bitmap exists */ drawItemName(item, x, y, width) { - if (!item) { - return; + if (!this.hasBitmap()) { + return false; } const iconBoxWidth = Window_Base._iconWidth + 4; @@ -11767,6 +11876,8 @@ DKTools.Base = class { width: width || 312 - iconBoxWidth, align: 'left' }); + + return true; }; // fill methods @@ -11778,7 +11889,7 @@ DKTools.Base = class { * @param {Object} [object={}] - Parameters for drawing * * @param {String} [object.color='white'] - Fill color - * @param {PIXI.Rectangle | Rectangle | Object | null} [object.rect=undefined] - Rectangle for drawing + * @param {PIXI.Rectangle | Rectangle | Object} [object.rect] - Rectangle for drawing * @param {Number} [object.x=0] - The X coordinate (if object.rect is undefined or null) * @param {Number} [object.y=0] - The Y coordinate (if object.rect is undefined or null) * @param {Number} [object.width=this.standardDrawingWidth()] - Width of the rectangle (if object.rect is undefined or null) @@ -11789,6 +11900,9 @@ DKTools.Base = class { * @param {Number} [object.rect.width] - Width of the rectangle * @param {Number} [object.rect.height] - Height of the rectangle * + * @see DKTools.Base.prototype.hasBitmap + * @see DKTools.Base.prototype.standardDrawingWidth + * @see DKTools.Base.prototype.standardDrawingHeight * @see Bitmap.prototype.fillRect * * @returns {Boolean} Bitmap exists @@ -11812,7 +11926,12 @@ DKTools.Base = class { height = object.height; } - this.bitmap.fillRect(x || 0, y || 0, width || this.standardDrawingWidth(), height || this.standardDrawingHeight(), object.color); + x = x || 0; + y = y || 0; + width = width || this.standardDrawingWidth(); + height = height || this.standardDrawingHeight(); + + this.bitmap.fillRect(x, y, width, height, object.color); return true; }; @@ -11842,13 +11961,14 @@ DKTools.Base = class { * @param {Number} [object.endAngle=Math.PI*2] - End angle * @param {String} [object.color='white'] - Fill color * @param {Boolean} [object.anticlockwise=false] - Draws an anticlockwise - * @param {PIXI.Point | PIXI.ObservablePoint | Point | Object | null) [object.pos=undefined] - Position of the arc + * @param {PIXI.Point | PIXI.ObservablePoint | Point | Object} [object.pos] - Position of the arc * @param {Number} [object.x=0] - The X coordinate (if object.pos is undefined or null) * @param {Number} [object.y=0] - The Y coordinate (if object.pos is undefined or null) * * @param {Number} [object.pos.x=0] - The X coordinate * @param {Number} [object.pos.y=0] - The Y coordinate * + * @see DKTools.Base.prototype.hasBitmap * @see DKTools.Utils.Bitmap.fillArc * * @returns {Boolean} Bitmap exists @@ -11890,7 +12010,7 @@ DKTools.Base = class { * * @param {String} [object.color='white'] - Fill color * @param {Number} [object.lineWidth=1] - Line width - * @param {PIXI.Rectangle | Rectangle | Object | null} [object.rect=undefined] - Rectangle for drawing + * @param {PIXI.Rectangle | Rectangle | Object} [object.rect] - Rectangle for drawing * @param {Number} [object.x=0] - The X coordinate (if object.rect is undefined or null) * @param {Number} [object.y=0] - The Y coordinate (if object.rect is undefined or null) * @param {Number} [object.width=this.standardDrawingWidth()] - Width of the rectangle (if object.rect is undefined or null) @@ -11901,6 +12021,9 @@ DKTools.Base = class { * @param {Number} [object.rect.width] - Width of the rectangle * @param {Number} [object.rect.height] - Height of the rectangle * + * @see DKTools.Base.prototype.hasBitmap + * @see DKTools.Base.prototype.standardDrawingWidth + * @see DKTools.Base.prototype.standardDrawingHeight * @see DKTools.Utils.Bitmap.strokeRect * * @returns {Boolean} Bitmap exists @@ -11924,7 +12047,12 @@ DKTools.Base = class { height = object.height; } - DKTools.Utils.Bitmap.strokeRect(this.bitmap, x || 0, y || 0, width || this.standardDrawingWidth(), height || this.standardDrawingHeight(), object.color, object.lineWidth); + x = x || 0; + y = y || 0; + width = width || this.standardDrawingWidth(); + height = height || this.standardDrawingHeight(); + + DKTools.Utils.Bitmap.strokeRect(this.bitmap, x, y, width, height, object.color, object.lineWidth); return true; }; @@ -11941,13 +12069,14 @@ DKTools.Base = class { * @param {String} [object.color='white'] - Line color * @param {Number} [object.lineWidth=1] - Line width * @param {Boolean} [object.anticlockwise=false] - Draws an anticlockwise - * @param {PIXI.Point | PIXI.ObservablePoint | Point | Object | null) [object.pos=undefined] - Position of arc + * @param {PIXI.Point | PIXI.ObservablePoint | Point | Object} [object.pos] - Position of arc * @param {Number} [object.x=0] - The X coordinate (if object.pos is undefined or null) * @param {Number} [object.y=0] - The Y coordinate (if object.pos is undefined or null) * * @param {Number} [object.pos.x=0] - The X coordinate * @param {Number} [object.pos.y=0] - The Y coordinate * + * @see DKTools.Base.prototype.hasBitmap * @see DKTools.Utils.Bitmap.strokeArc * * @returns {Boolean} Bitmap exists @@ -11967,7 +12096,7 @@ DKTools.Base = class { const anticlockwise = object.anticlockwise || false; let x, y; - if (object.pos) { + if (object.pos instanceof Object) { x = object.pos.x; y = object.pos.y; } else { @@ -11993,18 +12122,17 @@ DKTools.Base = class { * @param {Number | String} [object.y=0] - The Y coordinate or line number (String) * @param {Number | String} [object.width=this.standardDrawingWidth()] - Width of the rectangle * @param {Number | String} [object.height=this.standardDrawingHeight()] - Height of the rectangle or number of lines (String) - * @param {PIXI.Rectangle | Rectangle | Object | null} [object.rect=undefined] - Rectangle for drawing (ignores other parameters of position: x, y, width, height) + * @param {PIXI.Rectangle | Rectangle | Object} [object.rect] - Rectangle for drawing (ignores other parameters of position: x, y, width, height) * * @param {Number | String} [object.rect.x=0] - The X coordinate * @param {Number | String} [object.rect.y=0] - The Y coordinate or line number (String) * @param {Number | String} [object.rect.width=this.standardDrawingWidth()] - Width of the rectangle * @param {Number | String} [object.rect.height=this.standardDrawingHeight()] - Height of the rectangle or number of lines (String) * + * @see DKTools.Base.prototype.hasBitmap + * @see DKTools.Base.prototype.standardDrawingWidth + * @see DKTools.Base.prototype.standardDrawingHeight * @see Bitmap.prototype.gradientFillRect - * @see DKTools.Base.prototype.getConvertedX - * @see DKTools.Base.prototype.getConvertedY - * @see DKTools.Base.prototype.getConvertedWidth - * @see DKTools.Base.prototype.getConvertedHeight * * @returns {Boolean} Bitmap exists */ @@ -12029,10 +12157,10 @@ DKTools.Base = class { height = object.height; } - x = this.getConvertedX(x) || 0; - y = this.getConvertedY(y) || 0; - width = this.getConvertedWidth(width) || this.standardDrawingWidth(); - height = this.getConvertedHeight(height) || this.standardDrawingHeight(); + x = x || 0; + y = y || 0; + width = width || this.standardDrawingWidth(); + height = height || this.standardDrawingHeight(); this.bitmap.gradientFillRect(x, y, width, height, color1, color2, object.vertical || false); @@ -12066,10 +12194,17 @@ DKTools.Base = class { * @param {Number} [options.maxWidth] - Max width of a text line * @param {Number} [options.maxLines] - Max lines * @param {Boolean} [options.breakWords] - Breaks a words for the wrapping + * + * @see DKTools.Base.prototype.hasBitmap + * @see DKTools.Base.prototype.getTextWidth * * @returns {String} Wrapped text */ textWrap(text, options) { + if (text == null) { + return ''; + } + text = String(text); options = options || {}; @@ -12079,7 +12214,6 @@ DKTools.Base = class { const lines = text.split('\n'); const maxWidth = options.maxWidth || (this.hasBitmap() ? this.bitmap.width : 0); - const spaceWidth = this.getTextWidth(' '); let result = ''; @@ -12354,13 +12488,13 @@ DKTools.Base = class { // load methods /** - * Loads a bitmap from a folder img/animations/ + * Loads a bitmap from img/animations/ * Returns true if the bitmap of the object has been changed * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap @@ -12381,13 +12515,13 @@ DKTools.Base = class { }; /** - * Loads a bitmap from a folder img/battlebacks1/ + * Loads a bitmap from img/battlebacks1/ * Returns true if the bitmap of the object has been changed * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap @@ -12408,13 +12542,13 @@ DKTools.Base = class { }; /** - * Loads a bitmap from a folder img/battlebacks2/ + * Loads a bitmap from img/battlebacks2/ * Returns true if the bitmap of the object has been changed * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap @@ -12435,13 +12569,13 @@ DKTools.Base = class { }; /** - * Loads a bitmap from a folder img/enemies/ + * Loads a bitmap from img/enemies/ * Returns true if the bitmap of the object has been changed * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap @@ -12462,13 +12596,13 @@ DKTools.Base = class { }; /** - * Loads a bitmap from a folder img/characters/ + * Loads a bitmap from img/characters/ * Returns true if the bitmap of the object has been changed * - * @@param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap @@ -12489,13 +12623,13 @@ DKTools.Base = class { }; /** - * Loads a bitmap from a folder img/faces/ + * Loads a bitmap from img/faces/ * Returns true if the bitmap of the object has been changed * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap @@ -12516,13 +12650,13 @@ DKTools.Base = class { }; /** - * Loads a bitmap from a folder img/parallaxes/ + * Loads a bitmap from img/parallaxes/ * Returns true if the bitmap of the object has been changed * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap @@ -12543,13 +12677,13 @@ DKTools.Base = class { }; /** - * Loads a bitmap from a folder img/pictures/ + * Loads a bitmap from img/pictures/ * Returns true if the bitmap of the object has been changed * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap @@ -12570,13 +12704,13 @@ DKTools.Base = class { }; /** - * Loads a bitmap from a folder img/sv_actors/ + * Loads a bitmap from img/sv_actors/ * Returns true if the bitmap of the object has been changed * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap @@ -12597,13 +12731,13 @@ DKTools.Base = class { }; /** - * Loads a bitmap from a folder img/sv_enemies/ + * Loads a bitmap from img/sv_enemies/ * Returns true if the bitmap of the object has been changed * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap @@ -12624,13 +12758,13 @@ DKTools.Base = class { }; /** - * Loads a bitmap from a folder img/system/ + * Loads a bitmap from img/system/ * Returns true if the bitmap of the object has been changed * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap @@ -12651,13 +12785,13 @@ DKTools.Base = class { }; /** - * Loads a bitmap from a folder img/tilesets/ + * Loads a bitmap from img/tilesets/ * Returns true if the bitmap of the object has been changed * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap @@ -12678,13 +12812,13 @@ DKTools.Base = class { }; /** - * Loads a bitmap from a folder img/titles1/ + * Loads a bitmap from img/titles1/ * Returns true if the bitmap of the object has been changed * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap @@ -12705,13 +12839,13 @@ DKTools.Base = class { }; /** - * Loads a bitmap from a folder img/titles2/ + * Loads a bitmap from img/titles2/ * Returns true if the bitmap of the object has been changed * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap @@ -12732,13 +12866,13 @@ DKTools.Base = class { }; /** - * Loads a windowskin from a folder img/system/ + * Loads a windowskin from img/system/ * Returns true if the bitmap of the object has been changed * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap @@ -12761,408 +12895,471 @@ DKTools.Base = class { // reserve methods /** - * Loads and reserves a bitmap from a folder img/animations/ + * Loads and reserves a bitmap from img/animations/ * Returns true if the bitmap of the object has been changed * + * @version 3.0.0 + * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap * @param {Number} [object.hue] - Hue of bitmap * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID * * @see Bitmap.prototype.addLoadListener * * @returns {Boolean} Bitmap of the object has been changed */ - reserveAnimation(object, listener, hue, smooth) { + reserveAnimation(object, listener, hue, smooth, reservationId) { if (object instanceof Object) { - return this.reserveBitmap('img/animations/', object.filename, object.listener, object.hue, object.smooth); + return this.reserveBitmap('img/animations/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); } // object - String - return this.reserveBitmap('img/animations/', object, listener, hue, smooth); + return this.reserveBitmap('img/animations/', object, listener, hue, smooth, reservationId); }; /** - * Loads and reserves a bitmap from a folder img/battlebacks1/ + * Loads and reserves a bitmap from img/battlebacks1/ * Returns true if the bitmap of the object has been changed * + * @version 3.0.0 + * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap * @param {Number} [object.hue] - Hue of bitmap * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID * * @see Bitmap.prototype.addLoadListener * * @returns {Boolean} Bitmap of the object has been changed */ - reserveBattleback1(object, listener, hue, smooth) { + reserveBattleback1(object, listener, hue, smooth, reservationId) { if (object instanceof Object) { - return this.reserveBitmap('img/battlebacks1/', object.filename, object.listener, object.hue, object.smooth); + return this.reserveBitmap('img/battlebacks1/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); } // object - String - return this.reserveBitmap('img/battlebacks1/', object, listener, hue, smooth); + return this.reserveBitmap('img/battlebacks1/', object, listener, hue, smooth, reservationId); }; /** - * Loads and reserves a bitmap from a folder img/battlebacks2/ + * Loads and reserves a bitmap from img/battlebacks2/ * Returns true if the bitmap of the object has been changed * + * @version 3.0.0 + * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap * @param {Number} [object.hue] - Hue of bitmap * @param {Boolean} [object.smooth] - Smooth of bitmap - * + * @param {Number} [object.reservationId] - Reservation ID + * * @see Bitmap.prototype.addLoadListener * * @returns {Boolean} Bitmap of the object has been changed */ - reserveBattleback2(object, listener, hue, smooth) { + reserveBattleback2(object, listener, hue, smooth, reservationId) { if (object instanceof Object) { - return this.reserveBitmap('img/battlebacks2/', object.filename, object.listener, object.hue, object.smooth); + return this.reserveBitmap('img/battlebacks2/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); } // object - String - return this.reserveBitmap('img/battlebacks2/', object, listener, hue, smooth); + return this.reserveBitmap('img/battlebacks2/', object, listener, hue, smooth, reservationId); }; /** - * Loads and reserves a bitmap from a folder img/enemies/ + * Loads and reserves a bitmap from img/enemies/ * Returns true if the bitmap of the object has been changed * + * @version 3.0.0 + * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap * @param {Number} [object.hue] - Hue of bitmap * @param {Boolean} [object.smooth] - Smooth of bitmap - * + * @param {Number} [object.reservationId] - Reservation ID + * * @see Bitmap.prototype.addLoadListener * * @returns {Boolean} Bitmap of the object has been changed */ - reserveEnemy(object, listener, hue, smooth) { + reserveEnemy(object, listener, hue, smooth, reservationId) { if (object instanceof Object) { - return this.reserveBitmap('img/enemies/', object.filename, object.listener, object.hue, object.smooth); + return this.reserveBitmap('img/enemies/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); } // object - String - return this.reserveBitmap('img/enemies/', object, listener, hue, smooth); + return this.reserveBitmap('img/enemies/', object, listener, hue, smooth, reservationId); }; /** - * Loads and reserves a bitmap from a folder img/characters/ + * Loads and reserves a bitmap from img/characters/ * Returns true if the bitmap of the object has been changed * + * @version 3.0.0 + * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap * @param {Number} [object.hue] - Hue of bitmap * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID * * @see Bitmap.prototype.addLoadListener * * @returns {Boolean} Bitmap of the object has been changed */ - reserveCharacter(object, listener, hue, smooth) { + reserveCharacter(object, listener, hue, smooth, reservationId) { if (object instanceof Object) { - return this.reserveBitmap('img/characters/', object.filename, object.listener, object.hue, object.smooth); + return this.reserveBitmap('img/characters/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); } // object - String - return this.reserveBitmap('img/characters/', object, listener, hue, smooth); + return this.reserveBitmap('img/characters/', object, listener, hue, smooth, reservationId); }; /** - * Loads and reserves a bitmap from a folder img/faces/ + * Loads and reserves a bitmap from img/faces/ * Returns true if the bitmap of the object has been changed * + * @version 3.0.0 + * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap * @param {Number} [object.hue] - Hue of bitmap * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID * * @see Bitmap.prototype.addLoadListener * * @returns {Boolean} Bitmap of the object has been changed */ - reserveFace(object, listener, hue, smooth) { + reserveFace(object, listener, hue, smooth, reservationId) { if (object instanceof Object) { - return this.reserveBitmap('img/faces/', object.filename, object.listener, object.hue, object.smooth); + return this.reserveBitmap('img/faces/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); } // object - String - return this.reserveBitmap('img/faces/', object, listener, hue, smooth); + return this.reserveBitmap('img/faces/', object, listener, hue, smooth, reservationId); }; /** - * Loads and reserves a bitmap from a folder img/parallaxes/ + * Loads and reserves a bitmap from img/parallaxes/ * Returns true if the bitmap of the object has been changed * + * @version 3.0.0 + * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap * @param {Number} [object.hue] - Hue of bitmap * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID * * @see Bitmap.prototype.addLoadListener * * @returns {Boolean} Bitmap of the object has been changed */ - reserveParallax(object, listener, hue, smooth) { + reserveParallax(object, listener, hue, smooth, reservationId) { if (object instanceof Object) { - return this.reserveBitmap('img/parallaxes/', object.filename, object.listener, object.hue, object.smooth); + return this.reserveBitmap('img/parallaxes/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); } // object - String - return this.reserveBitmap('img/parallaxes/', object, listener, hue, smooth); + return this.reserveBitmap('img/parallaxes/', object, listener, hue, smooth, reservationId); }; /** - * Loads and reserves a bitmap from a folder img/pictures/ + * Loads and reserves a bitmap from img/pictures/ * Returns true if the bitmap of the object has been changed * - * @@param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @version 3.0.0 + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap * @param {Number} [object.hue] - Hue of bitmap * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID * * @see Bitmap.prototype.addLoadListener * * @returns {Boolean} Bitmap of the object has been changed */ - reservePicture(object, listener, hue, smooth) { + reservePicture(object, listener, hue, smooth, reservationId) { if (object instanceof Object) { - return this.reserveBitmap('img/pictures/', object.filename, object.listener, object.hue, object.smooth); + return this.reserveBitmap('img/pictures/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); } // object - String - return this.reserveBitmap('img/pictures/', object, listener, hue, smooth); + return this.reserveBitmap('img/pictures/', object, listener, hue, smooth, reservationId); }; /** - * Loads and reserves a bitmap from a folder img/sv_actors/ + * Loads and reserves a bitmap from img/sv_actors/ * Returns true if the bitmap of the object has been changed * + * @version 3.0.0 + * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap * @param {Number} [object.hue] - Hue of bitmap * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID * * @see Bitmap.prototype.addLoadListener * * @returns {Boolean} Bitmap of the object has been changed */ - reserveSvActor(object, listener, hue, smooth) { + reserveSvActor(object, listener, hue, smooth, reservationId) { if (object instanceof Object) { - return this.reserveBitmap('img/sv_actors/', object.filename, object.listener, object.hue, object.smooth); + return this.reserveBitmap('img/sv_actors/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); } // object - String - return this.reserveBitmap('img/sv_actors/', object, listener, hue, smooth); + return this.reserveBitmap('img/sv_actors/', object, listener, hue, smooth, reservationId); }; /** - * Loads and reserves a bitmap from a folder img/sv_enemies/ + * Loads and reserves a bitmap from img/sv_enemies/ * Returns true if the bitmap of the object has been changed * + * @version 3.0.0 + * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap * @param {Number} [object.hue] - Hue of bitmap * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID * * @see Bitmap.prototype.addLoadListener * * @returns {Boolean} Bitmap of the object has been changed */ - reserveSvEnemy(object, listener, hue, smooth) { + reserveSvEnemy(object, listener, hue, smooth, reservationId) { if (object instanceof Object) { - return this.reserveBitmap('img/sv_enemies/', object.filename, object.listener, object.hue, object.smooth); + return this.reserveBitmap('img/sv_enemies/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); } // object - String - return this.reserveBitmap('img/sv_enemies/', object, listener, hue, smooth); + return this.reserveBitmap('img/sv_enemies/', object, listener, hue, smooth, reservationId); }; /** - * Loads and reserves a bitmap from a folder img/system/ + * Loads and reserves a bitmap from img/system/ * Returns true if the bitmap of the object has been changed * + * @version 3.0.0 + * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap * @param {Number} [object.hue] - Hue of bitmap * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID * * @see Bitmap.prototype.addLoadListener * * @returns {Boolean} Bitmap of the object has been changed */ - reserveSystem(object, listener, hue, smooth) { + reserveSystem(object, listener, hue, smooth, reservationId) { if (object instanceof Object) { - return this.reserveBitmap('img/system/', object.filename, object.listener, object.hue, object.smooth); + return this.reserveBitmap('img/system/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); } // object - String - return this.reserveBitmap('img/system/', object, listener, hue, smooth); + return this.reserveBitmap('img/system/', object, listener, hue, smooth, reservationId); }; /** - * Loads and reserves a bitmap from a folder img/tilesets/ + * Loads and reserves a bitmap from img/tilesets/ * Returns true if the bitmap of the object has been changed * + * @version 3.0.0 + * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap * @param {Number} [object.hue] - Hue of bitmap * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID * * @see Bitmap.prototype.addLoadListener * * @returns {Boolean} Bitmap of the object has been changed */ - reserveTileset(object, listener, hue, smooth) { + reserveTileset(object, listener, hue, smooth, reservationId) { if (object instanceof Object) { - return this.reserveBitmap('img/tilesets/', object.filename, object.listener, object.hue, object.smooth); + return this.reserveBitmap('img/tilesets/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); } // object - String - return this.reserveBitmap('img/tilesets/', object, listener, hue, smooth); + return this.reserveBitmap('img/tilesets/', object, listener, hue, smooth, reservationId); }; /** - * Loads and reserves a bitmap from a folder img/titles1/ + * Loads and reserves a bitmap from img/titles1/ * Returns true if the bitmap of the object has been changed * + * @version 3.0.0 + * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap * @param {Number} [object.hue] - Hue of bitmap * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID * * @see Bitmap.prototype.addLoadListener * * @returns {Boolean} Bitmap of the object has been changed */ - reserveTitle1(object, listener, hue, smooth) { + reserveTitle1(object, listener, hue, smooth, reservationId) { if (object instanceof Object) { - return this.reserveBitmap('img/titles1/', object.filename, object.listener, object.hue, object.smooth); + return this.reserveBitmap('img/titles1/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); } // object - String - return this.reserveBitmap('img/titles1/', object, listener, hue, smooth); + return this.reserveBitmap('img/titles1/', object, listener, hue, smooth, reservationId); }; /** - * Loads and reserves a bitmap from a folder img/titles2/ + * Loads and reserves a bitmap from img/titles2/ * Returns true if the bitmap of the object has been changed * + * @version 3.0.0 + * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap * @param {Number} [object.hue] - Hue of bitmap * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID * + * @see DKTools.Base.prototype.reserveBitmap * @see Bitmap.prototype.addLoadListener * * @returns {Boolean} Bitmap of the object has been changed */ - reserveTitle2(object, listener, hue, smooth) { + reserveTitle2(object, listener, hue, smooth, reservationId) { if (object instanceof Object) { - return this.reserveBitmap('img/titles2/', object.filename, object.listener, object.hue, object.smooth); + return this.reserveBitmap('img/titles2/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); } // object - String - return this.reserveBitmap('img/titles2/', object, listener, hue, smooth); + return this.reserveBitmap('img/titles2/', object, listener, hue, smooth, reservationId); }; /** - * Loads and reserves a windowskin img/system/ + * Loads and reserves a windowskin from img/system/ * Returns true if the bitmap of the object has been changed * + * @version 3.0.0 + * * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) * * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap * @param {Number} [object.hue] - Hue of bitmap * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID * + * @see DKTools.Base.prototype.standardWindowskin + * @see DKTools.Base.prototype.reserveSystem * @see Bitmap.prototype.addLoadListener * * @returns {Boolean} Bitmap of the object has been changed */ - reserveWindowskin(object, listener, hue, smooth) { + reserveWindowskin(object, listener, hue, smooth, reservationId) { if (object instanceof Object) { - return this.reserveSystem(object.filename || this.standardWindowskin(), object.listener, object.hue, object.smooth); + return this.reserveSystem(object.filename || this.standardWindowskin(), object.listener, object.hue, object.smooth, object.reservationId); } // object - String - return this.reserveSystem(object || this.standardWindowskin(), listener, hue, smooth); + return this.reserveSystem(object || this.standardWindowskin(), listener, hue, smooth, reservationId); }; // options methods @@ -13205,7 +13402,7 @@ DKTools.Base = class { * @returns {Boolean} Conjunction of the options */ isOptionsEnabled(object) { - return this._optionManager.isOptionsEnabled(object); + return this._optionManager.isOptionsEnabled.apply(this._optionManager, arguments); }; /** @@ -13220,7 +13417,7 @@ DKTools.Base = class { * @returns {Boolean} Disjunction of the options */ isSomeOptionsEnabled(object) { - return this._optionManager.isSomeOptionsEnabled(object); + return this._optionManager.isSomeOptionsEnabled.apply(this._optionManager, arguments); }; /** @@ -13250,7 +13447,7 @@ DKTools.Base = class { * @returns {Boolean} Conjunction of the options */ isOptionsDisabled(object) { - return this._optionManager.isOptionsDisabled(object); + return this._optionManager.isOptionsDisabled.apply(this._optionManager, arguments); }; /** @@ -13265,7 +13462,7 @@ DKTools.Base = class { * @returns {Boolean} Disjunction of the options */ isSomeOptionsDisabled(object) { - return this._optionManager.isSomeOptionsDisabled(object); + return this._optionManager.isSomeOptionsDisabled.apply(this._optionManager, arguments); }; /** @@ -13332,7 +13529,7 @@ DKTools.Base = class { * @see DKTools.OptionManager.prototype.enableOptions */ enableOptions(object) { - this._optionManager.enableOption(object); + this._optionManager.enableOptions.apply(this._optionManager, arguments); }; /** @@ -13358,7 +13555,7 @@ DKTools.Base = class { * @see DKTools.OptionManager.prototype.disableOptions */ disableOptions(object) { - this._optionManager.disableOption(object); + this._optionManager.disableOptions.apply(this._optionManager, arguments); }; /** @@ -13371,7 +13568,7 @@ DKTools.Base = class { * @see DKTools.OptionManager.prototype.switchOption */ switchOption(option) { - this._optionManager.disableOption(option); + this._optionManager.switchOption(option); }; /** @@ -13384,7 +13581,7 @@ DKTools.Base = class { * @see DKTools.OptionManager.prototype.switchOptions */ switchOptions(object) { - this._optionManager.switchOptions(object); + this._optionManager.switchOptions.apply(this._optionManager, arguments); }; // events methods @@ -14102,6 +14299,9 @@ DKTools.Base = class { * Updates all * * @version 1.1.0 + * + * @see DKTools.Base.prototype.updateOpacity + * @see DKTools.Base.prototype.updateUpdateAllEvents */ updateAll() { this.updateOpacity(); @@ -14110,6 +14310,10 @@ DKTools.Base = class { /** * Updates the object + * + * @see DKTools.Base.prototype.updateChildren + * @see DKTools.Base.prototype.processAll + * @see DKTools.Base.prototype.updateEvents */ update() { this.updateChildren(); @@ -14140,342 +14344,659 @@ DKTools.Base = class { Object.defineProperties(DKTools.Base.prototype, { /** - * The object ID + * The object ID + * + * @readonly + * @type {Number | String | null} + * @memberof DKTools.Base.prototype + */ + id : { + get: function() { + return this._id; + }, + configurable: true + }, + + /** + * The X coordinate of mouse inside the object + * + * @readonly + * @type {Number} + * @memberof DKTools.Base.prototype + */ + mouseX : { + get: function() { + return this.canvasToLocalX(TouchInput.mouseX); + }, + configurable: true + }, + + /** + * The Y coordinate of mouse inside the object + * + * @readonly + * @type {Number} + * @memberof DKTools.Base.prototype + */ + mouseY : { + get: function() { + return this.canvasToLocalY(TouchInput.mouseY); + }, + configurable: true + }, + + /** + * Number of pixels scrolling mouse on X axis + * + * @readonly + * @type {Number} + * @memberof DKTools.Base.prototype + */ + wheelX: { + get: function() { + return this._wheelX; + }, + configurable: true + }, + + /** + * Number of pixels scrolling mouse on Y axis + * + * @readonly + * @type {Number} + * @memberof DKTools.Base.prototype + */ + wheelY: { + get: function() { + return this._wheelY; + }, + configurable: true + }, + + /** + * Time of mouse enter inside the object + * + * @readonly + * @type {Number} + * @memberof DKTools.Base.prototype + */ + mouseEnterTime: { + get: function() { + return this._mouseEnterTime; + }, + configurable: true + } + +}); + + + + +//=========================================================================== +// DKTools.Sprite +//=========================================================================== + +DKTools.Sprite.prototype = Object.create(Sprite.prototype); +DKTools.Utils.mixin(DKTools.Sprite.prototype, DKTools.Base.prototype); +DKTools.Sprite.prototype.constructor = DKTools.Sprite; + +/** + * Counter of created sprites + * + * @private + * @readonly + * @type {Number} + * @memberof DKTools.Sprite + */ +DKTools.Sprite._counter = 0; + +// properties + +Object.defineProperties(DKTools.Sprite.prototype, { + + /** + * Window skin + * + * @readonly + * @type {Bitmap | null} + * @memberof DKTools.Sprite.prototype + */ + windowskin: { + get: function() { + return this._windowskin; + }, + configurable: true + }, + + /** + * Frame of the sprite + * + * @readonly + * @type {Rectangle} + * @memberof DKTools.Sprite.prototype + */ + frame: { + get: function() { + return this._frame; + }, + configurable: true + }, + + /** + * Real width of the sprite (not including scaling) + * + * @type {Number} + * @memberof DKTools.Sprite.prototype + */ + realWidth: { + get: function() { + return this._frame.width; + }, + set: function(value) { + this._frame.width = value; + this._refresh(); + }, + configurable: true + }, + + /** + * Real height of the sprite (not including scaling) + * + * @type {Number} + * @memberof DKTools.Sprite.prototype + */ + realHeight: { + get: function() { + return this._frame.height; + }, + set: function(value) { + this._frame.height = value; + this._refresh(); + }, + configurable: true + }, + + /** + * Width of the sprite (taking into account the scaling) + * + * @type {Number} + * @memberof DKTools.Sprite.prototype + */ + width: { + get: function() { + return this.realWidth * this.scale.x; + }, + set: function(value) { + this.realWidth = Math.floor(value / this.scale.x); + }, + configurable: true + }, + + /** + * Height of the sprite (taking into account the scaling) + * + * @type {Number} + * @memberof DKTools.Sprite.prototype + */ + height: { + get: function() { + return this.realHeight * this.scale.y; + }, + set: function(value) { + this.realHeight = Math.floor(value / this.scale.y); + }, + configurable: true + }, + + /** + * Text font + * + * @readonly + * @type {Object} + * @memberof DKTools.Sprite.prototype + */ + font: { + get: function() { + return this._font; + }, + configurable: true + }, + + /** + * Text color + * + * @readonly + * @type {String} + * @memberof DKTools.Sprite.prototype + */ + textColor: { + get: function() { + return this._textColor; + }, + configurable: true + }, + + /** + * Paint opacity * * @readonly - * @type {Number | String | null} - * @memberOf DKTools.Base.prototype + * @type {Number} + * @memberof DKTools.Sprite.prototype */ - id : { + paintOpacity: { get: function() { - return this._id; + return this._paintOpacity; }, configurable: true }, /** - * The X coordinate of mouse inside the object + * Fill color * * @readonly - * @type {Number} - * @memberOf DKTools.Base.prototype + * @type {String | null} + * @memberof DKTools.Sprite.prototype */ - mouseX : { + fillColor: { get: function() { - return this.canvasToLocalX(TouchInput.mouseX); + return this._fillColor; }, configurable: true }, /** - * The Y coordinate of mouse inside the object + * Text align * * @readonly - * @type {Number} - * @memberOf DKTools.Base.prototype + * @type {String} + * @memberof DKTools.Sprite.prototype */ - mouseY : { + align: { get: function() { - return this.canvasToLocalY(TouchInput.mouseY); + return this._align; }, configurable: true }, /** - * Number of pixels scrolling mouse on X axis + * Texts * * @readonly - * @type {Number} - * @memberOf DKTools.Base.prototype + * @type {Object[]} + * @memberof DKTools.Sprite.prototype */ - wheelX: { + texts: { get: function() { - return this._wheelX; + return this._texts; }, configurable: true }, /** - * Number of pixels scrolling mouse on Y axis + * Graphic folder * * @readonly - * @type {Number} - * @memberOf DKTools.Base.prototype + * @type {String} + * @memberof DKTools.Sprite.prototype */ - wheelY: { + graphicFolder: { get: function() { - return this._wheelY; + return this._graphicFolder; }, configurable: true }, /** - * Time of mouse enter inside the object + * Graphic name * * @readonly - * @type {Number} - * @memberOf DKTools.Base.prototype + * @type {String} + * @memberof DKTools.Sprite.prototype */ - mouseEnterTime: { + graphicName: { get: function() { - return this._mouseEnterTime; + return this._graphicName; }, configurable: true } }); +// initialize methods +/** + * Initializes a class object + * + * @version 3.0.0 + * + * @override + * + * @param {Number | DKTools.Sprite | Bitmap | PIXI.Rectangle | Rectangle | Object} [object] - The X coordinate or Sprite or Bitmap or Rectangle or object with properties + * @param {Number} [y] - The Y coordinate (if object is Number) + * @param {Number} [width] - Width of the bitmap (if object is Number) + * @param {Number} [height] - Height of the bitmap (if object is Number) + * + * @param {Number} [object.x] - The X coordinate + * @param {Number} [object.y] - The Y coordinate + * @param {Number} [object.width] - Width of the bitmap + * @param {Number} [object.height] - Height of the bitmap + * @param {Bitmap | Object} [object] - Bitmap or object with parameters + * + * @param {String} object.folder - Path to file + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see Sprite.prototype.initialize + * @see DKTools.Base.prototype.initialize + * @see DKTools.Sprite.prototype.setupAll + * @see DKTools.Sprite.prototype.setupSize + * @see DKTools.Sprite.prototype.setupBitmap + * @see DKTools.Sprite.prototype.updateBitmap + */ +DKTools.Sprite.prototype.initialize = function(object, y, width, height) { + Sprite.prototype.initialize.call(this); + DKTools.Base.prototype.initialize.call(this, object, y, width, height); + if (object instanceof DKTools.Sprite && !object.isStarted() && !object.hasFixedBitmap()) { + this.setupSize(object._getBitmapWidth(), object._getBitmapHeight()); + } else if (object instanceof Bitmap) { + this.setupBitmap(object); + } -//=========================================================================== -// DKTools.Sprite -//=========================================================================== + this.updateBitmap(); + DKTools.Sprite._counter++; +}; -DKTools.Sprite.prototype = Object.create(Sprite.prototype); -DKTools.Utils.mixin(DKTools.Sprite.prototype, DKTools.Base.prototype); -DKTools.Sprite.prototype.constructor = DKTools.Sprite; +// _clear methods /** - * Counter of created sprites + * Clears all data * * @private - * @readonly - * @type {Number} - * @memberOf DKTools.Sprite + * @override + * + * @see DKTools.Base.prototype._clearAll + * @see DKTools.Sprite.prototype._clearTexts */ -DKTools.Sprite._counter = 0; - -// properties - -Object.defineProperties(DKTools.Sprite.prototype, { +DKTools.Sprite.prototype._clearAll = function() { + DKTools.Base.prototype._clearAll.call(this); + this._clearTexts(); +}; +/** + * Clears all texts + * + * @private + */ +DKTools.Sprite.prototype._clearTexts = function() { /** - * Window skin - * + * @private * @readonly - * @type {Bitmap | null} - * @memberOf DKTools.Sprite.prototype + * @type {Object[]} */ - windowskin: { - get: function() { - return this._windowskin; - }, - configurable: true - }, + this._texts = []; +}; - /** - * Frame of the sprite - * - * @readonly - * @type {Rectangle} - * @memberOf DKTools.Sprite.prototype - */ - frame: { - get: function() { - return this._frame; - }, - configurable: true - }, +// standard methods - /** - * Real width of the sprite (not including scaling) - * - * @type {Number} - * @memberOf DKTools.Sprite.prototype - */ - realWidth: { - get: function() { - return this._frame.width; - }, - set: function(value) { - this._frame.width = value; - this._refresh(); - }, - configurable: true - }, +/** + * Returns the standard font face + * + * @returns {String} Standard font face + */ +DKTools.Sprite.prototype.standardFontFace = function() { + return 'GameFont'; +}; - /** - * Real height of the sprite (not including scaling) - * - * @type {Number} - * @memberOf DKTools.Sprite.prototype - */ - realHeight: { - get: function() { - return this._frame.height; - }, - set: function(value) { - this._frame.height = value; - this._refresh(); - }, - configurable: true - }, +/** + * Returns the standard font size + * + * @returns {String} Standard font size + */ +DKTools.Sprite.prototype.standardFontSize = function() { + return 28; +}; + +/** + * Returns the standard font italic + * + * @returns {String} Standard font italic + */ +DKTools.Sprite.prototype.standardFontItalic = function() { + return false; +}; + +/** + * Returns the standard font + * + * @see DKTools.Sprite.prototype.standardFontFace + * @see DKTools.Sprite.prototype.standardFontSize + * @see DKTools.Sprite.prototype.standardFontItalic + * + * @returns {Object} Standard font + */ +DKTools.Sprite.prototype.standardFont = function() { + return { + fontFace: this.standardFontFace(), + fontSize: this.standardFontSize(), + fontItalic: this.standardFontItalic() + }; +}; + +/** + * Returns the standard text color + * + * @returns {String} Standard text color + */ +DKTools.Sprite.prototype.standardTextColor = function() { + return '#ffffff'; +}; + +/** + * Returns the standard paint opacity + * + * @returns {Number} Standard paint opacity + */ +DKTools.Sprite.prototype.standardPaintOpacity = function() { + return 255; +}; + +/** + * Returns the standard fill color + * + * @returns {String | null} Standard fill color + */ +DKTools.Sprite.prototype.standardFillColor = function() { + return null; +}; + +/** + * Returns the standard text align + * + * @returns {String} Standard text align + */ +DKTools.Sprite.prototype.standardAlign = function() { + return 'center'; +}; + +/** + * Returns the standard graphic folder + * + * @returns {String} Standard graphic folder + */ +DKTools.Sprite.prototype.standardGraphicFolder = function() { + return 'img/system/'; +}; - /** - * Width of the sprite (taking into account the scaling) - * - * @type {Number} - * @memberOf DKTools.Sprite.prototype - */ - width: { - get: function() { - return this.realWidth * this.scale.x; - }, - set: function(value) { - this.realWidth = Math.floor(value / this.scale.x); - }, - configurable: true - }, +/** + * Returns the standard graphic name + * + * @returns {String} standard graphic name + */ +DKTools.Sprite.prototype.standardGraphicName = function() { + return ''; +}; - /** - * Height of the sprite (taking into account the scaling) - * - * @type {Number} - * @memberOf DKTools.Sprite.prototype - */ - height: { - get: function() { - return this.realHeight * this.scale.y; - }, - set: function(value) { - this.realHeight = Math.floor(value / this.scale.y); - }, - configurable: true - }, +/** + * Returns the standard opacity + * + * @returns {Number} Standard opacity + */ +DKTools.Sprite.prototype.standardOpacity = function() { + return 255; +}; - /** - * Text font - * - * @readonly - * @type {Object} - * @memberOf DKTools.Sprite.prototype - */ - font: { - get: function() { - return this._font; - }, - configurable: true - }, +/** + * Returns the standard frame + * + * @returns {Rectangle} Standard frame + */ +DKTools.Sprite.prototype.standardFrame = function() { + return new Rectangle(0, 0, this.width, this.height); +}; - /** - * Text color - * - * @readonly - * @type {String} - * @memberOf DKTools.Sprite.prototype - */ - textColor: { - get: function() { - return this._textColor; - }, - configurable: true - }, +/** + * Returns the standard anchor + * + * @returns {Point} Standard anchor + */ +DKTools.Sprite.prototype.standardAnchor = function() { + return new Point(0, 0); +}; - /** - * Paint opacity - * - * @readonly - * @type {Number} - * @memberOf DKTools.Sprite.prototype - */ - paintOpacity: { - get: function() { - return this._paintOpacity; - }, - configurable: true - }, +// setup methods - /** - * Fill color - * - * @readonly - * @type {String | null} - * @memberOf DKTools.Sprite.prototype - */ - fillColor: { - get: function() { - return this._fillColor; - }, - configurable: true - }, +/** + * Sets all parameters + * + * @override + * + * @param {Object} [object] - Parameters + * + * @param {Bitmap | Object} [object.bitmap] - Bitmap or object with parameters + * @param {Object} [object.font] - Text font + * @param {String} [object.textColor] - Text color + * @param {Number} [object.paintOpacity] - Paint opacity + * @param {String} [object.fillColor] - Fill color + * @param {String} [object.align] - Text align + * @param {Number} [object.opacity] - Opacity + * @param {String} [object.graphicFolder] - Graphic folder + * @param {String} [object.graphicName] - Graphic name + * @param {PIXI.Rectangle | Rectangle | Object} [object.frame] - Rectangle or object with parameters + * @param {PIXI.Point | PIXI.ObservablePoint | Point | Object} [object.anchor] - Anchor of the sprite + * + * @param {String} object.folder - Path to file + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @param {String} [object.font.fontFace] - Font face + * @param {Number} [object.font.fontSize] - Font size + * @param {Boolean} [object.font.fontItalic] - Font italic + * + * @param {Number} [object.frame.x] - The X coordinate + * @param {Number} [object.frame.y] - The Y coordinate + * @param {Number} [object.frame.width] - Width of the frame + * @param {Number} [object.frame.height] - Height of the frame + * + * @param {Number} [object.anchor.x] - The X coordinate + * @param {Number} [object.anchor.y] - The Y coordinate + * + * @see DKTools.Base.prototype.setupAll + * @see DKTools.Sprite.prototype.setupBitmap + * @see DKTools.Sprite.prototype.setupFont + * @see DKTools.Sprite.prototype.setupTextColor + * @see DKTools.Sprite.prototype.setupPaintOpacity + * @see DKTools.Sprite.prototype.setupFillColor + * @see DKTools.Sprite.prototype.setupAlign + * @see DKTools.Sprite.prototype.setupOpacity + * @see DKTools.Sprite.prototype.setupGraphicFolder + * @see DKTools.Sprite.prototype.setupGraphicName + * @see DKTools.Sprite.prototype.setupFrame + * @see DKTools.Sprite.prototype.setupAnchor + */ +DKTools.Sprite.prototype.setupAll = function(object) { + object = object || {}; + DKTools.Base.prototype.setupAll.call(this, object); + this.setupBitmap(object); + this.setupFont(object.font); + this.setupTextColor(object.textColor); + this.setupPaintOpacity(object.paintOpacity); + this.setupFillColor(object.fillColor); + this.setupAlign(object.align); + this.setupOpacity(object.opacity); + this.setupGraphicFolder(object.graphicFolder); + this.setupGraphicName(object.graphicName); + this.setupFrame(object.frame); + this.setupAnchor(object.anchor); +}; +/** + * Sets the width of the bitmap + * + * @param {Number} [width] - Width of the bitmap + * + * @see DKTools.Base.prototype._checkWidth + */ +DKTools.Sprite.prototype.setupWidth = function(width) { /** - * Text align - * + * @private * @readonly - * @type {String} - * @memberOf DKTools.Sprite.prototype + * @type {Number} */ - align: { - get: function() { - return this._align; - }, - configurable: true - }, + this._bitmapWidth = this._checkWidth(width); +}; - /** - * Texts - * - * @readonly - * @type {Object[]} - * @memberOf DKTools.Sprite.prototype - */ - texts: { - get: function() { - return this._texts; - }, - configurable: true - }, +/** + * Sets the height of the bitmap + * + * @param {Number | String} [height] - Height of the bitmap or number of lines + * + * @see DKTools.Base.prototype.getLineHeight + * @see DKTools.Base.prototype._checkHeight + */ +DKTools.Sprite.prototype.setupHeight = function(height) { + if (DKTools.Utils.isString(height)) { + height = this.getLineHeight() * Number(height); + } /** - * Graphic folder - * + * @private * @readonly - * @type {String} - * @memberOf DKTools.Sprite.prototype + * @type {Number} */ - graphicFolder: { - get: function() { - return this._graphicFolder; - }, - configurable: true - }, + this._bitmapHeight = this._checkHeight(height); +}; - /** - * Graphic name - * - * @readonly - * @type {String} - * @memberOf DKTools.Sprite.prototype - */ - graphicName: { - get: function() { - return this._graphicName; - }, - configurable: true +/** + * Sets the size of the bitmap + * + * @param {Number | Object} [object] - Width of the bitmap or object with parameters + * @param {Number} [height] - Height of the bitmap (if object is Object) + * + * @param {Number} [object.width] - Width of the bitmap + * @param {Number} [object.height] - Height of the bitmap + * + * @see DKTools.Sprite.prototype.setupWidth + * @see DKTools.Sprite.prototype.setupHeight + */ +DKTools.Sprite.prototype.setupSize = function(object, height) { + if (object instanceof Object) { + return this.setupSize(object.width, object.height); } -}); - -// initialize methods + this.setupWidth(object); + this.setupHeight(height); +}; /** - * Initializes a class object - * - * @version 1.1.0 - * - * @override + * Sets the bitmap * - * @param {Number | DKTools.Sprite | Bitmap | PIXI.Rectangle | Rectangle | Object} [object] - The X coordinate or Sprite or Bitmap or Rectangle or object with properties - * @param {Number} [y] - The Y coordinate (if object is Number) - * @param {Number} [width] - Width of the bitmap (if object is Number) - * @param {Number} [height] - Height of the bitmap (if object is Number) + * @version 2.0.1 * - * @param {Number} [object.x] - The X coordinate - * @param {Number} [object.y] - The Y coordinate - * @param {Number} [object.width] - Width of the bitmap - * @param {Number} [object.height] - Height of the bitmap * @param {Bitmap | Object} [object] - Bitmap or object with parameters * * @param {String} object.folder - Path to file @@ -14484,188 +15005,255 @@ Object.defineProperties(DKTools.Sprite.prototype, { * @param {Number} [object.hue] - Hue of bitmap * @param {Boolean} [object.smooth] - Smooth of bitmap * - * @see Sprite.prototype.initialize - * @see DKTools.Base.prototype.initialize - * @see DKTools.Sprite.prototype.setupAll - * @see DKTools.Sprite.prototype.setupSize - * @see DKTools.Sprite.prototype.setupBitmap - * @see DKTools.Sprite.prototype.updateBitmap -*/ -DKTools.Sprite.prototype.initialize = function(object, y, width, height) { - Sprite.prototype.initialize.call(this); - DKTools.Base.prototype.initialize.call(this, object, y, width, height); + * @see DKTools.Utils.Bitmap.load + */ +DKTools.Sprite.prototype.setupBitmap = function(object) { + let bitmap = null; - if (object instanceof DKTools.Sprite && !object.isStarted() && !object.hasFixedBitmap()) { - // TODO: object._getBitmapWidth() || object._bitmapWidth, object._getBitmapHeight() || object._bitmapHeight ? - this.setupSize(object._bitmapWidth, object._bitmapHeight); - } else if (object instanceof Bitmap) { - this.setupBitmap(object); + if (object instanceof DKTools.Sprite && + object.hasFixedBitmap() && + object.canCloneFixedBitmap()) { + bitmap = DKTools.Utils.Bitmap.clone(object.bitmap); + } else { + bitmap = DKTools.Utils.Bitmap.load(object); } - this.updateBitmap(); - DKTools.Sprite._counter++; -}; - -// _clear methods + if (bitmap) { + this.bitmap = bitmap; + this.bitmap.addLoadListener(this.setupSize.bind(this)); + } else { + this.bitmap = null; + } -/** - * Clears all data - * - * @private - * @override - */ -DKTools.Sprite.prototype._clearAll = function() { - DKTools.Base.prototype._clearAll.call(this); - this._clearTexts(); + /** + * @private + * @readonly + * @type {Boolean} + */ + this._fixedBitmap = !!this.bitmap; }; /** - * Clears all texts + * Sets the font of the bitmap * - * @private + * @param {Object} [font=this.standardFont()] - Text font + * + * @param {String} [object.font.fontFace] - Font face + * @param {Number} [object.font.fontSize] - Font size + * @param {Boolean} [object.font.fontItalic] - Font italic + * + * @see DKTools.Sprite.prototype.standardFont */ -DKTools.Sprite.prototype._clearTexts = function() { +DKTools.Sprite.prototype.setupFont = function(font) { /** * @private * @readonly - * @type {Object[]} + * @type {Object} */ - this._texts = []; + this._font = Object.assign(this.standardFont(), font); }; -// standard methods - /** - * Returns the standard font face + * Sets the color of the text * - * @returns {String} Standard font face - */ -DKTools.Sprite.prototype.standardFontFace = function() { - return 'GameFont'; -}; - -/** - * Returns the standard font size + * @param {String} [color=this.standardTextColor()] - Text color * - * @returns {String} Standard font size + * @see DKTools.Sprite.prototype.standardTextColor */ -DKTools.Sprite.prototype.standardFontSize = function() { - return 28; +DKTools.Sprite.prototype.setupTextColor = function(color) { + /** + * @private + * @readonly + * @type {String} + */ + this._textColor = color || this.standardTextColor(); }; /** - * Returns the standard font italic + * Sets the paint opacity * - * @returns {String} Standard font italic - */ -DKTools.Sprite.prototype.standardFontItalic = function() { - return false; -}; - -/** - * Returns the standard font + * @param {Number} [opacity=this.standardPaintOpacity()] - Paint opacity * - * @returns {Object} Standard font + * @see DKTools.Sprite.prototype.standardPaintOpacity */ -DKTools.Sprite.prototype.standardFont = function() { - return { - fontFace: this.standardFontFace(), - fontSize: this.standardFontSize(), - fontItalic: this.standardFontItalic() - }; +DKTools.Sprite.prototype.setupPaintOpacity = function(opacity) { + /** + * @private + * @readonly + * @type {Number} + */ + this._paintOpacity = (opacity == null ? this.standardPaintOpacity() : opacity); }; /** - * Returns the standard text color + * Sets the fill color * - * @returns {String} Standard text color + * @param {String} [color=this.standardFillColor()] - Fill color + * + * @see DKTools.Sprite.prototype.standardFillColor */ -DKTools.Sprite.prototype.standardTextColor = function() { - return '#ffffff'; +DKTools.Sprite.prototype.setupFillColor = function(color) { + /** + * @private + * @readonly + * @type {String | null} + */ + this._fillColor = (color == null ? this.standardFillColor() : color); }; /** - * Returns the standard paint opacity + * Sets the align * - * @returns {Number} Standard paint opacity + * @param {String} [align=this.standardAlign()] - Text align + * + * @see DKTools.Sprite.prototype.standardAlign */ -DKTools.Sprite.prototype.standardPaintOpacity = function() { - return 255; +DKTools.Sprite.prototype.setupAlign = function(align) { + /** + * @private + * @readonly + * @type {String} + */ + this._align = align || this.standardAlign(); }; /** - * Returns the standard fill color + * Sets the opacity of the sprite * - * @returns {String | null} Standard fill color + * @param {Number} [opacity=this.standardOpacity()] - Opacity + * + * @see DKTools.Sprite.prototype.standardOpacity */ -DKTools.Sprite.prototype.standardFillColor = function() { - return null; +DKTools.Sprite.prototype.setupOpacity = function(opacity) { + /** + * @private + * @readonly + * @type {Number} + */ + this._opacity = (opacity == null ? this.standardOpacity() : opacity); }; /** - * Returns the standard text align + * Sets the graphic folder * - * @returns {String} Standard text align + * @param {String} [folder=this.standardGraphicFolder()] - Path to folder + * + * @see DKTools.Sprite.prototype.standardGraphicFolder */ -DKTools.Sprite.prototype.standardAlign = function() { - return 'center'; +DKTools.Sprite.prototype.setupGraphicFolder = function(folder) { + /** + * @private + * @readonly + * @type {String} + */ + this._graphicFolder = (folder == null ? this.standardGraphicFolder() : folder); }; /** - * Returns the standard graphic folder + * Sets the graphic name * - * @returns {String} Standard graphic folder + * @param {String} [graphicName=this.standardGraphicName()] - Graphic name + * + * @see DKTools.Sprite.prototype.standardGraphicName */ -DKTools.Sprite.prototype.standardGraphicFolder = function() { - return 'img/system/'; +DKTools.Sprite.prototype.setupGraphicName = function(graphicName) { + /** + * @private + * @readonly + * @type {String} + */ + this._graphicName = (graphicName == null ? this.standardGraphicName() : graphicName); }; /** - * Returns the standard graphic name + * Sets the frame of the sprite * - * @returns {String} standard graphic name + * @version 1.1.0 + * + * @param {Number | Rectangle | Object} [object] - The X coordinate or Rectangle or object with parameters + * @param {Number} [y] - The Y coordinate (if object is Number) + * @param {Number} [width] - Width of the frame (if object is Number) + * @param {Number} [height] - Height of the frame (if object is Number) + * + * @param {Number} [object.x] - The X coordinate + * @param {Number} [object.y] - The Y coordinate + * @param {Number} [object.width] - Width of the frame + * @param {Number} [object.height] - Height of the frame + * + * @see DKTools.Utils.Rectangle.toRectangle + * @see DKTools.Sprite.prototype.standardFrame + * @see Sprite.prototype.setFrame + * @see DKTools.Sprite.prototype.hasFixedBitmap */ -DKTools.Sprite.prototype.standardGraphicName = function() { - return ''; +DKTools.Sprite.prototype.setupFrame = function(object, y, width, height) { + const frame = DKTools.Utils.Rectangle.toRectangle(object, y, width, height); + const newFrame = Object.assign(this.standardFrame(), frame); + + Sprite.prototype.setFrame.call(this, newFrame.x, newFrame.y, newFrame.width, newFrame.height); + + if (this.hasFixedBitmap() && !this.bitmap.isReady()) { + this._refreshFrame = true; + } }; /** - * Returns the standard opacity + * Sets the anchor of the sprite * - * @returns {Number} Standard opacity + * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object=this.standardAnchor()] - The X coordinate or Point or object with parameters + * @param {Number} [y=undefined] - The Y coordinate (is object is Number) + * + * @param {Number} [object.x] - The X coordinate + * @param {Number} [object.y] - The Y coordinate + * + * @see DKTools.Utils.Point.toPoint + * @see DKTools.Sprite.prototype.standardAnchor */ -DKTools.Sprite.prototype.standardOpacity = function() { - return 255; +DKTools.Sprite.prototype.setupAnchor = function(object, y) { + const anchor = DKTools.Utils.Point.toPoint(object, y); + const newAnchor = Object.assign(this.standardAnchor(), anchor); + + /** + * @type {PIXI.ObservablePoint} + */ + this.anchor.copy(newAnchor); }; /** - * Returns the standard frame - * - * @returns {Rectangle} Standard frame + * Sets the mask + * + * @since 2.0.0 + * @param {PIXI.Graphics} [mask] - Mask */ -DKTools.Sprite.prototype.standardFrame = function() { - return new Rectangle(0, 0, this.width, this.height); +DKTools.Sprite.prototype.setupMask = function(mask) { + this.mask = mask || null; }; /** - * Returns the standard anchor + * Sets the listener on load of graphic * - * @returns {Point} Standard anchor + * @param {Function} listener - Listener */ -DKTools.Sprite.prototype.standardAnchor = function() { - return new Point(0, 0); +DKTools.Sprite.prototype.setupGraphicLoadListener = function(listener) { + /** + * @private + * @readonly + * @type {Function} + */ + this._graphicLoadListener = listener || null; }; -// setup methods +// set methods /** - * Sets all parameters + * Changes all parameters + * Returns the number of changed parameters * * @override * - * @param {Object} [object] - Parameters + * @param {Object} [object={}] - Parameters + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [activate=false] - Activates the sprite * - * @param {Bitmap | Object} [object.bitmap] - Bitmap or object with parameters * @param {Object} [object.font] - Text font * @param {String} [object.textColor] - Text color * @param {Number} [object.paintOpacity] - Paint opacity @@ -14674,118 +15262,108 @@ DKTools.Sprite.prototype.standardAnchor = function() { * @param {Number} [object.opacity] - Opacity * @param {String} [object.graphicFolder] - Graphic folder * @param {String} [object.graphicName] - Graphic name - * @param {PIXI.Rectangle | Rectangle | Object} [object.frame] - Rectangle or object with parameters - * @param {PIXI.Point | PIXI.ObservablePoint | Point | Object} [object.anchor] - Anchor of the sprite - * - * @param {String} object.folder - Path to file - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @param {String} [object.font.fontFace] - Font face - * @param {Number} [object.font.fontSize] - Font size - * @param {Boolean} [object.font.fontItalic] - Font italic * - * @param {Number} [object.frame.x] - The X coordinate - * @param {Number} [object.frame.y] - The Y coordinate - * @param {Number} [object.frame.width] - Width of the frame - * @param {Number} [object.frame.height] - Height of the frame + * @param {String} [object.font.fontFace] - Название шрифта + * @param {Number} [object.font.fontSize] - Размер шрифта + * @param {Boolean} [object.font.fontItalic] - Курсив шрифта * - * @param {Number} [object.anchor.x] - The X coordinate - * @param {Number} [object.anchor.y] - The Y coordinate + * @see DKTools.Base.prototype.setAll + * @see DKTools.Sprite.prototype.setFont + * @see DKTools.Sprite.prototype.setTextColor + * @see DKTools.Sprite.prototype.setPaintOpacity + * @see DKTools.Sprite.prototype.setFillColor + * @see DKTools.Sprite.prototype.setAlign + * @see DKTools.Sprite.prototype.setOpacity + * @see DKTools.Sprite.prototype.setGraphicFolder + * @see DKTools.Sprite.prototype.setGraphicName + * @see DKTools.Sprite.prototype.start + * @see DKTools.Sprite.prototype.activate * - * @see DKTools.Base.prototype.setupAll - * @see DKTools.Sprite.prototype.setupBitmap - * @see DKTools.Sprite.prototype.setupFont - * @see DKTools.Sprite.prototype.setupTextColor - * @see DKTools.Sprite.prototype.setupPaintOpacity - * @see DKTools.Sprite.prototype.setupFillColor - * @see DKTools.Sprite.prototype.setupAlign - * @see DKTools.Sprite.prototype.setupOpacity - * @see DKTools.Sprite.prototype.setupGraphicFolder - * @see DKTools.Sprite.prototype.setupGraphicName - * @see DKTools.Sprite.prototype.setupFrame - * @see DKTools.Sprite.prototype.setupAnchor -*/ -DKTools.Sprite.prototype.setupAll = function(object) { + * @returns {Number} Number of changed parameters + */ +DKTools.Sprite.prototype.setAll = function(object, blockStart, activate) { object = object || {}; - DKTools.Base.prototype.setupAll.call(this, object); - this.setupBitmap(object); - this.setupFont(object.font); - this.setupTextColor(object.textColor); - this.setupPaintOpacity(object.paintOpacity); - this.setupFillColor(object.fillColor); - this.setupAlign(object.align); - this.setupOpacity(object.opacity); - this.setupGraphicFolder(object.graphicFolder); - this.setupGraphicName(object.graphicName); - this.setupFrame(object.frame); - this.setupAnchor(object.anchor); + const block = true; + let changed = DKTools.Base.prototype.setAll.call(this, object, block); + + if (this.setFont(object.font, block)) { + changed++; + } + + if (this.setTextColor(object.textColor, block)) { + changed++; + } + + if (this.setPaintOpacity(object.paintOpacity, block)) { + changed++; + } + + if (this.setFillColor(object.fillColor, block)) { + changed++; + } + + if (this.setAlign(object.align, block)) { + changed++; + } + + if (this.setOpacity(object.opacity, block)) { + changed++; + } + + if (this.setGraphicFolder(object.graphicFolder), block) { + changed++; + } + + if (this.setGraphicName(object.graphicName, block)) { + changed++; + } + + if (changed) { + if (!blockStart) { + this.start(); + } + + if (activate) { + this.activate(); + } + } + + return changed; }; /** - * Sets the width of the bitmap + * Changes the width of the bitmap + * Returns true if the change occurred * * @param {Number} [width] - Width of the bitmap + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @see DKTools.Base.prototype._checkWidth -*/ -DKTools.Sprite.prototype.setupWidth = function(width) { - /** - * @private - * @readonly - * @type {Number} - */ - this._bitmapWidth = this._checkWidth(width); -}; - -/** - * Sets the height of the bitmap - * - * @param {Number | String} [height] - Height of the bitmap or number of lines + * @see DKTools.Sprite.prototype.resize * - * @see DKTools.Base.prototype.getLineHeight - * @see DKTools.Base.prototype._checkHeight -*/ -DKTools.Sprite.prototype.setupHeight = function(height) { - if (_.isString(height)) { - height = this.getLineHeight() * Number(height); - } - - /** - * @private - * @readonly - * @type {Number} - */ - this._bitmapHeight = this._checkHeight(height); + * @returns {Boolean} Change occurred + */ +DKTools.Sprite.prototype.setWidth = function(width, blockStart) { + return this.resize(width, this._bitmapHeight, blockStart); }; /** - * Sets the size of the bitmap + * hanges the width of the bitmap + * Returns true if the change occurred * - * @param {Number | Object} [object] - Width of the bitmap or object with parameters - * @param {Number} [height] - Height of the bitmap (if object is Object) + * @param {Number} [height] - Height of the bitmap + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @param {Number} [object.width] - Width of the bitmap - * @param {Number} [object.height] - Height of the bitmap + * @see DKTools.Sprite.prototype.resize * - * @see DKTools.Sprite.prototype.setupWidth - * @see DKTools.Sprite.prototype.setupHeight + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.setupSize = function(object, height) { - if (object instanceof Object) { - return this.setupSize(object.width, object.height); - } - - this.setupWidth(object); - this.setupHeight(height); +DKTools.Sprite.prototype.setHeight = function(height, blockStart) { + return this.resize(this._bitmapWidth, height, blockStart); }; /** - * Sets the bitmap - * - * @version 2.0.1 + * Changes the bitmap + * Returns true if the change occurred * * @param {Bitmap | Object} [object] - Bitmap or object with parameters * @@ -14795,170 +15373,273 @@ DKTools.Sprite.prototype.setupSize = function(object, height) { * @param {Number} [object.hue] - Hue of bitmap * @param {Boolean} [object.smooth] - Smooth of bitmap * - * @see DKTools.Utils.Bitmap.load + * @see DKTools.Sprite.prototype.setupBitmap + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.setupBitmap = function(object) { - let bitmap = null; +DKTools.Sprite.prototype.setBitmap = function(object) { + if (this.bitmap == object) { + return false; + } - if (object instanceof DKTools.Sprite && - object.hasFixedBitmap() && - object.canCloneFixedBitmap()) { - bitmap = DKTools.Utils.Bitmap.clone(object.bitmap); - } else { - bitmap = DKTools.Utils.Bitmap.load(object); + this.setupBitmap(object); + + return true; +}; + +/** + * Changes the font of the bitmap + * Returns true if the change occurred + * + * @param {Object} [font] - Text font + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * + * @param {String} [object.font.fontFace] - Font face + * @param {Number} [object.font.fontSize] - Font size + * @param {Boolean} [object.font.fontItalic] - Font italic + * + * @see DKTools.Sprite.prototype.standardFont + * @see DKTools.Sprite.prototype.setupFont + * @see DKTools.Sprite.prototype.start + * + * @returns {Boolean} Change occurred + */ +DKTools.Sprite.prototype.setFont = function(font, blockStart) { + if (_.isEqual(this._font, Object.assign(this.standardFont(), font))) { + return false; } - if (bitmap) { - this.bitmap = bitmap; - this.bitmap.addLoadListener(this.setupSize.bind(this)); - } else { - this.bitmap = null; + this.setupFont(font); + + if (!blockStart) { + this.start(); } - /** - * @private - * @readonly - * @type {Boolean} - */ - this._fixedBitmap = !!this.bitmap; + return true; }; /** - * Sets the font of the bitmap + * Changes the text color + * Returns true if the change occurred * - * @param {Object} [font=this.standardFont()] - Text font + * @param {String} [color] - Text color + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @param {String} [object.font.fontFace] - Font face - * @param {Number} [object.font.fontSize] - Font size - * @param {Boolean} [object.font.fontItalic] - Font italic + * @see DKTools.Sprite.prototype.setupTextColor + * @see DKTools.Sprite.prototype.refreshAll * - * @see DKTools.Sprite.prototype.standardFont + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.setupFont = function(font) { - /** - * @private - * @readonly - * @type {Object} - */ - this._font = Object.assign(this.standardFont(), font); +DKTools.Sprite.prototype.setTextColor = function(color, blockRefreshAll) { + if (this._textColor === color) { + return false; + } + + const lastColor = this._textColor; + this.setupTextColor(color); + + if (this._textColor === lastColor) { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Sets the color of the text + * Changes the paint opacity + * Returns true if the change occurred * - * @param {String} [color=this.standardTextColor()] - Text color + * @param {Number} [opacity] - Paint opacity + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.prototype.standardTextColor + * @see DKTools.Sprite.prototype.setupPaintOpacity + * @see DKTools.Sprite.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.setupTextColor = function(color) { - /** - * @private - * @readonly - * @type {String} - */ - this._textColor = color || this.standardTextColor(); +DKTools.Sprite.prototype.setPaintOpacity = function(opacity, blockRefreshAll) { + if (this._paintOpacity === opacity) { + return false; + } + + const lastOpacity = this._paintOpacity; + this.setupPaintOpacity(opacity); + + if (this._paintOpacity === lastOpacity) { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Sets the paint opacity + * Changes the fill color + * Returns true if the change occurred * - * @param {Number} [opacity=this.standardPaintOpacity()] - Paint opacity + * @param {String} [color] - Fill color + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.prototype.standardPaintOpacity + * @see DKTools.Sprite.prototype.setupFillColor + * @see DKTools.Sprite.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.setupPaintOpacity = function(opacity) { - /** - * @private - * @readonly - * @type {Number} - */ - this._paintOpacity = (opacity == null ? this.standardPaintOpacity() : opacity); +DKTools.Sprite.prototype.setFillColor = function(color, blockRefreshAll) { + if (this._fillColor === color) { + return false; + } + + const lastColor = this._fillColor; + this.setupFillColor(color); + + if (this._fillColor === lastColor) { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Sets the fill color + * Changes the align + * Returns true if the change occurred * - * @param {String} [color=this.standardFillColor()] - Fill color + * @param {String} [align] - Text align + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.prototype.standardFillColor + * @see DKTools.Sprite.prototype.setupAlign + * @see DKTools.Sprite.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.setupFillColor = function(color) { - /** - * @private - * @readonly - * @type {String | null} - */ - this._fillColor = (color == null ? this.standardFillColor() : color); +DKTools.Sprite.prototype.setAlign = function(align, blockRefreshAll) { + if (this._align === align) { + return false; + } + + const lastAlign = this._align; + this.setupAlign(align); + + if (this._align === lastAlign) { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Sets the align + * Changes the opacity of the sprite + * Returns true if the change occurred * - * @param {String} [align=this.standardAlign()] - Text align + * @param {Number} [opacity] - Opacity of the sprite + * @param {Boolean} [blockUpdateOpacity=false] - Blocking the call of the "updateOpacity" function * - * @see DKTools.Sprite.prototype.standardAlign + * @see DKTools.Sprite.prototype.setupOpacity + * @see DKTools.Sprite.prototype.updateOpacity + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.setupAlign = function(align) { - /** - * @private - * @readonly - * @type {String} - */ - this._align = align || this.standardAlign(); +DKTools.Sprite.prototype.setOpacity = function(opacity, blockUpdateOpacity) { + if (this._opacity === opacity) { + return false; + } + + const lastOpacity = this._opacity; + this.setupOpacity(opacity); + + if (this._opacity === lastOpacity) { + return false; + } + + if (!blockUpdateOpacity) { + this.updateOpacity(); + } + + return true; }; /** - * Sets the opacity of the sprite + * Changes the graphic folder + * Returns true if the change occurred * - * @param {Number} [opacity=this.standardOpacity()] - Opacity + * @param {String} [graphicName] - Graphic folder + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @see DKTools.Sprite.prototype.standardOpacity + * @see DKTools.Sprite.prototype.setupGraphicFolder + * @see DKTools.Sprite.prototype.start + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.setupOpacity = function(opacity) { - /** - * @private - * @readonly - * @type {Number} - */ - this._opacity = (opacity == null ? this.standardOpacity() : opacity); +DKTools.Sprite.prototype.setGraphicFolder = function(folder, blockStart) { + if (this._graphicFolder === folder) { + return false; + } + + const lastFolder = this._graphicFolder; + this.setupGraphicFolder(folder); + + if (this._graphicFolder === lastFolder) { + return false; + } + + if (!blockStart) { + this.start(); + } + + return true; }; /** - * Sets the graphic folder + * Changes the graphic name + * Returns true if the change occurred * - * @param {String} [folder=this.standardGraphicFolder()] - Path to folder + * @param {String} [graphicName] - Graphic name + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @see DKTools.Sprite.prototype.standardGraphicFolder + * @see DKTools.Sprite.prototype.setupGraphicName + * @see DKTools.Sprite.prototype.start + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.setupGraphicFolder = function(folder) { - /** - * @private - * @readonly - * @type {String} - */ - this._graphicFolder = (folder == null ? this.standardGraphicFolder() : folder); -}; +DKTools.Sprite.prototype.setGraphicName = function(graphicName, blockStart) { + if (this._graphicName === graphicName) { + return false; + } + + const lastGraphic = this._graphicName; + this.setupGraphicName(graphicName); + + if (this._graphicName === lastGraphic) { + return false; + } -/** - * Sets the graphic name - * - * @param {String} [graphicName=this.standardGraphicName()] - Graphic name - * - * @see DKTools.Sprite.prototype.standardGraphicName - */ -DKTools.Sprite.prototype.setupGraphicName = function(graphicName) { - /** - * @private - * @readonly - * @type {String} - */ - this._graphicName = (graphicName == null ? this.standardGraphicName() : graphicName); + if (!blockStart) { + this.start(); + } + + return true; }; /** - * Sets the frame of the sprite + * Changes the frame of the sprite + * Returns true if the change occurred * - * @version 1.1.0 + * @override * * @param {Number | Rectangle | Object} [object] - The X coordinate or Rectangle or object with parameters * @param {Number} [y] - The Y coordinate (if object is Number) @@ -14971,1569 +15652,1655 @@ DKTools.Sprite.prototype.setupGraphicName = function(graphicName) { * @param {Number} [object.height] - Height of the frame * * @see DKTools.Utils.Rectangle.toRectangle - * @see DKTools.Sprite.prototype.standardFrame - * @see Sprite.prototype.setFrame - * @see DKTools.Sprite.prototype.hasFixedBitmap + * @see DKTools.Utils.Rectangle.equals + * @see DKTools.Utils.Rectangle.clone + * @see DKTools.Sprite.prototype.setupFrame + * @see DKTools.Utils.Rectangle.equals + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.setupFrame = function(object, y, width, height) { - const frame = DKTools.Utils.Rectangle.toRectangle(object, y, width, height); - const newFrame = Object.assign(this.standardFrame(), frame); - - Sprite.prototype.setFrame.call(this, newFrame.x, newFrame.y, newFrame.width, newFrame.height); +DKTools.Sprite.prototype.setFrame = function(object, y, width, height) { + if (object instanceof Object) { + return this.setFrame(object.x, object.y, object.width, object.height); + } - if (this.hasFixedBitmap() && !this.bitmap.isReady()) { - this._refreshFrame = true; + // object - Number + const newFrame = DKTools.Utils.Rectangle.toRectangle(object, y, width, height); + + if (DKTools.Utils.Rectangle.equals(this._frame, newFrame)) { + return false; } + + const lastFrame = DKTools.Utils.Rectangle.clone(this._frame); + this.setupFrame(newFrame); + + return !DKTools.Utils.Rectangle.equals(this._frame, lastFrame); }; /** - * Sets the anchor of the sprite + * Changes the anchor of the sprite + * Returns true if the change occurred * - * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object=this.standardAnchor()] - The X coordinate or Point or object with parameters + * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object] - The X coordinate or Point or object with parameters * @param {Number} [y=undefined] - The Y coordinate (is object is Number) * * @param {Number} [object.x] - The X coordinate * @param {Number} [object.y] - The Y coordinate * * @see DKTools.Utils.Point.toPoint - * @see DKTools.Sprite.prototype.standardAnchor + * @see DKTools.Utils.Point.clone + * @see DKTools.Sprite.prototype.setupAnchor + * @see DKTools.Utils.Point.equals + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.setupAnchor = function(object, y) { - const anchor = DKTools.Utils.Point.toPoint(object, y); - const newAnchor = Object.assign(this.standardAnchor(), anchor); +DKTools.Sprite.prototype.setAnchor = function(object, y) { + if (object instanceof Object) { + return this.setAnchor(object.x, object.y); + } - /** - * @type {PIXI.ObservablePoint} - */ - this.anchor.copy(newAnchor); + // object - Number + const newAnchor = DKTools.Utils.Point.toPoint(object, y); + + if (DKTools.Utils.Point.equals(this.anchor, newAnchor)) { + return false; + } + + const lastAnchor = DKTools.Utils.Point.clone(this.anchor); + this.setupAnchor(newAnchor); + + return !DKTools.Utils.Point.equals(this.anchor, lastAnchor); }; /** - * Sets the mask + * Changes the mask + * Returns true if the change occurred * * @since 2.0.0 * @param {PIXI.Graphics} [mask] - Mask + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.setupMask = function(mask) { - this.mask = mask || null; +DKTools.Sprite.prototype.setMask = function(mask) { + if (this.mask == mask) { + return false; + } + + this.setupMask(mask); + + return true; }; +// remove methods + /** - * Sets the listener on load of graphic - * - * @param {Function} listener - Listener + * Removes the bitmap + * + * @see DKTools.Sprite.prototype.hasBitmap + * @see DKTools.Sprite.prototype.setBitmap */ -DKTools.Sprite.prototype.setupGraphicLoadListener = function(listener) { - /** - * @private - * @readonly - * @type {Function} - */ - this._graphicLoadListener = listener || null; +DKTools.Sprite.prototype.removeBitmap = function() { + if (this.hasBitmap()) { + this.setBitmap(); + } }; -// set methods - /** - * Changes all parameters - * Returns the number of changed parameters - * - * @override - * - * @param {Object} [object={}] - Parameters - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * @param {Boolean} [activate=false] - Activates the sprite - * - * @param {Object} [object.font] - Text font - * @param {String} [object.textColor] - Text color - * @param {Number} [object.paintOpacity] - Paint opacity - * @param {String} [object.fillColor] - Fill color - * @param {String} [object.align] - Text align - * @param {Number} [object.opacity] - Opacity - * @param {String} [object.graphicFolder] - Graphic folder - * @param {String} [object.graphicName] - Graphic name - * - * @param {String} [object.font.fontFace] - Название шрифта - * @param {Number} [object.font.fontSize] - Размер шрифта - * @param {Boolean} [object.font.fontItalic] - Курсив шрифта - * - * @see DKTools.Base.prototype.setAll - * @see DKTools.Sprite.prototype.setFont - * @see DKTools.Sprite.prototype.setTextColor - * @see DKTools.Sprite.prototype.setPaintOpacity - * @see DKTools.Sprite.prototype.setFillColor - * @see DKTools.Sprite.prototype.setAlign - * @see DKTools.Sprite.prototype.setOpacity - * @see DKTools.Sprite.prototype.setGraphicFolder + * Removes the graphic name + * + * @see DKTools.Sprite.prototype.hasGraphicName * @see DKTools.Sprite.prototype.setGraphicName - * @see DKTools.Sprite.prototype.start - * @see DKTools.Sprite.prototype.activate - * - * @returns {Number} Number of changed parameters -*/ -DKTools.Sprite.prototype.setAll = function(object, blockStart, activate) { - object = object || {}; - const block = true; - let changed = DKTools.Base.prototype.setAll.call(this, object, block); - - if (this.setFont(object.font, block)) { - changed++; + */ +DKTools.Sprite.prototype.removeGraphicName = function() { + if (this.hasGraphicName()) { + this.setGraphicName(); } +}; - if (this.setTextColor(object.textColor, block)) { - changed++; - } +/** + * Removes the text by ID + * + * @param {Number | String | *} id - ID of the text + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.prototype.getTextById + * @see DKTools.Sprite.prototype.refreshAll + * @see DKTools.Utils.Array.remove + */ +DKTools.Sprite.prototype.removeText = function(id, blockRefreshAll) { + const textObj = this.getTextById(id); - if (this.setPaintOpacity(object.paintOpacity, block)) { - changed++; - } + if (textObj) { + DKTools.Utils.Array.remove(this._texts, textObj); - if (this.setFillColor(object.fillColor, block)) { - changed++; + if (!blockRefreshAll) { + this.refreshAll(); + } } +}; - if (this.setAlign(object.align, block)) { - changed++; - } +// check methods - if (this.setOpacity(object.opacity, block)) { - changed++; - } +/** + * Checks the size of the sprirte + * Returns the number of changed parameters + * + * @override + * + * @see DKTools.Sprite.prototype.getMinWidth + * @see DKTools.Sprite.prototype.getMinHeight + * @see DKTools.Sprite.prototype.setupWidth + * @see DKTools.Sprite.prototype.setupHeight + * + * @returns {Number} Number of changed parameters + */ +DKTools.Sprite.prototype.checkSize = function() { + const minWidth = this.getMinWidth(); + const minHeight = this.getMinHeight(); + let changed = 0; - if (this.setGraphicFolder(object.graphicFolder), block) { + if (this._bitmapWidth < minWidth) { + this.setupWidth(minWidth); changed++; } - if (this.setGraphicName(object.graphicName, block)) { + if (this._bitmapHeight < minHeight) { + this.setupHeight(minHeight); changed++; } - if (changed) { - if (!blockStart) { - this.start(); - } - - if (activate) { - this.activate(); - } - } - - return changed; -}; - -/** - * Changes the width of the bitmap - * Returns true if the change occurred - * - * @param {Number} [width] - Width of the bitmap - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * - * @see DKTools.Sprite.prototype.resize - * - * @returns {Boolean} Change occurred - */ -DKTools.Sprite.prototype.setWidth = function(width, blockStart) { - return this.resize(width, this._bitmapHeight, blockStart); + return changed; }; +// create methods + /** - * hanges the width of the bitmap - * Returns true if the change occurred + * Creates all objects * - * @param {Number} [height] - Height of the bitmap - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @version 2.0.0 * - * @see DKTools.Sprite.prototype.resize + * @override * - * @returns {Boolean} Change occurred + * @see DKTools.Base.prototype.createAll + * @see DKTools.Sprite.prototype.createBitmap + * @see DKTools.Sprite.prototype.createMask */ -DKTools.Sprite.prototype.setHeight = function(height, blockStart) { - return this.resize(this._bitmapWidth, height, blockStart); +DKTools.Sprite.prototype.createAll = function() { + DKTools.Base.prototype.createAll.call(this); + this.createBitmap(); + this.createMask(); }; /** - * Changes the bitmap - * Returns true if the change occurred - * - * @param {Bitmap | Object} [object] - Bitmap or object with parameters - * - * @param {String} object.folder - Path to file - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap + * Loads an image by graphic name (if exists) or create the bitmap (if the fixed bitmap does not exist) * - * @see DKTools.Sprite.prototype.setupBitmap + * @version 1.1.0 * - * @returns {Boolean} Change occurred + * @see DKTools.Sprite.prototype.hasGraphicName + * @see DKTools.Sprite.prototype._loadGraphic + * @see DKTools.Sprite.prototype.hasFixedBitmap + * @see DKTools.Sprite.prototype._getBitmapWidth + * @see DKTools.Sprite.prototype._getBitmapHeight + * @see Bitmap */ -DKTools.Sprite.prototype.setBitmap = function(object) { - if (this.bitmap == object) { - return false; +DKTools.Sprite.prototype.createBitmap = function() { + if (this.hasGraphicName()) { + this._loadGraphic(); + } else if (!this.hasFixedBitmap()) { + this.bitmap = new Bitmap(this._getBitmapWidth(), this._getBitmapHeight()); } - - this.setupBitmap(object); - - return true; }; /** - * Changes the font of the bitmap - * Returns true if the change occurred - * - * @param {Object} [font] - Text font - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * - * @param {String} [object.font.fontFace] - Font face - * @param {Number} [object.font.fontSize] - Font size - * @param {Boolean} [object.font.fontItalic] - Font italic - * - * @see DKTools.Sprite.prototype.standardFont - * @see DKTools.Sprite.prototype.setupFont - * @see DKTools.Sprite.prototype.start - * - * @returns {Boolean} Change occurred + * Creates a mask + * + * @since 2.0.0 + * + * @see DKTools.Sprite.prototype.createRectMask + * @see DKTools.Sprite.prototype.createCircleMask + * @see DKTools.Sprite.prototype.createEllipseMask */ -DKTools.Sprite.prototype.setFont = function(font, blockStart) { - if (_.isEqual(this._font, Object.assign(this.standardFont(), font))) { - return false; +DKTools.Sprite.prototype.createMask = function(maskShape) { + switch (maskShape) { + case 'rect': + this.createRectMask(); + break; + case 'circle': + this.createCircleMask(); + break; + case 'ellipse': + this.createEllipseMask(); + break; } +}; - this.setupFont(font); +/** + * Creates a mask in the form of a rectangle + * + * @since 2.0.0 + * + * @see DKTools.Sprite.prototype.setMask + * @see PIXI.Graphics + */ +DKTools.Sprite.prototype.createRectMask = function() { + const mask = new PIXI.Graphics(); - if (!blockStart) { - this.start(); - } + mask.beginFill(); + mask.drawRect(this.x, this.y, this.bitmap.width, this.bitmap.height); + mask.endFill(); - return true; + this.setMask(mask); }; /** - * Changes the text color - * Returns true if the change occurred - * - * @param {String} [color] - Text color - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.prototype.setupTextColor - * @see DKTools.Sprite.prototype.refreshAll + * Creates a mask in the form of a circle * - * @returns {Boolean} Change occurred + * @since 2.0.0 + * + * @see DKTools.Sprite.prototype.setMask + * @see PIXI.Graphics */ -DKTools.Sprite.prototype.setTextColor = function(color, blockRefreshAll) { - if (this._textColor === color) { - return false; - } +DKTools.Sprite.prototype.createCircleMask = function() { + const mask = new PIXI.Graphics(); + const radius = this.bitmap.width / 2; + const centerX = this.x + radius; + const centerY = this.y + radius; - const lastColor = this._textColor; - this.setupTextColor(color); + mask.beginFill(); + mask.drawCircle(centerX, centerY, radius); + mask.endFill(); - if (this._textColor === lastColor) { - return false; - } + this.setMask(mask); +}; - if (!blockRefreshAll) { - this.refreshAll(); - } +/** + * Creates a mask in the form of an ellipse + * + * @since 2.0.0 + * + * @see DKTools.Sprite.prototype.setMask + * @see PIXI.Graphics + */ +DKTools.Sprite.prototype.createEllipseMask = function() { + const mask = new PIXI.Graphics(); + const width = this.bitmap.width / 2; + const height = this.bitmap.height / 2; + const centerX = this.x + width; + const centerY = this.y + height; - return true; + mask.beginFill(); + mask.drawEllipse(centerX, centerY, width, height); + mask.endFill(); + + this.setMask(mask); }; +// add methods + /** - * Changes the paint opacity - * Returns true if the change occurred + * Adds the text * - * @param {Number} [opacity] - Paint opacity - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * @param {String | Number} text - Text + * @param {Object} options - Options + * @param {Boolean} [refreshAll=false] - Refreshes all * - * @see DKTools.Sprite.prototype.setupPaintOpacity - * @see DKTools.Sprite.prototype.refreshAll + * @param {String | Number} [options.id] - ID of the text + * @param {String} [options.type='drawText'] - Type of the text ('drawText' or 'drawTextEx') * - * @returns {Boolean} Change occurred + * @see DKTools.Sprite.prototype.drawTextEx + * @see DKTools.Sprite.prototype.drawText */ -DKTools.Sprite.prototype.setPaintOpacity = function(opacity, blockRefreshAll) { - if (this._paintOpacity === opacity) { - return false; +DKTools.Sprite.prototype.addText = function(text, options, refreshAll) { + if (text == null) { + return; } - const lastOpacity = this._paintOpacity; - this.setupPaintOpacity(opacity); + text = String(text); + options = options || {}; - if (this._paintOpacity === lastOpacity) { - return false; - } + this._texts.push({ + text, + options, + id: options.id, + type: options.type || 'drawText' + }); - if (!blockRefreshAll) { + if (refreshAll) { this.refreshAll(); } - - return true; }; +// redraw methods + /** - * Changes the fill color - * Returns true if the change occurred - * - * @param {String} [color] - Fill color - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.prototype.setupFillColor - * @see DKTools.Sprite.prototype.refreshAll + * Redraws all * - * @returns {Boolean} Change occurred + * @version 1.1.0 + * @override + * + * @see DKTools.Sprite.prototype.clear + * @see DKTools.Sprite.prototype.drawAll + * @see DKTools.Sprite.prototype.updateRedrawAllEvents */ -DKTools.Sprite.prototype.setFillColor = function(color, blockRefreshAll) { - if (this._fillColor === color) { - return false; - } +DKTools.Sprite.prototype.redrawAll = function() { + this.clear(); + this.drawAll(); + this.updateRedrawAllEvents(); +}; - const lastColor = this._fillColor; - this.setupFillColor(color); +// _get methods - if (this._fillColor === lastColor) { - return false; - } +/** + * Returns the width of the bitmap + * + * @since 2.0.0 + * @private + * @returns {Number} Width of the bitmap + */ +DKTools.Sprite.prototype._getBitmapWidth = function() { + return this._bitmapWidth; +}; - if (!blockRefreshAll) { - this.refreshAll(); - } +/** + * Returns the height of the bitmap + * + * @since 2.0.0 + * @private + * @returns {Number} Height of the bitmap + */ +DKTools.Sprite.prototype._getBitmapHeight = function() { + return this._bitmapHeight; +}; + +// get methods + +/** + * Returns an object of text by its ID + * + * @param {Number | String | *} id - ID of object of text + * @returns {Object} Object of text + */ +DKTools.Sprite.prototype.getTextById = function(id) { + return _.find(this._texts, { id }); +}; - return true; +/** + * Returns the current opacity of the sprite + * + * @returns {Number} Current opacity of the sprite + */ +DKTools.Sprite.prototype.getCurrentOpacity = function() { + return this.alpha * 255; }; +// size methods + /** - * Changes the align + * Changes the width and height of the sprite * Returns true if the change occurred * - * @param {String} [align] - Text align - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * @param {Number} [width] - Width of the sprite + * @param {Number | String} [height] - Height of the sprite or number of lines + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @see DKTools.Sprite.prototype.setupAlign - * @see DKTools.Sprite.prototype.refreshAll + * @see DKTools.Sprite.prototype.isResizable + * @see DKTools.Sprite.prototype.getMinWidth + * @see DKTools.Sprite.prototype.getMinHeight + * @see DKTools.Sprite.prototype.setupSize + * @see DKTools.Sprite.prototype.start * * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.setAlign = function(align, blockRefreshAll) { - if (this._align === align) { +DKTools.Sprite.prototype.resize = function(width, height, blockStart) { + if (!this.isResizable()) { return false; } - const lastAlign = this._align; - this.setupAlign(align); + width = (width == null ? this.getMinWidth() : width); + height = (height == null ? this.getMinHeight() : height); - if (this._align === lastAlign) { - return false; + if (DKTools.Utils.isString(height)) { + height = this.getLineHeight() * Number(height); } - if (!blockRefreshAll) { - this.refreshAll(); + if (this._bitmapWidth === width && this._bitmapHeight === height) { + return false; } - return true; -}; + const lastWidth = this._bitmapWidth; + const lastHeight = this._bitmapHeight; -/** - * Changes the opacity of the sprite - * Returns true if the change occurred - * - * @param {Number} [opacity] - Opacity of the sprite - * @param {Boolean} [blockUpdateOpacity=false] - Blocking the call of the "updateOpacity" function - * - * @see DKTools.Sprite.prototype.setupOpacity - * @see DKTools.Sprite.prototype.updateOpacity - * - * @returns {Boolean} Change occurred -*/ -DKTools.Sprite.prototype.setOpacity = function(opacity, blockUpdateOpacity) { - if (this._opacity === opacity) { - return false; - } + this.setupSize(width, height); - const lastOpacity = this._opacity; - this.setupOpacity(opacity); - - if (this._opacity === lastOpacity) { - return false; + if (this._bitmapWidth === lastWidth && this._bitmapHeight === lastHeight) { + return false; } - if (!blockUpdateOpacity) { - this.updateOpacity(); + if (!blockStart) { + this.start(); } - return true; + return true; }; +// can methods + /** - * Changes the graphic folder - * Returns true if the change occurred + * Returns true if the sprite can be updated and redrawn * - * @param {String} [graphicName] - Graphic folder - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @since 1.1.0 * - * @see DKTools.Sprite.prototype.setupGraphicFolder - * @see DKTools.Sprite.prototype.start + * @override * - * @returns {Boolean} Change occurred + * @see DKTools.Base.prototype.canRedrawAll + * @see DKTools.Sprite.prototype.hasGraphicName + * @see DKTools.Sprite.prototype.hasFixedBitmap + * + * @returns {Boolean} Sprite can be updated and redrawn */ -DKTools.Sprite.prototype.setGraphicFolder = function(folder, blockStart) { - if (this._graphicFolder === folder) { - return false; - } +DKTools.Sprite.prototype.canRedrawAll = function() { + return DKTools.Base.prototype.canRedrawAll.call(this) && !this.hasGraphicName() && !this.hasFixedBitmap(); +}; - const lastFolder = this._graphicFolder; - this.setupGraphicFolder(folder); +/** + * Returns true if the sprite can clone the fixed bitmap + * + * @returns {Boolean} Sprite can clone the fixed bitmap + */ +DKTools.Sprite.prototype.canCloneFixedBitmap = function() { + return true; +}; - if (this._graphicFolder === lastFolder) { +// effects methods + +/** + * Changes the tone of the bitmap + * Returns true if bitmap exists + * + * @param {Number[]} tone - Tone (RGB) + * + * @see DKTools.Sprite.prototype.hasBitmap + * @see Bitmap.prototype.adjustTone + * + * @returns {Boolean} Bitmap exists + */ +DKTools.Sprite.prototype.adjustTone = function(tone) { + if (!this.hasBitmap()) { return false; } - if (!blockStart) { - this.start(); + if (DKTools.Utils.Array.isNumberArray(tone) && tone.length === 3) { + Bitmap.prototype.adjustTone.apply(this.bitmap, tone); + return true; } - return true; + return false; }; /** - * Changes the graphic name - * Returns true if the change occurred - * - * @param {String} [graphicName] - Graphic name - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * - * @see DKTools.Sprite.prototype.setupGraphicName - * @see DKTools.Sprite.prototype.start + * Rotates the hue of the bitmap + * Returns true if bitmap exists * - * @returns {Boolean} Change occurred + * @param {Number} offset - Offset + * + * @see DKTools.Sprite.prototype.hasBitmap + * @see Bitmap.prototype.rotateHue + * + * @returns {Boolean} Bitmap exists */ -DKTools.Sprite.prototype.setGraphicName = function(graphicName, blockStart) { - if (this._graphicName === graphicName) { +DKTools.Sprite.prototype.rotateHue = function(offset) { + if (!this.hasBitmap()) { return false; } - const lastGraphic = this._graphicName; - this.setupGraphicName(graphicName); + this.bitmap.rotateHue(offset); - if (this._graphicName === lastGraphic) { + return true; +}; + +/** + * Imposes a blur effect on the bitmap + * Returns true if bitmap exists + * + * @see DKTools.Sprite.prototype.hasBitmap + * @see Bitmap.prototype.blur + * + * @returns {Boolean} Bitmap exists + */ +DKTools.Sprite.prototype.blur = function() { + if (!this.hasBitmap()) { return false; } - if (!blockStart) { - this.start(); - } + this.bitmap.blur(); return true; }; +// change methods + /** - * Changes the frame of the sprite - * Returns true if the change occurred - * - * @override - * - * @param {Number | Rectangle | Object} [object] - The X coordinate or Rectangle or object with parameters - * @param {Number} [y] - The Y coordinate (if object is Number) - * @param {Number} [width] - Width of the frame (if object is Number) - * @param {Number} [height] - Height of the frame (if object is Number) + * Changes the font of the bitmap * - * @param {Number} [object.x] - The X coordinate - * @param {Number} [object.y] - The Y coordinate - * @param {Number} [object.width] - Width of the frame - * @param {Number} [object.height] - Height of the frame + * @param {Object} font - Text font * - * @see DKTools.Utils.Rectangle.toRectangle - * @see DKTools.Utils.Rectangle.equals - * @see DKTools.Utils.Rectangle.clone - * @see DKTools.Sprite.prototype.setupFrame - * @see DKTools.Utils.Rectangle.equals + * @param {String} [object.font.fontFace] - Font face + * @param {Number} [object.font.fontSize] - Font size + * @param {Boolean} [object.font.fontItalic] - Font italic * - * @returns {Boolean} Change occurred + * @see DKTools.Sprite.prototype.hasBitmap + * @see DKTools.Sprite.prototype.updateFont */ -DKTools.Sprite.prototype.setFrame = function(object, y, width, height) { - if (object instanceof Object) { - return this.setFrame(object.x, object.y, object.width, object.height); - } - - // object - Number - const newFrame = DKTools.Utils.Rectangle.toRectangle(object, y, width, height); - - if (DKTools.Utils.Rectangle.equals(this._frame, newFrame)) { - return false; +DKTools.Sprite.prototype.changeFont = function(font) { + if (this.hasBitmap()) { + this.updateFont(font); } - - const lastFrame = DKTools.Utils.Rectangle.clone(this._frame); - this.setupFrame(newFrame); - - return !DKTools.Utils.Rectangle.equals(this._frame, lastFrame); }; /** - * Changes the anchor of the sprite - * Returns true if the change occurred - * - * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object] - The X coordinate or Point or object with parameters - * @param {Number} [y=undefined] - The Y coordinate (is object is Number) - * - * @param {Number} [object.x] - The X coordinate - * @param {Number} [object.y] - The Y coordinate + * Changes the text color * - * @see DKTools.Utils.Point.toPoint - * @see DKTools.Utils.Point.clone - * @see DKTools.Sprite.prototype.setupAnchor - * @see DKTools.Utils.Point.equals + * @param {String} textColor - Text color * - * @returns {Boolean} Change occurred + * @see DKTools.Sprite.prototype.hasBitmap + * @see DKTools.Sprite.prototype.updateTextColor */ -DKTools.Sprite.prototype.setAnchor = function(object, y) { - if (object instanceof Object) { - return this.setAnchor(object.x, object.y); +DKTools.Sprite.prototype.changeTextColor = function(textColor) { + if (this.hasBitmap()) { + this.updateTextColor(textColor); } +}; - // object - Number - const newAnchor = DKTools.Utils.Point.toPoint(object, y); - - if (DKTools.Utils.Point.equals(this.anchor, newAnchor)) { - return false; +/** + * Changes the paint opacity + * + * @param {Number} paintOpacity - Paint opacity + * + * @see DKTools.Sprite.prototype.hasBitmap + * @see DKTools.Sprite.prototype.updatePaintOpacity + */ +DKTools.Sprite.prototype.changePaintOpacity = function(paintOpacity) { + if (this.hasBitmap()) { + this.updatePaintOpacity(paintOpacity); } +}; - const lastAnchor = DKTools.Utils.Point.clone(this.anchor); - this.setupAnchor(newAnchor); +// reset methods - return !DKTools.Utils.Point.equals(this.anchor, lastAnchor); +/** + * Resets all + * + * @see DKTools.Sprite.prototype.resetFont + * @see DKTools.Sprite.prototype.resetTextColor + * @see DKTools.Sprite.prototype.resetPaintOpacity + */ +DKTools.Sprite.prototype.resetAll = function() { + this.resetFont(); + this.resetTextColor(); + this.resetPaintOpacity(); }; /** - * Changes the mask - * Returns true if the change occurred - * - * @since 2.0.0 - * @param {PIXI.Graphics} [mask] - Mask - * - * @returns {Boolean} Change occurred + * Resets the font + * + * @see DKTools.Sprite.prototype.changeFont */ -DKTools.Sprite.prototype.setMask = function(mask) { - if (this.mask == mask) { - return false; - } +DKTools.Sprite.prototype.resetFont = function() { + this.changeFont(this.font); +}; - this.setupMask(mask); +/** + * Resets the text color + * + * @see DKTools.Sprite.prototype.changeTextColor + */ +DKTools.Sprite.prototype.resetTextColor = function() { + this.changeTextColor(this.textColor); +}; - return true; +/** + * Resets the paint opacity + * + * @see DKTools.Sprite.prototype.changePaintOpacity + */ +DKTools.Sprite.prototype.resetPaintOpacity = function() { + this.changePaintOpacity(this.paintOpacity); }; -// remove methods +// has methods /** - * Removes the bitmap + * Returns true if the sprite has fixed bitmap (setted using setupBitmap or setBitmap) + * + * @since 1.1.0 + * @returns {Boolean} Sprite has fixed bitmap (setted using setupBitmap or setBitmap) */ -DKTools.Sprite.prototype.removeBitmap = function() { - if (this.hasBitmap()) { - this.setBitmap(null); - } +DKTools.Sprite.prototype.hasFixedBitmap = function() { + return !!this._fixedBitmap; }; /** - * Removes the graphic name + * Returns true if the sprite has the fill color + * + * @returns {Boolean} Sprite has the fill color */ -DKTools.Sprite.prototype.removeGraphicName = function() { - if (this.hasGraphicName()) { - this.setGraphicName(null); - } +DKTools.Sprite.prototype.hasFillColor = function() { + return !!this._fillColor; }; /** - * Removes the text by ID + * Returns true if the sprite has the texts * - * @param {Number | String | *} id - ID of the text - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * @returns {Boolean} Sprite has the texts + */ +DKTools.Sprite.prototype.hasTexts = function() { + return this._texts.length > 0; +}; + +/** + * Returns true if the sprite has the graphic folder * - * @see DKTools.Sprite.prototype.getTextById - * @see DKTools.Utils.Array.remove - * @see DKTools.Sprite.prototype.refreshAll + * @returns {Boolean} Sprite has the graphic folder */ -DKTools.Sprite.prototype.removeText = function(id, blockRefreshAll) { - const textObj = this.getTextById(id); +DKTools.Sprite.prototype.hasGraphicFolder = function() { + return !!this._graphicFolder; +}; - if (textObj) { - DKTools.Utils.Array.remove(this._texts, textObj); - if (!blockRefreshAll) { - this.refreshAll(); - } - } +/** + * Returns true if the sprite has the graphic name + * + * @returns {Boolean} Sprite has the graphic name + */ +DKTools.Sprite.prototype.hasGraphicName = function() { + return !!this._graphicName; }; -// check methods +// is methods /** - * Checks the size of the sprirte - * Returns the number of changed parameters + * Returns true if you can change the size of the sprite + * + * @version 1.1.0 + * + * @see DKTools.Sprite.prototype.hasGraphicName + * @see DKTools.Sprite.prototype.hasFixedBitmap + * + * @returns {Boolean} You can change the size of the sprite + */ +DKTools.Sprite.prototype.isResizable = function() { + return !this.hasGraphicName() && !this.hasFixedBitmap(); +}; + +/** + * Returns true if the coordinates is inside the sprite * * @override * - * @see DKTools.Sprite.prototype.getMinWidth - * @see DKTools.Sprite.prototype.getMinHeight - * @see DKTools.Sprite.prototype.setupWidth - * @see DKTools.Sprite.prototype.setupHeight + * @param {Number} x - The X coordinate + * @param {Number} y - The Y coordinate + * + * @see DKTools.Sprite.prototype.canvasToLocalX + * @see DKTools.Sprite.prototype.canvasToLocalY * - * @returns {Number} Number of changed parameters + * @returns {Boolean} Coordinates is inside the sprite */ -DKTools.Sprite.prototype.checkSize = function() { - const minWidth = this.getMinWidth(); - const minHeight = this.getMinHeight(); - let changed = 0; +DKTools.Sprite.prototype.isInside = function(x, y) { + const localX = this.canvasToLocalX(x); + const localY = this.canvasToLocalY(y); + const width = this.width; + const height = this.height; + const anchor = this.anchor; + const frame = new Rectangle(-width * anchor.x, -height * anchor.y, width, height); - if (this._bitmapWidth < minWidth) { - this.setupWidth(minWidth); - changed++; - } + return frame.contains(localX, localY); +}; - if (this._bitmapHeight < minHeight) { - this.setupHeight(minHeight); - changed++; - } +// draw methods - return changed; +/** + * Draws all + * + * @version 1.1.0 + * @override + * + * @see DKTools.Sprite.prototype.updateFill + * @see DKTools.Sprite.prototype.drawAllTexts + * @see DKTools.Sprite.prototype.updateDrawAllEvents + */ +DKTools.Sprite.prototype.drawAll = function() { + this.updateFill(); + this.drawAllTexts(); + this.updateDrawAllEvents(); }; -// create methods +/** + * Draws all texts + */ +DKTools.Sprite.prototype.drawAllTexts = function() { + _.forEach(this._texts, function(obj) { + this[obj.type](obj.text, obj.options); + }.bind(this)); +}; /** - * Creates all objects + * Draws the text + * Returns true if bitmap exists * - * @version 2.0.0 + * @param {String} text - Text + * @param {Object} [options={}] - Options for drawing * - * @override + * @param {Object} [options.font=this.font] - Use custom font + * @param {String} [options.textColor=this.textColor] - Use custom text color + * @param {Number} [options.paintOpacity=this.paintOpacity] - Use custom paint opacity + * @param {String} [options.align=this.align] - Align + * @param {Boolean} [options.resetFont=false] - Use standard font after drawing the text + * @param {String} [options.resetTextColor=false] - Use standard text color after drawing the text + * @param {String} [options.resetPaintOpacity=false] - Use standard paint opacity after drawing the text + * @param {Number} [options.x=0] - The X coordinate + * @param {Number | String} [options.y=0] - The Y coordinate or line number (String) + * @param {Number | String} [options.width=this.standardDrawingWidth()] - Width of the rectangle + * @param {Number | String} [options.height=this.getLineHeight()] - Height of the rectangle or number of lines (String) + * @param {PIXI.Point | PIXI.ObservablePoint | Point | Object} [options.pos] - Position of the text (ignores other parameters of position: x, y, width, height) + * @param {PIXI.Rectangle | Rectangle | Object} [options.rect] - Rectangle for drawing (ignores other parameters of position: x, y, width, height, pos) * - * @see DKTools.Base.prototype.createAll - * @see DKTools.Sprite.prototype.createBitmap - * @see DKTools.Sprite.prototype.createMask + * @param {Number} [options.pos.x=0] - The X coordinate + * @param {Number | String} [options.pos.y=0] - The Y coordinate or line number (String) + * + * @param {Number} [options.rect.x=0] - The X coordinate + * @param {Number | String} [options.rect.y=0] - The Y coordinate or line number (String) + * @param {Number | String} [options.rect.width=this.standardDrawingWidth()] - Width of the rectangle + * @param {Number | String} [options.rect.height=this.getLineHeight()] - Height of the rectangle or number of lines (String) + * + * @example + * var sprite = new DKTools.Sprite(0, 0, 100, 36); + * sprite.start(); + * sprite.drawText('Text', { + * y: '1' + * }); + * + * @see DKTools.Base.prototype.hasBitmap + * @see DKTools.Sprite.prototype.changeFont + * @see DKTools.Sprite.prototype.changeTextColor + * @see DKTools.Sprite.prototype.changePaintOpacity + * @see DKTools.Base.prototype.standardDrawingWidth + * @see DKTools.Base.prototype.standardDrawingHeight + * @see DKTools.Base.prototype.getLineHeight + * @see DKTools.Sprite.prototype.resetFont + * @see DKTools.Sprite.prototype.resetTextColor + * @see DKTools.Sprite.prototype.resetPaintOpacity + * @see Bitmap.prototype.drawText + * + * @returns {Boolean} Bitmap exists */ -DKTools.Sprite.prototype.createAll = function() { - DKTools.Base.prototype.createAll.call(this); - this.createBitmap(); - this.createMask(); -}; +DKTools.Sprite.prototype.drawText = function(text, options) { + text = String(text); + options = options || {}; + + if (!this.hasBitmap() || !text) { + return false; + } + + if (options.font) { + this.changeFont(options.font); + } + + if (options.textColor) { + this.changeTextColor(options.textColor); + } + + if (options.paintOpacity) { + this.changePaintOpacity(options.paintOpacity); + } + + let x = options.x; + let y = options.y; + let width = options.width; + let height = options.height; + const pos = options.pos; + const rect = options.rect; -/** - * Loads an image by graphic name (if exists) or create the bitmap (if the fixed bitmap does not exist) - * - * @version 1.1.0 - * - * @see DKTools.Sprite.prototype.hasGraphicName - * @see DKTools.Sprite.prototype._loadGraphic - * @see DKTools.Sprite.prototype.hasFixedBitmap - * @see Bitmap - */ -DKTools.Sprite.prototype.createBitmap = function() { - if (this.hasGraphicName()) { - this._loadGraphic(); - } else if (!this.hasFixedBitmap()) { - this.bitmap = new Bitmap(this._getBitmapWidth(), this._getBitmapHeight()); + if (pos instanceof Object) { + x = pos.x; + y = pos.y; } -}; -/** - * Creates a mask - * - * @since 2.0.0 - */ -DKTools.Sprite.prototype.createMask = function(maskShape) { - switch (maskShape) { - case 'rect': - this.createRectMask(); - break; - case 'circle': - this.createCircleMask(); - break; - case 'ellipse': - this.createEllipseMask(); - break; + if (rect instanceof Object) { + x = rect.x; + y = rect.y; + width = rect.width; + height = rect.height; } -}; -/** - * Creates a mask in the form of a rectangle - * - * @since 2.0.0 - */ -DKTools.Sprite.prototype.createRectMask = function() { - const mask = new PIXI.Graphics(); + if (DKTools.Utils.isString(y)) { // line number + y = this.getLineHeight() * Number(y); + } - mask.beginFill(); - mask.drawRect(this.x, this.y, this.bitmap.width, this.bitmap.height); - mask.endFill(); + if (DKTools.Utils.isString(height)) { // number of lines + height = this.getLineHeight() * Number(height); + } - this.setMask(mask); -}; + x = x || 0; + y = y || 0; + width = width || this.standardDrawingWidth(); + height = height || this.getLineHeight(); -/** - * Creates a mask in the form of a circle - * - * @since 2.0.0 - */ -DKTools.Sprite.prototype.createCircleMask = function() { - const mask = new PIXI.Graphics(); - const radius = this.bitmap.width / 2; - const centerX = this.x + radius; - const centerY = this.y + radius; + const align = options.align || this.align; - mask.beginFill(); - mask.drawCircle(centerX, centerY, radius); - mask.endFill(); + this.bitmap.drawText(text, x, y, width, height, align); - this.setMask(mask); -}; + if (options.resetFont) { + this.resetFont(); + } -/** - * Creates a mask in the form of an ellipse - * - * @since 2.0.0 - */ -DKTools.Sprite.prototype.createEllipseMask = function() { - const mask = new PIXI.Graphics(); - const width = this.bitmap.width / 2; - const height = this.bitmap.height / 2; - const centerX = this.x + width; - const centerY = this.y + height; + if (options.resetTextColor) { + this.resetTextColor(); + } - mask.beginFill(); - mask.drawEllipse(centerX, centerY, width, height); - mask.endFill(); + if (options.resetPaintOpacity) { + this.resetPaintOpacity(); + } - this.setMask(mask); + return true; }; -// add methods +// load methods /** - * Adds the text + * Loads a bitmap + * Returns true if the bitmap of the sprite has been changed * - * @param {String | Number} text - Text - * @param {Object} options - Options - * @param {Boolean} [refreshAll=false] - Refreshes all + * @version 3.0.0 * - * @param {String | Number} [options.id] - ID of the text - * @param {String} [options.type='drawText'] - Type of the text ('drawText' or 'drawTextEx') + * @param {String | Object} object - Path to file or object with parameters + * @param {String} filename - Name of file + * @param {Function} [listener] - Function of processing after loading a bitmap + * @param {Number} [hue] - Hue of bitmap + * @param {Boolean} [smooth] - Smooth of bitmap * - * @see DKTools.Sprite.prototype.drawTextEx - * @see DKTools.Sprite.prototype.drawText + * @param {String} object.folder - Path to file + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see DKTools.Sprite.prototype.setBitmap + * @see DKTools.Utils.Bitmap.load + * + * @returns {Boolean} Bitmap of the sprite has been changed */ -DKTools.Sprite.prototype.addText = function(text, options, refreshAll) { - text = String(text); - options = options || {}; - - this._texts.push({ - text, - options, - id: options.id, - type: options.type || 'drawText' - }); - - if (refreshAll) { - this.refreshAll(); +DKTools.Sprite.prototype.loadBitmap = function(object, filename, listener, hue, smooth) { + if (object instanceof Object) { + return this.loadBitmap(object.folder, object.filename, object.listener, object.hue, object.smooth); } -}; -// redraw methods - -/** - * Redraws all - * - * @version 1.1.0 - * @override - */ -DKTools.Sprite.prototype.redrawAll = function() { - this.clear(); - this.drawAll(); - this.updateRedrawAllEvents(); -}; + // object - String (folder) + const bitmap = DKTools.Utils.Bitmap.load(object, filename, hue, smooth); -// _get methods + if (this.setBitmap(bitmap)) { + if (listener) { + this.bitmap.addLoadListener(listener); + } -/** - * Returns the width of the bitmap - * - * @since 2.0.0 - * @private - * @returns {Number} Width of the bitmap - */ -DKTools.Sprite.prototype._getBitmapWidth = function() { - return this._bitmapWidth; -}; + return true; + } -/** - * Returns the height of the bitmap - * - * @since 2.0.0 - * @private - * @returns {Number} Height of the bitmap - */ -DKTools.Sprite.prototype._getBitmapHeight = function() { - return this._bitmapHeight; + return false; }; -// get methods +// reserve methods /** - * Returns an object of text by its ID - * + * Loads and reserves a bitmap + * Returns true if the bitmap of the sprite has been changed * - * @param {Number | String | *} id - ID of object of text - * @returns {Object} Object of text - */ -DKTools.Sprite.prototype.getTextById = function(id) { - return _.find(this._texts, { id }); -}; - -/** - * Returns the current opacity of the sprite + * @version 3.0.0 * - * @returns {Number} Current opacity of the sprite - */ -DKTools.Sprite.prototype.getCurrentOpacity = function() { - return this.alpha * 255; -}; - -// size methods - -/** - * Changes the width and height of the sprite - * Returns true if the change occurred + * @param {String | Object} object - Path to file or object with parameters + * @param {String} filename - Name of file + * @param {Function} [listener] - Function of processing after loading a bitmap + * @param {Number} [hue] - Hue of bitmap + * @param {Boolean} [smooth] - Smooth of bitmap + * @param {Number} [reservationId] - Reservation ID * - * @param {Number} [width] - Width of the sprite - * @param {Number} [height] - Height of the sprite - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {String} object.folder - Path to file + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID * - * @see DKTools.Sprite.prototype.isResizable - * @see DKTools.Sprite.prototype.getMinWidth - * @see DKTools.Sprite.prototype.getMinHeight - * @see DKTools.Sprite.prototype.setupSize - * @see DKTools.Sprite.prototype.start + * @see DKTools.Sprite.prototype.setBitmap + * @see DKTools.Utils.Bitmap.reserve * - * @returns {Boolean} Change occurred + * @returns {Boolean} Bitmap of the sprite has been changed */ -DKTools.Sprite.prototype.resize = function(width, height, blockStart) { - if (!this.isResizable()) { - return false; - } - - width = (width == null ? this.getMinWidth() : width); - height = (height == null ? this.getMinHeight() : height); - - if (DKTools.Utils.isString(height)) { - height = this.getLineHeight() * Number(height); - } - - if (this._bitmapWidth === width && this._bitmapHeight === height) { - return false; +DKTools.Sprite.prototype.reserveBitmap = function(object, filename, listener, hue, smooth, reservationId) { + if (object instanceof Object) { + return this.reserveBitmap(object.folder, object.filename, object.listener, object.hue, object.smooth, object.reservationId); } - const lastWidth = this._bitmapWidth; - const lastHeight = this._bitmapHeight; - this.setupSize(width, height); + // object - String + const bitmap = DKTools.Utils.Bitmap.reserve(object, filename, listener, hue, smooth, reservationId) - if (this._bitmapWidth === lastWidth && this._bitmapHeight === lastHeight) { - return false; - } + if (this.setBitmap(bitmap)) { + if (listener) { + this.bitmap.addLoadListener(listener); + } - if (!blockStart) { - this.start(); + return true; } - return true; + return false; }; -// can methods +// graphic methods /** - * Returns true if the sprite can be updated and redrawn - * - * @since 1.1.0 + * Loads the graphic (using graphic folder and graphic name) * - * @override + * @private * - * @see DKTools.Base.prototype.canRedrawAll + * @see DKTools.Sprite.prototype.hasGraphicFolder * @see DKTools.Sprite.prototype.hasGraphicName - * @see DKTools.Sprite.prototype.hasFixedBitmap - * - * @returns {Boolean} Sprite can be updated and redrawn + * @see DKTools.Sprite.prototype.loadBitmap + * @see DKTools.Sprite.prototype.hasBitmap + * @see DKTools.Sprite.prototype.updateReadyEvents */ -DKTools.Sprite.prototype.canRedrawAll = function() { - return DKTools.Base.prototype.canRedrawAll.call(this) && !this.hasGraphicName() && !this.hasFixedBitmap(); +DKTools.Sprite.prototype._loadGraphic = function() { + if (this.hasGraphicFolder() && this.hasGraphicName()) { + const folder = this.graphicFolder; + const filename = this.graphicName; + const listener = this._graphicLoadListener; + + this.loadBitmap(folder, filename); + + if (listener && this.hasBitmap()) { + this.bitmap.addLoadListener(listener); + } + + this.updateReadyEvents(); + } }; +// event methods + /** - * Returns true if the sprite can clone the fixed bitmap + * Updates the events with type: draw-all * - * @returns {Boolean} Sprite can clone the fixed bitmap + * @see DKTools.Sprite.prototype.updateEventsContainer */ -DKTools.Sprite.prototype.canCloneFixedBitmap = function() { - return true; +DKTools.Sprite.prototype.updateDrawAllEvents = function() { + this.updateEventsContainer('draw-all'); }; -// effects methods +// update methods /** - * Changes the tone of the bitmap - * Returns true if bitmap exists + * Updates all * - * @param {Number[]} tone - Tone (RGB) - * @returns {Boolean} Bitmap exists + * @override + * + * @see DKTools.Base.prototype.updateAll + * @see DKTools.Sprite.prototype.updateBitmap */ -DKTools.Sprite.prototype.adjustTone = function(tone) { - if (!this.hasBitmap()) { - return false; - } +DKTools.Sprite.prototype.updateAll = function() { + DKTools.Base.prototype.updateAll.call(this); + this.updateBitmap(); +}; - if (DKTools.Utils.Array.isNumberArray(tone) && tone.length === 3) { - Bitmap.prototype.adjustTone.apply(this.bitmap, tone); - return true; +/** + * Updates the bitmap + * + * @see DKTools.Sprite.prototype.hasBitmap + * @see DKTools.Sprite.prototype.updateFont + * @see DKTools.Sprite.prototype.updateTextColor + * @see DKTools.Sprite.prototype.updatePaintOpacity + */ +DKTools.Sprite.prototype.updateBitmap = function() { + if (this.hasBitmap()) { + this.updateFont(); + this.updateTextColor(); + this.updatePaintOpacity(); } - - return false; }; /** - * Rotates the hue of the bitmap - * Returns true if bitmap exists + * Updates the font of the bitmap * - * @param {Number} offset - Offset - * @returns {Boolean} Bitmap exists + * @param {Object} [font=this.font] - Text font + * + * @param {String} [font.fontFace] - Font face + * @param {Number} [font.fontSize] - Font size + * @param {Boolean} [font.fontItalic] - Font italic */ -DKTools.Sprite.prototype.rotateHue = function(offset) { - if (!this.hasBitmap()) { - return false; +DKTools.Sprite.prototype.updateFont = function(font) { + font = font || this.font; + + if (DKTools.Utils.isString(font.fontFace)) { + this.bitmap.fontFace = font.fontFace; } - this.bitmap.rotateHue(offset); + if (Number.isFinite(font.fontSize)) { + this.bitmap.fontSize = font.fontSize; + } - return true; + this.bitmap.fontItalic = !!font.fontItalic; }; /** - * Imposes a blur effect on the bitmap - * Returns true if bitmap exists + * Updates the text color * - * @returns {Boolean} Bitmap exists + * @param {String} [textColor=this.textColor] - Text color */ -DKTools.Sprite.prototype.blur = function() { - if (!this.hasBitmap()) { - return false; - } - - this.bitmap.blur(); - - return true; +DKTools.Sprite.prototype.updateTextColor = function(textColor) { + this.bitmap.textColor = textColor || this.textColor; }; -// change methods - /** - * Changes the font of the bitmap - * - * @param {Object} font - Text font - * - * @param {String} [object.font.fontFace] - Font face - * @param {Number} [object.font.fontSize] - Font size - * @param {Boolean} [object.font.fontItalic] - Font italic + * Updates the paint opacity * - * @see DKTools.Sprite.prototype.hasBitmap - * @see DKTools.Sprite.prototype.updateFont + * @param {Number} [paintOpacity=this.paintOpacity] - Paint opacity */ -DKTools.Sprite.prototype.changeFont = function(font) { - if (this.hasBitmap()) { - this.updateFont(font); +DKTools.Sprite.prototype.updatePaintOpacity = function(paintOpacity) { + if (Number.isFinite(paintOpacity)) { + this.bitmap.paintOpacity = paintOpacity; + } else { + this.bitmap.paintOpacity = this.paintOpacity; } }; /** - * Changes the text color - * - * @param {String} textColor - Text color + * Updates the fill of the sprite * - * @see DKTools.Sprite.prototype.hasBitmap - * @see DKTools.Sprite.prototype.updateTextColor + * @see DKTools.Sprite.prototype.hasFillColor + * @see DKTools.Sprite.prototype.fillAll */ -DKTools.Sprite.prototype.changeTextColor = function(textColor) { - if (this.hasBitmap()) { - this.updateTextColor(textColor); +DKTools.Sprite.prototype.updateFill = function() { + if (this.hasFillColor()) { + this.fillAll(this.fillColor); } }; /** - * Changes the paint opacity + * Updates the opacity of the sprite * - * @param {Number} paintOpacity - Paint opacity + * @override * - * @see DKTools.Sprite.prototype.hasBitmap - * @see DKTools.Sprite.prototype.updatePaintOpacity + * @param {Number} [opacity=this._opacity] - Opacity of the sprite */ -DKTools.Sprite.prototype.changePaintOpacity = function(paintOpacity) { - if (this.hasBitmap()) { - this.updatePaintOpacity(paintOpacity); +DKTools.Sprite.prototype.updateOpacity = function(opacity) { + if (!Number.isFinite(opacity)) { + opacity = this._opacity; } + + this.alpha = opacity.clamp(0, 255) / 255; }; -// reset methods -/** - * Resets all - * - * @see DKTools.Sprite.prototype.resetFont - * @see DKTools.Sprite.prototype.resetTextColor - * @see DKTools.Sprite.prototype.resetPaintOpacity - */ -DKTools.Sprite.prototype.resetAll = function() { - this.resetFont(); - this.resetTextColor(); - this.resetPaintOpacity(); -}; -/** - * Resets the font - * - * @see DKTools.Sprite.prototype.changeFont - */ -DKTools.Sprite.prototype.resetFont = function() { - this.changeFont(this.font); -}; + + +//=========================================================================== +// Sprites based on DKTools.Sprite +//=========================================================================== + + + + + +//=========================================================================== +// DKTools.Sprite.Button +//=========================================================================== + +DKTools.Sprite.Button.prototype = Object.create(DKTools.Sprite.prototype); +DKTools.Sprite.Button.prototype.constructor = DKTools.Sprite.Button; + +// properties + +Object.defineProperties(DKTools.Sprite.Button.prototype, { + + /** + * Interval of long pressing + * + * @readonly + * @type {Number} + * @memberof DKTools.Sprite.Button.prototype + */ + longPressInterval: { + get: function() { + return this._longPressInterval; + }, + configurable: true + }, + + /** + * Mouse press time + * + * @readonly + * @type {Number} + * @memberof DKTools.Sprite.Button.prototype + */ + mousePressTime: { + get: function() { + return this._mousePressTime; + }, + configurable: true + }, + + /** + * The X coordinate of press inside the sprite + * + * @readonly + * @type {Number} + * @memberof DKTools.Sprite.Button.prototype + */ + pressX : { + get: function() { + return this.canvasToLocalX(TouchInput.x); + }, + configurable: true + }, + + /** + * The Y coordinate of press inside the sprite + * + * @readonly + * @type {Number} + * @memberof DKTools.Sprite.Button.prototype + */ + pressY : { + get: function() { + return this.canvasToLocalY(TouchInput.y); + }, + configurable: true + } + +}); + +// _clear methods /** - * Resets the text color + * Clears all data * - * @see DKTools.Sprite.prototype.changeTextColor + * @version 2.0.0 + * @private + * @override + * + * @see DKTools.Sprite.prototype._clearAll + * @see DKTools.Sprite.Button.prototype._clearMousePressTime */ -DKTools.Sprite.prototype.resetTextColor = function() { - this.changeTextColor(this.textColor); +DKTools.Sprite.Button.prototype._clearAll = function() { + DKTools.Sprite.prototype._clearAll.call(this); + this._clearMousePressTime(); }; /** - * Resets the paint opacity + * Clears pressed time * - * @see DKTools.Sprite.prototype.changePaintOpacity + * @since 2.0.0 + * @private */ -DKTools.Sprite.prototype.resetPaintOpacity = function() { - this.changePaintOpacity(this.paintOpacity); +DKTools.Sprite.Button.prototype._clearMousePressTime = function() { + /** + * @private + * @readonly + * @type {Number} + */ + this._mousePressTime = 0; }; -// has methods +// _setup methods /** - * Returns true if the sprite has fixed bitmap (setted using setupBitmap or setBitmap) + * Sets the events * - * @since 1.1.0 - * @returns {Boolean} Sprite has fixed bitmap (setted using setupBitmap or setBitmap) - */ -DKTools.Sprite.prototype.hasFixedBitmap = function() { - return this._fixedBitmap; -}; - -/** - * Returns true if the sprite has the fill color + * @version 2.0.0 + * @private + * @override * - * @returns {Boolean} Sprite has the fill color + * @see DKTools.Sprite.prototype._setupEvents + * @see DKTools.Sprite.Button.prototype._setupUpdateButtonStateEvent */ -DKTools.Sprite.prototype.hasFillColor = function() { - return !!this._fillColor; +DKTools.Sprite.Button.prototype._setupEvents = function() { + DKTools.Sprite.prototype._setupEvents.call(this); + this._setupUpdateButtonStateEvent(); }; /** - * Returns true if the sprite has the texts + * Sets the options * - * @returns {Boolean} Sprite has the texts - */ -DKTools.Sprite.prototype.hasTexts = function() { - return this._texts.length > 0; -}; - -/** - * Returns true if the sprite has the graphic folder + * @version 2.0.0 + * @private + * @override * - * @returns {Boolean} Sprite has the graphic folder + * @see DKTools.Sprite.prototype._setupOptions + * @see DKTools.Sprite.Button.prototype._setupProcessMouseOption */ -DKTools.Sprite.prototype.hasGraphicFolder = function() { - return !!this._graphicFolder; +DKTools.Sprite.Button.prototype._setupOptions = function() { + DKTools.Sprite.prototype._setupOptions.call(this); + this._setupProcessMouseOption(); }; /** - * Returns true if the sprite has the graphic name + * Sets the update event * - * @returns {Boolean} Sprite has the graphic name - */ -DKTools.Sprite.prototype.hasGraphicName = function() { - return !!this._graphicName; -}; - -// is methods - -/** - * Returns true if you can change the size of the sprite + * @since 2.0.0 + * @private * - * @version 1.1.0 - * @returns {Boolean} You can change the size of the sprite + * @see DKTools.Sprite.Button.prototype.addEvent + * @see DKTools.Sprite.Button.prototype.updateButtonState */ -DKTools.Sprite.prototype.isResizable = function() { - return !this.hasGraphicName() && !this.hasFixedBitmap(); +DKTools.Sprite.Button.prototype._setupUpdateButtonStateEvent = function() { + this.addEvent({ + type: 'update', + onUpdate: this.updateButtonState.bind(this) + }); }; /** - * Returns true if the coordinates is inside the sprite - * - * @override + * Sets the option process-mouse * - * @param {Number} x - The X coordinate - * @param {Number} y - The Y coordinate + * @since 2.0.0 + * @private * - * @returns {Boolean} Coordinates is inside the sprite + * @see DKTools.Sprite.Button.prototype.enableOption */ -DKTools.Sprite.prototype.isInside = function(x, y) { - const localX = this.canvasToLocalX(x); - const localY = this.canvasToLocalY(y); - const width = this.width; - const height = this.height; - const anchor = this.anchor; - const frame = new Rectangle(-width * anchor.x, -height * anchor.y, width, height); - - return frame.contains(localX, localY); +DKTools.Sprite.Button.prototype._setupProcessMouseOption = function() { + this.enableOption('process-mouse'); }; -// draw methods +// standard methods /** - * Draws all + * Returns the standard activity of the button * - * @version 1.1.0 * @override + * @returns {Boolean} Standard activity of the button */ -DKTools.Sprite.prototype.drawAll = function() { - this.updateFill(); - this.drawAllTexts(); - this.updateDrawAllEvents(); -}; - -/** - * Draws all texts - */ -DKTools.Sprite.prototype.drawAllTexts = function() { - _.forEach(this._texts, function(obj) { - this[obj.type](obj.text, obj.options); - }.bind(this)); -}; - -/** - * Draws the text - * Returns true if bitmap exists - * - * @param {String} text - Text - * @param {Object} [options={}] - Options for drawing - * - * @param {Object} [options.font=this.font] - Use custom font - * @param {String} [options.textColor=this.textColor] - Use custom text color - * @param {Number} [options.paintOpacity=this.paintOpacity] - Use custom paint opacity - * @param {String} [options.align=this.align] - Align - * @param {Boolean} [options.resetFont=false] - Use standard font after drawing the text - * @param {String} [options.resetTextColor=false] - Use standard text color after drawing the text - * @param {String} [options.resetPaintOpacity=false] - Use standard paint opacity after drawing the text - * @param {Number} [options.x=0] - The X coordinate - * @param {Number | String} [options.y=0] - The Y coordinate or line number (String) - * @param {Number | String} [options.width=this.standardDrawingWidth()] - Width of the rectangle - * @param {Number | String} [options.height=this.getLineHeight()] - Height of the rectangle or number of lines (String) - * @param {PIXI.Point | PIXI.ObservablePoint | Point | Object} [options.pos=undefined] - Position of the text (ignores other parameters of position: x, y, width, height) - * @param {PIXI.Rectangle | Rectangle | Object} [options.rect=undefined] - Rectangle for drawing (ignores other parameters of position: x, y, width, height, pos) - * - * @param {Number} [options.pos.x=0] - The X coordinate - * @param {Number | String} [options.pos.y=0] - The Y coordinate or line number (String) - * - * @param {Number} [options.rect.x=0] - The X coordinate - * @param {Number | String} [options.rect.y=0] - The Y coordinate or line number (String) - * @param {Number | String} [options.rect.width=this.standardDrawingWidth()] - Width of the rectangle - * @param {Number | String} [options.rect.height=this.getLineHeight()] - Height of the rectangle or number of lines (String) - * - * @example - * var sprite = new DKTools.Sprite(0, 0, 100, 36); - * sprite.start(); - * sprite.drawText('Text', { - * y: '1', - * width: '50%', - * height: '75%' - * }); - * - * @see DKTools.Base.prototype.hasBitmap - * @see DKTools.Sprite.prototype.changeFont - * @see DKTools.Sprite.prototype.changeTextColor - * @see DKTools.Sprite.prototype.changePaintOpacity - * @see DKTools.Base.prototype.standardDrawingWidth - * @see DKTools.Base.prototype.standardDrawingHeight - * @see DKTools.Base.prototype.getLineHeight - * @see DKTools.Sprite.prototype.resetFont - * @see DKTools.Sprite.prototype.resetTextColor - * @see DKTools.Sprite.prototype.resetPaintOpacity - * @see Bitmap.prototype.drawText - * - * @returns {Boolean} Bitmap exists - */ -DKTools.Sprite.prototype.drawText = function(text, options) { - text = String(text); - options = options || {}; - - if (!this.hasBitmap() || !text) { - return false; - } - - if (options.font) { - this.changeFont(options.font); - } - - if (options.textColor) { - this.changeTextColor(options.textColor); - } - - if (options.paintOpacity) { - this.changePaintOpacity(options.paintOpacity); - } - - let x = options.x; - let y = options.y; - let width = options.width; - let height = options.height; - const pos = options.pos; - const rect = options.rect; - - if (pos instanceof Object) { - x = pos.x; - y = pos.y; - } - - if (rect instanceof Object) { - x = rect.x; - y = rect.y; - width = rect.width; - height = rect.height; - } - - if (DKTools.Utils.isString(y)) { // line number - y = this.getLineHeight() * Number(y); - } - - if (DKTools.Utils.isString(height)) { // number of lines - height = this.getLineHeight() * Number(height); - } - - x = x || 0; - y = y || 0; - width = width || this.standardDrawingWidth(); - height = height || this.getLineHeight(); - - const align = options.align || this.align; - - this.bitmap.drawText(text, x, y, width, height, align); +DKTools.Sprite.Button.prototype.standardActive = function() { + return false; +}; - if (options.resetFont) { - this.resetFont(); - } +/** + * Returns the standard interval of long pressing + * + * @returns {Number} Standard interval of long pressing + */ +DKTools.Sprite.Button.prototype.standardLongPressInterval = function() { + return 18; +}; - if (options.resetTextColor) { - this.resetTextColor(); - } +// setup methods - if (options.resetPaintOpacity) { - this.resetPaintOpacity(); - } +/** + * Sets all parameters + * + * @override + * + * @param {Object} [object={}] - Parameters + * + * @param {Number} [object.longPressInterval] - Interval of long pressing + * + * @see DKTools.Sprite.prototype.setupAll + * @see DKTools.Sprite.Button.prototype.setupLongPressInterval + */ +DKTools.Sprite.Button.prototype.setupAll = function(object) { + object = object || {}; + DKTools.Sprite.prototype.setupAll.call(this, object); + this.setupLongPressInterval(object.longPressInterval); +}; - return true; +/** + * Sets the interval of long pressing + * + * @param {Number} [interval=this.standardLongPressInterval()] - Interval of long pressing + * + * @see DKTools.Sprite.Button.prototype.standardLongPressInterval + */ +DKTools.Sprite.Button.prototype.setupLongPressInterval = function(interval) { + /** + * @private + * @readonly + * @type {Number} + */ + this._longPressInterval = interval || this.standardLongPressInterval(); }; -// load methods +// set methods /** - * Loads a bitmap from a folder - * Returns true if the bitmap of the sprite has been changed + * Changes all parameters + * Returns the number of changed parameters * - * @param {String | Object} object - Path to file or object with parameters - * @param {String} filename - Name of file - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @version 2.0.0 + * @override * - * @param {String} object.folder - Path to file - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Object} [object={}] - Parameters + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [activate=false] - Activates the button * - * @see ImageManager.loadBitmap - * @see DKTools.Sprite.prototype.setBitmap + * @param {Number} [object.longPressInterval] - Interval of long pressing * - * @returns {Boolean} Bitmap of the sprite has been changed -*/ -DKTools.Sprite.prototype.loadBitmap = function(object, filename, listener, hue, smooth) { - if (object instanceof Object) { - return this.loadBitmap(object.folder, object.filename, object.listener, object.hue, object.smooth); - } + * @see DKTools.Sprite.prototype.setAll + * @see DKTools.Sprite.Button.prototype.setLongPressInterval + * + * @returns {Number} Number of changed parameters + */ +DKTools.Sprite.Button.prototype.setAll = function(object, blockStart, activate) { + object = object || {}; + const block = true; - // object - String (folder) - const bitmap = ImageManager.loadBitmap(object, filename, hue, smooth); + let changed = DKTools.Sprite.prototype.setAll.call(this, object, block); - if (this.setBitmap(bitmap)) { - if (listener) { - this.bitmap.addLoadListener(listener); + if (this.setLongPressInterval(object.longPressInterval)) { + changed++; + } + + if (changed) { + if (!blockStart) { + this.start(); } - return true; + if (activate) { + this.activate(); + } } - return false; + return changed; }; -// reserve methods - /** - * Loads a bitmap from a folder - * Returns true if the bitmap of the sprite has been changed + * Changes the interval of long pressing + * Returns true if the change occurred * - * @param {String | Object} object - Путь к файлу или Объект типа {} - * @param {String} filename - Название файла - * @param {Function} [listener] - Метод обработки после загрузки Bitmap - * @param {Number} [hue] - Оттенок - * @param {Boolean} [smooth] - Сглаживание + * @param {Number} [interval] - Interval of long pressing * - * @param {String} object.folder - Путь к файлу - * @param {String} object.filename - Название файла - * @param {Function} [object.listener] - Метод обработки после загрузки Bitmap - * @param {Number} [object.hue] - Оттенок - * @param {Boolean} [object.smooth] - Сглаживание + * @see DKTools.Sprite.Button.prototype.setupLongPressInterval * - * @returns {Boolean} Bitmap of the sprite has been changed + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.reserveBitmap = function(object, filename, listener, hue, smooth) { - if (object instanceof Object) { - return this.reserveBitmap(object.folder, object.filename, object.listener, object.hue, object.smooth); +DKTools.Sprite.Button.prototype.setLongPressInterval = function(interval) { + if (this._longPressInterval === interval) { + return false; } - // object - String - const bitmap = ImageManager.reserveBitmap(object, filename, hue, smooth); - - if (this.setBitmap(bitmap)) { - if (listener) { - this.bitmap.addLoadListener(listener); - } - - return true; - } + const lastInterval = this._longPressInterval; + this.setupLongPressInterval(interval); - return false; + return this._longPressInterval !== lastInterval; }; -// graphic methods +// is methods /** - * Loads the graphic (using graphic folder and graphic name) + * Returns true if the button is pressed * - * @private + * @see DKTools.Sprite.Button.prototype.isLongPressed * - * @see DKTools.Sprite.prototype.hasGraphicFolder - * @see DKTools.Sprite.prototype.hasGraphicName - * @see DKTools.Sprite.prototype.loadBitmap - * @see DKTools.Sprite.prototype.hasBitmap - * @see DKTools.Sprite.prototype.updateReadyEvents + * @returns {Boolean} Button is pressed */ -DKTools.Sprite.prototype._loadGraphic = function() { - if (this.hasGraphicFolder() && this.hasGraphicName()) { - const folder = this.graphicFolder; - const filename = this.graphicName; - const listener = this._graphicLoadListener; - - this.loadBitmap(folder, filename); - - if (listener && this.hasBitmap()) { - this.bitmap.addLoadListener(listener); - } +DKTools.Sprite.Button.prototype.isPressed = function() { + return this._mousePressTime > 0 && !this.isLongPressed(); +}; - this.updateReadyEvents(); - } +/** + * Returns true if the button is pressed longer than the long press interval + * + * @returns {Boolean} Button is pressed longer than the long press interval + */ +DKTools.Sprite.Button.prototype.isLongPressed = function() { + return this._mousePressTime >= this._longPressInterval; }; // event methods /** - * Updates the events with type: draw-all + * Updates the events with type: mouse-down-button * - * @see DKTools.Sprite.prototype.updateEventsContainer + * @since 2.0.0 + * + * @param {String} button - Mouse button (left, middle or right) + * + * @see DKTools.Sprite.Button.prototype.updateEventsContainer */ -DKTools.Sprite.prototype.updateDrawAllEvents = function() { - this.updateEventsContainer('draw-all'); +DKTools.Sprite.Button.prototype.updateMouseDownEvents = function(button) { + this.updateEventsContainer('mouse-down-' + button); }; -// update methods - /** - * Updates all + * Updates the events with type: mouse-up-button * - * @override + * @since 2.0.0 + * + * @param {String} button - Mouse button (left, middle or right) + * + * @see DKTools.Sprite.Button.prototype.updateEventsContainer */ -DKTools.Sprite.prototype.updateAll = function() { - DKTools.Base.prototype.updateAll.call(this); - this.updateBitmap(); +DKTools.Sprite.Button.prototype.updateMouseUpEvents = function(button) { + this.updateEventsContainer('mouse-up-' + button); }; /** - * Updates the bitmap + * Updates the events with type: mouse-click-button + * + * @since 2.0.0 + * + * @param {String} button - Mouse button (left, middle or right) + * + * @see DKTools.Sprite.Button.prototype.updateEventsContainer */ -DKTools.Sprite.prototype.updateBitmap = function() { - if (this.hasBitmap()) { - this.updateFont(); - this.updateTextColor(); - this.updatePaintOpacity(); - } +DKTools.Sprite.Button.prototype.updateMouseClickEvents = function(button) { + this.updateEventsContainer('mouse-click-' + button); }; /** - * Updates the font of the bitmap + * Updates the events with type: mouse-long-press-button * - * @param {Object} [font=this.font] - Text font + * @since 2.0.0 * - * @param {String} [font.fontFace] - Font face - * @param {Number} [font.fontSize] - Font size - * @param {Boolean} [font.fontItalic] - Font italic + * @param {String} button - Mouse button (left, middle or right) + * + * @see DKTools.Sprite.Button.prototype.updateEventsContainer */ -DKTools.Sprite.prototype.updateFont = function(font) { - font = font || this.font; - - if (DKTools.Utils.isString(font.fontFace)) { - this.bitmap.fontFace = font.fontFace; - } - - if (Number.isFinite(font.fontSize)) { - this.bitmap.fontSize = font.fontSize; - } +DKTools.Sprite.Button.prototype.updateMouseLongPressEvents = function(button) { + this.updateEventsContainer('mouse-long-press-' + button); +}; - this.bitmap.fontItalic = !!font.fontItalic; +/** + * Updates the events with type: mouse-long-press-button-started + * + * @since 2.0.0 + * + * @param {String} button - Mouse button (left, middle or right) + * + * @see DKTools.Sprite.Button.prototype.updateEventsContainer + */ +DKTools.Sprite.Button.prototype.updateMouseLongPressStartedEvents = function(button) { + this.updateEventsContainer(`mouse-long-press-${button}-started`); }; /** - * Updates the text color + * Updates the events with type: mouse-long-press-button-finished * - * @param {String} [textColor=this.textColor] - Text color + * @since 2.0.0 + * + * @param {String} button - Mouse button (left, middle or right) + * + * @see DKTools.Sprite.Button.prototype.updateEventsContainer */ -DKTools.Sprite.prototype.updateTextColor = function(textColor) { - this.bitmap.textColor = textColor || this.textColor; +DKTools.Sprite.Button.prototype.updateMouseLongPressFinishedEvents = function(button) { + this.updateEventsContainer(`mouse-long-press-${button}-finished`); }; /** - * Updates the paint opacity + * Updates the events with type: state-normal * - * @param {Number} [paintOpacity=this.paintOpacity] - Paint opacity + * @since 2.0.0 + * + * @see DKTools.Sprite.Button.prototype.updateEventsContainer */ -DKTools.Sprite.prototype.updatePaintOpacity = function(paintOpacity) { - if (Number.isFinite(paintOpacity)) { - this.bitmap.paintOpacity = paintOpacity; - } else { - this.bitmap.paintOpacity = this.paintOpacity; - } +DKTools.Sprite.Button.prototype.updateStateNormalEvents = function() { + this.updateEventsContainer('state-normal'); }; /** - * Updates the fill of the sprite + * Updates the events with type: state-pressed * - * @see DKTools.Sprite.prototype.hasFillColor - * @see DKTools.Sprite.prototype.fillAll + * @since 2.0.0 + * + * @see DKTools.Sprite.Button.prototype.updateEventsContainer */ -DKTools.Sprite.prototype.updateFill = function() { - if (this.hasFillColor()) { - this.fillAll(this.fillColor); - } +DKTools.Sprite.Button.prototype.updateStatePressedEvents = function() { + this.updateEventsContainer('state-pressed'); }; +// process methods + /** - * Updates the opacity of the sprite + * Processes all * * @override * - * @param {Number} [opacity=this._opacity] - Opacity of the sprite + * @see DKTools.Sprite.prototype.processAll + * @see DKTools.Sprite.Button.prototype.isOptionDisabled + * @see DKTools.Sprite.Button.prototype.processMousePress */ -DKTools.Sprite.prototype.updateOpacity = function(opacity) { - if (!Number.isFinite(opacity)) { - opacity = this._opacity; - } - - this.alpha = opacity.clamp(0, 255) / 255; +DKTools.Sprite.Button.prototype.processAll = function() { + DKTools.Sprite.prototype.processAll.call(this); + this.processMousePress(); }; +/** + * Processes a mouse press + * + * @version 2.0.0 + * + * @see DKTools.Sprite.Button.prototype.isVisibleAndActive + * @see TouchInput.isMousePressed + * @see DKTools.Sprite.Button.prototype.isMouseInside + * @see DKTools.Sprite.Button.prototype.isLongPressed + * @see TouchInput.isLeftButtonPressed + * @see TouchInput.isMiddleButtonPressed + * @see TouchInput.isRightButtonPressed + * @see DKTools.Sprite.Button.prototype.updateMouseLongPressEvents + * @see DKTools.Sprite.Button.prototype.isPressed + * @see DKTools.Sprite.Button.prototype.updateMouseClickEvents + * @see DKTools.Sprite.Button.prototype._clearMousePressTime + */ +DKTools.Sprite.Button.prototype.processMousePress = function() { + if (this.isVisible() && this.isMouseInside() && + (this.isActive() || this.isOptionEnabled('process-mouse-press-ignore-active'))) { + if (TouchInput.isMousePressed()) { + this._mousePressTime++; + + let button; + + if (TouchInput.isLeftButtonPressed()) { + button = 'left'; + } else if (TouchInput.isMiddleButtonPressed()) { + button = 'middle'; + } else if (TouchInput.isRightButtonPressed()) { + button = 'right'; + } + if (button) { + this.updateMouseDownEvents(button); + if (this.isLongPressed()) { + if (this._mousePressTime === this._longPressInterval) { + this.updateMouseLongPressStartedEvents(button); + } + this.updateMouseLongPressEvents(button); + } + } + } else { + let button; -//=========================================================================== -// Elements based on DKTools.Sprite -//=========================================================================== + if (TouchInput.isLeftButtonReleased()) { + button = 'left'; + } else if (TouchInput.isMiddleButtonReleased()) { + button = 'middle'; + } else if (TouchInput.isRightButtonReleased()) { + button = 'right'; + } + + if (button) { + if (this.isLongPressed()) { + this.updateMouseLongPressFinishedEvents(button); + } else if (this.isPressed()) { + this.updateMouseClickEvents(button); + } + + if (this._mousePressTime > 0) { + this.updateMouseUpEvents(button); + } + } + + this._clearMousePressTime(); + } + } else { + this._clearMousePressTime(); + } +}; + +// update methods + +/** + * Updates the button state + * + * @see DKTools.Sprite.Button.prototype.isPressed + * @see DKTools.Sprite.Button.prototype.isLongPressed + * @see DKTools.Sprite.Button.prototype.updateStatePressedEvents + * @see DKTools.Sprite.Button.prototype.updateStateNormalEvents + */ +DKTools.Sprite.Button.prototype.updateButtonState = function() { + if (this._mousePressTime > 0) { + this.updateStatePressedEvents(); + } else { + this.updateStateNormalEvents(); + } +}; //=========================================================================== -// DKTools.Sprite.Button +// DKTools.Sprite.Cursor //=========================================================================== -DKTools.Sprite.Button.prototype = Object.create(DKTools.Sprite.prototype); -DKTools.Sprite.Button.prototype.constructor = DKTools.Sprite.Button; +DKTools.Sprite.Cursor.prototype = Object.create(DKTools.Sprite.prototype); +DKTools.Sprite.Cursor.prototype.constructor = DKTools.Sprite.Cursor; // properties -Object.defineProperties(DKTools.Sprite.Button.prototype, { - - /** - * Interval of long pressing - * - * @readonly - * @type {Number} - * @memberOf DKTools.Sprite.Button.prototype - */ - longPressInterval: { - get: function() { - return this._longPressInterval; - }, - configurable: true - }, - - /** - * Pressed time - * - * @readonly - * @type {Number} - * @memberOf DKTools.Sprite.Button.prototype - */ - mousePressTime: { - get: function() { - return this._mousePressTime; - }, - configurable: true - }, +Object.defineProperties(DKTools.Sprite.Cursor.prototype, { /** - * The X coordinate of press inside the sprite + * Rectangle of the cursor * * @readonly - * @type {Number} - * @memberOf DKTools.Sprite.Button.prototype + * @type {Rectangle} + * @memberof DKTools.Sprite.Cursor.prototype */ - pressX : { + cursorRect: { get: function() { - return this.canvasToLocalX(TouchInput.x); + return this._cursorRect; }, configurable: true }, /** - * The Y coordinate of press inside the sprite + * Blink speed * * @readonly * @type {Number} - * @memberOf DKTools.Sprite.Button.prototype + * @memberof DKTools.Sprite.Cursor.prototype */ - pressY : { + blinkSpeed: { get: function() { - return this.canvasToLocalY(TouchInput.y); + return this._blinkSpeed; }, configurable: true } @@ -16545,112 +17312,108 @@ Object.defineProperties(DKTools.Sprite.Button.prototype, { /** * Clears all data * - * @version 2.0.0 * @private * @override * * @see DKTools.Sprite.prototype._clearAll - * @see DKTools.Sprite.Button.prototype._clearMousePressTime + * @see DKTools.Sprite.Cursor.prototype._clearAnimationCount */ -DKTools.Sprite.Button.prototype._clearAll = function() { +DKTools.Sprite.Cursor.prototype._clearAll = function() { DKTools.Sprite.prototype._clearAll.call(this); - this._clearMousePressTime(); + this._clearAnimationCount(); }; /** - * Clears pressed time + * Clears the animation count * - * @since 2.0.0 * @private */ -DKTools.Sprite.Button.prototype._clearMousePressTime = function() { +DKTools.Sprite.Cursor.prototype._clearAnimationCount = function() { /** * @private * @readonly * @type {Number} */ - this._mousePressTime = 0; + this._animationCount = 0; }; -// _setup methods +// _create methods /** - * Sets the events + * Creates all * - * @version 2.0.0 * @private * @override * - * @see DKTools.Sprite.prototype._setupEvents - * @see DKTools.Sprite.Button.prototype._setupUpdateButtonStateEvent + * @see DKTools.Sprite.prototype._createAll + * @see DKTools.Sprite.Cursor.prototype._createWindowskin */ -DKTools.Sprite.Button.prototype._setupEvents = function() { - DKTools.Sprite.prototype._setupEvents.call(this); - this._setupUpdateButtonStateEvent(); +DKTools.Sprite.Cursor.prototype._createAll = function() { + DKTools.Sprite.prototype._createAll.call(this); + this._createWindowskin(); }; /** - * Sets the options + * Creates the window skin * - * @version 2.0.0 * @private - * @override * - * @see DKTools.Sprite.prototype._setupOptions - * @see DKTools.Sprite.Button.prototype._setupProcessMouseOption + * @see DKTools.Sprite.Cursor.prototype.standardWindowskin */ -DKTools.Sprite.Button.prototype._setupOptions = function() { - DKTools.Sprite.prototype._setupOptions.call(this); - this._setupProcessMouseOption(); +DKTools.Sprite.Cursor.prototype._createWindowskin = function() { + this._windowskin = ImageManager.loadSystem(this.standardWindowskin()); }; +// _setup methods + /** - * Sets the update event + * Sets the events * - * @since 2.0.0 + * @version 2.0.0 * @private + * @override * - * @see DKTools.Sprite.Button.prototype.addEvent - * @see DKTools.Sprite.Button.prototype.updateButtonState + * @see DKTools.Sprite.prototype._setupEvents + * @see DKTools.Sprite.Cursor.prototype._setupUpdateEvent */ -DKTools.Sprite.Button.prototype._setupUpdateButtonStateEvent = function() { - this.addEvent({ - type: 'update', - onUpdate: this.updateButtonState.bind(this) - }); +DKTools.Sprite.Cursor.prototype._setupEvents = function() { + DKTools.Sprite.prototype._setupEvents.call(this); + this._setupUpdateCursorAnimationEvent(); }; /** - * Sets the option process-mouse + * Sets the update event * * @since 2.0.0 * @private * - * @see DKTools.Sprite.Button.prototype.enableOption + * @see DKTools.Sprite.Cursor.prototype.addEvent */ -DKTools.Sprite.Button.prototype._setupProcessMouseOption = function() { - this.enableOption('process-mouse'); +DKTools.Sprite.Cursor.prototype._setupUpdateCursorAnimationEvent = function() { + this.addEvent({ + type: 'update', + onUpdate: this.updateCursorAnimation.bind(this) + }); }; // standard methods /** - * Returns the standard activity of the button + * Returns the standard rectangle of the cursor * - * @override - * @returns {Boolean} Standard activity of the button + * @returns {Rectangle} Standard rectangle of the cursor */ -DKTools.Sprite.Button.prototype.standardActive = function() { - return false; +DKTools.Sprite.Cursor.prototype.standardCursorRect = function() { + return new Rectangle(0, 0, 0, 0); }; /** - * Returns the standard interval of long pressing + * Returns the standard blink speed * - * @returns {Number} Standard interval of long pressing + * @returns {Number} Standard blink speed */ -DKTools.Sprite.Button.prototype.standardLongPressInterval = function() { - return 18; +DKTools.Sprite.Cursor.prototype.standardBlinkSpeed = function() { + return 8; }; // setup methods @@ -16662,31 +17425,66 @@ DKTools.Sprite.Button.prototype.standardLongPressInterval = function() { * * @param {Object} [object={}] - Parameters * - * @param {Number} [object.longPressInterval] - Interval of long pressing + * @param {PIXI.Rectangle | Rectangle | Object} [object.cursorRect] - Rectangle of the cursor + * @param {Number} [object.blinkSpeed] - Blink speed + * + * @param {Number} [object.cursorRect.x] - The X coordinate + * @param {Number} [object.cursorRect.y] - The Y coordinate + * @param {Number} [object.cursorRect.width] - Width of the rectangle + * @param {Number} [object.cursorRect.height] - Height of the rectangle * * @see DKTools.Sprite.prototype.setupAll - * @see DKTools.Sprite.Button.prototype.setupLongPressInterval + * @see DKTools.Sprite.Cursor.prototype.setupCursorRect + * @see DKTools.Sprite.Cursor.prototype.setupBlinkSpeed */ -DKTools.Sprite.Button.prototype.setupAll = function(object) { +DKTools.Sprite.Cursor.prototype.setupAll = function(object) { object = object || {}; DKTools.Sprite.prototype.setupAll.call(this, object); - this.setupLongPressInterval(object.longPressInterval); + this.setupCursorRect(object.cursorRect); + this.setupBlinkSpeed(object.blinkSpeed); +} + +/** + * Sets the rectangle of the cursor + * + * @param {Number | PIXI.Rectangle | Rectangle | Object} [object=this.standardCursorRect()] - The X coordinate or Rectangle or object with parameters + * @param {Number} [y] - The Y coordinate (if object is Number) + * @param {Number} [width] - Width of the rectangle (if object is Number) + * @param {Number} [height] - Height of the rectangle (if object is Number) + * + * @param {Number} [object.x] - The X coordinate + * @param {Number} [object.y] - The Y coordinate + * @param {Number} [object.width] - Width of the rectangle + * @param {Number} [object.height] - Height of the rectangle + * + * @see DKTools.Utils.Rectangle.toRectangle + * @see DKTools.Sprite.Cursor.prototype.standardCursorRect + */ +DKTools.Sprite.Cursor.prototype.setupCursorRect = function(object, y, width, height) { + const rect = DKTools.Utils.Rectangle.toRectangle(object, y, width, height); + + /** + * @private + * @readonly + * @type {Rectangle} + */ + this._cursorRect = Object.assign(this.standardCursorRect(), rect); }; /** - * Sets the interval of long pressing + * Sets the blink speed * - * @param {Number} [interval=this.standardLongPressInterval()] - Interval of long pressing + * @param {Number} [blinkSpeed=this.standardBlinkSpeed()] - Blink speed * - * @see DKTools.Sprite.Button.prototype.standardLongPressInterval + * @see DKTools.Sprite.Cursor.prototype.standardBlinkSpeed */ -DKTools.Sprite.Button.prototype.setupLongPressInterval = function(interval) { +DKTools.Sprite.Cursor.prototype.setupBlinkSpeed = function(blinkSpeed) { /** * @private * @readonly * @type {Number} */ - this._longPressInterval = interval || this.standardLongPressInterval(); + this._blinkSpeed = blinkSpeed || this.standardBlinkSpeed(); }; // set methods @@ -16695,27 +17493,38 @@ DKTools.Sprite.Button.prototype.setupLongPressInterval = function(interval) { * Changes all parameters * Returns the number of changed parameters * - * @version 2.0.0 * @override * * @param {Object} [object={}] - Parameters * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * @param {Boolean} [activate=false] - Activates the button + * @param {Boolean} [activate=false] - Activates the cursor * - * @param {Number} [object.longPressInterval] - Interval of long pressing + * @param {PIXI.Rectangle | Rectangle | Object} [object.cursorRect] - Rectangle of the cursor + * @param {Number} [object.blinkSpeed] - Blink speed + * + * @param {Number} [object.cursorRect.x] - The X coordinate + * @param {Number} [object.cursorRect.y] - The Y coordinate + * @param {Number} [object.cursorRect.width] - Width of the rectangle + * @param {Number} [object.cursorRect.height] - Height of the rectangle * * @see DKTools.Sprite.prototype.setAll - * @see DKTools.Sprite.Button.prototype.setLongPressInterval + * @see DKTools.Sprite.Cursor.prototype.setCursorRect + * @see DKTools.Sprite.Cursor.prototype.setBlinkSpeed + * @see DKTools.Sprite.Cursor.prototype.start + * @see DKTools.Sprite.Cursor.prototype.activate * * @returns {Number} Number of changed parameters */ -DKTools.Sprite.Button.prototype.setAll = function(object, blockStart, activate) { +DKTools.Sprite.Cursor.prototype.setAll = function(object, blockStart, activate) { object = object || {}; const block = true; - let changed = DKTools.Sprite.prototype.setAll.call(this, object, block); - if (this.setLongPressInterval(object.longPressInterval)) { + if (this.setCursorRect(object.cursorRect)) { + changed++; + } + + if (this.setBlinkSpeed(object.blinkSpeed)) { changed++; } @@ -16733,5227 +17542,5609 @@ DKTools.Sprite.Button.prototype.setAll = function(object, blockStart, activate) }; /** - * Changes the interval of long pressing + * Changes the rectangle of the cursor * Returns true if the change occurred * - * @param {Number} [interval] - Interval of long pressing + * @param {Number | PIXI.Rectangle | Rectangle | Object} [object] - The X coordinate or Rectangle or object with parameters + * @param {Number} [y] - The Y coordinate (if object is Number) + * @param {Number} [width] - Width of the rectangle (if object is Number) + * @param {Number} [height] - Height of the rectangle (if object is Number) * - * @see DKTools.Sprite.Button.prototype.setupLongPressInterval + * @param {Number} [object.x] - The X coordinate + * @param {Number} [object.y] - The Y coordinate + * @param {Number} [object.width] - Width of the rectangle + * @param {Number} [object.height] - Height of the rectangle + * + * @see DKTools.Utils.Rectangle.toRectangle + * @see DKTools.Utils.Rectangle.equals + * @see DKTools.Sprite.Cursor.prototype.setupCursorRect + * @see DKTools.Sprite.Cursor.prototype.refreshCursor * * @returns {Boolean} Change occurred */ -DKTools.Sprite.Button.prototype.setLongPressInterval = function(interval) { - if (this._longPressInterval === interval) { +DKTools.Sprite.Cursor.prototype.setCursorRect = function(object, y, width, height) { + if (object instanceof Object) { + return this.setCursorRect(object.x, object.y, object.width, object.height); + } + + const newRect = DKTools.Utils.Rectangle.toRectangle(object, y, width, height); + + if (DKTools.Utils.Rectangle.equals(this._cursorRect, newRect)) { return false; } - const lastInterval = this._longPressInterval; - this.setupLongPressInterval(interval); + const lastRect = DKTools.Utils.Rectangle.clone(this._cursorRect); + this.setupCursorRect(newRect); - return this._longPressInterval !== lastInterval; + if (!DKTools.Utils.Rectangle.equals(this._cursorRect, lastRect)) { + this.refreshCursor(); + return true; + } + + return false; }; -// is methods +/** + * Changes the blink speed + * Returns true if the change occurred + * + * @param {Number} [blinkSpeed] - Blink speed + * + * @see DKTools.Sprite.Cursor.prototype.setupBlinkSpeed + * + * @returns {Boolean} Change occurred + */ +DKTools.Sprite.Cursor.prototype.setBlinkSpeed = function(blinkSpeed) { + if (this._blinkSpeed === blinkSpeed) { + return false; + } + + const lastSpeed = this._blinkSpeed; + this.setupBlinkSpeed(blinkSpeed); + + return this._blinkSpeed !== lastSpeed; +}; + +// refresh methods /** - * Returns true if the button is pressed + * Updates and redraws all * - * @see DKTools.Sprite.Button.prototype.isLongPressed + * @override * - * @returns {Boolean} Button is pressed + * @see DKTools.Sprite.prototype.refreshAll + * @see DKTools.Sprite.Cursor.prototype.refreshCursor */ -DKTools.Sprite.Button.prototype.isPressed = function() { - return this._mousePressTime > 0 && !this.isLongPressed(); +DKTools.Sprite.Cursor.prototype.refreshAll = function() { + DKTools.Sprite.prototype.refreshAll.call(this); + this.refreshCursor(); }; /** - * Returns true if the button is pressed longer than the long press interval + * Updates the cursor + * + * @see DKTools.Sprite.Cursor.prototype.move + * @see DKTools.Sprite.Cursor.prototype.setupBitmap + */ +DKTools.Sprite.Cursor.prototype.refreshCursor = function() { + const x = this._cursorRect.x; + const y = this._cursorRect.y; + const w = this._cursorRect.width; + const h = this._cursorRect.height; + const m = 4; + const ox = 0; + const oy = 0; + const parent = this.parent; + const w2 = Math.min(w, parent.realWidth - x); + const h2 = Math.min(h, parent.realHeight - y); + + this.move(x, y); + + if (w > 0 && h > 0) { + const skin = this._windowskin; + const bitmap = new Bitmap(w2, h2); + const p = 96; + const q = 48; + + bitmap.blt(skin, p+m, p+m, q-m*2, q-m*2, ox+m, oy+m, w-m*2, h-m*2); + bitmap.blt(skin, p+m, p+0, q-m*2, m, ox+m, oy+0, w-m*2, m); + bitmap.blt(skin, p+m, p+q-m, q-m*2, m, ox+m, oy+h-m, w-m*2, m); + bitmap.blt(skin, p+0, p+m, m, q-m*2, ox+0, oy+m, m, h-m*2); + bitmap.blt(skin, p+q-m, p+m, m, q-m*2, ox+w-m, oy+m, m, h-m*2); + bitmap.blt(skin, p+0, p+0, m, m, ox+0, oy+0, m, m); + bitmap.blt(skin, p+q-m, p+0, m, m, ox+w-m, oy+0, m, m); + bitmap.blt(skin, p+0, p+q-m, m, m, ox+0, oy+h-m, m, m); + bitmap.blt(skin, p+q-m, p+q-m, m, m, ox+w-m, oy+h-m, m, m); + + this.setupBitmap(bitmap); + } +}; + +// update methods + +/** + * Updates the cursor animation * - * @returns {Boolean} Button is pressed longer than the long press interval + * @see DKTools.Sprite.Cursor.prototype.setOpacity */ -DKTools.Sprite.Button.prototype.isLongPressed = function() { - return this._mousePressTime >= this._longPressInterval; +DKTools.Sprite.Cursor.prototype.updateCursorAnimation = function() { + const blinkCount = this._animationCount % 40; + let parentOpacity = this.parent.getCurrentOpacity(); + + if (this.parent.isVisibleAndActive()) { + this._animationCount++; + + if (blinkCount < 20) { + parentOpacity -= blinkCount * this._blinkSpeed; + } else { + parentOpacity -= (40 - blinkCount) * this._blinkSpeed; + } + } + + this.setOpacity(parentOpacity); }; -// event methods + + + + +//=========================================================================== +// DKTools.Sprite.Arrow +//=========================================================================== + +DKTools.Sprite.Arrow.prototype = Object.create(DKTools.Sprite.Button.prototype); +DKTools.Sprite.Arrow.prototype.constructor = DKTools.Sprite.Arrow; + +// properties + +Object.defineProperties(DKTools.Sprite.Arrow.prototype, { + + /** + * Type of the arrow + * + * @readonly + * @type {String} + * @memberof DKTools.Sprite.Arrow.prototype + */ + arrowType: { + get: function() { + return this._arrowType; + }, + configurable: true + } + +}); + +// standard methods /** - * Updates the events with type: mouse-up-button - * - * @since 2.0.0 - * - * @param {String} button - Mouse button (left, middle or right) + * Returns the standard visibility of the arrow * - * @see DKTools.Sprite.Button.prototype.updateEventsContainer + * @override + * @returns {Boolean} Standard visibility of the arrow */ -DKTools.Sprite.Button.prototype.updateMouseUpEvents = function(button) { - this.updateEventsContainer('mouse-up-' + button); +DKTools.Sprite.Arrow.prototype.standardVisible = function() { + return false; }; /** - * Updates the events with type: mouse-down-button + * Returns the standard graphic name * - * @since 2.0.0 + * @override * - * @param {String} button - Mouse button (left, middle or right) + * @see DKTools.Base.prototype.standardWindowskin * - * @see DKTools.Sprite.Button.prototype.updateEventsContainer + * @returns {String} Standard graphic name */ -DKTools.Sprite.Button.prototype.updateMouseDownEvents = function(button) { - this.updateEventsContainer('mouse-down-' + button); +DKTools.Sprite.Arrow.prototype.standardGraphicName = function() { + return this.standardWindowskin(); }; /** - * Updates the events with type: mouse-click-button - * - * @since 2.0.0 - * - * @param {String} button - Mouse button (left, middle or right) + * Returns the standard anchor * - * @see DKTools.Sprite.Button.prototype.updateEventsContainer + * @override + * @returns {Point} Standard anchor */ -DKTools.Sprite.Button.prototype.updateMouseClickEvents = function(button) { - this.updateEventsContainer('mouse-click-' + button); +DKTools.Sprite.Arrow.prototype.standardAnchor = function() { + return new Point(0.5, 0.5); }; /** - * Updates the events with type: mouse-long-press-button - * - * @since 2.0.0 - * - * @param {String} button - Mouse button (left, middle or right) + * Returns the standard type of the arrow * - * @see DKTools.Sprite.Button.prototype.updateEventsContainer + * @returns {null} Standard type of the arrow */ -DKTools.Sprite.Button.prototype.updateMouseLongPressEvents = function(button) { - this.updateEventsContainer('mouse-long-press-' + button); +DKTools.Sprite.Arrow.prototype.standardArrowType = function() { + return null; }; +// setup methods + /** - * Updates the events with type: mouse-long-press-button-started + * Sets all parameters * - * @since 2.0.0 - * - * @param {String} button - Mouse button (left, middle or right) + * @override * - * @see DKTools.Sprite.Button.prototype.updateEventsContainer + * @param {Object} [object] - Parameters + * + * @param {String} [object.arrowType] - Type of the arrow + * + * @see DKTools.Sprite.Button.prototype.setupAll + * @see DKTools.Sprite.Arrow.prototype.setupArrowType */ -DKTools.Sprite.Button.prototype.updateMouseLongPressStartedEvents = function(button) { - this.updateEventsContainer(`mouse-long-press-${button}-started`); +DKTools.Sprite.Arrow.prototype.setupAll = function(object) { + object = object || {}; + DKTools.Sprite.Button.prototype.setupAll.call(this, object); + this.setupArrowType(object.arrowType); }; /** - * Updates the events with type: mouse-long-press-button-finished + * Sets the type of the arrow * - * @since 2.0.0 + * @param {String} [type] - Type of the arrow * - * @param {String} button - Mouse button (left, middle or right) - * - * @see DKTools.Sprite.Button.prototype.updateEventsContainer + * @see DKTools.Sprite.Arrow.prototype.standardArrowType */ -DKTools.Sprite.Button.prototype.updateMouseLongPressFinishedEvents = function(button) { - this.updateEventsContainer(`mouse-long-press-${button}-finished`); +DKTools.Sprite.Arrow.prototype.setupArrowType = function(type) { + /** + * @private + * @readonly + * @type {String} + */ + this._arrowType = type || this.standardArrowType(); }; +// set methods + /** - * Updates the events with type: state-normal + * Changes all parameters + * Returns the number of changed parameters * - * @since 2.0.0 + * @override * - * @see DKTools.Sprite.Button.prototype.updateEventsContainer + * @param {Object} [object] - Parameters + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [activate=false] - Activates the arrow + * + * @param {String} [object.arrowType] - Type of the arrow + * + * @see DKTools.Sprite.Button.prototype.setAll + * @see DKTools.Sprite.Arrow.prototype.setArrowType + * @see DKTools.Sprite.Arrow.prototype.start + * @see DKTools.Sprite.Arrow.prototype.activate + * + * @returns {Number} Number of changed parameters */ -DKTools.Sprite.Button.prototype.updateStateNormalEvents = function() { - this.updateEventsContainer('state-normal'); +DKTools.Sprite.Arrow.prototype.setAll = function(object, blockStart, activate) { + object = object || {}; + const block = true; + let changed = DKTools.Sprite.Button.prototype.setAll.call(this, object, block); + + if (this.setArrowType(object.arrowType, block)) { + changed++; + } + + if (changed) { + if (!blockStart) { + this.start(); + } + + if (activate) { + this.activate(); + } + } + + return changed; }; /** - * Updates the events with type: state-pressed + * Changes the type of the arrow + * Returns true if the change occurred * - * @since 2.0.0 + * @param {String} [type] - Type of the arrow + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.Button.prototype.updateEventsContainer + * @see DKTools.Sprite.Arrow.prototype.setupArrowType + * @see DKTools.Sprite.Arrow.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Button.prototype.updateStatePressedEvents = function() { - this.updateEventsContainer('state-pressed'); +DKTools.Sprite.Arrow.prototype.setArrowType = function(type, blockRefreshAll) { + if (this._arrowType === type) { + return false; + } + + const lastType = this._arrowType; + this.setupArrowType(type); + + if (this._arrowType === lastType) { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; -// process methods +// refresh methods /** - * Processes all + * Updates and redraws all * * @override - * - * @see DKTools.Sprite.prototype.processAll - * @see DKTools.Sprite.Button.prototype.isOptionDisabled - * @see DKTools.Sprite.Button.prototype.processMousePress + * + * @see DKTools.Sprite.Button.prototype.refreshAll + * @see DKTools.Sprite.Arrow.prototype.refreshArrow */ -DKTools.Sprite.Button.prototype.processAll = function() { - DKTools.Sprite.prototype.processAll.call(this); - this.processMousePress(); +DKTools.Sprite.Arrow.prototype.refreshAll = function() { + DKTools.Sprite.Button.prototype.refreshAll.call(this); + this.refreshArrow(); }; /** - * Processes a mouse press - * - * @version 2.0.0 + * Updates and redraws the arrow * - * @see DKTools.Sprite.Button.prototype.isVisibleAndActive - * @see TouchInput.isMousePressed - * @see DKTools.Sprite.Button.prototype.isMouseInside - * @see DKTools.Sprite.Button.prototype.isLongPressed - * @see TouchInput.isLeftButtonPressed - * @see TouchInput.isMiddleButtonPressed - * @see TouchInput.isRightButtonPressed - * @see DKTools.Sprite.Button.prototype.updateMouseLongPressEvents - * @see DKTools.Sprite.Button.prototype.isPressed - * @see DKTools.Sprite.Button.prototype.updateMouseClickEvents - * @see DKTools.Sprite.Button.prototype._clearMousePressTime + * @see DKTools.Sprite.Arrow.prototype.setFrame */ -DKTools.Sprite.Button.prototype.processMousePress = function() { - if (this.isVisible() && this.isMouseInside() && - (this.isActive() || this.isOptionEnabled('process-mouse-press-ignore-active'))) { - if (TouchInput.isMousePressed()) { - this._mousePressTime++; - - let button; - - if (TouchInput.isLeftButtonPressed()) { - button = 'left'; - } else if (TouchInput.isMiddleButtonPressed()) { - button = 'middle'; - } else if (TouchInput.isRightButtonPressed()) { - button = 'right'; - } - - if (button) { - this.updateMouseDownEvents(button); - - if (this.isLongPressed()) { - if (this._mousePressTime === this._longPressInterval) { - this.updateMouseLongPressStartedEvents(button); - } - - this.updateMouseLongPressEvents(button); - } - } - } else { - let button; - - if (TouchInput.isLeftButtonReleased()) { - button = 'left'; - } else if (TouchInput.isMiddleButtonReleased()) { - button = 'middle'; - } else if (TouchInput.isRightButtonReleased()) { - button = 'right'; - } - - if (button) { - if (this.isLongPressed()) { - this.updateMouseLongPressFinishedEvents(button); - } else if (this.isPressed()) { - this.updateMouseClickEvents(button); - } - - if (this._mousePressTime > 0) { - this.updateMouseUpEvents(button); - } - } +DKTools.Sprite.Arrow.prototype.refreshArrow = function() { + const p = 24; + const q = p / 2; + const sx = 96 + p; + const sy = p; - this._clearMousePressTime(); - } - } else { - this._clearMousePressTime(); + switch (this._arrowType) { + case 'up': + this.setFrame(sx + q, sy, p, q); + break; + case 'down': + this.setFrame(sx + q, sy + q + p, p, q); + break; + case 'left': + this.setFrame(sx, sy + q, q, p); + break; + case 'right': + this.setFrame(sx + q + p, sy + q, q, p); + break; + default: + throw new Error('Arrow does not have an arrowType!'); + break; } }; -// update methods - -/** - * Updates the button state - * - * @see DKTools.Sprite.Button.prototype.isPressed - * @see DKTools.Sprite.Button.prototype.isLongPressed - * @see DKTools.Sprite.Button.prototype.updateStatePressedEvents - * @see DKTools.Sprite.Button.prototype.updateStateNormalEvents - */ -DKTools.Sprite.Button.prototype.updateButtonState = function() { - if (this._mousePressTime > 0) { - this.updateStatePressedEvents(); - } else { - this.updateStateNormalEvents(); - } -}; //=========================================================================== -// DKTools.Sprite.Cursor +// DKTools.Sprite.Selectable //=========================================================================== -DKTools.Sprite.Cursor.prototype = Object.create(DKTools.Sprite.prototype); -DKTools.Sprite.Cursor.prototype.constructor = DKTools.Sprite.Cursor; +DKTools.Sprite.Selectable.prototype = Object.create(DKTools.Sprite.Button.prototype); +DKTools.Sprite.Selectable.prototype.constructor = DKTools.Sprite.Selectable; // properties -Object.defineProperties(DKTools.Sprite.Cursor.prototype, { +Object.defineProperties(DKTools.Sprite.Selectable.prototype, { /** - * Rectangle of the cursor - * * @readonly - * @type {Rectangle} - * @memberOf DKTools.Sprite.Cursor.prototype + * @type {DKTools.Sprite.Cursor} + * @memberof DKTools.Sprite.Selectable.prototype */ - cursorRect: { + cursorSprite: { get: function() { - return this._cursorRect; + return this._cursorSprite; }, configurable: true }, /** - * Blink speed + * Index * * @readonly * @type {Number} - * @memberOf DKTools.Sprite.Cursor.prototype + * @memberof DKTools.Sprite.Selectable.prototype */ - blinkSpeed: { + index: { get: function() { - return this._blinkSpeed; + return this._index; }, configurable: true - } + }, -}); + /** + * Maximum of the columns + * + * @readonly + * @type {Number} + * @memberof DKTools.Sprite.Selectable.prototype + */ + maxCols: { + get: function() { + return this._maxCols; + }, + configurable: true + }, -// _clear methods + /** + * Fixed cursor + * + * @readonly + * @type {Boolean} + * @memberof DKTools.Sprite.Selectable.prototype + */ + cursorFixed: { + get: function() { + return this._cursorFixed; + }, + configurable: true + }, -/** - * Clears all data - * - * @private - * @override - */ -DKTools.Sprite.Cursor.prototype._clearAll = function() { - DKTools.Sprite.prototype._clearAll.call(this); - this._clearAnimationCount(); -}; + /** + * Cursor all + * + * @readonly + * @type {Boolean} + * @memberof DKTools.Sprite.Selectable.prototype + */ + cursorAll: { + get: function() { + return this._cursorAll; + }, + configurable: true + }, -/** - * Clears the animation count - * - * @private - */ -DKTools.Sprite.Cursor.prototype._clearAnimationCount = function() { /** - * @private + * Horizontal spacing + * * @readonly * @type {Number} + * @memberof DKTools.Sprite.Selectable.prototype */ - this._animationCount = 0; -}; + horizontalSpacing: { + get: function() { + return this._horizontalSpacing; + }, + configurable: true + }, -// _create methods + /** + * Vertical spacing + * + * @readonly + * @type {Number} + * @memberof DKTools.Sprite.Selectable.prototype + */ + verticalSpacing: { + get: function() { + return this._verticalSpacing; + }, + configurable: true + }, -/** - * Creates all - * - * @private - * @override - * - * @see DKTools.Sprite.prototype._createAll - * @see DKTools.Sprite.Cursor.prototype._createWindowskin - */ -DKTools.Sprite.Cursor.prototype._createAll = function() { - DKTools.Sprite.prototype._createAll.call(this); - this._createWindowskin(); -}; + /** + * Text padding + * + * @readonly + * @type {Number} + * @memberof DKTools.Sprite.Selectable.prototype + */ + textPadding: { + get: function() { + return this._textPadding; + }, + configurable: true + }, + + /** + * List of the items + * + * @readonly + * @type {Object[]} + * @memberof DKTools.Sprite.Selectable.prototype + */ + items: { + get: function() { + return this._items; + }, + configurable: true + }, + + /** + * Handler of draw of the item + * + * @readonly + * @type {Function | null} + * @memberof DKTools.Sprite.Selectable.prototype + */ + drawItemHandler: { + get: function() { + return this._drawItemHandler; + }, + configurable: true + }, + + /** + * Width of the item + * + * @readonly + * @type {Function | Number} + * @memberof DKTools.Sprite.Selectable.prototype + */ + itemWidth: { + get: function() { + return this._itemWidth; + }, + configurable: true + }, + + /** + * Height of the item + * + * @readonly + * @type {Function | Number} + * @memberof DKTools.Sprite.Selectable.prototype + */ + itemHeight: { + get: function() { + return this._itemHeight; + }, + configurable: true + }, + + /** + * Font of the item + * + * @readonly + * @type {Function | Object} + * @memberof DKTools.Sprite.Selectable.prototype + */ + itemFont: { + get: function() { + return this._itemFont; + }, + configurable: true + }, + + /** + * Text color of the item + * + * @readonly + * @type {Function | String} + * @memberof DKTools.Sprite.Selectable.prototype + */ + itemTextColor: { + get: function() { + return this._itemTextColor; + }, + configurable: true + }, + + /** + * Paint opacity of the item + * + * @readonly + * @type {Function | Number} + * @memberof DKTools.Sprite.Selectable.prototype + */ + itemPaintOpacity: { + get: function() { + return this._itemPaintOpacity; + }, + configurable: true + }, + + /** + * Align of the item + * + * @readonly + * @type {Function | String} + * @memberof DKTools.Sprite.Selectable.prototype + */ + itemAlign: { + get: function() { + return this._itemAlign; + }, + configurable: true + } + +}); + +// _clear methods /** - * Creates the window skin + * Clears all data * * @private - * - * @see DKTools.Sprite.Cursor.prototype.standardWindowskin + * @override + * + * @see DKTools.Sprite.Button.prototype._clearAll + * @see DKTools.Sprite.Selectable.prototype._clearItems + * @see DKTools.Sprite.Selectable.prototype._clearHandlers + * @see DKTools.Sprite.Selectable.prototype._clearTopRow + * @see DKTools.Sprite.Selectable.prototype._clearTopCol */ -DKTools.Sprite.Cursor.prototype._createWindowskin = function() { - const filename = this.standardWindowskin(); - this._windowskin = ImageManager.loadSystem(filename); +DKTools.Sprite.Selectable.prototype._clearAll = function() { + DKTools.Sprite.Button.prototype._clearAll.call(this); + this._clearItems(); + this._clearHandlers(); + this._clearTopRow(); + this._clearTopCol(); }; -// _setup methods - /** - * Sets the events + * Clears items * - * @version 2.0.0 * @private - * @override - * - * @see DKTools.Sprite.prototype._setupEvents - * @see DKTools.Sprite.Cursor.prototype._setupUpdateEvent */ -DKTools.Sprite.Cursor.prototype._setupEvents = function() { - DKTools.Sprite.prototype._setupEvents.call(this); - this._setupUpdateCursorAnimationEvent(); +DKTools.Sprite.Selectable.prototype._clearItems = function() { + /** + * @private + * @readonly + * @type {Object[]} + */ + this._items = []; }; /** - * Sets the update event + * Clears the selection handlers * - * @since 2.0.0 * @private - * - * @see DKTools.Sprite.Cursor.prototype.addEvent */ -DKTools.Sprite.Cursor.prototype._setupUpdateCursorAnimationEvent = function() { - this.addEvent({ - type: 'update', - onUpdate: this.updateCursorAnimation.bind(this) - }); +DKTools.Sprite.Selectable.prototype._clearHandlers = function() { + /** + * @readonly + * @private + * @type {Object} + */ + this._handlers = {}; }; -// standard methods - /** - * Returns the standard rectangle of the cursor + * Clears the top row * - * @returns {Rectangle} Standard rectangle of the cursor + * @private */ -DKTools.Sprite.Cursor.prototype.standardCursorRect = function() { - return new Rectangle(0, 0, 0, 0); +DKTools.Sprite.Selectable.prototype._clearTopRow = function() { + /** + * @private + * @readonly + * @type {Number} + */ + this._topRow = 0; }; /** - * Returns the standard blink speed + * Clears the top col * - * @returns {Number} Standard blink speed + * @private */ -DKTools.Sprite.Cursor.prototype.standardBlinkSpeed = function() { - return 8; +DKTools.Sprite.Selectable.prototype._clearTopCol = function() { + /** + * @private + * @readonly + * @type {Number} + */ + this._topCol = 0; }; -// setup methods +// _create methods /** - * Sets all parameters + * Creates all * + * @private * @override - * - * @param {Object} [object={}] - Parameters - * - * @param {PIXI.Rectangle | Rectangle | Object} [object.cursorRect] - Rectangle of the cursor - * @param {Number} [object.blinkSpeed] - Blink speed - * - * @param {Number} [object.cursorRect.x] - The X coordinate - * @param {Number} [object.cursorRect.y] - The Y coordinate - * @param {Number} [object.cursorRect.width] - Width of the rectangle - * @param {Number} [object.cursorRect.height] - Height of the rectangle - * - * @see DKTools.Sprite.prototype.setupAll - * @see DKTools.Sprite.Cursor.prototype.setupCursorRect - * @see DKTools.Sprite.Cursor.prototype.setupBlinkSpeed - */ -DKTools.Sprite.Cursor.prototype.setupAll = function(object) { - object = object || {}; - DKTools.Sprite.prototype.setupAll.call(this, object); - this.setupCursorRect(object.cursorRect); - this.setupBlinkSpeed(object.blinkSpeed); -} - -/** - * Sets the rectangle of the cursor - * - * @param {Number | PIXI.Rectangle | Rectangle | Object} [object=this.standardCursorRect()] - The X coordinate or Rectangle or object with parameters - * @param {Number} [y] - The Y coordinate (if object is Number) - * @param {Number} [width] - Width of the rectangle (if object is Number) - * @param {Number} [height] - Height of the rectangle (if object is Number) - * - * @param {Number} [object.x] - The X coordinate - * @param {Number} [object.y] - The Y coordinate - * @param {Number} [object.width] - Width of the rectangle - * @param {Number} [object.height] - Height of the rectangle - * - * @see DKTools.Utils.Rectangle.toRectangle - * @see DKTools.Sprite.Cursor.prototype.standardCursorRect + * + * @see DKTools.Sprite.Button.prototype._createAll + * @see DKTools.Sprite.Selectable.prototype._createCursorSprite */ -DKTools.Sprite.Cursor.prototype.setupCursorRect = function(object, y, width, height) { - const rect = DKTools.Utils.Rectangle.toRectangle(object, y, width, height); - - /** - * @private - * @readonly - * @type {Rectangle} - */ - this._cursorRect = Object.assign(this.standardCursorRect(), rect); +DKTools.Sprite.Selectable.prototype._createAll = function() { + DKTools.Sprite.Button.prototype._createAll.call(this); + this._createCursorSprite(); }; /** - * Sets the blink speed - * - * @param {Number} [blinkSpeed=this.standardBlinkSpeed()] - Blink speed + * Creates sprite of the cursor * - * @see DKTools.Sprite.Cursor.prototype.standardBlinkSpeed + * @private + * + * @see DKTools.Sprite.Cursor */ -DKTools.Sprite.Cursor.prototype.setupBlinkSpeed = function(blinkSpeed) { +DKTools.Sprite.Selectable.prototype._createCursorSprite = function() { /** * @private * @readonly - * @type {Number} + * @type {DKTools.Sprite.Cursor} */ - this._blinkSpeed = blinkSpeed || this.standardBlinkSpeed(); + this._cursorSprite = new DKTools.Sprite.Cursor(); }; -// set methods +// _setup methods /** - * Changes all parameters - * Returns the number of changed parameters + * Sets the events * + * @version 3.0.0 + * @private * @override - * - * @param {Object} [object={}] - Parameters - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * @param {Boolean} [activate=false] - Activates the cursor - * - * @param {PIXI.Rectangle | Rectangle | Object} [object.cursorRect] - Rectangle of the cursor - * @param {Number} [object.blinkSpeed] - Blink speed - * - * @param {Number} [object.cursorRect.x] - The X coordinate - * @param {Number} [object.cursorRect.y] - The Y coordinate - * @param {Number} [object.cursorRect.width] - Width of the rectangle - * @param {Number} [object.cursorRect.height] - Height of the rectangle - * - * @see DKTools.Sprite.prototype.setAll - * @see DKTools.Sprite.Cursor.prototype.setCursorRect - * @see DKTools.Sprite.Cursor.prototype.setBlinkSpeed - * @see DKTools.Sprite.Cursor.prototype.start - * @see DKTools.Sprite.Cursor.prototype.activate - * - * @returns {Number} Number of changed parameters + * + * @see DKTools.Sprite.Button.prototype._setupEvents + * @see DKTools.Sprite.Selectable.prototype._setupMouseClickEvent + * @see DKTools.Sprite.Selectable.prototype._setupMouseLongPressEvent + * @see DKTools.Sprite.Selectable.prototype._setupMouseHoverEvents + * @see DKTools.Sprite.Selectable.prototype._setupWheelScrollEvents */ -DKTools.Sprite.Cursor.prototype.setAll = function(object, blockStart, activate) { - object = object || {}; - const block = true; - let changed = DKTools.Sprite.prototype.setAll.call(this, object, block); - - if (this.setCursorRect(object.cursorRect)) { - changed++; - } - - if (this.setBlinkSpeed(object.blinkSpeed)) { - changed++; - } - - if (changed) { - if (!blockStart) { - this.start(); - } - - if (activate) { - this.activate(); - } - } - - return changed; +DKTools.Sprite.Selectable.prototype._setupEvents = function() { + DKTools.Sprite.Button.prototype._setupEvents.call(this); + this._setupMouseClickEvent(); + this._setupMouseLongPressEvent(); + this._setupMouseHoverEvents(); + this._setupWheelScrollEvents(); }; /** - * Changes the rectangle of the cursor - * Returns true if the change occurred - * - * @param {Number | PIXI.Rectangle | Rectangle | Object} [object] - The X coordinate or Rectangle or object with parameters - * @param {Number} [y] - The Y coordinate (if object is Number) - * @param {Number} [width] - Width of the rectangle (if object is Number) - * @param {Number} [height] - Height of the rectangle (if object is Number) - * - * @param {Number} [object.x] - The X coordinate - * @param {Number} [object.y] - The Y coordinate - * @param {Number} [object.width] - Width of the rectangle - * @param {Number} [object.height] - Height of the rectangle - * - * @see DKTools.Utils.Rectangle.toRectangle - * @see DKTools.Utils.Rectangle.equals - * @see DKTools.Sprite.Cursor.prototype.setupCursorRect - * @see DKTools.Sprite.Cursor.prototype.refreshCursor + * Sets the event of the click (mouse-click-left) * - * @returns {Boolean} Change occurred + * @private + * + * @see DKTools.Sprite.Selectable.prototype.addEvent */ -DKTools.Sprite.Cursor.prototype.setCursorRect = function(object, y, width, height) { - if (object instanceof Object) { - return this.setCursorRect(object.x, object.y, object.width, object.height); - } - - const newRect = DKTools.Utils.Rectangle.toRectangle(object, y, width, height); - - if (DKTools.Utils.Rectangle.equals(this._cursorRect, newRect)) { - return false; - } - - const lastRect = DKTools.Utils.Rectangle.clone(this._cursorRect); - this.setupCursorRect(newRect); - - if (!DKTools.Utils.Rectangle.equals(this._cursorRect, lastRect)) { - this.refreshCursor(); - return true; - } - - return false; +DKTools.Sprite.Selectable.prototype._setupMouseClickEvent = function() { + this.addEvent({ + type: 'mouse-click-left', + onUpdate: this._onTouch.bind(this, true) + }); }; /** - * Changes the blink speed - * Returns true if the change occurred - * - * @param {Number} [blinkSpeed] - Blink speed + * Sets the event of the long press (mouse-long-press-left) * - * @see DKTools.Sprite.Cursor.prototype.setupBlinkSpeed + * @private + * + * @see DKTools.Sprite.Selectable.prototype.addEvent + */ +DKTools.Sprite.Selectable.prototype._setupMouseLongPressEvent = function() { + this.addEvent({ + type: 'mouse-long-press-left', + onUpdate: this._onTouch.bind(this, false) + }); +}; + +/** + * Sets the events of the mouse hover (mouse-enter and mouse-move) * - * @returns {Boolean} Change occurred + * @private + * + * @see DKTools.Sprite.Selectable.prototype.addEvent */ -DKTools.Sprite.Cursor.prototype.setBlinkSpeed = function(blinkSpeed) { - if (this._blinkSpeed === blinkSpeed) { - return false; - } +DKTools.Sprite.Selectable.prototype._setupMouseHoverEvents = function() { + this.addEvent({ + type: 'mouse-enter', + onUpdate: this.processMouseHover.bind(this) + }); - const lastSpeed = this._blinkSpeed; - this.setupBlinkSpeed(blinkSpeed); + this.addEvent({ + type: 'mouse-move', + onUpdate: this.processMouseHover.bind(this) + }); +}; - return this._blinkSpeed !== lastSpeed; +/** + * Sets the events of the wheel scrolling (wheel-Y-inside and wheel-Y-outside) + * + * @private + * + * @see DKTools.Sprite.Selectable.prototype.addEvent + */ +DKTools.Sprite.Selectable.prototype._setupWheelScrollEvents = function() { + this.addEvent({ + type: 'wheel-Y-inside', + onUpdate: this.processWheelScroll.bind(this) + }); + + this.addEvent({ + type: 'wheel-Y-outside', + onUpdate: this.processWheelScroll.bind(this) + }); }; -// refresh methods +// _add methods /** - * Updates and redraws all + * Adds children objects to processing * + * @private * @override - * - * @see DKTools.Sprite.prototype.refreshAll - * DKTools.Sprite.Cursor.prototype.refreshCursor + * + * @see DKTools.Sprite.Button.prototype._addAllChildren + * @see DKTools.Sprite.Selectable.prototype._addCursorSprite */ -DKTools.Sprite.Cursor.prototype.refreshAll = function() { - DKTools.Sprite.prototype.refreshAll.call(this); - this.refreshCursor(); +DKTools.Sprite.Selectable.prototype._addAllChildren = function() { + DKTools.Sprite.Button.prototype._addAllChildren.call(this); + this._addCursorSprite(); }; /** - * Updates the cursor + * Adds sprite of the cursor to processing + * + * @private */ -DKTools.Sprite.Cursor.prototype.refreshCursor = function() { - const x = this._cursorRect.x; - const y = this._cursorRect.y; - const w = this._cursorRect.width; - const h = this._cursorRect.height; - const m = 4; - const ox = 0; - const oy = 0; - const parent = this.parent; - const w2 = Math.min(w, parent.realWidth - x); - const h2 = Math.min(h, parent.realHeight - y); +DKTools.Sprite.Selectable.prototype._addCursorSprite = function() { + this.addChild(this._cursorSprite); +}; - this.move(x, y); +// standard methods - if (w > 0 && h > 0) { - const skin = this._windowskin; - const bitmap = new Bitmap(w2, h2); - const p = 96; - const q = 48; - bitmap.blt(skin, p+m, p+m, q-m*2, q-m*2, ox+m, oy+m, w-m*2, h-m*2); - bitmap.blt(skin, p+m, p+0, q-m*2, m, ox+m, oy+0, w-m*2, m); - bitmap.blt(skin, p+m, p+q-m, q-m*2, m, ox+m, oy+h-m, w-m*2, m); - bitmap.blt(skin, p+0, p+m, m, q-m*2, ox+0, oy+m, m, h-m*2); - bitmap.blt(skin, p+q-m, p+m, m, q-m*2, ox+w-m, oy+m, m, h-m*2); - bitmap.blt(skin, p+0, p+0, m, m, ox+0, oy+0, m, m); - bitmap.blt(skin, p+q-m, p+0, m, m, ox+w-m, oy+0, m, m); - bitmap.blt(skin, p+0, p+q-m, m, m, ox+0, oy+h-m, m, m); - bitmap.blt(skin, p+q-m, p+q-m, m, m, ox+w-m, oy+h-m, m, m); - this.setupBitmap(bitmap); - } +/** + * Returns the standard index + * + * @returns {Number} Standard index + */ +DKTools.Sprite.Selectable.prototype.standardIndex = function() { + return 0; }; -// update methods +/** + * Returns the standard number of the columns + * + * @returns {Number} Standard number of the columns + */ +DKTools.Sprite.Selectable.prototype.standardMaxCols = function() { + return 1; +}; /** - * Updates the cursor animation + * Returns the standard fixed cursor * - * @see DKTools.Sprite.Cursor.prototype.setOpacity + * @returns {Boolean} Standard fixed cursor */ -DKTools.Sprite.Cursor.prototype.updateCursorAnimation = function() { - const blinkCount = this._animationCount % 40; - let parentOpacity = this.parent.getCurrentOpacity(); +DKTools.Sprite.Selectable.prototype.standardCursorFixed = function() { + return false; +}; - if (this.parent.isVisibleAndActive()) { - this._animationCount++; - if (blinkCount < 20) { - parentOpacity -= blinkCount * this._blinkSpeed; - } else { - parentOpacity -= (40 - blinkCount) * this._blinkSpeed; - } - } +/** + * Returns the standard cursor all + * + * @returns {Boolean} Standard cursor all + */ +DKTools.Sprite.Selectable.prototype.standardCursorAll = function() { + return false; +}; - this.setOpacity(parentOpacity); +/** + * Returns the standard fixed horizontal position + * + * @returns {Boolean} Standard fixed horizontal position + */ +DKTools.Sprite.Selectable.prototype.standardFixedHorizontal = function() { + return false; }; +/** + * Returns the standard horizontal spacing + * + * @returns {Number} Standard horizontal spacing + */ +DKTools.Sprite.Selectable.prototype.standardHorizontalSpacing = function() { + return 0; +}; +/** + * Returns the standard vertical spacing + * + * @returns {Number} Standard vertical spacing + */ +DKTools.Sprite.Selectable.prototype.standardVerticalSpacing = function() { + return 0; +}; +/** + * Returns the standard text padding + * + * @returns {Number} Standard text padding + */ +DKTools.Sprite.Selectable.prototype.standardTextPadding = function() { + return 6; +}; +/** + * Returns the standard list of the items + * + * @returns {Array} Standard list of the items + */ +DKTools.Sprite.Selectable.prototype.standardItems = function() { + return []; +}; -//=========================================================================== -// DKTools.Sprite.Arrow -//=========================================================================== +/** + * Returns the standard handler of draw of the item + * + * @returns {Function} Standard handler of draw of the item + */ +DKTools.Sprite.Selectable.prototype.standardDrawItemHandler = function() { + return function(index) { + const name = this.getItemName(index); + const font = this.getItemFontByIndex(index); + const textColor = this.getItemTextColorByIndex(index); + const paintOpacity = this.getItemPaintOpacityByIndex(index); + const align = this.getItemAlignByIndex(index); + const rect = this.getItemRectForTextByIndex(index); -DKTools.Sprite.Arrow.prototype = Object.create(DKTools.Sprite.Button.prototype); -DKTools.Sprite.Arrow.prototype.constructor = DKTools.Sprite.Arrow; + this.drawText(name, { + font, + textColor, + paintOpacity, + align, + rect, + resetFont: true, + resetTextColor: true, + resetPaintOpacity: true + }); + }.bind(this); +}; -// properties +/** + * Returns the standard item width + * + * @returns {Function} Standard item width + */ +DKTools.Sprite.Selectable.prototype.standardItemWidth = function() { + return function() { + const spacing = this._horizontalSpacing; + return Math.floor((this.realWidth + spacing) / this.getMaxCols() - spacing); + }.bind(this); +}; -Object.defineProperties(DKTools.Sprite.Arrow.prototype, { +/** + * Returns the standard item height + * + * @returns {Function} Standard item height + */ +DKTools.Sprite.Selectable.prototype.standardItemHeight = function() { + return this.getLineHeight(); +}; - /** - * Type of the arrow - * - * @readonly - * @type {String} - * @memberOf DKTools.Sprite.Arrow.prototype - */ - arrowType: { - get: function() { - return this._arrowType; - }, - configurable: true - } +/** + * Returns the standard item rect + * + * @returns {Function} Standard item rect + */ +DKTools.Sprite.Selectable.prototype.standardItemRect = function() { + return function(index) { + const rect = new Rectangle(); + const maxCols = this.getMaxCols(); -}); + rect.width = this.getItemWidth(); + rect.height = this.getItemHeight(); -// standard methods + if (this.isHorizontal()) { + rect.x = (index - this.getTopCol()) * (rect.width + this._horizontalSpacing); + rect.y = 0; + } else { + rect.x = index % maxCols * (rect.width + this._horizontalSpacing); + rect.y = (Math.floor(index / maxCols) - this.getTopRow()) * (rect.height + this._verticalSpacing); + } + + return rect; + }.bind(this); +}; /** - * Returns the standard visibility of the arrow + * Returns the standard item font * - * @override - * @returns {Boolean} Standard visibility of the arrow + * @returns {Object} Standard item font */ -DKTools.Sprite.Arrow.prototype.standardVisible = function() { - return false; +DKTools.Sprite.Selectable.prototype.standardItemFont = function() { + return this.font; }; /** - * Returns the standard graphic name - * - * @override - * - * @see DKTools.Base.prototype.standardWindowskin + * Returns the standard text color of the item * - * @returns {String} Standard graphic name + * @returns {String} Standard text color of the item */ -DKTools.Sprite.Arrow.prototype.standardGraphicName = function() { - return this.standardWindowskin(); +DKTools.Sprite.Selectable.prototype.standardItemTextColor = function() { + return this.textColor; }; /** - * Returns the standard anchor + * Returns the standard paint opacity of the item * - * @override - * @returns {Point} Standard anchor + * @returns {Number} Standard paint opacity of the item */ -DKTools.Sprite.Arrow.prototype.standardAnchor = function() { - return new Point(0.5, 0.5); +DKTools.Sprite.Selectable.prototype.standardItemPaintOpacity = function() { + return function(index) { + if (this.isItemEnabled(index)) { + return this.standardEnabledItemPaintOpacity(); + } else { + return this.standardDisabledItemPaintOpacity(); + } + }.bind(this); }; /** - * Returns the standard type of the arrow + * Returns the standard paint opacity of the enabled item * - * @returns {null} Standard type of the arrow + * @returns {Number} Standard paint opacity of the enabled item */ -DKTools.Sprite.Arrow.prototype.standardArrowType = function() { - return null; +DKTools.Sprite.Selectable.prototype.standardEnabledItemPaintOpacity = function() { + return 255; }; -// setup methods - /** - * Sets all parameters - * - * @override - * - * @param {Object} [object] - Parameters - * - * @param {String} [object.arrowType] - Type of the arrow + * Returns the standard paint opacity of the disabled item * - * @see DKTools.Sprite.Button.prototype.setupAll - * @see DKTools.Sprite.Arrow.prototype.setupArrowType + * @returns {Number} Standard paint opacity of the disabled item */ -DKTools.Sprite.Arrow.prototype.setupAll = function(object) { - object = object || {}; - DKTools.Sprite.Button.prototype.setupAll.call(this, object); - this.setupArrowType(object.arrowType); +DKTools.Sprite.Selectable.prototype.standardDisabledItemPaintOpacity = function() { + try { + return Window_Base.prototype.translucentOpacity.call(this); + } catch(e) { + return 160; + } }; /** - * Sets the type of the arrow + * Returns the standard item align * - * @param {String} [type] - Type of the arrow + * @returns {String} Standard item align */ -DKTools.Sprite.Arrow.prototype.setupArrowType = function(type) { - /** - * @private - * @readonly - * @type {String} - */ - this._arrowType = type || this.standardArrowType(); +DKTools.Sprite.Selectable.prototype.standardItemAlign = function() { + return this.align; }; -// set methods +// setup methods /** - * Changes all parameters - * Returns the number of changed parameters + * Sets all parameters * * @override * * @param {Object} [object] - Parameters - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * @param {Boolean} [activate=false] - Activates the arrow * - * @param {String} [object.arrowType] - Type of the arrow + * @param {Number} [object.index] - Index + * @param {Number} [object.maxCols] - Number of the columns + * @param {Boolean} [object.fixedHorizontal] - Fixed horizontal position + * @param {Boolean} [object.cursorFixed] - Fixed cursor + * @param {Boolean} [object.cursorAll] - Cursor all + * @param {Number} [object.horizontalSpacing] - Horizontal spacing + * @param {Number} [object.verticalSpacing] - Vertical spacing + * @param {Number} [object.textPadding] - Text padding + * @param {Object[]} [object.items] - List of the items + * @param {Function} [object.drawItemHandler] - Handler of draw of the item + * @param {Function | Number} [object.itemWidth] - Width of the item + * @param {Function | Number} [object.itemHeight] - Height of the item + * @param {Function} [object.itemRect] - Rectangle of the item + * @param {Function | Object} [object.itemFont] - Font of the item + * @param {Function | String} [object.itemTextColor] - Text color of the item + * @param {Function | Number} [object.itemPaintOpacity] - Paint opacity of the item + * @param {Function | String} [object.itemAlign] - Align of the item * - * @see DKTools.Sprite.Button.prototype.setAll - * @see DKTools.Sprite.Arrow.prototype.setArrowType + * @param {String} [object.font.fontFace] - Font face + * @param {Number} [object.font.fontSize] - Font size + * @param {Boolean} [object.font.fontItalic] - Font italic * - * @returns {Number} Number of changed parameters + * @see DKTools.Sprite.Button.prototype.setupAll + * @see DKTools.Sprite.Selectable.prototype.setupIndex + * @see DKTools.Sprite.Selectable.prototype.setupMaxCols + * @see DKTools.Sprite.Selectable.prototype.setupFixedHorizontal + * @see DKTools.Sprite.Selectable.prototype.setupCursorFixed + * @see DKTools.Sprite.Selectable.prototype.setupCursorAll + * @see DKTools.Sprite.Selectable.prototype.setupSpacing + * @see DKTools.Sprite.Selectable.prototype.setupTextPadding + * @see DKTools.Sprite.Selectable.prototype.setupItems + * @see DKTools.Sprite.Selectable.prototype.setupDrawItemHandler + * @see DKTools.Sprite.Selectable.prototype.setupItemWidth + * @see DKTools.Sprite.Selectable.prototype.setupItemHeight + * @see DKTools.Sprite.Selectable.prototype.setupItemRect + * @see DKTools.Sprite.Selectable.prototype.setupItemFont + * @see DKTools.Sprite.Selectable.prototype.setupItemTextColor + * @see DKTools.Sprite.Selectable.prototype.setupItemPaintOpacity + * @see DKTools.Sprite.Selectable.prototype.setupItemAlign */ -DKTools.Sprite.Arrow.prototype.setAll = function(object, blockStart, activate) { +DKTools.Sprite.Selectable.prototype.setupAll = function(object) { object = object || {}; - const block = true; - let changed = DKTools.Sprite.Button.prototype.setAll.call(this, object, block); - - if (this.setArrowType(object.arrowType, block)) { - changed++; - } - - if (changed) { - if (!blockStart) { - this.start(); - } - - if (activate) { - this.activate(); - } - } - - return changed; -}; - -/** - * Changes the type of the arrow - * Returns true if the change occurred - * - * @param {String} [type] - Type of the arrow - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @returns {Boolean} Change occurred - */ -DKTools.Sprite.Arrow.prototype.setArrowType = function(type, blockRefreshAll) { - if (this._arrowType === type) { - return false; - } - - const lastType = this._arrowType; - this.setupArrowType(type); - - if (this._arrowType === lastType) { - return false; - } - - if (!blockRefreshAll) { - this.refreshAll(); - } - - return true; -}; - -// refresh methods - -/** - * Updates and redraws all - * - * @override - */ -DKTools.Sprite.Arrow.prototype.refreshAll = function() { - DKTools.Sprite.Button.prototype.refreshAll.call(this); - this.refreshArrow(); -}; - -/** - * Updates and redraws the arrow - */ -DKTools.Sprite.Arrow.prototype.refreshArrow = function() { - const p = 24; - const q = p / 2; - const sx = 96 + p; - const sy = p; - - switch (this._arrowType) { - case 'up': - this.setFrame(sx + q, sy, p, q); - break; - case 'down': - this.setFrame(sx + q, sy + q + p, p, q); - break; - case 'left': - this.setFrame(sx, sy + q, q, p); - break; - case 'right': - this.setFrame(sx + q + p, sy + q, q, p); - break; - default: - throw new Error('Arrow does not have an arrowType!'); - break; - } -}; - - - - - - -//=========================================================================== -// DKTools.Sprite.Selectable -//=========================================================================== - -DKTools.Sprite.Selectable.prototype = Object.create(DKTools.Sprite.Button.prototype); -DKTools.Sprite.Selectable.prototype.constructor = DKTools.Sprite.Selectable; - -// properties - -Object.defineProperties(DKTools.Sprite.Selectable.prototype, { + DKTools.Sprite.Button.prototype.setupAll.call(this, object); + this.setupIndex(object.index); + this.setupMaxCols(object.maxCols); + this.setupFixedHorizontal(object.fixedHorizontal); + this.setupCursorFixed(object.cursorFixed); + this.setupCursorAll(object.cursorAll); + this.setupSpacing(object.horizontalSpacing, object.verticalSpacing); + this.setupTextPadding(object.textPadding); + this.setupItems(object.items); + this.setupDrawItemHandler(object.drawItemHandler); + this.setupItemWidth(object.itemWidth); + this.setupItemHeight(object.itemHeight); + this.setupItemRect(object.itemRect); + this.setupItemFont(object.itemFont); + this.setupItemTextColor(object.itemTextColor); + this.setupItemPaintOpacity(object.itemPaintOpacity); + this.setupItemAlign(object.itemAlign); +}; +/** + * Sets the index + * + * @param {Number} [index=this.standardIndex()] - Index + * + * @see DKTools.Sprite.Selectable.prototype.standardIndex + */ +DKTools.Sprite.Selectable.prototype.setupIndex = function(index) { /** + * @private * @readonly - * @type {DKTools.Sprite.Cursor} - * @memberOf DKTools.Sprite.Selectable.prototype + * @type {Number} */ - cursorSprite: { - get: function() { - return this._cursorSprite; - }, - configurable: true - }, + this._index = (index == null ? this.standardIndex() : index); +}; +/** + * Sets the number of the columns + * + * @param {Number} [cols=this.standardMaxCols()] - Number of the columns + * + * @see DKTools.Sprite.Selectable.prototype.standardMaxCols + */ +DKTools.Sprite.Selectable.prototype.setupMaxCols = function(cols) { /** - * Index - * + * @private * @readonly * @type {Number} - * @memberOf DKTools.Sprite.Selectable.prototype */ - index: { - get: function() { - return this._index; - }, - configurable: true - }, + this._maxCols = cols || this.standardMaxCols(); +}; +/** + * Sets the fixed horizontal position + * + * @param {Boolean} [fixedHorizontal=this.standardFixedHorizontal()] - Fixed horizontal position + * + * @see DKTools.Sprite.Selectable.prototype.standardFixedHorizontal + */ +DKTools.Sprite.Selectable.prototype.setupFixedHorizontal = function(fixedHorizontal) { /** - * Maximum of the columns - * + * @private * @readonly - * @type {Number} - * @memberOf DKTools.Sprite.Selectable.prototype + * @type {Boolean} */ - maxCols: { - get: function() { - return this._maxCols; - }, - configurable: true - }, + this._fixedHorizontal = (fixedHorizontal == null ? this.standardFixedHorizontal() : fixedHorizontal); +}; +/** + * Sets the fixed cursor + * + * @param {Boolean} [cursorFixed=this.standardCursorFixed()] - Fixed cursor + * + * @see DKTools.Sprite.Selectable.prototype.standardCursorFixed + */ +DKTools.Sprite.Selectable.prototype.setupCursorFixed = function(cursorFixed) { /** - * Fixed cursor - * + * @private * @readonly * @type {Boolean} - * @memberOf DKTools.Sprite.Selectable.prototype */ - cursorFixed: { - get: function() { - return this._cursorFixed; - }, - configurable: true - }, + this._cursorFixed = (cursorFixed == null ? this.standardCursorFixed() : cursorFixed); +}; +/** + * Sets the cursor all + * + * @param {Boolean} [cursorAll=this.standardCursorAll()] - Cursor all + * + * @see DKTools.Sprite.Selectable.prototype.standardCursorAll + */ +DKTools.Sprite.Selectable.prototype.setupCursorAll = function(cursorAll) { /** - * Cursor all - * + * @private * @readonly * @type {Boolean} - * @memberOf DKTools.Sprite.Selectable.prototype */ - cursorAll: { - get: function() { - return this._cursorAll; - }, - configurable: true - }, + this._cursorAll = (cursorAll == null ? this.standardCursorAll() : cursorAll); +}; +/** + * Sets the horizontal spacing + * + * @param {Number} [spacing=this.standardHorizontalSpacing()] - Horizontal spacing + * + * @see DKTools.Sprite.Selectable.prototype.standardHorizontalSpacing + */ +DKTools.Sprite.Selectable.prototype.setupHorizontalSpacing = function(spacing) { /** - * Horizontal spacing - * + * @private * @readonly * @type {Number} - * @memberOf DKTools.Sprite.Selectable.prototype */ - horizontalSpacing: { - get: function() { - return this._horizontalSpacing; - }, - configurable: true - }, + this._horizontalSpacing = (spacing == null ? this.standardHorizontalSpacing() : spacing); +}; +/** + * Sets the vertical spacing + * + * @param {Number} [spacing=this.standardVerticalSpacing()] - Vertical spacing + * + * @see DKTools.Sprite.Selectable.prototype.standardVerticalSpacing + */ +DKTools.Sprite.Selectable.prototype.setupVerticalSpacing = function(spacing) { /** - * Vertical spacing - * + * @private * @readonly * @type {Number} - * @memberOf DKTools.Sprite.Selectable.prototype */ - verticalSpacing: { - get: function() { - return this._verticalSpacing; - }, - configurable: true - }, + this._verticalSpacing = (spacing == null ? this.standardVerticalSpacing() : spacing); +}; + +/** + * Sets the horizontal and vertical spacings + * + * @param {Number} [horizontalSpacing] - Horizontal spacing + * @param {Number} [verticalSpacing] - Vertical spacing + * + * @see DKTools.Sprite.Selectable.prototype.setupHorizontalSpacing + * @see DKTools.Sprite.Selectable.prototype.setupVerticalSpacing + */ +DKTools.Sprite.Selectable.prototype.setupSpacing = function(horizontalSpacing, verticalSpacing) { + this.setupHorizontalSpacing(horizontalSpacing); + this.setupVerticalSpacing(verticalSpacing); +}; +/** + * Sets the text padding + * + * @param {Number} [textPadding=this.standardTextPadding()] - Text padding + * + * @see DKTools.Sprite.Selectable.prototype.standardTextPadding + */ +DKTools.Sprite.Selectable.prototype.setupTextPadding = function(textPadding) { /** - * Text padding - * + * @private * @readonly * @type {Number} - * @memberOf DKTools.Sprite.Selectable.prototype */ - textPadding: { - get: function() { - return this._textPadding; - }, - configurable: true - }, + this._textPadding = (textPadding == null ? this.standardTextPadding() : textPadding); +}; - /** - * List of the items - * - * @readonly - * @type {Object[]} - * @memberOf DKTools.Sprite.Selectable.prototype - */ - items: { - get: function() { - return this._items; - }, - configurable: true - }, +/** + * Sets the list of the items + * + * @param {Object[]} items - Items + * + * @param {Function | String} [items[].name] - Item name + * @param {Function | String} [items[].align] - Item align + * @param {Function | String} [items[].textColor] - Item text color + * @param {Function | Object} [items[].font] - Item font + * @param {Function | Number} [items[].paintOpacity] - Item paint opacity + * @param {Function | Boolean} [items[].enabled] - Item activity + * @param {String} [items[].symbol] - Item symbol + * @param {Function} [items[].handler] - Item handler + * @param {String} [items[].font.fontFace] - Font face + * @param {Number} [items[].font.fontSize] - Font size + * @param {Boolean} [items[].font.fontItalic] - Font italic + */ +DKTools.Sprite.Selectable.prototype.setupItems = function(items) { + if (items == null) { + items = this.standardItems(); + } - /** - * Handler of draw of the item - * - * @readonly - * @type {Function | null} - * @memberOf DKTools.Sprite.Selectable.prototype - */ - drawItemHandler: { - get: function() { - return this._drawItemHandler; - }, - configurable: true - }, + _.forEach(items, this._checkItem.bind(this)); + + this._items = items; +}; +/** + * Sets the handler of draw of the item + * + * @param {Function} [handler=this.standardDrawItemHandler()] - Handler of draw of the item + * + * @see DKTools.Sprite.Selectable.prototype.standardDrawItemHandler + */ +DKTools.Sprite.Selectable.prototype.setupDrawItemHandler = function(handler) { /** - * Width of the item - * + * @private * @readonly - * @type {Function | Number} - * @memberOf DKTools.Sprite.Selectable.prototype + * @type {Function | null} */ - itemWidth: { - get: function() { - return this._itemWidth; - }, - configurable: true - }, + this._drawItemHandler = handler || this.standardDrawItemHandler(); +}; +/** + * Sets the width of the item + * + * @param {Function | Number} [itemWidth=this.standardItemWidth()] - Width of the item + * + * @see DKTools.Sprite.Selectable.prototype.standardItemWidth + */ +DKTools.Sprite.Selectable.prototype.setupItemWidth = function(itemWidth) { /** - * Height of the item - * + * @private * @readonly * @type {Function | Number} - * @memberOf DKTools.Sprite.Selectable.prototype */ - itemHeight: { - get: function() { - return this._itemHeight; - }, - configurable: true - }, + this._itemWidth = itemWidth || this.standardItemWidth(); +}; +/** + * Sets the height of the item + * + * @param {Function | Number} [itemHeight=this.standardItemHeight()] - Height of the item + * + * @see DKTools.Sprite.Selectable.prototype.standardItemHeight + */ +DKTools.Sprite.Selectable.prototype.setupItemHeight = function(itemHeight) { /** - * Font of the item - * + * @private * @readonly - * @type {Function | Object} - * @memberOf DKTools.Sprite.Selectable.prototype + * @type {Function | Number} */ - itemFont: { - get: function() { - return this._itemFont; - }, - configurable: true - }, + this._itemHeight = itemHeight || this.standardItemHeight(); +}; +/** + * Sets the rectangle of the item + * + * @param {Function} [itemRect=this.standardItemRect()] - Rectangle of the item + * + * @see DKTools.Sprite.Selectable.prototype.standardItemRect + */ +DKTools.Sprite.Selectable.prototype.setupItemRect = function(itemRect) { /** - * Text color of the item - * + * @private * @readonly - * @type {Function | String} - * @memberOf DKTools.Sprite.Selectable.prototype + * @type {Function} */ - itemTextColor: { - get: function() { - return this._itemTextColor; - }, - configurable: true - }, + this._itemRect = itemRect || this.standardItemRect(); +}; +/** + * Sets the font of the item + * + * @param {Function | Object} [itemFont=this.standardItemFont()] - Font of the item + * + * @param {String} [itemFont.fontFace] - Font face + * @param {Number} [itemFont.fontSize] - Font size + * @param {Boolean} [itemFont.fontItalic] - Font italic + * + * @see DKTools.Sprite.Selectable.prototype.standardItemFont + */ +DKTools.Sprite.Selectable.prototype.setupItemFont = function(itemFont) { /** - * Paint opacity of the item - * + * @private * @readonly - * @type {Function | Number} - * @memberOf DKTools.Sprite.Selectable.prototype + * @type {Function | Object} */ - itemPaintOpacity: { - get: function() { - return this._itemPaintOpacity; - }, - configurable: true - }, + this._itemFont = itemFont || this.standardItemFont(); +}; +/** + * Sets the text color of the item + * + * @param {Function | String} [itemTextColor=this.standardItemTextColor()] - Text color of the item + * + * @see DKTools.Sprite.Selectable.prototype.standardItemTextColor + */ +DKTools.Sprite.Selectable.prototype.setupItemTextColor = function(itemTextColor) { /** - * Align of the item - * + * @private * @readonly * @type {Function | String} - * @memberOf DKTools.Sprite.Selectable.prototype */ - itemAlign: { - get: function() { - return this._itemAlign; - }, - configurable: true - } - -}); - -// _clear methods + this._itemTextColor = itemTextColor || this.standardItemTextColor(); +}; /** - * Clears all data + * Sets the paint opacity of the item * - * @private - * @override + * @param {Function | Number} [itemPaintOpacity=this.standardItemPaintOpacity()] - Paint opacity of the item * - * @see DKTools.Sprite.Button.prototype._clearAll - * @see DKTools.Sprite.Selectable.prototype._clearItems - * @see DKTools.Sprite.Selectable.prototype._clearHandlers - * @see DKTools.Sprite.Selectable.prototype._clearTopRow - * @see DKTools.Sprite.Selectable.prototype._clearTopCol + * @see DKTools.Sprite.Selectable.prototype.standardItemPaintOpacity */ -DKTools.Sprite.Selectable.prototype._clearAll = function() { - DKTools.Sprite.Button.prototype._clearAll.call(this); - this._clearItems(); - this._clearHandlers(); - this._clearTopRow(); - this._clearTopCol(); +DKTools.Sprite.Selectable.prototype.setupItemPaintOpacity = function(itemPaintOpacity) { + /** + * @private + * @readonly + * @type {Function | Number} + */ + this._itemPaintOpacity = itemPaintOpacity || this.standardItemPaintOpacity(); }; /** - * Clears items + * Sets the align of the item * - * @private + * @param {Function | String} [itemAlign=this.standardItemAlign()] - Align of the item + * + * @see DKTools.Sprite.Selectable.prototype.standardItemAlign */ -DKTools.Sprite.Selectable.prototype._clearItems = function() { +DKTools.Sprite.Selectable.prototype.setupItemAlign = function(itemAlign) { /** * @private * @readonly - * @type {Object[]} + * @type {Function | String} */ - this._items = []; + this._itemAlign = itemAlign || this.standardItemAlign(); }; +// set methods + /** - * Clears the selection handlers + * Changes all parameters + * Returns the number of changed parameters * - * @private + * @override + * + * @param {Object} [object={}] - Parameters + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [activate=false] - Activates the object + * + * @param {Number} [object.index] - Index + * @param {Number} [object.maxCols] - Number of the columns + * @param {Boolean} [object.fixedHorizontal] - Fixed horizontal position + * @param {Boolean} [object.cursorFixed] - Fixed cursor + * @param {Boolean} [object.cursorAll] - Cursor all + * @param {Number} [object.horizontalSpacing] - Horizontal spacing + * @param {Number} [object.verticalSpacing] - Vertical spacing + * @param {Number} [object.textPadding] - Text padding + * @param {Object[]} [object.items] - List of the items + * @param {Function} [object.drawItemHandler] - Handler of draw of the item + * @param {Function | Number} [object.itemWidth] - Width of the item + * @param {Function | Number} [object.itemHeight] - Height of the item + * @param {Function} [object.itemRect] - Rectangle of the item + * @param {Function | Object} [object.itemFont] - Font of the item + * @param {Function | String} [object.itemTextColor] - Text color of the item + * @param {Function | Number} [object.itemPaintOpacity] - Paint opacity of the item + * @param {Function | String} [object.itemAlign] - Align of the item + * + * @param {String} [object.font.fontFace] - Font face + * @param {Number} [object.font.fontSize] - Font size + * @param {Boolean} [object.font.fontItalic] - Font italic + * + * @see DKTools.Sprite.Button.prototype.setAll + * @see DKTools.Sprite.Selectable.prototype.setIndex + * @see DKTools.Sprite.Selectable.prototype.setMaxCols + * @see DKTools.Sprite.Selectable.prototype.setFixedHorizontal + * @see DKTools.Sprite.Selectable.prototype.setCursorFixed + * @see DKTools.Sprite.Selectable.prototype.setCursorAll + * @see DKTools.Sprite.Selectable.prototype.setSpacing + * @see DKTools.Sprite.Selectable.prototype.setTextPadding + * @see DKTools.Sprite.Selectable.prototype.setItems + * @see DKTools.Sprite.Selectable.prototype.setDrawItemHandler + * @see DKTools.Sprite.Selectable.prototype.setItemWidth + * @see DKTools.Sprite.Selectable.prototype.setItemHeight + * @see DKTools.Sprite.Selectable.prototype.setItemRect + * @see DKTools.Sprite.Selectable.prototype.setItemFont + * @see DKTools.Sprite.Selectable.prototype.setItemTextColor + * @see DKTools.Sprite.Selectable.prototype.setItemPaintOpacity + * @see DKTools.Sprite.Selectable.prototype.setItemAlign + * @see DKTools.Sprite.Selectable.prototype.start + * @see DKTools.Sprite.Selectable.prototype.activate + * + * @returns {Number} Number of changed parameters */ -DKTools.Sprite.Selectable.prototype._clearHandlers = function() { - /** - * @readonly - * @private - * @type {Object} - */ - this._handlers = {}; -}; +DKTools.Sprite.Selectable.prototype.setAll = function(object, blockStart, activate) { + object = object || {}; + const block = true; + let changed = DKTools.Sprite.Button.prototype.setAll.call(this, object, block); + + if (this.setIndex(object.index, block)) { + changed++; + } + + if (this.setMaxCols(object.maxCols, block)) { + changed++; + } + + if (this.setFixedHorizontal(object.fixedHorizontal, block)) { + changed++; + } + + if (this.setCursorFixed(object.cursorFixed, block)) { + changed++; + } + + if (this.setCursorAll(object.cursorAll, block)) { + changed++; + } + + changed += this.setSpacing(object.horizontalSpacing, object.verticalSpacing, block); + + if (this.setTextPadding(object.textPadding, block)) { + changed++; + } + + if (this.setItems(object.items, block)) { + changed++; + } + + if (this.setDrawItemHandler(object.drawItemHandler, block)) { + changed++; + } + + if (this.setItemWidth(object.itemWidth, block)) { + changed++; + } + + if (this.setItemHeight(object.itemHeight, block)) { + changed++; + } + + if (this.setItemRect(object.itemRect, block)) { + changed++; + } + + if (this.setItemFont(object.itemFont, block)) { + changed++; + } + + if (this.setItemTextColor(object.itemTextColor, block)) { + changed++; + } + + if (this.setItemPaintOpacity(object.itemPaintOpacity, block)) { + changed++; + } + + if (this.setItemAlign(object.itemAlign, block)) { + changed++; + } + + if (changed) { + if (!blockStart) { + this.start(); + } + + if (activate) { + this.activate(); + } + } -/** - * Clears the top row - * - * @private - */ -DKTools.Sprite.Selectable.prototype._clearTopRow = function() { - /** - * @private - * @readonly - * @type {Number} - */ - this._topRow = 0; + return changed; }; /** - * Clears the top col + * Changes the index + * Returns true if the change occurred * - * @private - */ -DKTools.Sprite.Selectable.prototype._clearTopCol = function() { - /** - * @private - * @readonly - * @type {Number} - */ - this._topCol = 0; -}; - -// _create methods - -/** - * Creates all + * @param {Number} [index] - Index + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @private - * @override + * @see DKTools.Sprite.Selectable.prototype.setupIndex + * @see DKTools.Sprite.Selectable.prototype.refreshAll * - * @see DKTools.Sprite.Button.prototype._createAll - * @see DKTools.Sprite.Selectable.prototype._createCursorSprite + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype._createAll = function() { - DKTools.Sprite.Button.prototype._createAll.call(this); - this._createCursorSprite(); -}; +DKTools.Sprite.Selectable.prototype.setIndex = function(index, blockRefreshAll) { + if (this._index === index) { + return false; + } -/** - * Creates sprite of the cursor - * - * @private - */ -DKTools.Sprite.Selectable.prototype._createCursorSprite = function() { - /** - * @private - * @readonly - * @type {DKTools.Sprite.Cursor} - */ - this._cursorSprite = new DKTools.Sprite.Cursor(); -}; + const lastIndex = this._index; + this.setupIndex(index); -// _setup methods + if (this._index === lastIndex) { + return false; + } -/** - * Sets the events - * - * @private - * @override - * - * @see DKTools.Sprite.Button.prototype._setupEvents - * @see DKTools.Sprite.Selectable.prototype._setupClickEvent - * @see DKTools.Sprite.Selectable.prototype._setupLongPressEvent - * @see DKTools.Sprite.Selectable.prototype._setupMouseHoverEvents - * @see DKTools.Sprite.Selectable.prototype._setupWheelScrollEvents - */ -DKTools.Sprite.Selectable.prototype._setupEvents = function() { - DKTools.Sprite.Button.prototype._setupEvents.call(this); - this._setupClickEvent(); - this._setupLongPressEvent(); - this._setupMouseHoverEvents(); - this._setupWheelScrollEvents(); -}; + if (!blockRefreshAll) { + this.refreshAll(); + } -/** - * Sets the event of the click (mouse-click-left) - * - * @private - * - * @see DKTools.Sprite.Selectable.prototype.addEvent - */ -DKTools.Sprite.Selectable.prototype._setupClickEvent = function() { - this.addEvent({ - type: 'mouse-click-left', - onUpdate: this._onTouch.bind(this, true) - }); + return true; }; /** - * Sets the event of the long press (mouse-long-press-left) + * Changes the number of the columns + * Returns true if the change occurred * - * @private + * @param {Number} [cols] - Number of the columns + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.setupMaxCols + * @see DKTools.Sprite.Selectable.prototype.refreshAll * - * @see DKTools.Sprite.Selectable.prototype.addEvent + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype._setupLongPressEvent = function() { - this.addEvent({ - type: 'mouse-long-press-left', - onUpdate: this._onTouch.bind(this, false) - }); +DKTools.Sprite.Selectable.prototype.setMaxCols = function(cols, blockRefreshAll) { + if (this._maxCols === cols) { + return false; + } + + const lastCols = this._maxCols; + this.setupMaxCols(cols); + + if (this._maxCols === lastCols) { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Sets the events of the mouse hover (mouse-enter and mouse-move) - * - * @private + * Changes the fixed horizontal position + * Returns true if the change occurred * - * @see DKTools.Sprite.Selectable.prototype.addEvent + * @param {Boolean} [fixedHorizontal] + * @param {Boolean} [blockRefreshAll=false] Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.setupFixedHorizontal + * @see DKTools.Sprite.Selectable.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype._setupMouseHoverEvents = function() { - this.addEvent({ - type: 'mouse-enter', - onUpdate: this.processMouseHover.bind(this) - }); +DKTools.Sprite.Selectable.prototype.setFixedHorizontal = function(fixedHorizontal, blockRefreshAll) { + if (this._fixedHorizontal === fixedHorizontal) { + return false; + } - this.addEvent({ - type: 'mouse-move', - onUpdate: this.processMouseHover.bind(this) - }); + const lastFixed = this._fixedHorizontal; + this.setupFixedHorizontal(fixedHorizontal); + + if (this._fixedHorizontal === lastFixed) { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Sets the events of the wheel scrolling (wheel-Y-inside and wheel-Y-outside) - * - * @private + * Changes the fixed cursor + * Returns true if the change occurred * - * @see DKTools.Sprite.Selectable.prototype.addEvent + * @param {Boolean} [cursorFixed] - Fixed cursor + * @param {Boolean} [blockRefreshAll=false] Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.setupCursorFixed + * @see DKTools.Sprite.Selectable.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype._setupWheelScrollEvents = function() { - this.addEvent({ - type: 'wheel-Y-inside', - onUpdate: this.processWheelScroll.bind(this) - }); +DKTools.Sprite.Selectable.prototype.setCursorFixed = function(cursorFixed, blockRefreshAll) { + if (this._cursorFixed === cursorFixed) { + return false; + } - this.addEvent({ - type: 'wheel-Y-outside', - onUpdate: this.processWheelScroll.bind(this) - }); -}; + const lastFixed = this._cursorFixed; + this.setupCursorFixed(cursorFixed); -// _add methods + if (this._cursorFixed === lastFixed) { + return false; + } -/** - * Adds children objects to processing - * - * @private - * @override - * - * @see DKTools.Sprite.Button.prototype._addAllChildren - * @see DKTools.Sprite.Selectable.prototype._addCursorSprite - */ -DKTools.Sprite.Selectable.prototype._addAllChildren = function() { - DKTools.Sprite.Button.prototype._addAllChildren.call(this); - this._addCursorSprite(); + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Adds sprite of the cursor to processing - * - * @private + * Changes the cursor all + * Returns true if the change occurred + * + * @param {Boolean} [cursorAll] - Cursor all + * @param {Boolean} [blockRefreshAll=false] Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.setupCursorAll + * @see DKTools.Sprite.Selectable.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype._addCursorSprite = function() { - this.addChild(this._cursorSprite); -}; +DKTools.Sprite.Selectable.prototype.setCursorAll = function(cursorAll, blockRefreshAll) { + if (this._cursorAll === cursorAll) { + return false; + } -// standard methods + const lastAll = this._cursorAll; + this.setupCursorAll(cursorAll); -/** - * Returns the standard index - * - * @returns {Number} Standard index - */ -DKTools.Sprite.Selectable.prototype.standardIndex = function() { - return 0; -}; + if (this._cursorAll === lastAll) { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); + } -/** - * Returns the standard number of the columns - * - * @returns {Number} Standard number of the columns - */ -DKTools.Sprite.Selectable.prototype.standardMaxCols = function() { - return 1; + return true; }; /** - * Returns the standard fixed cursor + * Changes the horizontal spacing + * Returns true if the change occurred * - * @returns {Boolean} Standard fixed cursor - */ -DKTools.Sprite.Selectable.prototype.standardCursorFixed = function() { - return false; -}; - -/** - * Returns the standard cursor all + * @param {Number} [spacing] - Horizontal spacing + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @returns {Boolean} Standard cursor all + * @see DKTools.Sprite.Selectable.prototype.setupHorizontalSpacing + * @see DKTools.Sprite.Selectable.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype.standardCursorAll = function() { - return false; -}; +DKTools.Sprite.Selectable.prototype.setHorizontalSpacing = function(spacing, blockRefreshAll) { + if (this._horizontalSpacing === spacing) { + return false; + } -/** - * Returns the standard fixed horizontal position - * - * @returns {Boolean} Standard fixed horizontal position - */ -DKTools.Sprite.Selectable.prototype.standardFixedHorizontal = function() { - return false; -}; + const lastSpacing = this._horizontalSpacing; + this.setupHorizontalSpacing(spacing); -/** - * Returns the standard horizontal spacing - * - * @returns {Number} Standard horizontal spacing - */ -DKTools.Sprite.Selectable.prototype.standardHorizontalSpacing = function() { - return 0;12; -}; + if (this._horizontalSpacing === lastSpacing) { + return false; + } -/** - * Returns the standard vertical spacing - * - * @returns {Number} Standard vertical spacing - */ -DKTools.Sprite.Selectable.prototype.standardVerticalSpacing = function() { - return 0; -}; + if (!blockRefreshAll) { + this.refreshAll(); + } -/** - * Returns the standard text padding - * - * @returns {Number} Standard text padding - */ -DKTools.Sprite.Selectable.prototype.standardTextPadding = function() { - return 6; + return true; }; /** - * Returns the standard list of the items + * Changes the vertical spacing + * Returns true if the change occurred * - * @returns {Array} Standard list of the items - */ -DKTools.Sprite.Selectable.prototype.standardItems = function() { - return []; -}; - -/** - * Returns the standard handler of draw of the item + * @param {Number} [spacing] - Vertical spacing + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @returns {Function} Standard handler of draw of the item + * @see DKTools.Sprite.Selectable.prototype.setupVerticalSpacing + * @see DKTools.Sprite.Selectable.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype.standardDrawItemHandler = function() { - return function(index) { - const name = this.getItemName(index); - const font = this.getItemFontByIndex(index); - const textColor = this.getItemTextColorByIndex(index); - const paintOpacity = this.getItemPaintOpacityByIndex(index); - const align = this.getItemAlignByIndex(index); - const rect = this.getItemRectForTextByIndex(index); +DKTools.Sprite.Selectable.prototype.setVerticalSpacing = function(spacing, blockRefreshAll) { + if (this._verticalSpacing === spacing) { + return false; + } - this.drawText(name, { - font: font, - textColor: textColor, - paintOpacity: paintOpacity, - align: align, - rect: rect, - resetFont: true, - resetTextColor: true, - resetPaintOpacity: true - }); - }.bind(this); -}; + const lastSpacing = this._verticalSpacing; + this.setupVerticalSpacing(spacing); -/** - * Returns the standard item width - * - * @returns {Function} Standard item width - */ -DKTools.Sprite.Selectable.prototype.standardItemWidth = function() { - return function() { - const spacing = this._horizontalSpacing; - return Math.floor((this.realWidth + spacing) / this.getMaxCols() - spacing); - }.bind(this); -}; + if (this._verticalSpacing === lastSpacing) { + return false; + } -/** - * Returns the standard item height - * - * @returns {Function} Standard item height - */ -DKTools.Sprite.Selectable.prototype.standardItemHeight = function() { - return this.getLineHeight(); -}; + if (!blockRefreshAll) { + this.refreshAll(); + } -/** - * Returns the standard item rect - * - * @returns {Function} Standard item rect - */ -DKTools.Sprite.Selectable.prototype.standardItemRect = function() { - return function(index) { - const rect = new Rectangle(); - const maxCols = this.getMaxCols(); - rect.width = this.getItemWidth(); - rect.height = this.getItemHeight(); - if (this.isHorizontal()) { - rect.x = (index - this.getTopCol()) * (rect.width + this._horizontalSpacing); - rect.y = 0; - } else { - rect.x = index % maxCols * (rect.width + this._horizontalSpacing); - rect.y = (Math.floor(index / maxCols) - this.getTopRow()) * (rect.height + this._verticalSpacing); - } - return rect; - }.bind(this); + return true; }; /** - * Returns the standard item font + * Changes the horizontal and vertical spacings + * Returns the number of changed parameters * - * @returns {Object} Standard item font - */ -DKTools.Sprite.Selectable.prototype.standardItemFont = function() { - return this.font; -}; - -/** - * Returns the standard text color of the item + * @param {Number} [horizontalSpacing] - Horizontal spacing + * @param {Number} [verticalSpacing] - Vertical spacing + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @returns {String} Standard text color of the item + * @see DKTools.Sprite.Selectable.prototype.setHorizontalSpacing + * @see DKTools.Sprite.Selectable.prototype.setVerticalSpacing + * + * @returns {Number} Number of changed parameters */ -DKTools.Sprite.Selectable.prototype.standardItemTextColor = function() { - return this.textColor; +DKTools.Sprite.Selectable.prototype.setSpacing = function(horizontalSpacing, verticalSpacing, blockRefreshAll) { + const block = true; + let changed = 0; + + if (this.setHorizontalSpacing(horizontalSpacing, block)) { + changed++; + } + + if (this.setVerticalSpacing(verticalSpacing, block)) { + changed++; + } + + if (changed && !blockRefreshAll) { + this.refreshAll(); + } + + return changed; }; /** - * Returns the standard paint opacity of the item + * Changes the text padding + * Returns true if the change occurred * - * @returns {Number} Standard paint opacity of the item + * @param {Number} [textPadding] - Text padding + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.setupTextPadding + * @see DKTools.Sprite.Selectable.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype.standardItemPaintOpacity = function() { - return function(index) { - if (this.isItemEnabled(index)) { - return this.standardEnabledItemPaintOpacity(); - } else { - return this.standardDisabledItemPaintOpacity(); - } - }.bind(this); +DKTools.Sprite.Selectable.prototype.setTextPadding = function(textPadding, blockRefreshAll) { + if (this._textPadding === textPadding) { + return false; + } + + const lastPadding = this._textPadding; + this.setupTextPadding(textPadding); + + if (this._textPadding === lastPadding) { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Returns the standard paint opacity of the enabled item + * Changes the items + * Returns true if the change occurred * - * @returns {Number} Standard paint opacity of the enabled item + * @param {Object[]} [items] - List of the items + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.setupItems + * @see DKTools.Sprite.Selectable.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype.standardEnabledItemPaintOpacity = function() { - return 255; +DKTools.Sprite.Selectable.prototype.setItems = function(items, blockRefreshAll) { + if (this._items == items) { + return false; + } + + this.setupItems(items); + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Returns the standard paint opacity of the disabled item + * Changes the handler of draw of the item + * Returns true if the change occurred * - * @returns {Number} Standard paint opacity of the disabled item + * @param {Function} [handler] - Handler of draw of the item + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.setupDrawItemHandler + * @see DKTools.Sprite.Selectable.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype.standardDisabledItemPaintOpacity = function() { - try { - return Window_Base.prototype.translucentOpacity.call(this); - } catch(e) { - return 160; +DKTools.Sprite.Selectable.prototype.setDrawItemHandler = function(handler, blockRefreshAll) { + if (this._drawItemHandler === handler) { + return false; } -}; -/** - * Returns the standard item align - * - * @returns {String} Standard item align - */ -DKTools.Sprite.Selectable.prototype.standardItemAlign = function() { - return this.align; -}; + const lastHandler = this._drawItemHandler; + this.setupDrawItemHandler(handler); -// setup methods + if (this._drawItemHandler === lastHandler) { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; +}; /** - * Sets all parameters - * - * @override - * - * @param {Object} [object] - Parameters + * Changes the width of the item + * Returns true if the change occurred * - * @param {Number} [object.index] - Index - * @param {Number} [object.maxCols] - Number of the columns - * @param {Boolean} [object.fixedHorizontal] - Fixed horizontal position - * @param {Boolean} [object.cursorFixed] - Fixed cursor - * @param {Boolean} [object.cursorAll] - Cursor all - * @param {Number} [object.horizontalSpacing] - Horizontal spacing - * @param {Number} [object.verticalSpacing] - Vertical spacing - * @param {Number} [object.textPadding] - Text padding - * @param {Object[]} [object.items] - List of the items - * @param {Function} [object.drawItemHandler] - Handler of draw of the item - * @param {Function | Number} [object.itemWidth] - Width of the item - * @param {Function | Number} [object.itemHeight] - Height of the item - * @param {Function} [object.itemRect] - Rectangle of the item - * @param {Function | Object} [object.itemFont] - Font of the item - * @param {Function | String} [object.itemTextColor] - Text color of the item - * @param {Function | Number} [object.itemPaintOpacity] - Paint opacity of the item - * @param {Function | String} [object.itemAlign] - Align of the item + * @param {Function | Number} [itemWidth] - Width of the item + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @param {String} [object.font.fontFace] - Font face - * @param {Number} [object.font.fontSize] - Font size - * @param {Boolean} [object.font.fontItalic] - Font italic + * @see DKTools.Sprite.Selectable.prototype.setupItemWidth + * @see DKTools.Sprite.Selectable.prototype.refreshAll * - * @see DKTools.Sprite.Button.prototype.setupAll - * @see DKTools.Sprite.Selectable.prototype.setupItems + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype.setupAll = function(object) { - object = object || {}; - DKTools.Sprite.Button.prototype.setupAll.call(this, object); - this.setupIndex(object.index); - this.setupMaxCols(object.maxCols); - this.setupFixedHorizontal(object.fixedHorizontal); - this.setupCursorFixed(object.cursorFixed); - this.setupCursorAll(object.cursorAll); - this.setupSpacing(object.horizontalSpacing, object.verticalSpacing); - this.setupTextPadding(object.textPadding); - this.setupItems(object.items); - this.setupDrawItemHandler(object.drawItemHandler); - this.setupItemWidth(object.itemWidth); - this.setupItemHeight(object.itemHeight); - this.setupItemRect(object.itemRect); - this.setupItemFont(object.itemFont); - this.setupItemTextColor(object.itemTextColor); - this.setupItemPaintOpacity(object.itemPaintOpacity); - this.setupItemAlign(object.itemAlign); +DKTools.Sprite.Selectable.prototype.setItemWidth = function(itemWidth, blockRefreshAll) { + if (this._itemWidth === itemWidth) { + return false; + } + + const lastWidth = this._itemWidth; + this.setupItemWidth(itemWidth); + + if (this._itemWidth === lastWidth) { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Sets the index + * Changes the height of the item + * Returns true if the change occurred * - * @param {Number} [index=this.standardIndex()] - Index + * @param {Function | Number} [itemHeight] - Height of the item + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.Selectable.prototype.standardIndex + * @see DKTools.Sprite.Selectable.prototype.setupItemHeight + * @see DKTools.Sprite.Selectable.prototype.refreshAll + * + * @returns {Boolean} Change occured */ -DKTools.Sprite.Selectable.prototype.setupIndex = function(index) { - /** - * @private - * @readonly - * @type {Number} - */ - this._index = (index == null ? this.standardIndex() : index); +DKTools.Sprite.Selectable.prototype.setItemHeight = function(itemHeight, blockRefreshAll) { + if (this._itemHeight === itemHeight) { + return false; + } + + const lastHeight = this._itemHeight; + this.setupItemHeight(itemHeight); + + if (this._itemHeight === lastHeight) { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Sets the number of the columns + * Changes the font of the item + * Returns true if the change occurred * - * @param {Number} [cols=this.standardMaxCols()] - Number of the columns + * @param {Function | Object} [itemFont] - Font of the item + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.Selectable.prototype.standardMaxCols + * @see DKTools.Sprite.Selectable.prototype.setupItemFont + * @see DKTools.Sprite.Selectable.prototype.refreshAll + * + * @returns {Boolean} Change occured */ -DKTools.Sprite.Selectable.prototype.setupMaxCols = function(cols) { - /** - * @private - * @readonly - * @type {Number} - */ - this._maxCols = cols || this.standardMaxCols(); -}; +DKTools.Sprite.Selectable.prototype.setItemFont = function(itemFont, blockRefreshAll) { + if (this._itemFont === itemFont) { + return false; + } -/** - * Sets the fixed horizontal position - * - * @param {Boolean} [fixedHorizontal=this.standardFixedHorizontal()] - Fixed horizontal position - * - * @see DKTools.Sprite.Selectable.prototype.standardFixedHorizontal - */ -DKTools.Sprite.Selectable.prototype.setupFixedHorizontal = function(fixedHorizontal) { - /** - * @private - * @readonly - * @type {Boolean} - */ - this._fixedHorizontal = (fixedHorizontal == null ? this.standardFixedHorizontal() : fixedHorizontal); -}; + const lastFont = this._itemFont; + this.setupItemFont(itemFont); -/** - * Sets the fixed cursor - * - * @param {Boolean} [cursorFixed=this.standardCursorFixed()] - Fixed cursor - * - * @see DKTools.Sprite.Selectable.prototype.standardCursorFixed - */ -DKTools.Sprite.Selectable.prototype.setupCursorFixed = function(cursorFixed) { - /** - * @private - * @readonly - * @type {Boolean} - */ - this._cursorFixed = (cursorFixed == null ? this.standardCursorFixed() : cursorFixed); -}; + if (this._itemFont === lastFont) { + return false; + } -/** - * Sets the cursor all - * - * @param {Boolean} [cursorAll=this.standardCursorAll()] - Cursor all - * - * @see DKTools.Sprite.Selectable.prototype.standardCursorAll - */ -DKTools.Sprite.Selectable.prototype.setupCursorAll = function(cursorAll) { - /** - * @private - * @readonly - * @type {Boolean} - */ - this._cursorAll = (cursorAll == null ? this.standardCursorAll() : cursorAll); + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Sets the horizontal spacing + * Changes the text color of the item + * Returns true if the change occurred + * + * @param {Function | String} [itemTextColor] - Text color of the item + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @param {Number} [spacing=this.standardHorizontalSpacing()] - Horizontal spacing + * @see DKTools.Sprite.Selectable.prototype.setupItemTextColor + * @see DKTools.Sprite.Selectable.prototype.refreshAll * - * @see DKTools.Sprite.Selectable.prototype.standardHorizontalSpacing + * @returns {Boolean} Change occured */ -DKTools.Sprite.Selectable.prototype.setupHorizontalSpacing = function(spacing) { - /** - * @private - * @readonly - * @type {Number} - */ - this._horizontalSpacing = (spacing == null ? this.standardHorizontalSpacing() : spacing); +DKTools.Sprite.Selectable.prototype.setItemTextColor = function(itemTextColor, blockRefreshAll) { + if (this._itemTextColor === itemTextColor) { + return false; + } + + const lastTextColor = this._itemTextColor; + this.setupItemTextColor(itemTextColor); + + if (this._itemTextColor === lastTextColor) { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Sets the vertical spacing + * Changes the item paint opacity + * Returns true if the change occurred * - * @param {Number} [spacing=this.standardVerticalSpacing()] - Vertical spacing + * @param {Function | Number} [itemPaintOpacity] - Paint opacity of the item + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.Selectable.prototype.standardVerticalSpacing - */ -DKTools.Sprite.Selectable.prototype.setupVerticalSpacing = function(spacing) { - /** - * @private - * @readonly - * @type {Number} - */ - this._verticalSpacing = (spacing == null ? this.standardVerticalSpacing() : spacing); -}; - -/** - * Sets the horizontal and vertical spacings + * @see DKTools.Sprite.Selectable.prototype.setupItemPaintOpacity + * @see DKTools.Sprite.Selectable.prototype.refreshAll * - * @param {Number} [horizontalSpacing] - Horizontal spacing - * @param {Number} [verticalSpacing] - Vertical spacing - * - * @see DKTools.Sprite.Selectable.prototype.setupHorizontalSpacing - * @see DKTools.Sprite.Selectable.prototype.setupVerticalSpacing + * @returns {Boolean} Change occured */ -DKTools.Sprite.Selectable.prototype.setupSpacing = function(horizontalSpacing, verticalSpacing) { - this.setupHorizontalSpacing(horizontalSpacing); - this.setupVerticalSpacing(verticalSpacing); +DKTools.Sprite.Selectable.prototype.setItemPaintOpacity = function(itemPaintOpacity, blockRefreshAll) { + if (this._itemPaintOpacity === itemPaintOpacity) { + return false; + } + + const lastPaintOpacity = this._itemPaintOpacity; + this.setupItemPaintOpacity(itemPaintOpacity); + + if (this._itemPaintOpacity === lastPaintOpacity) { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Sets the text padding + * Changes the align of the item + * Returns true if the change occurred * - * @param {Number} [textPadding=this.standardTextPadding()] - Text padding - * - * @see DKTools.Sprite.Selectable.prototype.standardTextPadding + * @param {Function | String} [itemAlign] - Align of the item + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.setupItemAlign + * @see DKTools.Sprite.Selectable.prototype.refreshAll + * + * @returns {Boolean} Change occured */ -DKTools.Sprite.Selectable.prototype.setupTextPadding = function(textPadding) { - /** - * @private - * @readonly - * @type {Number} - */ - this._textPadding = (textPadding == null ? this.standardTextPadding() : textPadding); +DKTools.Sprite.Selectable.prototype.setItemAlign = function(itemAlign, blockRefreshAll) { + if (this._itemAlign === itemAlign) { + return false; + } + + const lastAlign = this._itemAlign; + this.setupItemAlign(itemAlign); + + if (this._itemAlign === lastAlign) { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Sets the list of the items - * - * @param {Object[]} items - Items + * Changes the top row * - * @param {Function | String} [items[].name] - Item name - * @param {Function | String} [items[].align] - Item align - * @param {Function | String} [items[].textColor] - Item text color - * @param {Function | Object} [items[].font] - Item font - * @param {Function | Number} [items[].paintOpacity] - Item paint opacity - * @param {Function | Boolean} [items[].enabled] - Item activity - * @param {String} [items[].symbol] - Item symbol - * @param {Function} [items[].handler] - Item handler - * @param {String} [items[].font.fontFace] - Font face - * @param {Number} [items[].font.fontSize] - Font size - * @param {Boolean} [items[].font.fontItalic] - Font italic + * @param {Number} row - Row + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.getMaxTopRow + * @see DKTools.Sprite.Selectable.prototype.refreshAll */ -DKTools.Sprite.Selectable.prototype.setupItems = function(items) { - if (items == null) { - items = this.standardItems(); - } +DKTools.Sprite.Selectable.prototype.setTopRow = function(row, blockRefreshAll) { + const topRow = _.clamp(row, 0, this.getMaxTopRow()); - _.forEach(items, this._checkItem.bind(this)); + if (this._topRow !== topRow) { + this._topRow = topRow; - this._items = items; + if (!blockRefreshAll) { + this.refreshAll(); + } + } }; /** - * Sets the handler of draw of the item - * - * @param {Function} [handler=this.standardDrawItemHandler()] - Handler of draw of the item + * Changes the top column * - * @see DKTools.Sprite.Selectable.prototype.standardDrawItemHandler + * @param {Number} col - Column + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.getMaxTopCol + * @see DKTools.Sprite.Selectable.prototype.refreshAll */ -DKTools.Sprite.Selectable.prototype.setupDrawItemHandler = function(handler) { - /** - * @private - * @readonly - * @type {Function | null} - */ - this._drawItemHandler = handler || this.standardDrawItemHandler(); +DKTools.Sprite.Selectable.prototype.setTopCol = function(col, blockRefreshAll) { + const topCol = _.clamp(col, 0, this.getMaxTopCol()); + + if (this._topCol !== topCol) { + this._topCol = topCol; + + if (!blockRefreshAll) { + this.refreshAll(); + } + } }; /** - * Sets the width of the item - * - * @param {Function | Number} [itemWidth=this.standardItemWidth()] - Width of the item + * Chagnes the bottom row * - * @see DKTools.Sprite.Selectable.prototype.standardItemWidth + * @param {Number} row - Row + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows + * @see DKTools.Sprite.Selectable.prototype.setTopRow */ -DKTools.Sprite.Selectable.prototype.setupItemWidth = function(itemWidth) { - /** - * @private - * @readonly - * @type {Function | Number} - */ - this._itemWidth = itemWidth || this.standardItemWidth(); +DKTools.Sprite.Selectable.prototype.setBottomRow = function(row, blockRefreshAll) { + this.setTopRow(row - (this.getMaxPageRows() - 1), blockRefreshAll); }; /** - * Sets the height of the item - * - * @param {Function | Number} [itemHeight=this.standardItemHeight()] - Height of the item + * Chagnes the bottom column * - * @see DKTools.Sprite.Selectable.prototype.standardItemHeight + * @param {Number} col - Column + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.getMaxPageCols + * @see DKTools.Sprite.Selectable.prototype.setTopCol */ -DKTools.Sprite.Selectable.prototype.setupItemHeight = function(itemHeight) { - /** - * @private - * @readonly - * @type {Function | Number} - */ - this._itemHeight = itemHeight || this.standardItemHeight(); +DKTools.Sprite.Selectable.prototype.setBottomCol = function(col, blockRefreshAll) { + this.setTopCol(col - (this.getMaxPageCols() - 1), blockRefreshAll); }; /** - * Sets the rectangle of the item - * - * @param {Function} [itemRect=this.standardItemRect()] - Rectangle of the item + * Changes the handler of the symbol * - * @see DKTools.Sprite.Selectable.prototype.standardItemRect + * @param {String} symbol - Symbol + * @param {Function} [handler] - Handler */ -DKTools.Sprite.Selectable.prototype.setupItemRect = function(itemRect) { - /** - * @private - * @readonly - * @type {Function} - */ - this._itemRect = itemRect || this.standardItemRect(); +DKTools.Sprite.Selectable.prototype.setHandler = function(symbol, handler) { + this._handlers[symbol] = handler; }; /** - * Sets the font of the item - * - * @param {Function | Object} [itemFont=this.standardItemFont()] - Font of the item + * Changes the cursor rect + * Returns true if the change occurred + * + * @param {PIXI.Rectangle | Rectangle | Object | Number} object - The X coordinate or Rectangle + * @param {Number} [y] - The Y coordinate + * @param {Number} [width] - Width of the rect + * @param {Number} [height] - Height of the rect * - * @param {String} [itemFont.fontFace] - Font face - * @param {Number} [itemFont.fontSize] - Font size - * @param {Boolean} [itemFont.fontItalic] - Font italic + * @param {Number} object.x - The X coordinate + * @param {Number} object.y - The Y coordinate + * @param {Number} object.width - Width of the rect + * @param {Number} object.height - Height of the rect * - * @see DKTools.Sprite.Selectable.prototype.standardItemFont + * @see DKTools.Sprite.Cursor.prototype.setCursorRect + * + * @returns {Boolean} Change occured */ -DKTools.Sprite.Selectable.prototype.setupItemFont = function(itemFont) { - /** - * @private - * @readonly - * @type {Function | Object} - */ - this._itemFont = itemFont || this.standardItemFont(); +DKTools.Sprite.Selectable.prototype.setCursorRect = function(object, y, width, height) { + return this._cursorSprite.setCursorRect(object, y, width, height); }; +// get methods + /** - * Sets the text color of the item + * Returns the rectangle of the item by index * - * @param {Function | String} [itemTextColor=this.standardItemTextColor()] - Text color of the item - * - * @see DKTools.Sprite.Selectable.prototype.standardItemTextColor + * @param {Number} index - Index + * @returns {Rectangle} Rectangle of the item by index */ -DKTools.Sprite.Selectable.prototype.setupItemTextColor = function(itemTextColor) { - /** - * @private - * @readonly - * @type {Function | String} - */ - this._itemTextColor = itemTextColor || this.standardItemTextColor(); +DKTools.Sprite.Selectable.prototype.getItemRectByIndex = function(index) { + return this._itemRect(index); }; /** - * Sets the paint opacity of the item + * Returns the rectangle of the item + * + * @param {Object} item - Item + * + * @see DKTools.Sprite.Selectable.prototype.getItemIndex + * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex * - * @param {Function | Number} [itemPaintOpacity=this.standardItemPaintOpacity()] - Paint opacity of the item - * - * @see DKTools.Sprite.Selectable.prototype.standardItemPaintOpacity + * @returns {Rectangle} Rectangle of the item */ -DKTools.Sprite.Selectable.prototype.setupItemPaintOpacity = function(itemPaintOpacity) { - /** - * @private - * @readonly - * @type {Function | Number} - */ - this._itemPaintOpacity = itemPaintOpacity || this.standardItemPaintOpacity(); +DKTools.Sprite.Selectable.prototype.getItemRect = function(item) { + return this.getItemRectByIndex(this.getItemIndex(item)); }; /** - * Sets the align of the item + * Returns the rectangle of the current item (selected item) * - * @param {Function | String} [itemAlign=this.standardItemAlign()] - Align of the item - * - * @see DKTools.Sprite.Selectable.prototype.standardItemAlign + * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex + * + * @returns {Rectangle} Rectangle of the current item (selected item) */ -DKTools.Sprite.Selectable.prototype.setupItemAlign = function(itemAlign) { - /** - * @private - * @readonly - * @type {Function | String} - */ - this._itemAlign = itemAlign || this.standardItemAlign(); +DKTools.Sprite.Selectable.prototype.getCurrentItemRect = function() { + return this.getItemRectByIndex(this._index); }; -// set methods - /** - * Changes all parameters - * Returns the number of changed parameters + * Returns the rectangle of text of the item by index * - * @override + * @param {Number} index - Index * - * @param {Object} [object={}] - Parameters - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * @param {Boolean} [activate=false] - Activates the object + * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex * - * @param {Number} [object.index] - Index - * @param {Number} [object.maxCols] - Number of the columns - * @param {Boolean} [object.fixedHorizontal] - Fixed horizontal position - * @param {Boolean} [object.cursorFixed] - Fixed cursor - * @param {Boolean} [object.cursorAll] - Cursor all - * @param {Number} [object.horizontalSpacing] - Horizontal spacing - * @param {Number} [object.verticalSpacing] - Vertical spacing - * @param {Number} [object.textPadding] - Text padding - * @param {Object[]} [object.items] - List of the items - * @param {Function} [object.drawItemHandler] - Handler of draw of the item - * @param {Function | Number} [object.itemWidth] - Width of the item - * @param {Function | Number} [object.itemHeight] - Height of the item - * @param {Function} [object.itemRect] - Rectangle of the item - * @param {Function | Object} [object.itemFont] - Font of the item - * @param {Function | String} [object.itemTextColor] - Text color of the item - * @param {Function | Number} [object.itemPaintOpacity] - Paint opacity of the item - * @param {Function | String} [object.itemAlign] - Align of the item + * @returns {Rectangle} Rectangle of text of the item by index + */ +DKTools.Sprite.Selectable.prototype.getItemRectForTextByIndex = function(index) { + const rect = this.getItemRectByIndex(index); + rect.x += this._textPadding; + rect.width -= this._textPadding * 2; + return rect; +}; + +/** + * Returns the rectangle of text of the item * - * @param {String} [object.font.fontFace] - Font face - * @param {Number} [object.font.fontSize] - Font size - * @param {Boolean} [object.font.fontItalic] - Font italic + * @param {Object} item - Item * - * @see DKTools.Sprite.Button.prototype.setAll + * @see DKTools.Sprite.Selectable.prototype.getItemIndex + * @see DKTools.Sprite.Selectable.prototype.getItemRectForTextByIndex * - * @returns {Number} Number of changed parameters + * @returns {Rectangle} Rectangle of text of the item */ -DKTools.Sprite.Selectable.prototype.setAll = function(object, blockStart, activate) { - object = object || {}; - const block = true; - let changed = DKTools.Sprite.Button.prototype.setAll.call(this, object, block); - - if (this.setIndex(object.index, block)) { - changed++; - } - - if (this.setMaxCols(object.maxCols, block)) { - changed++; - } +DKTools.Sprite.Selectable.prototype.getItemRectForText = function(item) { + return this.getItemRectForTextByIndex(this.getItemIndex(item)); +}; - if (this.setFixedHorizontal(object.fixedHorizontal, block)) { - changed++; +/** + * Returns the width of the item + * + * @returns {Number} Width of the item + */ +DKTools.Sprite.Selectable.prototype.getItemWidth = function() { + if (DKTools.Utils.isFunction(this._itemWidth)) { + return this._itemWidth(); } - if (this.setCursorFixed(object.cursorFixed, block)) { - changed++; - } + return this._itemWidth; +}; - if (this.setCursorAll(object.cursorAll, block)) { - changed++; +/** + * Returns the height of the item + * + * @returns {Number} Height of the item + */ +DKTools.Sprite.Selectable.prototype.getItemHeight = function() { + if (DKTools.Utils.isFunction(this._itemHeight)) { + return this._itemHeight(); + } else if (DKTools.Utils.isString(this._itemHeight)) { + return Number(this._itemHeight) * this.getLineHeight(); } - changed += this.setSpacing(object.horizontalSpacing, object.verticalSpacing, block); - - if (this.setTextPadding(object.textPadding, block)) { - changed++; - } + return this._itemHeight; +}; - if (this.setItems(object.items, block)) { - changed++; - } +/** + * Returns the item by index + * + * @param {Number} index - Index + * @returns {Object | null} Item or null + */ +DKTools.Sprite.Selectable.prototype.getItem = function(index) { + return this._items[index] || null; +}; - if (this.setDrawItemHandler(object.drawItemHandler, block)) { - changed++; - } +/** + * Returns the font of the item by index + * + * @param {Number} index - Index + * @returns {Object} Font of the item by index + */ +DKTools.Sprite.Selectable.prototype.getItemFontByIndex = function(index) { + const item = this.getItem(index); + const itemFont = item.font || this._itemFont; - if (this.setItemWidth(object.itemWidth, block)) { - changed++; + if (DKTools.Utils.isFunction(itemFont)) { + return itemFont(index); } - if (this.setItemHeight(object.itemHeight, block)) { - changed++; - } + return itemFont; +}; - if (this.setItemRect(object.itemRect, block)) { - changed++; - } +/** + * Returns the font of the item + * + * @param {Object} item - Item + * + * @see DKTools.Sprite.Selectable.prototype.getItemIndex + * @see DKTools.Sprite.Selectable.prototype.getItemFontByIndex + * + * @returns {Object} Font of the item + */ +DKTools.Sprite.Selectable.prototype.getItemFont = function(item) { + return this.getItemFontByIndex(this.getItemIndex(item)); +}; - if (this.setItemFont(object.itemFont, block)) { - changed++; - } +/** + * Returns the text color of the item by index + * + * @param {Number} index - Index + * @returns {String} Text color of the item by index + */ +DKTools.Sprite.Selectable.prototype.getItemTextColorByIndex = function(index) { + const item = this.getItem(index); + const itemTextColor = item.textColor || this._itemTextColor; - if (this.setItemTextColor(object.itemTextColor, block)) { - changed++; + if (DKTools.Utils.isFunction(itemTextColor)) { + return itemTextColor(index); } - if (this.setItemPaintOpacity(object.itemPaintOpacity, block)) { - changed++; - } + return itemTextColor; +}; - if (this.setItemAlign(object.itemAlign, block)) { - changed++; - } +/** + * Returns the text color of the item + * + * @param {Object} item - Item + * + * @see DKTools.Sprite.Selectable.prototype.getItemIndex + * @see DKTools.Sprite.Selectable.prototype.getItemTextColorByIndex + * + * @returns {String} Text color of the item + */ +DKTools.Sprite.Selectable.prototype.getItemTextColor = function(item) { + return this.getItemTextColorByIndex(this.getItemIndex(item)); +}; - if (changed) { - if (!blockStart) { - this.start(); - } +/** + * Returns the paint opacity of the item by index + * + * @param {Number} index - Index + * @returns {Number} Paint opacity of the item by index + */ +DKTools.Sprite.Selectable.prototype.getItemPaintOpacityByIndex = function(index) { + const item = this.getItem(index); + const itemPaintOpacity = Number.isFinite(item.paintOpacity) ? item.paintOpacity : this._itemPaintOpacity; - if (activate) { - this.activate(); - } + if (DKTools.Utils.isFunction(itemPaintOpacity)) { + return itemPaintOpacity(index); } - return changed; + return itemPaintOpacity; }; /** - * Changes the index - * Returns true if the change occurred + * Returns the paint opacity of the item * - * @param {Number} [index] - Index - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * @param {Object} item - Item * - * @see DKTools.Sprite.Selectable.prototype.setupIndex - * @see DKTools.Sprite.Selectable.prototype.refreshAll - * - * @returns {Boolean} Change occurred + * @see DKTools.Sprite.Selectable.prototype.getItemIndex + * @see DKTools.Sprite.Selectable.prototype.getItemPaintOpacityByIndex + * + * @returns {Number} Paint opacity of the item */ -DKTools.Sprite.Selectable.prototype.setIndex = function(index, blockRefreshAll) { - if (this._index === index) { - return false; - } - - const lastIndex = this._index; - this.setupIndex(index); +DKTools.Sprite.Selectable.prototype.getItemPaintOpacity = function(item) { + return this.getItemPaintOpacityByIndex(this.getItemIndex(item)); +}; - if (this._index === lastIndex) { - return false; - } +/** + * Returns the align of the item by index + * + * @param {Number} index - Index + * @returns {String} Align of the item by index + */ +DKTools.Sprite.Selectable.prototype.getItemAlignByIndex = function(index) { + const item = this.getItem(index); + const itemAlign = item.align || this._itemAlign; - if (!blockRefreshAll) { - this.refreshAll(); + if (DKTools.Utils.isFunction(itemAlign)) { + return itemAlign(index); } - return true; + return itemAlign; }; /** - * Changes the number of the columns - * Returns true if the change occurred + * Returns the align of the item * - * @param {Number} [cols] - Number of the columns - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * @param {Object} item - Item * - * @see DKTools.Sprite.Selectable.prototype.setupMaxCols - * @see DKTools.Sprite.Selectable.prototype.refreshAll - * - * @returns {Boolean} Change occurred + * @see DKTools.Sprite.Selectable.prototype.getItemIndex + * @see DKTools.Sprite.Selectable.prototype.getItemAlignByIndex + * + * @returns {String} Align of the item by index */ -DKTools.Sprite.Selectable.prototype.setMaxCols = function(cols, blockRefreshAll) { - if (this._maxCols === cols) { - return false; - } - - const lastCols = this._maxCols; - this.setupMaxCols(cols); - - if (this._maxCols === lastCols) { - return false; - } +DKTools.Sprite.Selectable.prototype.getItemAlign = function(item) { + return this.getItemAlignByIndex(this.getItemIndex(item)); +}; - if (!blockRefreshAll) { - this.refreshAll(); +/** + * Returns the previous index + * + * @param {Boolean} [wrap=false] - Cyclic selection + * @returns {Number} Previous index + */ +DKTools.Sprite.Selectable.prototype.getPrevIndex = function(wrap) { + if (this._index > 0) { + return this._index - 1; + } else if (wrap) { + return this.getMaxItems() - 1; } - return true; + return -1; }; /** - * Changes the fixed horizontal position - * Returns true if the change occurred - * - * @param {Boolean} [fixedHorizontal] - * @param {Boolean} [blockRefreshAll=false] Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.setupFixedHorizontal - * @see DKTools.Sprite.Selectable.prototype.refreshAll - * - * @returns {Boolean} Change occurred + * Returns the next index + * + * @param {Boolean} [wrap=false] - Cyclic selection + * @returns {Number} Next index */ -DKTools.Sprite.Selectable.prototype.setFixedHorizontal = function(fixedHorizontal, blockRefreshAll) { - if (this._fixedHorizontal === fixedHorizontal) { - return false; +DKTools.Sprite.Selectable.prototype.getNextIndex = function(wrap) { + if (this._index < this.getMaxItems() - 1) { + return this._index + 1; + } else if (wrap) { + return 0; } - const lastFixed = this._fixedHorizontal; - this.setupFixedHorizontal(fixedHorizontal); - - if (this._fixedHorizontal === lastFixed) { - return false; - } + return -1; +}; - if (!blockRefreshAll) { - this.refreshAll(); - } +/** + * Returns the previous item + * + * @param {Boolean} [wrap=false] - Cyclic selection + * + * @see DKTools.Sprite.Selectable.prototype.getPrevIndex + * @see DKTools.Sprite.Selectable.prototype.getItem + * + * @returns {Object | null} Previous item or null + */ +DKTools.Sprite.Selectable.prototype.getPrevItem = function(wrap) { + return this.getItem(this.getPrevIndex(wrap)); +}; - return true; +/** + * Returns the next item + * + * @param {Boolean} [wrap=false] - Cyclic selection + * + * @see DKTools.Sprite.Selectable.prototype.getNextIndex + * @see DKTools.Sprite.Selectable.prototype.getItem + * + * @returns {Object | null} Next item or null + */ +DKTools.Sprite.Selectable.prototype.getNextItem = function(wrap) { + return this.getItem(this.getNextIndex(wrap)); }; /** - * Changes the fixed cursor - * Returns true if the change occurred - * - * @param {Boolean} [cursorFixed] - Fixed cursor - * @param {Boolean} [blockRefreshAll=false] Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.setupCursorFixed - * @see DKTools.Sprite.Selectable.prototype.refreshAll - * - * @returns {Boolean} Change occurred + * Returns the current item (selected item) + * + * @see DKTools.Sprite.Selectable.prototype.getItem + * + * @returns {Object | null} Current item (selected item) or null */ -DKTools.Sprite.Selectable.prototype.setCursorFixed = function(cursorFixed, blockRefreshAll) { - if (this._cursorFixed === cursorFixed) { - return false; - } +DKTools.Sprite.Selectable.prototype.getCurrentItem = function() { + return this.getItem(this._index); +}; - const lastFixed = this._cursorFixed; - this.setupCursorFixed(cursorFixed); +/** + * Returns the index of the item + * + * @param {Object} item - item + * @returns {Number} Index of the item + */ +DKTools.Sprite.Selectable.prototype.getItemIndex = function(item) { + return _.indexOf(this._items, item); +}; - if (this._cursorFixed === lastFixed) { - return false; - } +/** + * Returns the visible items + * + * @returns {Object[]} Visible items + */ +DKTools.Sprite.Selectable.prototype.getVisibleItems = function() { + const maxPageItems = this.getMaxPageItems(); + const maxItems = this.getMaxItems(); + let index = this.getTopIndex(); + let items = []; - if (!blockRefreshAll) { - this.refreshAll(); + for(let i = 0; i < maxPageItems && index < maxItems; i++, index++) { + items.push(this.getItem(index)); } - return true; + return items; }; /** - * Changes the cursor all - * Returns true if the change occurred - * - * @param {Boolean} [cursorAll] - Cursor all - * @param {Boolean} [blockRefreshAll=false] Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.setupCursorAll - * @see DKTools.Sprite.Selectable.prototype.refreshAll - * - * @returns {Boolean} Change occurred + * Returns the name of the item by index + * + * @param {Number} index - Index + * @returns {String | null} Name of the item by index or null */ -DKTools.Sprite.Selectable.prototype.setCursorAll = function(cursorAll, blockRefreshAll) { - if (this._cursorAll === cursorAll) { - return false; - } - - const lastAll = this._cursorAll; - this.setupCursorAll(cursorAll); - - if (this._cursorAll === lastAll) { - return false; - } +DKTools.Sprite.Selectable.prototype.getItemName = function(index) { + const item = this.getItem(index); - if (!blockRefreshAll) { - this.refreshAll(); + if (item) { + const name = item.name; + if (DKTools.Utils.isFunction(name)) { + return name(index); + } + return name; } - return true; + return null; }; /** - * Changes the horizontal spacing - * Returns true if the change occurred - * - * @param {Number} [spacing] - Horizontal spacing - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.setupHorizontalSpacing - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * Returns the symbol of the item by index * - * @returns {Boolean} Change occurred + * @param {Number} index - Index + * @returns {String | null} Symbol of the item by index or null */ -DKTools.Sprite.Selectable.prototype.setHorizontalSpacing = function(spacing, blockRefreshAll) { - if (this._horizontalSpacing === spacing) { - return false; - } - - const lastSpacing = this._horizontalSpacing; - this.setupHorizontalSpacing(spacing); - - if (this._horizontalSpacing === lastSpacing) { - return false; - } +DKTools.Sprite.Selectable.prototype.getItemSymbol = function(index) { + const item = this.getItem(index); + return item ? item.symbol : null; +}; - if (!blockRefreshAll) { - this.refreshAll(); - } +/** + * Returns the ext of the item by index + * + * @param {Number} index - Index + * @returns {* | null} Ext of the item by index or null + */ +DKTools.Sprite.Selectable.prototype.getItemExt = function(index) { + var item = this.getItem(index); + return item ? item.ext : null; +}; - return true; +/** + * Returns the name of the current item (selected item) + * + * @see DKTools.Sprite.Selectable.prototype.getItemName + * + * @returns {String | null} Name of the current item (selected item) or null + */ +DKTools.Sprite.Selectable.prototype.getCurrentItemName = function() { + return this.getItemName(this._index); }; /** - * Changes the vertical spacing - * Returns true if the change occurred - * - * @param {Number} [spacing] - Vertical spacing - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * Returns the symbol of the current item (selected item) * - * @see DKTools.Sprite.Selectable.prototype.setupVerticalSpacing - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * @see DKTools.Sprite.Selectable.prototype.getItemSymbol * - * @returns {Boolean} Change occurred + * @returns {String | null} Symbol of the current item (selected item) or null */ -DKTools.Sprite.Selectable.prototype.setVerticalSpacing = function(spacing, blockRefreshAll) { - if (this._verticalSpacing === spacing) { - return false; - } - - const lastSpacing = this._verticalSpacing; - this.setupVerticalSpacing(spacing); - - if (this._verticalSpacing === lastSpacing) { - return false; - } - - if (!blockRefreshAll) { - this.refreshAll(); - } - - return true; +DKTools.Sprite.Selectable.prototype.getCurrentItemSymbol = function() { + return this.getItemSymbol(this._index); }; /** - * Changes the horizontal and vertical spacings - * Returns the number of changed parameters + * Returns the ext of the current item (selected item) * - * @param {Number} [horizontalSpacing] - Horizontal spacing - * @param {Number} [verticalSpacing] - Vertical spacing - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * @see DKTools.Sprite.Selectable.prototype.getItemExt * - * @see DKTools.Sprite.Selectable.prototype.setHorizontalSpacing - * @see DKTools.Sprite.Selectable.prototype.setVerticalSpacing - * - * @returns {Number} Number of changed parameters + * @returns {* | null} Ext of the current item (selected item) or null */ -DKTools.Sprite.Selectable.prototype.setSpacing = function(horizontalSpacing, verticalSpacing, blockRefreshAll) { - const block = true; - let changed = 0; - - if (this.setHorizontalSpacing(horizontalSpacing, block)) { - changed++; - } - - if (this.setVerticalSpacing(verticalSpacing, block)) { - changed++; - } - - if (changed && !blockRefreshAll) { - this.refreshAll(); - } - - return changed; +DKTools.Sprite.Selectable.prototype.getCurrentItemExt = function() { + return this.getItemExt(this._index); }; /** - * Changes the text padding - * Returns true if the change occurred - * - * @param {Number} [textPadding] - Text padding - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.setupTextPadding - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * Returns the number of the items * - * @returns {Boolean} Change occurred + * @returns {Number} Number of the items */ -DKTools.Sprite.Selectable.prototype.setTextPadding = function(textPadding, blockRefreshAll) { - if (this._textPadding === textPadding) { - return false; - } - - const lastPadding = this._textPadding; - this.setupTextPadding(textPadding); - - if (this._textPadding === lastPadding) { - return false; - } - - if (!blockRefreshAll) { - this.refreshAll(); - } - - return true; +DKTools.Sprite.Selectable.prototype.getMaxItems = function() { + return this._items.length; }; /** - * Changes the items - * Returns true if the change occurred - * - * @param {Object[]} [items] - List of the items - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.setupItems - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * Returns the maximum number of the rows * - * @returns {Boolean} Change occurred + * @returns {Number} Maximum number of the rows */ -DKTools.Sprite.Selectable.prototype.setItems = function(items, blockRefreshAll) { - if (this._items == items) { - return false; +DKTools.Sprite.Selectable.prototype.getMaxRows = function() { + if (this.isFixedHorizontal()) { + return 1; } - this.setupItems(items); + return Math.max(1, Math.ceil(this.getMaxItems() / this.getMaxCols())); +}; - if (!blockRefreshAll) { - this.refreshAll(); - } +/** + * Returns the maximum number of the columns + * + * @returns {Number} Maximum number of the columns + */ +DKTools.Sprite.Selectable.prototype.getMaxCols = function() { + return this._maxCols; +}; - return true; +/** + * Returns the maximum top row + * + * @see DKTools.Sprite.Selectable.prototype.getMaxRows + * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows + * + * @returns {Number} Maximum top row + */ +DKTools.Sprite.Selectable.prototype.getMaxTopRow = function() { + return Math.max(0, this.getMaxRows() - this.getMaxPageRows()); }; /** - * Changes the handler of draw of the item - * Returns true if the change occurred - * - * @param {Function} [handler] - Handler of draw of the item - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.setupDrawItemHandler - * @see DKTools.Sprite.Selectable.prototype.refreshAll - * - * @returns {Boolean} Change occurred + * Returns the maximum top column + * + * @see DKTools.Sprite.Selectable.prototype.getMaxItems + * @see DKTools.Sprite.Selectable.prototype.getMaxPageCols + * + * @returns {Number} Maximum top column */ -DKTools.Sprite.Selectable.prototype.setDrawItemHandler = function(handler, blockRefreshAll) { - if (this._drawItemHandler === handler) { - return false; - } +DKTools.Sprite.Selectable.prototype.getMaxTopCol = function() { + return Math.max(0, this.getMaxItems() - this.getMaxPageCols()); +}; - const lastHandler = this._drawItemHandler; - this.setupDrawItemHandler(handler); +/** + * Returns the maximum page rows + * + * @see DKTools.Sprite.Selectable.prototype.getItemHeight + * @see DKTools.Sprite.Selectable.prototype.getMaxRows + * + * @returns {Number} Maximum page rows + */ +DKTools.Sprite.Selectable.prototype.getMaxPageRows = function() { + const spacing = this._verticalSpacing; + const realHeight = this.realHeight; + const itemHeight = this.getItemHeight(); + const maxRows = this.getMaxRows(); + let rows = 0, height = 0; - if (this._drawItemHandler === lastHandler) { - return false; + for(; rows < maxRows && height + itemHeight + spacing <= realHeight && height + itemHeight <= realHeight; rows++) { + height += itemHeight + spacing; } - if (!blockRefreshAll) { - this.refreshAll(); - } + return rows; +}; - return true; +/** + * Returns the maximum page columns + * + * @see DKTools.Sprite.Selectable.prototype.getMaxCols + * + * @returns {Number} Maximum page columns + */ +DKTools.Sprite.Selectable.prototype.getMaxPageCols = function() { + return this.getMaxCols(); }; /** - * Changes the width of the item - * Returns true if the change occurred - * - * @param {Function | Number} [itemWidth] - Width of the item - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.setupItemWidth - * @see DKTools.Sprite.Selectable.prototype.refreshAll - * - * @returns {Boolean} Change occurred + * Returns the maximum page items + * + * @see DKTools.Sprite.Selectable.prototype.isHorizontal + * @see DKTools.Sprite.Selectable.prototype.getMaxPageCols + * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows + * + * @returns {Number} Maximum page items */ -DKTools.Sprite.Selectable.prototype.setItemWidth = function(itemWidth, blockRefreshAll) { - if (this._itemWidth === itemWidth) { - return false; +DKTools.Sprite.Selectable.prototype.getMaxPageItems = function() { + if (this.isHorizontal()) { + return this.getMaxPageCols(); } - const lastWidth = this._itemWidth; - this.setupItemWidth(itemWidth); + return this.getMaxPageRows() * this.getMaxPageCols(); +}; - if (this._itemWidth === lastWidth) { - return false; - } +/** + * Returns the row by index + * + * @param {Number} index - Index + * + * @see DKTools.Sprite.Selectable.prototype.getMaxCols + * + * @returns {Number} Row by index + */ +DKTools.Sprite.Selectable.prototype.getRowByIndex = function(index) { + return Math.floor(index / this.getMaxCols()); +}; - if (!blockRefreshAll) { - this.refreshAll(); - } +/** + * Returns the current row + * + * @see DKTools.Sprite.Selectable.prototype.getRowByIndex + * + * @returns {Number} Current row + */ +DKTools.Sprite.Selectable.prototype.getCurrentRow = function() { + return this.getRowByIndex(this._index); +}; - return true; +/** + * Returns the row of the item + * + * @param {Object} item - Item + * + * @see DKTools.Sprite.Selectable.prototype.getItemIndex + * @see DKTools.Sprite.Selectable.prototype.getRowByIndex + * + * @returns {Number} Row of the item + */ +DKTools.Sprite.Selectable.prototype.getItemRow = function(item) { + return this.getRowByIndex(this.getItemIndex(item)); }; /** - * Changes the height of the item - * Returns true if the change occurred - * - * @param {Function | Number} [itemHeight] - Height of the item - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.setupItemHeight - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * Returns the list of the items by row * - * @returns {Boolean} Change occured + * @param {Number} row - Row + * + * @see DKTools.Sprite.Selectable.prototype.getMaxRows + * @see DKTools.Sprite.Selectable.prototype.getMaxPageItems + * @see DKTools.Sprite.Selectable.prototype.getMaxItems + * @see DKTools.Sprite.Selectable.prototype.getMaxCols + * @see DKTools.Sprite.Selectable.prototype.getRowByIndex + * @see DKTools.Sprite.Selectable.prototype.getItem + * + * @returns {Object[]} List of the items by row */ -DKTools.Sprite.Selectable.prototype.setItemHeight = function(itemHeight, blockRefreshAll) { - if (this._itemHeight === itemHeight) { - return false; - } - - const lastHeight = this._itemHeight; - this.setupItemHeight(itemHeight); +DKTools.Sprite.Selectable.prototype.getRowItems = function(row) { + const items = []; - if (this._itemHeight === lastHeight) { - return false; - } + if (_.inRange(row, 0, this.getMaxRows())) { + const maxPageItems = this.getMaxPageItems(); + const maxItems = this.getMaxItems(); + let index = row * this.getMaxCols(); - if (!blockRefreshAll) { - this.refreshAll(); + for(let i = 0; i < maxPageItems && index < maxItems && this.getRowByIndex(index) === row; i++, index++) { + items.push(this.getItem(index)); + } } - return true; + return items; }; /** - * Changes the font of the item - * Returns true if the change occurred - * - * @param {Function | Object} [itemFont] - Font of the item - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.setupItemFont - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * Returns the column by index * - * @returns {Boolean} Change occured + * @param {Number} index - Index + * + * @see DKTools.Sprite.Selectable.prototype.getMaxCols + * + * @returns {Number} Column by index */ -DKTools.Sprite.Selectable.prototype.setItemFont = function(itemFont, blockRefreshAll) { - if (this._itemFont === itemFont) { - return false; - } - - const lastFont = this._itemFont; - this.setupItemFont(itemFont); - - if (this._itemFont === lastFont) { - return false; - } - - if (!blockRefreshAll) { - this.refreshAll(); - } - - return true; +DKTools.Sprite.Selectable.prototype.getColByIndex = function(index) { + return Math.floor(index % this.getMaxCols()); }; /** - * Changes the text color of the item - * Returns true if the change occurred - * - * @param {Function | String} [itemTextColor] - Text color of the item - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.setupItemTextColor - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * Returns the current column * - * @returns {Boolean} Change occured + * @see DKTools.Sprite.Selectable.prototype.isHorizontal + * @see DKTools.Sprite.Selectable.prototype.getColByIndex + * + * @returns {Number} Current column */ -DKTools.Sprite.Selectable.prototype.setItemTextColor = function(itemTextColor, blockRefreshAll) { - if (this._itemTextColor === itemTextColor) { - return false; - } - - const lastTextColor = this._itemTextColor; - this.setupItemTextColor(itemTextColor); - - if (this._itemTextColor === lastTextColor) { - return false; - } - - if (!blockRefreshAll) { - this.refreshAll(); +DKTools.Sprite.Selectable.prototype.getCurrentCol = function() { + if (this.isHorizontal()) { + return this._index; } - return true; + return this.getColByIndex(this._index); }; /** - * Changes the item paint opacity - * Returns true if the change occurred - * - * @param {Function | Number} [itemPaintOpacity] - Paint opacity of the item - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.setupItemPaintOpacity - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * Returns the column of the item * - * @returns {Boolean} Change occured + * @param {Object} item - Item + * + * @see DKTools.Sprite.Selectable.prototype.getItemIndex + * @see DKTools.Sprite.Selectable.prototype.getColByIndex + * + * @returns {Number} Column of the item */ -DKTools.Sprite.Selectable.prototype.setItemPaintOpacity = function(itemPaintOpacity, blockRefreshAll) { - if (this._itemPaintOpacity === itemPaintOpacity) { - return false; - } +DKTools.Sprite.Selectable.prototype.getItemCol = function(item) { + return this.getColByIndex(this.getItemIndex(item)); +}; - const lastPaintOpacity = this._itemPaintOpacity; - this.setupItemPaintOpacity(itemPaintOpacity); +/** + * Returns the list of the items by column + * + * @param {Number} col - Column + * + * @see DKTools.Sprite.Selectable.prototype.getMaxCols + * @see DKTools.Sprite.Selectable.prototype.getMaxItems + * @see DKTools.Sprite.Selectable.prototype.getColByIndex + * @see DKTools.Sprite.Selectable.prototype.getItem + * + * @returns {Object[]} List of the items by column + */ +DKTools.Sprite.Selectable.prototype.getColItems = function(col) { + const items = []; - if (this._itemPaintOpacity === lastPaintOpacity) { - return false; - } + if (_.inRange(col, 0, this.getMaxCols())) { + const maxItems = this.getMaxItems(); - if (!blockRefreshAll) { - this.refreshAll(); + for(let index = 0; index < maxItems; index++) { + if (this.getColByIndex(index) === col) { + items.push(this.getItem(index)); + } + } } - return true; + return items; }; /** - * Changes the align of the item - * Returns true if the change occurred - * - * @param {Function | String} [itemAlign] - Align of the item - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.setupItemAlign - * @see DKTools.Sprite.Selectable.prototype.refreshAll - * - * @returns {Boolean} Change occured + * Returns the top index + * + * @see DKTools.Sprite.Selectable.prototype.isHorizontal + * @see DKTools.Sprite.Selectable.prototype.getTopCol + * @see DKTools.Sprite.Selectable.prototype.getTopRow + * @see DKTools.Sprite.Selectable.prototype.getMaxCols + * + * @returns {Number} Top index */ -DKTools.Sprite.Selectable.prototype.setItemAlign = function(itemAlign, blockRefreshAll) { - if (this._itemAlign === itemAlign) { - return false; +DKTools.Sprite.Selectable.prototype.getTopIndex = function() { + if (this.isHorizontal()) { + return this.getTopCol(); } - const lastAlign = this._itemAlign; - this.setupItemAlign(itemAlign); - - if (this._itemAlign === lastAlign) { - return false; - } + return this.getTopRow() * this.getMaxCols(); +}; - if (!blockRefreshAll) { - this.refreshAll(); - } +/** + * Returns the top row + * + * @returns {Number} Top row + */ +DKTools.Sprite.Selectable.prototype.getTopRow = function() { + return this._topRow; +}; - return true; +/** + * Returns the top column + * + * @returns {Number} Top column + */ +DKTools.Sprite.Selectable.prototype.getTopCol = function() { + return this._topCol; }; /** - * Changes the top row + * Returns the bottom row * - * @param {Number} row - Row - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * @see DKTools.Sprite.Selectable.prototype.getTopRow + * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows * - * @see DKTools.Sprite.Selectable.prototype.getMaxTopRow - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * @returns {Number} Bottom row */ -DKTools.Sprite.Selectable.prototype.setTopRow = function(row, blockRefreshAll) { - const topRow = _.clamp(row, 0, this.getMaxTopRow()); - - if (this._topRow !== topRow) { - this._topRow = topRow; +DKTools.Sprite.Selectable.prototype.getBottomRow = function() { + return Math.max(0, this.getTopRow() + this.getMaxPageRows() - 1); +}; - if (!blockRefreshAll) { - this.refreshAll(); - } - } +/** + * Returns the bottom column + * + * @see DKTools.Sprite.Selectable.prototype.getTopCol + * @see DKTools.Sprite.Selectable.prototype.getMaxPageCols + * + * @returns {Number} Bottom column + */ +DKTools.Sprite.Selectable.prototype.getBottomCol = function() { + return Math.max(0, this.getTopCol() + this.getMaxPageCols() - 1); }; /** - * Changes the top column + * Returns the bottom index * - * @param {Number} col - Column - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * @see DKTools.Sprite.Selectable.prototype.getTopIndex + * @see DKTools.Sprite.Selectable.prototype.getMaxPageItems + * @see DKTools.Sprite.Selectable.prototype.getMaxItems * - * @see DKTools.Sprite.Selectable.prototype.getMaxTopCol - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * @returns {Number} Bottom index */ -DKTools.Sprite.Selectable.prototype.setTopCol = function(col, blockRefreshAll) { - const topCol = _.clamp(col, 0, this.getMaxTopCol()); +DKTools.Sprite.Selectable.prototype.getBottomIndex = function() { + return Math.min(this.getTopIndex() + this.getMaxPageItems(), this.getMaxItems()) - 1; +}; - if (this._topCol !== topCol) { - this._topCol = topCol; +// is methods - if (!blockRefreshAll) { - this.refreshAll(); - } - } + +/** + * Returns true if the cursor is fixed + * + * @returns {Boolean} Cursor is fixed + */ +DKTools.Sprite.Selectable.prototype.isCursorFixed = function() { + return this._cursorFixed; }; /** - * Chagnes the bottom row - * - * @param {Number} row - Row - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows - * @see DKTools.Sprite.Selectable.prototype.setTopRow + * Returns true if the cursor all + * + * @returns {Boolean} Cursor all */ -DKTools.Sprite.Selectable.prototype.setBottomRow = function(row, blockRefreshAll) { - this.setTopRow(row - (this.getMaxPageRows() - 1), blockRefreshAll); +DKTools.Sprite.Selectable.prototype.isCursorAll = function() { + return this._cursorAll; }; /** - * Chagnes the bottom column - * - * @param {Number} col - Column - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.getMaxPageCols - * @see DKTools.Sprite.Selectable.prototype.setTopCol + * Returns true if the fixed horizontal position of the items + * + * @returns {Boolean} Fixed horizontal position of the items */ -DKTools.Sprite.Selectable.prototype.setBottomCol = function(col, blockRefreshAll) { - this.setTopCol(col - (this.getMaxPageCols() - 1), blockRefreshAll); +DKTools.Sprite.Selectable.prototype.isFixedHorizontal = function() { + return this._fixedHorizontal; }; /** - * Changes the handler of the symbol + * Returns true if the position of the items is horizontal + * + * @see DKTools.Sprite.Selectable.prototype.isFixedHorizontal + * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows * - * @param {String} symbol - Symbol - * @param {Function} [handler] - Handler + * @returns {Boolean} Position of the items is horizontal */ -DKTools.Sprite.Selectable.prototype.setHandler = function(symbol, handler) { - this._handlers[symbol] = handler; +DKTools.Sprite.Selectable.prototype.isHorizontal = function() { + return this.isFixedHorizontal() || this.getMaxPageRows() === 1; }; /** - * Changes the cursor rect - * Returns true if the change occurred - * - * @param {PIXI.Rectangle | Rectangle | Object | Number} object - The X coordinate or Rectangle - * @param {Number} [y] - The Y coordinate - * @param {Number} [width] - Width of the rect - * @param {Number} [height] - Height of the rect + * Returns true if the position of the items is vertical * - * @param {Number} object.x - The X coordinate - * @param {Number} object.y - The Y coordinate - * @param {Number} object.width - Width of the rect - * @param {Number} object.height - Height of the rect + * @see DKTools.Sprite.Selectable.prototype.isHorizontal * - * @see DKTools.Sprite.Cursor.prototype.setCursorRect - * - * @returns {Boolean} Change occured + * @returns {Boolean} Position of the items is vertical */ -DKTools.Sprite.Selectable.prototype.setCursorRect = function(object, y, width, height) { - return this._cursorSprite.setCursorRect(object, y, width, height); +DKTools.Sprite.Selectable.prototype.isVertical = function() { + return !this.isHorizontal(); }; -// get methods - /** - * Returns the rectangle of the item by index + * Returns true if the cursor can move * - * @param {Number} index - Index - * @returns {Rectangle} Rectangle of the item by index + * @see DKTools.Sprite.Selectable.prototype.isVisibleAndActive + * @see DKTools.Sprite.Selectable.prototype.isCursorFixed + * @see DKTools.Sprite.Selectable.prototype.isCursorAll + * @see DKTools.Sprite.Selectable.prototype.getMaxItems + * + * @returns {Boolean} Cursor can move */ -DKTools.Sprite.Selectable.prototype.getItemRectByIndex = function(index) { - return this._itemRect(index); +DKTools.Sprite.Selectable.prototype.isCursorMovable = function() { + return this.isVisibleAndActive() && !this.isCursorFixed() && !this.isCursorAll() && this.getMaxItems() > 0; }; /** - * Returns the rectangle of the item - * - * @param {Object} item - Item - * - * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex - * - * @returns {Rectangle} Rectangle of the item + * Returns true if the Ok is enabled + * + * @returns {Boolean} Ok is enabled */ -DKTools.Sprite.Selectable.prototype.getItemRect = function(item) { - return this.getItemRectByIndex(this.getItemIndex(item)); +DKTools.Sprite.Selectable.prototype.isOkEnabled = function() { + return true; }; /** - * Returns the rectangle of the current item (selected item) - * - * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex - * - * @returns {Rectangle} Rectangle of the current item (selected item) + * Returns true if the cancel is enabled + * + * @see DKTools.Sprite.Selectable.prototype.isHandled + * + * @returns {Boolean} Cancel is enabled */ -DKTools.Sprite.Selectable.prototype.getCurrentItemRect = function() { - return this.getItemRectByIndex(this._index); +DKTools.Sprite.Selectable.prototype.isCancelEnabled = function() { + return this.isHandled('cancel'); }; /** - * Returns the rectangle of text of the item by index - * - * @param {Number} index - Index - * - * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex - * - * @returns {Rectangle} Rectangle of text of the item by index + * Returns true if the Ok is triggered + * + * @returns {Boolean} Ok is triggered */ -DKTools.Sprite.Selectable.prototype.getItemRectForTextByIndex = function(index) { - const rect = this.getItemRectByIndex(index); - rect.x += this._textPadding; - rect.width -= this._textPadding * 2; - return rect; +DKTools.Sprite.Selectable.prototype.isOkTriggered = function() { + return Input.isRepeated('ok'); }; /** - * Returns the rectangle of text of the item - * - * @param {Object} item - Item - * - * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.getItemRectForTextByIndex - * - * @returns {Rectangle} Rectangle of text of the item + * Returns true if the cancel is triggered + * + * @returns {Boolean} Cancel is triggered */ -DKTools.Sprite.Selectable.prototype.getItemRectForText = function(item) { - return this.getItemRectForTextByIndex(this.getItemIndex(item)); +DKTools.Sprite.Selectable.prototype.isCancelTriggered = function() { + return Input.isRepeated('cancel') || TouchInput.isCancelled(); }; /** - * Returns the width of the item + * Returns true if the cursor is visible * - * @returns {Number} Width of the item + * @see DKTools.Sprite.Selectable.prototype.isHorizontal + * @see DKTools.Sprite.Selectable.prototype.getTopCol + * @see DKTools.Sprite.Selectable.prototype.getBottomCol + * @see DKTools.Sprite.Selectable.prototype.getCurrentRow + * @see DKTools.Sprite.Selectable.prototype.getTopRow + * @see DKTools.Sprite.Selectable.prototype.getBottomRow + * + * @returns {Boolean} Cursor is visible */ -DKTools.Sprite.Selectable.prototype.getItemWidth = function() { - if (DKTools.Utils.isFunction(this._itemWidth)) { - return this._itemWidth(); +DKTools.Sprite.Selectable.prototype.isCursorVisible = function() { + if (!this._cursorSprite.isVisible()) { + return false; } - return this._itemWidth; + if (this.isHorizontal()) { + const col = this.getCurrentCol(); + + return col >= this.getTopCol() && col <= this.getBottomCol(); + } + + const row = this.getCurrentRow(); + + return row >= this.getTopRow() && row <= this.getBottomRow(); }; /** - * Returns the height of the item + * Returns true if the item by index is enabled * - * @returns {Number} Height of the item + * @param {Number} index - Index + * + * @see DKTools.Sprite.Selectable.prototype.getItem + * + * @returns {Boolean} Item by index is enabled */ -DKTools.Sprite.Selectable.prototype.getItemHeight = function() { - if (DKTools.Utils.isFunction(this._itemHeight)) { - return this._itemHeight(); - } else if (_.isString(this._itemHeight)) { - return Number(this._itemHeight) * this.getLineHeight(); +DKTools.Sprite.Selectable.prototype.isItemEnabled = function(index) { + const item = this.getItem(index); + + if (item) { + const enabled = item.enabled; + + if (DKTools.Utils.isFunction(enabled)) { + return enabled(index); + } + + return enabled; } - return this._itemHeight; + return false; }; /** - * Returns the item by index + * Returns true if the current item (selected item) is enabled * - * @param {Number} index - Index - * @returns {Object | null} Item or null + * @see DKTools.Sprite.Selectable.prototype.isItemEnabled + * + * @returns {Boolean} Current item (selected item) is enabled */ -DKTools.Sprite.Selectable.prototype.getItem = function(index) { - return this._items[index] || null; +DKTools.Sprite.Selectable.prototype.isCurrentItemEnabled = function() { + return this.isItemEnabled(this._index); }; /** - * Returns the font of the item by index + * Returns true if the symbol is handling * - * @param {Number} index - Index - * @returns {Object} Font of the item by index + * @param {String} symbol - Symbol + * @returns {Boolean} Symbol is handling */ -DKTools.Sprite.Selectable.prototype.getItemFontByIndex = function(index) { - const item = this.getItem(index); - const itemFont = item.font || this._itemFont; - - if (DKTools.Utils.isFunction(itemFont)) { - return itemFont(index); - } +DKTools.Sprite.Selectable.prototype.isHandled = function(symbol) { + return !!this._handlers[symbol]; +}; - return itemFont; +/** + * Returns true if the item by index is visible + * + * @param {Number} index - Index + * + * @see DKTools.Sprite.Selectable.prototype.getTopIndex + * @see DKTools.Sprite.Selectable.prototype.getBottomIndex + * + * @returns {Boolean} Item by index is visible + */ +DKTools.Sprite.Selectable.prototype.isItemVisibleByIndex = function(index) { + return _.inRange(index, this.getTopIndex(), this.getBottomIndex() + 1); }; /** - * Returns the font of the item + * Returns true if the item is visible * * @param {Object} item - Item * - * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.getItemFontByIndex + * @see DKTools.Sprite.Selectable.prototype.isItemVisibleByIndex * - * @returns {Object} Font of the item + * @returns {Boolean} Item is visible */ -DKTools.Sprite.Selectable.prototype.getItemFont = function(item) { - return this.getItemFontByIndex(this.getItemIndex(item)); +DKTools.Sprite.Selectable.prototype.isItemVisible = function(item) { + return this.isItemVisibleByIndex(this.getItemIndex(item)); }; +// has methods + /** - * Returns the text color of the item by index + * Returns true if the item by index exists * * @param {Number} index - Index - * @returns {String} Text color of the item by index + * + * @see DKTools.Sprite.Selectable.prototype.getItem + * + * @returns {Boolean} Item by index exists */ -DKTools.Sprite.Selectable.prototype.getItemTextColorByIndex = function(index) { - const item = this.getItem(index); - const itemTextColor = item.textColor || this._itemTextColor; - - if (DKTools.Utils.isFunction(itemTextColor)) { - return itemTextColor(index); - } - - return itemTextColor; +DKTools.Sprite.Selectable.prototype.hasItemByIndex = function(index) { + return !!this.getItem(index); }; /** - * Returns the text color of the item + * Returns true if the item exists * - * @param {Object} item - Item + * @param {Object} item - item * * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.getItemTextColorByIndex + * @see DKTools.Sprite.Selectable.prototype.hasItemByIndex * - * @returns {String} Text color of the item + * @returns {Boolean} Item exists */ -DKTools.Sprite.Selectable.prototype.getItemTextColor = function(item) { - return this.getItemTextColorByIndex(this.getItemIndex(item)); +DKTools.Sprite.Selectable.prototype.hasItem = function(item) { + return this.hasItemByIndex(this.getItemIndex(item)); }; /** - * Returns the paint opacity of the item by index + * Returns true if the items exists * - * @param {Number} index - Index - * @returns {Number} Paint opacity of the item by index + * @see DKTools.Sprite.Selectable.prototype.getMaxItems + * + * @returns {Boolean} Items exists */ -DKTools.Sprite.Selectable.prototype.getItemPaintOpacityByIndex = function(index) { - const item = this.getItem(index); - const itemPaintOpacity = Number.isFinite(item.paintOpacity) ? item.paintOpacity : this._itemPaintOpacity; - - if (DKTools.Utils.isFunction(itemPaintOpacity)) { - return itemPaintOpacity(index); - } - - return itemPaintOpacity; +DKTools.Sprite.Selectable.prototype.hasItems = function() { + return this.getMaxItems() > 0; }; /** - * Returns the paint opacity of the item - * - * @param {Object} item - Item + * Returns true if the handler of draw of the item exists * - * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.getItemPaintOpacityByIndex + * @returns {Boolean} Handler of draw of the item exists + */ +DKTools.Sprite.Selectable.prototype.hasDrawItemHandler = function() { + return !!this._drawItemHandler; +}; + +// active methods + +/** + * Activates the object * - * @returns {Number} Paint opacity of the item + * @override */ -DKTools.Sprite.Selectable.prototype.getItemPaintOpacity = function(item) { - return this.getItemPaintOpacityByIndex(this.getItemIndex(item)); +DKTools.Sprite.Selectable.prototype.activate = function() { + DKTools.Sprite.Button.prototype.activate.call(this); + this.reselect(); }; /** - * Returns the align of the item by index + * Deactivates the object * - * @param {Number} index - Index - * @returns {String} Align of the item by index + * @override + * @param {Boolean} [deselect=false] - Deselects the current item (selected item) + * + * @see DKTools.Sprite.Selectable.prototype.deselect */ -DKTools.Sprite.Selectable.prototype.getItemAlignByIndex = function(index) { - const item = this.getItem(index); - const itemAlign = item.align || this._itemAlign; +DKTools.Sprite.Selectable.prototype.deactivate = function(deselect) { + DKTools.Sprite.Button.prototype.deactivate.call(this); - if (DKTools.Utils.isFunction(itemAlign)) { - return itemAlign(index); + if (deselect) { + this.deselect(); } - - return itemAlign; }; +// cursor methods + /** - * Returns the align of the item - * - * @param {Object} item - Item - * - * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.getItemAlignByIndex + * Moves the cursor to down * - * @returns {String} Align of the item by index + * @param {Boolean} [wrap=false] - Cyclic selection + * + * @see DKTools.Sprite.Selectable.prototype.isHorizontal + * @see DKTools.Sprite.Selectable.prototype.getMaxItems + * @see DKTools.Sprite.Selectable.prototype.getMaxCols + * @see DKTools.Sprite.Selectable.prototype.getMaxRows + * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex */ -DKTools.Sprite.Selectable.prototype.getItemAlign = function(item) { - return this.getItemAlignByIndex(this.getItemIndex(item)); +DKTools.Sprite.Selectable.prototype.cursorDown = function(wrap) { + if (this.isHorizontal()) { + return; + } + + const index = this._index; + const maxItems = this.getMaxItems(); + const maxCols = this.getMaxCols(); + + if (index < maxItems - maxCols || (wrap && maxItems === this.getMaxRows() * maxCols)) { + this.selectItemByIndex((index + maxCols) % maxItems); + } }; /** - * Returns the previous index + * Moves the cursor to up * * @param {Boolean} [wrap=false] - Cyclic selection - * @returns {Number} Previous index + * + * @see DKTools.Sprite.Selectable.prototype.isHorizontal + * @see DKTools.Sprite.Selectable.prototype.getMaxItems + * @see DKTools.Sprite.Selectable.prototype.getMaxCols + * @see DKTools.Sprite.Selectable.prototype.getMaxRows + * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex */ -DKTools.Sprite.Selectable.prototype.getPrevIndex = function(wrap) { - if (this._index > 0) { - return this._index - 1; - } else if (wrap) { - return this.getMaxItems() - 1; +DKTools.Sprite.Selectable.prototype.cursorUp = function(wrap) { + if (this.isHorizontal()) { + return; } - return -1; + const index = this._index; + const maxItems = this.getMaxItems(); + const maxCols = this.getMaxCols(); + + if (index >= maxCols || (wrap && maxItems === this.getMaxRows() * maxCols)) { + this.selectItemByIndex((index - maxCols + maxItems) % maxItems); + } }; /** - * Returns the next index + * Moves the cursor to right * * @param {Boolean} [wrap=false] - Cyclic selection - * @returns {Number} Next index + * + * @see DKTools.Sprite.Selectable.prototype.getMaxItems + * @see DKTools.Sprite.Selectable.prototype.isHorizontal + * @see DKTools.Sprite.Selectable.prototype.selectNext + * @see DKTools.Sprite.Selectable.prototype.getMaxCols + * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex */ -DKTools.Sprite.Selectable.prototype.getNextIndex = function(wrap) { - if (this._index < this.getMaxItems() - 1) { - return this._index + 1; - } else if (wrap) { - return 0; +DKTools.Sprite.Selectable.prototype.cursorRight = function(wrap) { + const maxItems = this.getMaxItems(); + + if (maxItems < 2) { + return; } - return -1; + if (this.isVertical()) { + const index = this._index; + const maxCols = this.getMaxCols(); + + if (maxCols >= 2 && (index < maxItems - 1 || wrap)) { + this.selectItemByIndex((index + 1) % maxItems); + } + } else { + this.selectNext(wrap); + } }; /** - * Returns the previous item + * Moves the cursor to left * * @param {Boolean} [wrap=false] - Cyclic selection - * - * @see DKTools.Sprite.Selectable.prototype.getPrevIndex - * @see DKTools.Sprite.Selectable.prototype.getItem - * - * @returns {Object | null} Previous item or null + * + * @see DKTools.Sprite.Selectable.prototype.getMaxItems + * @see DKTools.Sprite.Selectable.prototype.isHorizontal + * @see DKTools.Sprite.Selectable.prototype.selectPrev + * @see DKTools.Sprite.Selectable.prototype.getMaxCols + * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex */ -DKTools.Sprite.Selectable.prototype.getPrevItem = function(wrap) { - return this.getItem(this.getPrevIndex(wrap)); +DKTools.Sprite.Selectable.prototype.cursorLeft = function(wrap) { + const maxItems = this.getMaxItems(); + + if (maxItems < 2) { + return; + } + + if (this.isVertical()) { + const index = this._index; + const maxCols = this.getMaxCols(); + + if (maxCols >= 2 && (index > 0 || wrap)) { + this.selectItemByIndex((index - 1 + maxItems) % maxItems); + } + } else { + this.selectPrev(wrap); + } +}; + +/** + * Moves the cursor to lower page + * + * @see DKTools.Sprite.Selectable.prototype.isHorizontal + * @see DKTools.Sprite.Selectable.prototype.getTopRow + * @see DKTools.Sprite.Selectable.prototype.getTopCol + * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows + * @see DKTools.Sprite.Selectable.prototype.getMaxPageCols + * @see DKTools.Sprite.Selectable.prototype.getMaxPageItems + * @see DKTools.Sprite.Selectable.prototype.getMaxItems + * @see DKTools.Sprite.Selectable.prototype.getMaxRows + * @see DKTools.Sprite.Selectable.prototype.setTopRow + * @see DKTools.Sprite.Selectable.prototype.setTopCol + * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + */ +DKTools.Sprite.Selectable.prototype.cursorPagedown = function() { + if (this.isHorizontal()) { + const topCol = this.getTopCol(); + const maxPageCols = this.getMaxPageCols(); + const maxItems = this.getMaxItems(); + + if (topCol + maxPageCols < maxItems) { + this.setTopCol(topCol + maxPageCols); + this.selectItemByIndex(Math.min(this._index + this.getMaxPageItems(), maxItems - 1)); + } + } else { + const topRow = this.getTopRow(); + const maxPageRows = this.getMaxPageRows(); + + if (topRow + maxPageRows < this.getMaxRows()) { + this.setTopRow(topRow + maxPageRows); + this.selectItemByIndex(Math.min(this._index + this.getMaxPageItems(), this.getMaxItems() - 1)); + } + } }; /** - * Returns the next item - * - * @param {Boolean} [wrap=false] - Cyclic selection - * - * @see DKTools.Sprite.Selectable.prototype.getNextIndex - * @see DKTools.Sprite.Selectable.prototype.getItem - * - * @returns {Object | null} Next item or null + * Moves the cursor to upper page + * + * @see DKTools.Sprite.Selectable.prototype.isHorizontal + * @see DKTools.Sprite.Selectable.prototype.getTopRow + * @see DKTools.Sprite.Selectable.prototype.getTopCol + * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows + * @see DKTools.Sprite.Selectable.prototype.getMaxPageCols + * @see DKTools.Sprite.Selectable.prototype.getMaxPageItems + * @see DKTools.Sprite.Selectable.prototype.setTopRow + * @see DKTools.Sprite.Selectable.prototype.setTopCol + * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex */ -DKTools.Sprite.Selectable.prototype.getNextItem = function(wrap) { - return this.getItem(this.getNextIndex(wrap)); +DKTools.Sprite.Selectable.prototype.cursorPageup = function() { + if (this.isHorizontal()) { + const topCol = this.getTopCol(); + + if (topCol > 0) { + this.setTopCol(topCol - this.getMaxPageCols()); + this.selectItemByIndex(Math.max(0, this._index - this.getMaxPageItems())); + } + } else { + const topRow = this.getTopRow(); + + if (topRow > 0) { + this.setTopRow(topRow - this.getMaxPageRows()); + this.selectItemByIndex(Math.max(0, this._index - this.getMaxPageItems())); + } + } }; /** - * Returns the current item (selected item) - * - * @see DKTools.Sprite.Selectable.prototype.getItem - * - * @returns {Object | null} Current item (selected item) or null + * Shows the cursor */ -DKTools.Sprite.Selectable.prototype.getCurrentItem = function() { - return this.getItem(this._index); +DKTools.Sprite.Selectable.prototype.showCursor = function() { + this._cursorSprite.show(true); }; /** - * Returns the index of the item - * - * @param {Object} item - item - * @returns {Number} Index of the item + * Hides the cursor */ -DKTools.Sprite.Selectable.prototype.getItemIndex = function(item) { - return _.indexOf(this._items, item); +DKTools.Sprite.Selectable.prototype.hideCursor = function() { + this._cursorSprite.hide(); }; +// touch methods + /** - * Returns the visible items - * - * @returns {Object[]} Visible items + * @private + * @param {Boolean} triggered + * + * @see DKTools.Sprite.Selectable.prototype.hitTest + * @see DKTools.Sprite.Selectable.prototype.isOkEnabled + * @see DKTools.Sprite.Selectable.prototype.isCursorMovable + * @see DKTools.Sprite.Selectable.prototype.processOk + * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + * @see DKTools.Sprite.Selectable.prototype.playCursorSound */ -DKTools.Sprite.Selectable.prototype.getVisibleItems = function() { - const maxPageItems = this.getMaxPageItems(); - const maxItems = this.getMaxItems(); - let index = this.getTopIndex(); - let items = []; +DKTools.Sprite.Selectable.prototype._onTouch = function(triggered) { + const lastIndex = this._index; + const x = TouchInput.x; + const y = TouchInput.y; + const hitIndex = this.hitTest(x, y); - for(let i = 0; i < maxPageItems && index < maxItems; i++, index++) { - items.push(this.getItem(index)); + if (hitIndex >= 0) { + if (this._index === hitIndex) { + if (triggered && this.isOkEnabled()) { + this.processOk(); + } + } else if (this.isCursorMovable()) { + this.selectItemByIndex(hitIndex); + } } - return items; + if (this._index !== lastIndex) { + this.playCursorSound(); + } }; /** - * Returns the name of the item by index - * - * @param {Number} index - Index - * @returns {String | null} Name of the item by index or null + * @param {Number} x - The X coordinate + * @param {Number} y - The Y coordinate + * + * @see DKTools.Sprite.Selectable.prototype.isOutside + * @see DKTools.Sprite.Selectable.prototype.canvasToLocalX + * @see DKTools.Sprite.Selectable.prototype.canvasToLocalY + * @see DKTools.Sprite.Selectable.prototype.getMaxPageItems + * @see DKTools.Sprite.Selectable.prototype.getMaxItems + * @see DKTools.Sprite.Selectable.prototype.getTopIndex + * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex + * + * @returns {Number} */ -DKTools.Sprite.Selectable.prototype.getItemName = function(index) { - const item = this.getItem(index); +DKTools.Sprite.Selectable.prototype.hitTest = function(x, y) { + if (this.isOutside(x, y)) { + return -1; + } - if (item) { - const name = item.name; - if (DKTools.Utils.isFunction(name)) { - return name(index); + const scale = this.scale; + const localX = this.canvasToLocalX(x); + const localY = this.canvasToLocalY(y); + const maxPageItems = this.getMaxPageItems(); + const maxItems = this.getMaxItems(); + let index = this.getTopIndex(); + + for (let i = 0; i < maxPageItems && index < maxItems; i++ , index++) { + const rect = this.getItemRectByIndex(index); + + rect.x *= scale.x; + rect.y *= scale.y; + rect.width *= scale.x; + rect.height *= scale.y; + + if (rect.contains(localX, localY)) { + return index; } - return name; } - return null; + return -1; }; +// draw methods + /** - * Returns the symbol of the item by index + * Draws all * - * @param {Number} index - Index - * @returns {String | null} Symbol of the item by index or null + * @override */ -DKTools.Sprite.Selectable.prototype.getItemSymbol = function(index) { - const item = this.getItem(index); - return item ? item.symbol : null; +DKTools.Sprite.Selectable.prototype.drawAll = function() { + DKTools.Sprite.Button.prototype.drawAll.call(this); + this.drawAllItems(); }; /** - * Returns the ext of the item by index - * - * @param {Number} index - Index - * @returns {* | null} Ext of the item by index or null + * Draws all items + * + * @see DKTools.Sprite.Selectable.prototype.getMaxPageItems + * @see DKTools.Sprite.Selectable.prototype.getMaxItems + * @see DKTools.Sprite.Selectable.prototype.getTopIndex + * @see DKTools.Sprite.Selectable.prototype.drawItemByIndex */ -DKTools.Sprite.Selectable.prototype.getItemExt = function(index) { - var item = this.getItem(index); - return item ? item.ext : null; +DKTools.Sprite.Selectable.prototype.drawAllItems = function() { + const maxPageItems = this.getMaxPageItems(); + const maxItems = this.getMaxItems(); + let index = this.getTopIndex(); + + for(let i = 0; i < maxPageItems && index < maxItems; i++, index++) { + this.drawItemByIndex(index); + } }; /** - * Returns the name of the current item (selected item) - * - * @see DKTools.Sprite.Selectable.prototype.getItemName + * Draws the item by index * - * @returns {String | null} Name of the current item (selected item) or null + * @param {Number} index - Index + * + * @see DKTools.Sprite.Selectable.prototype.hasDrawItemHandler */ -DKTools.Sprite.Selectable.prototype.getCurrentItemName = function() { - return this.getItemName(this._index); +DKTools.Sprite.Selectable.prototype.drawItemByIndex = function(index) { + if (this.hasDrawItemHandler()) { + this._drawItemHandler(index); + } }; /** - * Returns the symbol of the current item (selected item) - * - * @see DKTools.Sprite.Selectable.prototype.getItemSymbol + * Draws the item * - * @returns {String | null} Symbol of the current item (selected item) or null + * @param {Object} item - Item + * + * @see DKTools.Sprite.Selectable.prototype.getItemIndex + * @see DKTools.Sprite.Selectable.prototype.drawItemByIndex */ -DKTools.Sprite.Selectable.prototype.getCurrentItemSymbol = function() { - return this.getItemSymbol(this._index); +DKTools.Sprite.Selectable.prototype.drawItem = function(item) { + this.drawItemByIndex(this.getItemIndex(item)); }; /** - * Returns the ext of the current item (selected item) + * Clears the item by index * - * @see DKTools.Sprite.Selectable.prototype.getItemExt + * @param {Number} index - Index * - * @returns {* | null} Ext of the current item (selected item) or null + * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex + * @see DKTools.Sprite.Selectable.prototype.clearRect */ -DKTools.Sprite.Selectable.prototype.getCurrentItemExt = function() { - return this.getItemExt(this._index); +DKTools.Sprite.Selectable.prototype.clearItemByIndex = function(index) { + this.clearRect(this.getItemRectByIndex(index)); }; /** - * Returns the number of the items + * Clears the item * - * @returns {Number} Number of the items - */ -DKTools.Sprite.Selectable.prototype.getMaxItems = function() { - return this._items.length; -}; - -/** - * Returns the maximum number of the rows + * @param {Object} item - Item * - * @returns {Number} Maximum number of the rows + * @see DKTools.Sprite.Selectable.prototype.getItemIndex + * @see DKTools.Sprite.Selectable.prototype.clearItemByIndex */ -DKTools.Sprite.Selectable.prototype.getMaxRows = function() { - if (this.isFixedHorizontal()) { - return 1; - } - - return Math.max(1, Math.ceil(this.getMaxItems() / this.getMaxCols())); +DKTools.Sprite.Selectable.prototype.clearItem = function(item) { + this.clearItemByIndex(this.getItemIndex(item)); }; /** - * Returns the maximum number of the columns + * Redraws the item by index * - * @returns {Number} Maximum number of the columns - */ -DKTools.Sprite.Selectable.prototype.getMaxCols = function() { - return this._maxCols; -}; - -/** - * Returns the maximum top row - * - * @see DKTools.Sprite.Selectable.prototype.getMaxRows - * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows - * - * @returns {Number} Maximum top row + * @param {Number} index - Index + * + * @see DKTools.Sprite.Selectable.prototype.isItemVisibleByIndex + * @see DKTools.Sprite.Selectable.prototype.clearItemByIndex + * @see DKTools.Sprite.Selectable.prototype.drawItemByIndex */ -DKTools.Sprite.Selectable.prototype.getMaxTopRow = function() { - return Math.max(0, this.getMaxRows() - this.getMaxPageRows()); +DKTools.Sprite.Selectable.prototype.redrawItemByIndex = function(index) { + if (index >= 0 && this.isItemVisibleByIndex(index)) { + this.clearItemByIndex(index); + this.drawItemByIndex(index); + } }; /** - * Returns the maximum top column - * - * @see DKTools.Sprite.Selectable.prototype.getMaxItems - * @see DKTools.Sprite.Selectable.prototype.getMaxPageCols - * - * @returns {Number} Maximum top column + * Redraws the item + * + * @param {Object} item - Item + * + * @see DKTools.Sprite.Selectable.prototype.getItemIndex + * @see DKTools.Sprite.Selectable.prototype.redrawItemByIndex */ -DKTools.Sprite.Selectable.prototype.getMaxTopCol = function() { - return Math.max(0, this.getMaxItems() - this.getMaxPageCols()); +DKTools.Sprite.Selectable.prototype.redrawItem = function(item) { + this.redrawItemByIndex(this.getItemIndex(item)); }; /** - * Returns the maximum page rows - * - * @see DKTools.Sprite.Selectable.prototype.getItemHeight - * @see DKTools.Sprite.Selectable.prototype.getMaxRows - * - * @returns {Number} Maximum page rows + * Redraws the current item (selected item) + * + * @see DKTools.Sprite.Selectable.prototype.redrawItemByIndex */ -DKTools.Sprite.Selectable.prototype.getMaxPageRows = function() { - const spacing = this._verticalSpacing; - const realHeight = this.realHeight; - const itemHeight = this.getItemHeight(); - const maxRows = this.getMaxRows(); - let rows = 0, height = 0; - - for(; rows < maxRows && height + itemHeight + spacing <= realHeight && height + itemHeight <= realHeight; rows++) { - height += itemHeight + spacing; - } - - return rows; +DKTools.Sprite.Selectable.prototype.redrawCurrentItem = function() { + this.redrawItemByIndex(this._index); }; +// sound methods + /** - * Returns the maximum page columns - * - * @see DKTools.Sprite.Selectable.prototype.getMaxCols - * - * @returns {Number} Maximum page columns + * Plays "ok" sound + * + * @see SoundManager.playOk */ -DKTools.Sprite.Selectable.prototype.getMaxPageCols = function() { - return this.getMaxCols(); +DKTools.Sprite.Selectable.prototype.playOkSound = function() { + SoundManager.playOk(); }; /** - * Returns the maximum page items - * - * @see DKTools.Sprite.Selectable.prototype.isHorizontal - * @see DKTools.Sprite.Selectable.prototype.getMaxPageCols - * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows - * - * @returns {Number} Maximum page items + * Plays "cancel" sound + * + * @see SoundManager.playCancel */ -DKTools.Sprite.Selectable.prototype.getMaxPageItems = function() { - if (this.isHorizontal()) { - return this.getMaxPageCols(); - } - - return this.getMaxPageRows() * this.getMaxPageCols(); +DKTools.Sprite.Selectable.prototype.playCancelSound = function() { + SoundManager.playCancel(); }; /** - * Returns the row by index + * Plays "cursor" sound * - * @param {Number} index - Index - * - * @see DKTools.Sprite.Selectable.prototype.getMaxCols - * - * @returns {Number} Row by index + * @see SoundManager.playCursor */ -DKTools.Sprite.Selectable.prototype.getRowByIndex = function(index) { - return Math.floor(index / this.getMaxCols()); +DKTools.Sprite.Selectable.prototype.playCursorSound = function() { + SoundManager.playCursor(); }; /** - * Returns the current row + * Plays "buzzer" sound * - * @see DKTools.Sprite.Selectable.prototype.getRowByIndex - * - * @returns {Number} Current row + * @see SoundManager.playBuzzer */ -DKTools.Sprite.Selectable.prototype.getCurrentRow = function() { - return this.getRowByIndex(this._index); +DKTools.Sprite.Selectable.prototype.playBuzzerSound = function() { + SoundManager.playBuzzer(); }; +// call methods + /** - * Returns the row of the item + * Calls the handler of the symbol * - * @param {Object} item - Item - * - * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.getRowByIndex + * @param {String} symbol - Symbol * - * @returns {Number} Row of the item + * @see DKTools.Sprite.Selectable.prototype.isHandled */ -DKTools.Sprite.Selectable.prototype.getItemRow = function(item) { - return this.getRowByIndex(this.getItemIndex(item)); +DKTools.Sprite.Selectable.prototype.callHandler = function(symbol) { + if (this.isHandled(symbol)) { + this._handlers[symbol](this._index); + } }; /** - * Returns the list of the items by row - * - * @param {Number} row - Row - * - * @see DKTools.Sprite.Selectable.prototype.getMaxRows - * @see DKTools.Sprite.Selectable.prototype.getMaxPageItems - * @see DKTools.Sprite.Selectable.prototype.getMaxItems - * @see DKTools.Sprite.Selectable.prototype.getMaxCols - * @see DKTools.Sprite.Selectable.prototype.getRowByIndex - * @see DKTools.Sprite.Selectable.prototype.getItem + * Calls the handler of the Ok * - * @returns {Object[]} List of the items by row + * @see DKTools.Sprite.Selectable.prototype.getCurrentItemSymbol + * @see DKTools.Sprite.Selectable.prototype.isHandled + * @see DKTools.Sprite.Selectable.prototype.callHandler + * @see DKTools.Sprite.Selectable.prototype.activate */ -DKTools.Sprite.Selectable.prototype.getRowItems = function(row) { - const items = []; - - if (_.inRange(row, 0, this.getMaxRows())) { - const maxPageItems = this.getMaxPageItems(); - const maxItems = this.getMaxItems(); - let index = row * this.getMaxCols(); +DKTools.Sprite.Selectable.prototype.callOkHandler = function() { + const symbol = this.getCurrentItemSymbol(); - for(let i = 0; i < maxPageItems && index < maxItems && this.getRowByIndex(index) === row; i++, index++) { - items.push(this.getItem(index)); - } + if (this.isHandled(symbol)) { + this.callHandler(symbol); + } else if (this.isHandled('ok')) { + this.callHandler('ok'); + } else { + this.activate(); } - - return items; }; /** - * Returns the column by index - * - * @param {Number} index - Index - * - * @see DKTools.Sprite.Selectable.prototype.getMaxCols + * Calls the handler of the cancel * - * @returns {Number} Column by index + * @see DKTools.Sprite.Selectable.prototype.callHandler */ -DKTools.Sprite.Selectable.prototype.getColByIndex = function(index) { - return Math.floor(index % this.getMaxCols()); +DKTools.Sprite.Selectable.prototype.callCancelHandler = function() { + this.callHandler('cancel'); }; +// event methods + /** - * Returns the current column - * - * @see DKTools.Sprite.Selectable.prototype.isHorizontal - * @see DKTools.Sprite.Selectable.prototype.getColByIndex + * Updates the events with type: select * - * @returns {Number} Current column + * @see DKTools.Sprite.Selectable.prototype.updateEventsContainer */ -DKTools.Sprite.Selectable.prototype.getCurrentCol = function() { - if (this.isHorizontal()) { - return this._index; - } +DKTools.Sprite.Selectable.prototype.updateSelectEvents = function() { + this.updateEventsContainer('select'); +}; - return this.getColByIndex(this._index); +// select methods + +/** + * Selects the item by index + * + * @param {Number} index - Index + * + * @see DKTools.Sprite.Selectable.prototype.setupIndex + * @see DKTools.Sprite.Selectable.prototype.refreshAll + * @see DKTools.Sprite.Selectable.prototype.updateSelectEvents + */ +DKTools.Sprite.Selectable.prototype.selectItemByIndex = function(index) { + this.setupIndex(index); + this.refreshAll(); + this.updateSelectEvents(); }; /** - * Returns the column of the item + * Selects the item * * @param {Object} item - Item - * + * * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.getColByIndex - * - * @returns {Number} Column of the item + * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex */ -DKTools.Sprite.Selectable.prototype.getItemCol = function(item) { - return this.getColByIndex(this.getItemIndex(item)); +DKTools.Sprite.Selectable.prototype.selectItem = function(item) { + this.selectItemByIndex(this.getItemIndex(item)); }; /** - * Returns the list of the items by column + * Selects the item by symbol * - * @param {Number} col - Column - * - * @see DKTools.Sprite.Selectable.prototype.getMaxCols - * @see DKTools.Sprite.Selectable.prototype.getMaxItems - * @see DKTools.Sprite.Selectable.prototype.getColByIndex - * @see DKTools.Sprite.Selectable.prototype.getItem - * - * @returns {Object[]} List of the items by column + * @param {String} symbol - Symbol + * + * @see DKTools.Sprite.Selectable.prototype.findSymbol + * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex */ -DKTools.Sprite.Selectable.prototype.getColItems = function(col) { - const items = []; - - if (_.inRange(col, 0, this.getMaxCols())) { - const maxItems = this.getMaxItems(); - - for(let index = 0; index < maxItems; index++) { - if (this.getColByIndex(index) === col) { - items.push(this.getItem(index)); - } - } - } +DKTools.Sprite.Selectable.prototype.selectSymbol = function(symbol) { + const index = Math.max(0, this.findSymbol(symbol)); + this.selectItemByIndex(index); +}; - return items; +/** + * Selects the item by ext + * + * @param {*} ext - Ext of the item + * + * @see DKTools.Sprite.Selectable.prototype.findExt + * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + */ +DKTools.Sprite.Selectable.prototype.selectExt = function(ext) { + const index = Math.max(0, this.findExt(ext)); + this.selectItemByIndex(index); }; /** - * Returns the top index - * - * @see DKTools.Sprite.Selectable.prototype.isHorizontal - * @see DKTools.Sprite.Selectable.prototype.getTopCol - * @see DKTools.Sprite.Selectable.prototype.getTopRow - * @see DKTools.Sprite.Selectable.prototype.getMaxCols + * Deselects the current item (selected item) * - * @returns {Number} Top index + * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex */ -DKTools.Sprite.Selectable.prototype.getTopIndex = function() { - if (this.isHorizontal()) { - return this.getTopCol(); - } - - return this.getTopRow() * this.getMaxCols(); +DKTools.Sprite.Selectable.prototype.deselect = function() { + this.selectItemByIndex(-1); }; /** - * Returns the top row + * Reselects the current item (selected item) * - * @returns {Number} Top row + * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex */ -DKTools.Sprite.Selectable.prototype.getTopRow = function() { - return this._topRow; +DKTools.Sprite.Selectable.prototype.reselect = function() { + this.selectItemByIndex(this._index); }; /** - * Returns the top column - * - * @returns {Number} Top column + * Selects the previous item + * + * @param {Boolean} [wrap=false] - Cyclic selection + * + * @see DKTools.Sprite.Selectable.prototype.getPrevIndex + * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex */ -DKTools.Sprite.Selectable.prototype.getTopCol = function() { - return this._topCol; +DKTools.Sprite.Selectable.prototype.selectPrev = function(wrap) { + const index = this.getPrevIndex(wrap); + + if (index >= 0) { + this.selectItemByIndex(index); + } }; /** - * Returns the bottom row - * - * @see DKTools.Sprite.Selectable.prototype.getTopRow - * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows - * - * @returns {Number} Bottom row + * Selects the next item + * + * @param {Boolean} [wrap=false] - Cyclic selection + * + * @see DKTools.Sprite.Selectable.prototype.getNextIndex + * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex */ -DKTools.Sprite.Selectable.prototype.getBottomRow = function() { - return Math.max(0, this.getTopRow() + this.getMaxPageRows() - 1); +DKTools.Sprite.Selectable.prototype.selectNext = function(wrap) { + const index = this.getNextIndex(wrap); + + if (index >= 0) { + this.selectItemByIndex(index); + } }; +// remove methods + /** - * Returns the bottom column - * - * @see DKTools.Sprite.Selectable.prototype.getTopCol - * @see DKTools.Sprite.Selectable.prototype.getMaxPageCols - * - * @returns {Number} Bottom column + * Removes the handler of the symbol + * + * @param {String} symbol - Symbol */ -DKTools.Sprite.Selectable.prototype.getBottomCol = function() { - return Math.max(0, this.getTopCol() + this.getMaxPageCols() - 1); +DKTools.Sprite.Selectable.prototype.removeHandler = function(symbol) { + delete this._handlers[symbol]; }; +// item methods + /** - * Returns the bottom index + * Checks the item + * Returns the item * - * @see DKTools.Sprite.Selectable.prototype.getTopIndex - * @see DKTools.Sprite.Selectable.prototype.getMaxPageItems - * @see DKTools.Sprite.Selectable.prototype.getMaxItems + * @private * - * @returns {Number} Bottom index + * @param {Object} item - Item + * + * @see DKTools.Sprite.Selectable.prototype.setHandler + * + * @returns {Object} Item */ -DKTools.Sprite.Selectable.prototype.getBottomIndex = function() { - return Math.min(this.getTopIndex() + this.getMaxPageItems(), this.getMaxItems()) - 1; -}; +DKTools.Sprite.Selectable.prototype._checkItem = function(item) { + if (item.enabled === undefined) { + item.enabled = true; + } -// is methods + if (item.ext === undefined) { + item.ext = null; + } + if (item.symbol && item.handler) { + this.setHandler(item.symbol, item.handler); + } -/** - * Returns true if the cursor is fixed - * - * @returns {Boolean} Cursor is fixed - */ -DKTools.Sprite.Selectable.prototype.isCursorFixed = function() { - return this._cursorFixed; + return item; }; /** - * Returns true if the cursor all + * Removes the item * - * @returns {Boolean} Cursor all + * @param {Object} item - Item + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.hasItem + * @see DKTools.Utils.Array.remove + * @see DKTools.Sprite.Selectable.prototype.refreshAll + * + * @returns {Object | null} Removed item or null */ -DKTools.Sprite.Selectable.prototype.isCursorAll = function() { - return this._cursorAll; +DKTools.Sprite.Selectable.prototype.removeItem = function(item, blockRefreshAll) { + if (!this.hasItem(item)) { + return null; + } + + DKTools.Utils.Array.remove(this._items, item); + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return item; }; /** - * Returns true if the fixed horizontal position of the items + * Removes the item by index * - * @returns {Boolean} Fixed horizontal position of the items + * @param {Number} index - Index + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.getItem + * @see DKTools.Sprite.Selectable.prototype.removeItem + * + * @returns {Object | null} Removed item or null */ -DKTools.Sprite.Selectable.prototype.isFixedHorizontal = function() { - return this._fixedHorizontal; +DKTools.Sprite.Selectable.prototype.removeItemByIndex = function(index, blockRefreshAll) { + return this.removeItem(this.getItem(index), blockRefreshAll); }; /** - * Returns true if the position of the items is horizontal + * Removes the items * - * @see DKTools.Sprite.Selectable.prototype.isFixedHorizontal - * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows - * - * @returns {Boolean} Position of the items is horizontal + * @param {Object[]} items - Items + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.removeItem + * @see DKTools.Sprite.Selectable.prototype.refreshAll + * + * @returns {Object[]} Removed items */ -DKTools.Sprite.Selectable.prototype.isHorizontal = function() { - return this.isFixedHorizontal() || this.getMaxPageRows() === 1; +DKTools.Sprite.Selectable.prototype.removeItems = function(items, blockRefreshAll) { + const removed = []; + + _.forEach(items, function(item) { + const removedItem = this.removeItem(item, true); + + if (removedItem) { + removed.push(removedItem); + } + }.bind(this)); + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return removed; }; /** - * Returns true if the position of the items is vertical + * Inserts the item * - * @see DKTools.Sprite.Selectable.prototype.isHorizontal - * - * @returns {Boolean} Position of the items is vertical + * @param {Object} item - Item + * @param {Number} [index=0] - Index to insert + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Utils.Array.insert + * @see DKTools.Sprite.Selectable.prototype.refreshAll */ -DKTools.Sprite.Selectable.prototype.isVertical = function() { - return !this.isHorizontal(); +DKTools.Sprite.Selectable.prototype.insertItem = function(item, index, blockRefreshAll) { + DKTools.Utils.Array.insert(this._items, this._checkItem(item), index); + + if (!blockRefreshAll) { + this.refreshAll(); + } }; /** - * Returns true if the cursor can move + * Inserts the items * - * @see DKTools.Sprite.Selectable.prototype.isVisibleAndActive - * @see DKTools.Sprite.Selectable.prototype.isCursorFixed - * @see DKTools.Sprite.Selectable.prototype.isCursorAll - * @see DKTools.Sprite.Selectable.prototype.getMaxItems - * - * @returns {Boolean} Cursor can move + * @param {Object[]} items - Items + * @param {Number} [index=0] - Index to insert + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.insertItem + * @see DKTools.Sprite.Selectable.prototype.refreshAll */ -DKTools.Sprite.Selectable.prototype.isCursorMovable = function() { - return this.isVisibleAndActive() && !this.isCursorFixed() && !this.isCursorAll() && this.getMaxItems() > 0; -}; +DKTools.Sprite.Selectable.prototype.insertItems = function(items, index, blockRefreshAll) { + items = _.reverse(items); + _.forEach(items, function(item) { + this.insertItem(item, index, true); + }.bind(this)); -/** - * Returns true if the Ok is enabled - * - * @returns {Boolean} Ok is enabled - */ -DKTools.Sprite.Selectable.prototype.isOkEnabled = function() { - return true; + if (!blockRefreshAll) { + this.refreshAll(); + } }; /** - * Returns true if the cancel is enabled - * - * @see DKTools.Sprite.Selectable.prototype.isHandled - * - * @returns {Boolean} Cancel is enabled + * Adds the item + * + * @param {Object} item - Item + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.insertItem + * @see DKTools.Sprite.Selectable.prototype.refreshAll */ -DKTools.Sprite.Selectable.prototype.isCancelEnabled = function() { - return this.isHandled('cancel'); +DKTools.Sprite.Selectable.prototype.addItem = function(item, blockRefreshAll) { + this.insertItem(item, this.getMaxItems() - 1, true); + + if (!blockRefreshAll) { + this.refreshAll(); + } }; /** - * Returns true if the Ok is triggered - * - * @returns {Boolean} Ok is triggered + * Adds the items + * + * @param {Object[]} items - Items + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.addItem + * @see DKTools.Sprite.Selectable.prototype.refreshAll */ -DKTools.Sprite.Selectable.prototype.isOkTriggered = function() { - return Input.isRepeated('ok'); +DKTools.Sprite.Selectable.prototype.addItems = function(items, blockRefreshAll) { + _.forEach(items, function(item) { + this.addItem(item, true); + }.bind(this)); + + if (!blockRefreshAll) { + this.refreshAll(); + } }; /** - * Returns true if the cancel is triggered - * - * @returns {Boolean} Cancel is triggered + * Replaces the item + * + * @param {Object} item - Item + * @param {Number} [index=0] - Index + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.refreshAll */ -DKTools.Sprite.Selectable.prototype.isCancelTriggered = function() { - return Input.isRepeated('cancel') || TouchInput.isCancelled(); +DKTools.Sprite.Selectable.prototype.replaceItem = function(item, index, blockRefreshAll) { + this._items[index || 0] = this._checkItem(item); + + if (!blockRefreshAll) { + this.refreshAll(); + } }; /** - * Returns true if the cursor is visible + * Enables the item * - * @see DKTools.Sprite.Selectable.prototype.isHorizontal - * @see DKTools.Sprite.Selectable.prototype.getTopCol - * @see DKTools.Sprite.Selectable.prototype.getBottomCol - * @see DKTools.Sprite.Selectable.prototype.getCurrentRow - * @see DKTools.Sprite.Selectable.prototype.getTopRow - * @see DKTools.Sprite.Selectable.prototype.getBottomRow - * - * @returns {Boolean} Cursor is visible + * @param {Object} item - Item + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.hasItem + * @see DKTools.Sprite.Selectable.prototype.refreshAll */ -DKTools.Sprite.Selectable.prototype.isCursorVisible = function() { - if (!this._cursorSprite.isVisible()) { - return false; +DKTools.Sprite.Selectable.prototype.enableItem = function(item, blockRefreshAll) { + if (!this.hasItem(item)) { + return; } - if (this.isHorizontal()) { - const col = this.getCurrentCol(); + item.enabled = true; - return col >= this.getTopCol() && col <= this.getBottomCol(); + if (!blockRefreshAll) { + this.refreshAll(); } - - const row = this.getCurrentRow(); - - return row >= this.getTopRow() && row <= this.getBottomRow(); }; /** - * Returns true if the item by index is enabled + * Enables the item by index * * @param {Number} index - Index - * + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * * @see DKTools.Sprite.Selectable.prototype.getItem - * - * @returns {Boolean} Item by index is enabled + * @see DKTools.Sprite.Selectable.prototype.enableItem */ -DKTools.Sprite.Selectable.prototype.isItemEnabled = function(index) { - const item = this.getItem(index); +DKTools.Sprite.Selectable.prototype.enableItemByIndex = function(index, blockRefreshAll) { + this.enableItem(this.getItem(index), blockRefreshAll); +}; - if (item) { - const enabled = item.enabled; +/** + * Disables the item + * + * @param {Object} item - Item + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.hasItem + * @see DKTools.Sprite.Selectable.prototype.refreshAll + */ +DKTools.Sprite.Selectable.prototype.disableItem = function(item, blockRefreshAll) { + if (!this.hasItem(item)) { + return; + } - if (DKTools.Utils.isFunction(enabled)) { - return enabled(index); - } + item.enabled = false; - return enabled; + if (!blockRefreshAll) { + this.refreshAll(); } - - return false; }; /** - * Returns true if the current item (selected item) is enabled + * Disables the item by index * - * @see DKTools.Sprite.Selectable.prototype.isItemEnabled + * @param {Number} index - Index + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @returns {Boolean} Current item (selected item) is enabled + * @see DKTools.Sprite.Selectable.prototype.getItem + * @see DKTools.Sprite.Selectable.prototype.disableItem */ -DKTools.Sprite.Selectable.prototype.isCurrentItemEnabled = function() { - return this.isItemEnabled(this._index); +DKTools.Sprite.Selectable.prototype.disableItemByIndex = function(index, blockRefreshAll) { + this.disableItem(this.getItem(index), blockRefreshAll); }; +// find methods + /** - * Returns true if the symbol is handling + * Returns the index of the item by symbol * - * @param {String} symbol - Symbol - * @returns {Boolean} Symbol is handling + * @param {Symbol} symbol - Symbol + * @returns {Number} Index of the item by symbol */ -DKTools.Sprite.Selectable.prototype.isHandled = function(symbol) { - return !!this._handlers[symbol]; +DKTools.Sprite.Selectable.prototype.findSymbol = function(symbol) { + return _.findIndex(this._items, { symbol }); }; /** - * Returns true if the item by index is visible + * Returns the index of the item by ext * - * @param {Number} index - Index - * - * @see DKTools.Sprite.Selectable.prototype.getTopIndex - * @see DKTools.Sprite.Selectable.prototype.getBottomIndex - * - * @returns {Boolean} Item by index is visible + * @param {*} ext - Ext of the item + * @returns {Number} Index of the item by ext */ -DKTools.Sprite.Selectable.prototype.isItemVisibleByIndex = function(index) { - return _.inRange(index, this.getTopIndex(), this.getBottomIndex() + 1); +DKTools.Sprite.Selectable.prototype.findExt = function(ext) { + return _.findIndex(this._items, { ext }); }; +// scroll methods + /** - * Returns true if the item is visible - * - * @param {Object} item - Item - * - * @see DKTools.Sprite.Selectable.prototype.isItemVisibleByIndex - * - * @returns {Boolean} Item is visible + * Resets the scroll + * + * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex */ -DKTools.Sprite.Selectable.prototype.isItemVisible = function(item) { - return this.isItemVisibleByIndex(this.getItemIndex(item)); +DKTools.Sprite.Selectable.prototype.resetScroll = function() { + if (this._index !== 0) { + this.selectItemByIndex(0); + } }; -// has methods - /** - * Returns true if the item by index exists - * - * @param {Number} index - Index - * - * @see DKTools.Sprite.Selectable.prototype.getItem - * - * @returns {Boolean} Item by index exists + * Scrolls down + * + * @see DKTools.Sprite.Selectable.prototype.getTopRow + * @see DKTools.Sprite.Selectable.prototype.getMaxRows + * @see DKTools.Sprite.Selectable.prototype.cursorDown */ -DKTools.Sprite.Selectable.prototype.hasItemByIndex = function(index) { - return !!this.getItem(index); +DKTools.Sprite.Selectable.prototype.scrollDown = function() { + if (this.getTopRow() + 1 < this.getMaxRows()) { + this.cursorDown(); + } }; /** - * Returns true if the item exists - * - * @param {Object} item - item + * Scrolls up * - * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.hasItemByIndex + * @version 3.0.0 * - * @returns {Boolean} Item exists + * @see DKTools.Sprite.Selectable.prototype.getTopRow + * @see DKTools.Sprite.Selectable.prototype.cursorUp */ -DKTools.Sprite.Selectable.prototype.hasItem = function(item) { - return this.hasItemByIndex(this.getItemIndex(item)); +DKTools.Sprite.Selectable.prototype.scrollUp = function() { + if (this.getCurrentRow() > 0) { + this.cursorUp(); + } }; /** - * Returns true if the items exists - * + * Scrolls right + * + * @see DKTools.Sprite.Selectable.prototype.getTopCol * @see DKTools.Sprite.Selectable.prototype.getMaxItems - * - * @returns {Boolean} Items exists + * @see DKTools.Sprite.Selectable.prototype.cursorRight */ -DKTools.Sprite.Selectable.prototype.hasItems = function() { - return this.getMaxItems() > 0; +DKTools.Sprite.Selectable.prototype.scrollRight = function() { + if (this.getTopCol() + 1 < this.getMaxItems()) { + this.cursorRight(); + } }; /** - * Returns true if the handler of draw of the item exists + * Scrolls left * - * @returns {Boolean} Handler of draw of the item exists + * @version 3.0.0 + * + * @see DKTools.Sprite.Selectable.prototype.getTopCol + * @see DKTools.Sprite.Selectable.prototype.cursorLeft */ -DKTools.Sprite.Selectable.prototype.hasDrawItemHandler = function() { - return !!this._drawItemHandler; +DKTools.Sprite.Selectable.prototype.scrollLeft = function() { + if (this.getCurrentCol() > 0) { + this.cursorLeft(); + } }; -// active methods +// process methods /** - * Activates the object + * Processes all * * @override + * + * @see DKTools.Sprite.Selectable.prototype.processCursorMove + * @see DKTools.Sprite.Selectable.prototype.processHandling */ -DKTools.Sprite.Selectable.prototype.activate = function() { - DKTools.Sprite.Button.prototype.activate.call(this); - this.reselect(); +DKTools.Sprite.Selectable.prototype.processAll = function() { + DKTools.Sprite.Button.prototype.processAll.call(this); + this.processCursorMove(); + this.processHandling(); }; /** - * Deactivates the object - * - * @override - * @param {Boolean} [deselect=false] - Deselects the current item (selected item) - * - * @see DKTools.Sprite.Selectable.prototype.deselect + * Processes the move of the cursor + * + * @see DKTools.Sprite.Selectable.prototype.isCursorMovable + * @see DKTools.Sprite.Selectable.prototype.isHandled + * @see DKTools.Sprite.Selectable.prototype.cursorDown + * @see DKTools.Sprite.Selectable.prototype.cursorUp + * @see DKTools.Sprite.Selectable.prototype.cursorRight + * @see DKTools.Sprite.Selectable.prototype.cursorLeft + * @see DKTools.Sprite.Selectable.prototype.cursorPagedown + * @see DKTools.Sprite.Selectable.prototype.cursorPageup + * @see DKTools.Sprite.Selectable.prototype.playCursorSound */ -DKTools.Sprite.Selectable.prototype.deactivate = function(deselect) { - DKTools.Sprite.Button.prototype.deactivate.call(this); +DKTools.Sprite.Selectable.prototype.processCursorMove = function() { + if (!this.isCursorMovable()) { + return; + } + + const lastIndex = this._index; + + if (Input.isRepeated('down')) { + this.cursorDown(Input.isTriggered('down')); + } - if (deselect) { - this.deselect(); + if (Input.isRepeated('up')) { + this.cursorUp(Input.isTriggered('up')); } -}; -// cursor methods + if (Input.isRepeated('right')) { + this.cursorRight(Input.isTriggered('right')); + } -/** - * Moves the cursor to down - * - * @param {Boolean} [wrap=false] - Cyclic selection - * - * @see DKTools.Sprite.Selectable.prototype.isHorizontal - * @see DKTools.Sprite.Selectable.prototype.getMaxItems - * @see DKTools.Sprite.Selectable.prototype.getMaxCols - * @see DKTools.Sprite.Selectable.prototype.getMaxRows - * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex - */ -DKTools.Sprite.Selectable.prototype.cursorDown = function(wrap) { - if (this.isHorizontal()) { - return; + if (Input.isRepeated('left')) { + this.cursorLeft(Input.isTriggered('left')); } - const index = this._index; - const maxItems = this.getMaxItems(); - const maxCols = this.getMaxCols(); + if (!this.isHandled('pagedown') && Input.isTriggered('pagedown')) { + this.cursorPagedown(); + } - if (index < maxItems - maxCols || (wrap && maxItems === this.getMaxRows() * maxCols)) { - this.selectItemByIndex((index + maxCols) % maxItems); + if (!this.isHandled('pageup') && Input.isTriggered('pageup')) { + this.cursorPageup(); + } + + if (this._index !== lastIndex) { + this.playCursorSound(); } }; /** - * Moves the cursor to up - * - * @param {Boolean} [wrap=false] - Cyclic selection + * Processes the handling * - * @see DKTools.Sprite.Selectable.prototype.isHorizontal - * @see DKTools.Sprite.Selectable.prototype.getMaxItems - * @see DKTools.Sprite.Selectable.prototype.getMaxCols - * @see DKTools.Sprite.Selectable.prototype.getMaxRows - * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + * @see DKTools.Sprite.Selectable.prototype.isVisibleAndActive + * @see DKTools.Sprite.Selectable.prototype.isOkEnabled + * @see DKTools.Sprite.Selectable.prototype.isOkTriggered + * @see DKTools.Sprite.Selectable.prototype.isCancelEnabled + * @see DKTools.Sprite.Selectable.prototype.isCancelTriggered + * @see DKTools.Sprite.Selectable.prototype.isHandled + * @see DKTools.Sprite.Selectable.prototype.processOk + * @see DKTools.Sprite.Selectable.prototype.processCancel + * @see DKTools.Sprite.Selectable.prototype.processPagedown + * @see DKTools.Sprite.Selectable.prototype.processPageup */ -DKTools.Sprite.Selectable.prototype.cursorUp = function(wrap) { - if (this.isHorizontal()) { +DKTools.Sprite.Selectable.prototype.processHandling = function() { + if (!this.isVisibleAndActive()) { return; } - const index = this._index; - const maxItems = this.getMaxItems(); - const maxCols = this.getMaxCols(); - - if (index >= maxCols || (wrap && maxItems === this.getMaxRows() * maxCols)) { - this.selectItemByIndex((index - maxCols + maxItems) % maxItems); + if (this.isOkEnabled() && this.isOkTriggered()) { + this.processOk(); + } else if (this.isCancelEnabled() && this.isCancelTriggered()) { + this.processCancel(); + } else if (this.isHandled('pagedown') && Input.isTriggered('pagedown')) { + this.processPagedown(); + } else if (this.isHandled('pageup') && Input.isTriggered('pageup')) { + this.processPageup(); } }; /** - * Moves the cursor to right - * - * @param {Boolean} [wrap=false] - Cyclic selection + * Processes the hover of the mouse * - * @see DKTools.Sprite.Selectable.prototype.getMaxItems - * @see DKTools.Sprite.Selectable.prototype.isHorizontal - * @see DKTools.Sprite.Selectable.prototype.selectNext - * @see DKTools.Sprite.Selectable.prototype.getMaxCols + * @see DKTools.Sprite.Selectable.prototype.isOptionEnabled + * @see DKTools.Sprite.Selectable.prototype.isCursorMovable + * @see DKTools.Sprite.Selectable.prototype.hitTest * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + * @see DKTools.Sprite.Selectable.prototype.playCursorSound */ -DKTools.Sprite.Selectable.prototype.cursorRight = function(wrap) { - const maxItems = this.getMaxItems(); - - if (maxItems < 2) { - return; - } - - if (this.isVertical()) { - const index = this._index; - const maxCols = this.getMaxCols(); +DKTools.Sprite.Selectable.prototype.processMouseHover = function() { + if (this.isOptionEnabled('process-mouse-hover') && this.isCursorMovable()) { + const lastIndex = this._index; + const x = TouchInput.mouseX; + const y = TouchInput.mouseY; + const hitIndex = this.hitTest(x, y); - if (maxCols >= 2 && (index < maxItems - 1 || wrap)) { - this.selectItemByIndex((index + 1) % maxItems); + if (hitIndex >= 0 && hitIndex !== lastIndex) { + this.selectItemByIndex(hitIndex); + this.playCursorSound(); } - } else { - this.selectNext(wrap); } }; /** - * Moves the cursor to left - * - * @param {Boolean} [wrap=false] - Cyclic selection + * Processes the scroll of the mouse wheel * - * @see DKTools.Sprite.Selectable.prototype.getMaxItems + * @see DKTools.Sprite.Selectable.prototype.isOptionEnabled + * @see DKTools.Sprite.Selectable.prototype.isVisibleAndActive * @see DKTools.Sprite.Selectable.prototype.isHorizontal - * @see DKTools.Sprite.Selectable.prototype.selectPrev - * @see DKTools.Sprite.Selectable.prototype.getMaxCols - * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + * @see DKTools.Sprite.Selectable.prototype.scrollRight + * @see DKTools.Sprite.Selectable.prototype.scrollDown + * @see DKTools.Sprite.Selectable.prototype.scrollLeft + * @see DKTools.Sprite.Selectable.prototype.scrollUp */ -DKTools.Sprite.Selectable.prototype.cursorLeft = function(wrap) { - const maxItems = this.getMaxItems(); - - if (maxItems < 2) { - return; - } - - if (this.isVertical()) { - const index = this._index; - const maxCols = this.getMaxCols(); +DKTools.Sprite.Selectable.prototype.processWheelScroll = function() { + if (this.isOptionEnabled('process-wheel-scroll') && this.isVisibleAndActive()) { + const wheelY = this._wheelY; - if (maxCols >= 2 && (index > 0 || wrap)) { - this.selectItemByIndex((index - 1 + maxItems) % maxItems); + if (wheelY > 0) { + if (this.isHorizontal()) { + this.scrollRight(); + } else { + this.scrollDown(); + } + } else { + if (this.isHorizontal()) { + this.scrollLeft(); + } else { + this.scrollUp(); + } } - } else { - this.selectPrev(wrap); } }; /** - * Moves the cursor to lower page + * Processes ok * - * @see DKTools.Sprite.Selectable.prototype.isHorizontal - * @see DKTools.Sprite.Selectable.prototype.getTopRow - * @see DKTools.Sprite.Selectable.prototype.getTopCol - * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows - * @see DKTools.Sprite.Selectable.prototype.getMaxPageCols - * @see DKTools.Sprite.Selectable.prototype.getMaxPageItems - * @see DKTools.Sprite.Selectable.prototype.getMaxItems - * @see DKTools.Sprite.Selectable.prototype.getMaxRows - * @see DKTools.Sprite.Selectable.prototype.setTopRow - * @see DKTools.Sprite.Selectable.prototype.setTopCol - * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + * @see DKTools.Sprite.Selectable.prototype.isCurrentItemEnabled + * @see DKTools.Sprite.Selectable.prototype.updateInputData + * @see DKTools.Sprite.Selectable.prototype.deactivate + * @see DKTools.Sprite.Selectable.prototype.callOkHandler + * @see DKTools.Sprite.Selectable.prototype.playOkSound + * @see DKTools.Sprite.Selectable.prototype.playBuzzerSound */ -DKTools.Sprite.Selectable.prototype.cursorPagedown = function() { - if (this.isHorizontal()) { - const topCol = this.getTopCol(); - const maxPageCols = this.getMaxPageCols(); - const maxItems = this.getMaxItems(); - - if (topCol + maxPageCols < maxItems) { - this.setTopCol(topCol + maxPageCols); - this.selectItemByIndex(Math.min(this._index + this.getMaxPageItems(), maxItems - 1)); - } +DKTools.Sprite.Selectable.prototype.processOk = function() { + if (this.isCurrentItemEnabled()) { + this.playOkSound(); + this.updateInputData(); + this.deactivate(); + this.callOkHandler(); } else { - const topRow = this.getTopRow(); - const maxPageRows = this.getMaxPageRows(); - - if (topRow + maxPageRows < this.getMaxRows()) { - this.setTopRow(topRow + maxPageRows); - this.selectItemByIndex(Math.min(this._index + this.getMaxPageItems(), this.getMaxItems() - 1)); - } + this.playBuzzerSound(); } }; /** - * Moves the cursor to upper page + * Processes cancel * - * @see DKTools.Sprite.Selectable.prototype.isHorizontal - * @see DKTools.Sprite.Selectable.prototype.getTopRow - * @see DKTools.Sprite.Selectable.prototype.getTopCol - * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows - * @see DKTools.Sprite.Selectable.prototype.getMaxPageCols - * @see DKTools.Sprite.Selectable.prototype.getMaxPageItems - * @see DKTools.Sprite.Selectable.prototype.setTopRow - * @see DKTools.Sprite.Selectable.prototype.setTopCol - * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + * @see DKTools.Sprite.Selectable.prototype.playCancelSound + * @see DKTools.Sprite.Selectable.prototype.updateInputData + * @see DKTools.Sprite.Selectable.prototype.deactivate + * @see DKTools.Sprite.Selectable.prototype.callCancelHandler */ -DKTools.Sprite.Selectable.prototype.cursorPageup = function() { - if (this.isHorizontal()) { - const topCol = this.getTopCol(); - - if (topCol > 0) { - this.setTopCol(topCol - this.getMaxPageCols()); - this.selectItemByIndex(Math.max(0, this._index - this.getMaxPageItems())); - } - } else { - const topRow = this.getTopRow(); +DKTools.Sprite.Selectable.prototype.processCancel = function() { + this.playCancelSound(); + this.updateInputData(); + this.deactivate(); + this.callCancelHandler(); +}; - if (topRow > 0) { - this.setTopRow(topRow - this.getMaxPageRows()); - this.selectItemByIndex(Math.max(0, this._index - this.getMaxPageItems())); - } - } +/** + * Processes pageup + * + * @see DKTools.Sprite.Selectable.prototype.playCursorSound + * @see DKTools.Sprite.Selectable.prototype.updateInputData + * @see DKTools.Sprite.Selectable.prototype.deactivate + * @see DKTools.Sprite.Selectable.prototype.callHandler + */ +DKTools.Sprite.Selectable.prototype.processPageup = function() { + this.playCursorSound(); + this.updateInputData(); + this.deactivate(); + this.callHandler('pageup'); }; /** - * Shows the cursor + * Processes pagedown + * + * @see DKTools.Sprite.Selectable.prototype.playCursorSound + * @see DKTools.Sprite.Selectable.prototype.updateInputData + * @see DKTools.Sprite.Selectable.prototype.deactivate + * @see DKTools.Sprite.Selectable.prototype.callHandler */ -DKTools.Sprite.Selectable.prototype.showCursor = function() { - this._cursorSprite.show(true); +DKTools.Sprite.Selectable.prototype.processPagedown = function() { + this.playCursorSound(); + this.updateInputData(); + this.deactivate(); + this.callHandler('pagedown'); }; +// update methods + /** - * Hides the cursor + * Updates all + * + * @override + * + * @see DKTools.Sprite.Selectable.prototype.updateCursor */ -DKTools.Sprite.Selectable.prototype.hideCursor = function() { - this._cursorSprite.hide(); +DKTools.Sprite.Selectable.prototype.updateAll = function() { + DKTools.Sprite.Button.prototype.updateAll.call(this); + this.updateCursor(); }; -// touch methods - /** - * @private - * @param {Boolean} triggered + * Updates the cursor * - * @see DKTools.Sprite.Selectable.prototype.hitTest - * @see DKTools.Sprite.Selectable.prototype.isOkEnabled - * @see DKTools.Sprite.Selectable.prototype.isCursorMovable - * @see DKTools.Sprite.Selectable.prototype.processOk - * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex - * @see DKTools.Sprite.Selectable.prototype.playCursorSound + * @see DKTools.Sprite.Selectable.prototype.isHorizontal + * @see DKTools.Sprite.Selectable.prototype.isCursorAll + * @see DKTools.Sprite.Selectable.prototype.isCursorVisible + * @see DKTools.Sprite.Selectable.prototype.getCurrentCol + * @see DKTools.Sprite.Selectable.prototype.getTopCol + * @see DKTools.Sprite.Selectable.prototype.getBottomCol + * @see DKTools.Sprite.Selectable.prototype.getMaxRows + * @see DKTools.Sprite.Selectable.prototype.getItemHeight + * @see DKTools.Sprite.Selectable.prototype.setTopCol + * @see DKTools.Sprite.Selectable.prototype.setBottomCol + * @see DKTools.Sprite.Selectable.prototype.setCursorRect + * @see DKTools.Sprite.Selectable.prototype.resetScroll + * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex + * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex */ -DKTools.Sprite.Selectable.prototype._onTouch = function(triggered) { - const lastIndex = this._index; - const x = TouchInput.x; - const y = TouchInput.y; - const hitIndex = this.hitTest(x, y); +DKTools.Sprite.Selectable.prototype.updateCursor = function() { + if (this.isHorizontal()) { + const col = this.getCurrentCol(); - if (hitIndex >= 0) { - if (this._index === hitIndex) { - if (triggered && this.isOkEnabled()) { - this.processOk(); - } - } else if (this.isCursorMovable()) { - this.selectItemByIndex(hitIndex); + if (col < this.getTopCol()) { + this.setTopCol(col); + } else if (col > this.getBottomCol()) { + this.setBottomCol(col); + } + } else { + const row = this.getCurrentRow(); + + if (row < this.getTopRow()) { + this.setTopRow(row); + } else if (row > this.getBottomRow()) { + this.setBottomRow(row); } } - if (this._index !== lastIndex) { - this.playCursorSound(); + if (this.isCursorAll()) { + const allRowsHeight = this.getMaxRows() * this.getItemHeight(); + this.setCursorRect(0, 0, this.realWidth, allRowsHeight); + this.resetScroll(); + } else if (this.isCursorVisible() || !this._cursorSprite.hasBitmap()) { + const rect = this.getItemRectByIndex(this._index); + this.setCursorRect(rect); + } else { + this.setCursorRect(Rectangle.emptyRectangle); } }; -/** - * @param {Number} x - The X coordinate - * @param {Number} y - The Y coordinate - * - * @see DKTools.Sprite.Selectable.prototype.isOutside - * @see DKTools.Sprite.Selectable.prototype.canvasToLocalX - * @see DKTools.Sprite.Selectable.prototype.canvasToLocalY - * @see DKTools.Sprite.Selectable.prototype.getMaxPageItems - * @see DKTools.Sprite.Selectable.prototype.getMaxItems - * @see DKTools.Sprite.Selectable.prototype.getTopIndex - * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex - * - * @returns {Number} - */ -DKTools.Sprite.Selectable.prototype.hitTest = function(x, y) { - if (this.isOutside(x, y)) { - return -1; - } - const scale = this.scale; - const localX = this.canvasToLocalX(x); - const localY = this.canvasToLocalY(y); - const maxPageItems = this.getMaxPageItems(); - const maxItems = this.getMaxItems(); - let index = this.getTopIndex(); - for (let i = 0; i < maxPageItems && index < maxItems; i++ , index++) { - const rect = this.getItemRectByIndex(index); - rect.x *= scale.x; - rect.y *= scale.y; - rect.width *= scale.x; - rect.height *= scale.y; - if (rect.contains(localX, localY)) { - return index; - } - } +//=========================================================================== +// DKTools.Sprite.ProgressBar +//=========================================================================== - return -1; -}; +DKTools.Sprite.ProgressBar.prototype = Object.create(DKTools.Sprite.prototype); +DKTools.Sprite.ProgressBar.prototype.constructor = DKTools.Sprite.ProgressBar; -// draw methods +// properties -/** - * Draws all - * - * @override - */ -DKTools.Sprite.Selectable.prototype.drawAll = function() { - DKTools.Sprite.Button.prototype.drawAll.call(this); - this.drawAllItems(); -}; +Object.defineProperties(DKTools.Sprite.ProgressBar.prototype, { -/** - * Draws all items - * - * @see DKTools.Sprite.Selectable.prototype.getMaxPageItems - * @see DKTools.Sprite.Selectable.prototype.getMaxItems - * @see DKTools.Sprite.Selectable.prototype.getTopIndex - * @see DKTools.Sprite.Selectable.prototype.drawItemByIndex - */ -DKTools.Sprite.Selectable.prototype.drawAllItems = function() { - const maxPageItems = this.getMaxPageItems(); - const maxItems = this.getMaxItems(); - let index = this.getTopIndex(); + /** + * Value step + * + * @readonly + * @type {Number} + * @memberof DKTools.Sprite.ProgressBar.prototype + */ + valueStep: { + get: function() { + return this._valueStep; + }, + configurable: true + }, - for(let i = 0; i < maxPageItems && index < maxItems; i++, index++) { - this.drawItemByIndex(index); - } -}; + /** + * Maximum value + * + * @readonly + * @type {Number} + * @memberof DKTools.Sprite.ProgressBar.prototype + */ + maxValue: { + get: function() { + return this._maxValue; + }, + configurable: true + }, -/** - * Draws the item by index - * - * @param {Number} index - Index - * - * @see DKTools.Sprite.Selectable.prototype.hasDrawItemHandler - */ -DKTools.Sprite.Selectable.prototype.drawItemByIndex = function(index) { - if (this.hasDrawItemHandler()) { - this._drawItemHandler(index); - } -}; + /** + * Value + * + * @readonly + * @type {Number} + * @memberof DKTools.Sprite.ProgressBar.prototype + */ + value: { + get: function() { + return this._value; + }, + configurable: true + }, -/** - * Draws the item - * - * @param {Object} item - Item - * - * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.drawItemByIndex - */ -DKTools.Sprite.Selectable.prototype.drawItem = function(item) { - this.drawItemByIndex(this.getItemIndex(item)); -}; + /** + * Background color + * + * @readonly + * @type {String} + * @memberof DKTools.Sprite.ProgressBar.prototype + */ + backgroundColor: { + get: function() { + return this._backgroundColor; + }, + configurable: true + }, + + /** + * Progress color + * + * @readonly + * @type {String} + * @memberof DKTools.Sprite.ProgressBar.prototype + */ + progressColor: { + get: function() { + return this._progressColor; + }, + configurable: true + }, + + /** + * Handler of draw of the graphic + * + * @readonly + * @type {Function} + * @memberof DKTools.Sprite.ProgressBar.prototype + */ + drawGraphicHandler: { + get: function() { + return this._drawGraphicHandler; + }, + configurable: true + }, + + /** + * Handler of draw of the text + * + * @readonly + * @type {Function} + * @memberof DKTools.Sprite.ProgressBar.prototype + */ + drawTextHandler: { + get: function() { + return this._drawTextHandler; + }, + configurable: true + } -/** - * Clears the item by index - * - * @param {Number} index - Index - * - * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex - * @see DKTools.Sprite.Selectable.prototype.clearRect - */ -DKTools.Sprite.Selectable.prototype.clearItemByIndex = function(index) { - this.clearRect(this.getItemRectByIndex(index)); -}; +}); -/** - * Clears the item - * - * @param {Object} item - Item - * - * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.clearItemByIndex - */ -DKTools.Sprite.Selectable.prototype.clearItem = function(item) { - this.clearItemByIndex(this.getItemIndex(item)); -}; +// standard methods /** - * Redraws the item by index - * - * @param {Number} index - Index + * Returns the standard activity of the progress bar * - * @see DKTools.Sprite.Selectable.prototype.isItemVisibleByIndex - * @see DKTools.Sprite.Selectable.prototype.clearItemByIndex - * @see DKTools.Sprite.Selectable.prototype.drawItemByIndex + * @override + * @returns {Boolean} Standard activity of the progress bar */ -DKTools.Sprite.Selectable.prototype.redrawItemByIndex = function(index) { - if (index >= 0 && this.isItemVisibleByIndex(index)) { - this.clearItemByIndex(index); - this.drawItemByIndex(index); - } +DKTools.Sprite.ProgressBar.prototype.standardActive = function() { + return false; }; /** - * Redraws the item - * - * @param {Object} item - Item + * Returns the standard value step * - * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.redrawItemByIndex + * @returns {Number} Standard value step */ -DKTools.Sprite.Selectable.prototype.redrawItem = function(item) { - this.redrawItemByIndex(this.getItemIndex(item)); +DKTools.Sprite.ProgressBar.prototype.standardValueStep = function() { + return 1; }; /** - * Redraws the current item (selected item) + * Returns the standard maximum value * - * @see DKTools.Sprite.Selectable.prototype.redrawItemByIndex + * @returns {Number} Standard maximum value */ -DKTools.Sprite.Selectable.prototype.redrawCurrentItem = function() { - this.redrawItemByIndex(this._index); +DKTools.Sprite.ProgressBar.prototype.standardMaxValue = function() { + return 100; }; -// sound methods - /** - * Plays "ok" sound + * Returns the standard value * - * @see SoundManager.playOk + * @returns {Number} Standard value */ -DKTools.Sprite.Selectable.prototype.playOkSound = function() { - SoundManager.playOk(); +DKTools.Sprite.ProgressBar.prototype.standardValue = function() { + return 0; }; /** - * Plays "cancel" sound + * Returns the standard background color * - * @see SoundManager.playCancel + * @returns {String} Standard background color */ -DKTools.Sprite.Selectable.prototype.playCancelSound = function() { - SoundManager.playCancel(); +DKTools.Sprite.ProgressBar.prototype.standardBackgroundColor = function() { + return 'grey'; }; /** - * Plays "cursor" sound + * Returns the standard progress color * - * @see SoundManager.playCursor + * @returns {String} Standard progress color */ -DKTools.Sprite.Selectable.prototype.playCursorSound = function() { - SoundManager.playCursor(); +DKTools.Sprite.ProgressBar.prototype.standardProgressColor = function() { + return '#33ccff'; }; /** - * Plays "buzzer" sound + * Returns the standard handler of draw of the graphic * - * @see SoundManager.playBuzzer + * @returns {null} Standard handler of draw of the graphic */ -DKTools.Sprite.Selectable.prototype.playBuzzerSound = function() { - SoundManager.playBuzzer(); +DKTools.Sprite.ProgressBar.prototype.standardDrawGraphicHandler = function() { + return null; }; -// call methods - /** - * Calls the handler of the symbol + * Returns the standard handler of draw of the text * - * @param {String} symbol - Symbol - * - * @see DKTools.Sprite.Selectable.prototype.isHandled - */ -DKTools.Sprite.Selectable.prototype.callHandler = function(symbol) { - if (this.isHandled(symbol)) { - this._handlers[symbol](this._index); - } -}; - -/** - * Calls the handler of the Ok - * - * @see DKTools.Sprite.Selectable.prototype.getCurrentItemSymbol - * @see DKTools.Sprite.Selectable.prototype.isHandled - * @see DKTools.Sprite.Selectable.prototype.callHandler - * @see DKTools.Sprite.Selectable.prototype.activate - */ -DKTools.Sprite.Selectable.prototype.callOkHandler = function() { - const symbol = this.getCurrentItemSymbol(); - - if (this.isHandled(symbol)) { - this.callHandler(symbol); - } else if (this.isHandled('ok')) { - this.callHandler('ok'); - } else { - this.activate(); - } -}; - -/** - * Calls the handler of the cancel - * - * @see DKTools.Sprite.Selectable.prototype.callHandler - */ -DKTools.Sprite.Selectable.prototype.callCancelHandler = function() { - this.callHandler('cancel'); -}; - -// event methods - -/** - * Updates the events with type: select - * - * @see DKTools.Sprite.Selectable.prototype.updateEventsContainer + * @returns {null} Standard handler of draw of the text */ -DKTools.Sprite.Selectable.prototype.updateSelectEvents = function() { - this.updateEventsContainer('select'); +DKTools.Sprite.ProgressBar.prototype.standardDrawTextHandler = function() { + return null; }; -// select methods +// setup methods /** - * Selects the item by index + * Sets all parameters * - * @param {Number} index - Index + * @override * - * @see DKTools.Sprite.Selectable.prototype.setupIndex - * @see DKTools.Sprite.Selectable.prototype.refreshAll - * @see DKTools.Sprite.Selectable.prototype.updateSelectEvents + * @param {Object | null} [object={}] - Parameters + * + * @param {Number} [object.valueStep] - Value step + * @param {Number} [object.maxValue] - Maximum value + * @param {Number} [object.value] - Value + * @param {String} [object.backgroundColor] - Background color + * @param {String} [object.progressColor] - Progress color + * @param {Function} [object.drawGraphicHandler] - Handler of draw of the graphic + * @param {Function} [object.drawTextHandler] - Handler of draw of the text + * + * @see DKTools.Sprite.prototype.setupAll + * @see DKTools.Sprite.ProgressBar.setupValueStep + * @see DKTools.Sprite.ProgressBar.setupMaxValue + * @see DKTools.Sprite.ProgressBar.setupValue + * @see DKTools.Sprite.ProgressBar.setupBackgroundColor + * @see DKTools.Sprite.ProgressBar.setupProgressColor + * @see DKTools.Sprite.ProgressBar.setupDrawGraphicHandler + * @see DKTools.Sprite.ProgressBar.setupDrawTextHandler */ -DKTools.Sprite.Selectable.prototype.selectItemByIndex = function(index) { - this.setupIndex(index); - this.refreshAll(); - this.updateSelectEvents(); +DKTools.Sprite.ProgressBar.prototype.setupAll = function(object) { + object = object || {}; + DKTools.Sprite.prototype.setupAll.call(this, object); + this.setupValueStep(object.valueStep); + this.setupMaxValue(object.maxValue); + this.setupValue(object.value); + this.setupBackgroundColor(object.progressColor); + this.setupProgressColor(object.progressColor); + this.setupDrawGraphicHandler(object.drawGraphicHandler); + this.setupDrawTextHandler(object.drawTextHandler); }; /** - * Selects the item + * Sets the value step * - * @param {Object} item - Item + * @param {Number} [step=this.standardValueStep()] - Value step * - * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + * @see DKTools.Sprite.ProgressBar.prototype.standardValueStep */ -DKTools.Sprite.Selectable.prototype.selectItem = function(item) { - this.selectItemByIndex(this.getItemIndex(item)); +DKTools.Sprite.ProgressBar.prototype.setupValueStep = function(step) { + /** + * @private + * @readonly + * @type {Number} + */ + this._valueStep = step || this.standardValueStep(); }; /** - * Selects the item by symbol + * Sets the maximum value * - * @param {String} symbol - Symbol + * @param {Number} [max=this.standardMaxValue()] - Maximum value * - * @see DKTools.Sprite.Selectable.prototype.findSymbol - * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + * @see DKTools.Sprite.ProgressBar.prototype.setupMaxValue */ -DKTools.Sprite.Selectable.prototype.selectSymbol = function(symbol) { - const index = Math.max(0, this.findSymbol(symbol)); - this.selectItemByIndex(index); +DKTools.Sprite.ProgressBar.prototype.setupMaxValue = function(max) { + /** + * @private + * @readonly + * @type {Number} + */ + this._maxValue = max || this.standardMaxValue(); }; /** - * Selects the item by ext + * Sets the value * - * @param {*} ext - Ext of the item + * @param {Number} [value=this.standardValue()] - Value * - * @see DKTools.Sprite.Selectable.prototype.findExt - * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + * @see DKTools.Sprite.ProgressBar.prototype.standardValue */ -DKTools.Sprite.Selectable.prototype.selectExt = function(ext) { - const index = Math.max(0, this.findExt(ext)); - this.selectItemByIndex(index); +DKTools.Sprite.ProgressBar.prototype.setupValue = function(value) { + const max = this._maxValue; + const newValue = Math.max(0, Math.min(value, max)); + + /** + * @private + * @readonly + * @type {Number} + */ + this._value = Number.isNaN(newValue) ? this.standardValue() : newValue; }; /** - * Deselects the current item (selected item) - * - * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + * Sets the background color + * + * @param {String} [color=this.standardBackgroundColor()] - Background color + * + * @see DKTools.Sprite.ProgressBar.prototype.setupBackgroundColor */ -DKTools.Sprite.Selectable.prototype.deselect = function() { - this.selectItemByIndex(-1); +DKTools.Sprite.ProgressBar.prototype.setupBackgroundColor = function(color) { + /** + * @private + * @readonly + * @type {String} + */ + this._backgroundColor = color || this.standardBackgroundColor(); }; /** - * Reselects the current item (selected item) - * - * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + * Sets the progress color + * + * @param {String} [color=this.standardProgressColor()] - Progress color + * + * @see DKTools.Sprite.ProgressBar.prototype.standardProgressColor */ -DKTools.Sprite.Selectable.prototype.reselect = function() { - this.selectItemByIndex(this._index); +DKTools.Sprite.ProgressBar.prototype.setupProgressColor = function(color) { + /** + * @private + * @readonly + * @type {String} + */ + this._progressColor = color || this.standardProgressColor(); }; /** - * Selects the previous item + * Sets the handler of draw of the graphic * - * @param {Boolean} [wrap=false] - Cyclic selection + * @param {Function} [handler=this.standardDrawGraphicHandler()] - Handler of draw of the graphic * - * @see DKTools.Sprite.Selectable.prototype.getPrevIndex - * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + * @see DKTools.Sprite.ProgressBar.prototype.standardDrawGraphicHandler */ -DKTools.Sprite.Selectable.prototype.selectPrev = function(wrap) { - const index = this.getPrevIndex(wrap); - - if (index >= 0) { - this.selectItemByIndex(index); - } +DKTools.Sprite.ProgressBar.prototype.setupDrawGraphicHandler = function(handler) { + /** + * @private + * @readonly + * @type {Function} + */ + this._drawGraphicHandler = handler || this.standardDrawGraphicHandler(); }; /** - * Selects the next item + * Sets the handler of draw of the text * - * @param {Boolean} [wrap=false] - Cyclic selection + * @param {Function} [handler=this.standardDrawTextHandler()] - Handler of draw of the text * - * @see DKTools.Sprite.Selectable.prototype.getNextIndex - * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + * @see DKTools.Sprite.ProgressBar.prototype.standardDrawTextHandler */ -DKTools.Sprite.Selectable.prototype.selectNext = function(wrap) { - const index = this.getNextIndex(wrap); - - if (index >= 0) { - this.selectItemByIndex(index); - } +DKTools.Sprite.ProgressBar.prototype.setupDrawTextHandler = function(handler) { + /** + * @private + * @readonly + * @type {Function} + */ + this._drawTextHandler = handler || this.standardDrawTextHandler(); }; -// remove methods +// set methods /** - * Removes the handler of the symbol + * Changes all parameters + * Returns the number of changed parameters * - * @param {String} symbol - Symbol + * @override + * + * @param {Object} [object={}] - Parameters + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [activate=false] - Activates the progress bar + * + * @param {Number} [object.valueStep] - Value step + * @param {Number} [object.maxValue] - Maximum value + * @param {Number} [object.value] - Value + * @param {String} [object.backgroundColor] - Background color + * @param {String} [object.progressColor] - Progress color + * @param {Function} [object.drawGraphicHandler] - Handler of draw of the graphic + * @param {Function} [object.drawTextHandler] - Handler of draw of the text + * + * @see DKTools.Sprite.prototype.setAll + * @see DKTools.Sprite.ProgressBar.prototype.setValueStep + * @see DKTools.Sprite.ProgressBar.prototype.setMaxValue + * @see DKTools.Sprite.ProgressBar.prototype.setValue + * @see DKTools.Sprite.ProgressBar.prototype.setBackgroundColor + * @see DKTools.Sprite.ProgressBar.prototype.setProgressColor + * @see DKTools.Sprite.ProgressBar.prototype.setDrawGraphicHandler + * @see DKTools.Sprite.ProgressBar.prototype.setDrawTextHandler + * @see DKTools.Sprite.ProgressBar.prototype.start + * @see DKTools.Sprite.ProgressBar.prototype.activate + * + * @returns {Number} Number of changed parameters */ -DKTools.Sprite.Selectable.prototype.removeHandler = function(symbol) { - delete this._handlers[symbol]; -}; +DKTools.Sprite.ProgressBar.prototype.setAll = function(object, blockStart, activate) { + object = object || {}; + const block = true; -// item methods + let changed = DKTools.Sprite.prototype.setAll.call(this, object, block); -/** - * Checks the item - * Returns the item - * - * @private - * - * @param {Object} item - Item - * - * @see DKTools.Sprite.Selectable.prototype.setHandler - * - * @returns {Object} Item - */ -DKTools.Sprite.Selectable.prototype._checkItem = function(item) { - if (item.enabled === undefined) { - item.enabled = true; + if (this.setValueStep(object.valueStep, block)) { + changed++; } - if (item.ext === undefined) { - item.ext = null; + if (this.setMaxValue(object.maxValue, block)) { + changed++; } - if (item.symbol && item.handler) { - this.setHandler(item.symbol, item.handler); + if (this.setValue(object.value, block)) { + changed++; } - return item; -}; + if (this.setBackgroundColor(object.backgroundColor, block)) { + changed++; + } -/** - * Removes the item - * - * @param {Object} item - Item - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.hasItem - * @see DKTools.Utils.Array.remove - * @see DKTools.Sprite.Selectable.prototype.refreshAll - * - * @returns {Object | null} Removed item or null - */ -DKTools.Sprite.Selectable.prototype.removeItem = function(item, blockRefreshAll) { - if (!this.hasItem(item)) { - return null; + if (this.setProgressColor(object.progressColor, block)) { + changed++; } - DKTools.Utils.Array.remove(this._items, item); + if (this.setDrawGraphicHandler(object.drawGraphicHandler, block)) { + changed++; + } - if (!blockRefreshAll) { - this.refreshAll(); + if (this.setDrawTextHandler(object.drawTextHandler, block)) { + changed++; } - return item; -}; + if (changed) { + if (!blockStart) { + this.start(); + } -/** - * Removes the item by index - * - * @param {Number} index - Index - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.getItem - * @see DKTools.Sprite.Selectable.prototype.removeItem - * - * @returns {Object | null} Removed item or null - */ -DKTools.Sprite.Selectable.prototype.removeItemByIndex = function(index, blockRefreshAll) { - return this.removeItem(this.getItem(index), blockRefreshAll); + if (activate) { + this.activate(); + } + } + + return changed; }; /** - * Removes the items + * Changes the value step + * Returns true if the change occurred * - * @param {Object[]} items - Items + * @param {Number} [step] - Шаг значения * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.Selectable.prototype.removeItem - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * @see DKTools.Sprite.ProgressBar.prototype.setupValueStep + * @see DKTools.Sprite.ProgressBar.prototype.refreshAll * - * @returns {Object[]} Removed items + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype.removeItems = function(items, blockRefreshAll) { - const removed = []; +DKTools.Sprite.ProgressBar.prototype.setValueStep = function(step, blockRefreshAll) { + if (this._valueStep === step) { + return false; + } - _.forEach(items, function(item) { - const removedItem = this.removeItem(item, true); + const lastStep = this._valueStep; + this.setupValueStep(step); - if (removedItem) { - removed.push(removedItem); - } - }.bind(this)); + if (this._valueStep === lastStep) { + return false; + } if (!blockRefreshAll) { this.refreshAll(); } - return removed; + return true; }; /** - * Inserts the item + * Changes the maximum value + * Returns true if the change occurred * - * @param {Object} item - Item - * @param {Number} [index=0] - Index to insert + * @param {Number} [max] - Maximum value * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Utils.Array.insert - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * @see DKTools.Sprite.ProgressBar.prototype.setupMaxValue + * @see DKTools.Sprite.ProgressBar.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype.insertItem = function(item, index, blockRefreshAll) { - DKTools.Utils.Array.insert(this._items, this._checkItem(item), index); - - if (!blockRefreshAll) { - this.refreshAll(); +DKTools.Sprite.ProgressBar.prototype.setMaxValue = function(max, blockRefreshAll) { + if (this._maxValue === max) { + return false; } -}; -/** - * Inserts the items - * - * @param {Object[]} items - Items - * @param {Number} [index=0] - Index to insert - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.insertItem - * @see DKTools.Sprite.Selectable.prototype.refreshAll - */ -DKTools.Sprite.Selectable.prototype.insertItems = function(items, index, blockRefreshAll) { - items = _.reverse(items); - _.forEach(items, function(item) { - this.insertItem(item, index, true); - }.bind(this)); + const lastMax = this._maxValue; + this.setupMaxValue(max); + + if (this._maxValue === lastMax) { + return false; + } if (!blockRefreshAll) { this.refreshAll(); } + + return true; }; /** - * Adds the item + * Changes the value + * Returns true if the change occurred * - * @param {Object} item - Item + * @param {Number} [value] - Value * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.Selectable.prototype.insertItem - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * @see DKTools.Sprite.ProgressBar.prototype.setupValue + * @see DKTools.Sprite.ProgressBar.prototype.refreshAll + * @see DKTools.Sprite.ProgressBar.prototype.updateValueEvents + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype.addItem = function(item, blockRefreshAll) { - this.insertItem(item, this.getMaxItems() - 1, true); +DKTools.Sprite.ProgressBar.prototype.setValue = function(value, blockRefreshAll) { + if (this._value === value) { + return false; + } + + const lastValue = this._value; + this.setupValue(value); + + if (this._value === lastValue) { + return false; + } if (!blockRefreshAll) { this.refreshAll(); } + + this.updateValueEvents(); + + return true; }; /** - * Adds the items + * Changes the background color + * Returns true if the change occurred * - * @param {Object[]} items - Items + * @param {String} [color] - Background color * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.Selectable.prototype.addItem - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * @see DKTools.Sprite.ProgressBar.prototype.setupBackgroundColor + * @see DKTools.Sprite.ProgressBar.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype.addItems = function(items, blockRefreshAll) { - _.forEach(items, function(item) { - this.addItem(item, true); - }.bind(this)); +DKTools.Sprite.ProgressBar.prototype.setBackgroundColor = function(color, blockRefreshAll) { + if (this._backgroundColor === color) { + return false; + } + + const lastColor = this._backgroundColor; + this.setupBackgroundColor(color); + + if (this._backgroundColor === lastColor) { + return false; + } if (!blockRefreshAll) { this.refreshAll(); } + + return true; }; /** - * Replaces the item + * Changes the progress color + * Returns true if the change occurred * - * @param {Object} item - Item - * @param {Number} [index=0] - Index + * @param {String} [color] - Progress color * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * @see DKTools.Sprite.ProgressBar.prototype.setupProgressColor + * @see DKTools.Sprite.ProgressBar.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype.replaceItem = function(item, index, blockRefreshAll) { - this._items[index || 0] = this._checkItem(item); +DKTools.Sprite.ProgressBar.prototype.setProgressColor = function(color, blockRefreshAll) { + if (this._progressColor === color) { + return false; + } + + const lastColor = this._progressColor; + this.setupProgressColor(color); + + if (this._progressColor === lastColor) { + return false; + } if (!blockRefreshAll) { this.refreshAll(); } + + return true; }; /** - * Enables the item + * Changes the handler of draw of the graphic + * Returns true if the change occurred * - * @param {Object} item - Item + * @param {Function} [handler] - Handler of draw of the graphic * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.Selectable.prototype.hasItem - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * @see DKTools.Sprite.ProgressBar.prototype.setupDrawGraphicHandler + * @see DKTools.Sprite.ProgressBar.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype.enableItem = function(item, blockRefreshAll) { - if (!this.hasItem(item)) { - return; +DKTools.Sprite.ProgressBar.prototype.setDrawGraphicHandler = function(handler, blockRefreshAll) { + if (this._drawGraphicHandler === handler) { + return false; } - item.enabled = true; + this.setupDrawGraphicHandler(handler); if (!blockRefreshAll) { this.refreshAll(); } -}; -/** - * Enables the item by index - * - * @param {Number} index - Index - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.getItem - * @see DKTools.Sprite.Selectable.prototype.enableItem - */ -DKTools.Sprite.Selectable.prototype.enableItemByIndex = function(index, blockRefreshAll) { - this.enableItem(this.getItem(index), blockRefreshAll); + return true; }; /** - * Disables the item + * Changes the handler of draw of the text + * Returns true if the change occurred * - * @param {Object} item - Item + * @param {Function} [handler] - Handler of draw of the text * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.Selectable.prototype.hasItem - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * @see DKTools.Sprite.ProgressBar.prototype.setupDrawTextHandler + * @see DKTools.Sprite.ProgressBar.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype.disableItem = function(item, blockRefreshAll) { - if (!this.hasItem(item)) { - return; +DKTools.Sprite.ProgressBar.prototype.setDrawTextHandler = function(handler, blockRefreshAll) { + if (this._drawTextHandler === handler) { + return false; } - item.enabled = false; + this.setupDrawTextHandler(handler); if (!blockRefreshAll) { this.refreshAll(); } + + return true; }; +// can methods + /** - * Disables the item by index - * - * @param {Number} index - Index - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * Returns true if the progress bar can clone the fixed bitmap * - * @see DKTools.Sprite.Selectable.prototype.getItem - * @see DKTools.Sprite.Selectable.prototype.disableItem + * @override + * @returns {Boolean} Progress bar can clone the fixed bitmap */ -DKTools.Sprite.Selectable.prototype.disableItemByIndex = function(index, blockRefreshAll) { - this.disableItem(this.getItem(index), blockRefreshAll); +DKTools.Sprite.ProgressBar.prototype.canCloneFixedBitmap = function() { + return false; }; -// find methods +// is methods /** - * Returns the index of the item by symbol + * Returns true if the progress bar is horizontal * - * @param {Symbol} symbol - Symbol - * @returns {Number} Index of the item by symbol + * @returns {Boolean} Progress bar is horizontal */ -DKTools.Sprite.Selectable.prototype.findSymbol = function(symbol) { - return _.findIndex(this._items, { symbol }); +DKTools.Sprite.ProgressBar.prototype.isHorizontal = function() { + return this.width > this.height; }; /** - * Returns the index of the item by ext + * Returns true if the progress bar is vertical * - * @param {*} ext - Ext of the item - * @returns {Number} Index of the item by ext + * @see DKTools.Sprite.ProgressBar.prototype.isHorizontal + * + * @returns {Boolean} Progress bar is vertical */ -DKTools.Sprite.Selectable.prototype.findExt = function(ext) { - return _.findIndex(this._items, { ext }); +DKTools.Sprite.ProgressBar.prototype.isVertical = function() { + return !this.isHorizontal(); }; -// scroll methods +/** + * Returns true if the progress bar is empty + * + * @returns {Boolean} Progress bar is empty + */ +DKTools.Sprite.ProgressBar.prototype.isEmpty = function() { + return this._value === 0; +}; /** - * Resets the scroll - * - * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + * Returns true if the progress bar is full + * + * @returns {Boolean} Progress bar is full */ -DKTools.Sprite.Selectable.prototype.resetScroll = function() { - if (this._index !== 0) { - this.selectItemByIndex(0); - } +DKTools.Sprite.ProgressBar.prototype.isFull = function() { + return this._value === this._maxValue; }; +// events methods + /** - * Scrolls down - * - * @see DKTools.Sprite.Selectable.prototype.getTopRow - * @see DKTools.Sprite.Selectable.prototype.getMaxRows - * @see DKTools.Sprite.Selectable.prototype.cursorDown + * Updates the events + * + * @override + * + * @see DKTools.Sprite.prototype.updateEvents + * @see DKTools.Sprite.ProgressBar.prototype.updateEmptyEvents + * @see DKTools.Sprite.ProgressBar.prototype.updateFullEvents */ -DKTools.Sprite.Selectable.prototype.scrollDown = function() { - if (this.getTopRow() + 1 < this.getMaxRows()) { - this.cursorDown(); - } +DKTools.Sprite.ProgressBar.prototype.updateEvents = function() { + DKTools.Sprite.prototype.updateEvents.call(this); + this.updateEmptyEvents(); + this.updateFullEvents(); }; /** - * Scrolls up - * - * @see DKTools.Sprite.Selectable.prototype.getTopRow - * @see DKTools.Sprite.Selectable.prototype.cursorUp + * Updates the events with type: value + * + * @see DKTools.Sprite.ProgressBar.prototype.updateEventsContainer */ -DKTools.Sprite.Selectable.prototype.scrollUp = function() { - if (this.getTopRow() > 0) { - this.cursorUp(); - } +DKTools.Sprite.ProgressBar.prototype.updateValueEvents = function() { + this.updateEventsContainer('value'); }; /** - * Scrolls right - * - * @see DKTools.Sprite.Selectable.prototype.getTopCol - * @see DKTools.Sprite.Selectable.prototype.getMaxItems - * @see DKTools.Sprite.Selectable.prototype.cursorRight + * Updates the events with type: empty + * + * @see DKTools.Sprite.ProgressBar.prototype.isEmpty + * @see DKTools.Sprite.ProgressBar.prototype.updateEventsContainer */ -DKTools.Sprite.Selectable.prototype.scrollRight = function() { - if (this.getTopCol() + 1 < this.getMaxItems()) { - this.cursorRight(); +DKTools.Sprite.ProgressBar.prototype.updateEmptyEvents = function() { + if (this.isEmpty()) { + this.updateEventsContainer('empty'); } }; /** - * Scrolls left - * - * @see DKTools.Sprite.Selectable.prototype.getTopCol - * @see DKTools.Sprite.Selectable.prototype.cursorLeft + * Updates the events with type: full + * + * @see DKTools.Sprite.ProgressBar.prototype.isFull + * @see DKTools.Sprite.ProgressBar.prototype.updateEventsContainer */ -DKTools.Sprite.Selectable.prototype.scrollLeft = function() { - if (this.getTopCol() > 0) { - this.cursorLeft(); +DKTools.Sprite.ProgressBar.prototype.updateFullEvents = function() { + if (this.isFull()) { + this.updateEventsContainer('full'); } }; -// process methods - /** - * Processes all + * Handler of update of animate the value * - * @override - * - * @see DKTools.Sprite.Selectable.prototype.processCursorMove - * @see DKTools.Sprite.Selectable.prototype.processHandling + * @private + * + * @param {Number} value - Value + * @param {DKTools.Event} event - Event + * + * @see DKTools.Sprite.ProgressBar.prototype.setValue */ -DKTools.Sprite.Selectable.prototype.processAll = function() { - DKTools.Sprite.Button.prototype.processAll.call(this); - this.processCursorMove(); - this.processHandling(); +DKTools.Sprite.ProgressBar.prototype._updateAnimateValue = function(value, event) { + const remainingTime = event.remainingTime; + const newValue = (this._value * (remainingTime - 1) + value) / remainingTime; + + this.setValue(newValue); }; /** - * Processes the move of the cursor - * - * @see DKTools.Sprite.Selectable.prototype.isCursorMovable - * @see DKTools.Sprite.Selectable.prototype.isHandled - * @see DKTools.Sprite.Selectable.prototype.cursorDown - * @see DKTools.Sprite.Selectable.prototype.cursorUp - * @see DKTools.Sprite.Selectable.prototype.cursorRight - * @see DKTools.Sprite.Selectable.prototype.cursorLeft - * @see DKTools.Sprite.Selectable.prototype.cursorPagedown - * @see DKTools.Sprite.Selectable.prototype.cursorPageup - * @see DKTools.Sprite.Selectable.prototype.playCursorSound + * Animates the value + * Returns the update event + * + * @param {Number} value - Value + * @param {Number} duration - Duration of animation + * + * @see DKTools.Sprite.ProgressBar.prototype.addEvent + * @see DKTools.Sprite.ProgressBar.prototype._updateAnimateValue + * + * @returns {DKTools.Event} Update event */ -DKTools.Sprite.Selectable.prototype.processCursorMove = function() { - if (!this.isCursorMovable()) { - return; - } - - const lastIndex = this._index; - - if (Input.isRepeated('down')) { - this.cursorDown(Input.isTriggered('down')); - } - - if (Input.isRepeated('up')) { - this.cursorUp(Input.isTriggered('up')); - } - - if (Input.isRepeated('right')) { - this.cursorRight(Input.isTriggered('right')); - } - - if (Input.isRepeated('left')) { - this.cursorLeft(Input.isTriggered('left')); - } - - if (!this.isHandled('pagedown') && Input.isTriggered('pagedown')) { - this.cursorPagedown(); - } - - if (!this.isHandled('pageup') && Input.isTriggered('pageup')) { - this.cursorPageup(); - } - - if (this._index !== lastIndex) { - this.playCursorSound(); - } +DKTools.Sprite.ProgressBar.prototype.animateValue = function(value, duration) { + return this.addEvent({ + type: 'update', + repeatTime: duration, + repeats: 0, + onUpdate: this._updateAnimateValue.bind(this, value) + }); }; /** - * Processes the handling - * - * @see DKTools.Sprite.Selectable.prototype.isVisibleAndActive - * @see DKTools.Sprite.Selectable.prototype.isOkEnabled - * @see DKTools.Sprite.Selectable.prototype.isOkTriggered - * @see DKTools.Sprite.Selectable.prototype.isCancelEnabled - * @see DKTools.Sprite.Selectable.prototype.isCancelTriggered - * @see DKTools.Sprite.Selectable.prototype.isHandled - * @see DKTools.Sprite.Selectable.prototype.processOk - * @see DKTools.Sprite.Selectable.prototype.processCancel - * @see DKTools.Sprite.Selectable.prototype.processPagedown - * @see DKTools.Sprite.Selectable.prototype.processPageup + * Animates the empty value + * Returns the update event + * + * @param {Number} duration - Duration of animation + * + * @see DKTools.Sprite.ProgressBar.prototype.animateValue + * + * @returns {DKTools.Event} Update event */ -DKTools.Sprite.Selectable.prototype.processHandling = function() { - if (!this.isVisibleAndActive()) { - return; - } - - if (this.isOkEnabled() && this.isOkTriggered()) { - this.processOk(); - } else if (this.isCancelEnabled() && this.isCancelTriggered()) { - this.processCancel(); - } else if (this.isHandled('pagedown') && Input.isTriggered('pagedown')) { - this.processPagedown(); - } else if (this.isHandled('pageup') && Input.isTriggered('pageup')) { - this.processPageup(); - } +DKTools.Sprite.ProgressBar.prototype.animateEmpty = function(duration) { + return this.animateValue(0, duration); }; /** - * Processes the hover of the mouse - * - * @see DKTools.Sprite.Selectable.prototype.isOptionEnabled - * @see DKTools.Sprite.Selectable.prototype.isCursorMovable - * @see DKTools.Sprite.Selectable.prototype.hitTest - * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex - * @see DKTools.Sprite.Selectable.prototype.playCursorSound + * Animates the full value + * Returns the update event + * + * @param {Number} duration - Duration of animation + * + * @see DKTools.Sprite.ProgressBar.prototype.animateValue + * + * @returns {DKTools.Event} Update event */ -DKTools.Sprite.Selectable.prototype.processMouseHover = function() { - if (this.isOptionEnabled('process-mouse-hover') && this.isCursorMovable()) { - const lastIndex = this._index; - const x = TouchInput.mouseX; - const y = TouchInput.mouseY; - const hitIndex = this.hitTest(x, y); +DKTools.Sprite.ProgressBar.prototype.aimateFull = function(duration) { + return this.animateValue(this._maxValue, duration); +}; - if (hitIndex >= 0 && hitIndex !== lastIndex) { - this.selectItemByIndex(hitIndex); - this.playCursorSound(); - } +// _draw methods + +/** + * Draws the graphic of progress + * + * @private + * + * @see DKTools.Sprite.ProgressBar.prototype.hasDrawGraphicHandler + */ +DKTools.Sprite.ProgressBar.prototype._drawProgressGraphic = function() { + if (this.hasDrawGraphicHandler()) { + this._drawGraphicHandler(this); } }; /** - * Processes the scroll of the mouse wheel - * - * @see DKTools.Sprite.Selectable.prototype.isOptionEnabled - * @see DKTools.Sprite.Selectable.prototype.isVisibleAndActive - * @see DKTools.Sprite.Selectable.prototype.isHorizontal - * @see DKTools.Sprite.Selectable.prototype.scrollRight - * @see DKTools.Sprite.Selectable.prototype.scrollDown - * @see DKTools.Sprite.Selectable.prototype.scrollLeft - * @see DKTools.Sprite.Selectable.prototype.scrollUp + * Draws the text of progress + * + * @private + * + * @see DKTools.Sprite.ProgressBar.prototype.hasDrawTextHandler */ -DKTools.Sprite.Selectable.prototype.processWheelScroll = function() { - if (this.isOptionEnabled('process-wheel-scroll') && this.isVisibleAndActive()) { - const wheelY = this._wheelY; - - - if (wheelY > 0) { - if (this.isHorizontal()) { - this.scrollRight(); - } else { - this.scrollDown(); - } - } else { - if (this.isHorizontal()) { - this.scrollLeft(); - } else { - this.scrollUp(); - } - } +DKTools.Sprite.ProgressBar.prototype._drawProgressText = function() { + if (this.hasDrawTextHandler()) { + this._drawTextHandler(this); } }; +// draw methods + /** - * Processes ok - * - * @see DKTools.Sprite.Selectable.prototype.isCurrentItemEnabled - * @see DKTools.Sprite.Selectable.prototype.updateInputData - * @see DKTools.Sprite.Selectable.prototype.deactivate - * @see DKTools.Sprite.Selectable.prototype.callOkHandler - * @see DKTools.Sprite.Selectable.prototype.playOkSound - * @see DKTools.Sprite.Selectable.prototype.playBuzzerSound + * Draws all + * + * @override */ -DKTools.Sprite.Selectable.prototype.processOk = function() { - if (this.isCurrentItemEnabled()) { - this.playOkSound(); - this.updateInputData(); - this.deactivate(); - this.callOkHandler(); - } else { - this.playBuzzerSound(); - } +DKTools.Sprite.ProgressBar.prototype.drawAll = function() { + DKTools.Sprite.prototype.drawAll.call(this); + this.drawProgress(); }; /** - * Processes cancel - * - * @see DKTools.Sprite.Selectable.prototype.playCancelSound - * @see DKTools.Sprite.Selectable.prototype.updateInputData - * @see DKTools.Sprite.Selectable.prototype.deactivate - * @see DKTools.Sprite.Selectable.prototype.callCancelHandler + * Draws the progress + * + * @see DKTools.Sprite.ProgressBar.prototype._drawProgressGraphic + * @see DKTools.Sprite.ProgressBar.prototype._drawProgressText */ -DKTools.Sprite.Selectable.prototype.processCancel = function() { - this.playCancelSound(); - this.updateInputData(); - this.deactivate(); - this.callCancelHandler(); +DKTools.Sprite.ProgressBar.prototype.drawProgress = function() { + this._drawProgressGraphic(); + this._drawProgressText(); }; +// has methods + /** - * Processes pageup - * - * @see DKTools.Sprite.Selectable.prototype.playCursorSound - * @see DKTools.Sprite.Selectable.prototype.updateInputData - * @see DKTools.Sprite.Selectable.prototype.deactivate - * @see DKTools.Sprite.Selectable.prototype.callHandler + * Returns true if the progress bar has the handler of draw of the graphic + * + * @returns {Boolean} Progress bar has the handler of draw of the graphic */ -DKTools.Sprite.Selectable.prototype.processPageup = function() { - this.playCursorSound(); - this.updateInputData(); - this.deactivate(); - this.callHandler('pageup'); +DKTools.Sprite.ProgressBar.prototype.hasDrawGraphicHandler = function() { + return !!this._drawGraphicHandler; }; /** - * Processes pagedown - * - * @see DKTools.Sprite.Selectable.prototype.playCursorSound - * @see DKTools.Sprite.Selectable.prototype.updateInputData - * @see DKTools.Sprite.Selectable.prototype.deactivate - * @see DKTools.Sprite.Selectable.prototype.callHandler + * Returns true if the progress bar has the handler of draw of the text + * + * @returns {Boolean} Progress bar has the handler of draw of the text */ -DKTools.Sprite.Selectable.prototype.processPagedown = function() { - this.playCursorSound(); - this.updateInputData(); - this.deactivate(); - this.callHandler('pagedown'); +DKTools.Sprite.ProgressBar.prototype.hasDrawTextHandler = function() { + return !!this._drawTextHandler; }; -// update methods +// get methods /** - * Updates all + * Returns the current value in percent * - * @override - * - * @see DKTools.Sprite.Selectable.prototype.updateCursor + * @returns {Number} Current value in percent */ -DKTools.Sprite.Selectable.prototype.updateAll = function() { - DKTools.Sprite.Button.prototype.updateAll.call(this); - this.updateCursor(); +DKTools.Sprite.ProgressBar.prototype.getPercents = function() { + return Math.ceil(this._value / this._maxValue * 100); }; /** - * Updates the cursor - * - * @see DKTools.Sprite.Selectable.prototype.isHorizontal - * @see DKTools.Sprite.Selectable.prototype.isCursorAll - * @see DKTools.Sprite.Selectable.prototype.isCursorVisible - * @see DKTools.Sprite.Selectable.prototype.getCurrentCol - * @see DKTools.Sprite.Selectable.prototype.getTopCol - * @see DKTools.Sprite.Selectable.prototype.getBottomCol - * @see DKTools.Sprite.Selectable.prototype.getMaxRows - * @see DKTools.Sprite.Selectable.prototype.getItemHeight - * @see DKTools.Sprite.Selectable.prototype.setTopCol - * @see DKTools.Sprite.Selectable.prototype.setBottomCol - * @see DKTools.Sprite.Selectable.prototype.setCursorRect - * @see DKTools.Sprite.Selectable.prototype.resetScroll - * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex - * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex + * Returns the previous value + * + * @returns {Number} Previous value */ -DKTools.Sprite.Selectable.prototype.updateCursor = function() { - if (this.isHorizontal()) { - const col = this.getCurrentCol(); - - if (col < this.getTopCol()) { - this.setTopCol(col); - } else if (col > this.getBottomCol()) { - this.setBottomCol(col); - } - } else { - const row = this.getCurrentRow(); - - if (row < this.getTopRow()) { - this.setTopRow(row); - } else if (row > this.getBottomRow()) { - this.setBottomRow(row); - } - } - - if (this.isCursorAll()) { - const allRowsHeight = this.getMaxRows() * this.getItemHeight(); - this.setCursorRect(0, 0, this.realWidth, allRowsHeight); - this.resetScroll(); - } else if (this.isCursorVisible() || !this._cursorSprite.hasBitmap()) { - const rect = this.getItemRectByIndex(this._index); - this.setCursorRect(rect); - } else { - this.setCursorRect(Rectangle.emptyRectangle); - } +DKTools.Sprite.ProgressBar.prototype.getPrevValue = function() { + return Math.max(0, this._value - this._valueStep); }; +/** + * Returns the next value + * + * @returns {Number} Next value + */ +DKTools.Sprite.ProgressBar.prototype.getNextValue = function() { + return Math.min(this._value + this._valueStep, this._maxValue); +}; - - - -//=========================================================================== -// DKTools.Sprite.ProgressBar -//=========================================================================== - -DKTools.Sprite.ProgressBar.prototype = Object.create(DKTools.Sprite.prototype); -DKTools.Sprite.ProgressBar.prototype.constructor = DKTools.Sprite.ProgressBar; - -// properties - -Object.defineProperties(DKTools.Sprite.ProgressBar.prototype, { - - /** - * Value step - * - * @readonly - * @type {Number} - * @memberOf DKTools.Sprite.ProgressBar.prototype - */ - valueStep: { - get: function() { - return this._valueStep; - }, - configurable: true - }, - - /** - * Maximum value - * - * @readonly - * @type {Number} - * @memberOf DKTools.Sprite.ProgressBar.prototype - */ - maxValue: { - get: function() { - return this._maxValue; - }, - configurable: true - }, - - /** - * Value - * - * @readonly - * @type {Number} - * @memberOf DKTools.Sprite.ProgressBar.prototype - */ - value: { - get: function() { - return this._value; - }, - configurable: true - }, - - /** - * Background color - * - * @readonly - * @type {String} - * @memberOf DKTools.Sprite.ProgressBar.prototype - */ - backgroundColor: { - get: function() { - return this._backgroundColor; - }, - configurable: true - }, - - /** - * Progress color - * - * @readonly - * @type {String} - * @memberOf DKTools.Sprite.ProgressBar.prototype - */ - progressColor: { - get: function() { - return this._progressColor; - }, - configurable: true - }, - - /** - * Handler of draw of the graphic - * - * @readonly - * @type {Function} - * @memberOf DKTools.Sprite.ProgressBar.prototype - */ - drawGraphicHandler: { - get: function() { - return this._drawGraphicHandler; - }, - configurable: true - }, - - /** - * Handler of draw of the text - * - * @readonly - * @type {Function} - * @memberOf DKTools.Sprite.ProgressBar.prototype - */ - drawTextHandler: { - get: function() { - return this._drawTextHandler; - }, - configurable: true - } - -}); - -// standard methods +// value methods /** - * Returns the standard activity of the progress bar + * Adds the value * - * @override - * @returns {Boolean} Standard activity of the progress bar + * @param {Number} value - Value + * + * @see DKTools.Sprite.ProgressBar.prototype.setValue */ -DKTools.Sprite.ProgressBar.prototype.standardActive = function() { - return false; +DKTools.Sprite.ProgressBar.prototype.addValue = function(value) { + if (value) { + this.setValue(this._value + value); + } }; /** - * Returns the standard value step + * Subtracts the value * - * @returns {Number} Standard value step + * @param {Number} value - Value + * + * @see DKTools.Sprite.ProgressBar.prototype.addValue */ -DKTools.Sprite.ProgressBar.prototype.standardValueStep = function() { - return 1; +DKTools.Sprite.ProgressBar.prototype.subValue = function(value) { + this.addValue(-value); }; /** - * Returns the standard maximum value + * Sets the previous value + * Returns true if the change occurred * - * @returns {Number} Standard maximum value + * @see DKTools.Sprite.ProgressBar.prototype.getPrevValue + * @see DKTools.Sprite.ProgressBar.prototype.setValue + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.ProgressBar.prototype.standardMaxValue = function() { - return 100; +DKTools.Sprite.ProgressBar.prototype.prevValue = function() { + return this.setValue(this.getPrevValue()); }; /** - * Returns the standard value + * Sets the next value + * Returns true if the change occurred * - * @returns {Number} Standard value + * @see DKTools.Sprite.ProgressBar.prototype.getNextValue + * @see DKTools.Sprite.ProgressBar.prototype.setValue + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.ProgressBar.prototype.standardValue = function() { - return 0; +DKTools.Sprite.ProgressBar.prototype.nextValue = function() { + return this.setValue(this.getNextValue()); }; /** - * Returns the standard background color + * Makes the progress bar empty * - * @returns {String} Standard background color + * @see DKTools.Sprite.ProgressBar.prototype.setValue */ -DKTools.Sprite.ProgressBar.prototype.standardBackgroundColor = function() { - return 'grey'; +DKTools.Sprite.ProgressBar.prototype.makeEmpty = function() { + this.setValue(0); }; /** - * Returns the standard progress color + * Makes the progress bar full * - * @returns {String} Standard progress color + * @see DKTools.Sprite.ProgressBar.prototype.setValue */ -DKTools.Sprite.ProgressBar.prototype.standardProgressColor = function() { - return '#33ccff'; +DKTools.Sprite.ProgressBar.prototype.makeFull = function() { + this.setValue(this._maxValue); }; + + + + +//=========================================================================== +// DKTools.Sprite.ProgressBar.Rectangle +//=========================================================================== + +DKTools.Sprite.ProgressBar.Rectangle.prototype = Object.create(DKTools.Sprite.ProgressBar.prototype); +DKTools.Sprite.ProgressBar.Rectangle.prototype.constructor = DKTools.Sprite.ProgressBar.Rectangle; + +// standard methods + /** - * Returns the standard handler of draw of the graphic + * Returns the standard handler of draw of the graphic for horizontal progress bar * - * @returns {null} Standard handler of draw of the graphic + * @returns {Function} Standard handler of draw of the graphic for horizontal progress bar */ -DKTools.Sprite.ProgressBar.prototype.standardDrawGraphicHandler = function() { - return null; +DKTools.Sprite.ProgressBar.Rectangle.prototype.standardHorizontalDrawGraphicHandler = function() { + return function() { + this.fillAll(this._backgroundColor); + + if (!this.isEmpty()) { + this.fillRect({ + color: this._progressColor, + width: this._value * this.realWidth / this._maxValue + }); + } + }.bind(this); }; /** - * Returns the standard handler of draw of the text + * Returns the standard handler of draw of the graphic for vertical progress bar * - * @returns {null} Standard handler of draw of the text + * @returns {Function} Standard handler of draw of the graphic for vertical progress bar */ -DKTools.Sprite.ProgressBar.prototype.standardDrawTextHandler = function() { - return null; -}; +DKTools.Sprite.ProgressBar.Rectangle.prototype.standardVerticalDrawGraphicHandler = function() { + return function() { + this.fillAll(this._backgroundColor); -// setup methods + if (!this.isEmpty()) { + const realHeight = this.realHeight; + const height = this._value * realHeight / this._maxValue; + + this.fillRect({ + color: this._progressColor, + y: realHeight - height, + width: this.realWidth, + height + }); + } + }.bind(this); +}; /** - * Sets all parameters + * Returns the standard handler of draw of the graphic * * @override * - * @param {Object | null} [object={}] - Parameters - * - * @param {Number} [object.valueStep] - Value step - * @param {Number} [object.maxValue] - Maximum value - * @param {Number} [object.value] - Value - * @param {String} [object.backgroundColor] - Background color - * @param {String} [object.progressColor] - Progress color - * @param {Function} [object.drawGraphicHandler] - Handler of draw of the graphic - * @param {Function} [object.drawTextHandler] - Handler of draw of the text + * @see DKTools.Sprite.ProgressBar.Rectangle.prototype.isHorizontal + * @see DKTools.Sprite.ProgressBar.Rectangle.prototype.standardHorizontalDrawGraphicHandler + * @see DKTools.Sprite.ProgressBar.Rectangle.prototype.standardVerticalDrawGraphicHandler * - * @see DKTools.Sprite.prototype.setupAll - * @see DKTools.Sprite.ProgressBar.setupValueStep - * @see DKTools.Sprite.ProgressBar.setupMaxValue - * @see DKTools.Sprite.ProgressBar.setupValue - * @see DKTools.Sprite.ProgressBar.setupBackgroundColor - * @see DKTools.Sprite.ProgressBar.setupProgressColor - * @see DKTools.Sprite.ProgressBar.setupDrawGraphicHandler - * @see DKTools.Sprite.ProgressBar.setupDrawTextHandler + * @returns {Function} Standard handler of draw of the graphic */ -DKTools.Sprite.ProgressBar.prototype.setupAll = function(object) { - object = object || {}; - DKTools.Sprite.prototype.setupAll.call(this, object); - this.setupValueStep(object.valueStep); - this.setupMaxValue(object.maxValue); - this.setupValue(object.value); - this.setupBackgroundColor(object.progressColor); - this.setupProgressColor(object.progressColor); - this.setupDrawGraphicHandler(object.drawGraphicHandler); - this.setupDrawTextHandler(object.drawTextHandler); +DKTools.Sprite.ProgressBar.Rectangle.prototype.standardDrawGraphicHandler = function() { + return function(progressBar) { + let handler; + + if (this.isHorizontal()) { + handler = this.standardHorizontalDrawGraphicHandler(); + } else { + handler = this.standardVerticalDrawGraphicHandler(); + } + + if (handler) { + handler(progressBar); + } + }.bind(this); }; /** - * Sets the value step - * - * @param {Number} [step=this.standardValueStep()] - Value step + * Returns the standard handler of draw of the text * - * @see DKTools.Sprite.ProgressBar.prototype.standardValueStep + * @override + * @returns {Function} Standard handler of draw of the text */ -DKTools.Sprite.ProgressBar.prototype.setupValueStep = function(step) { - /** - * @private - * @readonly - * @type {Number} - */ - this._valueStep = step || this.standardValueStep(); +DKTools.Sprite.ProgressBar.Rectangle.prototype.standardDrawTextHandler = function() { + return function() { + const percents = this.getPercents(); + const text = `${percents}%`; + + this.drawText(text, { + height: this.realHeight + }); + }.bind(this); }; -/** - * Sets the maximum value - * - * @param {Number} [max=this.standardMaxValue()] - Maximum value - * - * @see DKTools.Sprite.ProgressBar.prototype.setupMaxValue - */ -DKTools.Sprite.ProgressBar.prototype.setupMaxValue = function(max) { + + + + +//=========================================================================== +// DKTools.Sprite.ProgressBar.Circle +//=========================================================================== + +DKTools.Sprite.ProgressBar.Circle.prototype = Object.create(DKTools.Sprite.ProgressBar.prototype); +DKTools.Sprite.ProgressBar.Circle.prototype.constructor = DKTools.Sprite.ProgressBar.Circle; + +// properties + +Object.defineProperties(DKTools.Sprite.ProgressBar.Circle.prototype, { + /** - * @private + * Line width + * * @readonly * @type {Number} + * @memberof DKTools.Sprite.ProgressBar.Circle.prototype */ - this._maxValue = max || this.standardMaxValue(); -}; + lineWidth: { + get: function() { + return this._lineWidth; + }, + configurable: true + } + +}); + +// standard methods /** - * Sets the value - * - * @param {Number} [value=this.standardValue()] - Value + * Returns the standard handler of draw of the graphic * - * @see DKTools.Sprite.ProgressBar.prototype.standardValue + * @override + * @returns {Function} Standard handler of draw of the graphic */ -DKTools.Sprite.ProgressBar.prototype.setupValue = function(value) { - const max = this._maxValue; - const newValue = Math.max(0, Math.min(value, max)); +DKTools.Sprite.ProgressBar.Circle.prototype.standardDrawGraphicHandler = function() { + return function() { + const lineWidth = this._lineWidth; + const realWidth = this.realWidth; + const radius = (realWidth - lineWidth) / 2; + const x = radius + lineWidth / 2; + const y = x; - /** - * @private - * @readonly - * @type {Number} - */ - this._value = Number.isNaN(newValue) ? this.standardValue() : newValue; + this.strokeArc({ + x, + y, + radius, + color: this._backgroundColor, + lineWidth + }); + + this.strokeArc({ + x, + y, + radius, + startAngle: -Math.PI / 2, + endAngle: -Math.PI / 2 + Math.PI * 2 * this._value / this._maxValue, + color: this._progressColor, + lineWidth + }); + }.bind(this); }; /** - * Sets the background color - * - * @param {String} [color=this.standardBackgroundColor()] - Background color + * Returns the standard handler of draw of the text * - * @see DKTools.Sprite.ProgressBar.prototype.setupBackgroundColor + * @override + * @returns {Function} Standard handler of draw of the text */ -DKTools.Sprite.ProgressBar.prototype.setupBackgroundColor = function(color) { - /** - * @private - * @readonly - * @type {String} - */ - this._backgroundColor = color || this.standardBackgroundColor(); +DKTools.Sprite.ProgressBar.Circle.prototype.standardDrawTextHandler = function() { + return function() { + const percents = this.getPercents(); + const text = `${percents}%`; + this.drawText(text, { height: this.realHeight }); + }.bind(this); }; /** - * Sets the progress color - * - * @param {String} [color=this.standardProgressColor()] - Progress color + * Returns the standard line width * - * @see DKTools.Sprite.ProgressBar.prototype.standardProgressColor + * @returns {Number} Standard line width */ -DKTools.Sprite.ProgressBar.prototype.setupProgressColor = function(color) { - /** - * @private - * @readonly - * @type {String} - */ - this._progressColor = color || this.standardProgressColor(); +DKTools.Sprite.ProgressBar.Circle.prototype.standardLineWidth = function() { + return 10; }; +// setup methods + /** - * Sets the handler of draw of the graphic + * Sets all parameters * - * @param {Function} [handler=this.standardDrawGraphicHandler()] - Handler of draw of the graphic + * @override * - * @see DKTools.Sprite.ProgressBar.prototype.standardDrawGraphicHandler - */ -DKTools.Sprite.ProgressBar.prototype.setupDrawGraphicHandler = function(handler) { - /** - * @private - * @readonly - * @type {Function} - */ - this._drawGraphicHandler = handler || this.standardDrawGraphicHandler(); + * @param {Object} [object={}] - Parameters + * + * @param {Number} [object.lineWidth] - Line width + * + * @see DKTools.Sprite.ProgressBar.prototype.setupAll + * @see DKTools.Sprite.ProgressBar.Circle.prototype.setupLineWidth + */ +DKTools.Sprite.ProgressBar.Circle.prototype.setupAll = function(object) { + object = object || {}; + DKTools.Sprite.ProgressBar.prototype.setupAll.call(this, object); + this.setupLineWidth(object.lineWidth); }; /** - * Sets the handler of draw of the text + * Sets the line width * - * @param {Function} [handler=this.standardDrawTextHandler()] - Handler of draw of the text + * @param {Number} [width=this.standardLineWidth()] - Line width * - * @see DKTools.Sprite.ProgressBar.prototype.standardDrawTextHandler + * @see DKTools.Sprite.ProgressBar.Circle.prototype.standardLineWidth */ -DKTools.Sprite.ProgressBar.prototype.setupDrawTextHandler = function(handler) { +DKTools.Sprite.ProgressBar.Circle.prototype.setupLineWidth = function(width) { /** * @private * @readonly - * @type {Function} + * @type {Number} */ - this._drawTextHandler = handler || this.standardDrawTextHandler(); + this._lineWidth = width || this.standardLineWidth(); }; // set methods @@ -21968,58 +23159,21 @@ DKTools.Sprite.ProgressBar.prototype.setupDrawTextHandler = function(handler) { * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * @param {Boolean} [activate=false] - Activates the progress bar * - * @param {Number} [object.valueStep] - Value step - * @param {Number} [object.maxValue] - Maximum value - * @param {Number} [object.value] - Value - * @param {String} [object.backgroundColor] - Background color - * @param {String} [object.progressColor] - Progress color - * @param {Function} [object.drawGraphicHandler] - Handler of draw of the graphic - * @param {Function} [object.drawTextHandler] - Handler of draw of the text + * @param {Number} [object.lineWidth] - Line width * - * @see DKTools.Sprite.prototype.setAll - * @see DKTools.Sprite.ProgressBar.prototype.setValueStep - * @see DKTools.Sprite.ProgressBar.prototype.setMaxValue - * @see DKTools.Sprite.ProgressBar.prototype.setValue - * @see DKTools.Sprite.ProgressBar.prototype.setBackgroundColor - * @see DKTools.Sprite.ProgressBar.prototype.setProgressColor - * @see DKTools.Sprite.ProgressBar.prototype.setDrawGraphicHandler - * @see DKTools.Sprite.ProgressBar.prototype.setDrawTextHandler - * @see DKTools.Sprite.ProgressBar.prototype.start - * @see DKTools.Sprite.ProgressBar.prototype.activate + * @see DKTools.Sprite.ProgressBar.prototype.setAll + * @see DKTools.Sprite.ProgressBar.Circle.prototype.setLineWidth + * @see DKTools.Sprite.ProgressBar.Circle.prototype.start + * @see DKTools.Sprite.ProgressBar.Circle.prototype.activate * * @returns {Number} Number of changed parameters */ -DKTools.Sprite.ProgressBar.prototype.setAll = function(object, blockStart, activate) { +DKTools.Sprite.ProgressBar.Circle.prototype.setAll = function(object, blockStart, activate) { object = object || {}; const block = true; + let changed = DKTools.Sprite.ProgressBar.prototype.setAll.call(this, object, block); - let changed = DKTools.Sprite.prototype.setAll.call(this, object, block); - - if (this.setValueStep(object.valueStep, block)) { - changed++; - } - - if (this.setMaxValue(object.maxValue, block)) { - changed++; - } - - if (this.setValue(object.value, block)) { - changed++; - } - - if (this.setBackgroundColor(object.backgroundColor, block)) { - changed++; - } - - if (this.setProgressColor(object.progressColor, block)) { - changed++; - } - - if (this.setDrawGraphicHandler(object.drawGraphicHandler, block)) { - changed++; - } - - if (this.setDrawTextHandler(object.drawTextHandler, block)) { + if (this.setLineWidth(object.lineWidth, block)) { changed++; } @@ -22037,26 +23191,26 @@ DKTools.Sprite.ProgressBar.prototype.setAll = function(object, blockStart, activ }; /** - * Changes the value step + * Changes the line width * Returns true if the change occurred * - * @param {Number} [step] - Шаг значения + * @param {Number} [width] - Line width * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.ProgressBar.prototype.setupValueStep - * @see DKTools.Sprite.ProgressBar.prototype.refreshAll + * @see DKTools.Sprite.ProgressBar.Circle.prototype.setupLineWidth + * @see DKTools.Sprite.ProgressBar.Circle.prototype.refreshAll * * @returns {Boolean} Change occurred */ -DKTools.Sprite.ProgressBar.prototype.setValueStep = function(step, blockRefreshAll) { - if (this._valueStep === step) { +DKTools.Sprite.ProgressBar.Circle.prototype.setLineWidth = function(width, blockRefreshAll) { + if (this._lineWidth === width) { return false; } - const lastStep = this._valueStep; - this.setupValueStep(step); + const lastWidth = this._lineWidth; + this.setupLineWidth(width); - if (this._valueStep === lastStep) { + if (this._lineWidth === lastWidth) { return false; } @@ -22067,123 +23221,289 @@ DKTools.Sprite.ProgressBar.prototype.setValueStep = function(step, blockRefreshA return true; }; + + + + +//=========================================================================== +// DKTools.Sprite.ProgressBar.SemiCircle +//=========================================================================== + +DKTools.Sprite.ProgressBar.SemiCircle.prototype = Object.create(DKTools.Sprite.ProgressBar.Circle.prototype); +DKTools.Sprite.ProgressBar.SemiCircle.prototype.constructor = DKTools.Sprite.ProgressBar.SemiCircle; + /** - * Changes the maximum value - * Returns true if the change occurred + * Returns the standard handler of draw of the graphic * - * @param {Number} [max] - Maximum value - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * @override + * @returns {Function} Standard handler of draw of the graphic + */ +DKTools.Sprite.ProgressBar.SemiCircle.prototype.standardDrawGraphicHandler = function() { + return function() { + const lineWidth = this._lineWidth; + const realWidth = this.realWidth; + const radius = (realWidth - lineWidth) / 2; + const x = radius + lineWidth / 2; + const y = this.realHeight; + + this.strokeArc({ + x, + y, + radius, + startAngle: Math.PI, + color: this._backgroundColor, + lineWidth + }); + + this.strokeArc({ + x, + y, + radius, + startAngle: Math.PI, + endAngle: -Math.PI + Math.PI * this._value / this._maxValue, + color: this._progressColor, + lineWidth + }); + }.bind(this); +}; + + + + + +//=========================================================================== +// DKTools.Sprite.CheckBox +//=========================================================================== + +DKTools.Sprite.CheckBox.prototype = Object.create(DKTools.Sprite.Button.prototype); +DKTools.Sprite.CheckBox.prototype.constructor = DKTools.Sprite.CheckBox; + +// properties + +Object.defineProperties(DKTools.Sprite.CheckBox.prototype, { + + /** + * Checked + * + * @readonly + * @type {Boolean} + * @memberof DKTools.Sprite.CheckBox.prototype + */ + checked: { + get: function() { + return this._checked; + }, + configurable: true + }, + + /** + * Checked graphic + * + * @readonly + * @type {Bitmap | String | Object} + * @memberof DKTools.Sprite.CheckBox.prototype + */ + checkedGraphic: { + get: function() { + return this._checkedGraphic; + }, + configurable: true + }, + + /** + * Unchecked graphic + * + * @readonly + * @type {Bitmap | String | Object} + * @memberof DKTools.Sprite.CheckBox.prototype + */ + uncheckedGraphic: { + get: function() { + return this._uncheckedGraphic; + }, + configurable: true + }, + +}); + +// standard methods + +/** + * Returns the stadnard checked * - * @see DKTools.Sprite.ProgressBar.prototype.setupMaxValue - * @see DKTools.Sprite.ProgressBar.prototype.refreshAll + * @returns {Boolean} Checked + */ +DKTools.Sprite.CheckBox.prototype.standardChecked = function() { + return false; +}; + +/** + * Returns the stadnard checked graphic * - * @returns {Boolean} Change occurred + * @returns {null} Checked graphic */ -DKTools.Sprite.ProgressBar.prototype.setMaxValue = function(max, blockRefreshAll) { - if (this._maxValue === max) { - return false; - } +DKTools.Sprite.CheckBox.prototype.standardCheckedGraphic = function() { + return null; +}; - const lastMax = this._maxValue; - this.setupMaxValue(max); +/** + * Returns the stadnard unchecked graphic + * + * @returns {null} Unchecked graphic + */ +DKTools.Sprite.CheckBox.prototype.standardUncheckedGraphic = function() { + return null; +}; - if (this._maxValue === lastMax) { - return false; - } +// setup methods - if (!blockRefreshAll) { - this.refreshAll(); - } +/** + * Sets all parameters + * + * @override + * + * @param {Object} [object={}] - Parameters + * + * @param {Boolean} [object.checked] - Checked + * @param {Bitmap | String | Object} [object.checkedGraphic] - Checked graphic + * @param {Bitmap | String | Object} [object.uncheckedGraphic] - Unchecked graphic + * + * @see DKTools.Sprite.Button.prototype.setupAll + * @see DKTools.Sprite.CheckBox.prototype.setupChecked + * @see DKTools.Sprite.CheckBox.prototype.setupCheckedGraphic + * @see DKTools.Sprite.CheckBox.prototype.setupUncheckedGraphic + */ +DKTools.Sprite.CheckBox.prototype.setupAll = function(object) { + DKTools.Sprite.Button.prototype.setupAll.call(this, object); + this.setupChecked(object.checked); + this.setupCheckedGraphic(object.checkedGraphic); + this.setupUncheckedGraphic(object.uncheckedGraphic); +}; - return true; +/** + * Sets the checked + * + * @param {Boolean} [checked=this.standardChecked()] - Checked + * + * @see DKTools.Sprite.CheckBox.prototype.standardChecked + */ +DKTools.Sprite.CheckBox.prototype.setupChecked = function(checked) { + /** + * @private + * @readonly + * @type {Boolean} + */ + this._checked = checked == null ? this.standardChecked() : checked; }; /** - * Changes the value - * Returns true if the change occurred - * - * @param {Number} [value] - Value - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * Sets the checked graphic * - * @see DKTools.Sprite.ProgressBar.prototype.setupValue - * @see DKTools.Sprite.ProgressBar.prototype.refreshAll - * @see DKTools.Sprite.ProgressBar.prototype.updateValueEvents + * @param {Bitmap | String | Object} [graphic=this.standardCheckedGraphic()] - Checked graphic * - * @returns {Boolean} Change occurred + * @see DKTools.Sprite.CheckBox.prototype.standardCheckedGraphic */ -DKTools.Sprite.ProgressBar.prototype.setValue = function(value, blockRefreshAll) { - if (this._value === value) { - return false; - } - - const lastValue = this._value; - this.setupValue(value); - - if (this._value === lastValue) { - return false; - } - - if (!blockRefreshAll) { - this.refreshAll(); - } - - this.updateValueEvents(); +DKTools.Sprite.CheckBox.prototype.setupCheckedGraphic = function(graphic) { + /** + * @private + * @readonly + * @type {Bitmap | String | Object} + */ + this._checkedGraphic = graphic || this.standardCheckedGraphic(); +}; - return true; +/** + * Sets the unchecked graphic + * + * @param {Bitmap | String | Object} [graphic=this.standardUncheckedGraphic()] - Unchecked graphic + * + * @see DKTools.Sprite.CheckBox.prototype.standardUncheckedGraphic + */ +DKTools.Sprite.CheckBox.prototype.setupUncheckedGraphic = function(graphic) { + /** + * @private + * @readonly + * @type {Bitmap | String | Object} + */ + this._uncheckedGraphic = graphic || this.standardUncheckedGraphic(); }; +// set methods + /** - * Changes the background color - * Returns true if the change occurred + * Changes all parameters + * Returns the number of changed parameters * - * @param {String} [color] - Background color - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * @override * - * @see DKTools.Sprite.ProgressBar.prototype.setupBackgroundColor - * @see DKTools.Sprite.ProgressBar.prototype.refreshAll + * @param {Object} [object={}] - Parameters + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [activate=false] - Activates the check box * - * @returns {Boolean} Change occurred + * @param {Boolean} [object.checked] - Checked + * @param {Bitmap | String | Object} [object.checkedGraphic] - Checked graphic + * @param {Bitmap | String | Object} [object.uncheckedGraphic] - Unchecked graphic + * + * @see DKTools.Sprite.Button.prototype.setAll + * @see DKTools.Sprite.CheckBox.prototype.setChecked + * @see DKTools.Sprite.CheckBox.prototype.setCheckedGraphic + * @see DKTools.Sprite.CheckBox.prototype.setUncheckedGraphic + * @see DKTools.Sprite.CheckBox.prototype.start + * @see DKTools.Sprite.CheckBox.prototype.activate + * + * @returns {Number} Number of changed parameters */ -DKTools.Sprite.ProgressBar.prototype.setBackgroundColor = function(color, blockRefreshAll) { - if (this._backgroundColor === color) { - return false; +DKTools.Sprite.CheckBox.prototype.setAll = function(object, blockStart, activate) { + object = object || {}; + const block = true; + let changed = DKTools.Sprite.Button.prototype.setAll.call(this, object, block); + + if (this.setChecked(object.checked, block)) { + changed++; } - const lastColor = this._backgroundColor; - this.setupBackgroundColor(color); + if (this.setCheckedGraphic(object.checkedGraphic, block)) { + changed++; + } - if (this._backgroundColor === lastColor) { - return false; + if (this.setUncheckedGraphic(object.uncheckedGraphic, block)) { + changed++; } - if (!blockRefreshAll) { - this.refreshAll(); + if (changed) { + if (!blockStart) { + this.start(); + } + + if (activate) { + this.activate(); + } } - return true; + return changed; }; /** - * Changes the progress color + * Changes the checked * Returns true if the change occurred * - * @param {String} [color] - Progress color - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * @param {Boolean} [checked] - + * @param {Boolean} [blockRefreshAll=false] - * - * @see DKTools.Sprite.ProgressBar.prototype.setupProgressColor - * @see DKTools.Sprite.ProgressBar.prototype.refreshAll + * @see DKTools.Sprite.CheckBox.prototype.setupChecked + * @see DKTools.Sprite.CheckBox.prototype.refreshAll * * @returns {Boolean} Change occurred */ -DKTools.Sprite.ProgressBar.prototype.setProgressColor = function(color, blockRefreshAll) { - if (this._progressColor === color) { +DKTools.Sprite.CheckBox.prototype.setChecked = function(checked, blockRefreshAll) { + if (this._checked === checked) { return false; } - const lastColor = this._progressColor; - this.setupProgressColor(color); + const lastChecked = this._checked; + this.setupChecked(checked); - if (this._progressColor === lastColor) { + if (this._checked === lastChecked) { return false; } @@ -22195,50 +23515,37 @@ DKTools.Sprite.ProgressBar.prototype.setProgressColor = function(color, blockRef }; /** - * Changes the handler of draw of the graphic + * Changes the checked graphic * Returns true if the change occurred * - * @param {Function} [handler] - Handler of draw of the graphic + * @param {Bitmap | String | Object} [graphic] - Checked graphic * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.ProgressBar.prototype.setupDrawGraphicHandler - * @see DKTools.Sprite.ProgressBar.prototype.refreshAll + * @see DKTools.Sprite.CheckBox.prototype.setupCheckedGraphic + * @see DKTools.Sprite.CheckBox.prototype.refreshAll * * @returns {Boolean} Change occurred */ -DKTools.Sprite.ProgressBar.prototype.setDrawGraphicHandler = function(handler, blockRefreshAll) { - if (this._drawGraphicHandler === handler) { - return false; - } - - this.setupDrawGraphicHandler(handler); +DKTools.Sprite.CheckBox.prototype.setCheckedGraphic = function(graphic, blockRefreshAll) { + const checkedGraphic = this._checkedGraphic; - if (!blockRefreshAll) { - this.refreshAll(); + if (checkedGraphic == graphic) { + return false; } - return true; -}; + if (checkedGraphic instanceof Bitmap) { + this.setupCheckedGraphic(graphic); + } else if (DKTools.Utils.isString(checkedGraphic) || checkedGraphic instanceof Object) { + const lastGraphic = checkedGraphic; + this.setupCheckedGraphic(graphic); -/** - * Changes the handler of draw of the text - * Returns true if the change occurred - * - * @param {Function} [handler] - Handler of draw of the text - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.ProgressBar.prototype.setupDrawTextHandler - * @see DKTools.Sprite.ProgressBar.prototype.refreshAll - * - * @returns {Boolean} Change occurred - */ -DKTools.Sprite.ProgressBar.prototype.setDrawTextHandler = function(handler, blockRefreshAll) { - if (this._drawTextHandler === handler) { + if (_.isEqual(this._checkedGraphic, lastGraphic)) { + return false; + } + } else { return false; } - this.setupDrawTextHandler(handler); - if (!blockRefreshAll) { this.refreshAll(); } @@ -22246,440 +23553,398 @@ DKTools.Sprite.ProgressBar.prototype.setDrawTextHandler = function(handler, bloc return true; }; -// can methods - -/** - * Returns true if the progress bar can clone the fixed bitmap - * - * @override - * @returns {Boolean} Progress bar can clone the fixed bitmap - */ -DKTools.Sprite.ProgressBar.prototype.canCloneFixedBitmap = function() { - return false; -}; - -// is methods - -/** - * Returns true if the progress bar is horizontal - * - * @returns {Boolean} Progress bar is horizontal - */ -DKTools.Sprite.ProgressBar.prototype.isHorizontal = function() { - return this.width > this.height; -}; - -/** - * Returns true if the progress bar is vertical - * - * @see DKTools.Sprite.ProgressBar.prototype.isHorizontal - * - * @returns {Boolean} Progress bar is vertical - */ -DKTools.Sprite.ProgressBar.prototype.isVertical = function() { - return !this.isHorizontal(); -}; - -/** - * Returns true if the progress bar is empty - * - * @returns {Boolean} Progress bar is empty - */ -DKTools.Sprite.ProgressBar.prototype.isEmpty = function() { - return this._value === 0; -}; - -/** - * Returns true if the progress bar is full - * - * @returns {Boolean} Progress bar is full - */ -DKTools.Sprite.ProgressBar.prototype.isFull = function() { - return this._value === this._maxValue; -}; - -// events methods - -/** - * Updates the events - * - * @override - * - * @see DKTools.Sprite.prototype.updateEvents - * @see DKTools.Sprite.ProgressBar.prototype.updateEmptyEvents - * @see DKTools.Sprite.ProgressBar.prototype.updateFullEvents - */ -DKTools.Sprite.ProgressBar.prototype.updateEvents = function() { - DKTools.Sprite.prototype.updateEvents.call(this); - this.updateEmptyEvents(); - this.updateFullEvents(); -}; - -/** - * Updates the events with type: value - * - * @see DKTools.Sprite.ProgressBar.prototype.updateEventsContainer - */ -DKTools.Sprite.ProgressBar.prototype.updateValueEvents = function() { - this.updateEventsContainer('value'); -}; - -/** - * Updates the events with type: empty - * - * @see DKTools.Sprite.ProgressBar.prototype.isEmpty - * @see DKTools.Sprite.ProgressBar.prototype.updateEventsContainer - */ -DKTools.Sprite.ProgressBar.prototype.updateEmptyEvents = function() { - if (this.isEmpty()) { - this.updateEventsContainer('empty'); - } -}; - /** - * Updates the events with type: full + * Changes the unchecked graphic + * Returns true if the change occurred * - * @see DKTools.Sprite.ProgressBar.prototype.isFull - * @see DKTools.Sprite.ProgressBar.prototype.updateEventsContainer + * @param {Bitmap | String | Object} [graphic] - Unchecked graphic + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.CheckBox.prototype.setupUncheckedGraphic + * @see DKTools.Sprite.CheckBox.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.ProgressBar.prototype.updateFullEvents = function() { - if (this.isFull()) { - this.updateEventsContainer('full'); +DKTools.Sprite.CheckBox.prototype.setUncheckedGraphic = function(graphic, blockRefreshAll) { + const uncheckedGraphic = this._uncheckedGraphic; + + if (uncheckedGraphic == graphic) { + return false; + } + + if (uncheckedGraphic instanceof Bitmap) { + this.setupUncheckedGraphic(graphic); + } else if (DKTools.Utils.isString(uncheckedGraphic) || uncheckedGraphic instanceof Object) { + const lastGraphic = uncheckedGraphic; + this.setupUncheckedGraphic(graphic); + + if (_.isEqual(this._uncheckedGraphic, lastGraphic)) { + return false; + } + } else { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); } + + return true; }; +// _refresh methods + /** - * Handler of update of animate the value - * + * Refreshes the checked graphic + * * @private - * - * @param {Number} value - Value - * @param {DKTools.Event} event - Event - * - * @see DKTools.Sprite.ProgressBar.prototype.setValue + * + * @see DKTools.Sprite.CheckBox.prototype.loadBitmap */ -DKTools.Sprite.ProgressBar.prototype._updateAnimateValue = function(value, event) { - const remainingTime = event.remainingTime; - const newValue = (this._value * (remainingTime - 1) + value) / remainingTime; +DKTools.Sprite.CheckBox.prototype._refreshCheckedGraphic = function() { + let bitmapObject = null; - this.setValue(newValue); + if (DKTools.Utils.isString(this._checkedGraphic)) { + bitmapObject = { + folder: this._graphicFolder, + filename: this._checkedGraphic + }; + } else if (this._checkedGraphic instanceof Object) { + bitmapObject = this._checkedGraphic; + } + + if (bitmapObject) { + this.loadBitmap(bitmapObject); + } }; /** - * Animates the value - * Returns the update event - * - * @param {Number} value - Value - * @param {Number} duration - Duration of animation - * - * @see DKTools.Sprite.ProgressBar.prototype.addEvent - * @see DKTools.Sprite.ProgressBar.prototype._updateAnimateValue - * - * @returns {DKTools.Event} Update event + * Refreshes the unchecked graphic + * + * @private + * + * @see DKTools.Sprite.CheckBox.prototype.loadBitmap */ -DKTools.Sprite.ProgressBar.prototype.animateValue = function(value, duration) { - return this.addEvent({ - type: 'update', - repeatTime: duration, - repeats: 0, - onUpdate: this._updateAnimateValue.bind(this, value) - }); +DKTools.Sprite.CheckBox.prototype._refreshUncheckedGraphic = function() { + let bitmapObject = null; + + if (DKTools.Utils.isString(this._uncheckedGraphic)) { + bitmapObject = { + folder: this._graphicFolder, + filename: this._uncheckedGraphic + }; + } else if (this._uncheckedGraphic instanceof Object) { + bitmapObject = this._uncheckedGraphic; + } + + if (bitmapObject) { + this.loadBitmap(bitmapObject); + } }; /** - * Animates the empty value - * Returns the update event - * - * @param {Number} duration - Duration of animation - * - * @see DKTools.Sprite.ProgressBar.prototype.animateValue - * - * @returns {DKTools.Event} Update event + * Refreshes graphic + * + * @private + * + * @see DKTools.Sprite.CheckBox.prototype.isChecked + * @see DKTools.Sprite.CheckBox.prototype._refreshCheckedGraphic + * @see DKTools.Sprite.CheckBox.prototype._refreshUncheckedGraphic */ -DKTools.Sprite.ProgressBar.prototype.animateEmpty = function(duration) { - return this.animateValue(0, duration); +DKTools.Sprite.CheckBox.prototype._refreshGraphic = function() { + if (this.isChecked()) { + this._refreshCheckedGraphic(); + } else { + this._refreshUncheckedGraphic(); + } }; +// refresh methods + /** - * Animates the full value - * Returns the update event - * - * @param {Number} duration - Duration of animation - * - * @see DKTools.Sprite.ProgressBar.prototype.animateValue + * Updates and redraws all * - * @returns {DKTools.Event} Update event + * @override + * + * @see DKTools.Sprite.CheckBox.prototype._refreshGraphic + * @see DKTools.Sprite.Button.prototype.refreshAll */ -DKTools.Sprite.ProgressBar.prototype.aimateFull = function(duration) { - return this.animateValue(this._maxValue, duration); +DKTools.Sprite.CheckBox.prototype.refreshAll = function() { + this._refreshGraphic(); + DKTools.Sprite.Button.prototype.refreshAll.call(this); }; -// _draw methods +// is methods /** - * Draws the graphic of progress - * - * @private - * - * @see DKTools.Sprite.ProgressBar.prototype.hasDrawGraphicHandler + * Returns true if the checkbox is checked + * + * @returns {Boolean} Checkbox is checked */ -DKTools.Sprite.ProgressBar.prototype._drawProgressGraphic = function() { - if (this.hasDrawGraphicHandler()) { - this._drawGraphicHandler(this); - } +DKTools.Sprite.CheckBox.prototype.isChecked = function() { + return this._checked; }; +// event methods + /** - * Draws the text of progress + * Updates the events with type: mouse-click-button * - * @private + * @param {String} button - Mouse button * - * @see DKTools.Sprite.ProgressBar.prototype.hasDrawTextHandler + * @see DKTools.Sprite.CheckBox.prototype.switch + * @see DKTools.Sprite.Button.prototype.updateMouseClickEvents */ -DKTools.Sprite.ProgressBar.prototype._drawProgressText = function() { - if (this.hasDrawTextHandler()) { - this._drawTextHandler(this); - } +DKTools.Sprite.CheckBox.prototype.updateMouseClickEvents = function(button) { + this.switch(); + DKTools.Sprite.Button.prototype.updateMouseClickEvents.call(this, button); }; -// draw methods - /** - * Draws all + * Updates the events with type: checked * - * @override + * @see DKTools.Sprite.CheckBox.prototype.updateEventsContainer */ -DKTools.Sprite.ProgressBar.prototype.drawAll = function() { - DKTools.Sprite.prototype.drawAll.call(this); - this.drawProgress(); +DKTools.Sprite.CheckBox.prototype.updateCheckedEvents = function() { + this.updateEventsContainer('checked'); }; /** - * Draws the progress + * Updates the events with type: unchecked * - * @see DKTools.Sprite.ProgressBar.prototype._drawProgressGraphic - * @see DKTools.Sprite.ProgressBar.prototype._drawProgressText + * @see DKTools.Sprite.CheckBox.prototype.updateEventsContainer */ -DKTools.Sprite.ProgressBar.prototype.drawProgress = function() { - this._drawProgressGraphic(); - this._drawProgressText(); +DKTools.Sprite.CheckBox.prototype.updateUncheckedEvents = function() { + this.updateEventsContainer('unchecked'); }; -// has methods +// other methods /** - * Returns true if the progress bar has the handler of draw of the graphic + * Switches the checkbox * - * @returns {Boolean} Progress bar has the handler of draw of the graphic + * @see DKTools.Sprite.CheckBox.prototype.isChecked + * @see DKTools.Sprite.CheckBox.prototype.setChecked */ -DKTools.Sprite.ProgressBar.prototype.hasDrawGraphicHandler = function() { - return !!this._drawGraphicHandler; +DKTools.Sprite.CheckBox.prototype.switch = function() { + this.setChecked(!this.isChecked()); }; /** - * Returns true if the progress bar has the handler of draw of the text + * Checks the checkbox * - * @returns {Boolean} Progress bar has the handler of draw of the text + * @see DKTools.Sprite.CheckBox.prototype.isChecked + * @see DKTools.Sprite.CheckBox.prototype.switch + * @see DKTools.Sprite.CheckBox.prototype.updateCheckedEvents */ -DKTools.Sprite.ProgressBar.prototype.hasDrawTextHandler = function() { - return !!this._drawTextHandler; +DKTools.Sprite.CheckBox.prototype.check = function() { + if (!this.isChecked()) { + this.switch(); + this.updateCheckedEvents(); + } }; -// get methods - /** - * Returns the current value in percent + * Unchecks the checkbox * - * @returns {Number} Current value in percent + * @see DKTools.Sprite.CheckBox.prototype.isChecked + * @see DKTools.Sprite.CheckBox.prototype.switch + * @see DKTools.Sprite.CheckBox.prototype.updateUncheckedEvents */ -DKTools.Sprite.ProgressBar.prototype.getPercents = function() { - return Math.ceil(this._value / this._maxValue * 100); +DKTools.Sprite.CheckBox.prototype.uncheck = function() { + if (this.isChecked()) { + this.switch(); + this.updateUncheckedEvents(); + } }; -/** - * Returns the previous value - * - * @returns {Number} Previous value - */ -DKTools.Sprite.ProgressBar.prototype.getPrevValue = function() { - return Math.max(0, this._value - this._valueStep); -}; + + + + +//=========================================================================== +// DKTools.Viewport +//=========================================================================== + +DKTools.Viewport.prototype = Object.create(DKTools.Sprite.prototype); +DKTools.Viewport.prototype.constructor = DKTools.Viewport; + +// properties + +Object.defineProperties(DKTools.Viewport.prototype, { + + /** + * Shape of the mask + * + * @readonly + * @type {PIXI.Graphics} + * @memberof DKTools.Viewport.prototype + */ + maskShape: { + get: function() { + return this._maskShape; + }, + configurable: true + } + +}); + +// standard methods /** - * Returns the next value + * Returns the standard mask shape * - * @returns {Number} Next value + * @returns {String} Standard mask shape */ -DKTools.Sprite.ProgressBar.prototype.getNextValue = function() { - return Math.min(this._value + this._valueStep, this._maxValue); +DKTools.Viewport.prototype.standardMaskShape = function() { + return 'rect'; }; -// value methods +// setup methods /** - * Adds the value + * Sets all parameters * - * @param {Number} value - Value + * @override * - * @see DKTools.Sprite.ProgressBar.prototype.setValue - */ -DKTools.Sprite.ProgressBar.prototype.addValue = function(value) { - if (value) { - this.setValue(this._value + value); - } -}; - -/** - * Subtracts the value + * @param {Object} [object={}] - Parameters * - * @param {Number} value - Value + * @param {String} [object.maskShape] - Shape of the mask * - * @see DKTools.Sprite.ProgressBar.prototype.addValue + * @see DKTools.Sprite.prototype.setupAll + * @see DKTools.Viewport.prototype.setupMaskShape */ -DKTools.Sprite.ProgressBar.prototype.subValue = function(value) { - this.addValue(-value); +DKTools.Viewport.prototype.setupAll = function(object) { + object = object || {}; + DKTools.Sprite.prototype.setupAll.call(this, object); + this.setupMaskShape(object.maskShape); }; /** - * Sets the previous value - * Returns true if the change occurred - * - * @see DKTools.Sprite.ProgressBar.prototype.getPrevValue - * @see DKTools.Sprite.ProgressBar.prototype.setValue + * Sets the shape of the mask * - * @returns {Boolean} Change occurred + * @param {String} [shape] - Shape of the mask + * + * @see DKTools.Viewport.prototype.standardMaskShape */ -DKTools.Sprite.ProgressBar.prototype.prevValue = function() { - return this.setValue(this.getPrevValue()); +DKTools.Viewport.prototype.setupMaskShape = function(shape) { + /** + * @private + * @readonly + * @type {String} + */ + this._maskShape = shape || this.standardMaskShape(); }; +// set methods + /** - * Sets the next value - * Returns true if the change occurred + * Changes all parameters + * Returns the number of changed parameters * - * @see DKTools.Sprite.ProgressBar.prototype.getNextValue - * @see DKTools.Sprite.ProgressBar.prototype.setValue + * @override * - * @returns {Boolean} Change occurred - */ -DKTools.Sprite.ProgressBar.prototype.nextValue = function() { - return this.setValue(this.getNextValue()); -}; - -/** - * Makes the progress bar empty + * @param {Object} [object={}] - Parameters + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [activate=false] - Activates the object * - * @see DKTools.Sprite.ProgressBar.prototype.setValue - */ -DKTools.Sprite.ProgressBar.prototype.makeEmpty = function() { - this.setValue(0); -}; - -/** - * Makes the progress bar full + * @param {String} [object.maskShape] - Shape of the mask * - * @see DKTools.Sprite.ProgressBar.prototype.setValue + * @see DKTools.Sprite.prototype.setAll + * @see DKTools.Viewport.prototype.setMaskShape + * @see DKTools.Viewport.prototype.start + * @see DKTools.Viewport.prototype.activate + * + * @returns {Number} Number of changed parameters */ -DKTools.Sprite.ProgressBar.prototype.makeFull = function() { - this.setValue(this._maxValue); -}; - - +DKTools.Viewport.prototype.setAll = function(object, blockStart, activate) { + object = object || {}; + const block = true; + let changed = DKTools.Sprite.prototype.setAll.call(this, object, block); + if (this.setMaskShape(object.maskShape, block)) { + changed++; + } -//=========================================================================== -// DKTools.Sprite.ProgressBar.Rectangle -//=========================================================================== + if (changed) { + if (!blockStart) { + this.start(); + } -DKTools.Sprite.ProgressBar.Rectangle.prototype = Object.create(DKTools.Sprite.ProgressBar.prototype); -DKTools.Sprite.ProgressBar.Rectangle.prototype.constructor = DKTools.Sprite.ProgressBar.Rectangle; + if (activate) { + this.activate(); + } + } -// standard methods + return changed; +}; /** - * Returns the standard handler of draw of the graphic for horizontal progress bar + * Changes the shape of the mask + * Returns true if the change occurred * - * @returns {Function} Standard handler of draw of the graphic for horizontal progress bar + * @param {String} [shape] - Shape of the mask + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.ProgressBar.Rectangle.prototype.standardHorizontalDrawGraphicHandler = function() { - return function() { - this.fillAll(this._backgroundColor); +DKTools.Viewport.prototype.setMaskShape = function(shape, blockStart) { + if (this._maskShape === shape) { + return false; + } - if (!this.isEmpty()) { - this.fillRect({ - color: this._progressColor, - width: this._value * this.realWidth / this._maxValue - }); - } - }.bind(this); -}; + const lastShape = this._maskShape; + this.setupShape(shape); -/** - * Returns the standard handler of draw of the graphic for vertical progress bar - * - * @returns {Function} Standard handler of draw of the graphic for vertical progress bar - */ -DKTools.Sprite.ProgressBar.Rectangle.prototype.standardVerticalDrawGraphicHandler = function() { - return function() { - this.fillAll(this._backgroundColor); + if (this._maskShape === lastShape) { + return false; + } - if (!this.isEmpty()) { - const realHeight = this.realHeight; - const height = this._value * realHeight / this._maxValue; + if (!blockStart) { + this.start(); + } - this.fillRect({ - color: this._progressColor, - y: realHeight - height, - width: this.realWidth, - height - }); - } - }.bind(this); + return true; }; +// create methods + /** - * Returns the standard handler of draw of the graphic + * Creates all objects * * @override - * - * @see DKTools.Sprite.ProgressBar.Rectangle.prototype.isHorizontal - * @see DKTools.Sprite.ProgressBar.Rectangle.prototype.standardHorizontalDrawGraphicHandler - * @see DKTools.Sprite.ProgressBar.Rectangle.prototype.standardVerticalDrawGraphicHandler - * - * @returns {Function} Standard handler of draw of the graphic + * + * @see DKTools.Sprite.prototype.createAll + * @see DKTools.Viewport.prototype.createMask */ -DKTools.Sprite.ProgressBar.Rectangle.prototype.standardDrawGraphicHandler = function() { - return function(progressBar) { - let handler; - - if (this.isHorizontal()) { - handler = this.standardHorizontalDrawGraphicHandler(); - } else { - handler = this.standardVerticalDrawGraphicHandler(); - } +DKTools.Viewport.prototype.createAll = function() { + DKTools.Sprite.prototype.createAll.call(this); + this.createMask(); +}; - if (handler) { - handler(progressBar); - } - }.bind(this); +/** + * Creates a mask + * + * @version 2.0.0 + * @override + * + * @see DKTools.Sprite.prototype.createMask + */ +DKTools.Viewport.prototype.createMask = function() { + DKTools.Sprite.prototype.createMask.call(this, this._maskShape); }; +// can methods + /** - * Returns the standard handler of draw of the text + * Returns true if the viewport can clone the fixed bitmap * * @override - * @returns {Function} Standard handler of draw of the text + * @returns {Boolean} Viewport can clone the fixed bitmap */ -DKTools.Sprite.ProgressBar.Rectangle.prototype.standardDrawTextHandler = function() { - return function() { - const percents = this.getPercents(); - const text = `${percents}%`; - - this.drawText(text, { - height: this.realHeight - }); - }.bind(this); +DKTools.Viewport.prototype.canCloneFixedBitmap = function() { + return false; }; @@ -22687,400 +23952,405 @@ DKTools.Sprite.ProgressBar.Rectangle.prototype.standardDrawTextHandler = functio //=========================================================================== -// DKTools.Sprite.ProgressBar.Circle +// DKTools.Layout //=========================================================================== -DKTools.Sprite.ProgressBar.Circle.prototype = Object.create(DKTools.Sprite.ProgressBar.prototype); -DKTools.Sprite.ProgressBar.Circle.prototype.constructor = DKTools.Sprite.ProgressBar.Circle; +DKTools.Layout.prototype = Object.create(DKTools.Sprite.prototype); +DKTools.Layout.prototype.constructor = DKTools.Layout; + +// properties + +Object.defineProperties(DKTools.Layout.prototype, { + + /** + * Number of the columns + * + * @readonly + * @type {Number} + * @memberof DKTools.Layout.prototype + */ + maxCols: { + get: function() { + return this._maxCols; + }, + configurable: true + }, + + /** + * Items + * + * @readonly + * @type {DKTools.Sprite[] | *} + * @memberof DKTools.Layout.prototype + */ + items: { + get: function() { + return this._items; + }, + configurable: true + }, + + /** + * Height of the row + * + * @readonly + * @type {Function | Number} + * @memberof DKTools.Layout.prototype + */ + rowHeight: { + get: function() { + return this._rowHeight; + }, + configurable: true + }, -// properties + /** + * Width of the column + * + * @readonly + * @type {Function | Number} + * @memberof DKTools.Layout.prototype + */ + colWidth: { + get: function() { + return this._colWidth; + }, + configurable: true + }, -Object.defineProperties(DKTools.Sprite.ProgressBar.Circle.prototype, { + /** + * Horizontal spacing + * + * @readonly + * @type {Number} + * @memberof DKTools.Layout.prototype + */ + horizontalSpacing: { + get: function() { + return this._horizontalSpacing; + }, + configurable: true + }, /** - * Line width + * Vertical spacing * * @readonly * @type {Number} - * @memberOf DKTools.Sprite.ProgressBar.Circle.prototype + * @memberof DKTools.Layout.prototype */ - lineWidth: { + verticalSpacing: { get: function() { - return this._lineWidth; + return this._verticalSpacing; + }, + configurable: true + }, + + /** + * Value of the invert + * + * @readonly + * @type {Boolean} + * @memberof DKTools.Layout.prototype + */ + inverted: { + get: function() { + return this._inverted; }, configurable: true } }); -// standard methods +// _clear methods /** - * Returns the standard handler of draw of the graphic + * Clears all data * + * @private * @override - * @returns {Function} Standard handler of draw of the graphic + * + * @see DKTools.Sprite.prototype._clearAll + * @see DKTools.Layout.prototype._clearItems */ -DKTools.Sprite.ProgressBar.Circle.prototype.standardDrawGraphicHandler = function() { - return function() { - const lineWidth = this._lineWidth; - const realWidth = this.realWidth; - const radius = (realWidth - lineWidth) / 2; - const x = radius + lineWidth / 2; - const y = x; - - this.strokeArc({ - radius, - color: this._backgroundColor, - lineWidth, - x, - y - }); - - this.strokeArc({ - radius, - startAngle: -Math.PI / 2, - endAngle: -Math.PI / 2 + Math.PI * 2 * this._value / this._maxValue, - color: this._progressColor, - lineWidth, - x, - y - }); - }.bind(this); +DKTools.Layout.prototype._clearAll = function() { + DKTools.Sprite.prototype._clearAll.call(this); + this._clearItems(); }; /** - * Returns the standard handler of draw of the text + * Clears items * - * @override - * @returns {Function} Standard handler of draw of the text + * @private */ -DKTools.Sprite.ProgressBar.Circle.prototype.standardDrawTextHandler = function() { - return function() { - const percents = this.getPercents(); - const text = `${percents}%`; - this.drawText(text, { height: this.realHeight }); - }.bind(this); +DKTools.Layout.prototype._clearItems = function() { + /** + * @private + * @readonly + * @type {Array} + */ + this._items = []; }; +// clear methods + /** - * Returns the standard line width + * Clears items * - * @returns {Number} Standard line width + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * + * @see DKTools.Layout.prototype.removeAllItems + * @see DKTools.Layout.prototype._clearItems + * @see DKTools.Layout.prototype.start */ -DKTools.Sprite.ProgressBar.Circle.prototype.standardLineWidth = function() { - return 10; +DKTools.Layout.prototype.clearItems = function(blockStart) { + this.removeAllItems(); + this._clearItems(); + + if (!blockStart) { + this.start(); + } }; -// setup methods +// standard methods /** - * Sets all parameters + * Returns the standard activity of the layout * * @override - * - * @param {Object} [object={}] - Parameters - * - * @param {Number} [object.lineWidth] - Line width - * - * @see DKTools.Sprite.ProgressBar.prototype.setupAll - * @see DKTools.Sprite.ProgressBar.Circle.prototype.setupLineWidth + * @returns {Boolean} Standard activity of the layout */ -DKTools.Sprite.ProgressBar.Circle.prototype.setupAll = function(object) { - object = object || {}; - DKTools.Sprite.ProgressBar.prototype.setupAll.call(this, object); - this.setupLineWidth(object.lineWidth); +DKTools.Layout.prototype.standardActive = function() { + return false; }; /** - * Sets the line width - * - * @param {Number} [width=this.standardLineWidth()] - Line width + * Returns the standard number of the columns * - * @see DKTools.Sprite.ProgressBar.Circle.prototype.standardLineWidth + * @returns {Number} Standard number of columns */ -DKTools.Sprite.ProgressBar.Circle.prototype.setupLineWidth = function(width) { - /** - * @private - * @readonly - * @type {Number} - */ - this._lineWidth = width || this.standardLineWidth(); +DKTools.Layout.prototype.standardMaxCols = function() { + return 1; }; -// set methods - /** - * Changes all parameters - * Returns the number of changed parameters - * - * @override - * - * @param {Object} [object={}] - Parameters - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * @param {Boolean} [activate=false] - Activates the progress bar - * - * @param {Number} [object.lineWidth] - Line width - * - * @see DKTools.Sprite.ProgressBar.prototype.setAll - * @see DKTools.Sprite.ProgressBar.Circle.prototype.setLineWidth - * DKTools.Sprite.ProgressBar.Circle.prototype.start - * DKTools.Sprite.ProgressBar.Circle.prototype.activate + * Returns the standard horizontal spacing * - * @returns {Number} Number of changed parameters + * @returns {Number} Standard horizontal spacing */ -DKTools.Sprite.ProgressBar.Circle.prototype.setAll = function(object, blockStart, activate) { - object = object || {}; - const block = true; - let changed = DKTools.Sprite.ProgressBar.prototype.setAll.call(this, object, block); - - if (this.setLineWidth(object.lineWidth, block)) { - changed++; - } - - if (changed) { - if (!blockStart) { - this.start(); - } - - if (activate) { - this.activate(); - } - } - - return changed; +DKTools.Layout.prototype.standardHorizontalSpacing = function() { + return 12; }; /** - * Changes the line width - * Returns true if the change occurred - * - * @param {Number} [width] - Line width - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.ProgressBar.Circle.prototype.setupLineWidth - * @see DKTools.Sprite.ProgressBar.Circle.prototype.refreshAll + * Returns the standard vertical spacing * - * @returns {Boolean} Change occurred + * @returns {Number} Standard vertical spacing */ -DKTools.Sprite.ProgressBar.Circle.prototype.setLineWidth = function(width, blockRefreshAll) { - if (this._lineWidth === width) { - return false; - } - - const lastWidth = this._lineWidth; - this.setupLineWidth(width); - - if (this._lineWidth === lastWidth) { - return false; - } - - if (!blockRefreshAll) { - this.refreshAll(); - } - - return true; +DKTools.Layout.prototype.standardVerticalSpacing = function() { + return this.getLineHeight() / 2; }; - - - - -//=========================================================================== -// DKTools.Sprite.ProgressBar.SemiCircle -//=========================================================================== - -DKTools.Sprite.ProgressBar.SemiCircle.prototype = Object.create(DKTools.Sprite.ProgressBar.Circle.prototype); -DKTools.Sprite.ProgressBar.SemiCircle.prototype.constructor = DKTools.Sprite.ProgressBar.SemiCircle; +/** + * Returns the standard list of the items + * + * @returns {Array} Standard list of the items + */ +DKTools.Layout.prototype.standardItems = function() { + return []; +}; /** - * Returns the standard handler of draw of the graphic + * Returns the standard height of the row * - * @override - * @returns {Function} Standard handler of draw of the graphic + * @returns {Function} Standard height of the row */ -DKTools.Sprite.ProgressBar.SemiCircle.prototype.standardDrawGraphicHandler = function() { - return function() { - const lineWidth = this._lineWidth; - const realWidth = this.realWidth; - const radius = (realWidth - lineWidth) / 2; - const x = radius + lineWidth / 2; - const y = this.realHeight; - - this.strokeArc({ - radius, - startAngle: Math.PI, - color: this._backgroundColor, - lineWidth, - x, - y - }); - - this.strokeArc({ - radius, - startAngle: Math.PI, - endAngle: -Math.PI + Math.PI * this._value / this._maxValue, - color: this._progressColor, - lineWidth, - x, - y - }); +DKTools.Layout.prototype.standardRowHeight = function() { + return function(row) { + const items = this.getItemsInRow(row); + return _.max(_.map(items, 'height')); }.bind(this); }; +/** + * Returns the standard width of the column + * + * @returns {Function} Standard width of the column + */ +DKTools.Layout.prototype.standardColWidth = function() { + return function(col) { + const items = this.getItemsInCol(col); + return _.max(_.map(items, 'width')); + }.bind(this); +}; +/** + * Returns the standard value of the invert + * + * @returns {Boolean} Standard value of the invert + */ +DKTools.Layout.prototype.standardInverted = function() { + return false; +}; +// setup methods +/** + * Sets all parameters + * + * @override + * + * @param {Object} [object={}] - Parameters + * + * @param {Number} [object.maxCols] - Columns + * @param {Number} [object.horizontalSpacing] - Horizontal spacing + * @param {Number} [object.verticalSpacing] - Vertical spacing + * @param {Array} [object.items] - Items + * @param {Function | Number} [object.rowHeight] - Height of the row + * @param {Function | Number} [object.colWidth] - Width of the column + * @param {Boolean} [object.inverted] - Value of the invert + * + * @see DKTools.Sprite.prototype.setupAll + * @see DKTools.Layout.prototype.setupMaxCols + * @see DKTools.Layout.prototype.setupSpacing + * @see DKTools.Layout.prototype.setupItems + * @see DKTools.Layout.prototype.setupRowHeight + * @see DKTools.Layout.prototype.setupColWidth + * @see DKTools.Layout.prototype.setupInverted + */ +DKTools.Layout.prototype.setupAll = function(object) { + object = object || {}; + DKTools.Sprite.prototype.setupAll.call(this, object); + this.setupMaxCols(object.maxCols); + this.setupSpacing(object.horizontalSpacing, object.verticalSpacing); + this.setupItems(object.items); + this.setupRowHeight(object.rowHeight); + this.setupColWidth(object.colWidth); + this.setupInverted(object.inverted); +}; -//=========================================================================== -// DKTools.Sprite.CheckBox -//=========================================================================== - -DKTools.Sprite.CheckBox.prototype = Object.create(DKTools.Sprite.Button.prototype); -DKTools.Sprite.CheckBox.prototype.constructor = DKTools.Sprite.CheckBox; - -// properties - -Object.defineProperties(DKTools.Sprite.CheckBox.prototype, { - - /** - * @readonly - * @type {Boolean} - * @memberOf DKTools.Sprite.CheckBox.prototype - */ - checked: { - get: function() { - return this._checked; - }, - configurable: true - }, - - /** - * @readonly - * @type {Bitmap | String | Object} - * @memberOf DKTools.Sprite.CheckBox.prototype - */ - checkedGraphic: { - get: function() { - return this._checkedGraphic; - }, - configurable: true - }, - +/** + * Sets the number of the columns + * + * @param {Number} [cols=this.standardMaxCols()] - Columns + * + * @see DKTools.Layout.prototype.standardMaxCols + */ +DKTools.Layout.prototype.setupMaxCols = function(cols) { /** + * @private * @readonly - * @type {Bitmap | String | Object} - * @memberOf DKTools.Sprite.CheckBox.prototype + * @type {Number} */ - uncheckedGraphic: { - get: function() { - return this._uncheckedGraphic; - }, - configurable: true - }, - -}); - -// standard methods + this._maxCols = (cols == null ? this.standardMaxCols() : cols); +}; /** - * Returns the stadnard + * Sets the horizontal spacing * - * @returns {Boolean} + * @param {Number} [spacing=this.standardHorizontalSpacing()] - Horizontal spacing + * + * @see DKTools.Layout.prototype.standardHorizontalSpacing */ -DKTools.Sprite.CheckBox.prototype.standardChecked = function() { - return false; +DKTools.Layout.prototype.setupHorizontalSpacing = function(spacing) { + /** + * @private + * @readonly + * @type {Number} + */ + this._horizontalSpacing = (spacing == null ? this.standardHorizontalSpacing() : spacing); }; /** - * Returns the stadnard + * Sets the vertical spacing * - * @returns {null} + * @param {Number} [spacing=this.standardVerticalSpacing()] - Vertical spacing + * + * @see DKTools.Layout.prototype.standardVerticalSpacing */ -DKTools.Sprite.CheckBox.prototype.standardCheckedGraphic = function() { - return null; +DKTools.Layout.prototype.setupVerticalSpacing = function(spacing) { + /** + * @private + * @readonly + * @type {Number} + */ + this._verticalSpacing = (spacing == null ? this.standardVerticalSpacing() : spacing); }; /** - * Returns the stadnard + * Sets the horizontal and vertical spacing + * + * @param {Number} [horizontalSpacing] - Horizontal spacing + * @param {Number} [verticalSpacing] - Vertical spacing * - * @returns {null} + * @see DKTools.Layout.prototype.setupHorizontalSpacing + * @see DKTools.Layout.prototype.setupVerticalSpacing */ -DKTools.Sprite.CheckBox.prototype.standardUncheckedGraphic = function() { - return null; +DKTools.Layout.prototype.setupSpacing = function(horizontalSpacing, verticalSpacing) { + this.setupHorizontalSpacing(horizontalSpacing); + this.setupVerticalSpacing(verticalSpacing); }; -// setup methods - /** - * Sets all parameters - * - * @override - * - * @param {Object} [object={}] - Parameters + * Sets the items * - * @param {Boolean} [object.checked] - - * @param {Bitmap | String | Object} [object.checkedGraphic] - - * @param {Bitmap | String | Object} [object.uncheckedGraphic] - + * @param {DKTools.Sprite[] | *} [items=this.standardItems()] - Items * - * @see DKTools.Sprite.Button.prototype.setupAll - * @see DKTools.Sprite.CheckBox.prototype.setupChecked - * @see DKTools.Sprite.CheckBox.prototype.setupCheckedGraphic - * @see DKTools.Sprite.CheckBox.prototype.setupUncheckedGraphic + * @see DKTools.Layout.prototype.standardItems */ -DKTools.Sprite.CheckBox.prototype.setupAll = function(object) { - DKTools.Sprite.Button.prototype.setupAll.call(this, object); - this.setupChecked(object.checked); - this.setupCheckedGraphic(object.checkedGraphic); - this.setupUncheckedGraphic(object.uncheckedGraphic); +DKTools.Layout.prototype.setupItems = function(items) { + items = items || this.standardItems(); + _.forEach(items, function(item) { + this._items.push(item); + }.bind(this)); }; /** - * Sets the + * Sets the height of the row * - * @param {Boolean} [checked=this.standardChecked()] - + * @param {Function | Number} [rowHeight=this.standardRowHeight()] - Height of the row * - * @see DKTools.Sprite.CheckBox.prototype.standardChecked + * @see DKTools.Layout.prototype.standardRowHeight */ -DKTools.Sprite.CheckBox.prototype.setupChecked = function(checked) { +DKTools.Layout.prototype.setupRowHeight = function(rowHeight) { /** * @private * @readonly - * @type {Boolean} + * @type {Function | Number} */ - this._checked = checked == null ? this.standardChecked() : checked; + this._rowHeight = rowHeight || this.standardRowHeight(); }; /** - * Sets the + * Sets the width of the column * - * @param {Bitmap | String | Object} [graphic=this.standardCheckedGraphic()] - + * @param {Function | Number} [colWidth=this.standardColWidth()] - Width of the column * - * @see DKTools.Sprite.CheckBox.prototype.standardCheckedGraphic + * @see DKTools.Layout.prototype.standardColWidth */ -DKTools.Sprite.CheckBox.prototype.setupCheckedGraphic = function(graphic) { +DKTools.Layout.prototype.setupColWidth = function(colWidth) { /** * @private * @readonly - * @type {Bitmap | String | Object} + * @type {Function | Number} */ - this._checkedGraphic = graphic || this.standardCheckedGraphic(); + this._colWidth = colWidth || this.standardColWidth(); }; /** - * Sets the + * Sets the value of the invert * - * @param {Bitmap | String | Object} [graphic=this.standardUncheckedGraphic()] - + * @param {Boolean} [inverted=this.standardInverted()] - Value of the ivnert * - * @see DKTools.Sprite.CheckBox.prototype.standardUncheckedGraphic + * @see DKTools.Layout.prototype.standardInverted */ -DKTools.Sprite.CheckBox.prototype.setupUncheckedGraphic = function(graphic) { +DKTools.Layout.prototype.setupInverted = function(inverted) { /** * @private * @readonly - * @type {Bitmap | String | Object} + * @type {Boolean} */ - this._uncheckedGraphic = graphic || this.standardUncheckedGraphic(); + this._inverted = (inverted == null ? this.standardInverted() : inverted); }; // set methods @@ -23091,37 +24361,54 @@ DKTools.Sprite.CheckBox.prototype.setupUncheckedGraphic = function(graphic) { * * @override * - * @param {Object} [object={}] Parameters - * @param {Boolean} [blockStart=false] Blocking the call of the "start" function - * @param {Boolean} [activate=false] Activates the check box + * @param {Object} [object={}] - Parameters + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [activate=false] - Activates the layout * - * @param {Boolean} [object.checked] - * @param {Bitmap | String | Object} [object.checkedGraphic] - * @param {Bitmap | String | Object} [object.uncheckedGraphic] + * @param {Number} [object.maxCols] - Columns + * @param {Number} [object.horizontalSpacing] - Horizontal spacing + * @param {Number} [object.verticalSpacing] - Vertical spacing + * @param {Array} [object.items] - Items + * @param {Function | Number} [object.rowHeight] - Height of the row + * @param {Function | Number} [object.colWidth] - Width of the column + * @param {Boolean} [object.inverted] - Value of the invert * - * @see DKTools.Sprite.Button.prototype.setAll - * @see DKTools.Sprite.CheckBox.prototype.setChecked - * @see DKTools.Sprite.CheckBox.prototype.setCheckedGraphic - * @see DKTools.Sprite.CheckBox.prototype.setUncheckedGraphic - * @see DKTools.Sprite.CheckBox.prototype.start - * @see DKTools.Sprite.CheckBox.prototype.activate + * @see DKTools.Sprite.prototype.setupAll + * @see DKTools.Layout.prototype.setMaxCols + * @see DKTools.Layout.prototype.setSpacing + * @see DKTools.Layout.prototype.setItems + * @see DKTools.Layout.prototype.setRowHeight + * @see DKTools.Layout.prototype.setColWidth + * @see DKTools.Layout.prototype.setInverted + * @see DKTools.Layout.prototype.start + * @see DKTools.Layout.prototype.activate * * @returns {Number} Number of changed parameters */ -DKTools.Sprite.CheckBox.prototype.setAll = function(object, blockStart, activate) { - object = object || {}; - const block = true; - let changed = DKTools.Sprite.Button.prototype.setAll.call(this, object, block); +DKTools.Layout.prototype.setAll = function(object, blockStart, activate) { + object = object || {}; + const block = true; + let changed = DKTools.Sprite.prototype.setAll.call(this, object, block); + + if (this.setMaxCols(object.maxCols, block)) { + changed++; + } - if (this.setChecked(object.checked, block)) { + changed += this.setSpacing(object.horizontalSpacing, object.verticalSpacing, block); + + if (this.setItems(object.items, block)) { changed++; } - if (this.setCheckedGraphic(object.checkedGraphic, block)) { + if (this.setRowHeight(object.rowHeight, block)) { changed++; } - if (this.setUncheckedGraphic(object.uncheckedGraphic, block)) { + if (this.setColWidth(object.colWidth, block)) { + changed++; + } + + if (this.setInverted(object.reversed, block)) { changed++; } @@ -23135,5761 +24422,6136 @@ DKTools.Sprite.CheckBox.prototype.setAll = function(object, blockStart, activate } } - return changed; + return changed; }; /** - * Changes the + * Changes the number of the columns * Returns true if the change occurred * - * @param {Boolean} [checked] - - * @param {Boolean} [blockRefreshAll=false] - + * @param {Number} [cols] - Columns + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @see DKTools.Sprite.CheckBox.prototype.setupChecked - * @see DKTools.Sprite.CheckBox.prototype.refreshAll + * @see DKTools.Layout.prototype.setupMaxCols + * @see DKTools.Layout.prototype.start * * @returns {Boolean} Change occurred */ -DKTools.Sprite.CheckBox.prototype.setChecked = function(checked, blockRefreshAll) { - if (this._checked === checked) { +DKTools.Layout.prototype.setMaxCols = function(cols, blockStart) { + if (this._maxCols === cols) { return false; } - const lastChecked = this._checked; - this.setupChecked(checked); + const lastCols = this._maxCols; + this.setupMaxCols(cols); - if (this._checked === lastChecked) { + if (this._maxCols === lastCols) { return false; } - if (!blockRefreshAll) { - this.refreshAll(); + if (!blockStart) { + this.start(); } return true; }; /** - * Changes the + * Changes the horizontal spacing * Returns true if the change occurred * - * @param {Bitmap | String | Object} [graphic] - - * @param {Boolean} [blockRefreshAll=false] + * @param {Number} [scacing] - Horizontal spacing + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @see DKTools.Sprite.CheckBox.prototype.setupCheckedGraphic - * @see DKTools.Sprite.CheckBox.prototype.refreshAll + * @see DKTools.Layout.prototype.setupHorizontalSpacing + * @see DKTools.Layout.prototype.start * * @returns {Boolean} Change occurred */ -DKTools.Sprite.CheckBox.prototype.setCheckedGraphic = function(graphic, blockRefreshAll) { - const checkedGraphic = this._checkedGraphic; - - if (checkedGraphic == graphic) { +DKTools.Layout.prototype.setHorizontalSpacing = function(scacing, blockStart) { + if (this._horizontalSpacing === scacing) { return false; } - if (checkedGraphic instanceof Bitmap) { - this.setupCheckedGraphic(graphic); - } else if (DKTools.Utils.isString(checkedGraphic) || checkedGraphic instanceof Object) { - const lastGraphic = checkedGraphic; - this.setupCheckedGraphic(graphic); + const lastSpacing = this._horizontalSpacing; + this.setupHorizontalSpacing(scacing); - if (_.isEqual(this._checkedGraphic, lastGraphic)) { - return false; - } - } else { + if (this._horizontalSpacing === lastSpacing) { return false; } - if (!blockRefreshAll) { - this.refreshAll(); + if (!blockStart) { + this.start(); } return true; }; /** - * Changes the + * Changes the vertical spacing * Returns true if the change occurred * - * @param {Bitmap | String | Object} [graphic] - - * @param {Boolean} [blockRefreshAll=false] + * @param {Number} [scacing] - Vertical spacing + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @see DKTools.Sprite.CheckBox.prototype.setupUncheckedGraphic - * @see DKTools.Sprite.CheckBox.prototype.refreshAll + * @see DKTools.Layout.prototype.setupVerticalSpacing + * @see DKTools.Layout.prototype.start * * @returns {Boolean} Change occurred */ -DKTools.Sprite.CheckBox.prototype.setUncheckedGraphic = function(graphic, blockRefreshAll) { - const uncheckedGraphic = this._uncheckedGraphic; - - if (uncheckedGraphic == graphic) { +DKTools.Layout.prototype.setVerticalSpacing = function(scacing, blockStart) { + if (this._verticalSpacing === scacing) { return false; } - if (uncheckedGraphic instanceof Bitmap) { - this.setupUncheckedGraphic(graphic); - } else if (DKTools.Utils.isString(uncheckedGraphic) || uncheckedGraphic instanceof Object) { - const lastGraphic = uncheckedGraphic; - this.setupUncheckedGraphic(graphic); + const lastSpacing = this._verticalSpacing; + this.setupVerticalSpacing(scacing); - if (_.isEqual(this._uncheckedGraphic, lastGraphic)) { - return false; - } - } else { + if (this._verticalSpacing === lastSpacing) { return false; } - if (!blockRefreshAll) { - this.refreshAll(); + if (!blockStart) { + this.start(); } return true; }; -// _refresh methods +/** + * Changes the horizontal and vertical spacing + * Returns the number of changed parameters + * + * @param {Number} [horizontalSpacing] - Horizontal spacing + * @param {Number} [verticalSpacing] - Vertical spacing + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * + * @see DKTools.Layout.prototype.setHorizontalSpacing + * @see DKTools.Layout.prototype.setVerticalSpacing + * @see DKTools.Layout.prototype.start + * + * @returns {Number} Number of changed parameters + */ +DKTools.Layout.prototype.setSpacing = function(horizontalSpacing, verticalSpacing, blockStart) { + const block = true; + let changed = 0; + + if (this.setHorizontalSpacing(horizontalSpacing, block)) { + changed++; + } + + if (this.setVerticalSpacing(verticalSpacing, block)) { + changed++; + } + + if (changed && !blockStart) { + this.start(); + } + + return changed; +}; /** - * @private + * Changes the items + * Returns true if the change occurred + * + * @param {DKTools.Sprite[] | *} [items] - Items + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * + * @see DKTools.Layout.prototype.removeAllItems + * @see DKTools.Layout.prototype.setupItems + * @see DKTools.Layout.prototype.start + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.CheckBox.prototype._refreshCheckedGraphic = function() { - let bitmapObject = null; - if (_.isString(this._checkedGraphic)) { - bitmapObject = { - folder: this._graphicFolder, - filename: this._checkedGraphic - }; - } else if (this._checkedGraphic instanceof Object) { - bitmapObject = this._checkedGraphic; +DKTools.Layout.prototype.setItems = function(items, blockStart) { + if (this._items == items) { + return false; } - if (bitmapObject) { - this.loadBitmap(bitmapObject); + this.removeAllItems(); + this.setupItems(items); + + if (!blockStart) { + this.start(); } + + return true; }; /** - * @private + * Changes the height of the row + * Returns true if the change occurred + * + * @param @param {Function | Number} [rowHeight] - Height of the row + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * + * @see DKTools.Layout.prototype.setupRowHeight + * @see DKTools.Layout.prototype.start + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.CheckBox.prototype._refreshUncheckedGraphic = function() { - let bitmapObject = null; +DKTools.Layout.prototype.setRowHeight = function(rowHeight, blockStart) { + if (this._rowHeight === rowHeight) { + return false; + } - if (DKTools.Utils.isString(this._uncheckedGraphic)) { - bitmapObject = { - folder: this._graphicFolder, - filename: this._uncheckedGraphic - }; - } else if (this._uncheckedGraphic instanceof Object) { - bitmapObject = this._uncheckedGraphic; + const lastHeight = this._rowHeight; + this.setupRowHeight(rowHeight); + + if (this._rowHeight === lastHeight) { + return false; + } + + if (!blockStart) { + this.start(); + } + + return true; +}; + +/** + * Changes the width of the column + * Returns true if the change occurred + * + * @param {Function | Number} [colWidth] - Width of the column + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * + * @see DKTools.Layout.prototype.setupColWidth + * @see DKTools.Layout.prototype.start + * + * @returns {Boolean} Change occurred + */ +DKTools.Layout.prototype.setColWidth = function(colWidth, blockStart) { + if (this._colWidth === colWidth) { + return false; + } + + const lastWidth = this._colWidth; + this.setupColWidth(colWidth); + + if (this._colWidth === lastWidth) { + return false; + } + + if (!blockStart) { + this.start(); + } + + return true; +}; + +/** + * Changes the value of the invert + * Returns true if the change occurred + * + * @param {Boolean} [inverted] - Value of the invert + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * + * @see DKTools.Layout.prototype.setupInverted + * @see DKTools.Layout.prototype.start + * + * @returns {Boolean} Change occurred + */ +DKTools.Layout.prototype.setInverted = function(inverted, blockStart) { + if (this._inverted === inverted) { + return false; } - if (bitmapObject) { - this.loadBitmap(bitmapObject); + const lastReversed = this._inverted; + this.setupInverted(inverted); + + if (this._inverted === lastReversed) { + return false; } -}; -/** - * @private - */ -DKTools.Sprite.CheckBox.prototype._refreshGraphic = function() { - if (this.isChecked()) { - this._refreshCheckedGraphic(); - } else { - this._refreshUncheckedGraphic(); + if (!blockStart) { + this.start(); } + + return true; }; -// refresh methods +// start methods /** - * Updates and redraws all + * Starts the layout * * @override - * @see DKTools.Base.prototype.canRedrawAll + * + * @see DKTools.Sprite.prototype.start + * @see DKTools.Layout.prototype.isReady + * @see DKTools.Layout.prototype.addOneTimeEvent */ -DKTools.Sprite.CheckBox.prototype.refreshAll = function() { - this._refreshGraphic(); - DKTools.Sprite.Button.prototype.refreshAll.call(this); -}; - -// is methods +DKTools.Layout.prototype.start = function() { + this._started = true; -/** - * - * @returns {Boolean} - */ -DKTools.Sprite.CheckBox.prototype.isChecked = function() { - return this._checked; + if (this.isReady()) { + DKTools.Sprite.prototype.start.call(this); + } else { + this.addOneTimeEvent({ + type: 'ready', + onSuccess: this.start.bind(this) + }); + } }; -// event methods +// remove methods /** - * Updates the events with type: mouse-click-button + * Removes children objects from processing * - * @param {String} button - Mouse button + * @override * - * @see DKTools.Sprite.CheckBox.prototype.switch - * @see DKTools.Sprite.Button.prototype.updateMouseClickEvents + * @see DKTools.Sprite.prototype.removeAllChildren + * @see DKTools.Layout.prototype.removeAllItems */ -DKTools.Sprite.CheckBox.prototype.updateMouseClickEvents = function(button) { - this.switch(); - DKTools.Sprite.Button.prototype.updateMouseClickEvents.call(this, button); +DKTools.Layout.prototype.removeAllChildren = function() { + DKTools.Sprite.prototype.removeAllChildren.call(this); + this.removeAllItems(); }; /** - * Updates the events with type: checked + * Removes items from processing * - * @see DKTools.Sprite.CheckBox.prototype.updateEventsContainer + * @see DKTools.Layout.prototype.removeChild */ -DKTools.Sprite.CheckBox.prototype.updateCheckedEvents = function() { - this.updateEventsContainer('checked'); +DKTools.Layout.prototype.removeAllItems = function() { + this.removeChild.apply(this, this._items); }; /** - * Updates the events with type: unchecked + * Removes the item * - * @see DKTools.Sprite.CheckBox.prototype.updateEventsContainer + * @param {DKTools.Sprite | *} item - Item + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * + * @see DKTools.Layout.prototype.hasItem + * @see DKTools.Layout.prototype.removeChild + * @see DKTools.Layout.prototype.start + * @see DKTools.Utils.Array.remove */ -DKTools.Sprite.CheckBox.prototype.updateUncheckedEvents = function() { - this.updateEventsContainer('unchecked'); -}; +DKTools.Layout.prototype.removeItem = function(item, blockStart) { + if (!this.hasItem(item)) { + return; + } -// other methods + this.removeChild(item); -/** - * Switches the check box - * - * @see DKTools.Sprite.CheckBox.prototype.isChecked - * @see DKTools.Sprite.CheckBox.prototype.setChecked - */ -DKTools.Sprite.CheckBox.prototype.switch = function() { - this.setChecked(!this.isChecked()); -}; + DKTools.Utils.Array.remove(this._items, item); -/** - * - * - * @see DKTools.Sprite.CheckBox.prototype.isChecked - * @see DKTools.Sprite.CheckBox.prototype.switch - * @see DKTools.Sprite.CheckBox.prototype.updateCheckedEvents - */ -DKTools.Sprite.CheckBox.prototype.check = function() { - if (!this.isChecked()) { - this.switch(); - this.updateCheckedEvents(); + if (!blockStart) { + this.start(); } }; /** + * Removes the items * + * @param {Array} items - Items + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @see DKTools.Sprite.CheckBox.prototype.isChecked - * @see DKTools.Sprite.CheckBox.prototype.switch - * @see DKTools.Sprite.CheckBox.prototype.updateUncheckedEvents + * @see DKTools.Layout.prototype.removeItem + * @see DKTools.Layout.prototype.start */ -DKTools.Sprite.CheckBox.prototype.uncheck = function() { - if (this.isChecked()) { - this.switch(); - this.updateUncheckedEvents(); - } -}; - - - - - -//=========================================================================== -// DKTools.Viewport -//=========================================================================== - -DKTools.Viewport.prototype = Object.create(DKTools.Sprite.prototype); -DKTools.Viewport.prototype.constructor = DKTools.Viewport; - -// properties - -Object.defineProperties(DKTools.Viewport.prototype, { +DKTools.Layout.prototype.removeItems = function(items, blockStart) { + _.forEach(items, function(item) { + this.removeItem(item, true); + }.bind(this)); - /** - * Shape of the mask - * - * @readonly - * @type {PIXI.Graphics} - * @memberOf DKTools.Viewport.prototype - */ - maskShape: { - get: function() { - return this._maskShape; - }, - configurable: true + if (!blockStart) { + this.start(); } - -}); - -// standard methods +}; /** - * Returns the standard mask shape + * Removes the item by index * - * @returns {String} Standard mask shape + * @param {Number} index - Index + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * + * @see DKTools.Layout.prototype.getItem + * @see DKTools.Layout.prototype.removeItem */ -DKTools.Viewport.prototype.standardMaskShape = function() { - return 'rect'; +DKTools.Layout.prototype.removeItemByIndex = function(index, blockStart) { + this.removeItem(this.getItem(index), blockStart); }; -// setup methods - /** - * Sets all parameters - * - * @override - * - * @param {Object} [object] - Parameters + * Removes the columns * - * @param {String} [object.maskShape] - Shape of the mask + * @param {Number} cols - Columns * - * @see DKTools.Sprite.prototype.setupAll + * @see DKTools.Layout.prototype.getMaxCols + * @see DKTools.Layout.prototype.addCols */ -DKTools.Viewport.prototype.setupAll = function(object) { - object = object || {}; - - DKTools.Sprite.prototype.setupAll.call(this, object); - - this.setupMaskShape(object.maskShape); +DKTools.Layout.prototype.removeCols = function(cols) { + if (this.getMaxCols() - cols >= 1) { + this.addCols(-cols); + } }; /** - * Sets the shape of the mask + * Removes the column * - * @param {String} [shape] - Shape of the mask + * @see DKTools.Layout.prototype.removeCols */ -DKTools.Viewport.prototype.setupMaskShape = function(shape) { - /** - * @private - * @readonly - * @type {String} - */ - this._maskShape = shape || this.standardMaskShape(); +DKTools.Layout.prototype.removeCol = function() { + this.removeCols(1); }; -// set methods +// add methods /** - * Changes all parameters - * Returns the number of changed parameters + * Adds children objects to processing * * @override - * - * @param {Object} [object] - Parameters - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * @param {Boolean} [activate=false] - Activates the object - * - * @param {String} [object.maskShape] - Shape of the mask - * - * @see DKTools.Sprite.prototype.setAll - * - * @returns {Number} Number of changed parameters + * + * @see DKTools.Sprite.prototype.addAllChildren + * @see DKTools.Layout.prototype.addAllItems */ -DKTools.Viewport.prototype.setAll = function(object, blockStart, activate) { - object = object || {}; - const block = true; - - let changed = DKTools.Sprite.prototype.setAll.call(this, object, block); - - if (this.setMaskShape(object.maskShape, block)) { - changed++; - } - - if (changed) { - if (!blockStart) { - this.start(); - } - - if (activate) { - this.activate(); - } - } +DKTools.Layout.prototype.addAllChildren = function() { + DKTools.Sprite.prototype.addAllChildren.call(this); + this.addAllItems(); +}; - return changed; +/** + * Adds the itemns to processing + * + * @see DKTools.Layout.prototype.addChild + */ +DKTools.Layout.prototype.addAllItems = function() { + this.addChild.apply(this, this._items); }; /** - * Changes the shape of the mask - * Returns true if the change occurred + * Adds the item * - * @param {String} [shape] - Shape of the mask + * @param {DKTools.Sprite | *} item - Item * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @returns {Boolean} Change occurred + * @see DKTools.Layout.prototype.start */ -DKTools.Viewport.prototype.setMaskShape = function(shape, blockStart) { - if (this._maskShape === shape) { - return false; +DKTools.Layout.prototype.addItem = function(item, blockStart) { + if (!(item instanceof DKTools.Sprite)) { + return; } - const lastShape = this._maskShape; - this.setupShape(shape); + this._items.push(item); - if (this._maskShape === lastShape) { - return false; + if (!blockStart) { + this.start(); } +}; + +/** + * Adds the items + * + * @param {DKTools.Sprite[] | *} items - Items + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * + * @see DKTools.Layout.prototype.addItem + * @see DKTools.Layout.prototype.start + */ +DKTools.Layout.prototype.addItems = function(items, blockStart) { + _.forEach(items, function(item) { + this.addItem(item, true); + }.bind(this)); if (!blockStart) { this.start(); } - - return true; }; -// create methods - /** - * Creates all objects + * Adds the columns * - * @override + * @param {Number} cols - Columns + * + * @see DKTools.Layout.prototype.getMaxCols + * @see DKTools.Layout.prototype.setMaxCols */ -DKTools.Viewport.prototype.createAll = function() { - DKTools.Sprite.prototype.createAll.call(this); - this.createMask(); +DKTools.Layout.prototype.addCols = function(cols) { + this.setMaxCols(this.getMaxCols() + cols); }; /** - * Creates a mask - * - * @version 2.0.0 - * @override + * Adds the column + * + * @see DKTools.Layout.prototype.addCols */ -DKTools.Viewport.prototype.createMask = function() { - DKTools.Sprite.prototype.createMask.call(this, this._maskShape); +DKTools.Layout.prototype.addCol = function() { + this.addCols(1); }; // can methods /** - * Returns true if the viewport can clone the fixed bitmap + * Returns true if the layout can clone the fixed bitmap * * @override - * @returns {Boolean} Viewport can clone the fixed bitmap + * @returns {Boolean} Layout can clone the fixed bitmap */ -DKTools.Viewport.prototype.canCloneFixedBitmap = function() { +DKTools.Layout.prototype.canCloneFixedBitmap = function() { return false; }; +// _get methods +/** + * Returns the width of the bitmap + * + * @since 2.0.0 + * @private + * @override + * + * @see DKTools.Layout.prototype.getMaxCols + * @see DKTools.Layout.prototype.getColWidth + * + * @returns {Number} Width of the bitmap + */ +DKTools.Layout.prototype._getBitmapWidth = function() { + let width = 0; + const maxCols = this.getMaxCols(); + for (let i = 1; i <= maxCols; i++) { + width += this.getColWidth(i) + this._horizontalSpacing; + } + return width - this._horizontalSpacing; +}; -//=========================================================================== -// DKTools.Layout -//=========================================================================== - -DKTools.Layout.prototype = Object.create(DKTools.Sprite.prototype); -DKTools.Layout.prototype.constructor = DKTools.Layout; - -// properties - -Object.defineProperties(DKTools.Layout.prototype, { - - /** - * Number of the columns - * - * @readonly - * @type {Number} - * @memberOf DKTools.Layout.prototype - */ - maxCols: { - get: function() { - return this._maxCols; - }, - configurable: true - }, +/** + * Returns the height of the bitmap + * + * @since 2.0.0 + * @private + * @override + * + * @see DKTools.Layout.prototype.getMaxRows + * @see DKTools.Layout.prototype.getRowHeight + * + * @returns {Number} Height of the bitmap + */ +DKTools.Layout.prototype._getBitmapHeight = function() { + let height = 0; + const maxRows = this.getMaxRows(); - /** - * Items - * - * @readonly - * @type {DKTools.Sprite[] | *} - * @memberOf DKTools.Layout.prototype - */ - items: { - get: function() { - return this._items; - }, - configurable: true - }, + for (let i = 1; i <= maxRows; i++) { + height += this.getRowHeight(i) + this._verticalSpacing; + } - /** - * Height of the row - * - * @readonly - * @type {Function | Number} - * @memberOf DKTools.Layout.prototype - */ - rowHeight: { - get: function() { - return this._rowHeight; - }, - configurable: true - }, + return height - this._verticalSpacing; +}; - /** - * Width of the column - * - * @readonly - * @type {Function | Number} - * @memberOf DKTools.Layout.prototype - */ - colWidth: { - get: function() { - return this._colWidth; - }, - configurable: true - }, +// get methods - /** - * Horizontal spacing - * - * @readonly - * @type {Number} - * @memberOf DKTools.Layout.prototype - */ - horizontalSpacing: { - get: function() { - return this._horizontalSpacing; - }, - configurable: true - }, +/** + * Returns the maximum number of rows + * + * @see DKTools.Layout.prototype.getMaxItems + * @see DKTools.Layout.prototype.getMaxCols + * + * @returns {Number} Maximum number of rows + */ +DKTools.Layout.prototype.getMaxRows = function() { + return Math.max(1, Math.ceil(this.getMaxItems() / this.getMaxCols())); +}; - /** - * Vertical spacing - * - * @readonly - * @type {Number} - * @memberOf DKTools.Layout.prototype - */ - verticalSpacing: { - get: function() { - return this._verticalSpacing; - }, - configurable: true - }, +/** + * Returns the maximum number of columns + * + * @returns {Number} Maximum number of columns + */ +DKTools.Layout.prototype.getMaxCols = function() { + return this._maxCols; +}; - /** - * Value of the invert - * - * @readonly - * @type {Boolean} - * @memberOf DKTools.Layout.prototype - */ - inverted: { - get: function() { - return this._inverted; - }, - configurable: true +/** + * Returns the items + * + * @see DKTools.Layout.prototype.isInverted + * + * @returns {DKTools.Sprite[] | *} Items + */ +DKTools.Layout.prototype.getItems = function() { + if (this.isInverted()) { + return _.reverse(_.clone(this._items)); } -}); + return this._items; +}; -// _clear methods +/** + * Returns the number of the items + * + * @return {Number} Number of the items + */ +DKTools.Layout.prototype.getMaxItems = function() { + return this._items.length; +}; /** - * Clears all data + * Returns the index of the item + * + * @param {DKTools.Sprite | *} item - Item * - * @private - * @override + * @see DKTools.Layout.prototype.getItems * - * @see DKTools.Sprite.prototype._clearAll - * @see DKTools.Layout.prototype._clearItems + * @returns {Number} Index of the item */ -DKTools.Layout.prototype._clearAll = function() { - DKTools.Sprite.prototype._clearAll.call(this); - this._clearItems(); +DKTools.Layout.prototype.getItemIndex = function(item) { + return _.indexOf(this.getItems(), item); }; /** - * Clears items + * Returns the item by index * - * @private + * @param {Number} index - Index + * + * @see DKTools.Layout.prototype.getItems + * + * @returns {DKTools.Sprite | * | undefined} Item by index or undefined */ -DKTools.Layout.prototype._clearItems = function() { - /** - * @private - * @readonly - * @type {Array} - */ - this._items = []; +DKTools.Layout.prototype.getItem = function(index) { + return this.getItems()[index]; }; -// clear methods - /** - * Clears items + * Returns the items in the row * - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Number} row - Row * - * @see DKTools.Layout.prototype.removeAllItems - * @see DKTools.Layout.prototype._clearItems - * @see DKTools.Layout.prototype.start + * @see DKTools.Layout.prototype.getMaxCols + * @see DKTools.Layout.prototype.getMaxRows + * @see DKTools.Layout.prototype.getItem + * + * @returns {DKTools.Sprite[] | *} Items in the row */ -DKTools.Layout.prototype.clearItems = function(blockStart) { - this.removeAllItems(); - this._clearItems(); +DKTools.Layout.prototype.getItemsInRow = function(row) { + const items = []; + const maxCols = this.getMaxCols(); - if (!blockStart) { - this.start(); + if (row < 1 || row > this.getMaxRows()) { + return items; } -}; -// standard methods + const startIndex = maxCols * (row - 1); + + for(let i = 0; i < maxCols; i++) { + items.push(this.getItem(startIndex + i)); + } + + return items; +}; /** - * Returns the standard activity of the layout + * Returns the items in the column * - * @override - * @returns {Boolean} Standard activity of the layout + * @param {Number} col - Column + * + * @see DKTools.Layout.prototype.getMaxRows + * @see DKTools.Layout.prototype.getMaxCols + * @see DKTools.Layout.prototype.getItem + * + * @returns {DKTools.Sprite[] | *} Items in the column */ -DKTools.Layout.prototype.standardActive = function() { - return false; +DKTools.Layout.prototype.getItemsInCol = function(col) { + const items = []; + const maxRows = this.getMaxRows(); + const maxCols = this.getMaxCols(); + + if (col < 1 || col > maxCols) { + return items; + } + + const startIndex = col - 1; + + for(let i = 0; i < maxRows; i++) { + items.push(this.getItem(startIndex + maxCols * i)); + } + + return items; }; /** - * Returns the standard number of the columns + * Returns the height of the row * - * @returns {Number} Standard number of columns + * @param {Number} row - Row + * @returns {Number} Height of the row */ -DKTools.Layout.prototype.standardMaxCols = function() { - return 1; +DKTools.Layout.prototype.getRowHeight = function(row) { + if (DKTools.Utils.isFunction(this._rowHeight)) { + return this._rowHeight(row); + } + + return this._rowHeight; }; /** - * Returns the standard horizontal spacing + * Returns the width of the column * - * @returns {Number} Standard horizontal spacing + * @param {Number} col - Column + * @returns {Number} Width of the column */ -DKTools.Layout.prototype.standardHorizontalSpacing = function() { - return 12; +DKTools.Layout.prototype.getColWidth = function(col) { + if (DKTools.Utils.isFunction(this._colWidth)) { + return this._colWidth(col); + } + + return this._colWidth; }; /** - * Returns the standard vertical spacing + * Returns the Y coordinate of the row * - * @returns {Number} Standard vertical spacing + * @param {Number} row - Row + * + * @see DKTools.Layout.prototype.getRowHeight + * + * @returns {Number} The Y coordinate of the row */ -DKTools.Layout.prototype.standardVerticalSpacing = function() { - return this.getLineHeight() / 2; +DKTools.Layout.prototype.getRowY = function(row) { + let y = 0; + + for(let i = 1; i < row; i++) { + y += this.getRowHeight(i) + this._verticalSpacing; + } + + return y; }; /** - * Returns the standard list of the items + * Returns the X coordinate of the column * - * @returns {Array} Standard list of the items + * @param {Number} col - Column + * + * @see DKTools.Layout.prototype.getColWidth + * + * @returns {Number} The X coordinate of the column */ -DKTools.Layout.prototype.standardItems = function() { - return []; +DKTools.Layout.prototype.getColX = function(col) { + let x = 0; + + for(let i = 1; i < col; i++) { + x += this.getColWidth(i) + this._horizontalSpacing; + } + + return x; }; /** - * Returns the standard height of the row + * Returns the row of the item * - * @returns {Function} Standard height of the row + * @param {DKTools.Sprite | *} item - Item + * + * @see DKTools.Layout.prototype.getItemIndex + * @see DKTools.Layout.prototype.getMaxCols + * + * @returns {Number} Row of the item or -1 */ -DKTools.Layout.prototype.standardRowHeight = function() { - return function(row) { - const items = this.getItemsInRow(row); - return _.max(_.map(items, 'height')); - }.bind(this); +DKTools.Layout.prototype.getItemRow = function(item) { + const index = this.getItemIndex(item); + + if (index >= 0) { + return Math.floor(index / this.getMaxCols()) + 1; + } + + return -1; }; /** - * Returns the standard width of the column + * Returns the column of the item * - * @returns {Function} Standard width of the column + * @param {DKTools.Sprite | *} item - Item + * + * @see DKTools.Layout.prototype.getItemIndex + * @see DKTools.Layout.prototype.getMaxCols + * + * @returns {Number} Column of the item or -1 */ -DKTools.Layout.prototype.standardColWidth = function() { - return function(col) { - const items = this.getItemsInCol(col); - return _.max(_.map(items, 'width')); - }.bind(this); +DKTools.Layout.prototype.getItemCol = function(item) { + const index = this.getItemIndex(item); + + if (index >= 0) { + return (index % this.getMaxCols()) + 1; + } + + return -1; }; /** - * Returns the standard value of the invert + * Returns the cell by row and column * - * @returns {Boolean} Standard value of the invert + * @param {Number} row - Row + * @param {Number} col - Col + * + * @see DKTools.Layout.prototype.getMaxCols + * @see DKTools.Layout.prototype.getColX + * @see DKTools.Layout.prototype.getRowY + * @see DKTools.Layout.prototype.getColWidth + * @see DKTools.Layout.prototype.getRowHeight + * + * @returns {{ item: (DKTools.Sprite | * | undefined), x: Number, y: Number, width: Number, height: Number }} */ -DKTools.Layout.prototype.standardInverted = function() { - return false; +DKTools.Layout.prototype.getCell = function(row, col) { + const index = this.getMaxCols() * (row - 1) + (col - 1); + + return { + item: this.getItem(index), + x: this.getColX(col), + y: this.getRowY(row), + width: this.getColWidth(col), + height: this.getRowHeight(row) + }; }; -// setup methods +// move methods /** - * Sets all parameters - * - * @override + * Moves the item * - * @param {Object} [object={}] - Parameters + * @param {Number} index - Index + * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object] - The X coordinate or Point or object with parameters + * @param {Number} [y] - The Y coordinate (if object is Number) * - * @param {Number} [object.maxCols] - Columns - * @param {Number} [object.horizontalSpacing] - Horizontal spacing - * @param {Number} [object.verticalSpacing] - Vertical spacing - * @param {Array} [object.items] - Items - * @param {Function | Number} [object.rowHeight] - Height of the row - * @param {Function | Number} [object.colWidth] - Width of the column - * @param {Boolean} [object.inverted] - Value of the invert + * @param {Number} [object.x] - The X coordinate + * @param {Number} [object.y] - The Y coordinate * - * @see DKTools.Sprite.prototype.setupAll - * @see DKTools.Layout.prototype.setupMaxCols - * @see DKTools.Layout.prototype.setupSpacing - * @see DKTools.Layout.prototype.setupItems - * @see DKTools.Layout.prototype.setupRowHeight - * @see DKTools.Layout.prototype.setupColWidth - * @see DKTools.Layout.prototype.setupInverted -*/ -DKTools.Layout.prototype.setupAll = function(object) { - object = object || {}; - DKTools.Sprite.prototype.setupAll.call(this, object); - this.setupMaxCols(object.maxCols); - this.setupSpacing(object.horizontalSpacing, object.verticalSpacing); - this.setupItems(object.items); - this.setupRowHeight(object.rowHeight); - this.setupColWidth(object.colWidth); - this.setupInverted(object.inverted); + * @see DKTools.Layout.prototype.getItem + */ +DKTools.Layout.prototype.moveItem = function(index, object, y) { + const item = this.getItem(index); + + if (item) { + item.move(object, y); + } }; +// invert methods + /** - * Sets the number of the columns - * - * @param {Number} [cols=this.standardMaxCols()] - Columns + * Inverts the layout * - * @see DKTools.Layout.prototype.standardMaxCols + * @see DKTools.Layout.prototype.isInverted + * @see DKTools.Layout.prototype.setInverted */ -DKTools.Layout.prototype.setupMaxCols = function(cols) { - /** - * @private - * @readonly - * @type {Number} - */ - this._maxCols = (cols == null ? this.standardMaxCols() : cols); +DKTools.Layout.prototype.invert = function() { + this.setInverted(!this.isInverted()); }; +// is methods + /** - * Sets the horizontal spacing + * Returns true if the layout is empty * - * @param {Number} [spacing=this.standardHorizontalSpacing()] - Horizontal spacing + * @see DKTools.Layout.prototype.getMaxItems * - * @see DKTools.Layout.prototype.standardHorizontalSpacing + * @returns {Boolean} Layout is empty */ -DKTools.Layout.prototype.setupHorizontalSpacing = function(spacing) { - /** - * @private - * @readonly - * @type {Number} - */ - this._horizontalSpacing = (spacing == null ? this.standardHorizontalSpacing() : spacing); +DKTools.Layout.prototype.isEmpty = function() { + return this.getMaxItems() === 0; }; /** - * Sets the vertical spacing + * Returns true if the layout is ready * - * @param {Number} [spacing=this.standardVerticalSpacing()] - Vertical spacing + * @override * - * @see DKTools.Layout.prototype.standardVerticalSpacing + * @see DKTools.Layout.prototype.isEmpty + * + * @returns {Boolean} Layout is ready */ -DKTools.Layout.prototype.setupVerticalSpacing = function(spacing) { - /** - * @private - * @readonly - * @type {Number} - */ - this._verticalSpacing = (spacing == null ? this.standardVerticalSpacing() : spacing); +DKTools.Layout.prototype.isReady = function() { + return this.isEmpty() || _.every(this._items, function(item) { + return item.isReady(); + }); }; /** - * Sets the horizontal and vertical spacing - * - * @param {Number} [horizontalSpacing] - Horizontal spacing - * @param {Number} [verticalSpacing] - Vertical spacing + * Returns true if the layout is inverted * - * @see DKTools.Layout.prototype.setupHorizontalSpacing - * @see DKTools.Layout.prototype.setupVerticalSpacing + * @returns {Boolean} Layout is inverted */ -DKTools.Layout.prototype.setupSpacing = function(horizontalSpacing, verticalSpacing) { - this.setupHorizontalSpacing(horizontalSpacing); - this.setupVerticalSpacing(verticalSpacing); +DKTools.Layout.prototype.isInverted = function() { + return this._inverted; }; /** - * Sets the items + * Returns true if the layout is horizontal * - * @param {DKTools.Sprite[] | *} [items=this.standardItems()] - Items + * @see DKTools.Layout.prototype.getMaxRows * - * @see DKTools.Layout.prototype.standardItems + * @returns {boolean} Layout is horizontal */ -DKTools.Layout.prototype.setupItems = function(items) { - items = items || this.standardItems(); - _.forEach(items, function(item) { - this._items.push(item); - }.bind(this)); +DKTools.Layout.prototype.isHorizontal = function() { + return this.getMaxRows() === 1; }; /** - * Sets the height of the row + * Returns true if the layout is vertical * - * @param {Function | Number} [rowHeight=this.standardRowHeight()] - Height of the row + * @see DKTools.Layout.prototype.getMaxCols * - * @see DKTools.Layout.prototype.standardRowHeight + * @returns {boolean} Layout is vertical */ -DKTools.Layout.prototype.setupRowHeight = function(rowHeight) { - /** - * @private - * @readonly - * @type {Function | Number} - */ - this._rowHeight = rowHeight || this.standardRowHeight(); +DKTools.Layout.prototype.isVertical = function() { + return this.getMaxCols() === 1; }; +// has methods + /** - * Sets the width of the column + * Returns true if the layout has the items * - * @param {Function | Number} [colWidth=this.standardColWidth()] - Width of the column + * @see DKTools.Layout.prototype.isEmpty * - * @see DKTools.Layout.prototype.standardColWidth + * @returns {Boolean} Layout has the items */ -DKTools.Layout.prototype.setupColWidth = function(colWidth) { - /** - * @private - * @readonly - * @type {Function | Number} - */ - this._colWidth = colWidth || this.standardColWidth(); +DKTools.Layout.prototype.hasItems = function() { + return !this.isEmpty(); }; /** - * Sets the value of the invert + * Returns true if the layout has the item * - * @param {Boolean} [inverted=this.standardInverted()] - Value of the ivnert + * @param {DKTools.Sprite | *} item - Item * - * @see DKTools.Layout.prototype.standardInverted + * @see DKTools.Layout.prototype.getItemIndex + * + * @returns {Boolean} Layout has the item */ -DKTools.Layout.prototype.setupInverted = function(inverted) { - /** - * @private - * @readonly - * @type {Boolean} - */ - this._inverted = (inverted == null ? this.standardInverted() : inverted); +DKTools.Layout.prototype.hasItem = function(item) { + return this.getItemIndex(item) >= 0; }; -// set methods +// items methods /** - * Changes all parameters - * Returns the number of changed parameters - * - * @override - * - * @param {Object} [object={}] - Parameters - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * @param {Boolean} [activate=false] - Activates the layout + * Calls the callback function for the items * - * @param {Number} [object.maxCols] - Columns - * @param {Number} [object.horizontalSpacing] - Horizontal spacing - * @param {Number} [object.verticalSpacing] - Vertical spacing - * @param {Array} [object.items] - Items - * @param {Function | Number} [object.rowHeight] - Height of the row - * @param {Function | Number} [object.colWidth] - Width of the column - * @param {Boolean} [object.inverted] - Value of the invert + * @param {Function} callback - Function for the items + * @param {Boolean} [start=false] - Call of the "start" function * - * @see DKTools.Sprite.prototype.setupAll - * @see DKTools.Layout.prototype.setMaxCols - * @see DKTools.Layout.prototype.setSpacing - * @see DKTools.Layout.prototype.setItems - * @see DKTools.Layout.prototype.setRowHeight - * @see DKTools.Layout.prototype.setColWidth - * @see DKTools.Layout.prototype.setInverted + * @see DKTools.Layout.prototype.getItems * @see DKTools.Layout.prototype.start - * @see DKTools.Layout.prototype.activate - * - * @returns {Number} Number of changed parameters -*/ -DKTools.Layout.prototype.setAll = function(object, blockStart, activate) { - object = object || {}; - const block = true; - let changed = DKTools.Sprite.prototype.setAll.call(this, object, block); - - if (this.setMaxCols(object.maxCols, block)) { - changed++; - } - - changed += this.setSpacing(object.horizontalSpacing, object.verticalSpacing, block); - - if (this.setItems(object.items, block)) { - changed++; - } - - if (this.setRowHeight(object.rowHeight, block)) { - changed++; - } + */ +DKTools.Layout.prototype.iterateItems = function(callback, start) { + _.forEach(this.getItems(), callback); - if (this.setColWidth(object.colWidth, block)) { - changed++; + if (start) { + this.start(); } +}; - if (this.setInverted(object.reversed, block)) { - changed++; - } +/** + * Starts the items + * + * @param {Boolean} [activate=false] - Activates the item + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * + * @see DKTools.Layout.prototype.iterateItems + */ +DKTools.Layout.prototype.startItems = function(activate, blockStart) { + const callback = function(item) { + item.start(activate); + }; + this.iterateItems(callback, !blockStart); +}; - if (changed) { +/** + * Resizes the item + * + * @param {DKTools.Sprite | *} item - Item + * @param {Number} [width] - Width of the item + * @param {Number} [height] - Height of the item + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * + * @see DKTools.Layout.prototype.hasItem + * @see DKTools.Layout.prototype.start + */ +DKTools.Layout.prototype.resizeItem = function(item, width, height, blockStart) { + if (this.hasItem(item) && item.resize(width, height)) { if (!blockStart) { this.start(); } - - if (activate) { - this.activate(); - } } +}; - return changed; +/** + * Resizes the item by index + * + * @param {Number} index - Index + * @param {Number} [width] - Width of the item + * @param {Number} [height] - Height of the item + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * + * @see DKTools.Layout.prototype.getItem + * @see DKTools.Layout.prototype.resizeItem + */ +DKTools.Layout.prototype.resizeItemByIndex = function(index, width, height, blockStart) { + this.resizeItem(this.getItem(index), width, height, blockStart); +}; + +/** + * Resizes the items + * + * @param {Number} [width] - Width of the item + * @param {Number} [height] - Height of the item + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * + * @see DKTools.Layout.prototype.resizeItem + * @see DKTools.Layout.prototype.iterateItems + */ +DKTools.Layout.prototype.resizeItems = function(width, height, blockStart) { + const callback = function(item) { + this.resizeItem(item, width, height, true); + }.bind(this); + this.iterateItems(callback, !blockStart); }; /** - * Changes the number of the columns - * Returns true if the change occurred - * - * @param {Number} [cols] - Columns - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * Activates the items * - * @see DKTools.Layout.prototype.setupMaxCols - * @see DKTools.Layout.prototype.start + * @param {Boolean} [start=false] - Call of the "start" function * - * @returns {Boolean} Change occurred + * @see DKTools.Layout.prototype.iterateItems */ -DKTools.Layout.prototype.setMaxCols = function(cols, blockStart) { - if (this._maxCols === cols) { - return false; - } - - const lastCols = this._maxCols; - this.setupMaxCols(cols); - - if (this._maxCols === lastCols) { - return false; - } - - if (!blockStart) { - this.start(); - } - - return true; +DKTools.Layout.prototype.activateItems = function(start) { + const callback = function(item) { + item.activate(); + }; + this.iterateItems(callback, start); }; /** - * Changes the horizontal spacing - * Returns true if the change occurred - * - * @param {Number} [scacing] - Horizontal spacing - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * Deactivates the items * - * @see DKTools.Layout.prototype.setupHorizontalSpacing - * @see DKTools.Layout.prototype.start + * @param {Boolean} [start=false] - Call of the "start" function * - * @returns {Boolean} Change occurred + * @see DKTools.Layout.prototype.iterateItems */ -DKTools.Layout.prototype.setHorizontalSpacing = function(scacing, blockStart) { - if (this._horizontalSpacing === scacing) { - return false; - } - - const lastSpacing = this._horizontalSpacing; - this.setupHorizontalSpacing(scacing); - - if (this._horizontalSpacing === lastSpacing) { - return false; - } - - if (!blockStart) { - this.start(); - } - - return true; +DKTools.Layout.prototype.deactivateItems = function(start) { + const callback = function(item) { + item.deactivate(); + }; + this.iterateItems(callback, start); }; /** - * Changes the vertical spacing - * Returns true if the change occurred + * Shows the items * - * @param {Number} [scacing] - Vertical spacing - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [activate=false] - Activates the items + * @param {Boolean} [start=false] - Call of the "start" function * - * @see DKTools.Layout.prototype.setupVerticalSpacing - * @see DKTools.Layout.prototype.start + * @see DKTools.Layout.prototype.iterateItems + */ +DKTools.Layout.prototype.showItems = function(activate, start) { + const callback = function(item) { + item.show(activate); + }; + this.iterateItems(callback, start); +}; + +/** + * Hides the items * - * @returns {Boolean} Change occurred + * @param {Boolean} [blockDeactivate=false] - Block deactivation of the items + * @param {Boolean} [start=false] - Call of the "start" function + * + * @see DKTools.Layout.prototype.iterateItems */ -DKTools.Layout.prototype.setVerticalSpacing = function(scacing, blockStart) { - if (this._verticalSpacing === scacing) { - return false; - } +DKTools.Layout.prototype.hideItems = function(blockDeactivate, start) { + const callback = function(item) { + item.hide(blockDeactivate); + }; + this.iterateItems(callback, start); +}; - const lastSpacing = this._verticalSpacing; - this.setupVerticalSpacing(scacing); +// align methods - if (this._verticalSpacing === lastSpacing) { - return false; - } +/** + * Aligns the item + * + * @param {DKTools.Sprite | * | Number} item - Item or index + * + * @see DKTools.Layout.prototype.isReady + * @see DKTools.Layout.prototype.getItemRow + * @see DKTools.Layout.prototype.getItemCol + * @see DKTools.Layout.prototype.getRowHeight + * @see DKTools.Layout.prototype.getColWidth + * @see DKTools.Layout.prototype.getColX + * @see DKTools.Layout.prototype.getRowY + * @see DKTools.Layout.prototype.addOneTimeEvent + */ +DKTools.Layout.prototype.alignItem = function(item) { + if (this.isReady()) { + const itemRow = this.getItemRow(item); + const itemCol = this.getItemCol(item); + const rowHeight = this.getRowHeight(itemRow); + const colWidth = this.getColWidth(itemCol); + const x = this.getColX(itemCol) + (colWidth - item.width) / 2; + const y = this.getRowY(itemRow) + (rowHeight - item.height) / 2; - if (!blockStart) { - this.start(); + item.move(x, y); + } else { + this.addOneTimeEvent({ + type: 'ready', + onSuccess: this.alignItem.bind(this, item) + }); } - - return true; }; /** - * Changes the horizontal and vertical spacing - * Returns the number of changed parameters - * - * @param {Number} [horizontalSpacing] - Horizontal spacing - * @param {Number} [verticalSpacing] - Vertical spacing - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * Aligns the row * - * @see DKTools.Layout.prototype.setHorizontalSpacing - * @see DKTools.Layout.prototype.setVerticalSpacing - * @see DKTools.Layout.prototype.start + * @param {Number} row - Row * - * @returns {Number} Number of changed parameters + * @see DKTools.Layout.prototype.getItemsInRow + * @see DKTools.Layout.prototype.alignItem */ -DKTools.Layout.prototype.setSpacing = function(horizontalSpacing, verticalSpacing, blockStart) { - const block = true; - let changed = 0; - - if (this.setHorizontalSpacing(horizontalSpacing, block)) { - changed++; - } - - if (this.setVerticalSpacing(verticalSpacing, block)) { - changed++; - } +DKTools.Layout.prototype.alignRow = function(row) { + _.forEach(this.getItemsInRow(row), this.alignItem.bind(this)); +}; - if (changed && !blockStart) { - this.start(); - } +/** + * Aligns the column + * + * @param {Number} col - Column + * + * @see DKTools.Layout.prototype.getItemsInCol + * @see DKTools.Layout.prototype.alignItem + */ +DKTools.Layout.prototype.alignCol = function(col) { + _.forEach(this.getItemsInCol(col), this.alignItem.bind(this)); +}; - return changed; +/** + * Aligns the items + * + * @see DKTools.Layout.prototype.addOneTimeEvent + * @see DKTools.Layout.prototype.iterateItems + * @see DKTools.Layout.prototype.alignItem + */ +DKTools.Layout.prototype.alignItems = function() { + this.addOneTimeEvent({ + type: 'ready', + onSuccess: function() { + this.iterateItems(this.alignItem.bind(this)) + }.bind(this) + }); }; +// update methods + /** - * Changes the items - * Returns true if the change occurred + * Updates all * - * @param {DKTools.Sprite[] | *} [items] - Items - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @override * - * @see DKTools.Layout.prototype.removeAllItems - * @see DKTools.Layout.prototype.setupItems - * @see DKTools.Layout.prototype.start + * @see DKTools.Sprite.prototype.updateAll + * @see DKTools.Layout.prototype.updateLayout + */ +DKTools.Layout.prototype.updateAll = function() { + DKTools.Sprite.prototype.updateAll.call(this); + this.updateLayout(); +}; + +/** + * Updates the layout * - * @returns {Boolean} Change occurred + * @see DKTools.Layout.prototype.getMaxItems + * @see DKTools.Layout.prototype.getMaxRows + * @see DKTools.Layout.prototype.getMaxCols + * @see DKTools.Layout.prototype.getColX + * @see DKTools.Layout.prototype.getRowY + * @see DKTools.Layout.prototype.moveItem */ -DKTools.Layout.prototype.setItems = function(items, blockStart) { - if (this._items == items) { - return false; - } +DKTools.Layout.prototype.updateLayout = function() { + const maxItems = this.getMaxItems(); + const maxRows = this.getMaxRows(); + const maxCols = this.getMaxCols(); + let index = 0; - this.removeAllItems(); - this.setupItems(items); + for(let i = 1; i <= maxRows && index < maxItems; i++) { + for(let j = 1; j <= maxCols && index < maxItems; j++) { + const x = this.getColX(j); + const y = this.getRowY(i); - if (!blockStart) { - this.start(); + this.moveItem(index++, x, y); + } } +}; + + + + + +//=========================================================================== +// DKTools.Window +//=========================================================================== - return true; -}; +DKTools.Window.prototype = Object.create(Window_Base.prototype); +DKTools.Utils.mixin(DKTools.Window.prototype, DKTools.Base.prototype); +DKTools.Window.prototype.constructor = DKTools.Window; /** - * Changes the height of the row - * Returns true if the change occurred - * - * @param @param {Function | Number} [rowHeight] - Height of the row - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * - * @see DKTools.Layout.prototype.setupRowHeight - * @see DKTools.Layout.prototype.start + * Counter of created windows * - * @returns {Boolean} Change occurred + * @private + * @readonly + * @type {Number} + * @memberof DKTools.Window */ -DKTools.Layout.prototype.setRowHeight = function(rowHeight, blockStart) { - if (this._rowHeight === rowHeight) { - return false; - } +DKTools.Window._counter = 0; - const lastHeight = this._rowHeight; - this.setupRowHeight(rowHeight); +// properties - if (this._rowHeight === lastHeight) { - return false; - } +Object.defineProperties(DKTools.Window.prototype, { - if (!blockStart) { - this.start(); - } + /** + * Real width of the window (not including scaling) + * + * @readonly + * @type {Number} + * @memberof DKTools.Window.prototype + */ + realWidth: { + get: function() { + return this._width; + }, + set: function(value) { + this._width = value; + this._refreshAllParts(); + }, + configurable: true + }, - return true; -}; + /** + * Real height of the window (not including scaling) + * + * @readonly + * @type {Number} + * @memberof DKTools.Window.prototype + */ + realHeight: { + get: function() { + return this._height; + }, + set: function(value) { + this._height = value; + this._refreshAllParts(); + }, + configurable: true + }, -/** - * Changes the width of the column - * Returns true if the change occurred - * - * @param {Function | Number} [colWidth] - Width of the column - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * - * @see DKTools.Layout.prototype.setupColWidth - * @see DKTools.Layout.prototype.start - * - * @returns {Boolean} Change occurred - */ -DKTools.Layout.prototype.setColWidth = function(colWidth, blockStart) { - if (this._colWidth === colWidth) { - return false; - } + /** + * Width of the window (taking into account scaling) + * + * @type {Number} + * @memberof DKTools.Window.prototype + */ + width: { + get: function() { + return this.realWidth * this.scale.x; + }, + set: function(value) { + this._width = Math.floor(value / this.scale.x); + this._refreshAllParts(); + }, + configurable: true + }, - const lastWidth = this._colWidth; - this.setupColWidth(colWidth); + /** + * Height of the window (taking into account scaling) + * + * @type {Number} + * @memberof DKTools.Window.prototype + */ + height: { + get: function() { + return this.realHeight * this.scale.y; + }, + set: function(value) { + this._height = Math.floor(value / this.scale.y); + this._refreshAllParts(); + }, + configurable: true + }, - if (this._colWidth === lastWidth) { - return false; - } + /** + * Origin + * + * @readonly + * @type {Point} + * @memberof DKTools.Window.prototype + */ + origin: { + get: function() { + return this._origin; + }, + configurable: true + }, - if (!blockStart) { - this.start(); - } + /** + * Opacity of the window + * + * @type {Number} + * @memberof DKTools.Window.prototype + */ + windowOpacity: { + get: function() { + return this._windowSpriteContainer.alpha * 255; + }, + set: function(value) { + this._windowSpriteContainer.alpha = _.clamp(value, 0, 255) / 255; + }, + configurable: true + }, - return true; -}; + /** + * Opacity of the frame + * + * @type {Number} + * @memberof DKTools.Window.prototype + */ + frameOpacity: { + get: function() { + return this._windowFrameSprite.alpha * 255; + }, + set: function(value) { + this._windowFrameSprite.alpha = _.clamp(value, 0, 255) / 255; + }, + configurable: true + }, -/** - * Changes the value of the invert - * Returns true if the change occurred - * - * @param {Boolean} [inverted] - Value of the invert - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * - * @see DKTools.Layout.prototype.setupInverted - * @see DKTools.Layout.prototype.start - * - * @returns {Boolean} Change occurred - */ -DKTools.Layout.prototype.setInverted = function(inverted, blockStart) { - if (this._inverted === inverted) { - return false; - } + /** + * Opacity of the window + * + * @readonly + * @type {Object} + * @memberof DKTools.Window.prototype + */ + opacity: { + get: function() { + return this._opacity; + }, + configurable: true + }, - const lastReversed = this._inverted; - this.setupInverted(inverted); + /** + * Tone of the window + * + * @readonly + * @type {Number[]} + * @memberof DKTools.Window.prototype + */ + tone: { + get: function() { + return this._tone; + }, + configurable: true + }, - if (this._inverted === lastReversed) { - return false; - } + /** + * Sprite of the contents + * + * @readonly + * @type {DKTools.Sprite} + * @memberof DKTools.Window.prototype + */ + contentsSprite: { + get: function() { + return this._windowContentsSprite; + }, + configurable: true + }, - if (!blockStart) { - this.start(); + /** + * Sprite of the frame + * + * @readonly + * @type {Sprite} + * @memberof DKTools.Window.prototype + */ + frameSprite: { + get: function() { + return this._windowFrameSprite; + }, + configurable: true + }, + + /** + * Sprite of the background + * + * @readonly + * @type {Sprite} + * @memberof DKTools.Window.prototype + */ + backSprite: { + get: function() { + return this._windowBackSprite; + }, + configurable: true + }, + + /** + * Bitmap of sprite of the contents + * To support functions from DKTools.Base + * + * @type {Bitmap} + * @memberof DKTools.Window.prototype + */ + bitmap: { + get: function() { + return this.contents; + }, + set: function(value) { + this.contents = value; + }, + configurable: true } - return true; -}; +}); -// start methods +// initialize methods /** - * Starts the layout + * Initializes a class object * * @override + * + * @param {Number | Object} [object] - The X coordinate + * @param {Number} [y] - The Y coordinate + * @param {Number} [width] - Width of the window + * @param {Number} [height] - Height of the window + * + * @see PIXI.Container + * @see DKTools.Base.prototype.initialize */ -DKTools.Layout.prototype.start = function() { - this._started = true; - - if (this.isReady()) { - DKTools.Sprite.prototype.start.call(this); - } else { - this.addOneTimeEvent({ - type: 'ready', - onSuccess: this.start.bind(this) - }); - } +DKTools.Window.prototype.initialize = function(object, y, width, height) { + PIXI.Container.call(this); + DKTools.Base.prototype.initialize.call(this, object, y, width, height); + DKTools.Window._counter++; }; -// remove methods +// _clear methods /** - * Removes children objects from processing + * Clears all data * + * @private * @override - * - * @see DKTools.Sprite.prototype.removeAllChildren - * @see DKTools.Layout.prototype.removeAllItems + * + * @see DKTools.Base.prototype._clearAll + * @see DKTools.Window.prototype._clearIsWindow + * @see DKTools.Window.prototype._clearOpenness + * @see DKTools.Window.prototype._clearPadding + * @see DKTools.Window.prototype._clearMargin + * @see DKTools.Window.prototype._clearColorTone + * @see DKTools.Window.prototype._clearOrigin + * @see DKTools.Window.prototype._clearArrows */ -DKTools.Layout.prototype.removeAllChildren = function() { - DKTools.Sprite.prototype.removeAllChildren.call(this); - this.removeAllItems(); +DKTools.Window.prototype._clearAll = function() { + DKTools.Base.prototype._clearAll.call(this); + this._clearIsWindow(); + this._clearOpenness(); + this._clearPadding(); + this._clearMargin(); + this._clearColorTone(); + this._clearOrigin(); + this._clearArrows(); }; /** - * Removes items from processing + * Clears the "isWindow" * - * @see DKTools.Layout.prototype.removeChild + * @private */ -DKTools.Layout.prototype.removeAllItems = function() { - this.removeChild.apply(this, this._items); +DKTools.Window.prototype._clearIsWindow = function() { + /** + * @private + * @readonly + * @type {Boolean} + */ + this._isWindow = true; }; /** - * Removes the item - * - * @param {DKTools.Sprite | *} item - Item - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * Clears the openness * - * @see DKTools.Layout.prototype.hasItem - * @see DKTools.Layout.prototype.removeChild - * @see DKTools.Utils.Array.remove - * @see DKTools.Layout.prototype.start + * @private + * + * @see DKTools.Window.prototype.standardOpenness */ -DKTools.Layout.prototype.removeItem = function(item, blockStart) { - if (!this.hasItem(item)) { - return; - } - this.removeChild(item); - DKTools.Utils.Array.remove(this._items, item); - if (!blockStart) { - this.start(); - } +DKTools.Window.prototype._clearOpenness = function() { + /** + * @private + * @readonly + * @type {Number} + */ + this._openness = this.standardOpenness(); }; /** - * Removes the items - * - * @param {Array} items - Items - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * Clears the padding * - * @see DKTools.Layout.prototype.removeItem - * @see DKTools.Layout.prototype.start + * @private + * + * @see DKTools.Window.prototype.standardPadding */ -DKTools.Layout.prototype.removeItems = function(items, blockStart) { - _.forEach(items, function(item) { - this.removeItem(item, true); - }.bind(this)); - if (!blockStart) { - this.start(); - } +DKTools.Window.prototype._clearPadding = function() { + /** + * @private + * @readonly + * @type {Number} + */ + this._padding = this.standardPadding(); }; /** - * Removes the item by index - * - * @param {Number} index - Index - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * Clears the margin * - * @see DKTools.Layout.prototype.getItem - * @see DKTools.Layout.prototype.removeItem + * @private + * + * @see DKTools.Window.prototype.standardMargin */ -DKTools.Layout.prototype.removeItemByIndex = function(index, blockStart) { - this.removeItem(this.getItem(index), blockStart); +DKTools.Window.prototype._clearMargin = function() { + /** + * @private + * @readonly + * @type {Number} + */ + this._margin = this.standardMargin(); }; /** - * Removes the columns + * Clears the color tone * - * @param {Number} cols - Columns + * @private + * + * @see DKTools.Window.prototype.standardTone + */ +DKTools.Window.prototype._clearColorTone = function() { + /** + * @private + * @readonly + * @type {Number[]} + */ + this._colorTone = this.standardTone(); +}; + +/** + * Clears the origin * - * @see DKTools.Layout.prototype.getMaxCols - * @see DKTools.Layout.prototype.addCols + * @private + * + * @see DKTools.Window.prototype.standardOrigin */ -DKTools.Layout.prototype.removeCols = function(cols) { - if (this.getMaxCols() - cols >= 1) { - this.addCols(-cols); - } +DKTools.Window.prototype._clearOrigin = function() { + /** + * @private + * @readonly + * @type {Point} + */ + this._origin = this.standardOrigin(); }; /** - * Removes the column + * Clears the arrows * - * @see DKTools.Layout.prototype.removeCols + * @private */ -DKTools.Layout.prototype.removeCol = function() { - this.removeCols(1); +DKTools.Window.prototype._clearArrows = function() { + /** + * @private + * @readonly + * @type {DKTools.Sprite.Arrow[]} + */ + this._arrows = []; }; -// add methods +// _create methods /** - * Adds children objects to processing + * Creates all * + * @private * @override + * + * @see DKTools.Base.prototype._createAll + * @see DKTools.Window.prototype._createAllParts + * @see DKTools.Window.prototype._createWindowskin */ -DKTools.Layout.prototype.addAllChildren = function() { - DKTools.Sprite.prototype.addAllChildren.call(this); - this.addAllItems(); +DKTools.Window.prototype._createAll = function() { + DKTools.Base.prototype._createAll.call(this); + this._createAllParts(); + this._createWindowskin(); }; /** - * Adds the itemns to processing + * Creates all parts of the window * - * @see DKTools.Layout.prototype.addChild + * @private + * @override + * + * @see DKTools.Window.prototype._createSpriteContainer + * @see DKTools.Window.prototype._createBackSprite + * @see DKTools.Window.prototype._createFrameSprite + * @see DKTools.Window.prototype._createPauseSignSprite */ -DKTools.Layout.prototype.addAllItems = function() { - this.addChild.apply(this, this._items); +DKTools.Window.prototype._createAllParts = function() { + this._createSpriteContainer(); + this._createBackSprite(); + this._createFrameSprite(); + this._createPauseSignSprite(); }; /** - * Adds the item + * Creates the container of the sprites * - * @param {DKTools.Sprite | *} item - Item - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @private + * + * @see PIXI.Container + */ +DKTools.Window.prototype._createSpriteContainer = function() { + /** + * @private + * @readonly + * @type {PIXI.Container} + */ + this._windowSpriteContainer = new PIXI.Container(); +}; + +/** + * Creates the sprite of the background * - * @see DKTools.Layout.prototype.start + * @private + * + * @see DKTools.Window.prototype.needsCreateBackSprite + * @see DKTools.Window.prototype.standardBackOpacity + * @see DKTools.Window.prototype.standardBackVisible */ -DKTools.Layout.prototype.addItem = function(item, blockStart) { - if (!(item instanceof DKTools.Sprite)) { - return; - } - this._items.push(item); - if (!blockStart) { - this.start(); +DKTools.Window.prototype._createBackSprite = function() { + if (this.needsCreateBackSprite()) { + /** + * @private + * @readonly + * @type {Sprite} + */ + this._windowBackSprite = new Sprite(); + this._windowBackSprite.opacity = this.standardBackOpacity(); + this._windowBackSprite.visible = this.standardBackVisible(); } }; /** - * Adds the items - * - * @param {DKTools.Sprite[] | *} items - Items - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * Creates the sprtie of the frame * - * @see DKTools.Layout.prototype.addItem - * @see DKTools.Layout.prototype.start + * @private + * + * @see DKTools.Window.prototype.needsCreateFrameSprite + * @see DKTools.Window.prototype.standardFrameVisible */ -DKTools.Layout.prototype.addItems = function(items, blockStart) { - _.forEach(items, function(item) { - this.addItem(item, true); - }.bind(this)); - if (!blockStart) { - this.start(); +DKTools.Window.prototype._createFrameSprite = function() { + if (this.needsCreateFrameSprite()) { + /** + * @private + * @readonly + * @type {Sprite} + */ + this._windowFrameSprite = new Sprite(); + this._windowFrameSprite.visible = this.standardFrameVisible(); } }; /** - * Adds the columns - * - * @param {Number} cols - Columns + * Creates the sprite of the pause sign * - * @see DKTools.Layout.prototype.getMaxCols - * @see DKTools.Layout.prototype.setMaxCols + * @private + * + * @see DKTools.Window.prototype.needsCreatePauseSignSprite */ -DKTools.Layout.prototype.addCols = function(cols) { - this.setMaxCols(this.getMaxCols() + cols); +DKTools.Window.prototype._createPauseSignSprite = function() { + if (this.needsCreatePauseSignSprite()) { + /** + * @private + * @readonly + * @type {Sprite} + */ + this._windowPauseSignSprite = new Sprite(); + } }; /** - * Adds the column + * Creates the window skin * - * @see DKTools.Layout.prototype.addCols - */ -DKTools.Layout.prototype.addCol = function() { - this.addCols(1); -}; - -// can methods - -/** - * Returns true if the layout can clone the fixed bitmap + * @private * - * @override - * @returns {Boolean} Layout can clone the fixed bitmap + * @see DKTools.Window.prototype.loadWindowskin */ -DKTools.Layout.prototype.canCloneFixedBitmap = function() { - return false; +DKTools.Window.prototype._createWindowskin = function() { + this.windowskin = this.loadWindowskin(); }; -// _get methods +// _setup methods /** - * Returns the width of the bitmap - * - * @since 2.0.0 + * Sets the events + * * @private * @override - * - * @see DKTools.Layout.prototype.getMaxCols - * @see DKTools.Layout.prototype.getColWidth - * - * @returns {Number} Width of the bitmap + * + * @see DKTools.Base.prototype._setupEvents + * @see DKTools.Base.prototype.needsCreateArrowsSprites + * @see DKTools.Base.prototype._setupCreateArrowsEvent */ -DKTools.Layout.prototype._getBitmapWidth = function() { - let width = 0; - const maxCols = this.getMaxCols(); +DKTools.Window.prototype._setupEvents = function() { + DKTools.Base.prototype._setupEvents.call(this); - for (let i = 1; i <= maxCols; i++) { - width += this.getColWidth(i) + this._horizontalSpacing; + if (this.needsCreateArrowsSprites()) { + this._setupCreateArrowsEvent(); } - - return width - this._horizontalSpacing; }; /** - * Returns the height of the bitmap + * Sets the create arrows event * - * @since 2.0.0 * @private - * @override - * - * @see DKTools.Layout.prototype.getMaxRows - * @see DKTools.Layout.prototype.getRowHeight * - * @returns {Number} Height of the bitmap + * @see DKTools.Window.prototype.addOneTimeEvent */ -DKTools.Layout.prototype._getBitmapHeight = function() { - let height = 0; - const maxRows = this.getMaxRows(); - - for (let i = 1; i <= maxRows; i++) { - height += this.getRowHeight(i) + this._verticalSpacing; - } - - return height - this._verticalSpacing; +DKTools.Window.prototype._setupCreateArrowsEvent = function() { + this.addOneTimeEvent({ + type: 'create-all', + onSuccess: this.createArrows.bind(this) + }); }; -// get methods +// _add methods /** - * Returns the maximum number of rows + * Adds children objects to processing * - * @see DKTools.Layout.prototype.getMaxItems - * @see DKTools.Layout.prototype.getMaxCols + * @private + * @override * - * @returns {Number} Maximum number of rows + * @see DKTools.Base.prototype._addAllChildren + * @see DKTools.Window.prototype._addAllParts */ -DKTools.Layout.prototype.getMaxRows = function() { - return Math.max(1, Math.ceil(this.getMaxItems() / this.getMaxCols())); +DKTools.Window.prototype._addAllChildren = function() { + DKTools.Base.prototype._addAllChildren.call(this); + this._addAllParts(); }; /** - * Returns the maximum number of columns + * Adds all parts of the window to processing * - * @returns {Number} Maximum number of columns + * @private + * + * @see DKTools.Window.prototype._addSpriteContainer + * @see DKTools.Window.prototype._addPauseSignSprite */ -DKTools.Layout.prototype.getMaxCols = function() { - return this._maxCols; +DKTools.Window.prototype._addAllParts = function() { + this._addSpriteContainer(); + this._addPauseSignSprite(); }; /** - * Returns the items - * - * @see DKTools.Layout.prototype.isInverted + * Adds the container of the sprites to processing * - * @returns {DKTools.Sprite[] | *} Items + * @private + * + * @see DKTools.Window.prototype.hasSpriteContainer + * @see DKTools.Window.prototype.hasBackSprite + * @see DKTools.Window.prototype.hasFrameSprite */ -DKTools.Layout.prototype.getItems = function() { - if (this.isInverted()) { - return _.reverse(_.clone(this._items)); - } +DKTools.Window.prototype._addSpriteContainer = function() { + if (this.hasSpriteContainer()) { + if (this.hasBackSprite()) { + this._windowSpriteContainer.addChild(this._windowBackSprite); + } - return this._items; -}; + if (this.hasFrameSprite()) { + this._windowSpriteContainer.addChild(this._windowFrameSprite); + } -/** - * Returns the number of the items - * - * @return {Number} Number of the items - */ -DKTools.Layout.prototype.getMaxItems = function() { - return this._items.length; + this.addChild(this._windowSpriteContainer); + } }; /** - * Returns the index of the item - * - * @param {DKTools.Sprite | *} item - Item - * - * @see DKTools.Layout.prototype.getItems + * Adds the sprite of the contents to processing * - * @returns {Number} Index of the item + * @private + * + * @see DKTools.Window.prototype.hasContentsSprite */ -DKTools.Layout.prototype.getItemIndex = function(item) { - return _.indexOf(this.getItems(), item); +DKTools.Window.prototype._addContentsSprite = function() { + if (this.hasContentsSprite()) { + this.addChild(this._windowContentsSprite); + } }; /** - * Returns the item by index - * - * @param {Number} index - Index - * - * @see DKTools.Layout.prototype.getItems + * Adds the sprite of the pause sign to processing * - * @returns {DKTools.Sprite | * | undefined} Item by index or undefined + * @private + * + * @see DKTools.Window.prototype.hasPauseSignSprite */ -DKTools.Layout.prototype.getItem = function(index) { - return index >= 0 ? this.getItems()[index] : undefined; +DKTools.Window.prototype._addPauseSignSprite = function() { + if (this.hasPauseSignSprite()) { + this.addChild(this._windowPauseSignSprite); + } }; +// standard methods + /** - * Returns the items in the row - * - * @param {Number} row - Row - * - * @see DKTools.Layout.prototype.getMaxCols - * @see DKTools.Layout.prototype.getMaxRows - * @see DKTools.Layout.prototype.getItem + * Returns the standard openness of the window * - * @returns {DKTools.Sprite[] | *} Items in the row + * @returns {Number} Standard openness of the window */ -DKTools.Layout.prototype.getItemsInRow = function(row) { - const items = []; - const maxCols = this.getMaxCols(); - - if (row < 1 || row > this.getMaxRows()) { - return items; - } - - const startIndex = maxCols * (row - 1); - - for(let i = 0; i < maxCols; i++) { - const item = this.getItem(startIndex + i); - items.push(item); - } - - return items; +DKTools.Window.prototype.standardOpenness = function() { + return 255; }; /** - * Returns the items in the column - * - * @param {Number} col - Column - * - * @see DKTools.Layout.prototype.getMaxRows - * @see DKTools.Layout.prototype.getMaxCols - * @see DKTools.Layout.prototype.getItem + * Returns the standard openness speed of the window * - * @returns {DKTools.Sprite[] | *} Items in the column - */ -DKTools.Layout.prototype.getItemsInCol = function(col) { - const items = []; - const maxRows = this.getMaxRows(); - const maxCols = this.getMaxCols(); - - if (col < 1 || col > maxCols) { - return items; - } - - const startIndex = col - 1; - - for(let i = 0; i < maxRows; i++) { - const item = this.getItem(startIndex + maxCols * i); - items.push(item); - } - - return items; + * @returns {Number} Standard openness speed of the window + */ +DKTools.Window.prototype.standardOpennessSpeed = function() { + return 16; }; /** - * Returns the height of the row + * Returns the standard margin of the window * - * @param {Number} row - Row - * @returns {Number} Height of the row + * @returns {Number} Standard margin of the window */ -DKTools.Layout.prototype.getRowHeight = function(row) { - if (DKTools.Utils.isFunction(this._rowHeight)) { - return this._rowHeight(row); - } - - return this._rowHeight; +DKTools.Window.prototype.standardMargin = function() { + return 4; }; /** - * Returns the width of the column + * Returns the standard origin of the window * - * @param {Number} col - Column - * @returns {Number} Width of the column + * @returns {Point} Standard origin of the window */ -DKTools.Layout.prototype.getColWidth = function(col) { - if (DKTools.Utils.isFunction(this._colWidth)) { - return this._colWidth(col); - } - - return this._colWidth; +DKTools.Window.prototype.standardOrigin = function() { + return new Point(0, 0); }; /** - * Returns the Y coordinate of the row - * - * @param {Number} row - Row - * - * @see DKTools.Layout.prototype.getRowHeight + * Returns the standard normal state of the arrow * - * @returns {Number} The Y coordinate of the row + * @returns {Function} Standard normal state of the arrow */ -DKTools.Layout.prototype.getRowY = function(row) { - let y = 0; - - for(let i = 1; i < row; i++) { - y += this.getRowHeight(i) + this._verticalSpacing; - } - - return y; +DKTools.Window.prototype.standardArrowStateNormal = function() { + return function(event) { + const arrow = event.target; + arrow.setScale(1, 1); + arrow.setOpacity(255); + }; }; /** - * Returns the X coordinate of the column - * - * @param {Number} col - Column - * - * @see DKTools.Layout.prototype.getColWidth + * Returns the standard pressed state of the arrow * - * @returns {Number} The X coordinate of the column + * @returns {Function} Standard pressed state of the arrow */ -DKTools.Layout.prototype.getColX = function(col) { - let x = 0; - - for(let i = 1; i < col; i++) { - x += this.getColWidth(i) + this._horizontalSpacing; - } - - return x; +DKTools.Window.prototype.standardArrowStatePressed = function() { + return function(event) { + const arrow = event.target; + arrow.setScale(0.9, 0.9); + arrow.setOpacity(160); + }; }; /** - * Returns the row of the item - * - * @param {DKTools.Sprite | *} item - Item - * - * @see DKTools.Layout.prototype.getItemIndex - * @see DKTools.Layout.prototype.getMaxCols + * Returns the standard sprite of the contents * - * @returns {Number} Row of the item or -1 + * @returns {DKTools.Sprite} Standard sprite of the contents */ -DKTools.Layout.prototype.getItemRow = function(item) { - const index = this.getItemIndex(item); - - if (index >= 0) { - return Math.floor(index / this.getMaxCols()) + 1; - } - - return -1; +DKTools.Window.prototype.standardContentsSprite = function() { + return new DKTools.Sprite(); }; /** - * Returns the column of the item - * - * @param {DKTools.Sprite | *} item - Item - * - * @see DKTools.Layout.prototype.getItemIndex - * @see DKTools.Layout.prototype.getMaxCols + * Returns the standard X coordinate of the child * - * @returns {Number} Column of the item or -1 + * @returns {Number} Standard X coordinate of the child */ -DKTools.Layout.prototype.getItemCol = function(item) { - const index = this.getItemIndex(item); - - if (index >= 0) { - return (index % this.getMaxCols()) + 1; - } - - return -1; +DKTools.Window.prototype.standardChildX = function() { + return this.standardPadding(); }; /** - * Returns the cell by row and column - * - * @param {Number} row - Row - * @param {Number} col - Col - * - * @see DKTools.Layout.prototype.getMaxCols - * @see DKTools.Layout.prototype.getColX - * @see DKTools.Layout.prototype.getRowY - * @see DKTools.Layout.prototype.getColWidth - * @see DKTools.Layout.prototype.getRowHeight + * Returns the standard Y coordinate of the child * - * @returns {{ item: (DKTools.Sprite | * | undefined), x: Number, y: Number, width: Number, height: Number }} + * @returns {Number} Standard Y coordinate of the child */ -DKTools.Layout.prototype.getCell = function(row, col) { - const index = this.getMaxCols() * (row - 1) + (col - 1); - - return { - item: this.getItem(index), - x: this.getColX(col), - y: this.getRowY(row), - width: this.getColWidth(col), - height: this.getRowHeight(row) - }; +DKTools.Window.prototype.standardChildY = function() { + return this.standardPadding(); }; -// move methods - /** - * Moves the item - * - * @param {Number} index - Index - * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object] - The X coordinate or Point or object with parameters - * @param {Number} [y] - The Y coordinate (if object is Number) - * - * @param {Number} [object.x] - The X coordinate - * @param {Number} [object.y] - The Y coordinate + * Returns the standard position of the child * - * @see DKTools.Layout.prototype.getItem - * @see DKTools.Sprite.prototype.move + * @returns {Point} Standard position of the child */ -DKTools.Layout.prototype.moveItem = function(index, object, y) { - const item = this.getItem(index); - - if (item) { - item.move(object, y); - } +DKTools.Window.prototype.standardChildPosition = function() { + return new Point(this.standardChildX(), this.standardChildY()); }; -// invert methods - /** - * Inverts the layout + * Returns the standard position of the contents * - * @see DKTools.Layout.prototype.isInverted - * @see DKTools.Layout.prototype.setInverted + * @returns {Point} Standard position of the contents */ -DKTools.Layout.prototype.invert = function() { - this.setInverted(!this.isInverted()); +DKTools.Window.prototype.standardContentsPosition = function() { + return this.standardChildPosition(); }; -// is methods - /** - * Returns true if the layout is empty - * - * @see DKTools.Layout.prototype.getMaxItems + * Returns the standard visibility of the background * - * @returns {Boolean} Layout is empty + * @returns {Boolean} Standard visibility of the background */ -DKTools.Layout.prototype.isEmpty = function() { - return this.getMaxItems() === 0; +DKTools.Window.prototype.standardBackVisible = function() { + return true; }; /** - * Returns true if the layout is ready + * Returns the standard visibility of the frame * - * @override + * @returns {Boolean} Standard visibility of the frame + */ +DKTools.Window.prototype.standardFrameVisible = function() { + return true; +}; + +/** + * Returns the standard width of the contents * - * @see DKTools.Layout.prototype.isEmpty + * @returns {Function} Standard width of the contents + */ +DKTools.Window.prototype.standardContentsWidth = function() { + return function() { + return this._width - this.standardPadding() * 2; + }.bind(this); +}; + +/** + * Returns the standard height of the contents * - * @returns {Boolean} Layout is ready -*/ -DKTools.Layout.prototype.isReady = function() { - return this.isEmpty() || _.every(this._items, function(item) { - return item.isReady(); - }); + * @returns {Function} Standard height of the contents + */ +DKTools.Window.prototype.standardContentsHeight = function() { + return function() { + return this._height - this.standardPadding() * 2; + }.bind(this); }; /** - * Returns true if the layout is inverted + * Returns the standard opacity of the window * - * @returns {Boolean} Layout is inverted + * @returns {Number} Standard opacity of the window */ -DKTools.Layout.prototype.isInverted = function() { - return this._inverted; +DKTools.Window.prototype.standardWindowOpacity = function() { + return 255; }; /** - * Returns true if the layout is horizontal + * Returns the standard opacity of the contents * - * @see DKTools.Layout.prototype.getMaxRows + * @returns {Number} Standard opacity of the contents + */ +DKTools.Window.prototype.standardContentsOpacity = function() { + return 255; +}; + +/** + * Returns the standard opacity of the frame * - * @returns {boolean} Layout is horizontal + * @returns {Number} Standard opacity of the frame */ -DKTools.Layout.prototype.isHorizontal = function() { - return this.getMaxRows() === 1; +DKTools.Window.prototype.standardFrameOpacity = function() { + return 255; }; /** - * Returns true if the layout is vertical + * Returns the standard opacity * - * @see DKTools.Layout.prototype.getMaxCols + * @see DKTools.Window.prototype.standardWindowOpacity + * @see DKTools.Window.prototype.standardContentsOpacity + * @see DKTools.Window.prototype.standardFrameOpacity + * @see DKTools.Window.prototype.standardBackOpacity * - * @returns {boolean} Layout is vertical + * @returns {Object} Standard opacity */ -DKTools.Layout.prototype.isVertical = function() { - return this.getMaxCols() === 1; +DKTools.Window.prototype.standardOpacity = function() { + return { + windowOpacity: this.standardWindowOpacity(), + contentsOpacity: this.standardContentsOpacity(), + frameOpacity: this.standardFrameOpacity(), + backOpacity: this.standardBackOpacity() + }; }; -// has methods - /** - * Returns true if the layout has the items - * - * @see DKTools.Layout.prototype.isEmpty + * Returns the standard tone of the window * - * @returns {Boolean} Layout has the items + * @returns {Number[]} Standard tone of the window */ -DKTools.Layout.prototype.hasItems = function() { - return !this.isEmpty(); +DKTools.Window.prototype.standardTone = function() { + try { + return $gameSystem.windowTone(); + } catch(e) { + } + + return [0, 0, 0]; }; +// setup methods + /** - * Returns true if the layout has the item + * Sets all parameters * - * @param {DKTools.Sprite | *} item - Item + * @override * - * @see DKTools.Layout.prototype.getItemIndex + * @param {Object} [object={}] - Parameters * - * @returns {Boolean} Layout has the item - */ -DKTools.Layout.prototype.hasItem = function(item) { - return this.getItemIndex(item) >= 0; -}; - -// items methods - -/** - * Calls the callback function for the items + * @param {Function | Number} [object.contentsWidth] - Width of thw window + * @param {Function | Number} [object.contentsHeight] - Height of thw window + * @param {Object} [object.opacity] - Opacity of the window + * @param {Number[]} [object.tone] - Tone of the window * - * @param {Function} callback - Function for the items - * @param {Boolean} [start=false] - Call of the "start" function + * @param {Number} [opacity.windowOpacity] - Opacity of the window + * @param {Number} [opacity.contentsOpacity] - Opacity of the contents + * @param {Number} [opacity.frameOpacity] - Opacity of the frame + * @param {Number} [opacity.backOpacity] - Opacity of the background * - * @see DKTools.Layout.prototype.getItems - * @see DKTools.Layout.prototype.start + * @see DKTools.Base.prototype.setupAll + * @see DKTools.Window.prototype.setupContentsWidth + * @see DKTools.Window.prototype.setupContentsHeight + * @see DKTools.Window.prototype.setupContentsSprite + * @see DKTools.Window.prototype.setupContentsPosition + * @see DKTools.Window.prototype.setupOpacity + * @see DKTools.Window.prototype.setupTone */ -DKTools.Layout.prototype.iterateItems = function(callback, start) { - _.forEach(this.getItems(), callback); +DKTools.Window.prototype.setupAll = function(object) { + object = object || {}; + DKTools.Base.prototype.setupAll.call(this, object); + let contentsSprite = object.contentsSprite; - if (start) { - this.start(); + if (object instanceof DKTools.Window && contentsSprite instanceof DKTools.Sprite) { + contentsSprite = contentsSprite.clone({ blockStart: true }); } + + this.setupContentsWidth(object.contentsWidth); + this.setupContentsHeight(object.contentsHeight); + this.setupContentsSprite(contentsSprite); + this.setupContentsPosition(object.contentsPosition); + this.setupOpacity(object.opacity); + this.setupTone(object.tone); }; /** - * Starts the items - * - * @param {Boolean} [activate=false] - Activates the item - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * Sets the width of the window * - * @see DKTools.Layout.prototype.iterateItems -*/ -DKTools.Layout.prototype.startItems = function(activate, blockStart) { - const callback = function(item) { - item.start(activate); - }; - this.iterateItems(callback, !blockStart); + * @param {Number} [width] - Width of the window + * + * @see DKTools.Window.prototype._checkWidth + */ +DKTools.Window.prototype.setupWidth = function(width) { + this.realWidth = this._checkWidth(width); }; /** - * Resizes the item - * - * @param {DKTools.Sprite | *} item - Item - * @param {Number} [width] - Width of the item - * @param {Number} [height] - Height of the item - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * Sets the height of the window * - * @see DKTools.Layout.prototype.hasItem - * @see DKTools.Layout.prototype.start + * @param {Number | String} [height] - Height of the window of number of lines (String) + * + * @see DKTools.Window.prototype._checkHeight */ -DKTools.Layout.prototype.resizeItem = function(item, width, height, blockStart) { - if (this.hasItem(item) && item.resize(width, height)) { - if (!blockStart) { - this.start(); - } +DKTools.Window.prototype.setupHeight = function(height) { + if (DKTools.Utils.isString(height)) { + height = this.getLineHeight() * Number(height); } + + this.realHeight = this._checkHeight(height); }; /** - * Resizes the item by index + * Sets the size of the window * - * @param {Number} index - Index - * @param {Number} [width] - Width of the item - * @param {Number} [height] - Height of the item - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Number | Object} [object] - Width of the window or object with parameters + * @param {Number | String} [height] - Height of the window or number of lines (String) (if object is Number) * - * @see DKTools.Layout.prototype.getItem - * @see DKTools.Layout.prototype.resizeItem + * @param {Number} [object.width] - Width of the window + * @param {Number | String} [object.height] - Height of the window or number of lines (String) + * + * @see DKTools.Window.prototype.getLineHeight + * @see DKTools.Window.prototype._checkWidth + * @see DKTools.Window.prototype._checkHeight + * @see Window.prototype.move */ -DKTools.Layout.prototype.resizeItemByIndex = function(index, width, height, blockStart) { - this.resizeItem(this.getItem(index), width, height, blockStart); -}; +DKTools.Window.prototype.setupSize = function(object, height) { + if (object instanceof Object) { + return this.setupSize(object.width, object.height); + } -/** - * Resizes the items - * - * @param {Number} [width] - Width of the item - * @param {Number} [height] - Height of the item - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * - * @see DKTools.Layout.prototype.resizeItem - * @see DKTools.Layout.prototype.iterateItems -*/ -DKTools.Layout.prototype.resizeItems = function(width, height, blockStart) { - const callback = function(item) { - this.resizeItem(item, width, height, true); - }.bind(this); - this.iterateItems(callback, !blockStart); -}; + if (DKTools.Utils.isString(height)) { + height = this.getLineHeight() * Number(height); + } -/** - * Activates the items - * - * @param {Boolean} [start=false] - Call of the "start" function - * - * @see DKTools.Layout.prototype.iterateItems -*/ -DKTools.Layout.prototype.activateItems = function(start) { - const callback = function(item) { - item.activate(); - }; - this.iterateItems(callback, start); + // object - Number + object = this._checkWidth(object); + height = this._checkHeight(height); + + Window.prototype.move.call(this, this.x, this.y, object, height); }; /** - * Deactivates the items + * Sets the width of the contents * - * @param {Boolean} [start=false] - Call of the "start" function + * @param {Function | Number} [contentsWidth=this.standardContentsWidth()] - Width of the contents * - * @see DKTools.Layout.prototype.iterateItems -*/ -DKTools.Layout.prototype.deactivateItems = function(start) { - const callback = function(item) { - item.deactivate(); - }; - this.iterateItems(callback, start); + * @see DKTools.Window.prototype.standardContentsWidth + */ +DKTools.Window.prototype.setupContentsWidth = function(contentsWidth) { + this._contentsWidth = contentsWidth || this.standardContentsWidth(); }; /** - * Shows the items + * Sets the height of the contents * - * @param {Boolean} [activate=false] - Activates the items - * @param {Boolean} [start=false] - Call of the "start" function + * @param {Function | Number} [contentsHeight=this.standardContentsHeight()] - Height of the contents * - * @see DKTools.Layout.prototype.iterateItems + * @see DKTools.Window.prototype.standardContentsHeight */ -DKTools.Layout.prototype.showItems = function(activate, start) { - const callback = function(item) { - item.show(activate); - }; - this.iterateItems(callback, start); +DKTools.Window.prototype.setupContentsHeight = function(contentsHeight) { + this._contentsHeight = contentsHeight || this.standardContentsHeight(); }; /** - * Hides the items + * Sets the sprite of the contents * - * @param {Boolean} [blockDeactivate=false] - Block deactivation of the items - * @param {Boolean} [start=false] - Call of the "start" function + * @param {DKTools.Sprite | *} [contentsSprite=this.standardContentsSprite()] - Sprite of the contents * - * @see DKTools.Layout.prototype.iterateItems + * @see DKTools.Window.prototype.standardContentsSprite */ -DKTools.Layout.prototype.hideItems = function(blockDeactivate, start) { - const callback = function(item) { - item.hide(blockDeactivate); - }; - this.iterateItems(callback, start); +DKTools.Window.prototype.setupContentsSprite = function(contentsSprite) { + /** + * @private + * @readonly + * @type {DKTools.Sprite | *} + */ + this._windowContentsSprite = contentsSprite || this.standardContentsSprite(); }; -// align methods - /** - * Aligns the item + * Sets the position of the contents * - * @param {DKTools.Sprite | * | Number} item - Item or index + * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object=this.standardContentsPosition()] - The X coordinate or Point or object with parameters + * @param {Number} [y=undefined] - The Y coordinate (if object is Number) * - * @see DKTools.Layout.prototype.isReady - * @see DKTools.Layout.prototype.getItemRow - * @see DKTools.Layout.prototype.getItemCol - * @see DKTools.Layout.prototype.getRowHeight - * @see DKTools.Layout.prototype.getColWidth - * @see DKTools.Layout.prototype.getColX - * @see DKTools.Layout.prototype.getRowY - * @see DKTools.Layout.prototype.addOneTimeEvent + * @param {Number} [object.x] - The X coordinate + * @param {Number} [object.y] - The Y coordinate + * + * @see DKTools.Utils.Point.toPoint + * @see DKTools.Utils.Point.standardContentsPosition */ -DKTools.Layout.prototype.alignItem = function(item) { - if (this.isReady()) { - const itemRow = this.getItemRow(item); - const itemCol = this.getItemCol(item); - const rowHeight = this.getRowHeight(itemRow); - const colWidth = this.getColWidth(itemCol); - const x = this.getColX(itemCol) + (colWidth - item.width) / 2; - const y = this.getRowY(itemRow) + (rowHeight - item.height) / 2; - item.move(x, y); - } else { - this.addOneTimeEvent({ - type: 'ready', - onSuccess: this.alignItem.bind(this, item) - }); - } +DKTools.Window.prototype.setupContentsPosition = function(object, y) { + const position = DKTools.Utils.Point.toPoint(object, y); + const newPosition = Object.assign(this.standardContentsPosition(), position); + + /** + * @private + * @readonly + * @type {Point} + */ + this._contentsPosition = new Point(newPosition.x, newPosition.y); }; /** - * Aligns the row + * Sets the opacity of the window * - * @param {Number} row - Row + * @param {Object} [opacity=this.standardOpacity()] - Opacity of the window * - * @see DKTools.Layout.prototype.getItemsInRow - * @see DKTools.Layout.prototype.alignItem + * @param {Number} [opacity.windowOpacity] - Opacity of the window + * @param {Number} [opacity.contentsOpacity] - Opacity of the contents + * @param {Number} [opacity.frameOpacity] - Opacity of the frame + * @param {Number} [opacity.backOpacity] - Opacity of the background + * + * @see DKTools.Window.prototype.standardOpacity */ -DKTools.Layout.prototype.alignRow = function(row) { - const items = this.getItemsInRow(row); - _.forEach(items, this.alignItem.bind(this)); +DKTools.Window.prototype.setupOpacity = function(opacity) { + /** + * @private + * @type {Object} + */ + this._opacity = Object.assign(this.standardOpacity(), opacity); }; /** - * Aligns the column + * Sets the tone of the window * - * @param {Number} col - Column + * @param {Number[]} [tone=this.standardTone()] - Tone of the window * - * @see DKTools.Layout.prototype.getItemsInCol - * @see DKTools.Layout.prototype.alignItem + * @see DKTools.Window.prototype.standardTone */ -DKTools.Layout.prototype.alignCol = function(col) { - const items = this.getItemsInCol(col); - _.forEach(items, this.alignItem.bind(this)); -}; +DKTools.Window.prototype.setupTone = function(tone) { + const standardTone = _.clone(this.standardTone()); -/** - * Aligns the items - * - * @see DKTools.Layout.prototype.addOneTimeEvent - * @see DKTools.Layout.prototype.iterateItems - * @see DKTools.Layout.prototype.alignItem - */ -DKTools.Layout.prototype.alignItems = function() { - this.addOneTimeEvent({ - type: 'ready', - onSuccess: function() { - this.iterateItems(this.alignItem.bind(this)) - }.bind(this) - }); + /** + * @private + * @type {Number[]} + */ + this._tone = Object.assign(standardTone, tone); }; -// update methods +// set methods /** - * Updates all + * Changes all parameters + * Returns the number of changed parameters * * @override * - * @see DKTools.Sprite.prototype.updateAll - * @see DKTools.Layout.prototype.updateLayout - */ -DKTools.Layout.prototype.updateAll = function() { - DKTools.Sprite.prototype.updateAll.call(this); - this.updateLayout(); -}; - -/** - * Updates the layout + * @param {Object} [object] - Parameters + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [activate=false] - Activates the window * - * @see DKTools.Layout.prototype.getMaxItems - * @see DKTools.Layout.prototype.getMaxRows - * @see DKTools.Layout.prototype.getMaxCols - * @see DKTools.Layout.prototype.getColX - * @see DKTools.Layout.prototype.getRowY - * @see DKTools.Layout.prototype.moveItem -*/ -DKTools.Layout.prototype.updateLayout = function() { - const maxItems = this.getMaxItems(); - const maxRows = this.getMaxRows(); - const maxCols = this.getMaxCols(); - let index = 0; - - for(let i = 1; i <= maxRows && index < maxItems; i++) { - for(let j = 1; j <= maxCols && index < maxItems; j++) { - const x = this.getColX(j); - const y = this.getRowY(i); - this.moveItem(index++, x, y); - } + * @param {Object} [object.opacity] - Opacity of the window + * @param {Number[]} [object.tone] - Tone of the window + * + * @param {Number} [object.opacity.windowOpacity] - Opacity of the window + * @param {Number} [object.opacity.contentsOpacity] - Opacity of the contents + * @param {Number} [object.opacity.frameOpacity] - Opacity of the frame + * @param {Number} [object.opacity.backOpacity] - Opacity of the background + * + * @see DKTools.Base.prototype.setAll + * @see DKTools.Window.prototype.setOpacity + * @see DKTools.Window.prototype.setTone + * @see DKTools.Window.prototype.start + * @see DKTools.Window.prototype.activate + * + * @returns {Number} Number of changed parameters + */ +DKTools.Window.prototype.setAll = function(object, blockStart, activate) { + object = object || {}; + const block = true; + let changed = DKTools.Base.prototype.setAll.call(this, object, block); + + if (this.setOpacity(object.opacity, block)) { + changed++; } -}; - - + if (this.setTone(object.tone, block)) { + changed++; + } + if (changed) { + if (!blockStart) { + this.start(); + } -//=========================================================================== -// DKTools.Window -//=========================================================================== + if (activate) { + this.activate(); + } + } -DKTools.Window.prototype = Object.create(Window_Base.prototype); -DKTools.Utils.mixin(DKTools.Window.prototype, DKTools.Base.prototype); -DKTools.Window.prototype.constructor = DKTools.Window; + return changed; +}; /** - * Counter of created windows + * Changes the width of the window + * Returns true if the change occurred * - * @private - * @readonly - * @type {Number} - * @memberOf DKTools.Window + * @param {Number} [width] - Width of the window + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [activate=false] - Activates the window + * + * @see DKTools.Window.prototype.resize + * + * @returns {Boolean} Change occurred */ -DKTools.Window._counter = 0; - -// properties - -Object.defineProperties(DKTools.Window.prototype, { +DKTools.Window.prototype.setWidth = function(width, blockStart, activate) { + return this.resize(width, this._height, blockStart, activate); +}; - /** - * Real width of the window (not including scaling) - * - * @readonly - * @type {Number} - * @memberOf DKTools.Window.prototype - */ - realWidth: { - get: function() { - return this._width; - }, - set: function(value) { - this._width = value; - this._refreshAllParts(); - }, - configurable: true - }, +/** + * Changes the height of the window + * Returns true if the change occurred + * + * @param {Number} [height] - Height of the window + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [activate=false] - Activates the window + * + * @see DKTools.Window.prototype.resize + * + * @returns {Boolean} Change occurred + */ +DKTools.Window.prototype.setHeight = function(height, blockStart, activate) { + return this.resize(this._width, height, blockStart, activate); +}; - /** - * Real height of the window (not including scaling) - * - * @readonly - * @type {Number} - * @memberOf DKTools.Window.prototype - */ - realHeight: { - get: function() { - return this._height; - }, - set: function(value) { - this._height = value; - this._refreshAllParts(); - }, - configurable: true - }, +/** + * Changes the sprite of the contents + * Returns true if the change occurred + * + * @param {DKTools.Sprite | *} [contentsSprite] + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [activate=false] - Activates the window + * + * @see DKTools.Window.prototype.removeContentsSprite + * @see DKTools.Window.prototype.setupContentsSprite + * @see DKTools.Window.prototype.addContentsSprite + * @see DKTools.Window.prototype.activate + * + * @returns {Boolean} Change occurred + */ +DKTools.Window.prototype.setContentsSprite = function(contentsSprite, blockStart, activate) { + if (this._windowContentsSprite == contentsSprite) { + return false; + } - /** - * Width of the window (taking into account scaling) - * - * @type {Number} - * @memberOf DKTools.Window.prototype - */ - width: { - get: function() { - return this.realWidth * this.scale.x; - }, - set: function(value) { - this._width = Math.floor(value / this.scale.x); - this._refreshAllParts(); - }, - configurable: true - }, + // TODO: проверить + this.removeContentsSprite(); + this.setupContentsSprite(contentsSprite); + this.addContentsSprite(); - /** - * Height of the window (taking into account scaling) - * - * @type {Number} - * @memberOf DKTools.Window.prototype - */ - height: { - get: function() { - return this.realHeight * this.scale.y; - }, - set: function(value) { - this._height = Math.floor(value / this.scale.y); - this._refreshAllParts(); - }, - configurable: true - }, + if (!blockStart) { + this.start(); + } - /** - * Origin - * - * @readonly - * @type {Point} - * @memberOf DKTools.Window.prototype - */ - origin: { - get: function() { - return this._origin; - }, - configurable: true - }, + if (activate) { + this.activate(); + } - /** - * Opacity of the window - * - * @type {Number} - * @memberOf DKTools.Window.prototype - */ - windowOpacity: { - get: function() { - return this._windowSpriteContainer.alpha * 255; - }, - set: function(value) { - this._windowSpriteContainer.alpha = _.clamp(value, 0, 255) / 255; - }, - configurable: true - }, + return true; +}; - /** - * Opacity of the frame - * - * @type {Number} - * @memberOf DKTools.Window.prototype - */ - frameOpacity: { - get: function() { - return this._windowFrameSprite.alpha * 255; - }, - set: function(value) { - this._windowFrameSprite.alpha = _.clamp(value, 0, 255) / 255; - }, - configurable: true - }, +/** + * Changes the position of the contents + * Returns true if the change occurred + * + * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object] - The X coordinate or Point or object with parameters + * @param {Number} [y=undefined] - The Y coordinate (if object is Number) + * + * @param {Number} [object.x] - The X coordinate + * @param {Number} [object.y] - The Y coordinate + * + * @see DKTools.Utils.Point.toPoint + * @see DKTools.Utils.Point.equals + * @see DKTools.Utils.Point.clone + * @see DKTools.Window.prototype.setupContentsPosition + * @see DKTools.Window.prototype._refreshContents + * + * @returns {Boolean} Change occurred + */ +DKTools.Window.prototype.setContentsPosition = function(object, y) { + if (object instanceof Object) { + return this.setContentsPosition(object, y); + } - /** - * Opacity of the window - * - * @readonly - * @type {Object} - * @memberOf DKTools.Window.prototype - */ - opacity: { - get: function() { - return this._opacity; - }, - configurable: true - }, + // object - Number + const newPos = DKTools.Utils.Point.toPoint(object, y); - /** - * Tone of the window - * - * @readonly - * @type {Number[]} - * @memberOf DKTools.Window.prototype - */ - tone: { - get: function() { - return this._tone; - }, - configurable: true - }, + if (DKTools.Utils.Point.equals(this._contentsPosition, newPos)) { + return false; + } - /** - * Sprite of the contents - * - * @readonly - * @type {DKTools.Sprite} - * @memberOf DKTools.Window.prototype - */ - contentsSprite: { - get: function() { - return this._windowContentsSprite; - }, - configurable: true - }, + const lastPos = DKTools.Utils.Point.clone(this._contentsPosition); + this.setupContentsPosition(newPos); - /** - * Sprite of the frame - * - * @readonly - * @type {Sprite} - * @memberOf DKTools.Window.prototype - */ - frameSprite: { - get: function() { - return this._windowFrameSprite; - }, - configurable: true - }, + if (!DKTools.Utils.Point.equals(this._contentsPosition, lastPos)) { + this._refreshContents(); + return true; + } - /** - * Sprite of the background - * - * @readonly - * @type {Sprite} - * @memberOf DKTools.Window.prototype - */ - backSprite: { - get: function() { - return this._windowBackSprite; - }, - configurable: true - }, + return false; +}; - /** - * Bitmap of sprite of the contents - * To support functions from DKTools.Base - * - * @type {Bitmap} - * @memberOf DKTools.Window.prototype - */ - bitmap: { - get: function() { - return this.contents; - }, - set: function(value) { - this.contents = value; - }, - configurable: true +/** + * Changes the opacity of the window + * Returns true if the change occurred + * + * @param {Object} [opacity] - Opacity of the window + * {Boolean} [blockUpdateOpacity=false] - Blocking the call of the "updateOpacity" function + * + * @param {Number} [opacity.windowOpacity] - Opacity of the window + * @param {Number} [opacity.contentsOpacity] - Opacity of the contents + * @param {Number} [opacity.frameOpacity] - Opacity of the frame + * @param {Number} [opacity.backOpacity] - Opacity of the background + * + * @see DKTools.Window.prototype.setupOpacity + * @see DKTools.Window.prototype.updateOpacity + * + * @returns {Boolean} Change occurred + */ +DKTools.Window.prototype.setOpacity = function(opacity, blockUpdateOpacity) { + if (_.isEqual(this._opacity, Object.assign(this.standardOpacity(), opacity))) { + return false; } -}); + this.setupOpacity(opacity); -// initialize methods + if (!blockUpdateOpacity) { + this.updateOpacity(); + } + + return true; +}; /** - * Initializes a class object + * Changes the tone of the window + * Returns true if the change occurred * * @override * - * @param {Number | Object} [object] - The X coordinate - * @param {Number} [y] - The Y coordinate - * @param {Number} [width] - Width of the window - * @param {Number} [height] - Height of the window + * @param {Number[]} [tone] - Tone of the window + * @param {Boolean} [blockUpdateTone=false] - Blocking the call of the "updateTone" function * - * @see PIXI.Container - * @see DKTools.Base.prototype.initialize + * @see DKTools.Window.prototype.setupTone + * @see DKTools.Window.prototype.updateTone + * + * @returns {Boolean} Change occurred */ -DKTools.Window.prototype.initialize = function(object, y, width, height) { - PIXI.Container.call(this); - DKTools.Base.prototype.initialize.call(this, object, y, width, height); - DKTools.Window._counter++; +DKTools.Window.prototype.setTone = function(tone, blockUpdateTone) { + const standardTone = _.clone(this.standardTone()); + + if (_.isEqual(this._tone, Object.assign(standardTone, tone))) { + return false; + } + + this.setupTone(tone); + + if (!blockUpdateTone) { + this.updateTone(); + } + + return true; }; -// _clear methods +// get methods /** - * Clears all data + * Returns the minimum width of the window * - * @private * @override + * + * @see DKTools.Window.prototype.standardPadding + * @see DKTools.Base.prototype.getMinWidth + * + * @returns {Number} Minimum width of the window */ -DKTools.Window.prototype._clearAll = function() { - DKTools.Base.prototype._clearAll.call(this); - this._clearIsWindow(); - this._clearOpenness(); - this._clearPadding(); - this._clearMargin(); - this._clearColorTone(); - this._clearOrigin(); - this._clearArrows(); +DKTools.Window.prototype.getMinWidth = function() { + return this.standardPadding() * 2 + DKTools.Base.prototype.getMinWidth.call(this); }; /** - * Clears the "isWindow" + * Returns the minimum height of the window * - * @private + * @override + * + * @see DKTools.Window.prototype.standardPadding + * @see DKTools.Base.prototype.getMinHeight + * + * @returns {Number} Minimum height of the window */ -DKTools.Window.prototype._clearIsWindow = function() { - /** - * @private - * @readonly - * @type {Boolean} - */ - this._isWindow = true; +DKTools.Window.prototype.getMinHeight = function() { + return this.standardPadding() * 2 + DKTools.Base.prototype.getMinHeight.call(this); }; /** - * Clears the openness + * Returns the width of the contents * - * @private + * @returns {Number} Width of the contents */ -DKTools.Window.prototype._clearOpenness = function() { - /** - * @private - * @readonly - * @type {Number} - */ - this._openness = this.standardOpenness(); +DKTools.Window.prototype.getContentsWidth = function() { + if (DKTools.Utils.isFunction(this._contentsWidth)) { + return this._contentsWidth(); + } + + return this._contentsWidth; }; /** - * Clears the padding + * Returns the height of the contents * - * @private + * @returns {Number} Height of the contents */ -DKTools.Window.prototype._clearPadding = function() { - /** - * @private - * @readonly - * @type {Number} - */ - this._padding = this.standardPadding(); +DKTools.Window.prototype.getContentsHeight = function() { + if (DKTools.Utils.isFunction(this._contentsHeight)) { + return this._contentsHeight(); + } + + return this._contentsHeight; }; /** - * Clears the margin + * Returns the size of the contents * - * @private + * @see DKTools.Window.prototype.getContentsWidth + * @see DKTools.Window.prototype.getContentsHeight + * + * @returns {Object} Size of the contents */ -DKTools.Window.prototype._clearMargin = function() { - /** - * @private - * @readonly - * @type {Number} - */ - this._margin = this.standardMargin(); +DKTools.Window.prototype.getContentsSize = function() { + return { width: this.getContentsWidth(), height: this.getContentsHeight() }; }; /** - * Clears the color tone + * Returns the arrow by ID * - * @private + * @param {Number | String} id - ID of the arrow + * @returns {DKTools.Sprite.Arrow | undefined} Sprite of the arrow or undefined */ -DKTools.Window.prototype._clearColorTone = function() { - /** - * @private - * @readonly - * @type {Number[]} - */ - this._colorTone = this.standardTone(); +DKTools.Window.prototype.getArrow = function(id) { + return _.find(this._arrows, { id }); }; /** - * Clears the origin + * Returns the current opacity of the window * - * @private + * @returns {Number} Current opacity of the window */ -DKTools.Window.prototype._clearOrigin = function() { - /** - * @private - * @readonly - * @type {Point} - */ - this._origin = this.standardOrigin(); +DKTools.Window.prototype.getCurrentOpacity = function() { + return this.windowOpacity; }; +// needs create methods + /** - * Clears the arrows + * Returns true if needs to create the sprite of the background * - * @private + * @returns {Boolean} Needs to create the sprite of the background */ -DKTools.Window.prototype._clearArrows = function() { - /** - * @private - * @readonly - * @type {DKTools.Sprite.Arrow[]} - */ - this._arrows = []; +DKTools.Window.prototype.needsCreateBackSprite = function() { + return true; }; -// _create methods - /** - * Creates all - * - * @private - * @override + * Returns true if needs to create the sprite of the frame * - * @see DKTools.Base.prototype._createAll - * @see DKTools.Window.prototype._createAllParts - * @see DKTools.Window.prototype._createWindowskin + * @returns {Boolean} Needs to create the sprite of the frame */ -DKTools.Window.prototype._createAll = function() { - DKTools.Base.prototype._createAll.call(this); - this._createAllParts(); - this._createWindowskin(); +DKTools.Window.prototype.needsCreateFrameSprite = function() { + return true; }; /** - * Creates all parts of the window - * - * @private - * @override + * Returns true if needs to create the sprites of the arrows * - * @see DKTools.Window.prototype._createSpriteContainer - * @see DKTools.Window.prototype._createBackSprite - * @see DKTools.Window.prototype._createFrameSprite - * @see DKTools.Window.prototype._createPauseSignSprite + * @returns {Boolean} Needs to create the sprites of the arrows */ -DKTools.Window.prototype._createAllParts = function() { - this._createSpriteContainer(); - this._createBackSprite(); - this._createFrameSprite(); - this._createPauseSignSprite(); +DKTools.Window.prototype.needsCreateArrowsSprites = function() { + return false; }; /** - * Creates the container of the sprites + * Returns true if needs to create the sprite of the down arrow * - * @private + * @returns {Boolean} Needs to create the sprite of the down arrow */ -DKTools.Window.prototype._createSpriteContainer = function() { - /** - * @private - * @readonly - * @type {PIXI.Container} - */ - this._windowSpriteContainer = new PIXI.Container(); +DKTools.Window.prototype.needsCreateDownArrowSprite = function() { + return true; }; /** - * Creates the sprite of the background + * Returns true if needs to create the sprite of the up arrow * - * @private + * @returns {Boolean} Needs to create the sprite of the up arrow */ -DKTools.Window.prototype._createBackSprite = function() { - if (this.needsCreateBackSprite()) { - /** - * @private - * @readonly - * @type {Sprite} - */ - this._windowBackSprite = new Sprite(); - this._windowBackSprite.opacity = this.standardBackOpacity(); - this._windowBackSprite.visible = this.standardBackVisible(); - } +DKTools.Window.prototype.needsCreateUpArrowSprite = function() { + return true; }; /** - * Creates the sprtie of the frame + * Returns true if needs to create the sprite of the left arrow * - * @private + * @returns {Boolean} Needs to create the sprite of the left arrow */ -DKTools.Window.prototype._createFrameSprite = function() { - if (this.needsCreateFrameSprite()) { - /** - * @private - * @readonly - * @type {Sprite} - */ - this._windowFrameSprite = new Sprite(); - this._windowFrameSprite.visible = this.standardFrameVisible(); - } +DKTools.Window.prototype.needsCreateLeftArrowSprite = function() { + return true; }; /** - * Creates the sprite of the pause sign + * Returns true if needs to create the sprite of the right arrow * - * @private + * @returns {Boolean} Needs to create the sprite of the right arrow */ -DKTools.Window.prototype._createPauseSignSprite = function() { - if (this.needsCreatePauseSignSprite()) { - /** - * @private - * @readonly - * @type {Sprite} - */ - this._windowPauseSignSprite = new Sprite(); - } +DKTools.Window.prototype.needsCreateRightArrowSprite = function() { + return true; }; /** - * Creates the window skin - * - * @private + * Returns true if needs to create the sprite of the pause sign * - * @see DKTools.Window.prototype.loadWindowskin + * @returns {Boolean} Needs to create the sprite of the pause sign */ -DKTools.Window.prototype._createWindowskin = function() { - this.windowskin = this.loadWindowskin(); +DKTools.Window.prototype.needsCreatePauseSignSprite = function() { + return true; }; -// _setup methods +// _refresh methods /** - * Sets the events + * Updates all parts of the window * * @private * @override * - * @see DKTools.Base.prototype._setupEvents - * @see DKTools.Base.prototype.needsCreateArrowsSprites - * @see DKTools.Base.prototype._setupCreateArrowsEvent - */ -DKTools.Window.prototype._setupEvents = function() { - DKTools.Base.prototype._setupEvents.call(this); - - if (this.needsCreateArrowsSprites()) { - this._setupCreateArrowsEvent(); - } -}; - -/** - * @private + * @see DKTools.Window.prototype._refreshBack + * @see DKTools.Window.prototype._refreshFrame + * @see DKTools.Window.prototype._refreshContents + * @see DKTools.Window.prototype._refreshPauseSign */ -DKTools.Window.prototype._setupCreateArrowsEvent = function() { - this.addOneTimeEvent({ - type: 'create-all', - onSuccess: this.createArrows.bind(this) - }); +DKTools.Window.prototype._refreshAllParts = function() { + this._refreshBack(); + this._refreshFrame(); + this._refreshContents(); + this._refreshPauseSign(); }; -// _add methods - /** - * Adds children objects to processing + * Updates the background of the window * * @private * @override * - * @see DKTools.Base.prototype._addAllChildren - * @see DKTools.Window.prototype._addAllParts + * @see Window.prototype._refreshBack */ -DKTools.Window.prototype._addAllChildren = function() { - DKTools.Base.prototype._addAllChildren.call(this); - this._addAllParts(); +DKTools.Window.prototype._refreshBack = function() { + if (this.hasBackSprite()) { + Window.prototype._refreshBack.call(this); + } }; /** - * Adds all parts of the window to processing + * Updates the frame of the window * * @private + * @override * - * @see DKTools.Window.prototype._addSpriteContainer - * @see DKTools.Window.prototype._addPauseSignSprite + * @see Window.prototype._refreshFrame */ -DKTools.Window.prototype._addAllParts = function() { - this._addSpriteContainer(); - this._addPauseSignSprite(); +DKTools.Window.prototype._refreshFrame = function() { + if (this.hasFrameSprite()) { + Window.prototype._refreshFrame.call(this); + } }; /** - * Adds the container of the sprites to processing + * Updates the contents * * @private + * @override */ -DKTools.Window.prototype._addSpriteContainer = function() { - if (this.hasSpriteContainer()) { - if (this.hasBackSprite()) { - this._windowSpriteContainer.addChild(this._windowBackSprite); - } - if (this.hasFrameSprite()) { - this._windowSpriteContainer.addChild(this._windowFrameSprite); - } - this.addChild(this._windowSpriteContainer); +DKTools.Window.prototype._refreshContents = function() { + if (this.hasContentsSprite()) { + this._windowContentsSprite.move(this._contentsPosition); } }; /** - * Adds the sprite of the contents to processing + * Updates the sprite of the pause sign * * @private + * @override + * + * @see Window.prototype._refreshPauseSign */ -DKTools.Window.prototype._addContentsSprite = function() { - if (this.hasContentsSprite()) { - this.addChild(this._windowContentsSprite); +DKTools.Window.prototype._refreshPauseSign = function() { + if (this.hasPauseSignSprite()) { + Window.prototype._refreshPauseSign.call(this); } }; +// start methods + /** - * Adds the sprite of the pause sign to processing + * Starts the window * - * @private + * @param {Boolean} [activate=false] - Activates the window + * + * @see DKTools.Base.prototype.start */ -DKTools.Window.prototype._addPauseSignSprite = function() { - if (this.hasPauseSignSprite()) { - this.addChild(this._windowPauseSignSprite); +DKTools.Window.prototype.start = function(activate) { + if (this.hasContentsSprite()) { + const contentsSprite = this._windowContentsSprite; + contentsSprite.resize(this.getContentsWidth(), this.getContentsHeight(), true); + contentsSprite.start(activate); } + + DKTools.Base.prototype.start.call(this, activate); }; -// standard methods +// remove methods /** - * Returns the standard openness of the window + * Removes children objects from processing * - * @returns {Number} Standard openness of the window + * @override */ -DKTools.Window.prototype.standardOpenness = function() { - return 255; +DKTools.Window.prototype.removeAllChildren = function() { + DKTools.Base.prototype.removeAllChildren.call(this); + this.removeContentsSprite(); }; /** - * Returns the standard openness speed of the window - * - * @returns {Number} Standard openness speed of the window + * Removes the sprite of the contents from processing */ -DKTools.Window.prototype.standardOpennessSpeed = function() { - return 16; +DKTools.Window.prototype.removeContentsSprite = function() { + if (this.hasContentsSprite()) { + this.removeChild(this._windowContentsSprite); + } }; /** - * Returns the standard margin of the window + * Removes the arrow by ID * - * @returns {Number} Standard margin of the window + * @param {Number | String} id - ID of the arrow + * + * @see DKTools.Window.prototype.getArrow + * @see DKTools.Utils.Array.remove + * @see DKTools.Window.prototype.removeChild */ -DKTools.Window.prototype.standardMargin = function() { - return 4; +DKTools.Window.prototype.removeArrow = function(id) { + const arrow = this.getArrow(id); + + if (arrow) { + DKTools.Utils.Array.remove(this._arrows, arrow); + this.removeChild(arrow); + } }; +// check methods + /** - * Returns the standard origin of the window + * Checks size of the window + * Returns the number of changed parameters * - * @returns {Point} Standard origin of the window + * @override + * + * @see DKTools.Window.prototype.getMinWidth + * @see DKTools.Window.prototype.getMinHeight + * + * @returns {Number} Number of changed parameters */ -DKTools.Window.prototype.standardOrigin = function() { - return new Point(0, 0); +DKTools.Window.prototype.checkSize = function() { + const minWidth = this.getMinWidth(); + const minHeight = this.getMinHeight(); + let changed = 0; + + if (this._width < minWidth) { + this.setupWidth(minWidth); + changed++; + } + + if (this._height < minHeight) { + this.setupHeight(minHeight); + changed++; + } + + return changed; }; +// create methods + /** - * Returns the standard normal state of the arrow + * Creates the arrow * - * @returns {Function} Standard normal state of the arrow + * @version 3.0.0 + * + * @param {String} arrowType - Type + * @param {Number | String | *} id - ID + * @param {Object} options - Options + * + * @param {Number} [options.x] - The X coordinate + * @param {Number | String} [options.y] - The Y coordinate or line number (String) + * @param {Function} [options.onMouseDown] - + * @param {Function} [options.onMouseUp] - + * @param {Function} [options.onMouseClick] - + * @param {Function} [options.onMouseLongPress] - + * @param {Function} [options.onMouseLongPressStarted] - + * @param {Function} [options.onMouseLongPressFinished] - + * @param {Function} [options.onStateNormal] - + * @param {Function} [options.onStatePressed] - + * + * @see DKTools.Sprite.Arrow + * @see DKTools.Event.prototype.onUpdate + * + * @returns {DKTools.Sprite.Arrow} Created arrow */ -DKTools.Window.prototype.standardArrowStateNormal = function() { - return function(event) { - const arrow = event.target; - arrow.setScale(1, 1); - arrow.setOpacity(255); - }; +DKTools.Window.prototype.createArrow = function(arrowType, id, options) { + const arrow = new DKTools.Sprite.Arrow({ + x: options.x, + y: options.y, + id, + arrowType + }); + + arrow.start(); + + arrow.addEvent({ + type: 'update', + onUpdate: function(event) { + if (this.isOpenAndVisible()) { + arrow.show(); + } else { + arrow.hide(); + } + + if (DKTools.Utils.isFunction(options.onUpdate)) { + options.onUpdate(event); + } + }.bind(this) + }); + + if (DKTools.Utils.isFunction(options.onMouseDown)) { + arrow.addEvent({ + type: 'mouse-down-left', + onUpdate: options.onMouseDown + }); + } + + if (DKTools.Utils.isFunction(options.onMouseUp)) { + arrow.addEvent({ + type: 'mouse-up-left', + onUpdate: options.onMouseUp + }); + } + + if (DKTools.Utils.isFunction(options.onMouseClick)) { + arrow.addEvent({ + type: 'mouse-click-left', + onUpdate: options.onMouseClick + }); + } + + if (DKTools.Utils.isFunction(options.onMouseLongPress)) { + arrow.addEvent({ + type: 'mouse-long-press-left', + onUpdate: options.onMouseLongPress + }); + } + + if (DKTools.Utils.isFunction(options.onMouseLongPressStarted)) { + arrow.addEvent({ + type: 'mouse-long-press-left-started', + onUpdate: options.onMouseLongPressStarted + }); + } + + if (DKTools.Utils.isFunction(options.onMouseLongPressFinished)) { + arrow.addEvent({ + type: 'mouse-long-press-left-finished', + onUpdate: options.onMouseLongPressFinished + }); + } + + if (DKTools.Utils.isFunction(options.onStateNormal)) { + arrow.addEvent({ + type: 'state-normal', + onUpdate: options.onStateNormal + }); + } + + if (DKTools.Utils.isFunction(options.onStatePressed)) { + arrow.addEvent({ + type: 'state-pressed', + onUpdate: options.onStatePressed + }); + } + + this._arrows.push(arrow); + + this.addChild(arrow); + + return arrow; }; /** - * Returns the standard pressed state of the arrow + * Creates the arrows * - * @returns {Function} Standard pressed state of the arrow + * @version 3.0.0 + * + * @see DKTools.Window.prototype.needsCreateDownArrowSprite + * @see DKTools.Window.prototype.needsCreateUpArrowSprite + * @see DKTools.Window.prototype.needsCreateRightArrowSprite + * @see DKTools.Window.prototype.needsCreateLeftArrowSprite + * @see DKTools.Window.prototype.createArrow + * @see DKTools.Window.prototype.onDownArrowUpdate + * @see DKTools.Window.prototype.onDownArrowMouseClick + * @see DKTools.Window.prototype.onDownArrowMouseLongPress + * @see DKTools.Window.prototype.onUpArrowUpdate + * @see DKTools.Window.prototype.onUpArrowMouseClick + * @see DKTools.Window.prototype.onUpArrowMouseLongPress + * @see DKTools.Window.prototype.onRightArrowUpdate + * @see DKTools.Window.prototype.onRightArrowMouseClick + * @see DKTools.Window.prototype.onRightArrowMouseLongPress + * @see DKTools.Window.prototype.onLeftArrowUpdate + * @see DKTools.Window.prototype.onLeftArrowMouseClick + * @see DKTools.Window.prototype.onLeftArrowMouseLongPress + * @see DKTools.Window.prototype.standardArrowStateNormal + * @see DKTools.Window.prototype.standardArrowStatePressed */ -DKTools.Window.prototype.standardArrowStatePressed = function() { - return function(event) { - const arrow = event.target; - arrow.setScale(0.9, 0.9); - arrow.setOpacity(160); - }; +DKTools.Window.prototype.createArrows = function() { + const w = this._width; + const h = this._height; + const q = 12; + + if (this.needsCreateDownArrowSprite()) { + this.createArrow('down', 'down', { + x: w / 2, + y: h - q, + onUpdate: this.onDownArrowUpdate.bind(this), + onMouseClick: this.onDownArrowMouseClick.bind(this), + onMouseLongPress: this.onDownArrowMouseLongPress.bind(this), + onStateNormal: this.standardArrowStateNormal(), + onStatePressed: this.standardArrowStatePressed() + }); + } + + if (this.needsCreateUpArrowSprite()) { + this.createArrow('up', 'up', { + x: w / 2, + y: q, + onUpdate: this.onUpArrowUpdate.bind(this), + onMouseClick: this.onUpArrowMouseClick.bind(this), + onMouseLongPress: this.onUpArrowMouseLongPress.bind(this), + onStateNormal: this.standardArrowStateNormal(), + onStatePressed: this.standardArrowStatePressed() + }); + } + + if (this.needsCreateRightArrowSprite()) { + this.createArrow('right', 'right', { + x: w - q, + y: h / 2, + onUpdate: this.onRightArrowUpdate.bind(this), + onMouseClick: this.onRightArrowMouseClick.bind(this), + onMouseLongPress: this.onRightArrowMouseLongPress.bind(this), + onStateNormal: this.standardArrowStateNormal(), + onStatePressed: this.standardArrowStatePressed() + }); + } + + if (this.needsCreateLeftArrowSprite()) { + this.createArrow('left', 'left', { + x: q, + y: h / 2, + onUpdate: this.onLeftArrowUpdate.bind(this), + onMouseClick: this.onLeftArrowMouseClick.bind(this), + onMouseLongPress: this.onLeftArrowMouseLongPress.bind(this), + onStateNormal: this.standardArrowStateNormal(), + onStatePressed: this.standardArrowStatePressed() + }); + } }; +// add methods + /** - * Returns the standard sprite of the contents + * Adds children objects to processing * - * @returns {DKTools.Sprite} Standard sprite of the contents + * @override */ -DKTools.Window.prototype.standardContentsSprite = function() { - return new DKTools.Sprite(); +DKTools.Window.prototype.addAllChildren = function() { + DKTools.Base.prototype.addAllChildren.call(this); + this.addContentsSprite(); }; /** - * Returns the standard X coordinate of the child - * - * @returns {Number} Standard X coordinate of the child -*/ -DKTools.Window.prototype.standardChildX = function() { - return this.standardPadding(); + * Adds the sprite of the contents to processing + */ +DKTools.Window.prototype.addContentsSprite = function() { + this._addContentsSprite(); + this._refreshContents(); }; -/** - * Returns the standard Y coordinate of the child - * - * @returns {Number} Standard Y coordinate of the child -*/ -DKTools.Window.prototype.standardChildY = function() { - return this.standardPadding(); -}; +// refresh methods /** - * Returns the standard position of the child + * Refreshes the arrows * - * @returns {Point} Standard position of the child + * @since 2.0.0 */ -DKTools.Window.prototype.standardChildPosition = function() { - return new Point(this.standardChildX(), this.standardChildY()); +DKTools.Window.prototype.refreshArrows = function() { + _.forEach(this._arrows, function(arrow) { + arrow.refreshAll(); + }); }; -/** - * Returns the standard position of the contents - * - * @returns {Point} Standard position of the contents - */ -DKTools.Window.prototype.standardContentsPosition = function() { - return this.standardChildPosition(); -}; +// redraw methods /** - * Returns the standard visibility of the background + * Redraws all * - * @returns {Boolean} Standard visibility of the background + * @version 1.1.0 */ -DKTools.Window.prototype.standardBackVisible = function() { - return true; +DKTools.Window.prototype.redrawAll = function() { + if (this.hasContentsSprite()) { + this._windowContentsSprite.redrawAll(); + } }; +// can methods + /** - * Returns the standard visibility of the frame + * Returns true if the window can be updated and redrawn * - * @returns {Boolean} Standard visibility of the frame + * @since 1.1.0 + * @override + * @returns {Boolean} Window can be updated and redrawn */ -DKTools.Window.prototype.standardFrameVisible = function() { - return true; +DKTools.Window.prototype.canRedrawAll = function() { + return this.hasContentsSprite() && DKTools.Base.prototype.canRedrawAll.call(this); }; +// draw methods + /** - * Returns the standard width of the contents + * Draws the text * - * @returns {Function} Standard width of the contents + * @override + * + * @param {String} text - Text + * @param {Object} [options={}] - Options for drawing + * + * @see DKTools.Window.prototype.hasContentsSprite + * @see DKTools.Sprite.prototype.drawText */ -DKTools.Window.prototype.standardContentsWidth = function() { - return function() { - return this._width - this.standardPadding() * 2; - }.bind(this); +DKTools.Window.prototype.drawText = function(text, options) { + if (this.hasContentsSprite()) { + this._windowContentsSprite.drawText(text, options); + } }; +// frame methods + /** - * Returns the standard height of the contents - * - * @returns {Function} Standard height of the contents + * Shows the frame */ -DKTools.Window.prototype.standardContentsHeight = function() { - return function() { - return this._height - this.standardPadding() * 2; - }.bind(this); +DKTools.Window.prototype.showFrame = function() { + if (this.hasFrameSprite()) { + this._windowFrameSprite.visible = true; + } }; /** - * Returns the standard opacity of the window - * - * @returns {Number} Standard opacity of the window + * Hides the frame */ -DKTools.Window.prototype.standardWindowOpacity = function() { - return 255; +DKTools.Window.prototype.hideFrame = function() { + if (this.hasFrameSprite()) { + this._windowFrameSprite.visible = false; + } }; +// back methods + /** - * Returns the standard opacity of the contents + * Shows the background * - * @returns {Number} Standard opacity of the contents + * @see DKTools.Window.prototype.hasBackSprite */ -DKTools.Window.prototype.standardContentsOpacity = function() { - return 255; +DKTools.Window.prototype.showBack = function() { + if (this.hasBackSprite()) { + this._windowBackSprite.visible = true; + } }; /** - * Returns the standard opacity of the frame + * Hides the background * - * @returns {Number} Standard opacity of the frame + * @see DKTools.Window.prototype.hasBackSprite */ -DKTools.Window.prototype.standardFrameOpacity = function() { - return 255; +DKTools.Window.prototype.hideBack = function() { + if (this.hasBackSprite()) { + this._windowBackSprite.visible = false; + } }; +// contents methods + /** - * Returns the standard opacity + * Shows the contents * - * @see DKTools.Window.prototype.standardWindowOpacity - * @see DKTools.Window.prototype.standardContentsOpacity - * @see DKTools.Window.prototype.standardFrameOpacity - * @see DKTools.Window.prototype.standardBackOpacity + * @param {Boolean} [activate=false] - Activates the contents * - * @returns {Object} Standard opacity + * @see DKTools.Window.prototype.hasContentsSprite */ -DKTools.Window.prototype.standardOpacity = function() { - return { - windowOpacity: this.standardWindowOpacity(), - contentsOpacity: this.standardContentsOpacity(), - frameOpacity: this.standardFrameOpacity(), - backOpacity: this.standardBackOpacity() - }; -}; - -/** - * Returns the standard tone of the window - * - * @returns {Number[]} Standard tone of the window -*/ -DKTools.Window.prototype.standardTone = function() { - try { - return $gameSystem.windowTone(); - } catch(e) { +DKTools.Window.prototype.showContents = function(activate) { + if (this.hasContentsSprite()) { + this._windowContentsSprite.show(activate); } - return [0, 0, 0]; }; -// setup methods - /** - * Sets all parameters - * - * @override - * - * @param {Object} [object] - Parameters - * - * @param {Function | Number} [object.contentsWidth] - Width of thw window - * @param {Function | Number} [object.contentsHeight] - Height of thw window - * @param {Object} [object.opacity] - Opacity of the window - * @param {Number[]} [object.tone] - Tone of the window - * - * @param {Number} [opacity.windowOpacity] - Opacity of the window - * @param {Number} [opacity.contentsOpacity] - Opacity of the contents - * @param {Number} [opacity.frameOpacity] - Opacity of the frame - * @param {Number} [opacity.backOpacity] - Opacity of the background - * - * @see свойства object: DKTools.Base.prototype.setupAll -*/ -DKTools.Window.prototype.setupAll = function(object) { - object = object || {}; - DKTools.Base.prototype.setupAll.call(this, object); - let contentsSprite = object.contentsSprite; - - if (object instanceof DKTools.Window && contentsSprite instanceof DKTools.Sprite) { - contentsSprite = contentsSprite.clone({ blockStart: true }); + * Hides the contents + */ +DKTools.Window.prototype.hideContents = function() { + if (this.hasContentsSprite()) { + this._windowContentsSprite.hide(); } - - this.setupContentsWidth(object.contentsWidth); - this.setupContentsHeight(object.contentsHeight); - this.setupContentsSprite(contentsSprite); - this.setupContentsPosition(object.contentsPosition); - this.setupOpacity(object.opacity); - this.setupTone(object.tone); }; +// is method + /** - * Sets the width of the window + * Returns true if the window is open and visible * - * @param {Number} [width] - Width of the window + * @returns {Boolean} Window is open and visible */ -DKTools.Window.prototype.setupWidth = function(width) { - this.realWidth = this._checkWidth(width); +DKTools.Window.prototype.isOpenAndVisible = function() { + return this.isOpen() && this.isVisible(); }; /** - * Sets the height of the window + * Returns true if the window is open and active * - * @param {Number | String} [height] - Height of the window + * @returns {Boolean} Window is open and active */ -DKTools.Window.prototype.setupHeight = function(height) { - if (_.isString(height)) { - height = this.getLineHeight() * Number(height); - } - - this.realHeight = this._checkHeight(height); +DKTools.Window.prototype.isOpenAndActive = function() { + return this.isOpen() && this.isActive(); }; /** - * Sets the size of the window + * Returns true if the coordinates is inside the window * - * @param {Number | Object} [object] - Width of the window or object with parameters - * @param {Number | String} [height] - Height of the window + * @override * - * @param {Number} [object.width] - Width of the window - * @param {Number | String} [object.height] - Height of the window + * @param {Number} x - The X coordinate + * @param {Number} y - The Y coordinate * - * @see DKTools.Window.prototype._checkWidth - * @see DKTools.Window.prototype._checkHeight - * @see Window.prototype.move + * @returns {Boolean} Coordinates is inside the window */ -DKTools.Window.prototype.setupSize = function(object, height) { - if (object instanceof Object) { - return this.setupSize(object.width, object.height); - } - - if (_.isString(height)) { - height = this.getLineHeight() * Number(height); - } - - // object - Number - object = this._checkWidth(object); - height = this._checkHeight(height); +DKTools.Window.prototype.isInside = function(x, y) { + const localX = this.canvasToLocalX(x); + const localY = this.canvasToLocalY(y); + const frame = new Rectangle(0, 0, this.width, this.height); - Window.prototype.move.call(this, this.x, this.y, object, height); + return frame.contains(localX, localY); }; +// has methods + /** - * Sets the width of the contents - * - * @param {Function | Number} [contentsWidth=this.standardContentsWidth()] - Width of the contents + * Returns true if the window has the container of the sprites * - * @see DKTools.Window.prototype.standardContentsWidth + * @returns {Boolean} Window has the container of the sprites */ -DKTools.Window.prototype.setupContentsWidth = function(contentsWidth) { - this._contentsWidth = contentsWidth || this.standardContentsWidth(); +DKTools.Window.prototype.hasSpriteContainer = function() { + return !!this._windowSpriteContainer; }; /** - * Sets the height of the contents - * - * @param {Function | Number} [contentsHeight=this.standardContentsHeight()] - Height of the contents + * Returns true if the window has the sprite of the background * - * @see DKTools.Window.prototype.standardContentsHeight + * @returns {Boolean} Window has the sprite of the background */ -DKTools.Window.prototype.setupContentsHeight = function(contentsHeight) { - this._contentsHeight = contentsHeight || this.standardContentsHeight(); +DKTools.Window.prototype.hasBackSprite = function() { + return !!this._windowBackSprite; }; /** - * Sets the sprite of the contents - * - * @param {DKTools.Sprite | *} [contentsSprite=this.standardContentsSprite()] - Sprite of the contents + * Returns true if the window has the sprite of the frame * - * @see DKTools.Window.prototype.standardContentsSprite + * @returns {Boolean} Window has the sprite of the frame */ -DKTools.Window.prototype.setupContentsSprite = function(contentsSprite) { - /** - * @private - * @readonly - * @type {DKTools.Sprite | *} - */ - this._windowContentsSprite = contentsSprite || this.standardContentsSprite(); +DKTools.Window.prototype.hasFrameSprite = function() { + return !!this._windowFrameSprite; }; /** - * Sets the position of the contents - * - * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object=this.standardContentsPosition()] - The X coordinate or Point or object with parameters - * @param {Number} [y=undefined] - The Y coordinate (if object is Number) - * - * @param {Number} [object.x] - The X coordinate - * @param {Number} [object.y] - The Y coordinate + * Returns true if the window has the sprite of the contents * - * @see DKTools.Utils.Point.toPoint - * @see DKTools.Utils.Point.standardContentsPosition + * @returns {Boolean} Window has the sprite of the contents */ -DKTools.Window.prototype.setupContentsPosition = function(object, y) { - const position = DKTools.Utils.Point.toPoint(object, y); - const newPosition = Object.assign(this.standardContentsPosition(), position); - - /** - * @private - * @readonly - * @type {Point} - */ - this._contentsPosition = new Point(newPosition.x, newPosition.y); +DKTools.Window.prototype.hasContentsSprite = function() { + return !!this._windowContentsSprite; }; /** - * Sets the opacity of the window + * Returns true if the window has the arrow by ID * - * @param {Object} [opacity=this.standardOpacity()] - Opacity of the window + * @param {Number | String | *} id - ID of the arrow * - * @param {Number} [opacity.windowOpacity] - Opacity of the window - * @param {Number} [opacity.contentsOpacity] - Opacity of the contents - * @param {Number} [opacity.frameOpacity] - Opacity of the frame - * @param {Number} [opacity.backOpacity] - Opacity of the background + * @see DKTools.Window.prototype.getArrow * - * @see DKTools.Window.prototype.standardOpacity -*/ -DKTools.Window.prototype.setupOpacity = function(opacity) { - /** - * @private - * @type {Object} - */ - this._opacity = Object.assign(this.standardOpacity(), opacity); + * @returns {Boolean} Window has the arrow by ID + */ +DKTools.Window.prototype.hasArrow = function(id) { + return !!this.getArrow(id); }; /** - * Sets the tone of the window - * - * @param {Number[]} [tone=this.standardTone()] - Tone of the window + * Returns true if the window has the sprites of the arrows * - * @see DKTools.Window.prototype.standardTone + * @returns {Boolean} Window has the sprites of the arrows */ -DKTools.Window.prototype.setupTone = function(tone) { - const standardTone = _.clone(this.standardTone()); - - /** - * @private - * @type {Number[]} - */ - this._tone = Object.assign(standardTone, tone); +DKTools.Window.prototype.hasArrowSprites = function() { + return this.hasUpArrowSprite() && this.hasDownArrowSprite() && + this.hasLeftArrowSprite() && this.hasRightArrowSprite(); }; -// set methods - /** - * Changes all parameters - * Returns the number of changed parameters - * - * @override - * - * @param {Object} [object] - Parameters - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * @param {Boolean} [activate=false] - Activates the window + * Returns true if the window has the sprite of the arrow of up * - * @param {Object} [object.opacity] - Opacity of the window - * @param {Number[]} [object.tone] - Tone of the window + * @see DKTools.Window.prototype.hasArrow * - * @param {Number} [object.opacity.windowOpacity] - Opacity of the window - * @param {Number} [object.opacity.contentsOpacity] - Opacity of the contents - * @param {Number} [object.opacity.frameOpacity] - Opacity of the frame - * @param {Number} [object.opacity.backOpacity] - Opacity of the background + * @returns {Boolean} Window has the sprite of the arrow of up + */ +DKTools.Window.prototype.hasUpArrowSprite = function() { + return this.hasArrow('up'); +}; + +/** + * Returns true if the window has the sprite of the arrow of down * - * @see DKTools.Base.prototype.setAll - * @see DKTools.Window.prototype.setOpacity - * @see DKTools.Window.prototype.setTone - * @see DKTools.Window.prototype.start - * @see DKTools.Window.prototype.activate + * @see DKTools.Window.prototype.hasArrow * - * @returns {Number} Number of changed parameters -*/ -DKTools.Window.prototype.setAll = function(object, blockStart, activate) { - object = object || {}; - const block = true; - let changed = DKTools.Base.prototype.setAll.call(this, object, block); - - if (this.setOpacity(object.opacity, block)) { - changed++; - } - - if (this.setTone(object.tone, block)) { - changed++; - } - - if (changed) { - if (!blockStart) { - this.start(); - } - - if (activate) { - this.activate(); - } - } - - return changed; + * @returns {Boolean} Window has the sprite of the arrow of down + */ +DKTools.Window.prototype.hasDownArrowSprite = function() { + return this.hasArrow('down'); }; /** - * Changes the width of the window - * Returns true if the change occurred - * - * @param {Number} [width] - Width of the window - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * @param {Boolean} [activate=false] - Activates the window + * Returns true if the window has the sprite of the arrow of left * - * @see DKTools.Window.prototype.resize + * @see DKTools.Window.prototype.hasArrow * - * @returns {Boolean} Change occurred + * @returns {Boolean} Window has the sprite of the arrow of left */ -DKTools.Window.prototype.setWidth = function(width, blockStart, activate) { - return this.resize(width, this._height, blockStart, activate); +DKTools.Window.prototype.hasLeftArrowSprite = function() { + return this.hasArrow('left'); }; /** - * Changes the height of the window - * Returns true if the change occurred - * - * @param {Number} [height] - Height of the window - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * @param {Boolean} [activate=false] - Activates the window + * Returns true if the window has the sprite of the arrow of right * - * @see DKTools.Window.prototype.resize + * @see DKTools.Window.prototype.hasArrow * - * @returns {Boolean} Change occurred + * @returns {Boolean} Window has the sprite of the arrow of right */ -DKTools.Window.prototype.setHeight = function(height, blockStart, activate) { - return this.resize(this._width, height, blockStart, activate); +DKTools.Window.prototype.hasRightArrowSprite = function() { + return this.hasArrow('right'); }; /** - * Changes the sprite of the contents - * Returns true if the change occurred - * - * @param {DKTools.Sprite | *} [contentsSprite] - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * @param {Boolean} [activate=false] - Activates the window + * Returns true if the window has the sprite of the pause sign * - * @see DKTools.Window.prototype.removeContentsSprite - * @see DKTools.Window.prototype.setupContentsSprite - * @see DKTools.Window.prototype.addContentsSprite - * @see DKTools.Window.prototype.activate + * @returns {Boolean} Window has the sprite of the pause sign + */ +DKTools.Window.prototype.hasPauseSignSprite = function() { + return !!this._windowPauseSignSprite; +}; + +/** + * Returns true if the window has the sprite of the background dimmer * - * @returns {Boolean} Change occurred + * @returns {Boolean} Window has the sprite of the background dimmer */ -DKTools.Window.prototype.setContentsSprite = function(contentsSprite, blockStart, activate) { - if (this._windowContentsSprite == contentsSprite) { - return false; - } +DKTools.Window.prototype.hasBackgroundDimmer = function() { + return !!this._dimmerSprite; +}; - // TODO: проверить - this.removeContentsSprite(); - this.setupContentsSprite(contentsSprite); - this.addContentsSprite(); +// active methods - if (!blockStart) { - this.start(); - } +/** + * Activates the window + * + * @override + */ +DKTools.Window.prototype.activate = function() { + DKTools.Base.prototype.activate.call(this); - if (activate) { - this.activate(); + if (this.hasContentsSprite()) { + this._windowContentsSprite.activate(); } +}; - return true; +/** + * Deactivates the window + * + * @override + */ +DKTools.Window.prototype.deactivate = function() { + DKTools.Base.prototype.deactivate.call(this); + + if (this.hasContentsSprite()) { + this._windowContentsSprite.deactivate(); + } }; +// size methods + /** - * Changes the position of the contents + * Changes the size of the window if they are different from the current ones * Returns true if the change occurred * - * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object] - The X coordinate or Point or object with parameters - * @param {Number} [y=undefined] - The Y coordinate (if object is Number) + * @override * - * @param {Number} [object.x] - The X coordinate - * @param {Number} [object.y] - The Y coordinate + * @param {Number} [width] - Width of the window + * @param {Number} [height] - Height of the window + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [activate=false] - Activates the window * - * @see DKTools.Utils.Point.toPoint - * @see DKTools.Utils.Point.equals - * @see DKTools.Utils.Point.clone - * @see DKTools.Window.prototype.setupContentsPosition - * @see DKTools.Window.prototype._refreshContents + * @see DKTools.Window.prototype.getMinWidth + * @see DKTools.Window.prototype.getMinHeight + * @see DKTools.Window.prototype.setupSize + * @see DKTools.Window.prototype.start * * @returns {Boolean} Change occurred */ -DKTools.Window.prototype.setContentsPosition = function(object, y) { - if (object instanceof Object) { - return this.setContentsPosition(object, y); - } +DKTools.Window.prototype.resize = function(width, height, blockStart, activate) { + width = (width == null ? this.getMinWidth() : width); + height = (height == null ? this.getMinHeight() : height); - // object - Number - const newPos = DKTools.Utils.Point.toPoint(object, y); + if (DKTools.Utils.isString(height)) { + height = this.getLineHeight() * Number(height); + } - if (DKTools.Utils.Point.equals(this._contentsPosition, newPos)) { + if (this._width === width && this._height === height) { return false; } - const lastPos = DKTools.Utils.Point.clone(this._contentsPosition); - this.setupContentsPosition(newPos); + const lastWidth = this._width; + const lastHeight = this._height; + this.setupSize(width, height); - if (!DKTools.Utils.Point.equals(this._contentsPosition, lastPos)) { - this._refreshContents(); - return true; + if (this._width === lastWidth && this._height === lastHeight) { + return false; } - return false; + if (!blockStart) { + this.start(activate); + } + + return true; }; +// load methods + /** - * Changes the opacity of the window - * Returns true if the change occurred + * Loads and returns a bitmap from img/animations/ * - * @param {Object} [opacity] - Opacity of the window - * {Boolean} [blockUpdateOpacity=false] - Blocking the call of the "updateOpacity" function + * @method DKTools.Window.prototype.loadAnimation * - * @param {Number} [opacity.windowOpacity] - Opacity of the window - * @param {Number} [opacity.contentsOpacity] - Opacity of the contents - * @param {Number} [opacity.frameOpacity] - Opacity of the frame - * @param {Number} [opacity.backOpacity] - Opacity of the background + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) * - * @see DKTools.Window.prototype.setupOpacity - * @see DKTools.Window.prototype.updateOpacity + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap * - * @returns {Boolean} Change occurred + * @see DKTools.Window.prototype.loadBitmap + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype.setOpacity = function(opacity, blockUpdateOpacity) { - if (_.isEqual(this._opacity, Object.assign(this.standardOpacity(), opacity))) { - return false; - } - - this.setupOpacity(opacity); - - if (!blockUpdateOpacity) { - this.updateOpacity(); - } - - return true; -}; /** - * Changes the tone of the window - * Returns true if the change occurred + * Loads and returns a bitmap from img/battleback1/ * - * @override + * @method DKTools.Window.prototype.loadBattleback1 * - * @param {Number[]} [tone] - Tone of the window - * @param {Boolean} [blockUpdateTone=false] - Blocking the call of the "updateTone" function + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) * - * @see DKTools.Window.prototype.setupTone - * @see DKTools.Window.prototype.updateTone + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap * - * @returns {Boolean} Change occurred + * @see DKTools.Window.prototype.loadBitmap + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype.setTone = function(tone, blockUpdateTone) { - const standardTone = _.clone(this.standardTone()); - - if (_.isEqual(this._tone, Object.assign(standardTone, tone))) { - return false; - } - - this.setupTone(tone); - - if (!blockUpdateTone) { - this.updateTone(); - } - - return true; -}; - -// get methods /** - * Returns the minimum width of the window + * Loads and returns a bitmap from img/battleback2/ * - * @override + * @method DKTools.Window.prototype.loadBattleback2 * - * @see DKTools.Window.prototype.standardPadding - * @see DKTools.Base.prototype.getMinWidth + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) * - * @returns {Number} Minimum width of the window + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see DKTools.Window.prototype.loadBitmap + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype.getMinWidth = function() { - return this.standardPadding() * 2 + DKTools.Base.prototype.getMinWidth.call(this); -}; /** - * Returns the minimum height of the window + * Loads and returns a bitmap from img/enemies/ * - * @override + * @method DKTools.Window.prototype.loadEnemy * - * @see DKTools.Window.prototype.standardPadding - * @see DKTools.Base.prototype.getMinHeight + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) * - * @returns {Number} Minimum height of the window + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see DKTools.Window.prototype.loadBitmap + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype.getMinHeight = function() { - return this.standardPadding() * 2 + DKTools.Base.prototype.getMinHeight.call(this); -}; /** - * Returns the width of the contents + * Loads and returns a bitmap from img/characters/ * - * @returns {Number} Width of the contents + * @method DKTools.Window.prototype.loadCharacter + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see DKTools.Window.prototype.loadBitmap + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype.getContentsWidth = function() { - if (DKTools.Utils.isFunction(this._contentsWidth)) { - return this._contentsWidth(); - } - return this._contentsWidth; -}; +/** + * Loads and returns a bitmap from img/faces/ + * + * @method DKTools.Window.prototype.loadFace + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see DKTools.Window.prototype.loadBitmap + * + * @returns {Bitmap} Loaded bitmap + */ /** - * Returns the height of the contents + * Loads and returns a bitmap from img/parallaxes/ * - * @returns {Number} Height of the contents + * @method DKTools.Window.prototype.loadParallax + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see DKTools.Window.prototype.loadBitmap + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype.getContentsHeight = function() { - if (DKTools.Utils.isFunction(this._contentsHeight)) { - return this._contentsHeight(); - } - return this._contentsHeight; -}; +/** + * Loads and returns a bitmap from img/pictures/ + * + * @method DKTools.Window.prototype.loadPicture + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see DKTools.Window.prototype.loadBitmap + * + * @returns {Bitmap} Loaded bitmap + */ /** - * Returns the size of the contents + * Loads and returns a bitmap from img/sv_actors/ * - * @see DKTools.Window.prototype.getContentsWidth - * @see DKTools.Window.prototype.getContentsHeight + * @method DKTools.Window.prototype.loadSvActor * - * @returns {Object} Size of the contents + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see DKTools.Window.prototype.loadBitmap + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype.getContentsSize = function() { - return { width: this.getContentsWidth(), height: this.getContentsHeight() }; -}; /** - * Returns the arrow by ID + * Loads and returns a bitmap from img/sv_enemies/ * - * @param {Number | String} id - ID of the arrow - * @returns {DKTools.Sprite.Arrow | undefined} Sprite of the arrow or undefined + * @method DKTools.Window.prototype.loadSvEnemy + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see DKTools.Window.prototype.loadBitmap + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype.getArrow = function(id) { - return _.find(this._arrows, { id }); -}; /** - * Returns the current opacity of the window + * Loads and returns a bitmap from img/system/ * - * @returns {Number} Current opacity of the window + * @method DKTools.Window.prototype.loadSystem + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see DKTools.Window.prototype.loadBitmap + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype.getCurrentOpacity = function() { - return this.windowOpacity; -}; -// needs create methods +/** + * Loads and returns a bitmap from img/tilesets/ + * + * @method DKTools.Window.prototype.loadTileset + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see DKTools.Window.prototype.loadBitmap + * + * @returns {Bitmap} Loaded bitmap + */ /** - * Returns true if needs to create the sprite of the background + * Loads and returns a bitmap from img/titles1/ + * + * @method DKTools.Window.prototype.loadTitle1 + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see DKTools.Window.prototype.loadBitmap * - * @returns {Boolean} Needs to create the sprite of the background + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype.needsCreateBackSprite = function() { - return true; -}; /** - * Returns true if needs to create the sprite of the frame + * Loads and returns a bitmap from img/titles2/ * - * @returns {Boolean} Needs to create the sprite of the frame - */ -DKTools.Window.prototype.needsCreateFrameSprite = function() { - return true; -}; - -/** - * Returns true if needs to create the sprites of the arrows + * @method DKTools.Window.prototype.loadTitle2 * - * @returns {Boolean} Needs to create the sprites of the arrows + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see DKTools.Window.prototype.loadBitmap + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype.needsCreateArrowsSprites = function() { - return false; -}; /** - * Returns true if needs to create the sprite of the down arrow + * Loads and returns a bitmap from img/system/ * - * @returns {Boolean} Needs to create the sprite of the down arrow + * @method DKTools.Window.prototype.loadWindowskin + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see DKTools.Window.prototype.loadSystem + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype.needsCreateDownArrowSprite = function() { - return true; -}; /** - * Returns true if needs to create the sprite of the up arrow + * Loads and returns a bitmap * - * @returns {Boolean} Needs to create the sprite of the up arrow + * @param {String | Object} object - Path to file or object with parameters + * @param {String} filename - Name of file (if object is String) + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * + * @param {String} object.folder - Path to file + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see DKTools.Utils.Bitmap.load + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype.needsCreateUpArrowSprite = function() { - return true; +DKTools.Window.prototype.loadBitmap = function(object, filename, listener, hue, smooth) { + return DKTools.Utils.Bitmap.load(object, filename, listener, hue, smooth); }; +// reserve methods + /** - * Returns true if needs to create the sprite of the left arrow + * Loads, reserves and returns a bitmap from img/animations/ * - * @returns {Boolean} Needs to create the sprite of the left arrow + * @method DKTools.Window.prototype.reserveAnimation + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see DKTools.Window.prototype.reserveBitmap + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype.needsCreateLeftArrowSprite = function() { - return true; -}; /** - * Returns true if needs to create the sprite of the right arrow + * Loads, reserves and returns a bitmap from img/battleback1/ * - * @returns {Boolean} Needs to create the sprite of the right arrow + * @method DKTools.Window.prototype.reserveBattleback1 + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see DKTools.Window.prototype.reserveBitmap + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype.needsCreateRightArrowSprite = function() { - return true; -}; /** - * Returns true if needs to create the sprite of the pause sign + * Loads, reserves and returns a bitmap from img/battleback2/ * - * @returns {Boolean} Needs to create the sprite of the pause sign + * @method DKTools.Window.prototype.reserveBattleback2 + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see DKTools.Window.prototype.reserveBitmap + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype.needsCreatePauseSignSprite = function() { - return true; -}; - -// _refresh methods /** - * Updates all parts of the window + * Loads, reserves and returns a bitmap from img/enemies/ * - * @private - * @override + * @method DKTools.Window.prototype.reserveEnemy * - * @see DKTools.Window.prototype._refreshBack - * @see DKTools.Window.prototype._refreshFrame - * @see DKTools.Window.prototype._refreshContents - * @see DKTools.Window.prototype._refreshPauseSign + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see DKTools.Window.prototype.reserveBitmap + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype._refreshAllParts = function() { - this._refreshBack(); - this._refreshFrame(); - this._refreshContents(); - this._refreshPauseSign(); -}; /** - * Updates the background of the window + * Loads, reserves and returns a bitmap from img/characters/ * - * @private - * @override + * @method DKTools.Window.prototype.reserveCharacter * - * @see Window.prototype._refreshBack + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see DKTools.Window.prototype.reserveBitmap + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype._refreshBack = function() { - if (this.hasBackSprite()) { - Window.prototype._refreshBack.call(this); - } -}; /** - * Updates the frame of the window + * Loads, reserves and returns a bitmap from img/faces/ * - * @private - * @override + * @method DKTools.Window.prototype.reserveFace * - * @see Window.prototype._refreshFrame + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see DKTools.Window.prototype.reserveBitmap + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype._refreshFrame = function() { - if (this.hasFrameSprite()) { - Window.prototype._refreshFrame.call(this); - } -}; /** - * Updates the contents + * Loads, reserves and returns a bitmap from img/parallaxes/ * - * @private - * @override + * @method DKTools.Window.prototype.reserveParallax + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see DKTools.Window.prototype.reserveBitmap + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype._refreshContents = function() { - if (this.hasContentsSprite()) { - this._windowContentsSprite.move(this._contentsPosition); - } -}; /** - * Updates the sprite of the pause sign + * Loads, reserves and returns a bitmap from img/pictures/ * - * @private - * @override + * @method DKTools.Window.prototype.reservePicture * - * @see Window.prototype._refreshPauseSign + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see DKTools.Window.prototype.reserveBitmap + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype._refreshPauseSign = function() { - if (this.hasPauseSignSprite()) { - Window.prototype._refreshPauseSign.call(this); - } -}; - -// start methods /** - * Starts the window + * Loads, reserves and returns a bitmap from img/sv_actors/ * - * @param {Boolean} [activate=false] - Activates the window + * @method DKTools.Window.prototype.reserveSvActor * - * @see DKTools.Base.prototype.start + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see DKTools.Window.prototype.reserveBitmap + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype.start = function(activate) { - if (this.hasContentsSprite()) { - const contentsSprite = this._windowContentsSprite; - contentsSprite.resize(this.getContentsWidth(), this.getContentsHeight(), true); - contentsSprite.start(activate); - } - - DKTools.Base.prototype.start.call(this, activate); -}; - -// remove methods /** - * Removes children objects from processing + * Loads, reserves and returns a bitmap from img/sv_enemies/ * - * @override + * @method DKTools.Window.prototype.reserveSvEnemy + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see DKTools.Window.prototype.reserveBitmap + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype.removeAllChildren = function() { - DKTools.Base.prototype.removeAllChildren.call(this); - this.removeContentsSprite(); -}; /** - * Removes the sprite of the contents from processing + * Loads, reserves and returns a bitmap from img/system/ + * + * @method DKTools.Window.prototype.reserveSystem + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see DKTools.Window.prototype.reserveBitmap + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype.removeContentsSprite = function() { - if (this.hasContentsSprite()) { - this.removeChild(this._windowContentsSprite); - } -}; /** - * Removes the arrow by ID + * Loads, reserves and returns a bitmap from img/tilesets/ * - * @param {Number | String} id - ID of the arrow + * @method DKTools.Window.prototype.reserveTileset * - * @see DKTools.Window.prototype.getArrow - * @see DKTools.Utils.Array.remove - * @see DKTools.Window.prototype.removeChild + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see DKTools.Window.prototype.reserveBitmap + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype.removeArrow = function(id) { - const arrow = this.getArrow(id); - if (arrow) { - DKTools.Utils.Array.remove(this._arrows, arrow); - this.removeChild(arrow); - } -}; - -// check methods /** - * Checks size of the window - * Returns the number of changed parameters + * Loads, reserves and returns a bitmap from img/titles1/ + * + * @method DKTools.Window.prototype.loadTitle1 + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) * - * @override + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID * - * @see DKTools.Window.prototype.getMinWidth - * @see DKTools.Window.prototype.getMinHeight + * @see DKTools.Window.prototype.reserveBitmap * - * @returns {Number} Number of changed parameters + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype.checkSize = function() { - const minWidth = this.getMinWidth(); - const minHeight = this.getMinHeight(); - let changed = 0; - - if (this._width < minWidth) { - this.setupWidth(minWidth); - changed++; - } - - if (this._height < minHeight) { - this.setupHeight(minHeight); - changed++; - } - - return changed; -}; - -// create methods /** - * Creates the arrow + * Loads, reserves and returns a bitmap from img/titles2/ * - * @param {String} arrowType - Type of the arrow - * @param {Number | String | *} id - ID of the arrow - * @param {Object} options - + * @method DKTools.Window.prototype.loadTitle2 * - * @param {Number} [options.x] - The X coordinate - * @param {Number | String} [options.y] - The Y coordinate + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) * - * @see DKTools.Event.prototype.onUpdate - * @see DKTools.Sprite.Arrow + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID * - * @returns {DKTools.Sprite.Arrow} + * @see DKTools.Window.prototype.reserveBitmap + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype.createArrow = function(arrowType, id, options) { - const arrow = new DKTools.Sprite.Arrow({ - x: options.x, - y: options.y, - id, - arrowType - }); - arrow.start(); - - arrow.addEvent({ - type: 'update', - onUpdate: function(event) { - if (this.isOpenAndVisible()) { - arrow.show(); - } else { - arrow.hide(); - } - - if (DKTools.Utils.isFunction(options.onUpdate)) { - options.onUpdate(event); - } - }.bind(this) - }); - - if (DKTools.Utils.isFunction(options.onClick)) { - arrow.addEvent({ - type: 'mouse-click-left', - onUpdate: options.onClick - }); - } - - if (DKTools.Utils.isFunction(options.onLongPress)) { - arrow.addEvent({ - type: 'mouse-long-press-left', - onUpdate: options.onLongPress - }); - } - - if (DKTools.Utils.isFunction(options.onLongPressReleased)) { - arrow.addEvent({ - type: 'mouse-long-press-left-finished', - onUpdate: options.onLongPressReleased - }); - } - - if (DKTools.Utils.isFunction(options.onStateNormal)) { - arrow.addEvent({ - type: 'state-normal', - onUpdate: options.onStateNormal - }); - } - - if (DKTools.Utils.isFunction(options.onStatePressed)) { - arrow.addEvent({ - type: 'state-pressed', - onUpdate: options.onStatePressed - }); - } - - this._arrows.push(arrow); - this.addChild(arrow); - - return arrow; -}; /** - * Creates the arrows + * Loads, reserves and returns a bitmap from img/system/ * - * @see DKTools.Window.prototype.needsCreateDownArrowSprite - * @see DKTools.Window.prototype.needsCreateUpArrowSprite - * @see DKTools.Window.prototype.needsCreateRightArrowSprite - * @see DKTools.Window.prototype.needsCreateLeftArrowSprite - * @see DKTools.Window.prototype.createArrow - * @see DKTools.Window.prototype.onUpdateDownArrow - * @see DKTools.Window.prototype.onClickDownArrow - * @see DKTools.Window.prototype.onLongPressDownArrow - * @see DKTools.Window.prototype.onUpdateUpArrow - * @see DKTools.Window.prototype.onClickUpArrow - * @see DKTools.Window.prototype.onLongPressUpArrow - * @see DKTools.Window.prototype.onUpdateRightArrow - * @see DKTools.Window.prototype.onClickRightArrow - * @see DKTools.Window.prototype.onLongPressRightArrow - * @see DKTools.Window.prototype.onUpdateLeftArrow - * @see DKTools.Window.prototype.onClickLeftArrow - * @see DKTools.Window.prototype.onLongPressLeftArrow - * @see DKTools.Window.prototype.standardArrowStateNormal - * @see DKTools.Window.prototype.standardArrowStatePressed + * @method DKTools.Window.prototype.reserveWindowskin + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see DKTools.Window.prototype.reserveSystem + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype.createArrows = function() { - const w = this._width; - const h = this._height; - const q = 12; - - if (this.needsCreateDownArrowSprite()) { - this.createArrow('down', 'down', { - x: w / 2, - y: h - q, - onUpdate: this.onUpdateDownArrow.bind(this), - onClick: this.onClickDownArrow.bind(this), - onLongPress: this.onLongPressDownArrow.bind(this), - onStateNormal: this.standardArrowStateNormal(), - onStatePressed: this.standardArrowStatePressed() - }); - } - - if (this.needsCreateUpArrowSprite()) { - this.createArrow('up', 'up', { - x: w / 2, - y: q, - onUpdate: this.onUpdateUpArrow.bind(this), - onClick: this.onClickUpArrow.bind(this), - onLongPress: this.onLongPressUpArrow.bind(this), - onStateNormal: this.standardArrowStateNormal(), - onStatePressed: this.standardArrowStatePressed() - }); - } - - if (this.needsCreateRightArrowSprite()) { - this.createArrow('right', 'right', { - x: w - q, - y: h / 2, - onUpdate: this.onUpdateRightArrow.bind(this), - onClick: this.onClickRightArrow.bind(this), - onLongPress: this.onLongPressRightArrow.bind(this), - onStateNormal: this.standardArrowStateNormal(), - onStatePressed: this.standardArrowStatePressed() - }); - } - - if (this.needsCreateLeftArrowSprite()) { - this.createArrow('left', 'left', { - x: q, - y: h / 2, - onUpdate: this.onUpdateLeftArrow.bind(this), - onClick: this.onClickLeftArrow.bind(this), - onLongPress: this.onLongPressLeftArrow.bind(this), - onStateNormal: this.standardArrowStateNormal(), - onStatePressed: this.standardArrowStatePressed() - }); - } -}; - -// add methods /** - * Adds children objects to processing + * Loads, reserves and returns a bitmap + * + * @param {String | Object} object - Path to file or object with parameters + * @param {String} filename - Name of file (if object is String) + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) * - * @override + * @param {String} object.folder - Path to file + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see DKTools.Utils.Bitmap.reserve + * + * @returns {Bitmap} Loaded bitmap */ -DKTools.Window.prototype.addAllChildren = function() { - DKTools.Base.prototype.addAllChildren.call(this); - this.addContentsSprite(); +DKTools.Window.prototype.reserveBitmap = function(object, filename, listener, hue, smooth, reservationId) { + return DKTools.Utils.Bitmap.reserve(object, filename, listener, hue, smooth, reservationId); }; +// events methods + /** - * Adds the sprite of the contents to processing + * Updates the events with type: open */ -DKTools.Window.prototype.addContentsSprite = function() { - this._addContentsSprite(); - this._refreshContents(); +DKTools.Window.prototype.updateOpenEvents = function() { + this.updateEventsContainer('open'); }; -// refresh methods - /** - * Refreshes the arrows - * - * @since 2.0.0 + * Updates the events with type: close */ -DKTools.Window.prototype.refreshArrows = function() { - _.forEach(this._arrows, function(arrow) { - arrow.refreshAll(); - }); +DKTools.Window.prototype.updateCloseEvents = function() { + this.updateEventsContainer('close'); }; -// redraw methods +// arrow methods /** - * Redraws all + * Callback function that will be processing update of the up arrow * - * @version 1.1.0 + * @param {DKTools.Event} event - Event + * + * @see DKTools.Window.prototype.createArrows */ -DKTools.Window.prototype.redrawAll = function() { - if (this.hasContentsSprite()) { - this._windowContentsSprite.redrawAll(); - } +DKTools.Window.prototype.onUpArrowUpdate = function(event) { + // to be overriden by plugins }; -// can methods - /** - * Returns true if the window can be updated and redrawn + * Callback function that will be processing update of the down arrow * - * @since 1.1.0 - * @override - * @returns {Boolean} Window can be updated and redrawn + * @param {DKTools.Event} event - Event + * + * @see DKTools.Window.prototype.createArrows */ -DKTools.Window.prototype.canRedrawAll = function() { - return this.hasContentsSprite() && DKTools.Base.prototype.canRedrawAll.call(this); +DKTools.Window.prototype.onDownArrowUpdate = function(event) { + // to be overriden by plugins }; -// draw methods - /** - * Draws the text - * - * @override + * Callback function that will be processing update of the left arrow * - * @param {String} text - Text - * @param {Object} [options={}] - Options for drawing + * @param {DKTools.Event} event - Event * - * @see DKTools.Window.prototype.hasContentsSprite - * @see DKTools.Sprite.prototype.drawText + * @see DKTools.Window.prototype.createArrows */ -DKTools.Window.prototype.drawText = function(text, options) { - if (this.hasContentsSprite()) { - this._windowContentsSprite.drawText(text, options); - } +DKTools.Window.prototype.onLeftArrowUpdate = function(event) { + // to be overriden by plugins }; -// frame methods - /** - * Shows the frame + * Callback function that will be processing update of the right arrow + * + * @param {DKTools.Event} event - Event + * + * @see DKTools.Window.prototype.createArrows */ -DKTools.Window.prototype.showFrame = function() { - if (this.hasFrameSprite()) { - this._windowFrameSprite.visible = true; - } +DKTools.Window.prototype.onRightArrowUpdate = function(event) { + // to be overriden by plugins }; /** - * Hides the frame - */ -DKTools.Window.prototype.hideFrame = function() { - if (this.hasFrameSprite()) { - this._windowFrameSprite.visible = false; - } + * Callback function that will be processing click of the up arrow + * + * @param {DKTools.Event} event - Event + * + * @see DKTools.Window.prototype.createArrows + */ +DKTools.Window.prototype.onUpArrowMouseClick = function(event) { + // to be overriden by plugins }; -// back methods - /** - * Shows the background + * Callback function that will be processing click of the down arrow * - * @see DKTools.Window.prototype.hasBackSprite + * @param {DKTools.Event} event - Event + * + * @see DKTools.Window.prototype.createArrows */ -DKTools.Window.prototype.showBack = function() { - if (this.hasBackSprite()) { - this._windowBackSprite.visible = true; - } +DKTools.Window.prototype.onDownArrowMouseClick = function(event) { + // to be overriden by plugins }; /** - * Hides the background + * Callback function that will be processing click of the left arrow * - * @see DKTools.Window.prototype.hasBackSprite + * @param {DKTools.Event} event - Event + * + * @see DKTools.Window.prototype.createArrows */ -DKTools.Window.prototype.hideBack = function() { - if (this.hasBackSprite()) { - this._windowBackSprite.visible = false; - } +DKTools.Window.prototype.onLeftArrowMouseClick = function(event) { + // to be overriden by plugins }; -// contents methods - /** - * Shows the contents + * Callback function that will be processing click of the right arrow * - * @param {Boolean} [activate=false] - Activates the contents + * @param {DKTools.Event} event - Event * - * @see DKTools.Window.prototype.hasContentsSprite + * @see DKTools.Window.prototype.createArrows */ -DKTools.Window.prototype.showContents = function(activate) { - if (this.hasContentsSprite()) { - this._windowContentsSprite.show(activate); - } +DKTools.Window.prototype.onRightArrowMouseClick = function(event) { + // to be overriden by plugins }; /** - * Hides the contents + * Callback function that will be processing long press of the up arrow + * + * @param {DKTools.Event} event - Event + * + * @see DKTools.Window.prototype.createArrows */ -DKTools.Window.prototype.hideContents = function() { - if (this.hasContentsSprite()) { - this._windowContentsSprite.hide(); - } +DKTools.Window.prototype.onUpArrowMouseLongPress = function(event) { + // to be overriden by plugins }; -// is method - /** - * Returns true if the window is open and visible + * Callback function that will be processing long press of the down arrow * - * @returns {Boolean} Window is open and visible + * @param {DKTools.Event} event - Event + * + * @see DKTools.Window.prototype.createArrows */ -DKTools.Window.prototype.isOpenAndVisible = function() { - return this.isOpen() && this.isVisible(); +DKTools.Window.prototype.onDownArrowMouseLongPress = function(event) { + // to be overriden by plugins }; /** - * Returns true if the window is open and active + * Callback function that will be processing long press of the left arrow * - * @returns {Boolean} Window is open and active + * @param {DKTools.Event} event - Event + * + * @see DKTools.Window.prototype.createArrows */ -DKTools.Window.prototype.isOpenAndActive = function() { - return this.isOpen() && this.isActive(); +DKTools.Window.prototype.onLeftArrowMouseLongPress = function(event) { + // to be overriden by plugins }; /** - * Returns true if the coordinates is inside the window - * - * @override + * Callback function that will be processing long press of the right arrow * - * @param {Number} x - The X coordinate - * @param {Number} y - The Y coordinate + * @param {DKTools.Event} event - Event * - * @returns {Boolean} Coordinates is inside the window + * @see DKTools.Window.prototype.createArrows */ -DKTools.Window.prototype.isInside = function(x, y) { - const localX = this.canvasToLocalX(x); - const localY = this.canvasToLocalY(y); - const frame = new Rectangle(0, 0, this.width, this.height); - return frame.contains(localX, localY); +DKTools.Window.prototype.onRightArrowMouseLongPress = function(event) { + // to be overriden by plugins }; -// has methods +// _update methods /** - * Returns true if the window has the container of the sprites + * Updates the contents * - * @returns {Boolean} Window has the container of the sprites + * @private + * @override */ -DKTools.Window.prototype.hasSpriteContainer = function() { - return !!this._windowSpriteContainer; +DKTools.Window.prototype._updateContents = function() { + if (this.hasContentsSprite()) { + Window.prototype._updateContents.call(this); + } }; /** - * Returns true if the window has the sprite of the background + * Updates the sprite of the pause sign * - * @returns {Boolean} Window has the sprite of the background + * @private + * @override */ -DKTools.Window.prototype.hasBackSprite = function() { - return !!this._windowBackSprite; +DKTools.Window.prototype._updatePauseSign = function() { + if (this.hasPauseSignSprite()) { + Window.prototype._updatePauseSign.call(this); + } }; +// update methods + /** - * Returns true if the window has the sprite of the frame + * Updates all * - * @returns {Boolean} Window has the sprite of the frame + * @override */ -DKTools.Window.prototype.hasFrameSprite = function() { - return !!this._windowFrameSprite; +DKTools.Window.prototype.updateAll = function() { + if (this.hasContentsSprite()) { + this.updateContents(); + } + + DKTools.Base.prototype.updateAll.call(this); + this.updateTone(); }; /** - * Returns true if the window has the sprite of the contents - * - * @returns {Boolean} Window has the sprite of the contents + * Updates the contents */ -DKTools.Window.prototype.hasContentsSprite = function() { - return !!this._windowContentsSprite; +DKTools.Window.prototype.updateContents = function() { + if (this.hasContentsSprite()) { + this._windowContentsSprite.updateAll(); + } }; /** - * Returns true if the window has the arrow by ID - * - * @param {Number | String | *} id - ID of the arrow + * Updates the transform * - * @see DKTools.Window.prototype.getArrow + * @override * - * @returns {Boolean} Window has the arrow by ID + * @see DKTools.Window.prototype._updateContents + * @see DKTools.Window.prototype._updatePauseSign + * @see PIXI.Container.prototype.updateTransform */ -DKTools.Window.prototype.hasArrow = function(id) { - return !!this.getArrow(id); +DKTools.Window.prototype.updateTransform = function() { + this._updateContents(); + this._updatePauseSign(); + PIXI.Container.prototype.updateTransform.call(this); }; /** - * Returns true if the window has the sprites of the arrows + * Updates the opaciy of thw window * - * @returns {Boolean} Window has the sprites of the arrows + * @override + * + * @param {Object} [opacity] - Opacity + * + * @param {Number} [opacity.windowOpacity] - Opacity of the window + * @param {Number} [opacity.contentsOpacity] - Opacity of the contents + * @param {Number} [opacity.frameOpacity] - Opacity of the frame + * @param {Number} [opacity.backOpacity] - Opacity of the background */ -DKTools.Window.prototype.hasArrowSprites = function() { - return this.hasUpArrowSprite() && this.hasDownArrowSprite() && - this.hasLeftArrowSprite() && this.hasRightArrowSprite(); +DKTools.Window.prototype.updateOpacity = function(opacity) { + opacity = opacity || this.opacity; + + if (this.hasSpriteContainer()) { + this.windowOpacity = opacity.windowOpacity; + } + + if (this.hasContentsSprite()) { + this.contentsOpacity = opacity.contentsOpacity; + } + + if (this.hasFrameSprite()) { + this.frameOpacity = opacity.frameOpacity; + } + + if (this.hasBackSprite()) { + this.backOpacity = opacity.backOpacity; + } }; /** - * Returns true if the window has the sprite of the arrow of up + * Updates the tone of the window * - * @see DKTools.Window.prototype.hasArrow + * @override * - * @returns {Boolean} Window has the sprite of the arrow of up + * @see Window.prototype.setTone + * + * @param {Number[]} [tone] - Tone of the window */ -DKTools.Window.prototype.hasUpArrowSprite = function() { - return this.hasArrow('up'); +DKTools.Window.prototype.updateTone = function(tone) { + tone = tone || this.tone; + + if (this.hasBackSprite()) { + Window.prototype.setTone.apply(this, tone); + } }; /** - * Returns true if the window has the sprite of the arrow of down - * - * @see DKTools.Window.prototype.hasArrow + * Updates the opening of the window * - * @returns {Boolean} Window has the sprite of the arrow of down + * @override */ -DKTools.Window.prototype.hasDownArrowSprite = function() { - return this.hasArrow('down'); +DKTools.Window.prototype.updateOpen = function() { + if (!this._opening) { + return; + } + + this.openness += this.standardOpennessSpeed(); + + if (this.isOpen()) { + this._opening = false; + this.updateOpenEvents(); + } }; /** - * Returns true if the window has the sprite of the arrow of left - * - * @see DKTools.Window.prototype.hasArrow + * Updates the closing of the window * - * @returns {Boolean} Window has the sprite of the arrow of left + * @override */ -DKTools.Window.prototype.hasLeftArrowSprite = function() { - return this.hasArrow('left'); +DKTools.Window.prototype.updateClose = function() { + if (!this._closing) { + return; + } + + this.openness -= this.standardOpennessSpeed(); + + if (this.isClosed()) { + this._closing = false; + this.updateCloseEvents(); + } }; /** - * Returns true if the window has the sprite of the arrow of right - * - * @see DKTools.Window.prototype.hasArrow + * Updates the window * - * @returns {Boolean} Window has the sprite of the arrow of right + * @override */ -DKTools.Window.prototype.hasRightArrowSprite = function() { - return this.hasArrow('right'); +DKTools.Window.prototype.update = function() { + DKTools.Base.prototype.update.call(this); + this.updateOpen(); + this.updateClose(); + this.updateBackgroundDimmer(); }; + + + + +//=========================================================================== +// DKTools.Window.Selectable +//=========================================================================== + +DKTools.Window.Selectable.prototype = Object.create(DKTools.Window.prototype); +DKTools.Window.Selectable.prototype.constructor = DKTools.Window.Selectable; + +// standard methods + /** - * Returns true if the window has the sprite of the pause sign + * Returns the standard sprite of the contents * - * @returns {Boolean} Window has the sprite of the pause sign + * @override + * + * @see DKTools.Sprite.Selectable + * + * @returns {DKTools.Sprite.Selectable} Standard sprite of the contents */ -DKTools.Window.prototype.hasPauseSignSprite = function() { - return !!this._windowPauseSignSprite; +DKTools.Window.Selectable.prototype.standardContentsSprite = function() { + return new DKTools.Sprite.Selectable(); }; +// needs create methods + /** - * Returns true if the window has the sprite of the background dimmer + * Returns true if needs to create the sprites of the arrows * - * @returns {Boolean} Window has the sprite of the background dimmer + * @override + * + * @returns {Boolean} Needs to create the sprites of the arrows */ -DKTools.Window.prototype.hasBackgroundDimmer = function() { - return !!this._dimmerSprite; +DKTools.Window.Selectable.prototype.needsCreateArrowsSprites = function() { + return true; }; -// active methods +// arrow methods /** - * Activates the window + * Callback function that will be processing update of the up arrow * - * @override + * @param {DKTools.Event} event - Event + * + * @see DKTools.Window.prototype.createArrows */ -DKTools.Window.prototype.activate = function() { - DKTools.Base.prototype.activate.call(this); +DKTools.Window.Selectable.prototype.onUpArrowUpdate = function(event) { + const arrow = event.target; + arrow.hide(); if (this.hasContentsSprite()) { - this._windowContentsSprite.activate(); + const contentsSprite = this._windowContentsSprite; + + if (this.isChild(contentsSprite) && + contentsSprite.isVisible() && + contentsSprite.isSelectable() && + contentsSprite.isVertical()) { + if (contentsSprite.getTopRow() > 0) { + arrow.show(this.isVisibleAndActive() && contentsSprite.isActive()); + } + } } }; /** - * Deactivates the window + * Callback function that will be processing update of the down arrow * - * @override + * @param {DKTools.Event} event - Event + * + * @see DKTools.Window.prototype.createArrows */ -DKTools.Window.prototype.deactivate = function() { - DKTools.Base.prototype.deactivate.call(this); +DKTools.Window.Selectable.prototype.onDownArrowUpdate = function(event) { + const arrow = event.target; + arrow.hide(); if (this.hasContentsSprite()) { - this._windowContentsSprite.deactivate(); + const contentsSprite = this._windowContentsSprite; + + if (this.isChild(contentsSprite) && + contentsSprite.isVisible() && + contentsSprite.isSelectable() && + contentsSprite.isVertical()) { + const topRow = contentsSprite.getTopRow(); + const maxTopRow = contentsSprite.getMaxTopRow(); + + if (maxTopRow > 0 && topRow < maxTopRow) { + arrow.show(this.isVisibleAndActive() && contentsSprite.isActive()); + } + } } }; -// size methods - /** - * Changes the size of the window if they are different from the current ones - * Returns true if the change occurred - * - * @override - * - * @param {Number} [width] - Width of the window - * @param {Number} [height] - Height of the window - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * @param {Boolean} [activate=false] - Activates the window + * Callback function that will be processing update of the left arrow * - * @see DKTools.Window.prototype.getMinWidth - * @see DKTools.Window.prototype.getMinHeight - * @see DKTools.Window.prototype.setupSize - * @see DKTools.Window.prototype.start + * @param {DKTools.Event} event - Event * - * @returns {Boolean} Change occurred + * @see DKTools.Window.prototype.createArrows */ -DKTools.Window.prototype.resize = function(width, height, blockStart, activate) { - width = (width == null ? this.getMinWidth() : width); - height = (height == null ? this.getMinHeight() : height); - - if (_.isString(height)) { - height = this.getLineHeight() * Number(height); - } - - if (this._width === width && this._height === height) { - return false; - } - - const lastWidth = this._width; - const lastHeight = this._height; - this.setupSize(width, height); +DKTools.Window.Selectable.prototype.onLeftArrowUpdate = function(event) { + const arrow = event.target; + arrow.hide(); - if (this._width === lastWidth && this._height === lastHeight) { - return false; - } + if (this.hasContentsSprite()) { + const contentsSprite = this._windowContentsSprite; - if (!blockStart) { - this.start(activate); + if (this.isChild(contentsSprite) && + contentsSprite.isVisible() && + contentsSprite.isSelectable() && + contentsSprite.isHorizontal()) { + if (contentsSprite.getTopCol() > 0) { + arrow.show(this.isVisibleAndActive() && contentsSprite.isActive()); + } + } } - - return true; }; -// load methods - /** - * Loads a bitmap from a folder - * Возвращает загруженный Bitmap - * - * @param {String | Object} folder - Путь к файлу или Объект типа {} - * @param {String} filename - Название файла - * @param {Function} [listener] - Метод обработки после загрузки Bitmap - * @param {Number} [hue] - Оттенок - * @param {Boolean} [smooth] - Сглаживание + * Callback function that will be processing update of the right arrow * - * @param {String} object.folder - Путь к файлу - * @param {String} object.filename - Название файла - * @param {Function} [object.listener] - Метод обработки после загрузки Bitmap - * @param {Number} [object.hue] - Оттенок - * @param {Boolean} [object.smooth] - Сглаживание + * @param {DKTools.Event} event - Event * - * @returns {Bitmap} + * @see DKTools.Window.prototype.createArrows */ -DKTools.Window.prototype.loadBitmap = function(object, filename, listener, hue, smooth) { - if (object instanceof Object) { - return this.loadBitmap(object.folder, object.filename, object.listener, object.hue, object.smooth); - } +DKTools.Window.Selectable.prototype.onRightArrowUpdate = function(event) { + const arrow = event.target; + arrow.hide(); - // object - String - let bitmap = ImageManager.loadBitmap(object, filename, hue, smooth); + if (this.hasContentsSprite()) { + const contentsSprite = this._windowContentsSprite; - if (listener) { - bitmap.addLoadListener(listener); - } + if (this.isChild(contentsSprite) && + contentsSprite.isVisible() && + contentsSprite.isSelectable() && + contentsSprite.isHorizontal()) { + const topCol = contentsSprite.getTopCol(); + const maxTopCol = contentsSprite.getMaxTopCol(); - return bitmap; + if (maxTopCol > 0 && topCol < maxTopCol) { + arrow.show(this.isVisibleAndActive() && contentsSprite.isActive()); + } + } + } }; -// reserve methods - /** - * Loads and reserves a bitmap from a folder - * Возвращает загруженный Bitmap - * - * @param {String | Object} folder - Путь к файлу или Объект типа {} - * @param {String} filename - Название файла - * @param {Function} [listener] - Метод обработки после загрузки Bitmap - * @param {Number} [hue] - Оттенок - * @param {Boolean} [smooth] - Сглаживание + * Callback function that will be processing click of the up arrow * - * @param {String} object.folder - Путь к файлу - * @param {String} object.filename - Название файла - * @param {Function} [object.listener] - Метод обработки после загрузки Bitmap - * @param {Number} [object.hue] - Оттенок - * @param {Boolean} [object.smooth] - Сглаживание + * @param {DKTools.Event} event - Event * - * @returns {Bitmap} + * @see DKTools.Window.prototype.createArrows */ -DKTools.Window.prototype.reserveBitmap = function(object, filename, listener, hue, smooth) { - if (object instanceof Object) { - return this.reserveBitmap(object.folder, object.filename, object.listener, object.hue, object.smooth); - } - - // object - String - let bitmap = ImageManager.reserveBitmap(object, filename, hue, smooth); +DKTools.Window.Selectable.prototype.onUpArrowMouseClick = function(event) { + const arrow = event.target; - if (listener) { - bitmap.addLoadListener(listener); + if (arrow.isVisibleAndActive()) { + this._windowContentsSprite.selectPrev(); } - - return bitmap; }; -// events methods - /** - * Updates the events with type: open + * Callback function that will be processing click of the down arrow + * + * @param {DKTools.Event} event - Event + * + * @see DKTools.Window.prototype.createArrows */ -DKTools.Window.prototype.updateOpenEvents = function() { - this.updateEventsContainer('open'); +DKTools.Window.Selectable.prototype.onDownArrowMouseClick = function(event) { + const arrow = event.target; + + if (arrow.isVisibleAndActive()) { + this._windowContentsSprite.selectNext(); + } }; /** - * Updates the events with type: close + * Callback function that will be processing click of the left arrow + * + * @param {DKTools.Event} event - Event + * + * @see DKTools.Window.prototype.createArrows */ -DKTools.Window.prototype.updateCloseEvents = function() { - this.updateEventsContainer('close'); -}; +DKTools.Window.Selectable.prototype.onLeftArrowMouseClick = function(event) { + const arrow = event.target; -// arrow methods + if (arrow.isVisibleAndActive()) { + this._windowContentsSprite.selectPrev(); + } +}; /** - * Callback function that will be processing update of the up arrow + * Callback function that will be processing click of the right arrow * * @param {DKTools.Event} event - Event * * @see DKTools.Window.prototype.createArrows */ -DKTools.Window.prototype.onUpdateUpArrow = function(event) { - // to be overriden by plugins +DKTools.Window.Selectable.prototype.onRightArrowMouseClick = function(event) { + const arrow = event.target; + + if (arrow.isVisibleAndActive()) { + this._windowContentsSprite.selectNext(); + } }; /** - * Callback function that will be processing update of the down arrow + * Callback function that will be processing long press of the up arrow * * @param {DKTools.Event} event - Event * * @see DKTools.Window.prototype.createArrows */ -DKTools.Window.prototype.onUpdateDownArrow = function(event) { - // to be overriden by plugins +DKTools.Window.Selectable.prototype.onUpArrowMouseLongPress = function(event) { + this.onUpArrowMouseClick(event); }; /** - * Callback function that will be processing update of the left arrow + * Callback function that will be processing long press of the down arrow * * @param {DKTools.Event} event - Event * * @see DKTools.Window.prototype.createArrows */ -DKTools.Window.prototype.onUpdateLeftArrow = function(event) { - // to be overriden by plugins +DKTools.Window.Selectable.prototype.onDownArrowMouseLongPress = function(event) { + this.onDownArrowMouseClick(event); }; /** - * Callback function that will be processing update of the right arrow + * Callback function that will be processing long press of the left arrow * * @param {DKTools.Event} event - Event * * @see DKTools.Window.prototype.createArrows */ -DKTools.Window.prototype.onUpdateRightArrow = function(event) { - // to be overriden by plugins +DKTools.Window.Selectable.prototype.onLeftArrowMouseLongPress = function(event) { + this.onLeftArrowMouseClick(event); }; /** - * Callback function that will be processing click of the up arrow + * Callback function that will be processing long press of the right arrow * * @param {DKTools.Event} event - Event * * @see DKTools.Window.prototype.createArrows */ -DKTools.Window.prototype.onClickUpArrow = function(event) { - // to be overriden by plugins +DKTools.Window.Selectable.prototype.onRightArrowMouseLongPress = function(event) { + this.onRightArrowMouseClick(event); }; + + + + +//=========================================================================== +// DKTools.Scene +//=========================================================================== + +DKTools.Scene.prototype = Object.create(Scene_Base.prototype); +DKTools.Scene.prototype.constructor = DKTools.Scene; + +// initialize + /** - * Callback function that will be processing click of the down arrow + * Initializes a class object * - * @param {DKTools.Event} event - Event + * @override + * + * @see DKTools.Scene.prototype._clearAll + * @see DKTools.Scene.prototype._createAll + * @see DKTools.Scene.prototype._setupAll + * @see DKTools.Scene.prototype._addAllChildren + * @see Scene_Base.prototype.initialize + */ +DKTools.Scene.prototype.initialize = function() { + this._clearAll(); + this._createAll(); + this._setupAll(); + this._addAllChildren(); + Scene_Base.prototype.initialize.call(this); +}; + +// _clear methods + +/** + * Clears all data * - * @see DKTools.Window.prototype.createArrows + * @private */ -DKTools.Window.prototype.onClickDownArrow = function(event) { +DKTools.Scene.prototype._clearAll = function() { // to be overriden by plugins }; +// _create methods + /** - * Callback function that will be processing click of the left arrow - * - * @param {DKTools.Event} event - Event + * Creates all * - * @see DKTools.Window.prototype.createArrows + * @version 2.0.0 + * @private + * + * @see DKTools.Scene.prototype._createOptionManager + * @see DKTools.Scene.prototype._createEventManager */ -DKTools.Window.prototype.onClickLeftArrow = function(event) { - // to be overriden by plugins +DKTools.Scene.prototype._createAll = function() { + this._createOptionManager(); + this._createEventManager(); }; /** - * Callback function that will be processing click of the right arrow - * - * @param {DKTools.Event} event - Event - * - * @see DKTools.Window.prototype.createArrows + * Creates the option manager + * + * @since 2.0.0 + * @private */ -DKTools.Window.prototype.onClickRightArrow = function(event) { - // to be overriden by plugins +DKTools.Scene.prototype._createOptionManager = function() { + /** + * @private + * @readonly + * @type {DKTools.OptionManager} + */ + this._optionManager = new DKTools.OptionManager(); }; /** - * Callback function that will be processing long press of the up arrow - * - * @param {DKTools.Event} event - Event + * Creates the event manager * - * @see DKTools.Window.prototype.createArrows + * @since 2.0.0 + * @private + * + * @see DKTools.EventManager */ -DKTools.Window.prototype.onLongPressUpArrow = function(event) { - // to be overriden by plugins +DKTools.Scene.prototype._createEventManager = function() { + /** + * @private + * @readonly + * @type {DKTools.EventManager} + */ + this._eventManager = new DKTools.EventManager(this); }; +// _setup methods + /** - * Callback function that will be processing long press of the down arrow + * Sets all data * - * @param {DKTools.Event} event - Event + * @version 2.0.0 + * @private * - * @see DKTools.Window.prototype.createArrows + * @see DKTools.Scene.prototype._setupOptions + * @see DKTools.Scene.prototype._setupEvents + * @see DKTools.Scene.prototype._setupAnimations */ -DKTools.Window.prototype.onLongPressDownArrow = function(event) { - // to be overriden by plugins +DKTools.Scene.prototype._setupAll = function() { + this._setupOptions(); + this._setupEvents(); + this._setupAnimations(); }; /** - * Callback function that will be processing long press of the left arrow - * - * @param {DKTools.Event} event - Event + * Sets the options * - * @see DKTools.Window.prototype.createArrows + * @since 2.0.0 + * @private */ -DKTools.Window.prototype.onLongPressLeftArrow = function(event) { +DKTools.Scene.prototype._setupOptions = function() { // to be overriden by plugins }; /** - * Callback function that will be processing long press of the right arrow - * - * @param {DKTools.Event} event - Event - * - * @see DKTools.Window.prototype.createArrows + * Sets the events + * + * @since 2.0.0 + * @private */ -DKTools.Window.prototype.onLongPressRightArrow = function(event) { +DKTools.Scene.prototype._setupEvents = function() { // to be overriden by plugins }; -// _update methods - /** - * Updates the contents + * Sets the animations * + * @since 2.0.0 * @private - * @override */ -DKTools.Window.prototype._updateContents = function() { - if (this.hasContentsSprite()) { - Window.prototype._updateContents.call(this); - } +DKTools.Scene.prototype._setupAnimations = function() { + // to be overriden by plugins }; +// _add methods + /** - * Updates the sprite of the pause sign + * Adds children objects to processing * * @private - * @override */ -DKTools.Window.prototype._updatePauseSign = function() { - if (this.hasPauseSignSprite()) { - Window.prototype._updatePauseSign.call(this); - } +DKTools.Scene.prototype._addAllChildren = function() { + // to be overriden by plugins }; -// update methods +// create methods /** - * Updates all + * Creates all * * @override + * + * @see Scene_Base.prototype.create + * @see DKTools.Scene.prototype.createBackground + * @see DKTools.Scene.prototype.createAllSprites + * @see DKTools.Scene.prototype.createWindowLayer + * @see DKTools.Scene.prototype.createAllWindows + * @see DKTools.Scene.prototype.createForeground */ -DKTools.Window.prototype.updateAll = function() { - if (this.hasContentsSprite()) { - this.updateContents(); - } - - DKTools.Base.prototype.updateAll.call(this); - this.updateTone(); +DKTools.Scene.prototype.create = function() { + Scene_Base.prototype.create.call(this); + this.createBackground(); + this.createAllSprites(); + this.createWindowLayer(); + this.createAllWindows(); + this.createForeground(); }; /** - * Updates the contents + * Creates the background */ -DKTools.Window.prototype.updateContents = function() { - if (this.hasContentsSprite()) { - this._windowContentsSprite.updateAll(); - } +DKTools.Scene.prototype.createBackground = function() { + // to be overriden by plugins }; /** - * Updates the transform - * - * @override - * - * @see DKTools.Window.prototype._updateContents - * @see DKTools.Window.prototype._updatePauseSign - * @see PIXI.Container.prototype.updateTransform + * Creates all sprites */ -DKTools.Window.prototype.updateTransform = function() { - this._updateContents(); - this._updatePauseSign(); - PIXI.Container.prototype.updateTransform.call(this); +DKTools.Scene.prototype.createAllSprites = function() { + // to be overriden by plugins }; /** - * Updates the opaciy of thw window - * - * @override - * - * @param {Object} [opacity] - Opacity - * - * @param {Number} [opacity.windowOpacity] - Opacity of the window - * @param {Number} [opacity.contentsOpacity] - Opacity of the contents - * @param {Number} [opacity.frameOpacity] - Opacity of the frame - * @param {Number} [opacity.backOpacity] - Opacity of the background + * Creates all windows */ -DKTools.Window.prototype.updateOpacity = function(opacity) { - opacity = opacity || this.opacity; - - if (this.hasSpriteContainer()) { - this.windowOpacity = opacity.windowOpacity; - } - - if (this.hasContentsSprite()) { - this.contentsOpacity = opacity.contentsOpacity; - } - - if (this.hasFrameSprite()) { - this.frameOpacity = opacity.frameOpacity; - } +DKTools.Scene.prototype.createAllWindows = function() { + // to be overriden by plugins +}; - if (this.hasBackSprite()) { - this.backOpacity = opacity.backOpacity; - } +/** + * Creates the foreground + */ +DKTools.Scene.prototype.createForeground = function() { + // to be overriden by plugins }; +// start methods + /** - * Updates the tone of the window + * Starts the scene * * @override - * - * @see Window.prototype.setTone - * - * @param {Number[]} [tone] - Tone of the window -*/ -DKTools.Window.prototype.updateTone = function(tone) { - tone = tone || this.tone; - - if (this.hasBackSprite()) { - Window.prototype.setTone.apply(this, tone); - } + */ +DKTools.Scene.prototype.start = function() { + Scene_Base.prototype.start.call(this); + this.startAllSprites(); + this.startAllWindows(); }; /** - * Updates the opening of the window - * - * @override -*/ -DKTools.Window.prototype.updateOpen = function() { - if (!this._opening) { - return; - } + * Starts all sprites + */ +DKTools.Scene.prototype.startAllSprites = function() { + // to be overriden by plugins +}; - this.openness += this.standardOpennessSpeed(); - - if (this.isOpen()) { - this._opening = false; - this.updateOpenEvents(); - } +/** + * Starts all windows + */ +DKTools.Scene.prototype.startAllWindows = function() { + // to be overriden by plugins }; +// remove methods + /** - * Updates the closing of the window + * Removes the window from the scene * - * @override -*/ -DKTools.Window.prototype.updateClose = function() { - if (!this._closing) { - return; - } - - this.openness -= this.standardOpennessSpeed(); - - if (this.isClosed()) { - this._closing = false; - this.updateCloseEvents(); - } + * @param {DKTools.Window | *} window - Window to remove + */ +DKTools.Scene.prototype.removeWindow = function(window) { + if (this.hasWindowLayer() && this.isChild(window)) { + this._windowLayer.removeChild(window); + } }; +// has methods + /** - * Updates the window + * Returns true if the scene has the layer of windows * - * @override + * @returns {Boolean} Scene has the layer of windows */ -DKTools.Window.prototype.update = function() { - DKTools.Base.prototype.update.call(this); - this.updateOpen(); - this.updateClose(); - this.updateBackgroundDimmer(); +DKTools.Scene.prototype.hasWindowLayer = function() { + return !!this._windowLayer; }; +// is methods +/** + * Returns true if the window has the parent (if parameter is null or undefined) + * Returns true if the window is an parent of the object (parameter) + * + * @param [object=undefined] - Object + * @returns {Boolean} + */ +DKTools.Scene.prototype.isChild = function(object) { + if (this.hasWindowLayer() && object instanceof Window) { + return object.parent === this._windowLayer; + } + return object && object.parent === this; +}; - -//=========================================================================== -// DKTools.Window.Selectable -//=========================================================================== - -DKTools.Window.Selectable.prototype = Object.create(DKTools.Window.prototype); -DKTools.Window.Selectable.prototype.constructor = DKTools.Window.Selectable; - -// standard methods +// stop methods /** - * Returns the standard sprite of the contents + * Stops the scene * * @override * - * @see DKTools.Sprite.Selectable - * - * @returns {DKTools.Sprite.Selectable} Standard sprite of the contents + * @see Scene_Base.prototype.stop + * @see DKTools.Scene.prototype.stopAll */ -DKTools.Window.Selectable.prototype.standardContentsSprite = function() { - return new DKTools.Sprite.Selectable(); +DKTools.Scene.prototype.stop = function() { + Scene_Base.prototype.stop.call(this); + this.stopAll(); }; -// needs create methods - /** - * Returns true if needs to create the sprites of the arrows - * - * @override - * - * @returns {Boolean} Needs to create the sprites of the arrows + * Stops all */ -DKTools.Window.Selectable.prototype.needsCreateArrowsSprites = function() { - return true; +DKTools.Scene.prototype.stopAll = function() { + // to be overriden by plugins }; -// arrow methods +// terminate methods /** - * Callback function that will be processing update of the up arrow + * Terminates the scene * - * @param {DKTools.Event} event - Event + * @override * - * @see DKTools.Window.prototype.createArrows + * @see Scene_Base.prototype.terminate + * @see DKTools.Scene.prototype.stopAll */ -DKTools.Window.Selectable.prototype.onUpdateUpArrow = function(event) { - const arrow = event.target; - arrow.hide(); - - if (this.hasContentsSprite()) { - const contentsSprite = this._windowContentsSprite; +DKTools.Scene.prototype.terminate = function() { + Scene_Base.prototype.terminate.call(this); + this.terminateAll(); +}; - if (this.isChild(contentsSprite) && - contentsSprite.isVisible() && - contentsSprite.isSelectable() && - contentsSprite.isVertical()) { - if (contentsSprite.getTopRow() > 0) { - arrow.show(this.isVisibleAndActive() && contentsSprite.isActive()); - } - } - } +/** + * Terminates all + */ +DKTools.Scene.prototype.terminateAll = function() { + // to be overriden by plugins }; +// option methods + /** - * Callback function that will be processing update of the down arrow + * Clears the options * - * @param {DKTools.Event} event - Event + * @since 2.0.0 * - * @see DKTools.Window.prototype.createArrows + * @see DKTools.OptionManager.prototype.clear */ -DKTools.Window.Selectable.prototype.onUpdateDownArrow = function(event) { - const arrow = event.target; - arrow.hide(); - - if (this.hasContentsSprite()) { - const contentsSprite = this._windowContentsSprite; - - if (this.isChild(contentsSprite) && - contentsSprite.isVisible() && - contentsSprite.isSelectable() && - contentsSprite.isVertical()) { - const topRow = contentsSprite.getTopRow(); - const maxTopRow = contentsSprite.getMaxTopRow(); - - if (maxTopRow > 0 && topRow < maxTopRow) { - arrow.show(this.isVisibleAndActive() && contentsSprite.isActive()); - } - } - } +DKTools.Scene.prototype.clearOptions = function() { + this._optionManager.clear(); }; /** - * Callback function that will be processing update of the left arrow - * - * @param {DKTools.Event} event - Event + * Returns true if the option is enabled * - * @see DKTools.Window.prototype.createArrows + * @since 2.0.0 + * + * @param {String} option - Name of the option + * + * @see DKTools.OptionManager.prototype.isOptionEnabled + * + * @returns {Boolean} Option is enabled */ -DKTools.Window.Selectable.prototype.onUpdateLeftArrow = function(event) { - const arrow = event.target; - arrow.hide(); - - if (this.hasContentsSprite()) { - const contentsSprite = this._windowContentsSprite; - - if (this.isChild(contentsSprite) && - contentsSprite.isVisible() && - contentsSprite.isSelectable() && - contentsSprite.isHorizontal()) { - if (contentsSprite.getTopCol() > 0) { - arrow.show(this.isVisibleAndActive() && contentsSprite.isActive()); - } - } - } +DKTools.Scene.prototype.isOptionEnabled = function(option) { + return this._optionManager.isOptionEnabled(option); }; /** - * Callback function that will be processing update of the right arrow - * - * @param {DKTools.Event} event - Event + * Returns conjunction of the options * - * @see DKTools.Window.prototype.createArrows + * @since 2.0.0 + * + * @param {String[] | ...String} object - Names of the options + * + * @see DKTools.OptionManager.prototype.isOptionsEnabled + * + * @returns {Boolean} Conjunction of the options */ -DKTools.Window.Selectable.prototype.onUpdateRightArrow = function(event) { - const arrow = event.target; - arrow.hide(); - - if (this.hasContentsSprite()) { - const contentsSprite = this._windowContentsSprite; - - if (this.isChild(contentsSprite) && - contentsSprite.isVisible() && - contentsSprite.isSelectable() && - contentsSprite.isHorizontal()) { - const topCol = contentsSprite.getTopCol(); - const maxTopCol = contentsSprite.getMaxTopCol(); - - if (maxTopCol > 0 && topCol < maxTopCol) { - arrow.show(this.isVisibleAndActive() && contentsSprite.isActive()); - } - } - } +DKTools.Scene.prototype.isOptionsEnabled = function(object) { + return this._optionManager.isOptionsEnabled(object); }; /** - * Callback function that will be processing click of the up arrow + * Returns disjunction of the options * - * @param {DKTools.Event} event - Event + * @since 2.0.0 * - * @see DKTools.Window.prototype.createArrows + * @param {String[] | ...String} object - Names of the options + * + * @see DKTools.OptionManager.prototype.isSomeOptionsEnabled + * + * @returns {Boolean} Disjunction of the options */ -DKTools.Window.Selectable.prototype.onClickUpArrow = function(event) { - const arrow = event.target; - - if (arrow.isVisibleAndActive()) { - this._windowContentsSprite.selectPrev(); - } +DKTools.Scene.prototype.isSomeOptionsEnabled = function(object) { + return this._optionManager.isSomeOptionsEnabled(object); }; /** - * Callback function that will be processing click of the down arrow + * Returns true if the option is disabled * - * @param {DKTools.Event} event - Event + * @since 2.0.0 * - * @see DKTools.Window.prototype.createArrows + * @param {String} option - Name of the option + * + * @see DKTools.OptionManager.prototype.isOptionDisabled + * + * @returns {Boolean} Option is disabled */ -DKTools.Window.Selectable.prototype.onClickDownArrow = function(event) { - const arrow = event.target; - - if (arrow.isVisibleAndActive()) { - this._windowContentsSprite.selectNext(); - } +DKTools.Scene.prototype.isOptionDisabled = function(option) { + return this._optionManager.isOptionDisabled(option); }; /** - * Callback function that will be processing click of the left arrow - * - * @param {DKTools.Event} event - Event + * Returns conjunction of the options * - * @see DKTools.Window.prototype.createArrows + * @since 2.0.0 + * + * @param {String[] | ...String} object - Names of the options + * + * @see DKTools.OptionManager.prototype.isOptionsDisabled + * + * @returns {Boolean} Conjunction of the options */ -DKTools.Window.Selectable.prototype.onClickLeftArrow = function(event) { - const arrow = event.target; - - if (arrow.isVisibleAndActive()) { - this._windowContentsSprite.selectPrev(); - } +DKTools.Scene.prototype.isOptionsDisabled = function(object) { + return this._optionManager.isOptionsDisabled(object); }; /** - * Callback function that will be processing click of the right arrow + * Returns disjunction of the options * - * @param {DKTools.Event} event - Event + * @since 2.0.0 * - * @see DKTools.Window.prototype.createArrows + * @param {String[] | ...String} object - Names of the options + * + * @see DKTools.OptionManager.prototype.isSomeOptionsDisabled + * + * @returns {Boolean} Disjunction of the options */ -DKTools.Window.Selectable.prototype.onClickRightArrow = function(event) { - const arrow = event.target; - - if (arrow.isVisibleAndActive()) { - this._windowContentsSprite.selectNext(); - } +DKTools.Scene.prototype.isSomeOptionsDisabled = function(object) { + return this._optionManager.isSomeOptionsDisabled(object); }; /** - * Callback function that will be processing long press of the up arrow + * Returns true if some option is enabled * - * @param {DKTools.Event} event - Event + * @since 2.0.0 * - * @see DKTools.Window.prototype.createArrows + * @see DKTools.OptionManager.prototype.isSomeOptionEnabled + * + * @returns {Boolean} Some option is enabled */ -DKTools.Window.Selectable.prototype.onLongPressUpArrow = function(event) { - this.onClickUpArrow(event); +DKTools.Scene.prototype.isSomeOptionEnabled = function() { + return this._optionManager.isSomeOptionEnabled(); }; /** - * Callback function that will be processing long press of the down arrow - * - * @param {DKTools.Event} event - Event + * Adds a listener of change of the option * - * @see DKTools.Window.prototype.createArrows + * @since 2.0.0 + * + * @param {String} option - Name of the option + * @param {Function} listener - Listener + * + * @see DKTools.OptionManager.prototype.addOptionChangeListener */ -DKTools.Window.Selectable.prototype.onLongPressDownArrow = function(event) { - this.onClickDownArrow(event); +DKTools.Scene.prototype.addOptionChangeListener = function(option, listener) { + this._optionManager.addOptionChangeListener(options, listener); }; /** - * Callback function that will be processing long press of the left arrow - * - * @param {DKTools.Event} event - Event - * - * @see DKTools.Window.prototype.createArrows + * Removes the listener of change of the option + * + * @since 2.0.0 + * + * @param {String} option - Name of the option + * @param {Function} listener - Listener + * + * @see DKTools.OptionManager.prototype.removeOptionsChangeListener */ -DKTools.Window.Selectable.prototype.onLongPressLeftArrow = function(event) { - this.onClickLeftArrow(event); +DKTools.Scene.prototype.removeOptionChangeListener = function(option, listener) { + this._optionManager.removeOptionsChangeListener(option, listener); }; /** - * Callback function that will be processing long press of the right arrow - * - * @param {DKTools.Event} event - Event + * Turns on the option * - * @see DKTools.Window.prototype.createArrows + * @since 2.0.0 + * + * @param {String} option - Name of the option + * + * @see DKTools.OptionManager.prototype.enableOption */ -DKTools.Window.Selectable.prototype.onLongPressRightArrow = function(event) { - this.onClickRightArrow(event); +DKTools.Scene.prototype.enableOption = function(option) { + this._optionManager.enableOption(option); }; - - - - -//=========================================================================== -// DKTools.Scene -//=========================================================================== - -DKTools.Scene.prototype = Object.create(Scene_Base.prototype); -DKTools.Scene.prototype.constructor = DKTools.Scene; - -// initialize - /** - * Initializes a class object - * - * @override + * Turns on the options * - * @see DKTools.Scene.prototype._clearAll - * @see DKTools.Scene.prototype._createAll - * @see DKTools.Scene.prototype._setupAll - * @see DKTools.Scene.prototype._addAllChildren - * @see Scene_Base.prototype.initialize + * @since 2.0.0 + * + * @param {String[] | ...String} object - Names of the options + * + * @see DKTools.OptionManager.prototype.enableOptions */ -DKTools.Scene.prototype.initialize = function() { - this._clearAll(); - this._createAll(); - this._setupAll(); - this._addAllChildren(); - Scene_Base.prototype.initialize.call(this); +DKTools.Scene.prototype.enableOptions = function(object) { + this._optionManager.enableOption(object); }; -// _clear methods - /** - * Clears all data + * Turns off the option * - * @private + * @since 2.0.0 + * + * @param {String} option - Name of the option + * + * @see DKTools.OptionManager.prototype.disableOption */ -DKTools.Scene.prototype._clearAll = function() { - // to be overriden by plugins +DKTools.Scene.prototype.disableOption = function(option) { + this._optionManager.disableOption(option); }; -// _create methods - /** - * Creates all + * Turns off the options * - * @version 2.0.0 - * @private + * @since 2.0.0 * - * @see DKTools.Scene.prototype._createOptionManager - * @see DKTools.Scene.prototype._createEventManager + * @param {String[] | ...String} object - Names of the options + * + * @see DKTools.OptionManager.prototype.disableOptions */ -DKTools.Scene.prototype._createAll = function() { - this._createOptionManager(); - this._createEventManager(); +DKTools.Scene.prototype.disableOptions = function(object) { + this._optionManager.disableOption(object); }; /** - * Creates the option manager - * + * Switches the option + * * @since 2.0.0 - * @private + * + * @param {String} option - Name of the option + * + * @see DKTools.OptionManager.prototype.switchOption */ -DKTools.Scene.prototype._createOptionManager = function() { - /** - * @private - * @readonly - * @type {DKTools.OptionManager} - */ - this._optionManager = new DKTools.OptionManager(); +DKTools.Scene.prototype.switchOption = function(option) { + this._optionManager.disableOption(option); }; /** - * Creates the event manager + * Switches the options * * @since 2.0.0 - * @private * - * @see DKTools.EventManager + * @param {String[] | ...String} object - Names of the options + * + * @see DKTools.OptionManager.prototype.switchOptions */ -DKTools.Scene.prototype._createEventManager = function() { - /** - * @private - * @readonly - * @type {DKTools.EventManager} - */ - this._eventManager = new DKTools.EventManager(this); +DKTools.Scene.prototype.switchOptions = function(object) { + this._optionManager.switchOptions(object); }; -// _setup methods +// events methods /** - * Sets all data + * Clears the events * * @version 2.0.0 - * @private * - * @see DKTools.Scene.prototype._setupOptions - * @see DKTools.Scene.prototype._setupEvents - * @see DKTools.Scene.prototype._setupAnimations + * @param {String[] | String} object Array with event types or event type + * + * @see DKTools.EventManager.prototype.clearEvents */ -DKTools.Scene.prototype._setupAll = function() { - this._setupOptions(); - this._setupEvents(); - this._setupAnimations(); +DKTools.Scene.prototype.clearEvents = function(object) { + this._eventManager.clearEvents(object); }; /** - * Sets the options + * Removes the event from a container + * Returns true if the event was removed * * @since 2.0.0 - * @private + * + * @param {DKTools.Event | DKTools.Animation} event - Event + * + * @see DKTools.EventManager.prototype.removeEvent + * + * @returns {Boolean} Event was removed */ -DKTools.Scene.prototype._setupOptions = function() { - // to be overriden by plugins +DKTools.Scene.prototype.removeEvent = function(event) { + return this._eventManager.removeEvent(event); }; /** - * Sets the events - * + * Performs a callback function for the events + * * @since 2.0.0 - * @private + * + * @param {String} type - Type of the events + * @param {Function} callback - Event processing function + * + * @see DKTools.EventManager.prototype.iterateEventsContainer */ -DKTools.Scene.prototype._setupEvents = function() { - // to be overriden by plugins +DKTools.Scene.prototype.iterateEventsContainer = function(type, callback) { + this._eventManager.iterateEventsContainer(type, callback); }; /** - * Sets the animations + * Checks the events for pause + * Returns the conjunction of pauses of the events * * @since 2.0.0 - * @private + * + * @param {String} type - Type of the events + * + * @see DKTools.EventManager.prototype.isEventsPaused + * + * @returns {Boolean} Conjunction of pauses of the events */ -DKTools.Scene.prototype._setupAnimations = function() { - // to be overriden by plugins +DKTools.Scene.prototype.isEventsPaused = function(type) { + return this._eventManager.isEventsPaused(type); }; -// _add methods - /** - * Adds children objects to processing + * Pauses the events * - * @private + * @since 2.0.0 + * + * @param {String} type - Type of the events + * @param {Number} duration - Duration of pause + * + * @see DKTools.EventManager.prototype.pauseEvents */ -DKTools.Scene.prototype._addAllChildren = function() { - // to be overriden by plugins +DKTools.Scene.prototype.pauseEvents = function(type, duration) { + this._eventManager.pauseEvents(type, duration); }; -// create methods - /** - * Creates all + * Resumes the events * - * @override + * @since 2.0.0 * - * @see Scene_Base.prototype.create - * @see DKTools.Scene.prototype.createBackground - * @see DKTools.Scene.prototype.createAllSprites - * @see DKTools.Scene.prototype.createWindowLayer - * @see DKTools.Scene.prototype.createAllWindows - * @see DKTools.Scene.prototype.createForeground + * @param {String} type - Type of the events + * + * @see DKTools.EventManager.prototype.resumeEvents */ -DKTools.Scene.prototype.create = function() { - Scene_Base.prototype.create.call(this); - this.createBackground(); - this.createAllSprites(); - this.createWindowLayer(); - this.createAllWindows(); - this.createForeground(); +DKTools.Scene.prototype.resumeEvents = function(type) { + this._eventManager.resumeEvents(type); }; /** - * Creates the background + * Finishes the events + * + * @since 2.0.0 + * + * @param {String} type - Type of the events + * @param {Boolean} [forcedSuccess] - Forced success for the finish of the events + * + * @see DKTools.EventManager.prototype.finishEvents */ -DKTools.Scene.prototype.createBackground = function() { - // to be overriden by plugins +DKTools.Scene.prototype.finishEvents = function(type, forcedSuccess) { + this._eventManager.finishEvents(type, forcedSuccess); }; /** - * Creates all sprites + * Stops the events + * + * @since 2.0.0 + * + * @param {String} type - Type of the events + * @param {Boolean} [forcedSuccess] - Forced success for the finish of the events + * + * @see DKTools.EventManager.prototype.stopEvents */ -DKTools.Scene.prototype.createAllSprites = function() { - // to be overriden by plugins +DKTools.Scene.prototype.stopEvents = function(type, forcedSuccess) { + this._eventManager.stopEvents(type, forcedSuccess); }; /** - * Creates all windows + * Updates the events + * + * @since 2.0.0 + * + * @see DKTools.EventManager.prototype.update + * @see DKTools.Base.protoype.updateReadyEvents + * @see DKTools.Base.protoype.updateUpdateEvents + * @see DKTools.Base.protoype.updateQueueEvents + * @see DKTools.Base.protoype.updateWheelEvents */ -DKTools.Scene.prototype.createAllWindows = function() { - // to be overriden by plugins +DKTools.Scene.prototype.updateEvents = function() { + this._eventManager.update(); + this.updateReadyEvents(); + this.updateUpdateEvents(); + this.updateQueueEvents(); }; /** - * Creates the foreground + * Updates the event + * + * @since 2.0.0 + * + * @param {DKTools.Event | DKTools.Animation} event - Event + * + * @see DKTools.EventManager.prototype.updateEvent */ -DKTools.Scene.prototype.createForeground = function() { - // to be overriden by plugins +DKTools.Scene.prototype.updateEvent = function(event) { + this._eventManager.updateEvent(event); }; -// start methods - /** - * Starts the scene + * Updates the events from container * - * @override + * @since 2.0.0 + * + * @param {String} type - Type of the events + * + * @see DKTools.EventManager.prototype.updateEventsContainer */ -DKTools.Scene.prototype.start = function() { - Scene_Base.prototype.start.call(this); - this.startAllSprites(); - this.startAllWindows(); +DKTools.Scene.prototype.updateEventsContainer = function(type) { + this._eventManager.updateEventsContainer(type); }; /** - * Starts all sprites + * Updates the events with type: ready + * + * @since 2.0.0 + * + * @see DKTools.EventManager.prototype.updateEventsContainer */ -DKTools.Scene.prototype.startAllSprites = function() { - // to be overriden by plugins +DKTools.Scene.prototype.updateReadyEvents = function() { + if (this.isReady()) { + this.updateEventsContainer('ready'); + } }; /** - * Starts all windows + * Updates the events with type: update + * + * @since 2.0.0 + * + * @see DKTools.EventManager.prototype.updateEventsContainer */ -DKTools.Scene.prototype.startAllWindows = function() { - // to be overriden by plugins +DKTools.Scene.prototype.updateUpdateEvents = function() { + this.updateEventsContainer('update'); }; -// remove methods - /** - * Removes the window from the scene + * Updates the events with type: queue * - * @param {DKTools.Window | *} window - Window to remove + * @since 2.0.0 + * + * @see DKTools.EventManager.prototype.updateEventsContainer */ -DKTools.Scene.prototype.removeWindow = function(window) { - if (this.hasWindowLayer() && this.isChild(window)) { - this._windowLayer.removeChild(window); - } +DKTools.Scene.prototype.updateQueueEvents = function() { + const container = this.getEventsContainerByType('queue'); + const event = container[0]; + this.updateEvent(event); }; -// has methods - /** - * Returns true if the scene has the layer of windows + * Returns a container for the events by event type * - * @returns {Boolean} Scene has the layer of windows + * @since 2.0.0 + * + * @param {String} type - Type of the events + * + * @see DKTools.EventManager.prototype.getEventsContainerByType + * + * @returns {Array} Container for the events */ -DKTools.Scene.prototype.hasWindowLayer = function() { - return !!this._windowLayer; +DKTools.Scene.prototype.getEventsContainerByType = function(type) { + return this._eventManager.getEventsContainerByType(type); }; -// is methods - /** - * Returns true if the window has the parent (if parameter is null or undefined) - * Returns true if the window is an parent of the object (parameter) + * Returns a container for the events by event * - * @param [object=undefined] - Object - * @returns {Boolean} + * @since 2.0.0 + * + * @param {DKTools.Event | DKTools.Animation} event - Event + * + * @see DKTools.EventManager.prototype.getEventsContainer + * + * @returns {Array} Container for the events */ -DKTools.Scene.prototype.isChild = function(object) { - if (this.hasWindowLayer() && object instanceof Window) { - return object.parent === this._windowLayer; - } - - return object && object.parent === this; +DKTools.Scene.prototype.getEventsContainer = function(event) { + return this._eventManager.getEventsContainer(event); }; -// stop methods - /** - * Stops the scene + * Returns an index of the event in its container * - * @override + * @since 2.0.0 * - * @see Scene_Base.prototype.stop - * @see DKTools.Scene.prototype.stopAll + * @param {DKTools.Event | DKTools.Animation} event - Event + * + * @see DKTools.EventManager.prototype.getEventIndex + * + * @returns {Number} Index of the event in its container */ -DKTools.Scene.prototype.stop = function() { - Scene_Base.prototype.stop.call(this); - this.stopAll(); +DKTools.Scene.prototype.getEventIndex = function(event) { + return this._eventManager.getEventIndex(event); }; /** - * Stops all + * Returns an array with the all events or events of a certain type + * + * @since 2.0.0 + * + * @param {String} [type] - Type of the events + * + * @see DKTools.EventManager.prototype.getEvents + * + * @returns {Array} Array with the events */ -DKTools.Scene.prototype.stopAll = function() { - // to be overriden by plugins +DKTools.Scene.prototype.getEvents = function(type) { + return this._eventManager.getEvents(type); }; -// terminate methods - /** - * Terminates the scene + * Returns an array with the all animations or animations of a certain type * - * @override + * @since 2.0.0 * - * @see Scene_Base.prototype.terminate - * @see DKTools.Scene.prototype.stopAll + * @param {String} [type] - Type of animation + * + * @see DKTools.EventManager.prototype.getAnimations + * + * @returns {Array} Array with the animations */ -DKTools.Scene.prototype.terminate = function() { - Scene_Base.prototype.terminate.call(this); - this.terminateAll(); +DKTools.Scene.prototype.getAnimations = function(type) { + return this._eventManager.getAnimations(type); }; /** - * Terminates all + * Checks for existence of the event in the object + * Returns true if the event exists + * + * @since 2.0.0 + * + * @param {DKTools.Event | DKTools.Animation} event - Event + * + * @see DKTools.EventManager.prototype.hasEvent + * + * @returns {Boolean} Event exists */ -DKTools.Scene.prototype.terminateAll = function() { - // to be overriden by plugins +DKTools.Scene.prototype.hasEvent = function(event) { + return this._eventManager.hasEvent(event); }; -// option methods - /** - * Clears the options + * Checks for existence of the events of a certain type + * Returns true if the events exists * * @since 2.0.0 * - * @see DKTools.OptionManager.prototype.clear + * @param {String} [type] - Type of the Events + * + * @see DKTools.EventManager.prototype.hasEvents + * + * @returns {Boolean} Events exists */ -DKTools.Scene.prototype.clearOptions = function() { - this._optionManager.clear(); +DKTools.Scene.prototype.hasEvents = function(type) { + return this._eventManager.hasEvents(type); }; /** - * Returns true if the option is enabled + * Checks for existence of the animation in the object + * Returns true if the animation exists * * @since 2.0.0 - * - * @param {String} option - Name of the option - * - * @see DKTools.OptionManager.prototype.isOptionEnabled - * - * @returns {Boolean} Option is enabled + * + * @param {DKTools.Animation} animation - Animation + * + * @see DKTools.EventManager.prototype.hasAnimation + * + * @returns {Boolean} Animation exists */ -DKTools.Scene.prototype.isOptionEnabled = function(option) { - return this._optionManager.isOptionEnabled(option); +DKTools.Scene.prototype.hasAnimation = function(animation) { + return this._eventManager.hasAnimation(animation); }; /** - * Returns conjunction of the options + * Checks for existence of the animations of a certain type + * Returns true if the animations exists * * @since 2.0.0 - * - * @param {String[] | ...String} object - Names of the options - * - * @see DKTools.OptionManager.prototype.isOptionsEnabled - * - * @returns {Boolean} Conjunction of the options - */ -DKTools.Scene.prototype.isOptionsEnabled = function(object) { - return this._optionManager.isOptionsEnabled(object); + * + * @param {String} [type] - Type of the animations + * + * @see DKTools.EventManager.prototype.hasAnimations + * + * @returns {Boolean} Animations exists + */ +DKTools.Scene.prototype.hasAnimations = function(type) { + return this._eventManager.hasAnimations(type); }; /** - * Returns disjunction of the options + * Adds the event * * @since 2.0.0 * - * @param {String[] | ...String} object - Names of the options + * @param {DKTools.Event | Object} object - Event or object with parameters for the event * - * @see DKTools.OptionManager.prototype.isSomeOptionsEnabled + * @param {String} [object.type] - Type of the event + * @param {Number} [object.repeatTime] - Time of one repeat + * @param {Number} [object.repeats] - Amount of repeats + * @param {Number} [object.remainingPauseTime] - Remaining time of pause + * @param {Function} [object.onStart] - Handler of the event start + * @param {Function} [object.onUpdate] - Handler of the event update + * @param {Function} [object.onPause] - Handler of the event pause + * @param {Function} [object.onReset] - Handler of the event reset + * @param {Function} [object.onRepeat] - Handler of the event repeat + * @param {Function} [object.onSuccess] - Handler of the event success + * @param {Function} [object.onFail] - Handler of the event fail * - * @returns {Boolean} Disjunction of the options + * @see DKTools.Event + * @see DKTools.EventManager.prototype.addEvent + * + * @returns {DKTools.Event} Added event */ -DKTools.Scene.prototype.isSomeOptionsEnabled = function(object) { - return this._optionManager.isSomeOptionsEnabled(object); +DKTools.Scene.prototype.addEvent = function(object) { + return this._eventManager.addEvent(object); }; /** - * Returns true if the option is disabled + * Adds the one time event * * @since 2.0.0 * - * @param {String} option - Name of the option + * @param {DKTools.Event | Object} object - Event or object with parameters for the event * - * @see DKTools.OptionManager.prototype.isOptionDisabled + * @param {String} [object.type] - Type of the event + * @param {Number} [object.remainingPauseTime] - Remaining time of pause + * @param {Function} [object.onStart] - Handler of the event start + * @param {Function} [object.onUpdate] - Handler of the event update + * @param {Function} [object.onPause] - Handler of the event pause + * @param {Function} [object.onReset] - Handler of the event reset + * @param {Function} [object.onRepeat] - Handler of the event repeat + * @param {Function} [object.onSuccess] - Handler of the event success + * @param {Function} [object.onFail] - Handler of the event fail * - * @returns {Boolean} Option is disabled + * @see DKTools.Event + * @see DKTools.EventManager.prototype.addOneTimeEvent + * + * @returns {DKTools.Event} Added event */ -DKTools.Scene.prototype.isOptionDisabled = function(option) { - return this._optionManager.isOptionDisabled(option); +DKTools.Scene.prototype.addOneTimeEvent = function(object) { + return this._eventManager.addOneTimeEvent(object); }; /** - * Returns conjunction of the options + * Adds the animation * * @since 2.0.0 - * - * @param {String[] | ...String} object - Names of the options - * - * @see DKTools.OptionManager.prototype.isOptionsDisabled - * - * @returns {Boolean} Conjunction of the options + * + * @param {DKTools.Animation} animation - Animation to add + * + * @see DKTools.EventManager.addAnimation */ -DKTools.Scene.prototype.isOptionsDisabled = function(object) { - return this._optionManager.isOptionsDisabled(object); +DKTools.Scene.prototype.addAnimation = function(animation) { + this._eventManager.addAnimation(animation); }; +// other methods + /** - * Returns disjunction of the options - * - * @since 2.0.0 - * - * @param {String[] | ...String} object - Names of the options - * - * @see DKTools.OptionManager.prototype.isSomeOptionsDisabled + * Calls the callback function for the child objects * - * @returns {Boolean} Disjunction of the options + * @param {Function} callback - Function for the child objects */ -DKTools.Scene.prototype.isSomeOptionsDisabled = function(object) { - return this._optionManager.isSomeOptionsDisabled(object); +DKTools.Scene.prototype.iterateChildren = function(callback) { + _.forEach(this.children, callback); }; +// update methods + /** - * Returns true if some option is enabled - * - * @since 2.0.0 + * Updates the scene * - * @see DKTools.OptionManager.prototype.isSomeOptionEnabled + * @version 2.0.0 + * @override * - * @returns {Boolean} Some option is enabled + * @see DKTools.Scene.prototype.updateChildren + * @see DKTools.Scene.prototype.updateFade */ -DKTools.Scene.prototype.isSomeOptionEnabled = function() { - return this._optionManager.isSomeOptionEnabled(); +DKTools.Scene.prototype.update = function() { + this.updateChildren(); + this.updateFade(); + this.updateEvents(); }; /** - * Adds a listener of change of the option + * Updates the child object * - * @since 2.0.0 - * - * @param {String} option - Name of the option - * @param {Function} listener - Listener - * - * @see DKTools.OptionManager.prototype.addOptionChangeListener + * @param {*} child - Child object */ -DKTools.Scene.prototype.addOptionChangeListener = function(option, listener) { - this._optionManager.addOptionChangeListener(options, listener); +DKTools.Scene.prototype.updateChild = function(child) { + if (child && DKTools.Utils.isFunction(child.update)) { + child.update(); + } }; /** - * Removes the listener of change of the option - * - * @since 2.0.0 - * - * @param {String} option - Name of the option - * @param {Function} listener - Listener - * - * @see DKTools.OptionManager.prototype.removeOptionsChangeListener + * Updates the child objects + * + * @override + * + * @see DKTools.Scene.prototype.iterateChildren + * @see DKTools.Scene.prototype.updateChild */ -DKTools.Scene.prototype.removeOptionChangeListener = function(option, listener) { - this._optionManager.removeOptionsChangeListener(option, listener); +DKTools.Scene.prototype.updateChildren = function() { + this.iterateChildren(this.updateChild); }; /** - * Turns on the option - * - * @since 2.0.0 - * - * @param {String} option - Name of the option + * Updates the events * - * @see DKTools.OptionManager.prototype.enableOption + * @since 2.0.0 */ -DKTools.Scene.prototype.enableOption = function(option) { - this._optionManager.enableOption(option); +DKTools.Scene.prototype.updateEvents = function() { + this._eventManager.update(); }; + + + + +//=========================================================================== +// initialize parameters +//=========================================================================== + /** - * Turns on the options - * - * @since 2.0.0 - * - * @param {String[] | ...String} object - Names of the options - * - * @see DKTools.OptionManager.prototype.enableOptions + * @global + * @readonly + * @type {DKTools.ParameterManager} */ -DKTools.Scene.prototype.enableOptions = function(object) { - this._optionManager.enableOption(object); +const DKToolsParam = new DKTools.ParameterManager('DKTools'); + + + + + +//=========================================================================== +// window +//=========================================================================== + +const DKTools_window_onload = window.onload; +window.onload = function() { + DKTools.Utils.initialize(); + DKTools.IO.initialize(); + DKTools_window_onload.call(this); + DKTools.PluginManager.initialize(); + DKTools.PreloadManager.initialize(); +}; + + + + + +//=========================================================================== +// ImageCache +//=========================================================================== + +const DKTools_ImageCache_get = ImageCache.prototype.get; +ImageCache.prototype.get = function(key) { + return DKTools_ImageCache_get.call(this, key) || DKTools.PreloadManager.getCachedBitmapByKey(key); +}; + + + + + +//=========================================================================== +// Graphics +//=========================================================================== + +const DKTools_Graphics_initialize = Graphics.initialize; +Graphics.initialize = function(width, height, type) { + DKTools_Graphics_initialize.call(this, width, height, type); + + if (Utils.isOptionValid('test') && DKToolsParam.get('Show FPS')) { + this.showFps(); + } +}; + +const DKTools_Graphics_printLoadingError = Graphics.printLoadingError; +Graphics.printLoadingError = function(url) { + DKTools_Graphics_printLoadingError.call(this, url); + SceneManager._logError(`Failed to load: ${url}`); }; -/** - * Turns off the option - * - * @since 2.0.0 - * - * @param {String} option - Name of the option - * - * @see DKTools.OptionManager.prototype.disableOption - */ -DKTools.Scene.prototype.disableOption = function(option) { - this._optionManager.disableOption(option); -}; -/** - * Turns off the options - * - * @since 2.0.0 - * - * @param {String[] | ...String} object - Names of the options - * - * @see DKTools.OptionManager.prototype.disableOptions - */ -DKTools.Scene.prototype.disableOptions = function(object) { - this._optionManager.disableOption(object); -}; -/** - * Switches the option - * - * @since 2.0.0 - * - * @param {String} option - Name of the option - * - * @see DKTools.OptionManager.prototype.switchOption - */ -DKTools.Scene.prototype.switchOption = function(option) { - this._optionManager.disableOption(option); -}; -/** - * Switches the options - * - * @since 2.0.0 - * - * @param {String[] | ...String} object - Names of the options - * - * @see DKTools.OptionManager.prototype.switchOptions - */ -DKTools.Scene.prototype.switchOptions = function(object) { - this._optionManager.switchOptions(object); -}; -// events methods +//=========================================================================== +// TouchInput +//=========================================================================== + +const DKTools_TouchInput_clear = TouchInput.clear; +TouchInput.clear = function() { + DKTools_TouchInput_clear.call(this); + + /** + * @private + * @readonly + * @type {Boolean} + */ + this._mouseMoved = false; + + /** + * @private + * @readonly + * @type {Boolean} + */ + this._leftButtonPressed = false; + + /** + * @private + * @readonly + * @type {Boolean} + */ + this._middleButtonPressed = false; + + /** + * @private + * @readonly + * @type {Boolean} + */ + this._rightButtonPressed = false; + + /** + * @private + * @readonly + * @type {Boolean} + */ + this._leftButtonReleased = false; + + /** + * @private + * @readonly + * @type {Boolean} + */ + this._middleButtonReleased = false; + + /** + * @private + * @readonly + * @type {Boolean} + */ + this._rightButtonReleased = false; + + /** + * @private + * @readonly + * @type {Number} + */ + this._mouseX = 0; + + /** + * @private + * @readonly + * @type {Number} + */ + this._mouseY = 0; + + this._events.mouseMoved = false; -/** - * Clears the events - * - * @version 2.0.0 - * - * @param {String[] | String} object Array with event types or event type - * - * @see DKTools.EventManager.prototype.clearEvents - */ -DKTools.Scene.prototype.clearEvents = function(object) { - this._eventManager.clearEvents(object); -}; + this._events.leftButtonPressed = false; + this._events.middleButtonPressed = false; + this._events.rightButtonPressed = false; -/** - * Removes the event from a container - * Returns true if the event was removed - * - * @since 2.0.0 - * - * @param {DKTools.Event | DKTools.Animation} event - Event - * - * @see DKTools.EventManager.prototype.removeEvent - * - * @returns {Boolean} Event was removed - */ -DKTools.Scene.prototype.removeEvent = function(event) { - return this._eventManager.removeEvent(event); + this._events.leftButtonReleased = false; + this._events.middleButtonReleased = false; + this._events.rightButtonReleased = false; }; -/** - * Performs a callback function for the events - * - * @since 2.0.0 - * - * @param {String} type - Type of the events - * @param {Function} callback - Event processing function - * - * @see DKTools.EventManager.prototype.iterateEventsContainer - */ -DKTools.Scene.prototype.iterateEventsContainer = function(type, callback) { - this._eventManager.iterateEventsContainer(type, callback); -}; +const DKTools_TouchInput_update = TouchInput.update; +TouchInput.update = function() { + this._mouseMoved = this._events.mouseMoved; -/** - * Checks the events for pause - * Returns the conjunction of pauses of the events - * - * @since 2.0.0 - * - * @param {String} type - Type of the events - * - * @see DKTools.EventManager.prototype.isEventsPaused - * - * @returns {Boolean} Conjunction of pauses of the events - */ -DKTools.Scene.prototype.isEventsPaused = function(type) { - return this._eventManager.isEventsPaused(type); -}; + this._leftButtonPressed = this._events.leftButtonPressed; + this._middleButtonPressed = this._events.middleButtonPressed; + this._rightButtonPressed = this._events.rightButtonPressed; -/** - * Pauses the events - * - * @since 2.0.0 - * - * @param {String} type - Type of the events - * @param {Number} duration - Duration of pause - * - * @see DKTools.EventManager.prototype.pauseEvents - */ -DKTools.Scene.prototype.pauseEvents = function(type, duration) { - this._eventManager.pauseEvents(type, duration); -}; + this._leftButtonReleased = this._events.leftButtonReleased; + this._middleButtonReleased = this._events.middleButtonReleased; + this._rightButtonReleased = this._events.rightButtonReleased; -/** - * Resumes the events - * - * @since 2.0.0 - * - * @param {String} type - Type of the events - * - * @see DKTools.EventManager.prototype.resumeEvents - */ -DKTools.Scene.prototype.resumeEvents = function(type) { - this._eventManager.resumeEvents(type); -}; + this._events.mouseMoved = false; -/** - * Finishes the events - * - * @since 2.0.0 - * - * @param {String} type - Type of the events - * @param {Boolean} [forcedSuccess] - Forced success for the finish of the events - * - * @see DKTools.EventManager.prototype.finishEvents - */ -DKTools.Scene.prototype.finishEvents = function(type, forcedSuccess) { - this._eventManager.finishEvents(type, forcedSuccess); + this._events.leftButtonReleased = false; + this._events.middleButtonReleased = false; + this._events.rightButtonReleased = false; + + DKTools_TouchInput_update.call(this); }; +// is methods + /** - * Stops the events - * - * @since 2.0.0 - * - * @param {String} type - Type of the events - * @param {Boolean} [forcedSuccess] - Forced success for the finish of the events + * Returns true if the mouse is moving * - * @see DKTools.EventManager.prototype.stopEvents + * @static + * @returns {Boolean} Mouse is moving */ -DKTools.Scene.prototype.stopEvents = function(type, forcedSuccess) { - this._eventManager.stopEvents(type, forcedSuccess); +TouchInput.isMouseMoved = function() { + return this._mouseMoved; }; /** - * Updates the events - * - * @since 2.0.0 + * Returns true if the mouse is pressed (left, middle or right button) * - * @see DKTools.EventManager.prototype.update - * @see DKTools.Base.protoype.updateReadyEvents - * @see DKTools.Base.protoype.updateUpdateEvents - * @see DKTools.Base.protoype.updateQueueEvents - * @see DKTools.Base.protoype.updateWheelEvents + * @static + * @returns {Boolean} Mouse is pressed (left, middle or right button) */ -DKTools.Scene.prototype.updateEvents = function() { - this._eventManager.update(); - this.updateReadyEvents(); - this.updateUpdateEvents(); - this.updateQueueEvents(); +TouchInput.isMousePressed = function() { + return this.isLeftButtonPressed() || this.isMiddleButtonPressed() || this.isRightButtonPressed(); }; /** - * Updates the event - * - * @since 2.0.0 - * - * @param {DKTools.Event | DKTools.Animation} event - Event + * Returns true if the mouse is released (left, middle or right button is released) * - * @see DKTools.EventManager.prototype.updateEvent + * @static + * @returns {Boolean} Mouse is released (left, middle or right button is released) */ -DKTools.Scene.prototype.updateEvent = function(event) { - this._eventManager.updateEvent(event); +TouchInput.isMouseReleased = function() { + return this.isLeftButtonReleased() || this.isMiddleButtonReleased() || this.isRightButtonReleased(); }; /** - * Updates the events from container - * - * @since 2.0.0 - * - * @param {String} type - Type of the events + * Returns true if the left mouse button is pressed * - * @see DKTools.EventManager.prototype.updateEventsContainer + * @static + * @returns {Boolean} Left mouse button is pressed */ -DKTools.Scene.prototype.updateEventsContainer = function(type) { - this._eventManager.updateEventsContainer(type); +TouchInput.isLeftButtonPressed = function() { + return this._leftButtonPressed; }; /** - * Updates the events with type: ready - * - * @since 2.0.0 + * Returns true if the left mouse button is released * - * @see DKTools.EventManager.prototype.updateEventsContainer + * @static + * @returns {Boolean} Left mouse button is released */ -DKTools.Scene.prototype.updateReadyEvents = function() { - if (this.isReady()) { - this.updateEventsContainer('ready'); - } +TouchInput.isLeftButtonReleased = function() { + return this._leftButtonReleased; }; /** - * Updates the events with type: update - * - * @since 2.0.0 + * Returns true if the middle mouse button is pressed * - * @see DKTools.EventManager.prototype.updateEventsContainer + * @static + * @returns {Boolean} Middle mouse button is pressed */ -DKTools.Scene.prototype.updateUpdateEvents = function() { - this.updateEventsContainer('update'); +TouchInput.isMiddleButtonPressed = function() { + return this._middleButtonPressed; }; /** - * Updates the events with type: queue - * - * @since 2.0.0 + * Returns true if the middle mouse button is released * - * @see DKTools.EventManager.prototype.updateEventsContainer + * @static + * @returns {Boolean} Middle mouse button is released */ -DKTools.Scene.prototype.updateQueueEvents = function() { - const container = this.getEventsContainerByType('queue'); - const event = container[0]; - this.updateEvent(event); +TouchInput.isMiddleButtonReleased = function() { + return this._middleButtonReleased; }; /** - * Returns a container for the events by event type - * - * @since 2.0.0 - * - * @param {String} type - Type of the events - * - * @see DKTools.EventManager.prototype.getEventsContainerByType + * Returns true if the right mouse button is pressed * - * @returns {Array} Container for the events + * @static + * @returns {Boolean} Right mouse button is pressed */ -DKTools.Scene.prototype.getEventsContainerByType = function(type) { - return this._eventManager.getEventsContainerByType(type); +TouchInput.isRightButtonPressed = function() { + return this._rightButtonPressed; }; /** - * Returns a container for the events by event - * - * @since 2.0.0 - * - * @param {DKTools.Event | DKTools.Animation} event - Event - * - * @see DKTools.EventManager.prototype.getEventsContainer + * Returns true if the right mouse button is released * - * @returns {Array} Container for the events + * @static + * @returns {Boolean} Right mouse button is released */ -DKTools.Scene.prototype.getEventsContainer = function(event) { - return this._eventManager.getEventsContainer(event); +TouchInput.isRightButtonReleased = function() { + return this._rightButtonReleased; +}; + +// event methods + +const DKTools_TouchInput_onLeftButtonDown = TouchInput._onLeftButtonDown; +TouchInput._onLeftButtonDown = function(event) { + const x = Graphics.pageToCanvasX(event.pageX); + const y = Graphics.pageToCanvasY(event.pageY); + + DKTools_TouchInput_onLeftButtonDown.call(this, event); + + if (Graphics.isInsideCanvas(x, y)) { + this._events.leftButtonPressed = true; + } +}; + +const DKTools_TouchInput_onMiddleButtonDown = TouchInput._onMiddleButtonDown; +TouchInput._onMiddleButtonDown = function(event) { + const x = Graphics.pageToCanvasX(event.pageX); + const y = Graphics.pageToCanvasY(event.pageY); + + DKTools_TouchInput_onMiddleButtonDown.call(this, event); + + if (Graphics.isInsideCanvas(x, y)) { + this._events.middleButtonPressed = true; + } +}; + +const DKTools_TouchInput_onRightButtonDown = TouchInput._onRightButtonDown; +TouchInput._onRightButtonDown = function(event) { + const x = Graphics.pageToCanvasX(event.pageX); + const y = Graphics.pageToCanvasY(event.pageY); + + DKTools_TouchInput_onRightButtonDown.call(this, event); + + if (Graphics.isInsideCanvas(x, y)) { + this._events.rightButtonPressed = true; + } +}; + +const DKTools_TouchInput_onMouseMove = TouchInput._onMouseMove; +TouchInput._onMouseMove = function(event) { + const x = Graphics.pageToCanvasX(event.pageX); + const y = Graphics.pageToCanvasY(event.pageY); + + DKTools_TouchInput_onMouseMove.call(this, event); + + if (this._mouseX !== x || this._mouseY !== y) { + this._events.mouseMoved = true; + this._mouseX = x; + this._mouseY = y; + } +}; + +const DKTools_TouchInput_onMouseUp = TouchInput._onMouseUp; +TouchInput._onMouseUp = function(event) { + const x = Graphics.pageToCanvasX(event.pageX); + const y = Graphics.pageToCanvasY(event.pageY); + + DKTools_TouchInput_onMouseUp.call(this, event); + + this._events.leftButtonPressed = false; + this._events.middleButtonPressed = false; + this._events.rightButtonPressed = false; + + if (Graphics.isInsideCanvas(x, y)) { + if (event.button === 0) { // left button + this._events.leftButtonReleased = true; + } else if (event.button === 1) { // middle button + this._events.middleButtonReleased = true; + } else if (event.button === 2) { // right button + this._events.rightButtonReleased = true; + } + } +}; + +// properties + +Object.defineProperties(TouchInput, { + + /** + * The X coordinate of the mouse + * + * @readonly + * @type {Number} + * @memberof TouchInput + */ + mouseX: { + get: function() { + return this._mouseX; + }, + configurable: true + }, + + /** + * The Y coordinate of the mouse + * + * @readonly + * @type {Number} + * @memberof TouchInput + */ + mouseY: { + get: function() { + return this._mouseY; + }, + configurable: true + } + +}); + + + + + +//=========================================================================== +// SceneManager +//=========================================================================== + +const DKTools_SceneManager_initGraphics = SceneManager.initGraphics; +SceneManager.initGraphics = function() { + const param = DKToolsParam.get('Screen Resolution'); + const width = param['Screen Width']; + const height = param['Screen Height']; + + if (param['Enabled']) { + this._boxWidth = width; + this._screenWidth = width; + this._boxHeight = height; + this._screenHeight = height; + + DKTools_SceneManager_initGraphics.call(this); + + if (DKTools.Utils.isNwjs()) { + this.updateResolution(); + } + } else { + DKTools_SceneManager_initGraphics.call(this); + } +}; + +SceneManager.updateResolution = function() { + const resizeWidth = this._screenWidth - window.innerWidth; + const resizeHeight = this._screenHeight - window.innerHeight; + + if (!Imported.ScreenResolution && resizeWidth && resizeHeight) { + window.moveBy(-1 * resizeWidth / 2, -1 * resizeHeight / 2); + window.resizeBy(resizeWidth, resizeHeight); + } }; -/** - * Returns an index of the event in its container - * - * @since 2.0.0 - * - * @param {DKTools.Event | DKTools.Animation} event - Event - * - * @see DKTools.EventManager.prototype.getEventIndex - * - * @returns {Number} Index of the event in its container - */ -DKTools.Scene.prototype.getEventIndex = function(event) { - return this._eventManager.getEventIndex(event); +SceneManager._logError = function(e) { + if (!e || !DKTools.IO.isLocalMode()) { + return; + } + + const param = DKToolsParam.get('Errors Log'); + const enabled = param['Enabled']; + + if (enabled === 'None' || + enabled === 'Only Game' && Utils.isOptionValid('test') || + enabled === 'Only Test' && !Utils.isOptionValid('test')) { + return; + } + + const fs = DKTools.IO.fs; + const os = require('os'); + + if (!fs || !os) { + return; + } + + const fileSize = param['File Size'] * 1024 * 1024; + const filename = param['Filename']; + const file = new DKTools.IO.File(filename); + const stats = file.getStats({ sync: true }).data; + let fileDescription = fs.openSync(filename, 'a'); + + if (stats && stats.size > fileSize) { + fs.closeSync(fileDescription); + file.remove({ sync: true }); + fileDescription = fs.openSync(filename, 'a'); + } + + if (e instanceof Object) { + let data = `Date: ${new Date().toString()}` + os.EOL + + `Name: ${e.name}` + os.EOL + + `Message: ${e.message}` + os.EOL; + + if (e.filename != undefined) { + data += `Filename: ${e.filename}` + os.EOL; + } + + if (e.lineNumber !== undefined) { + data += `Line: ${e.lineNumber}` + os.EOL; + } + + if (e.columnNumber !== undefined) { + data += `Column: ${e.columnNumber}` + os.EOL; + } + + data += `Stack: ${e.stack}` + os.EOL + os.EOL; + + fs.writeSync(fileDescription, data); + } else { + const data = `Date: ${new Date().toString()}` + os.EOL + + `Error: ${e}` + os.EOL + os.EOL; + + fs.writeSync(fileDescription, data); + } + + fs.closeSync(fileDescription); }; -/** - * Returns an array with the all events or events of a certain type - * - * @since 2.0.0 - * - * @param {String} [type] - Type of the events - * - * @see DKTools.EventManager.prototype.getEvents - * - * @returns {Array} Array with the events - */ -DKTools.Scene.prototype.getEvents = function(type) { - return this._eventManager.getEvents(type); -}; +const DKTools_SceneManager_onKeyDown = SceneManager.onKeyDown; +SceneManager.onKeyDown = function(event) { + DKTools_SceneManager_onKeyDown.call(this, event); -/** - * Returns an array with the all animations or animations of a certain type - * - * @since 2.0.0 - * - * @param {String} [type] - Type of animation - * - * @see DKTools.EventManager.prototype.getAnimations - * - * @returns {Array} Array with the animations - */ -DKTools.Scene.prototype.getAnimations = function(type) { - return this._eventManager.getAnimations(type); -}; + if (event.ctrlKey || event.altKey) { + return; + } -/** - * Checks for existence of the event in the object - * Returns true if the event exists - * - * @since 2.0.0 - * - * @param {DKTools.Event | DKTools.Animation} event - Event - * - * @see DKTools.EventManager.prototype.hasEvent - * - * @returns {Boolean} Event exists - */ -DKTools.Scene.prototype.hasEvent = function(event) { - return this._eventManager.hasEvent(event); -}; + const quickLoadKeyCode = DKToolsParam.get('Quick Load', 'Key Code'); + const screenshotKeyCode = DKToolsParam.get('Screenshots', 'Key Code'); + const keyCode = event.keyCode; -/** - * Checks for existence of the events of a certain type - * Returns true if the events exists - * - * @since 2.0.0 - * - * @param {String} [type] - Type of the Events - * - * @see DKTools.EventManager.prototype.hasEvents - * - * @returns {Boolean} Events exists - */ -DKTools.Scene.prototype.hasEvents = function(type) { - return this._eventManager.hasEvents(type); -}; + if (keyCode === quickLoadKeyCode && + Utils.isOptionValid('test') && + DKToolsParam.get('Quick Load', 'Enabled')) { + const savefileId = DKToolsParam.get('Quick Load', 'Savefile ID'); + const scene = SceneManager._scene; -/** - * Checks for existence of the animation in the object - * Returns true if the animation exists - * - * @since 2.0.0 - * - * @param {DKTools.Animation} animation - Animation - * - * @see DKTools.EventManager.prototype.hasAnimation - * - * @returns {Boolean} Animation exists - */ -DKTools.Scene.prototype.hasAnimation = function(animation) { - return this._eventManager.hasAnimation(animation); -}; + if (savefileId > 0) { + if (DataManager.loadGame(savefileId)) { + SoundManager.playLoad(); -/** - * Checks for existence of the animations of a certain type - * Returns true if the animations exists - * - * @since 2.0.0 - * - * @param {String} [type] - Type of the animations - * - * @see DKTools.EventManager.prototype.hasAnimations - * - * @returns {Boolean} Animations exists - */ -DKTools.Scene.prototype.hasAnimations = function(type) { - return this._eventManager.hasAnimations(type); -}; + if (scene instanceof Scene_Base) { + scene.fadeOutAll(); + } -/** - * Adds the event - * - * @since 2.0.0 - * - * @param {DKTools.Event | Object} object - Event or object with parameters for the event - * - * @param {String} [object.type] - Type of the event - * @param {Number} [object.repeatTime] - Time of one repeat - * @param {Number} [object.repeats] - Amount of repeats - * @param {Number} [object.remainingPauseTime] - Remaining time of pause - * @param {Function} [object.onStart] - Handler of the event start - * @param {Function} [object.onUpdate] - Handler of the event update - * @param {Function} [object.onPause] - Handler of the event pause - * @param {Function} [object.onReset] - Handler of the event reset - * @param {Function} [object.onRepeat] - Handler of the event repeat - * @param {Function} [object.onSuccess] - Handler of the event success - * @param {Function} [object.onFail] - Handler of the event fail - * - * @see DKTools.Event - * @see DKTools.EventManager.prototype.addEvent - * - * @returns {DKTools.Event} Added event - */ -DKTools.Scene.prototype.addEvent = function(object) { - return this._eventManager.addEvent(object); + if ($gameSystem.versionId() !== $dataSystem.versionId) { + $gamePlayer.reserveTransfer($gameMap.mapId(), $gamePlayer.x, $gamePlayer.y); + $gamePlayer.requestMapReload(); + } + + SceneManager.goto(Scene_Map); + } + } else if (!(scene instanceof Scene_Load)) { + SceneManager.push(Scene_Load); + } + } else if (keyCode === screenshotKeyCode && DKToolsParam.get('Screenshots', 'Enabled')) { + DKTools.Utils.makeScreenshot(); + } }; -/** - * Adds the one time event - * - * @since 2.0.0 - * - * @param {DKTools.Event | Object} object - Event or object with parameters for the event - * - * @param {String} [object.type] - Type of the event - * @param {Number} [object.remainingPauseTime] - Remaining time of pause - * @param {Function} [object.onStart] - Handler of the event start - * @param {Function} [object.onUpdate] - Handler of the event update - * @param {Function} [object.onPause] - Handler of the event pause - * @param {Function} [object.onReset] - Handler of the event reset - * @param {Function} [object.onRepeat] - Handler of the event repeat - * @param {Function} [object.onSuccess] - Handler of the event success - * @param {Function} [object.onFail] - Handler of the event fail - * - * @see DKTools.Event - * @see DKTools.EventManager.prototype.addOneTimeEvent - * - * @returns {DKTools.Event} Added event - */ -DKTools.Scene.prototype.addOneTimeEvent = function(object) { - return this._eventManager.addOneTimeEvent(object); +const DKTools_SceneManager_catchException = SceneManager.catchException; +SceneManager.catchException = function(e) { + DKTools_SceneManager_catchException.call(this, e); + this._logError(e); }; -/** - * Adds the animation - * - * @since 2.0.0 - * - * @param {DKTools.Animation} animation - Animation to add - * - * @see DKTools.EventManager.addAnimation - */ -DKTools.Scene.prototype.addAnimation = function(animation) { - this._eventManager.addAnimation(animation); +const DKTools_SceneManager_onError = SceneManager.onError; +SceneManager.onError = function(e) { + DKTools_SceneManager_onError.call(this, e); + this._logError(e); }; -// other methods -/** - * Calls the callback function for the child objects - * - * @param {Function} callback - Function for the child objects - */ -DKTools.Scene.prototype.iterateChildren = function(callback) { - _.forEach(this.children, callback); -}; -// update methods -/** - * Updates the scene - * - * @version 2.0.0 - * @override - * - * @see DKTools.Scene.prototype.updateChildren - * @see DKTools.Scene.prototype.updateFade - */ -DKTools.Scene.prototype.update = function() { - this.updateChildren(); - this.updateFade(); - this.updateEvents(); -}; -/** - * Updates the child object - * - * @param {*} child - Child object - */ -DKTools.Scene.prototype.updateChild = function(child) { - if (child && DKTools.Utils.isFunction(child.update)) { - child.update(); +//=========================================================================== +// Scene_Boot +//=========================================================================== + +const DKTools_Scene_Boot_start = Scene_Boot.prototype.start; +Scene_Boot.prototype.start = function() { + const quickStart = DKToolsParam.get('Quick Start'); + + if (quickStart['Enabled']) { + DKTools_Scene_Boot_start.call(this); + + if (!DataManager.isBattleTest() && !DataManager.isEventTest() && + (quickStart['Skip Saves']) || !DataManager.isAnySavefileExists()) { + Scene_Base.prototype.start.call(this); + SoundManager.preloadImportantSounds(); + this.checkPlayerLocation(); + DataManager.setupNewGame(); + this.updateDocumentTitle(); + SceneManager.goto(window[quickStart['Scene Name']]); + } + } else { + DKTools_Scene_Boot_start.call(this); } }; -/** - * Updates the child objects - * - * @override - * - * @see DKTools.Scene.prototype.iterateChildren - * @see DKTools.Scene.prototype.updateChild - */ -DKTools.Scene.prototype.updateChildren = function() { - this.iterateChildren(this.updateChild); -}; -/** - * Updates the events - * - * @since 2.0.0 - */ -DKTools.Scene.prototype.updateEvents = function() { - this._eventManager.update(); + + + +//=========================================================================== +// Game_Interpreter +//=========================================================================== + +const DKTools_Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand; +Game_Interpreter.prototype.pluginCommand = function(command, args) { + DKTools_Game_Interpreter_pluginCommand.call(this, command, args); + DKTools.PluginCommandManager.process(this, command, args); }; \ No newline at end of file diff --git a/README.md b/README.md index bc3be95..e3e8803 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ **Author**: DK -**Version**: Public 2.0.1 +**Version**: Public 3.0.0 **Description**: Library for RPG Maker MV. Contains many tools for developing. @@ -49,9 +49,7 @@ DKTools.Utils.Sequence DKTools.Utils.Sequence.Alphabet -DKTools.ParameterManager - -DKTools.PluginManager +DKTools.Utils.Event DKTools.IO @@ -63,7 +61,13 @@ DKTools.IO.Directory DKTools.IO.WebStorage -DKTools.Localization +DKTools.ParameterManager + +DKTools.PluginManager + +DKTools.PluginCommandManager + +DKTools.PreloadManager DKTools.Audio