├── README.md ├── D$E_RingMenuItem.js ├── D$E_CustomMotions.js ├── PixelPerfectCollition.js ├── D$E_BattleRotationPerspective.js ├── D$E_WorldMap.js ├── D$E_RingMenuParty.js ├── D$E_Core.js ├── LICENSE ├── MVUI.js ├── D$E_RingSceneMenu.js ├── D$E_RingMenu.js └── I18n.js /README.md: -------------------------------------------------------------------------------- 1 | # mv-plugins 2 | My collection of my plugins made for RPG Maker MV 3 | -------------------------------------------------------------------------------- /D$E_RingMenuItem.js: -------------------------------------------------------------------------------- 1 | //============================================================================== 2 | // Dragon Engine (D$E) Ring Scene Item 3 | // D$E_RingMenuItem.js 4 | // Version 1.0.0 5 | //============================================================================== 6 | /* 7 | * Copyright 2015 Ramiro Rojo 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | /*: 20 | * @plugindesc Implements a generic item interface for selecting items as a 21 | * ring menu. 22 | * 23 | */ 24 | if (!window.D$E) { 25 | throw new Error("This plugin requires the 'Dragon Engine (D$E)' to work properly! Ensure your plugin list, or order of plugins."); 26 | } 27 | 28 | D$E.ensureParameters('D$E_RingMenuItem'); 29 | 30 | 31 | (function ($) { 32 | "use strict"; 33 | if (!$.ui || !$.ui.RingMenu) { 34 | throw "The Scene Menu with a ring menu requires the Ring menu (D$E_RingMenuItem) to work!"; 35 | } 36 | var params = RingMenu.readParams('D$E_RingMenuItem'); 37 | 38 | 39 | 40 | 41 | 42 | })(D$E); 43 | -------------------------------------------------------------------------------- /D$E_CustomMotions.js: -------------------------------------------------------------------------------- 1 | //============================================================================== 2 | // Dragon Engine (D$E) Custom motions 3 | // D$E_CustomMotions.js 4 | // Version 0.1.0 5 | //============================================================================== 6 | /* 7 | * Copyright 2015 Ramiro Rojo 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | /*: 20 | * @plugindesc Allows to set up custom motions (poses of sideview characters) 21 | * for skills or items. 22 | * 23 | * @help 24 | * 25 | * To change the motion of a skill or item add this tag: 26 | * 27 | * 28 | * Where motion name should be any of the following by default: 29 | * 30 | * - walk 31 | * - wait 32 | * - chant 33 | * - guard 34 | * - damage 35 | * - evade 36 | * - thrust 37 | * - swing 38 | * - missile 39 | * - skill 40 | * - spell 41 | * - item 42 | * - escape 43 | * - victory 44 | * - dying 45 | * - abnormal 46 | * - sleep 47 | * - dead 48 | * 49 | */ 50 | 51 | if (!window.D$E) { 52 | throw new Error("This plugin requires the 'Dragon Engine (D$E)' to work properly! Ensure your plugin list, or order of plugins."); 53 | } 54 | 55 | PluginManager.register("D$E_CustomMotions", "1.0.0", { 56 | "email": "ramiro.rojo.cretta@gmail.com", 57 | "website": "http://binarychest.wordpress.com", 58 | "name": "Ramiro Rojo" 59 | }, "2015-10-26"); 60 | -------------------------------------------------------------------------------- /PixelPerfectCollition.js: -------------------------------------------------------------------------------- 1 | //============================================================================= 2 | // Pixel Perfect Colition 3 | // PixelPerfectColition.js 4 | // Version: 1.0.1 5 | //============================================================================= 6 | /* 7 | * Copyright 2015 Ramiro Rojo 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | /*: 20 | * @plugindesc Allows to check if two sprites are colliding. 21 | * This is a tool for scripters. 22 | * 23 | * @author Ramiro Rojo 24 | * 25 | * @help 26 | * 27 | * This plugin doesn't have any parameters. 28 | * 29 | * Note: At the current version sprites do take account of anchor, 30 | * but they don't account rotation or scale into consideration. 31 | * This will made them quite fast at the cost of not using anything fancy. 32 | * 33 | * Ths plugins provides two simple, yet powerful functions: 34 | * 35 | * Sprite.prototype.collitionDataWith(rect); 36 | * - Gives a collition rect between two sprites. 37 | * - Parameters: 38 | * - sprite: The sprite to check the rect. 39 | * 40 | * - Returns: The collition data between both sprites or null if 41 | * no collition was made. 42 | * The data contains a rect and the initial points of both sprites. 43 | * 44 | * Sprite.prototype.collidesWith(sprite[, alpha]) 45 | * - Checks if two sprites are colliding by pixels. 46 | * - Parameters: 47 | * - sprite: The sprite to check collition. 48 | * - alpha: The tolerance to check collition, (by default 1) 49 | * if you are using alpha blending on your sprites considerer 50 | * giving it a larger value. 51 | * 52 | * - Returns: true if the sprites are colliding, false otherwise. 53 | */ 54 | //============================================================================= 55 | var Imported = Imported || {}; 56 | Imported['PixelPerfectColition'] = '1.0.1'; 57 | 58 | Sprite.prototype.collitionDataWith = function (sprite) { 59 | // get the rect of collition 60 | var w1 = this.scale.x * this.width, 61 | w2 = sprite.scale.x * sprite.width, 62 | h1 = this.height, 63 | h2 = sprite.height, 64 | x1 = this.x - w1 * this.anchor.x, 65 | x2 = sprite.x - w2 * sprite.anchor.x, 66 | y1 = this.y - this.anchor.y * h1, 67 | y2 = sprite.y - sprite.anchor.y * h2, 68 | x = Math.max(x1, x2), 69 | y = Math.max(y1, y2), 70 | n1 = Math.min(x1 + w1, x2 + w2), 71 | n2 = Math.min(y1 + h1, y2 + h2); 72 | if (n1 >= x && n2 >= y) { 73 | return { 74 | rect: new Rectangle(x, y, n1 - x, n2 - y), 75 | p1 : new Point(x1, y1), 76 | p2 : new Point(x2, y2) 77 | }; 78 | } 79 | return null; 80 | } 81 | 82 | Sprite.prototype.collidesWith = function (sprite /*, alpha */) { 83 | var data = this.collitionDataWith(sprite); 84 | if (!data) { 85 | return false; 86 | } 87 | var rect = data.rect; 88 | var alpha = arguments.length > 1 ? arguments[1] : 1; 89 | var p1, p2, a1, b1, a2, b2; 90 | var ex = rect.width + rect.x; 91 | var ey = rect.height + rect.y; 92 | for (var i = rect.x; i < ex; ++i) { 93 | a1 = i - data.p1.x + this._frame.x; 94 | a2 = i - data.p2.x + sprite._frame.x; 95 | for (var j = rect.y; j < ey; ++j) { 96 | b1 = j - data.p1.y + this._frame.y; 97 | p1 = this.bitmap.getAlphaPixel(a1, b1); 98 | b2 = j - data.p2.y + sprite._frame.y; 99 | p2 = sprite.bitmap.getAlphaPixel(a2, b2); 100 | if (Number(p1) > 0 && Number(p2) > 0) { 101 | return true; 102 | } 103 | } 104 | } 105 | return false; 106 | } 107 | 108 | /* 109 | 110 | function Scene_PPP() { 111 | Scene_Base.apply(this, arguments); 112 | } 113 | 114 | Scene_PPP.prototype = Object.create(Scene_Base.prototype); 115 | Scene_PPP.prototype.constructor = Scene_PPP; 116 | 117 | Scene_PPP.prototype.create = function () { 118 | this.s1 = new Sprite(ImageManager.loadPicture('s1')); 119 | this.s2 = new Sprite(ImageManager.loadPicture('s1')); 120 | this.s2.x = Graphics.width / 2; 121 | this.s2.y = Graphics.height / 2; 122 | this.s1.anchor.x = this.s2.anchor.x = 0.5; 123 | this.s1.anchor.y = this.s2.anchor.y =0.5; 124 | this.txt = new Sprite(new Bitmap(Graphics.width, 32)); 125 | this.addChild(this.s1); 126 | this.addChild(this.s2); 127 | this.addChild(this.txt); 128 | } 129 | 130 | Scene_PPP.prototype.update = function () { 131 | Scene_Base.prototype.update.apply(this, arguments); 132 | if (TouchInput.isTriggered()) { 133 | this.s1.x = TouchInput.x; 134 | this.s1.y = TouchInput.y; 135 | this.txt.bitmap.clear(); 136 | var t = this.s1.collidesWith(this.s2) ? 'YES!' : 'NO!'; 137 | this.txt.bitmap.drawText('Collide: ' + t, 0, 0, Graphics.width, 32); 138 | } 139 | } 140 | 141 | */ 142 | -------------------------------------------------------------------------------- /D$E_BattleRotationPerspective.js: -------------------------------------------------------------------------------- 1 | //============================================================================== 2 | // Dragon Engine (D$E) BattleRotationPerspective 3 | // D$E_BattleRotationPerspective.js 4 | // Version 0.1.0 5 | //============================================================================== 6 | /* 7 | * Copyright 2015 Ramiro Rojo 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | /*: 20 | *@plugindesc Allows the user to manipulate angle and inclination in battlers, 21 | *to imitate the animations used in golden sun. 22 | * 23 | * @param Starting actor angle 24 | * @desc The starting angle for actors, in degrees (0-360). 25 | * Default: 275 26 | * @default 275 27 | * 28 | * @param Ending actor angle 29 | * @desc At how many degrees actors should stop (0-360). 30 | * Default: 350 31 | * @default 350 32 | * 33 | * @param Starting enemy angle 34 | * @desc The starting angle for enemies, in degrees (0-360). 35 | * Default: 90 36 | * @default 90 37 | * 38 | * @param Ending enemy angle 39 | * @desc How many degrees an enemy adds with it's index (0-360) 40 | * Default: 10 41 | * @default 10 42 | * 43 | * @param Horizontal centre 44 | * @desc The centre of the middle point of the circular position. 45 | * Default: Graphics.boxWidth / 2 46 | * @default Graphics.boxWidth / 2 47 | * 48 | * @param Vertical centre 49 | * @desc The vertical centre used by the circular position. 50 | * Default: Graphics.boxHeight / 2 - Graphics.boxHeight / 8 51 | * @default Graphics.boxHeight / 2 - Graphics.boxHeight / 8 52 | * 53 | * @param Vertical radius 54 | * @desc The vertical radius used by the circular position. 55 | * Default: Graphics.boxHeight / 8 56 | * @default Graphics.boxHeight / 8 57 | * 58 | * @param Horizontal radius 59 | * @desc The horizontal radius used by the circular position. 60 | * Default: Graphics.boxWidth * 3 / 2 61 | * @default Graphics.boxWidth * 3 / 2 62 | * 63 | * @param Allow Plugin command 64 | * @desc Allow Plugin commands calls from this plugin. 65 | * Default: yes 66 | * Default: yes 67 | * @default yes 68 | * 69 | * @param Plugin command name 70 | * @desc the Plugin Parameter name you want to use for this plugin. 71 | * Default: BRP 72 | * @default BRP 73 | * 74 | *@help 75 | * 76 | * Add this plugin named as 'BattleRotationPerspective' in your plugins folder. 77 | * 78 | * Remember to activate sideview battles in your system! 79 | * 80 | * Also, D$E_BattleRotationPerspective must be the name of this plugin! 81 | * 82 | */ 83 | var Imported = Imported || {}; 84 | 85 | if (!window.D$E) { 86 | throw new Error("The plugin 'D$E_BattleRotationPerspective' requires the 'Dragon Engine (D$E)' to work properly! Ensure your plugin list, or order of plugins."); 87 | } 88 | 89 | if (PluginManager.register) { 90 | PluginManager.register("D$E_BattleRotationPerspective", "1.0.0", { 91 | "email": "ramiro.rojo.cretta@gmail.com", 92 | "website": "http://binarychest.wordpress.com", 93 | "name": "Ramiro Rojo" 94 | }, "2015-10-26"); 95 | } else { 96 | Imported["D$E_BattleRotationPerspective"] = "1.0.0"; 97 | } 98 | 99 | D$E.ensureParameters('D$E_BattleRotationPerspective'); 100 | 101 | (function ($) { 102 | "use strict"; 103 | var editorParams = $.parametersFromSchema(PluginManager.parameters("D$E_BattleRotationPerspective"), { 104 | "Starting actor angle": { type:'number', after: $.degToRad }, 105 | "Ending actor angle" : { type:'number', after: $.degToRad }, 106 | "Starting enemy angle": { type:'number', after: $.degToRad }, 107 | "Ending enemy angle" : { type:'number', after: $.degToRad }, 108 | "Horizontal centre" : 'function', 109 | "Vertical centre" : 'function', 110 | "Horizontal radius" : 'function', 111 | "Vertical radius" : 'function', 112 | "Allow Plugin command": 'bool', 113 | "Plugin command name" : 'string' 114 | }); 115 | 116 | var params = { 117 | // angles are converted to radians for quicker process. 118 | startingActorAngle: editorParams["Starting actor angle"], 119 | endingActorAngle: editorParams["Ending actor angle"], 120 | startingEnemyAngle: editorParams["Starting enemy angle"], 121 | endingEnemyAngle: editorParams["Ending enemy angle"], 122 | // centre and starting radius are stored as points. 123 | centre: new Point( 124 | /* x: */ editorParams["Horizontal centre"], 125 | /* y: */ editorParams["Vertical centre"] 126 | ), 127 | startingRadius: new Point( 128 | /* x: */ editorParams["Horizontal radius"], 129 | /* y: */ editorParams["Vertical radius"] 130 | ), 131 | allowPluginCommand: editorParams["Allow Plugin command"], 132 | pluginCommand: editorParams["Plugin command name"], 133 | }; 134 | 135 | function _handleCommand(/* ... */) { 136 | 137 | } 138 | 139 | $.BattleRotationPerspective = {}; 140 | $.BattleRotationPerspective._handleCommand = _handleCommand; 141 | 142 | $.PARAMETERS['BattleRotationPerspective'] = params; 143 | 144 | if (params.allowPluginCommand) { 145 | $.addCommandHandle(params.pluginCommand, $.BattleRotationPerspective); 146 | } 147 | 148 | })(D$E); 149 | -------------------------------------------------------------------------------- /D$E_WorldMap.js: -------------------------------------------------------------------------------- 1 | //============================================================================== 2 | // Dragon Engine (D$E) World Map 3 | // D$E_WorldMap.js 4 | // Version 1.0.0 5 | //============================================================================== 6 | /* 7 | * Copyright 2015 Ramiro Rojo 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | /*: 20 | * @plugindesc Allows the user to mark maps as "world maps" 21 | * A world map map has special properties. 22 | * 23 | * @param On menu common event id 24 | * @desc A common event is called when the player presses for the menu. 25 | * -1 for disables this and allows common functionality. Default: 0 26 | * @default 0 27 | * 28 | * @param On node step common event id 29 | * @desc A common event is called before the player steps on a node. 30 | * 0 for disables this. Default: 0 31 | * @default 0 32 | * 33 | * @param On path step common event id 34 | * @desc A common event to be called when the user travels between two nodes 35 | * 0 for disables this. Default: 0 36 | * @default 0 37 | * 38 | * @help 39 | * 40 | * ============================================================================ 41 | * * Making your map as a World Map 42 | * ============================================================================ 43 | * Add the tag as to any of your map you want to become one. 44 | * The map you select now will behave specially. Your map will be transformed 45 | * into 'nodes' and 'paths'. 46 | * A node, represents a place where you can open any kind of choice, being a 47 | * shop entering a map, or something like that. 48 | * 49 | * A path represents a place where the player may go trough, you must connect 50 | * your nodes trough paths using the region id. 51 | * 52 | * The map automatically changes some controls to call a common event when you 53 | * press the menu button, for example. 54 | * 55 | * ============================================================================ 56 | * * Adding paths 57 | * ============================================================================ 58 | * 59 | * In order to add a path, you must make a path marked with a region, 60 | * connecting two nodes. 61 | * 62 | * ============================================================================ 63 | * * Adding nodes. 64 | * ============================================================================ 65 | * 66 | * A node is just a way to call a fancy event a name. 67 | * Remember to add as the event's note the value . 68 | * 69 | * ============================================================================ 70 | * * Specific common events for specific maps 71 | * ============================================================================ 72 | * Af you plan on using many world maps and on each you may need a different 73 | * set of events, you can override the "default behaviour" by adding any of 74 | * this notetags: 75 | * 76 | * Replace id with the id of the common event you want to call. 77 | * 78 | * 79 | * 80 | * 81 | * 82 | * Each one will take precedence over the global settings, so if you disable it 83 | * using 0, for example, it will open the normal menu. 84 | * 85 | * So a chain of checking works like this: 86 | * check if the map has custom command, check if global settings are active, 87 | * default system function (nothing or opening the menu). 88 | * 89 | */ 90 | if (!window.D$E) { 91 | throw new Error("The plugin 'D$E_WorldMap' requires the 'Dragon Engine (D$E)' to work properly! Ensure your plugin list, or order of plugins."); 92 | } 93 | 94 | D$E.ensureParameters('D$E_WorldMap'); 95 | 96 | (function ($) { 97 | 98 | var editorParams = $.parametersFromSchema(PluginManager.parameters('D$E_WorldMap'), { 99 | 'On menu common event id': 'number', 100 | 'On node step common event id': 'number', 101 | 'On path step common event id': 'number' 102 | }); 103 | 104 | var params = { 105 | menuEventId: editorParams['On menu common event id'], 106 | nodeEventId: editorParams['On node step common event id'], 107 | pathEventId: editorParams['On path step common event id'] 108 | }; 109 | 110 | $.WorldMap = { 111 | _mapData: {} 112 | }; 113 | 114 | $.WorldMap.isWorldMap = function (mapId) { 115 | if (!$dataMap) return false; 116 | return !!MVC.getTag($dataMap.note || '', 'DE_WorldMap'); 117 | } 118 | 119 | $.WorldMap.data = function () { 120 | return $gameSystem.d$EWorldMapData(); 121 | } 122 | 123 | $.WorldMap.mapData = function () { 124 | if (!$dataMap) return null; 125 | var id = $gameMap.mapId(); 126 | if (!this._mapData[id]) { 127 | this._mapData[id] = this._generateData(id); 128 | } 129 | return this._mapData[id]; 130 | } 131 | 132 | $.WorldMap._generateData = function (id) { 133 | var result = {}; 134 | result.pathEventId = this._getValue('pathEventId'); 135 | result.nodeEventID = this._getValue('nodeEventID'); 136 | result.pathEventID = this._getValue('pathEventID'); 137 | result.nodes = this._generateNodes(id); 138 | result.paths = this._generatePaths(id, result.nodes); 139 | result.unlockedPaths = this.data().unlockedPaths(id); 140 | return result; 141 | } 142 | 143 | $.WorldMap._getValue = function (name) { 144 | var value = MVC.getTag($dataMap.note || '', 'DE_' + name); 145 | if (value === null) { 146 | return params[name]; 147 | } 148 | return Number(value.params[0] || ''); 149 | } 150 | 151 | $.WorldMap._generateNodes = function (id) { 152 | var result = {}; 153 | return result; 154 | } 155 | 156 | $.WorldMap._generatePaths = function (id, nodes) { 157 | var result = {}; 158 | return result; 159 | } 160 | 161 | $.WorldMap.unlock = function (mapId, pathId) { 162 | 163 | } 164 | 165 | $.WorldMap.lock = function (mapId, pathId) { 166 | 167 | } 168 | 169 | $.WorldMap.Data = MVC.extend(); 170 | 171 | $.WorldMap.Data.prototype.initialize = function () { 172 | this._unlockedPaths = {}; 173 | } 174 | 175 | $.WorldMap.Data.prototype.unlockedPaths = function (mapId) { 176 | if (!this._unlockedPaths[mapId]) { 177 | this._unlockedPaths[mapId] = []; 178 | }; 179 | return this._unlockedPaths[mapId]; 180 | } 181 | 182 | Game_System.prototype.d$EWorldMapData = function () { 183 | if (!this._d$eWorldMapData) { 184 | this._d$eWorldMapData = $.WorldMap.Data(); 185 | } 186 | return this._d$eWorldMapData; 187 | } 188 | 189 | })(D$E); 190 | -------------------------------------------------------------------------------- /D$E_RingMenuParty.js: -------------------------------------------------------------------------------- 1 | //============================================================================== 2 | // Dragon Engine (D$E) Ring Menu Party 3 | // D$E_RingMenuParty.js 4 | // Version 1.4.1 5 | //============================================================================== 6 | /* 7 | * Copyright 2015 Ramiro Rojo 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | /*: 20 | *@plugindesc Used for any ring menu scene than requires an actor window. 21 | * 22 | * @param Icons 23 | * @desc The set of icon used by the ring menu. 24 | * The list is in the format name: icon1, name2: icon2, ... 25 | * @default item: 176, skill: 79, equip: 137, status: 82, formation: 75, options: 83, save: 84, gameEnd: 1, cancel: 74 26 | * 27 | * @param Centre X 28 | * @desc The x position to display the centre of the menu. 29 | * Default: $gamePlayer.screenX() 30 | * @default $gamePlayer.screenX() 31 | * 32 | * @param Centre Y 33 | * @desc The y position to display the centre of the menu. 34 | * Default: $gamePlayer.screenY() - ($gamePlayer.isInAirship() ? 48 : 16) 35 | * @default $gamePlayer.screenY() - ($gamePlayer.isInAirship() ? 48 : 16) 36 | * 37 | * @param Radius X 38 | * @desc The x radius of the menu. 39 | * Default: Graphics.boxWidth / 10 40 | * @default Graphics.boxWidth / 10 41 | * 42 | * @param Radius Y 43 | * @desc The y radius of the menu. 44 | * Default: 32 45 | * @default 32 46 | * * 47 | * @param Starting Angle 48 | * @desc The starting angle of the first element, in degrees 49 | * Default: -90 50 | * @default -90 51 | * 52 | * @param Rotation 53 | * @desc 1- to clockwise, 1 to counter clockwise 54 | * Default: -1 55 | * @default -1 56 | * 57 | * @param Scale Difference 58 | * @desc Reduction / Increment for y values when rotating for 3d effect. 59 | * Default: 0.2 60 | * @default 0.2 61 | * 62 | * @param Show Actor Sprite 63 | * @desc Handles if the actor should be shown at the middle of the menu. 64 | * Default: yes 65 | * @default yes 66 | * @help 67 | * ============================================================================= 68 | * * FAQ 69 | * ============================================================================= 70 | * - It is not working! 71 | * Press F8, check the console, it usually gives you a nice formatted error 72 | * made by me. 73 | * If it doesn't then report please! 74 | * --------------------------------------------------------------------------- 75 | * - Can I use images instead of the iconset? 76 | * Yes! you can, instead of putting a number, put it as a name like: 77 | * item: My Awesome Name. 78 | * Be aware than spaces before and after your name WILL be ignored 79 | * So 'My Awesome name' is the same as 'My Awesome name ' (notice the spaces 80 | * at the end) And remeber to not put the name with ''. 81 | * --------------------------------------------------------------------------- 82 | */ 83 | if (!window.D$E) { 84 | throw new Error("This plugin requires the 'Dragon Engine (D$E)' to work properly! Ensure your plugin list, or order of plugins."); 85 | } 86 | 87 | D$E.ensureParameters('D$E_RingMenuParty'); 88 | 89 | PluginManager.register("D$E_RingMenuParty", "1.0.0", { 90 | "email": "ramiro.rojo.cretta@gmail.com", 91 | "website": "http://binarychest.wordpress.com", 92 | "name": "Ramiro Rojo" 93 | }, "2015-11-04"); 94 | 95 | 96 | 97 | (function ($) { 98 | "use strict"; 99 | if (!$.ui || !$.ui.RingMenu) { 100 | throw "The Ring Menu Party with a ring menu requires the Ring menu (D$E_RingSceneMenu) to work!"; 101 | } 102 | var RingMenu = $.ui.RingMenu; 103 | var params = RingMenu.readParams('D$E_RingMenuParty'); 104 | 105 | // Party Window 106 | 107 | $.ui.RingMenu.Party = $.ui.RingMenu.Command.extend(); 108 | 109 | $.ui.RingMenu.Party.prototype.initialize = function(parent) { 110 | $.ui.RingMenu.Command.prototype.initialize.call(this, parent, params.make()); 111 | this.close(0); 112 | this._active = false; 113 | this._formationMode = false; 114 | this._pendingIndex = -1; 115 | this.selectLast(); 116 | } 117 | 118 | MVC.accessor(Window_MenuStatus.prototype, 'formationMode'); 119 | 120 | $.ui.RingMenu.Party.prototype.makeCommandList = function () { 121 | var self = this; 122 | $gameParty.members().forEach(function (member, i) { 123 | self.addCommand(member.name(), i, true); 124 | }); 125 | this.addCancelCommand(); 126 | } 127 | 128 | $.ui.RingMenu.prototype.pendingIndex = function () { 129 | return this._pendingIndex; 130 | } 131 | 132 | $.ui.RingMenu.prototype.setPendingIndex = function (index) { 133 | this._pendingIndex = index; 134 | } 135 | 136 | $.ui.RingMenu.Party.prototype._createButton = function (text, name, enabled, icon) { 137 | if (name == 'cancel') { 138 | return new $.ui.RingMenu.Button(this, name); 139 | } 140 | return new $.ui.RingMenu.Party.Button(this, name); 141 | } 142 | 143 | $.ui.RingMenu.Party.prototype.setFormationMode = function (formationMode) { 144 | this._formationMode = formationMode; 145 | } 146 | 147 | $.ui.RingMenu.Party.prototype.selectLast = function () { 148 | this.select($gameParty.menuActor().index() || 0); 149 | } 150 | 151 | $.ui.RingMenu.Party.prototype.processOk = function () { 152 | var member = $gameParty.members()[this.index()]; 153 | if (member) { 154 | $gameParty.setMenuActor(member); 155 | } 156 | $.ui.RingMenu.prototype.processOk.call(this); 157 | } 158 | 159 | // Button 160 | $.ui.RingMenu.Party.Button = $.ui.RingMenu.Button.extend(); 161 | 162 | $.ui.RingMenu.Party.Button.prototype._updateIconBitmap = function () { 163 | var pw, ph, sx, sy; 164 | var index = this._menu.indexOf(this._name); 165 | var icon = $gameParty.members()[ index ]; 166 | if (this._menu.pendingIndex() == index) { 167 | this.setColorTone([0, 0, 0, 255]); 168 | } else { 169 | this.setColorTone([0, 0, 0, 0]); 170 | } 171 | if (icon == this._lastIcon) { 172 | return; 173 | } 174 | this._lastIcon = icon; 175 | this.anchor.x = 0.5; 176 | this.anchor.y = 1; 177 | var bitmap = ImageManager.loadCharacter(icon.characterName()); 178 | var big = ImageManager.isBigCharacter(icon.characterName()); 179 | pw = bitmap.width / (big ? 3 : 12); 180 | ph = bitmap.height / (big ? 4 : 8); 181 | var n = icon.characterIndex(); 182 | sx = (n % 4 * 3 + 1) * pw; 183 | sy = (Math.floor(n / 4) * 4) * ph; 184 | this.bitmap = bitmap; 185 | this.setColdFrame(sx, sy, pw, ph * 3 / 4); 186 | }; 187 | 188 | $.PARAMETERS['RingMenuParty'] = params; 189 | 190 | })(D$E); 191 | -------------------------------------------------------------------------------- /D$E_Core.js: -------------------------------------------------------------------------------- 1 | //============================================================================== 2 | // Dragon Engine (D$E) Core 3 | // D$E_Core.js 4 | // Version 1.1.0 5 | //============================================================================== 6 | /* 7 | * Copyright 2015 Ramiro Rojo 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | /*: 20 | * @plugindesc The core script used by all of the Dragon Engine plugins. 21 | * 22 | * @param Allow Plugin Commands 23 | * Determines if this plugin and it's extensions will allow plugin commands. 24 | * Default: yes 25 | * @default yes 26 | * 27 | * @param Plugin Command name 28 | * The name used as plugin command. 29 | * Default: D$E 30 | * @default D$E 31 | * 32 | * @help 33 | * 34 | * 35 | */ 36 | var Imported = Imported || {}; 37 | 38 | if (PluginManager.register) { 39 | PluginManager.register("D$E_Core", "1.0.0", { 40 | "email": "ramiro.rojo.cretta@gmail.com", 41 | "website": "http://binarychest.wordpress.com", 42 | "name": "Ramiro Rojo" 43 | }, "2015-10-26"); 44 | } else { 45 | Imported["D$E_Core"] = "1.0.0"; 46 | } 47 | 48 | if (!window.MVC) { 49 | throw new Error("The plugin 'D$E_Core' require the 'MVCommons plugin' to work properly!"); 50 | } 51 | 52 | if (!Object.keys(PluginManager.parameters("D$E_Core")).length) { 53 | throw new Error("You seem to have put to 'D$E_Core' a different name in your plugin folder, this won't work!"); 54 | } 55 | 56 | var D$E = (function (oldD$E) { 57 | "use strict"; 58 | var editorParams = PluginManager.parameters("D$E_Core"); 59 | 60 | var $ = {}; 61 | var params = {}; 62 | var _pluginCommands = {}; 63 | 64 | /** 65 | * Restores the previous value stored in the D$E variable. 66 | * 67 | * @return The current value of the dragon engine. 68 | */ 69 | $.noConflict = function () { 70 | D$E = oldD$E; 71 | return $; 72 | }; 73 | 74 | if (MVC && MVC.naturalBoolean) { 75 | // I just take it from MVCommons then 76 | $.naturalBoolean = MVC.naturalBoolean; 77 | } else { 78 | /** 79 | * Allows to match your string as any of this to true: 80 | * - true 81 | * - yes 82 | * - active 83 | * - enabled 84 | * - on 85 | * - y 86 | * 87 | * @param text The text to check. 88 | * @return true if the text matches any of that text, or false. 89 | * @note Value is case insensitive. 90 | */ 91 | $.naturalBoolean = function (text) { 92 | if ( text.match(/(y(es)?)|true|on|active|enabled/gi) ) { 93 | return true; 94 | } 95 | return false; 96 | }; 97 | } 98 | 99 | $.number = function (value, max, min) { 100 | var n = Number(value || 0); 101 | if (max !== null && n > max) { 102 | return max; 103 | } 104 | if (min !== null && n < min) { 105 | return min; 106 | } 107 | return n; 108 | } 109 | 110 | $.trim = function (value) { 111 | return ('' + value).trim(); 112 | } 113 | 114 | $.asFunction = function (value) { 115 | return Function("return " + value + ';'); 116 | } 117 | 118 | $.parseList = function (list, schema, separator) { 119 | return list.split(separator).map(function (i) { 120 | return $.parseParamType(schema, i) 121 | }); 122 | } 123 | 124 | $.parseHash = function (list, schema, separator, keySeparator) { 125 | var result = {}; 126 | function each(i) { 127 | var list = i.split(keySeparator); 128 | result[list[0].trim()] = $.parseParamType(schema, list[1]); 129 | }; 130 | list.split(separator).forEach(each); 131 | return result; 132 | } 133 | 134 | $.parseAsStringOrNumber = function (value) { 135 | var t = $.trim(value); 136 | return isNaN(t) ? t : Number(value || 0); 137 | } 138 | 139 | $.parseParamType = function (schema, value) { 140 | var s, t, v, result, filter; 141 | filter = true; 142 | if (typeof schema == 'string') { 143 | t = schema; 144 | s = {}; 145 | } else { 146 | t = schema.type || null; 147 | s = schema; 148 | } 149 | v = s.before ? s.before(value) : value; 150 | switch ((t || 'string').toLowerCase()) { 151 | case 'bool': case 'boolean': 152 | result = $.naturalBoolean(v); 153 | break; 154 | case 'number': case 'nul': 155 | result = $.number(v, s.max || null, s.min || null); 156 | break; 157 | case 'list': case 'array': case 'arr': case 'ary': 158 | result = $.parseList(v, s.of || '', s.separator || s.sep || ','); 159 | break; 160 | case 'function': case 'method': case 'funct': case 'lambda': case 'fun': 161 | result = $.asFunction(v); 162 | break; 163 | case 'hash': case 'object': case 'obj': 164 | result = $.parseHash(v, s.of || '', s.separator || s.sep || ',', s.pairSeparator || ':' ); 165 | break; 166 | case 'json': 167 | result = JSON.parse(v); 168 | case 'str': case 'string': default: 169 | result = v.trim(); 170 | break; 171 | } 172 | if (s.after && filter) { 173 | return s.after(result); 174 | } 175 | return result; 176 | } 177 | 178 | $.parametersFromSchema = function (editorParameters, schema) { 179 | var result = {}; 180 | for (var p in schema) { 181 | result[p] = $.parseParamType(schema[p], editorParameters[p] || ''); 182 | } 183 | return result; 184 | } 185 | 186 | /** 187 | * Adds an object that can handle commands for the Dragon Engine. 188 | * It will be called inside D$E Plugin command to avoid name collitions. 189 | * When the command is requested, this plugin will call the method 190 | * _handleCommand of the handler object. 191 | * 192 | * @param name The name of the command. 193 | * @param handlerObject The object than handles the event. 194 | * 195 | */ 196 | $.addCommandHandle = function (name, handlerObject) { 197 | _pluginCommands[name] = handlerObject; 198 | }; 199 | 200 | if (MVC && MVC.safeEval) { 201 | // Taking it from MVC. 202 | $.safeEval = MVC.safeEval; 203 | } else { 204 | /** 205 | * Evaluates a context with some safety measure to stop it from breaking all. 206 | * 207 | * @param text The text to evaluate. 208 | * @return The result of the expression or null if something fails. 209 | * 210 | */ 211 | $.safeEval = function (text) { 212 | try { 213 | return eval(text); 214 | } catch(e) { 215 | console.error(e); // print the error as error anyway 216 | return null; 217 | } 218 | }; 219 | } 220 | 221 | 222 | if (MVC && MVC.degToRad) { 223 | // Taking it from MVC. 224 | $.degToRad = MVC.degToRad; 225 | } else { 226 | /** 227 | * Converts degrees into radians. 228 | * 229 | * @param deg Degrees to convert 230 | * @return Radiants equivalent to those degrees. 231 | * 232 | */ 233 | $.degToRad = function (deg) { 234 | return deg * Math.PI / 180; 235 | } 236 | } 237 | 238 | $.copyAttributes = function (src, dst) { 239 | for (var p in src) { 240 | if (src.hasOwnProperty(p)) { 241 | dst[p] = dst[p] || src[p]; 242 | } 243 | } 244 | } 245 | 246 | $.merge = function () { 247 | var result = {}; 248 | var length = arguments.length; 249 | for (var i = 0; i < length; ++i) { 250 | $.copyAttributes(arguments[i], result); 251 | } 252 | return result; 253 | } 254 | 255 | if (MVC && MVC.radToDeg) { 256 | $.radToDeg = MVC.radToDeg; 257 | } else { 258 | /** 259 | * Converts radians into degrees. 260 | * 261 | * @param rad Radians to convert 262 | * @return Degrees equivalent to those radians. 263 | * 264 | */ 265 | $.radToDeg = function (rad) { 266 | return rad * 180 / Math.PI; 267 | } 268 | } 269 | 270 | $.ensureParameters = function (name) { 271 | if (!Object.keys(PluginManager.parameters(name)).length) { 272 | throw new Error("You seem to have put to the plugin '" + name + "' a different name in your plugin folder, this won't work!"); 273 | } 274 | }; 275 | 276 | function fireEventCommand(name, args) { 277 | if (_pluginCommands[name]) { 278 | _pluginCommands['name']._handleCommand.apply(this, args); 279 | return; 280 | } 281 | throw new Error("The Dragon Engine doesn't recognize the plugin command '" + name + "'!"); 282 | } 283 | 284 | $.PARAMETERS = {}; 285 | 286 | $.PARAMETERS['Core'] = params; 287 | 288 | params.allowPluginCommands = $.naturalBoolean(editorParams["Allow Plugin Commands"] || 'no'); 289 | params.pluginCommandName = editorParams['Plugin Command name'] || 'D$E'; 290 | 291 | if (!params.allowPluginCommands) { 292 | $.addCommandHandle = function () {}; 293 | } 294 | 295 | // Adding plugin command handling 296 | var Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand; 297 | 298 | Game_Interpreter.prototype.pluginCommand = function(command, args) { 299 | Game_Interpreter_pluginCommand.call(this, command, args); 300 | if (command === params.pluginCommandName) { 301 | var subArgs = Array.prototype.slice.call(args, 1); 302 | fireEventCommand.call(this, args[0], subArgs); 303 | } 304 | }; 305 | 306 | $.mouse = new Point(0, 0); 307 | 308 | (function () { // must protect from pollution 309 | 310 | function _onMouseMove(event) { 311 | $.mouse.x = Graphics.pageToCanvasX(event.pageX); 312 | $.mouse.y = Graphics.pageToCanvasY(event.pageY); 313 | }; 314 | 315 | 316 | function _onTouchMove(event) { 317 | for (var i = 0; i < event.changedTouches.length; i++) { 318 | var touch = event.changedTouches[i]; 319 | $.mouse.x = Graphics.pageToCanvasX(touch.pageX); 320 | $.mouse.y = Graphics.pageToCanvasY(touch.pageY); 321 | } 322 | }; 323 | 324 | document.addEventListener('mousemove', _onMouseMove); 325 | document.addEventListener('touchmove', _onTouchMove); 326 | 327 | })(); 328 | 329 | 330 | return $; 331 | 332 | })(D$E || null); 333 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /MVUI.js: -------------------------------------------------------------------------------- 1 | var Imported = Imported || {}; 2 | Imported['MVUI'] = '1.0.0'; 3 | 4 | var ui = {}; 5 | (function (ui) { 6 | "use strict"; 7 | //============================================================================= 8 | // 9 | //----------------------------------------------------------------------------- 10 | // 11 | //============================================================================= 12 | function extend(parentClass) { 13 | var parent = parentClass || Object; 14 | var constructor = function () { this.initialize.apply(this, arguments); }; 15 | constructor.prototype = Object.create(parent.prototype); 16 | constructor.prototype.constructor = constructor; 17 | constructor.extend = function () { return extend(constructor); } 18 | constructor.include = function (mixin) { include(constructor, mixin) }; 19 | constructor.describe = function (desc) { describe(constructor, desc) }; 20 | return constructor; 21 | } 22 | ui.extend = extend; 23 | 24 | //============================================================================= 25 | // 26 | //----------------------------------------------------------------------------- 27 | // 28 | //============================================================================= 29 | function mixin(descriptor) { 30 | var c = function () { throw 'Cannot initialize a mixin.'; }; 31 | c.include = function (mixin) { include(c, mixin) }; 32 | c.describe = function (desc) { describe(c, desc) }; 33 | if (typeof descriptor !== 'undefined') { 34 | c.describe(descriptor); 35 | } 36 | return c; 37 | } 38 | ui.mixin = mixin; 39 | 40 | //============================================================================= 41 | // 42 | //----------------------------------------------------------------------------- 43 | // 44 | //============================================================================= 45 | function include(classType, mixin) { 46 | for (var p in mixin.prototype) { 47 | if (p !== 'constructor') { 48 | classType.prototype[p] = classType.prototype[p] || mixin.prototype[p]; 49 | } 50 | } 51 | } 52 | ui.include = include; 53 | 54 | //============================================================================= 55 | // 56 | //----------------------------------------------------------------------------- 57 | // 58 | //============================================================================= 59 | function describe(classValue, descriptor) { 60 | for (var p in descriptor) { 61 | var item = descriptor[p]; 62 | switch (typeof item) { 63 | case 'function': 64 | classValue.prototype[p] = item; 65 | break; 66 | default: 67 | Object.defineProperty(classValue.prototype, p, item); 68 | break; 69 | } 70 | } 71 | } 72 | ui.describe = describe; 73 | //============================================================================= 74 | // 75 | //----------------------------------------------------------------------------- 76 | // 77 | //============================================================================= 78 | function defaultGet(name) { 79 | return function () { return this['_' + name]; }; 80 | } 81 | //============================================================================= 82 | // 83 | //----------------------------------------------------------------------------- 84 | // 85 | //============================================================================= 86 | function defaultSet(name) { 87 | return function (value) { 88 | if (this.fire) { 89 | var event = new Event('propertychange'); 90 | event.older = this['_' + name] || undefined; 91 | event.newer = value; 92 | if (this.fire('propertychange', event)) { 93 | this['_' + name] = value; 94 | } 95 | }; 96 | }; 97 | } 98 | 99 | //============================================================================= 100 | // 101 | //----------------------------------------------------------------------------- 102 | // 103 | //============================================================================= 104 | function getter(name) { 105 | return { get: defaultGet(name), configurable: true }; 106 | } 107 | ui.getter = getter; 108 | 109 | //============================================================================= 110 | // 111 | //----------------------------------------------------------------------------- 112 | // 113 | //============================================================================= 114 | function writer(name) { 115 | return { set: defaultSet(name), configurable: true }; 116 | } 117 | ui.writer = writer; 118 | 119 | //============================================================================= 120 | // 121 | //----------------------------------------------------------------------------- 122 | // 123 | //============================================================================= 124 | function accessor(name) { 125 | return { get: defaultGet(name), set: defaultSet(name), configurable: true }; 126 | } 127 | ui.accessor = accessor; 128 | 129 | //============================================================================= 130 | // 131 | //============================================================================= 132 | var currentManager = null; 133 | 134 | //============================================================================= 135 | // 136 | //----------------------------------------------------------------------------- 137 | // 138 | //============================================================================= 139 | ui.EventHandler = mixin({ 140 | //=========================================================================== 141 | // 142 | //=========================================================================== 143 | setupEvents: function () { 144 | this.__events = {}; 145 | }, 146 | //=========================================================================== 147 | // 148 | //=========================================================================== 149 | on: function (name, callback) { 150 | this.__events[name] = this.__events[name] || []; 151 | }, 152 | //=========================================================================== 153 | // 154 | //=========================================================================== 155 | off: function (name, callback) { 156 | if (typeof callback == 'undefined') { 157 | this.__events[name] = []; 158 | return; 159 | } 160 | this.__events[name] = this.__events[name] || []; 161 | }, 162 | //=========================================================================== 163 | // 164 | //=========================================================================== 165 | fire: function (name, event) { 166 | this.__events[name] = this.__events[name] || []; 167 | this.__events.forEach(function (callback) { callback(event); }); 168 | return !event.defaultPrevented; 169 | } 170 | }); 171 | 172 | 173 | 174 | //============================================================================= 175 | // 176 | //----------------------------------------------------------------------------- 177 | // 178 | //============================================================================= 179 | ui.MixinContainer = mixin({ 180 | //=========================================================================== 181 | // 182 | //=========================================================================== 183 | setupChildren: function () { 184 | this.__children = []; 185 | }, 186 | //=========================================================================== 187 | // 188 | //=========================================================================== 189 | addChild: function (child) { 190 | var event = new Event('onchildadd'); 191 | event.child = child; 192 | if (this.fire && this.fire('onchildadd', event)) { 193 | var i = this.children().indexOf(child); 194 | if (i === -1) { 195 | this.children().push(child); 196 | } 197 | }; 198 | }, 199 | //=========================================================================== 200 | // 201 | //=========================================================================== 202 | removeChild : function (child) { 203 | var event = new Event('onchildremove'); 204 | event.child = child; 205 | if (this.fire && this.fire('onchildremove', event)) { 206 | var i = this.children().indexOf(child); 207 | if (i !== -1) { 208 | this.children().splice(i, 1); 209 | } 210 | }; 211 | }, 212 | //=========================================================================== 213 | // 214 | //=========================================================================== 215 | children: function () { 216 | return this.__children; 217 | } 218 | }); 219 | 220 | //============================================================================= 221 | // 222 | //----------------------------------------------------------------------------- 223 | // 224 | //============================================================================= 225 | ui.Manager = extend(WindowLayer); 226 | //=========================================================================== 227 | // 228 | //=========================================================================== 229 | ui.Manager.include(ui.EventHandler); 230 | //=========================================================================== 231 | // 232 | //=========================================================================== 233 | describe(ui.Manager, { 234 | //========================================================================= 235 | // 236 | //========================================================================= 237 | initialize: function () { 238 | WindowLayer.prototype.initialize.apply(this, arguments); 239 | this.setStartPosition(); 240 | this.setupEvents(); 241 | this.attach(); 242 | }, 243 | //========================================================================= 244 | // 245 | //========================================================================= 246 | setStartPosition: function () { 247 | var width = Graphics.boxWidth; 248 | var height = Graphics.boxHeight; 249 | var x = (Graphics.width - width) / 2; 250 | var y = (Graphics.height - height) / 2; 251 | this.move(x, y, width, height); 252 | }, 253 | //========================================================================= 254 | // 255 | //========================================================================= 256 | attach: function () { 257 | currentManager = this; 258 | }, 259 | //========================================================================= 260 | // 261 | //========================================================================= 262 | detach: function () { 263 | if (currentManager == this) { 264 | currentManager = null; 265 | } 266 | }, 267 | //========================================================================= 268 | // 269 | //========================================================================= 270 | addChild: function (child) { 271 | if (this.parent) { 272 | this.parent.addChild(child); 273 | } 274 | }, 275 | //========================================================================= 276 | // 277 | //========================================================================= 278 | removeChild : function (child) { 279 | if (this.parent) { 280 | this.parent.removeChild(child); 281 | } 282 | }, 283 | //========================================================================= 284 | // 285 | //========================================================================= 286 | children: function () { 287 | if (this.parent) { 288 | return this.parent.children; 289 | } 290 | } 291 | }); 292 | 293 | //============================================================================= 294 | // 295 | //----------------------------------------------------------------------------- 296 | // 297 | //============================================================================= 298 | ui.Widget = extend(); 299 | //=========================================================================== 300 | // 301 | //=========================================================================== 302 | ui.Widget.include(ui.EventHandler); 303 | //=========================================================================== 304 | // 305 | //=========================================================================== 306 | ui.Widget.describe({ 307 | initialize: function (parent) { 308 | this.setupEvents(); 309 | } 310 | }); 311 | 312 | //============================================================================= 313 | // 314 | //----------------------------------------------------------------------------- 315 | // 316 | //============================================================================= 317 | ui.Container = ui.Widget.extend(); 318 | //=========================================================================== 319 | // 320 | //=========================================================================== 321 | ui.Container.include(ui.MixinContainer); 322 | //=========================================================================== 323 | // 324 | //=========================================================================== 325 | ui.Container.describe({ 326 | initialize: function (parent) { 327 | ui.Widget.prototype.initialize.apply(this, arguments); 328 | this.setupChildren(); 329 | } 330 | }); 331 | 332 | //============================================================================= 333 | // 334 | //----------------------------------------------------------------------------- 335 | // 336 | //============================================================================= 337 | ui.DisplayWidget = ui.Container.extend(); 338 | 339 | //============================================================================= 340 | // Added: Scene_Base.prototype.createUiManager 341 | //----------------------------------------------------------------------------- 342 | // 343 | //============================================================================= 344 | Scene_Base.prototype.createUiManager = function() { 345 | }; 346 | 347 | var hiddenDiv = document.createElement('div'); 348 | hiddenDiv.style.width = hiddenDiv.style.height = 0; 349 | hiddenDiv.style.overflow = 'hidden'; 350 | hiddenDiv.style.opacity = 0; 351 | document.body.appendChild(hiddenDiv); 352 | 353 | //============================================================================= 354 | // 355 | //----------------------------------------------------------------------------- 356 | // 357 | //============================================================================= 358 | function addHiddenInput(type) { 359 | var input = document.createElement('input'); 360 | input.type = type; 361 | hiddenDiv.appendChild(input); 362 | return input; 363 | } 364 | ui.addHiddenInput = addHiddenInput; 365 | //============================================================================= 366 | // 367 | //----------------------------------------------------------------------------- 368 | // 369 | //============================================================================= 370 | function removeHiddenInput(input) { 371 | hiddenDiv.removeChild(input); 372 | } 373 | ui.removeHiddenInput = removeHiddenInput; 374 | 375 | })(ui); 376 | -------------------------------------------------------------------------------- /D$E_RingSceneMenu.js: -------------------------------------------------------------------------------- 1 | //============================================================================== 2 | // Dragon Engine (D$E) Ring Scene Menu 3 | // D$E_RingSceneMenu.js 4 | // Version 1.2.1 5 | //============================================================================== 6 | /* 7 | * Copyright 2015 Ramiro Rojo 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | /*: 20 | *@plugindesc Replaces the current scene 21 | * 22 | * @param Icons 23 | * @desc The set of icon used by the ring menu. 24 | * The list is in the format name: icon1, name2: icon2, ... 25 | * @default item: 176, skill: 79, equip: 137, status: 82, formation: 75, options: 83, save: 84, gameEnd: 1, cancel: 74 26 | * 27 | * @param Centre X 28 | * @desc The x position to display the centre of the menu. 29 | * Default: $gamePlayer.screenX() 30 | * @default $gamePlayer.screenX() 31 | * 32 | * @param Centre Y 33 | * @desc The y position to display the centre of the menu. 34 | * Default: $gamePlayer.screenY() - ($gamePlayer.isInAirship() ? 48 : 16) 35 | * @default $gamePlayer.screenY() - ($gamePlayer.isInAirship() ? 48 : 16) 36 | * 37 | * @param Radius X 38 | * @desc The x radius of the menu. 39 | * Default: Graphics.boxWidth / 10 40 | * @default Graphics.boxWidth / 10 41 | * 42 | * @param Radius Y 43 | * @desc The y radius of the menu. 44 | * Default: 32 45 | * @default 32 46 | * * 47 | * @param Starting Angle 48 | * @desc The starting angle of the first element, in degrees 49 | * Default: -90 50 | * @default -90 51 | * 52 | * @param Rotation 53 | * @desc 1- to clockwise, 1 to counter clockwise 54 | * Default: -1 55 | * @default -1 56 | * 57 | * @param Scale Difference 58 | * @desc Reduction / Increment for y values when rotating for 3d effect. 59 | * Default: 0.2 60 | * @default 0.2 61 | * 62 | * @param Show Actor Sprite 63 | * @desc Handles if the actor should be shown at the middle of the menu. 64 | * Default: yes 65 | * @default yes 66 | * 67 | * @param Show help window 68 | * @desc Select if you want to display the help window or not. 69 | * Default: yes. 70 | * @default yes 71 | * 72 | * @param Help Window X 73 | * @desc The default x position of the help window 74 | * Default: $gamePlayer.screenX() - 96 75 | * @default $gamePlayer.screenX() - 96 76 | * 77 | * @param Help Window Y 78 | * @desc The default y position of the help window 79 | * Default: $gamePlayer.screenY() - ($gamePlayer.isInAirship() ? 48 : 16) + 32 80 | * @default $gamePlayer.screenY() - ($gamePlayer.isInAirship() ? 48 : 16) + 32 81 | * 82 | * @param Help Window width 83 | * @desc The default width of the help window 84 | * Default: 320 85 | * @default 320 86 | * 87 | * @param Help Window height 88 | * @desc The default height of the help window 89 | * Default: 72 90 | * @default 72 91 | * 92 | * @param Help Window background opacity 93 | * @desc The opacity of the background for help window. o is transparent, 94 | * 255 means completely opaque. Default: 0 95 | * @default 0 96 | * 97 | * @help 98 | * ============================================================================= 99 | * * FAQ 100 | * ============================================================================= 101 | * - It is not working! 102 | * Press F8, check the console, it usually gives you a nice formatted error 103 | * made by me. 104 | * If it doesn't then report please! 105 | * --------------------------------------------------------------------------- 106 | * - Can I use images instead of the iconset? 107 | * Yes! you can, instead of putting a number, put it as a name like: 108 | * item: My Awesome Name. 109 | * Be aware than spaces before and after your name WILL be ignored 110 | * So 'My Awesome name' is the same as 'My Awesome name ' (notice the spaces 111 | * at the end) And remeber to not put the name with ''. 112 | * --------------------------------------------------------------------------- 113 | */ 114 | if (!window.D$E) { 115 | throw new Error("This plugin requires the 'Dragon Engine (D$E)' to work properly! Ensure your plugin list, or order of plugins."); 116 | } 117 | 118 | D$E.ensureParameters('D$E_RingSceneMenu'); 119 | 120 | PluginManager.register("D$E_RingSceneMenu", "1.0.0", { 121 | "email": "ramiro.rojo.cretta@gmail.com", 122 | "website": "http://binarychest.wordpress.com", 123 | "name": "Ramiro Rojo" 124 | }, "2015-11-04"); 125 | 126 | 127 | 128 | (function ($) { 129 | "use strict"; 130 | if (!$.ui || !$.ui.RingMenu) { 131 | throw "The Scene Menu with a ring menu requires the Ring menu (D$E_RingSceneMenu) to work!"; 132 | } 133 | 134 | if (!$.PARAMETERS['RingMenuParty']) { 135 | throw "The Scene Menu with a ring menu requires the Ring menu for the party (D$E_RingMenuParty) to work!"; 136 | } 137 | 138 | var RingMenu = $.ui.RingMenu; 139 | var params = RingMenu.readParams('D$E_RingSceneMenu'); 140 | 141 | $.PARAMETERS['RingSceneMenu'] = params; 142 | 143 | // Replacing the menu command itself. 144 | Window_MenuCommand = $.ui.RingMenu.extend(); 145 | 146 | Window_MenuCommand.prototype.initialize = function(parent) { 147 | this.parent = parent; 148 | $.ui.RingMenu.prototype.initialize.call(this, params.make()); 149 | this.makeCommandList(); 150 | this.selectLast(); 151 | this.close(0); 152 | this.open(30); 153 | }; 154 | 155 | Window_MenuCommand._lastCommandSymbol = null; 156 | 157 | Window_MenuCommand.initCommandPosition = function() { 158 | this._lastCommandSymbol = null; 159 | }; 160 | 161 | Window_MenuCommand.prototype.makeCommandList = function() { 162 | this.addMainCommands(); 163 | this.addFormationCommand(); 164 | this.addOriginalCommands(); 165 | this.addOptionsCommand(); 166 | this.addSaveCommand(); 167 | this.addGameEndCommand(); 168 | this.addCancelCommand(); 169 | }; 170 | 171 | Window_MenuCommand.prototype.addMainCommands = function() { 172 | var enabled = this.areMainCommandsEnabled(); 173 | if (this.needsCommand('item')) { 174 | this.addCommand(TextManager.item, 'item', enabled); 175 | } 176 | if (this.needsCommand('skill')) { 177 | this.addCommand(TextManager.skill, 'skill', enabled); 178 | } 179 | if (this.needsCommand('equip')) { 180 | this.addCommand(TextManager.equip, 'equip', enabled); 181 | } 182 | if (this.needsCommand('status')) { 183 | this.addCommand(TextManager.status, 'status', enabled); 184 | } 185 | }; 186 | 187 | Window_MenuCommand.prototype.addFormationCommand = function() { 188 | if (this.needsCommand('formation')) { 189 | var enabled = this.isFormationEnabled(); 190 | this.addCommand(TextManager.formation, 'formation', enabled); 191 | } 192 | }; 193 | 194 | Window_MenuCommand.prototype.addOriginalCommands = function() { 195 | }; 196 | 197 | Window_MenuCommand.prototype.addOptionsCommand = function() { 198 | if (this.needsCommand('options')) { 199 | var enabled = this.isOptionsEnabled(); 200 | this.addCommand(TextManager.options, 'options', enabled); 201 | } 202 | }; 203 | 204 | Window_MenuCommand.prototype.addSaveCommand = function() { 205 | if (this.needsCommand('save')) { 206 | var enabled = this.isSaveEnabled(); 207 | this.addCommand(TextManager.save, 'save', enabled); 208 | } 209 | }; 210 | 211 | Window_MenuCommand.prototype.addGameEndCommand = function() { 212 | var enabled = this.isGameEndEnabled(); 213 | this.addCommand(TextManager.gameEnd, 'gameEnd', enabled); 214 | }; 215 | 216 | Window_MenuCommand.prototype.needsCommand = function(name) { 217 | var flags = $dataSystem.menuCommands; 218 | if (flags) { 219 | switch (name) { 220 | case 'item': 221 | return flags[0]; 222 | case 'skill': 223 | return flags[1]; 224 | case 'equip': 225 | return flags[2]; 226 | case 'status': 227 | return flags[3]; 228 | case 'formation': 229 | return flags[4]; 230 | case 'save': 231 | return flags[5]; 232 | } 233 | } 234 | return true; 235 | }; 236 | 237 | Window_MenuCommand.prototype.areMainCommandsEnabled = function() { 238 | return $gameParty.exists(); 239 | }; 240 | 241 | Window_MenuCommand.prototype.isFormationEnabled = function() { 242 | return $gameParty.size() >= 2 && $gameSystem.isFormationEnabled(); 243 | }; 244 | 245 | Window_MenuCommand.prototype.isOptionsEnabled = function() { 246 | return true; 247 | }; 248 | 249 | Window_MenuCommand.prototype.isSaveEnabled = function() { 250 | return !DataManager.isEventTest() && $gameSystem.isSaveEnabled(); 251 | }; 252 | 253 | Window_MenuCommand.prototype.isGameEndEnabled = function() { 254 | return true; 255 | }; 256 | 257 | Window_MenuCommand.prototype.processOk = function() { 258 | Window_MenuCommand._lastCommandSymbol = this.currentSymbol(); 259 | RingMenu.prototype.processOk.call(this); 260 | }; 261 | 262 | Window_MenuCommand.prototype.selectLast = function() { 263 | this.selectSymbol(Window_MenuCommand._lastCommandSymbol); 264 | }; 265 | 266 | Window_MenuCommand.__inverseStart = false; 267 | 268 | Scene_Menu.__startAtActorSelection = false; 269 | 270 | Scene_Menu.prototype.createCommandWindow = function() { 271 | this._commandWindow = new Window_MenuCommand(this._windowLayer); 272 | this.addWindow(this._commandWindow); 273 | this._commandWindow.setHandler('item', this._prepareMenu(this.commandItem)); 274 | this._commandWindow.setHandler('skill', this._prepareMenu(this.commandPersonal, true)); 275 | this._commandWindow.setHandler('equip', this._prepareMenu(this.commandPersonal, true)); 276 | this._commandWindow.setHandler('status', this._prepareMenu(this.commandPersonal, true)); 277 | this._commandWindow.setHandler('formation', this._prepareMenu(this.commandFormation, true)); 278 | this._commandWindow.setHandler('options', this._prepareMenu(this.commandOptions)); 279 | this._commandWindow.setHandler('save', this._prepareMenu(this.commandSave)); 280 | this._commandWindow.setHandler('gameEnd', this._prepareMenu(this.commandGameEnd)); 281 | this._commandWindow.setHandler('cancel', this.popScene.bind(this)); 282 | if (Window_MenuCommand.__inverseStart) { 283 | this._commandWindow.inverseClose(0); 284 | if (!Scene_Menu.__startAtActorSelection) { 285 | this._commandWindow.open(); 286 | } 287 | Window_MenuCommand.__inverseStart = false; 288 | } 289 | }; 290 | 291 | Scene_Menu.prototype.createStatusWindow = function() { 292 | this._statusWindow = new $.ui.RingMenu.Party(this._windowLayer); 293 | this.addWindow(this._statusWindow); 294 | if (Scene_Menu.__startAtActorSelection) { 295 | Scene_Menu.__startAtActorSelection = false; 296 | this._commandWindow.deactivate(); 297 | this._statusWindow.activate(); 298 | this._statusWindow.inverseClose(0); 299 | this._statusWindow.open(); 300 | this.bindStatus(); 301 | } 302 | } 303 | 304 | Scene_Menu.prototype._prepareMenu = function (action, openStatus) { 305 | var self = this; 306 | return function () { 307 | self._commandWindow.inverseClose(); 308 | Window_MenuCommand.__inverseStart = true; 309 | if (openStatus) self._statusWindow.open(); 310 | self._sceneDied = true; 311 | self._sceneDieAction = action.bind(self); 312 | }; 313 | } 314 | 315 | var oldScene_Menu_popScene = Scene_Menu.prototype.popScene; 316 | var oldScene_Menu_update = Scene_Menu.prototype.update; 317 | var oldScene_Menu_onPersonalOk = Scene_Menu.prototype.onPersonalOk; 318 | var oldScene_Menu_onPersonalCancel = Scene_Menu.prototype.onPersonalCancel; 319 | var oldScene_Menu_create = Scene_Menu.prototype.create; 320 | var oldScene_Menu_onFormationCancel = Scene_Menu.prototype.onFormationCancel; 321 | 322 | Scene_Menu.prototype.popScene = function () { 323 | this._commandWindow.close(); 324 | this._sceneDied = true; 325 | this._sceneDieAction = oldScene_Menu_popScene.bind(this); 326 | } 327 | 328 | Scene_Menu.prototype.isPersonalCommand = function () { 329 | switch (this._commandWindow.currentSymbol()) { 330 | case 'skill': case 'equip': case 'formation': case 'status': 331 | return true; 332 | default: 333 | break; 334 | } 335 | return false; 336 | } 337 | 338 | Scene_Menu.prototype.bindStatus = function () { 339 | if (this.isPersonalCommand()) { 340 | this._bindPersonal(); 341 | } else { 342 | this._bindFormation(); 343 | } 344 | } 345 | 346 | Scene_Menu.prototype._bindPersonal = function() { 347 | this._statusWindow.setHandler('ok', this.onPersonalOk.bind(this)); 348 | this._statusWindow.setHandler('cancel', this.onPersonalCancel.bind(this)); 349 | }; 350 | 351 | Scene_Menu.prototype._bindFormation = function() { 352 | this._statusWindow.setHandler('ok', this.onFormationOk.bind(this)); 353 | this._statusWindow.setHandler('cancel', this.onFormationCancel.bind(this)); 354 | }; 355 | 356 | Scene_Menu.prototype.onPersonalCancel = function () { 357 | console.log('a'); 358 | this._statusWindow.close(); 359 | this._commandWindow.inverseClose(0); 360 | this._commandWindow.selectLast(); 361 | this._commandWindow.open(); 362 | this._commandWindow.activate(); 363 | this._sceneDied = true; 364 | this._sceneDieAction = oldScene_Menu_onPersonalCancel.bind(this); 365 | } 366 | 367 | Scene_Menu.prototype.onPersonalOk = function() { 368 | this._sceneDied = true; 369 | Scene_Menu.__startAtActorSelection = true; 370 | Window_MenuCommand.__inverseStart = true; 371 | this._statusWindow.inverseClose(); 372 | this._sceneDieAction = oldScene_Menu_onPersonalOk.bind(this); 373 | }; 374 | 375 | Scene_Menu.prototype.update = function () { 376 | if (this._sceneDied) { 377 | if (this.canCallDieAnimation()) { 378 | this._sceneDieAction(); 379 | this._sceneDied = false; 380 | return; 381 | } 382 | } 383 | oldScene_Menu_update.apply(this, arguments); 384 | } 385 | 386 | Scene_Menu.prototype.canCallDieAnimation = function () { 387 | return !this._commandWindow.isAnimating() && !this._statusWindow.isAnimating(); 388 | } 389 | 390 | Scene_Menu.prototype.create = function() { 391 | oldScene_Menu_create.call(this); 392 | this.createHelpWindow(); 393 | } 394 | 395 | Scene_Menu.prototype.createHelpWindow = function () { 396 | if (params.showHelpWindow) { 397 | this._helpWindow = new Window_Help(1); 398 | this.addWindow(this._helpWindow); 399 | this._commandWindow.setHelpWindow(this._helpWindow); 400 | this._statusWindow.setHelpWindow(this._helpWindow); 401 | var rect = params.helpWindowRect(); 402 | this._helpWindow.move(rect.x, rect.y, rect.width, rect.height); 403 | this._helpWindow.opacity = params.helpWindowOpacity(); 404 | } 405 | } 406 | 407 | Scene_Menu.prototype.onFormationCancel = function() { 408 | oldScene_Menu_onFormationCancel.call(this); 409 | this._statusWindow.close(); 410 | this._commandWindow.open(); 411 | this._sceneDied = true; 412 | this._sceneDieAction = this._statusWindow.selectLast.bind(this._statusWindow); 413 | }; 414 | 415 | $.PARAMETERS['RingSceneMenu'] = params; 416 | 417 | })(D$E); 418 | -------------------------------------------------------------------------------- /D$E_RingMenu.js: -------------------------------------------------------------------------------- 1 | //============================================================================== 2 | // Dragon Engine (D$E) Ring Menu 3 | // D$E_RingMenu.js 4 | // Version 1.5.0 5 | //============================================================================== 6 | /* 7 | * Copyright 2015 Ramiro Rojo 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | /*: 20 | *@plugindesc Allows to use an animated ring menu with options. 21 | *This is extended by many plugins. 22 | * 23 | * @param Cancel Text 24 | * @desc The text used by the cancel command. 25 | * Use it as your own language. 26 | * @default Cancel 27 | * 28 | * @param Default Rotation Time 29 | * @desc The time the ring manu takes to change to the next item in frames. 30 | * Default: 30 31 | * @default 30 32 | * 33 | */ 34 | if (!window.D$E) { 35 | throw new Error("This plugin requires the 'Dragon Engine (D$E)' to work properly! Ensure your plugin list, or order of plugins."); 36 | } 37 | 38 | D$E.ensureParameters('D$E_RingMenu'); 39 | 40 | PluginManager.register("D$E_RingMenu", "1.0.0", { 41 | "email": "ramiro.rojo.cretta@gmail.com", 42 | "website": "http://binarychest.wordpress.com", 43 | "name": "Ramiro Rojo" 44 | }, "2015-11-04"); 45 | 46 | 47 | 48 | (function ($) { 49 | "use strict"; 50 | 51 | var editorParams = $.parametersFromSchema(PluginManager.parameters('D$E_RingMenu'), { 52 | "Cancel Text": 'string', 53 | "Default Rotation Time": 'number' 54 | }); 55 | 56 | var params = { 57 | cancel: editorParams["Cancel Text"], 58 | defaultTime: editorParams["Default Rotation Time"] 59 | }; 60 | 61 | $.ui = $.ui || {}; 62 | 63 | $.ui.RingMenu = MVC.extend(PIXI.Container || PIXI.DisplayObjectContainer); 64 | 65 | $.ui.RingMenu.params = params; 66 | 67 | 68 | 69 | $.ui.RingMenu.prototype.initialize = function (options) { 70 | this._handlers = {}; 71 | this._disabled = {}; 72 | this._texts = {}; 73 | this._commands = options.commands || []; 74 | this._icons = options.icons || {}; 75 | this._commandButtons = []; 76 | if (this.clearCommandList) { 77 | this.clearCommandList(); 78 | this.drawAllItems(); 79 | } 80 | this.maxRadius = options.radius || new Point(128, 48); 81 | this._index = options.index || 0; 82 | this._helpWindow = null; 83 | this.startingAngle = options.startingAngle || 0; 84 | this._radius = new Point(this.maxRadius.x, this.maxRadius.y); 85 | this._centre = options.centre || new Point(0, 0); 86 | this._opacity = 255; 87 | this._destinationOpacity = this._opacity; 88 | this._destinationRadius = this._radius; 89 | this._animationTime = 0; 90 | this._active = true; 91 | this.rotation = options.rotation || -1; 92 | this._angle = this.startingAngle * this.rotation; 93 | this._destinationAngle = this._angle; 94 | this.scale = options.scale || 0; 95 | this._targetIndex = this._index; 96 | this._angle = this._destinationAngle; 97 | if (options.showActorSprite) { 98 | var char; 99 | if ($gamePlayer.isInVehicle()) { 100 | char = $gamePlayer.vehicle(); 101 | } else { 102 | char = $gamePlayer; 103 | } 104 | this._actorSprite = new Sprite_Character(char); 105 | if (this.parent.addChild) { 106 | this.parent.addChild(this._actorSprite); 107 | } 108 | } 109 | }; 110 | 111 | MVC.accessor($.ui.RingMenu.prototype, 'opacity', 112 | function (value) { 113 | this._opacity = Math.max(0, Math.min(value, 255)); 114 | } 115 | ); 116 | 117 | 118 | MVC.reader($.ui.RingMenu.prototype, 'angle'); 119 | 120 | MVC.reader($.ui.RingMenu.prototype, 'length', 121 | function () { 122 | return Object.keys(this._commands).length; 123 | } 124 | ); 125 | 126 | MVC.reader($.ui.RingMenu.prototype, 'radius', 127 | function () { 128 | return this._radius; 129 | } 130 | ); 131 | 132 | MVC.reader($.ui.RingMenu.prototype, 'centre', 133 | function () { 134 | return this._centre; 135 | } 136 | ); 137 | 138 | MVC.accessor($.ui.RingMenu.prototype, 'command', 139 | function (value) { 140 | this.select(this.indexOf(value)); 141 | }, 142 | function () { 143 | return this._commandsByIndex[this.index()]; 144 | } 145 | ); 146 | 147 | $.ui.RingMenu.prototype.index = function () { 148 | return this._index; 149 | } 150 | 151 | $.ui.RingMenu.prototype.deselect = function () { 152 | this.close(); 153 | } 154 | 155 | $.ui.RingMenu.prototype.helpWindow = function () { 156 | return this._helpWindow; 157 | } 158 | 159 | $.ui.RingMenu.prototype.setHelpWindow = function (window) { 160 | this._helpWindow = window; 161 | } 162 | 163 | $.ui.RingMenu.prototype.addCancelCommand = function () { 164 | var txt = $.ui.RingMenu.params.cancel; 165 | var cmd = new $.ui.RingMenu.Button(this, 'cancel'); 166 | this._setupCommand(cmd, txt, 'cancel', true); 167 | } 168 | 169 | $.ui.RingMenu.prototype.clearCommandList = function () { 170 | this._commandsByIndex = []; 171 | var self = this; 172 | this._commandButtons.forEach(function (i) { 173 | self.parent.removeChild(i); 174 | }); 175 | this._commandButtons = []; 176 | }; 177 | 178 | $.ui.RingMenu.prototype.redrawItem = function (index) { 179 | this._commandButtons[index].redraw(); 180 | } 181 | 182 | $.ui.RingMenu.prototype._refresh = function () { 183 | this.clearCommandList(); 184 | this.drawAllItems(); 185 | } 186 | 187 | $.ui.RingMenu.prototype.refresh = function () { 188 | this._refresh(); 189 | }; 190 | 191 | $.ui.RingMenu.prototype.iconOf = function (handler) { 192 | return this._icons[handler]; 193 | } 194 | 195 | $.ui.RingMenu.prototype.indexOf = function (handler) { 196 | return this._commandsByIndex.indexOf(handler); 197 | }; 198 | 199 | $.ui.RingMenu.prototype.setHandler = function (name, callback) { 200 | var idx = this.indexOf(name); 201 | this._handlers[name] = callback; 202 | if (idx >= 0) { 203 | this._commandButtons[idx].setClickHandler = callback; 204 | } 205 | }; 206 | 207 | $.ui.RingMenu.prototype.select = function (idx) { 208 | if (idx >= 0) { 209 | this._index = idx; 210 | this._angle = this._angleFor(this.index()); 211 | this._targetIndex = this.index(); 212 | this._destinationAngle = this._angle; 213 | } 214 | }; 215 | 216 | $.ui.RingMenu.prototype.selectSymbol = function (handler) { 217 | this.select(this.indexOf(handler)); 218 | }; 219 | 220 | $.ui.RingMenu.prototype.isOpen = function () { 221 | return this._radius.x == this._destinationRadius.x && this._radius.y == this._destinationRadius.y; 222 | }; 223 | 224 | $.ui.RingMenu.prototype.isAnimating = function () { 225 | return this._animationTime > 0; 226 | }; 227 | 228 | $.ui.RingMenu.prototype.isHandled = function (name) { 229 | return this._handlers[name]; 230 | }; 231 | 232 | $.ui.RingMenu.prototype.isActive = function (name) { 233 | return this._active; 234 | }; 235 | 236 | $.ui.RingMenu.prototype.canProcessInput = function () { 237 | return this.isOpenAndActive() && (!this.isAnimating()); 238 | }; 239 | 240 | $.ui.RingMenu.prototype.isEnabled = function (symbol) { 241 | return !this._disabled[symbol]; 242 | } 243 | 244 | $.ui.RingMenu.prototype.isEnabled = function () { 245 | return this.isOpen() && this.isActive(); 246 | } 247 | 248 | $.ui.RingMenu.prototype.isOpenAndActive = function () { 249 | return this.isOpen() && this.isActive(); 250 | } 251 | 252 | $.ui.RingMenu.prototype.isCurrentItemEnabled = function () { 253 | return this.isEnabled(this.command); 254 | }; 255 | 256 | $.ui.RingMenu.prototype.addCommand = function (text, name, enabled, icon) { 257 | if (typeof icon != 'undefined') { 258 | this._icons[name] = icon; 259 | } 260 | var cmd = this._createButton.apply(this, arguments); 261 | this._setupCommand(cmd, text, name, enabled, icon || undefined); 262 | }; 263 | 264 | $.ui.RingMenu.prototype._setupCommand = function (cmd, text, name, enabled) { 265 | cmd.setClickHandler(this._handlers[name]); 266 | this._texts[name] = text; 267 | this._commands[name] = cmd; 268 | this._commandButtons.push(cmd); 269 | this._commandsByIndex.push(name); 270 | this._disabled[name] = !enabled; 271 | this.parent.addChild(cmd); 272 | this.parent.children.sort(this.sort); 273 | this._angle = this._angleFor(this._index); 274 | } 275 | 276 | $.ui.RingMenu.prototype._createButton = function (text, name, enabled, icon) { 277 | return new $.ui.RingMenu.Button(this, name); 278 | } 279 | 280 | $.ui.RingMenu.prototype.currentSymbol = function () { 281 | var l = this._commandsByIndex[this.index()]; 282 | return l; 283 | } 284 | 285 | $.ui.RingMenu.prototype.disableCommand = function (name) { 286 | this._disabled[name] = true; 287 | }; 288 | 289 | $.ui.RingMenu.prototype.enableCommand = function (name) { 290 | this._disabled[name] = false; 291 | }; 292 | 293 | $.ui.RingMenu.prototype.deleteCommand = function (name) { 294 | this._commands[name] = null; 295 | this.clearCommandList(); 296 | this.drawAllItems(); 297 | }; 298 | 299 | $.ui.RingMenu.prototype.clearCommands = function (name) { 300 | this.clearCommandList(); 301 | this.drawAllItems(); 302 | }; 303 | 304 | $.ui.RingMenu.prototype.playOkSound = function() { 305 | SoundManager.playOk(); 306 | }; 307 | 308 | $.ui.RingMenu.prototype.playBuzzerSound = function() { 309 | SoundManager.playBuzzer(); 310 | }; 311 | 312 | $.ui.RingMenu.prototype.callOkHandler = function() { 313 | if (this.isHandled(this.command)) { 314 | this.callHandler(this.command); 315 | } else { 316 | this.callHandler('ok'); 317 | } 318 | }; 319 | 320 | $.ui.RingMenu.prototype.callCancelHandler = function() { 321 | this.callHandler('cancel'); 322 | }; 323 | 324 | 325 | $.ui.RingMenu.prototype.update = function () { 326 | if (this.isAnimating()) { 327 | this._updateAnimation(); 328 | } else { 329 | this._refreshValues(); 330 | this._updateInput(); 331 | this._updateHelpWindow(); 332 | } 333 | this._updateZIndexes(); 334 | } 335 | 336 | $.ui.RingMenu.prototype._updateHelpWindow = function () { 337 | if (this._helpWindow && this.canProcessHelp()) { 338 | this.currentButton().updateHelp(this._helpWindow); 339 | } 340 | } 341 | 342 | $.ui.RingMenu.prototype.text = function (symbol) { 343 | return this._texts[symbol]; 344 | } 345 | 346 | $.ui.RingMenu.prototype.currentButton = function () { 347 | return this._commandButtons[this.index()]; 348 | } 349 | 350 | $.ui.RingMenu.prototype.canProcessHelp = function () { 351 | return this.isActive(); 352 | } 353 | 354 | $.ui.RingMenu.prototype.sort = function (a, b) { 355 | if (isNaN(a.y) || isNaN(b.y) || a.y === null || b.y === null) { 356 | return 0; 357 | } 358 | if (a.y < b.y) 359 | return -1; 360 | if (a.y > b.y) 361 | return 1; 362 | return 0; 363 | } 364 | 365 | $.ui.RingMenu.prototype._updateZIndexes = function () { 366 | if (this.isAnimating()) { 367 | this.parent.children.sort(this.sort); 368 | } 369 | } 370 | 371 | $.ui.RingMenu.prototype._updateAnimation = function () { 372 | var t = this._animationTime; 373 | this._animationTime -= 1; 374 | var t2 = this._animationTime; 375 | this._opacity = (this._opacity * (t2) + this._destinationOpacity) / t; 376 | this._angle = (this._angle * (t2) + this._destinationAngle) / t; 377 | this._radius.x = (this._radius.x * (t2) + this._destinationRadius.x) / t; 378 | this._radius.y = (this._radius.y * (t2) + this._destinationRadius.y) / t; 379 | }; 380 | 381 | $.ui.RingMenu.prototype._refreshValues = function () { 382 | this._index = this._targetIndex; 383 | var a = this._index; 384 | var b = this.length; 385 | this._index = (a % b + b) % b; 386 | this._angle = this._angleFor(this._index); 387 | } 388 | 389 | $.ui.RingMenu.prototype._updateInput = function () { 390 | if (!this.canProcessInput()) { 391 | return; 392 | } 393 | if (this.isOkEnabled() && this.isOkTriggered()) { 394 | this.processOk(); 395 | } else if (this.isCancelEnabled() && this.isCancelTriggered()) { 396 | this.processCancel(); 397 | } else if (Input.isPressed('left')) { 398 | this.turnLeft(); 399 | } else if (Input.isPressed('right')) { 400 | this.turnRight(); 401 | } 402 | }; 403 | 404 | $.ui.RingMenu.prototype.updateInputData = function () { 405 | Input.update(); 406 | TouchInput.update(); 407 | }; 408 | 409 | $.ui.RingMenu.prototype.isOkEnabled = function () { 410 | return true; 411 | }; 412 | 413 | $.ui.RingMenu.prototype.isOkTriggered = function () { 414 | return Input.isRepeated('ok'); 415 | }; 416 | 417 | $.ui.RingMenu.prototype.isCancelEnabled = function () { 418 | return true; 419 | }; 420 | 421 | $.ui.RingMenu.prototype.isCancelTriggered = function () { 422 | return Input.isRepeated('cancel') || TouchInput.isCancelled(); 423 | }; 424 | 425 | $.ui.RingMenu.prototype.processOk = function () { 426 | if (this.isCurrentItemEnabled()) { 427 | this.playOkSound(); 428 | this.updateInputData(); 429 | this.deactivate(); 430 | this.callOkHandler(); 431 | return; 432 | } 433 | this.playBuzzerSound(); 434 | }; 435 | 436 | $.ui.RingMenu.prototype.processCancel = function () { 437 | SoundManager.playCancel(); 438 | this.updateInputData(); 439 | this.deactivate(); 440 | this.callCancelHandler(); 441 | }; 442 | 443 | $.ui.RingMenu.prototype.callHandler = function (name) { 444 | if (this.isHandled(name)) { 445 | this._handlers[name](); 446 | } 447 | }; 448 | 449 | $.ui.RingMenu.prototype.activate = function () { 450 | this._active = true; 451 | } 452 | 453 | $.ui.RingMenu.prototype.deactivate = function () { 454 | this._active = false; 455 | } 456 | 457 | $.ui.RingMenu.prototype.open = function (time) { 458 | if (arguments.length == 0) { 459 | time = params.defaultTime; 460 | } 461 | this._destinationRadius = this.maxRadius; 462 | this._destinationOpacity = 255; 463 | this._destinationAngle = this._angleFor(this.index()); 464 | this._angle = this._angle + Math.PI * time / 30; 465 | this._animationTime = 0; 466 | if (time <= 0) { 467 | this._opacity = this._destinationOpacity; 468 | this._radius = this._destinationRadius; 469 | this._angle = this._destinationAngle; 470 | return; 471 | } 472 | this._animationTime = time; 473 | }; 474 | 475 | $.ui.RingMenu.prototype.close = function (time) { 476 | if (arguments.length == 0) { 477 | time = params.defaultTime; 478 | } 479 | this._destinationRadius = new Point(0, 0); 480 | this._destinationOpacity = 0; 481 | this._destinationAngle = this._angle + Math.PI * time / 30; 482 | this._animationTime = 0; 483 | if (time <= 0) { 484 | this._opacity = this._destinationOpacity; 485 | this._radius = this._destinationRadius; 486 | this._angle = this._destinationAngle; 487 | return; 488 | } 489 | this._animationTime = time; 490 | }; 491 | 492 | 493 | $.ui.RingMenu.prototype.inverseClose = function (time) { 494 | if (arguments.length == 0) { 495 | time = params.defaultTime; 496 | } 497 | this._destinationRadius = new Point(this.maxRadius.x * 2, this.maxRadius.y * 2); 498 | this._destinationOpacity = 0; 499 | this._destinationAngle = this._angleFor(this.index()) + Math.PI * time / 30; 500 | this._animationTime = 0; 501 | if (time <= 0) { 502 | this._opacity = this._destinationOpacity; 503 | this._radius = this._destinationRadius; 504 | this._angle = this._destinationAngle; 505 | return; 506 | } 507 | this._animationTime = time; 508 | }; 509 | 510 | $.ui.RingMenu.prototype.turnTo = function (symbol, time) { 511 | var newIndex = this.indexOf(symbol); 512 | var n = this.index() - newIndex; 513 | if (n == this.length - 1) { 514 | this._destinationAngle = this._angleFor(this.index() + 1); 515 | } else if (n == - this.length + 1) { 516 | this._destinationAngle = this._angleFor(this.index() - 1); 517 | } else { 518 | this._destinationAngle = this.angleFor(symbol); 519 | } 520 | if (arguments.length == 1) { 521 | if ((n == this.length - 1) || (n == - this.length + 1) ) { 522 | time = params.defaultTime; 523 | } else { 524 | time = params.defaultTime * Math.abs(n); 525 | } 526 | 527 | } 528 | this._animationTime = time; 529 | SoundManager.playCursor(); 530 | if (time <= 0) { 531 | this._angle = this._destinationAngle; 532 | } 533 | this._targetIndex = newIndex; 534 | } 535 | 536 | $.ui.RingMenu.prototype.turnLeft = function (time) { 537 | if (arguments.length == 0) { 538 | time = params.defaultTime; 539 | } 540 | this._animationTime = time; 541 | this._destinationAngle = this._nextLeftAngle(); 542 | SoundManager.playCursor(); 543 | if (time <= 0) { 544 | this._angle = this._destinationAngle; 545 | } 546 | this._targetIndex = this._index - 1; 547 | }; 548 | 549 | $.ui.RingMenu.prototype.turnRight = function (time) { 550 | if (arguments.length == 0) { 551 | time = params.defaultTime; 552 | } 553 | SoundManager.playCursor(); 554 | this._animationTime = time; 555 | this._destinationAngle = this._nextRightAngle(); 556 | if (time <= 0) { 557 | this._angle = this._destinationAngle; 558 | } 559 | this._targetIndex = this._index + 1; 560 | }; 561 | 562 | $.ui.RingMenu.prototype._nextRightAngle = function () { 563 | return this._angleFor(this.index() + 1); 564 | }; 565 | 566 | $.ui.RingMenu.prototype._nextLeftAngle = function () { 567 | return this._angleFor(this.index() - 1); 568 | }; 569 | 570 | $.ui.RingMenu.prototype._angleFor = function (index) { 571 | var length = this.length; 572 | if (length < 0) { 573 | return this.startingAngle; 574 | } 575 | return (index - this._index) * Math.PI * 2 / length - this.startingAngle; 576 | }; 577 | 578 | $.ui.RingMenu.prototype.angleFor = function (handle) { 579 | return this._angleFor(this.indexOf(handle)); 580 | }; 581 | 582 | $.ui.RingMenu.prototype.drawAllItems = function () { 583 | var commands = this._commands; 584 | for (var commandName in commands) { 585 | if (commands.hasOwnProperty(commandName)) { 586 | this.drawItem(commandName); 587 | } 588 | } 589 | } 590 | 591 | $.ui.RingMenu.prototype.drawItem = function (commandName) { 592 | this._commandsByIndex.push(commandName); 593 | var cmd = this._createButton(this._texts[commandName], commandName, !this._disabled[commandName], this._icons[commandName]); 594 | cmd.setClickHandler(this._handlers[commandName]); 595 | this._commandButtons.push(cmd); 596 | this.parent.addChild(cmd); 597 | this.parent.children.sort(this.sort); 598 | } 599 | 600 | $.ui.RingMenu.prototype.resetScroll = function () { 601 | this.index = 0; 602 | } 603 | 604 | // Button here 605 | 606 | $.ui.RingMenu.Button = MVC.extend(Sprite_Button); 607 | 608 | $.ui.RingMenu.Button.prototype.initialize = function (menu, name) { 609 | Sprite_Button.prototype.initialize.call(this); 610 | this.opacity = 0; 611 | this._name = name; 612 | this._menu = menu; 613 | this._lastIcon = null; 614 | this.anchor.x = 0.5; 615 | this.anchor.y = 0.5; 616 | this.x = this._menu.centre.x; 617 | this.y = this._menu.centre.y; 618 | this._updateIconBitmap(); 619 | }; 620 | 621 | MVC.reader($.ui.RingMenu.Button.prototype, 'icon', 622 | function () { 623 | return this._menu.iconOf(this._name); 624 | } 625 | ); 626 | 627 | MVC.reader($.ui.RingMenu.Button.prototype, 'index', 628 | function () { 629 | return this._menu.indexOf(this._name); 630 | } 631 | ); 632 | 633 | $.ui.RingMenu.Button.prototype.update = function () { 634 | this._updateIconBitmap(); 635 | this._updatePosition(); 636 | //this.processTouch(); 637 | Sprite_Button.prototype.update.call(this); 638 | }; 639 | 640 | $.ui.RingMenu.Button.prototype.isActive = function () { 641 | return this._menu.isActive(); 642 | } 643 | 644 | $.ui.RingMenu.Button.prototype._updateIconBitmap = function () { 645 | var pw, ph, sx, sy; 646 | var icon = this.icon; 647 | if (icon == this._lastIcon) { 648 | return; 649 | } 650 | switch (typeof icon) { 651 | case 'number': 652 | this.bitmap = ImageManager.loadSystem('IconSet'); 653 | pw = Window_Base._iconWidth; 654 | ph = Window_Base._iconHeight; 655 | sx = icon % 16 * pw; 656 | sy = Math.floor(icon / 16) * ph; 657 | this.setColdFrame(sx, sy, pw, ph); 658 | this.setHotFrame(sx, sy, pw, ph); 659 | break; 660 | case 'string' : 661 | this.bitmap = ImageManager.loadSystem(icon); 662 | pw = this.bitmap.width / 2; 663 | ph = this.bitmap.height; 664 | sx = 0; 665 | sy = 0; 666 | this.setColdFrame(sx, sy, pw, ph); 667 | this.setHotFrame(sx + pw, sy, pw, ph); 668 | break; 669 | default: 670 | this.bitmap = ImageManager.loadSystem('IconSet'); 671 | pw = Window_Base._iconWidth; 672 | ph = Window_Base._iconHeight; 673 | sx = icon.cold % 16 * pw; 674 | sy = Math.floor(icon.cold / 16) * ph; 675 | this.setColdFrame(sx, sy, pw, ph); 676 | pw = Window_Base._iconWidth; 677 | ph = Window_Base._iconHeight; 678 | sx = icon.hot % 16 * pw; 679 | sy = Math.floor(icon.hot / 16) * ph; 680 | this.setHotFrame(sx, sy, pw, ph); 681 | break; 682 | } 683 | this._lastIcon = icon; 684 | }; 685 | 686 | $.ui.RingMenu.Button.prototype.isButtonTouched = function() { 687 | var x = this.canvasToLocalX(TouchInput.x); 688 | var y = this.canvasToLocalY(TouchInput.y); 689 | var w = this.width * Math.abs(this.scale.x); 690 | var h = this.height * Math.abs(this.scale.y); 691 | return x >= 0 && y >= 0 && x < w && y < h; 692 | }; 693 | 694 | $.ui.RingMenu.Button.prototype.canvasToLocalX = function(x) { 695 | var node = this; 696 | while (node) { 697 | x -= node.x; 698 | node = node.parent; 699 | } 700 | return x + this.anchor.x * this.width * Math.abs(this.scale.x); 701 | }; 702 | 703 | $.ui.RingMenu.Button.prototype.canvasToLocalY = function(y) { 704 | var node = this; 705 | while (node) { 706 | y -= node.y; 707 | node = node.parent; 708 | } 709 | return y + this.anchor.y * this.height * Math.abs(this.scale.y); 710 | }; 711 | 712 | $.ui.RingMenu.Button.prototype.callClickHandler = function () { 713 | if (this._name == this._menu.currentSymbol()) { 714 | this._menu.processOk(); 715 | } else { 716 | this._menu.turnTo(this._name); 717 | } 718 | } 719 | 720 | $.ui.RingMenu.Button.prototype._updatePosition = function () { 721 | var angle = this._menu.angleFor(this._name) - this._menu.angle + this._menu.startingAngle; 722 | var radius = this._menu.radius; 723 | var centre = this._menu.centre; 724 | this.anchor.x = 0.5; 725 | this.anchor.y = 0.5; 726 | this.x = centre.x + radius.x * Math.cos(angle); 727 | this.y = centre.y + radius.y * Math.sin(angle) * this._menu.rotation ; 728 | 729 | this.scale.x = 1.0 + (this.y - centre.y) * this._menu.scale / this._menu.maxRadius.y; 730 | this.scale.y = this.scale.x; 731 | this.opacity = this._menu.opacity * (this._menu.isEnabled(this._name) ? 1 : 0.5); 732 | }; 733 | 734 | $.ui.RingMenu.Button.prototype.redraw = function () { 735 | 736 | } 737 | 738 | $.ui.RingMenu.Button.prototype.updateHelp = function (window) { 739 | window.setText(this._menu.text(this._name)); 740 | } 741 | 742 | // Command Window 743 | 744 | $.ui.RingMenu.Command = $.ui.RingMenu.extend(); 745 | 746 | $.ui.RingMenu.Command.prototype.initialize = function(parent, params) { 747 | this.parent = parent; 748 | this._ext = {}; 749 | $.ui.RingMenu.prototype.initialize.call(this, params); 750 | this.makeCommandList(); 751 | } 752 | 753 | $.ui.RingMenu.Command.prototype.commandName = function(index) { 754 | return this._texts[this.commandSymbol(index)]; 755 | }; 756 | 757 | $.ui.RingMenu.Command.prototype.commandSymbol = function(index) { 758 | return this._commandsByIndex[index]; 759 | }; 760 | 761 | $.ui.RingMenu.Command.prototype.commandExt = function(index) { 762 | return this._ext[this.commandSymbol(index)]; 763 | }; 764 | 765 | $.ui.RingMenu.Command.prototype.isCommandEnabled = function(index) { 766 | return !this._disabled[this.commandSymbol(index)]; 767 | }; 768 | 769 | $.ui.RingMenu.Command.prototype.addCommand = function (text, name, enabled, ext, icon) { 770 | if (typeof ext == 'undefined') { 771 | ext = null; 772 | } 773 | this._ext[name] = icon; 774 | $.ui.RingMenu.prototype.addCommand.call(this, text, name, enabled, icon || undefined); 775 | } 776 | 777 | $.ui.RingMenu.Command.prototype.data = function (index) { 778 | return { 779 | name: this.commandName(index), 780 | text: this.commandSymbol(index), 781 | ext: this.commandExt(index), 782 | enabled: this.isCommandEnabled(index) 783 | }; 784 | } 785 | 786 | $.ui.RingMenu.Command.prototype.currentData = function() { 787 | return this.index() >= 0 ? this.data(this.index()) : null; 788 | }; 789 | 790 | $.ui.RingMenu.Command.prototype.currentExt = function () { 791 | return this.index() >= 0 ? this.commandExt(this.index()) : null; 792 | } 793 | 794 | $.ui.RingMenu.Command.prototype.findSymbol = function (symbol) { 795 | return this.indexOf(symbol); 796 | } 797 | 798 | $.ui.RingMenu.Command.prototype.findExt = function (ext) { 799 | var length = this._commandsByIndex.length; 800 | for (var i = 0; i < length; ++i) { 801 | var cmd = this._commandsByIndex[i]; 802 | if (this._ext[cmd] == ext) { 803 | return i; 804 | } 805 | } 806 | return -1; 807 | } 808 | 809 | $.ui.RingMenu.Command.prototype.selectExt = function(ext) { 810 | var index = this.findExt(ext); 811 | if (index >= 0) { 812 | this.select(index); 813 | } else { 814 | this.select(0); 815 | } 816 | }; 817 | 818 | // Parameter reader 819 | 820 | $.ui.RingMenu.readParams = function (name, extraParams) { 821 | var editorParams = $.parametersFromSchema(PluginManager.parameters(name), $.merge({ 822 | "Icons": { type:'hash', of: { type:'str', after: $.parseAsStringOrNumber } }, 823 | "Centre X": 'function', 824 | "Centre Y": 'function', 825 | "Radius X": 'function', 826 | "Radius Y": 'function', 827 | "Starting Angle": { type: 'number', after: $.degToRad }, 828 | "Rotation": 'number', 829 | "Scale Difference": 'number', 830 | "Show Actor Sprite": 'bool', 831 | "Show help window": 'bool', 832 | "Help Window X": 'function', 833 | "Help Window Y": 'function', 834 | "Help Window width": 'function', 835 | "Help Window height": 'function', 836 | "Help Window background opacity": 'function' 837 | }, extraParams || {})); 838 | 839 | return { 840 | editorParams: editorParams, 841 | icons: editorParams.Icons, 842 | centreX: editorParams["Centre X"], 843 | centreY: editorParams["Centre Y"], 844 | radiusX: editorParams["Radius X"], 845 | radiusY: editorParams["Radius Y"], 846 | startingAngle: editorParams["Starting Angle"], 847 | rotation: editorParams["Rotation"], 848 | scale: editorParams["Scale Difference"], 849 | showActorSprite: editorParams["Show Actor Sprite"], 850 | showHelpWindow: editorParams["Show help window"], 851 | helpWindowOpacity: editorParams["Help Window background opacity"], 852 | helpWindowRect: function () { 853 | return new Rectangle(this.editorParams["Help Window X"](), 854 | this.editorParams["Help Window Y"](), 855 | this.editorParams["Help Window width"](), 856 | this.editorParams["Help Window height"]() 857 | ); 858 | }, 859 | make: function () { 860 | return { 861 | icons: this.icons, 862 | centre: new Point(this.centreX(), this.centreY()), 863 | radius: new Point(this.radiusX(), this.radiusY()), 864 | startingAngle: this.startingAngle, 865 | rotation: this.rotation, 866 | scale: this.scale, 867 | showActorSprite: this.showActorSprite 868 | }; 869 | } 870 | }; 871 | } 872 | 873 | // Base window used for skills and items 874 | 875 | $.ui.RingMenu.ItemBase = $.ui.RingMenu.extend(); 876 | 877 | $.ui.RingMenu.ItemBase.prototype.initialize = function (parent, params) { 878 | this.parent = parent; 879 | $.ui.RingMenu.prototype.initialize.call(this, params); 880 | this.close(0); 881 | this._category = 'none'; 882 | this._data = []; 883 | } 884 | 885 | $.ui.RingMenu.ItemBase.prototype.setCategory = function(category) { 886 | if (this._category !== category) { 887 | this._category = category; 888 | this.refresh(); 889 | this.resetScroll(); 890 | } 891 | }; 892 | 893 | $.ui.RingMenu.ItemBase.prototype.maxItems = function() { 894 | return this._data ? this._data.length : 1; 895 | }; 896 | 897 | $.ui.RingMenu.ItemBase.prototype.includes = function(item) { 898 | return false; 899 | }; 900 | 901 | $.ui.RingMenu.ItemBase.prototype.needsNumber = function() { 902 | return true; 903 | }; 904 | 905 | $.ui.RingMenu.ItemBase.prototype.isEnabled = function(item) { 906 | return $gameParty.canUse(item); 907 | }; 908 | 909 | $.ui.RingMenu.ItemBase.prototype.makeItemList = function() { 910 | }; 911 | 912 | $.ui.RingMenu.ItemBase.prototype.selectLast = function() { 913 | var index = this._data.indexOf($gameParty.lastItem()); 914 | this.select(index >= 0 ? index : 0); 915 | }; 916 | 917 | $.ui.RingMenu.ItemBase.prototype.updateHelp = function() { 918 | this.setHelpWindowItem(this.item()); 919 | }; 920 | 921 | $.ui.RingMenu.ItemBase.prototype._refresh = function () { 922 | this.makeItemList(); 923 | $.ui.RingMenu.prototype._refresh.apply(this, arguments); 924 | } 925 | 926 | // Item window 927 | 928 | $.ui.RingMenu.Item = $.ui.RingMenu.ItemBase.extend(); 929 | 930 | $.ui.RingMenu.Item.prototype.makeItemList = function() { 931 | this._data = $gameParty.allItems().filter(function(item) { 932 | return this.includes(item); 933 | }, this); 934 | if (this.includes(null)) { 935 | this._data.push(null); 936 | } 937 | }; 938 | 939 | $.ui.RingMenu.Item.prototype.includes = function(item) { 940 | switch (this._category) { 941 | case 'item': 942 | return DataManager.isItem(item) && item.itypeId === 1; 943 | case 'weapon': 944 | return DataManager.isWeapon(item); 945 | case 'armor': 946 | return DataManager.isArmor(item); 947 | case 'keyItem': 948 | return DataManager.isItem(item) && item.itypeId === 2; 949 | default: 950 | return false; 951 | } 952 | }; 953 | 954 | // Skill window 955 | 956 | $.ui.RingMenu.Skill = $.ui.RingMenu.ItemBase.extend(); 957 | 958 | $.ui.RingMenu.Skill.prototype.initialize = function () { 959 | this._actor = null; 960 | this._stypeId = 0; 961 | $.ui.RingMenu.ItemBase.prototype.initialize.apply(this, arguments); 962 | } 963 | 964 | $.ui.RingMenu.Skill.prototype.setActor = function (actor) { 965 | if (this._actor !== actor) { 966 | this._actor = actor; 967 | this.refresh(); 968 | this.resetScroll(); 969 | } 970 | } 971 | 972 | $.ui.RingMenu.Skill.prototype.setStypeId = function(stypeId) { 973 | if (this._stypeId !== stypeId) { 974 | this._stypeId = stypeId; 975 | this.refresh(); 976 | this.resetScroll(); 977 | } 978 | }; 979 | 980 | $.ui.RingMenu.Skill.prototype.makeItemList = function() { 981 | if (this._actor) { 982 | this._data = this._actor.skills().filter(function(item) { 983 | return this.includes(item); 984 | }, this); 985 | } else { 986 | this._data = []; 987 | } 988 | }; 989 | 990 | $.ui.RingMenu.Skill.prototype.includes = function(item) { 991 | return item && item.stypeId === this._stypeId; 992 | }; 993 | 994 | $.PARAMETERS['RingMenu'] = params; 995 | 996 | })(D$E); 997 | -------------------------------------------------------------------------------- /I18n.js: -------------------------------------------------------------------------------- 1 | //============================================================================== 2 | // Dragon Engine (D$E) Ring Menu 3 | // D$E_RingMenu.js 4 | // Version 1.3.0 5 | //============================================================================== 6 | /* 7 | * Copyright 2015 Ramiro Rojo 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | /*: 20 | *@plugindesc Allows to easy translate all of your text from the game on a nice 21 | * format to read and write. 22 | * 23 | */ 24 | // this section is auto generated 25 | var I18n = (function() { 26 | "use strict"; 27 | 28 | /* 29 | * Generated by PEG.js 0.9.0. 30 | * 31 | * http://pegjs.org/ 32 | */ 33 | 34 | function peg$subclass(child, parent) { 35 | function ctor() { this.constructor = child; } 36 | ctor.prototype = parent.prototype; 37 | child.prototype = new ctor(); 38 | } 39 | 40 | function peg$SyntaxError(message, expected, found, location) { 41 | this.message = message; 42 | this.expected = expected; 43 | this.found = found; 44 | this.location = location; 45 | this.name = "SyntaxError"; 46 | 47 | if (typeof Error.captureStackTrace === "function") { 48 | Error.captureStackTrace(this, peg$SyntaxError); 49 | } 50 | } 51 | 52 | peg$subclass(peg$SyntaxError, Error); 53 | 54 | function peg$parse(input) { 55 | var options = arguments.length > 1 ? arguments[1] : {}, 56 | parser = this, 57 | 58 | peg$FAILED = {}, 59 | 60 | peg$startRuleFunctions = { start: peg$parsestart }, 61 | peg$startRuleFunction = peg$parsestart, 62 | 63 | peg$c0 = function(g) { return formatGroups(g); }, 64 | peg$c1 = "#", 65 | peg$c2 = { type: "literal", value: "#", description: "\"#\"" }, 66 | peg$c3 = { type: "any", description: "any character" }, 67 | peg$c4 = "\n", 68 | peg$c5 = { type: "literal", value: "\n", description: "\"\\n\"" }, 69 | peg$c6 = "\r", 70 | peg$c7 = { type: "literal", value: "\r", description: "\"\\r\"" }, 71 | peg$c8 = ":", 72 | peg$c9 = { type: "literal", value: ":", description: "\":\"" }, 73 | peg$c10 = function(k, v) { return { key: k, value: v, line: 0, col: 0 }; }, 74 | peg$c11 = /^[A-Za-z0-9_\-]/, 75 | peg$c12 = { type: "class", value: "[A-Za-z0-9_-]", description: "[A-Za-z0-9_-]" }, 76 | peg$c13 = function(r) { return r.join(''); }, 77 | peg$c14 = "\"", 78 | peg$c15 = { type: "literal", value: "\"", description: "\"\\\"\"" }, 79 | peg$c16 = function(s) { return s.join(''); }, 80 | peg$c17 = function(c) { return c; }, 81 | peg$c18 = function(r) { return r; }, 82 | peg$c19 = function(f, r) { return [f].concat(r); }, 83 | peg$c20 = function(p) { return p; }, 84 | peg$c21 = function(f, r) { console.log(INDENT.concat([])); return [f].concat(r).join('\n'); }, 85 | peg$c22 = function(s) { return s; }, 86 | peg$c23 = "&newline;", 87 | peg$c24 = { type: "literal", value: "&newline;", description: "\"&newline;\"" }, 88 | peg$c25 = function() { return '\n'; }, 89 | peg$c26 = "&return;", 90 | peg$c27 = { type: "literal", value: "&return;", description: "\"&return;\"" }, 91 | peg$c28 = function() { return '\r'; }, 92 | peg$c29 = "&tab;", 93 | peg$c30 = { type: "literal", value: "&tab;", description: "\"&tab;\"" }, 94 | peg$c31 = function() { return '\t'; }, 95 | peg$c32 = "&form;", 96 | peg$c33 = { type: "literal", value: "&form;", description: "\"&form;\"" }, 97 | peg$c34 = function() { return '\f'; }, 98 | peg$c35 = "&vtab;", 99 | peg$c36 = { type: "literal", value: "&vtab;", description: "\"&vtab;\"" }, 100 | peg$c37 = function() { return '\v'; }, 101 | peg$c38 = "&", 102 | peg$c39 = { type: "literal", value: "&", description: "\"&\"" }, 103 | peg$c40 = function() { return '&'; }, 104 | peg$c41 = ""e;", 105 | peg$c42 = { type: "literal", value: ""e;", description: "\""e;\"" }, 106 | peg$c43 = function() { return '"'; }, 107 | peg$c44 = "&space;", 108 | peg$c45 = { type: "literal", value: "&space;", description: "\"&space;\"" }, 109 | peg$c46 = function() { return ' '; }, 110 | peg$c47 = "&hash;", 111 | peg$c48 = { type: "literal", value: "&hash;", description: "\"&hash;\"" }, 112 | peg$c49 = function() { return '#'; }, 113 | peg$c50 = " ", 114 | peg$c51 = { type: "literal", value: " ", description: "\" \"" }, 115 | peg$c52 = "\t", 116 | peg$c53 = { type: "literal", value: "\t", description: "\"\\t\"" }, 117 | peg$c54 = function(s) { return s >= INDENT.top() }, 118 | peg$c55 = function(s) { INDENT.push(s); }, 119 | peg$c56 = function(s) { return s == INDENT.top(); }, 120 | peg$c57 = "", 121 | peg$c58 = function() { INDENT.pop(); }, 122 | peg$c59 = function(s) { return s.length; }, 123 | 124 | peg$currPos = 0, 125 | peg$savedPos = 0, 126 | peg$posDetailsCache = [{ line: 1, column: 1, seenCR: false }], 127 | peg$maxFailPos = 0, 128 | peg$maxFailExpected = [], 129 | peg$silentFails = 0, 130 | 131 | peg$result; 132 | 133 | if ("startRule" in options) { 134 | if (!(options.startRule in peg$startRuleFunctions)) { 135 | throw new Error("Can't start parsing from rule \"" + options.startRule + "\"."); 136 | } 137 | 138 | peg$startRuleFunction = peg$startRuleFunctions[options.startRule]; 139 | } 140 | 141 | function text() { 142 | return input.substring(peg$savedPos, peg$currPos); 143 | } 144 | 145 | function location() { 146 | return peg$computeLocation(peg$savedPos, peg$currPos); 147 | } 148 | 149 | function expected(description) { 150 | throw peg$buildException( 151 | null, 152 | [{ type: "other", description: description }], 153 | input.substring(peg$savedPos, peg$currPos), 154 | peg$computeLocation(peg$savedPos, peg$currPos) 155 | ); 156 | } 157 | 158 | function error(message) { 159 | throw peg$buildException( 160 | message, 161 | null, 162 | input.substring(peg$savedPos, peg$currPos), 163 | peg$computeLocation(peg$savedPos, peg$currPos) 164 | ); 165 | } 166 | 167 | function peg$computePosDetails(pos) { 168 | var details = peg$posDetailsCache[pos], 169 | p, ch; 170 | 171 | if (details) { 172 | return details; 173 | } else { 174 | p = pos - 1; 175 | while (!peg$posDetailsCache[p]) { 176 | p--; 177 | } 178 | 179 | details = peg$posDetailsCache[p]; 180 | details = { 181 | line: details.line, 182 | column: details.column, 183 | seenCR: details.seenCR 184 | }; 185 | 186 | while (p < pos) { 187 | ch = input.charAt(p); 188 | if (ch === "\n") { 189 | if (!details.seenCR) { details.line++; } 190 | details.column = 1; 191 | details.seenCR = false; 192 | } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") { 193 | details.line++; 194 | details.column = 1; 195 | details.seenCR = true; 196 | } else { 197 | details.column++; 198 | details.seenCR = false; 199 | } 200 | 201 | p++; 202 | } 203 | 204 | peg$posDetailsCache[pos] = details; 205 | return details; 206 | } 207 | } 208 | 209 | function peg$computeLocation(startPos, endPos) { 210 | var startPosDetails = peg$computePosDetails(startPos), 211 | endPosDetails = peg$computePosDetails(endPos); 212 | 213 | return { 214 | start: { 215 | offset: startPos, 216 | line: startPosDetails.line, 217 | column: startPosDetails.column 218 | }, 219 | end: { 220 | offset: endPos, 221 | line: endPosDetails.line, 222 | column: endPosDetails.column 223 | } 224 | }; 225 | } 226 | 227 | function peg$fail(expected) { 228 | if (peg$currPos < peg$maxFailPos) { return; } 229 | 230 | if (peg$currPos > peg$maxFailPos) { 231 | peg$maxFailPos = peg$currPos; 232 | peg$maxFailExpected = []; 233 | } 234 | 235 | peg$maxFailExpected.push(expected); 236 | } 237 | 238 | function peg$buildException(message, expected, found, location) { 239 | function cleanupExpected(expected) { 240 | var i = 1; 241 | 242 | expected.sort(function(a, b) { 243 | if (a.description < b.description) { 244 | return -1; 245 | } else if (a.description > b.description) { 246 | return 1; 247 | } else { 248 | return 0; 249 | } 250 | }); 251 | 252 | while (i < expected.length) { 253 | if (expected[i - 1] === expected[i]) { 254 | expected.splice(i, 1); 255 | } else { 256 | i++; 257 | } 258 | } 259 | } 260 | 261 | function buildMessage(expected, found) { 262 | function stringEscape(s) { 263 | function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); } 264 | 265 | return s 266 | .replace(/\\/g, '\\\\') 267 | .replace(/"/g, '\\"') 268 | .replace(/\x08/g, '\\b') 269 | .replace(/\t/g, '\\t') 270 | .replace(/\n/g, '\\n') 271 | .replace(/\f/g, '\\f') 272 | .replace(/\r/g, '\\r') 273 | .replace(/[\x00-\x07\x0B\x0E\x0F]/g, function(ch) { return '\\x0' + hex(ch); }) 274 | .replace(/[\x10-\x1F\x80-\xFF]/g, function(ch) { return '\\x' + hex(ch); }) 275 | .replace(/[\u0100-\u0FFF]/g, function(ch) { return '\\u0' + hex(ch); }) 276 | .replace(/[\u1000-\uFFFF]/g, function(ch) { return '\\u' + hex(ch); }); 277 | } 278 | 279 | var expectedDescs = new Array(expected.length), 280 | expectedDesc, foundDesc, i; 281 | 282 | for (i = 0; i < expected.length; i++) { 283 | expectedDescs[i] = expected[i].description; 284 | } 285 | 286 | expectedDesc = expected.length > 1 287 | ? expectedDescs.slice(0, -1).join(", ") 288 | + " or " 289 | + expectedDescs[expected.length - 1] 290 | : expectedDescs[0]; 291 | 292 | foundDesc = found ? "\"" + stringEscape(found) + "\"" : "end of input"; 293 | 294 | return "Expected " + expectedDesc + " but " + foundDesc + " found."; 295 | } 296 | 297 | if (expected !== null) { 298 | cleanupExpected(expected); 299 | } 300 | 301 | return new peg$SyntaxError( 302 | message !== null ? message : buildMessage(expected, found), 303 | expected, 304 | found, 305 | location 306 | ); 307 | } 308 | 309 | function peg$parsestart() { 310 | var s0, s1, s2, s3, s4, s5; 311 | 312 | s0 = peg$currPos; 313 | s1 = []; 314 | s2 = peg$parsenewline(); 315 | while (s2 !== peg$FAILED) { 316 | s1.push(s2); 317 | s2 = peg$parsenewline(); 318 | } 319 | if (s1 !== peg$FAILED) { 320 | s2 = peg$parsekey_group(); 321 | if (s2 !== peg$FAILED) { 322 | s3 = []; 323 | s4 = peg$parsenewline(); 324 | while (s4 !== peg$FAILED) { 325 | s3.push(s4); 326 | s4 = peg$parsenewline(); 327 | } 328 | if (s3 !== peg$FAILED) { 329 | s4 = []; 330 | s5 = peg$parseS(); 331 | while (s5 !== peg$FAILED) { 332 | s4.push(s5); 333 | s5 = peg$parseS(); 334 | } 335 | if (s4 !== peg$FAILED) { 336 | s5 = peg$parsecomment(); 337 | if (s5 === peg$FAILED) { 338 | s5 = null; 339 | } 340 | if (s5 !== peg$FAILED) { 341 | peg$savedPos = s0; 342 | s1 = peg$c0(s2); 343 | s0 = s1; 344 | } else { 345 | peg$currPos = s0; 346 | s0 = peg$FAILED; 347 | } 348 | } else { 349 | peg$currPos = s0; 350 | s0 = peg$FAILED; 351 | } 352 | } else { 353 | peg$currPos = s0; 354 | s0 = peg$FAILED; 355 | } 356 | } else { 357 | peg$currPos = s0; 358 | s0 = peg$FAILED; 359 | } 360 | } else { 361 | peg$currPos = s0; 362 | s0 = peg$FAILED; 363 | } 364 | 365 | return s0; 366 | } 367 | 368 | function peg$parsenewline() { 369 | var s0, s1, s2, s3, s4; 370 | 371 | s0 = peg$currPos; 372 | s1 = []; 373 | s2 = peg$parseS(); 374 | while (s2 !== peg$FAILED) { 375 | s1.push(s2); 376 | s2 = peg$parseS(); 377 | } 378 | if (s1 !== peg$FAILED) { 379 | s2 = peg$parsecomment(); 380 | if (s2 === peg$FAILED) { 381 | s2 = null; 382 | } 383 | if (s2 !== peg$FAILED) { 384 | s3 = []; 385 | s4 = peg$parseEOL(); 386 | if (s4 !== peg$FAILED) { 387 | while (s4 !== peg$FAILED) { 388 | s3.push(s4); 389 | s4 = peg$parseEOL(); 390 | } 391 | } else { 392 | s3 = peg$FAILED; 393 | } 394 | if (s3 !== peg$FAILED) { 395 | s1 = [s1, s2, s3]; 396 | s0 = s1; 397 | } else { 398 | peg$currPos = s0; 399 | s0 = peg$FAILED; 400 | } 401 | } else { 402 | peg$currPos = s0; 403 | s0 = peg$FAILED; 404 | } 405 | } else { 406 | peg$currPos = s0; 407 | s0 = peg$FAILED; 408 | } 409 | 410 | return s0; 411 | } 412 | 413 | function peg$parsecomment() { 414 | var s0, s1, s2, s3, s4, s5; 415 | 416 | s0 = peg$currPos; 417 | if (input.charCodeAt(peg$currPos) === 35) { 418 | s1 = peg$c1; 419 | peg$currPos++; 420 | } else { 421 | s1 = peg$FAILED; 422 | if (peg$silentFails === 0) { peg$fail(peg$c2); } 423 | } 424 | if (s1 !== peg$FAILED) { 425 | s2 = []; 426 | s3 = peg$currPos; 427 | s4 = peg$currPos; 428 | peg$silentFails++; 429 | s5 = peg$parseEOL(); 430 | peg$silentFails--; 431 | if (s5 === peg$FAILED) { 432 | s4 = void 0; 433 | } else { 434 | peg$currPos = s4; 435 | s4 = peg$FAILED; 436 | } 437 | if (s4 !== peg$FAILED) { 438 | if (input.length > peg$currPos) { 439 | s5 = input.charAt(peg$currPos); 440 | peg$currPos++; 441 | } else { 442 | s5 = peg$FAILED; 443 | if (peg$silentFails === 0) { peg$fail(peg$c3); } 444 | } 445 | if (s5 !== peg$FAILED) { 446 | s4 = [s4, s5]; 447 | s3 = s4; 448 | } else { 449 | peg$currPos = s3; 450 | s3 = peg$FAILED; 451 | } 452 | } else { 453 | peg$currPos = s3; 454 | s3 = peg$FAILED; 455 | } 456 | while (s3 !== peg$FAILED) { 457 | s2.push(s3); 458 | s3 = peg$currPos; 459 | s4 = peg$currPos; 460 | peg$silentFails++; 461 | s5 = peg$parseEOL(); 462 | peg$silentFails--; 463 | if (s5 === peg$FAILED) { 464 | s4 = void 0; 465 | } else { 466 | peg$currPos = s4; 467 | s4 = peg$FAILED; 468 | } 469 | if (s4 !== peg$FAILED) { 470 | if (input.length > peg$currPos) { 471 | s5 = input.charAt(peg$currPos); 472 | peg$currPos++; 473 | } else { 474 | s5 = peg$FAILED; 475 | if (peg$silentFails === 0) { peg$fail(peg$c3); } 476 | } 477 | if (s5 !== peg$FAILED) { 478 | s4 = [s4, s5]; 479 | s3 = s4; 480 | } else { 481 | peg$currPos = s3; 482 | s3 = peg$FAILED; 483 | } 484 | } else { 485 | peg$currPos = s3; 486 | s3 = peg$FAILED; 487 | } 488 | } 489 | if (s2 !== peg$FAILED) { 490 | s1 = [s1, s2]; 491 | s0 = s1; 492 | } else { 493 | peg$currPos = s0; 494 | s0 = peg$FAILED; 495 | } 496 | } else { 497 | peg$currPos = s0; 498 | s0 = peg$FAILED; 499 | } 500 | 501 | return s0; 502 | } 503 | 504 | function peg$parseEOL() { 505 | var s0; 506 | 507 | if (input.charCodeAt(peg$currPos) === 10) { 508 | s0 = peg$c4; 509 | peg$currPos++; 510 | } else { 511 | s0 = peg$FAILED; 512 | if (peg$silentFails === 0) { peg$fail(peg$c5); } 513 | } 514 | if (s0 === peg$FAILED) { 515 | if (input.charCodeAt(peg$currPos) === 13) { 516 | s0 = peg$c6; 517 | peg$currPos++; 518 | } else { 519 | s0 = peg$FAILED; 520 | if (peg$silentFails === 0) { peg$fail(peg$c7); } 521 | } 522 | } 523 | 524 | return s0; 525 | } 526 | 527 | function peg$parsekey_pair() { 528 | var s0, s1, s2, s3, s4; 529 | 530 | s0 = peg$currPos; 531 | s1 = peg$parsekey(); 532 | if (s1 !== peg$FAILED) { 533 | s2 = []; 534 | s3 = peg$parseS(); 535 | while (s3 !== peg$FAILED) { 536 | s2.push(s3); 537 | s3 = peg$parseS(); 538 | } 539 | if (s2 !== peg$FAILED) { 540 | if (input.charCodeAt(peg$currPos) === 58) { 541 | s3 = peg$c8; 542 | peg$currPos++; 543 | } else { 544 | s3 = peg$FAILED; 545 | if (peg$silentFails === 0) { peg$fail(peg$c9); } 546 | } 547 | if (s3 !== peg$FAILED) { 548 | s4 = peg$parsevalue(); 549 | if (s4 !== peg$FAILED) { 550 | peg$savedPos = s0; 551 | s1 = peg$c10(s1, s4); 552 | s0 = s1; 553 | } else { 554 | peg$currPos = s0; 555 | s0 = peg$FAILED; 556 | } 557 | } else { 558 | peg$currPos = s0; 559 | s0 = peg$FAILED; 560 | } 561 | } else { 562 | peg$currPos = s0; 563 | s0 = peg$FAILED; 564 | } 565 | } else { 566 | peg$currPos = s0; 567 | s0 = peg$FAILED; 568 | } 569 | 570 | return s0; 571 | } 572 | 573 | function peg$parsekey() { 574 | var s0; 575 | 576 | s0 = peg$parsealphanumeric_key(); 577 | if (s0 === peg$FAILED) { 578 | s0 = peg$parsequoted_string(); 579 | } 580 | 581 | return s0; 582 | } 583 | 584 | function peg$parsealphanumeric_key() { 585 | var s0, s1, s2; 586 | 587 | s0 = peg$currPos; 588 | s1 = []; 589 | if (peg$c11.test(input.charAt(peg$currPos))) { 590 | s2 = input.charAt(peg$currPos); 591 | peg$currPos++; 592 | } else { 593 | s2 = peg$FAILED; 594 | if (peg$silentFails === 0) { peg$fail(peg$c12); } 595 | } 596 | if (s2 !== peg$FAILED) { 597 | while (s2 !== peg$FAILED) { 598 | s1.push(s2); 599 | if (peg$c11.test(input.charAt(peg$currPos))) { 600 | s2 = input.charAt(peg$currPos); 601 | peg$currPos++; 602 | } else { 603 | s2 = peg$FAILED; 604 | if (peg$silentFails === 0) { peg$fail(peg$c12); } 605 | } 606 | } 607 | } else { 608 | s1 = peg$FAILED; 609 | } 610 | if (s1 !== peg$FAILED) { 611 | peg$savedPos = s0; 612 | s1 = peg$c13(s1); 613 | } 614 | s0 = s1; 615 | 616 | return s0; 617 | } 618 | 619 | function peg$parsequoted_string() { 620 | var s0, s1, s2, s3; 621 | 622 | s0 = peg$currPos; 623 | if (input.charCodeAt(peg$currPos) === 34) { 624 | s1 = peg$c14; 625 | peg$currPos++; 626 | } else { 627 | s1 = peg$FAILED; 628 | if (peg$silentFails === 0) { peg$fail(peg$c15); } 629 | } 630 | if (s1 !== peg$FAILED) { 631 | s2 = []; 632 | s3 = peg$parsestring_char(); 633 | while (s3 !== peg$FAILED) { 634 | s2.push(s3); 635 | s3 = peg$parsestring_char(); 636 | } 637 | if (s2 !== peg$FAILED) { 638 | if (input.charCodeAt(peg$currPos) === 34) { 639 | s3 = peg$c14; 640 | peg$currPos++; 641 | } else { 642 | s3 = peg$FAILED; 643 | if (peg$silentFails === 0) { peg$fail(peg$c15); } 644 | } 645 | if (s3 !== peg$FAILED) { 646 | peg$savedPos = s0; 647 | s1 = peg$c16(s2); 648 | s0 = s1; 649 | } else { 650 | peg$currPos = s0; 651 | s0 = peg$FAILED; 652 | } 653 | } else { 654 | peg$currPos = s0; 655 | s0 = peg$FAILED; 656 | } 657 | } else { 658 | peg$currPos = s0; 659 | s0 = peg$FAILED; 660 | } 661 | 662 | return s0; 663 | } 664 | 665 | function peg$parsestring_char() { 666 | var s0, s1, s2, s3; 667 | 668 | s0 = peg$currPos; 669 | s1 = peg$currPos; 670 | peg$silentFails++; 671 | if (input.charCodeAt(peg$currPos) === 34) { 672 | s2 = peg$c14; 673 | peg$currPos++; 674 | } else { 675 | s2 = peg$FAILED; 676 | if (peg$silentFails === 0) { peg$fail(peg$c15); } 677 | } 678 | peg$silentFails--; 679 | if (s2 === peg$FAILED) { 680 | s1 = void 0; 681 | } else { 682 | peg$currPos = s1; 683 | s1 = peg$FAILED; 684 | } 685 | if (s1 !== peg$FAILED) { 686 | s2 = peg$currPos; 687 | peg$silentFails++; 688 | s3 = peg$parseEOL(); 689 | peg$silentFails--; 690 | if (s3 === peg$FAILED) { 691 | s2 = void 0; 692 | } else { 693 | peg$currPos = s2; 694 | s2 = peg$FAILED; 695 | } 696 | if (s2 !== peg$FAILED) { 697 | s3 = peg$parseescaped_character(); 698 | if (s3 !== peg$FAILED) { 699 | peg$savedPos = s0; 700 | s1 = peg$c17(s3); 701 | s0 = s1; 702 | } else { 703 | peg$currPos = s0; 704 | s0 = peg$FAILED; 705 | } 706 | } else { 707 | peg$currPos = s0; 708 | s0 = peg$FAILED; 709 | } 710 | } else { 711 | peg$currPos = s0; 712 | s0 = peg$FAILED; 713 | } 714 | 715 | return s0; 716 | } 717 | 718 | function peg$parsevalue() { 719 | var s0; 720 | 721 | s0 = peg$parseindented_value(); 722 | if (s0 === peg$FAILED) { 723 | s0 = peg$parseunquoted_string(); 724 | if (s0 === peg$FAILED) { 725 | s0 = peg$parsequoted_string(); 726 | } 727 | } 728 | 729 | return s0; 730 | } 731 | 732 | function peg$parseindented_value() { 733 | var s0, s1, s2, s3; 734 | 735 | s0 = peg$currPos; 736 | s1 = peg$parseindent(); 737 | if (s1 !== peg$FAILED) { 738 | s2 = peg$parseindented_value_content(); 739 | if (s2 !== peg$FAILED) { 740 | s3 = peg$parseoutdent(); 741 | if (s3 !== peg$FAILED) { 742 | peg$savedPos = s0; 743 | s1 = peg$c18(s2); 744 | s0 = s1; 745 | } else { 746 | peg$currPos = s0; 747 | s0 = peg$FAILED; 748 | } 749 | } else { 750 | peg$currPos = s0; 751 | s0 = peg$FAILED; 752 | } 753 | } else { 754 | peg$currPos = s0; 755 | s0 = peg$FAILED; 756 | } 757 | 758 | return s0; 759 | } 760 | 761 | function peg$parseindented_value_content() { 762 | var s0, s1; 763 | 764 | s0 = peg$currPos; 765 | s1 = peg$parsekey_group(); 766 | if (s1 !== peg$FAILED) { 767 | peg$savedPos = s0; 768 | s1 = peg$c0(s1); 769 | } 770 | s0 = s1; 771 | if (s0 === peg$FAILED) { 772 | s0 = peg$parseblock_string(); 773 | } 774 | 775 | return s0; 776 | } 777 | 778 | function peg$parsekey_group() { 779 | var s0, s1, s2, s3; 780 | 781 | s0 = peg$currPos; 782 | s1 = peg$parsekey_pair(); 783 | if (s1 !== peg$FAILED) { 784 | s2 = []; 785 | s3 = peg$parsekey_group_continuation(); 786 | while (s3 !== peg$FAILED) { 787 | s2.push(s3); 788 | s3 = peg$parsekey_group_continuation(); 789 | } 790 | if (s2 !== peg$FAILED) { 791 | peg$savedPos = s0; 792 | s1 = peg$c19(s1, s2); 793 | s0 = s1; 794 | } else { 795 | peg$currPos = s0; 796 | s0 = peg$FAILED; 797 | } 798 | } else { 799 | peg$currPos = s0; 800 | s0 = peg$FAILED; 801 | } 802 | 803 | return s0; 804 | } 805 | 806 | function peg$parsekey_group_continuation() { 807 | var s0, s1, s2; 808 | 809 | s0 = peg$currPos; 810 | s1 = peg$parsesamedent(); 811 | if (s1 !== peg$FAILED) { 812 | s2 = peg$parsekey_pair(); 813 | if (s2 !== peg$FAILED) { 814 | peg$savedPos = s0; 815 | s1 = peg$c20(s2); 816 | s0 = s1; 817 | } else { 818 | peg$currPos = s0; 819 | s0 = peg$FAILED; 820 | } 821 | } else { 822 | peg$currPos = s0; 823 | s0 = peg$FAILED; 824 | } 825 | 826 | return s0; 827 | } 828 | 829 | function peg$parseunquoted_string() { 830 | var s0, s1, s2, s3, s4; 831 | 832 | s0 = peg$currPos; 833 | s1 = []; 834 | s2 = peg$parseS(); 835 | while (s2 !== peg$FAILED) { 836 | s1.push(s2); 837 | s2 = peg$parseS(); 838 | } 839 | if (s1 !== peg$FAILED) { 840 | s2 = []; 841 | s3 = peg$parseunquoted_char(); 842 | while (s3 !== peg$FAILED) { 843 | s2.push(s3); 844 | s3 = peg$parseunquoted_char(); 845 | } 846 | if (s2 !== peg$FAILED) { 847 | s3 = []; 848 | s4 = peg$parseS(); 849 | while (s4 !== peg$FAILED) { 850 | s3.push(s4); 851 | s4 = peg$parseS(); 852 | } 853 | if (s3 !== peg$FAILED) { 854 | peg$savedPos = s0; 855 | s1 = peg$c16(s2); 856 | s0 = s1; 857 | } else { 858 | peg$currPos = s0; 859 | s0 = peg$FAILED; 860 | } 861 | } else { 862 | peg$currPos = s0; 863 | s0 = peg$FAILED; 864 | } 865 | } else { 866 | peg$currPos = s0; 867 | s0 = peg$FAILED; 868 | } 869 | 870 | return s0; 871 | } 872 | 873 | function peg$parseunquoted_char() { 874 | var s0, s1, s2; 875 | 876 | s0 = peg$currPos; 877 | s1 = peg$currPos; 878 | peg$silentFails++; 879 | s2 = peg$parseEOL(); 880 | peg$silentFails--; 881 | if (s2 === peg$FAILED) { 882 | s1 = void 0; 883 | } else { 884 | peg$currPos = s1; 885 | s1 = peg$FAILED; 886 | } 887 | if (s1 !== peg$FAILED) { 888 | s2 = peg$parseescaped_character(); 889 | if (s2 !== peg$FAILED) { 890 | peg$savedPos = s0; 891 | s1 = peg$c17(s2); 892 | s0 = s1; 893 | } else { 894 | peg$currPos = s0; 895 | s0 = peg$FAILED; 896 | } 897 | } else { 898 | peg$currPos = s0; 899 | s0 = peg$FAILED; 900 | } 901 | 902 | return s0; 903 | } 904 | 905 | function peg$parseblock_string() { 906 | var s0, s1, s2, s3; 907 | 908 | s0 = peg$currPos; 909 | s1 = peg$parseunquoted_string(); 910 | if (s1 !== peg$FAILED) { 911 | s2 = []; 912 | s3 = peg$parseblock_string_continuation(); 913 | while (s3 !== peg$FAILED) { 914 | s2.push(s3); 915 | s3 = peg$parseblock_string_continuation(); 916 | } 917 | if (s2 !== peg$FAILED) { 918 | peg$savedPos = s0; 919 | s1 = peg$c21(s1, s2); 920 | s0 = s1; 921 | } else { 922 | peg$currPos = s0; 923 | s0 = peg$FAILED; 924 | } 925 | } else { 926 | peg$currPos = s0; 927 | s0 = peg$FAILED; 928 | } 929 | 930 | return s0; 931 | } 932 | 933 | function peg$parseblock_string_continuation() { 934 | var s0, s1, s2; 935 | 936 | s0 = peg$currPos; 937 | s1 = peg$parsesamedent(); 938 | if (s1 !== peg$FAILED) { 939 | s2 = peg$parseunquoted_string(); 940 | if (s2 !== peg$FAILED) { 941 | peg$savedPos = s0; 942 | s1 = peg$c22(s2); 943 | s0 = s1; 944 | } else { 945 | peg$currPos = s0; 946 | s0 = peg$FAILED; 947 | } 948 | } else { 949 | peg$currPos = s0; 950 | s0 = peg$FAILED; 951 | } 952 | 953 | return s0; 954 | } 955 | 956 | function peg$parseescaped_character() { 957 | var s0, s1; 958 | 959 | s0 = peg$currPos; 960 | if (input.substr(peg$currPos, 9) === peg$c23) { 961 | s1 = peg$c23; 962 | peg$currPos += 9; 963 | } else { 964 | s1 = peg$FAILED; 965 | if (peg$silentFails === 0) { peg$fail(peg$c24); } 966 | } 967 | if (s1 !== peg$FAILED) { 968 | peg$savedPos = s0; 969 | s1 = peg$c25(); 970 | } 971 | s0 = s1; 972 | if (s0 === peg$FAILED) { 973 | s0 = peg$currPos; 974 | if (input.substr(peg$currPos, 8) === peg$c26) { 975 | s1 = peg$c26; 976 | peg$currPos += 8; 977 | } else { 978 | s1 = peg$FAILED; 979 | if (peg$silentFails === 0) { peg$fail(peg$c27); } 980 | } 981 | if (s1 !== peg$FAILED) { 982 | peg$savedPos = s0; 983 | s1 = peg$c28(); 984 | } 985 | s0 = s1; 986 | if (s0 === peg$FAILED) { 987 | s0 = peg$currPos; 988 | if (input.substr(peg$currPos, 5) === peg$c29) { 989 | s1 = peg$c29; 990 | peg$currPos += 5; 991 | } else { 992 | s1 = peg$FAILED; 993 | if (peg$silentFails === 0) { peg$fail(peg$c30); } 994 | } 995 | if (s1 !== peg$FAILED) { 996 | peg$savedPos = s0; 997 | s1 = peg$c31(); 998 | } 999 | s0 = s1; 1000 | if (s0 === peg$FAILED) { 1001 | s0 = peg$currPos; 1002 | if (input.substr(peg$currPos, 6) === peg$c32) { 1003 | s1 = peg$c32; 1004 | peg$currPos += 6; 1005 | } else { 1006 | s1 = peg$FAILED; 1007 | if (peg$silentFails === 0) { peg$fail(peg$c33); } 1008 | } 1009 | if (s1 !== peg$FAILED) { 1010 | peg$savedPos = s0; 1011 | s1 = peg$c34(); 1012 | } 1013 | s0 = s1; 1014 | if (s0 === peg$FAILED) { 1015 | s0 = peg$currPos; 1016 | if (input.substr(peg$currPos, 6) === peg$c35) { 1017 | s1 = peg$c35; 1018 | peg$currPos += 6; 1019 | } else { 1020 | s1 = peg$FAILED; 1021 | if (peg$silentFails === 0) { peg$fail(peg$c36); } 1022 | } 1023 | if (s1 !== peg$FAILED) { 1024 | peg$savedPos = s0; 1025 | s1 = peg$c37(); 1026 | } 1027 | s0 = s1; 1028 | if (s0 === peg$FAILED) { 1029 | s0 = peg$currPos; 1030 | if (input.substr(peg$currPos, 5) === peg$c38) { 1031 | s1 = peg$c38; 1032 | peg$currPos += 5; 1033 | } else { 1034 | s1 = peg$FAILED; 1035 | if (peg$silentFails === 0) { peg$fail(peg$c39); } 1036 | } 1037 | if (s1 !== peg$FAILED) { 1038 | peg$savedPos = s0; 1039 | s1 = peg$c40(); 1040 | } 1041 | s0 = s1; 1042 | if (s0 === peg$FAILED) { 1043 | s0 = peg$currPos; 1044 | if (input.substr(peg$currPos, 7) === peg$c41) { 1045 | s1 = peg$c41; 1046 | peg$currPos += 7; 1047 | } else { 1048 | s1 = peg$FAILED; 1049 | if (peg$silentFails === 0) { peg$fail(peg$c42); } 1050 | } 1051 | if (s1 !== peg$FAILED) { 1052 | peg$savedPos = s0; 1053 | s1 = peg$c43(); 1054 | } 1055 | s0 = s1; 1056 | if (s0 === peg$FAILED) { 1057 | s0 = peg$currPos; 1058 | if (input.substr(peg$currPos, 7) === peg$c44) { 1059 | s1 = peg$c44; 1060 | peg$currPos += 7; 1061 | } else { 1062 | s1 = peg$FAILED; 1063 | if (peg$silentFails === 0) { peg$fail(peg$c45); } 1064 | } 1065 | if (s1 !== peg$FAILED) { 1066 | peg$savedPos = s0; 1067 | s1 = peg$c46(); 1068 | } 1069 | s0 = s1; 1070 | if (s0 === peg$FAILED) { 1071 | s0 = peg$currPos; 1072 | if (input.substr(peg$currPos, 6) === peg$c47) { 1073 | s1 = peg$c47; 1074 | peg$currPos += 6; 1075 | } else { 1076 | s1 = peg$FAILED; 1077 | if (peg$silentFails === 0) { peg$fail(peg$c48); } 1078 | } 1079 | if (s1 !== peg$FAILED) { 1080 | peg$savedPos = s0; 1081 | s1 = peg$c49(); 1082 | } 1083 | s0 = s1; 1084 | if (s0 === peg$FAILED) { 1085 | if (input.length > peg$currPos) { 1086 | s0 = input.charAt(peg$currPos); 1087 | peg$currPos++; 1088 | } else { 1089 | s0 = peg$FAILED; 1090 | if (peg$silentFails === 0) { peg$fail(peg$c3); } 1091 | } 1092 | } 1093 | } 1094 | } 1095 | } 1096 | } 1097 | } 1098 | } 1099 | } 1100 | } 1101 | 1102 | return s0; 1103 | } 1104 | 1105 | function peg$parseS() { 1106 | var s0; 1107 | 1108 | if (input.charCodeAt(peg$currPos) === 32) { 1109 | s0 = peg$c50; 1110 | peg$currPos++; 1111 | } else { 1112 | s0 = peg$FAILED; 1113 | if (peg$silentFails === 0) { peg$fail(peg$c51); } 1114 | } 1115 | if (s0 === peg$FAILED) { 1116 | if (input.charCodeAt(peg$currPos) === 9) { 1117 | s0 = peg$c52; 1118 | peg$currPos++; 1119 | } else { 1120 | s0 = peg$FAILED; 1121 | if (peg$silentFails === 0) { peg$fail(peg$c53); } 1122 | } 1123 | } 1124 | 1125 | return s0; 1126 | } 1127 | 1128 | function peg$parseindent() { 1129 | var s0, s1, s2, s3; 1130 | 1131 | s0 = peg$currPos; 1132 | s1 = []; 1133 | s2 = peg$parsenewline(); 1134 | if (s2 !== peg$FAILED) { 1135 | while (s2 !== peg$FAILED) { 1136 | s1.push(s2); 1137 | s2 = peg$parsenewline(); 1138 | } 1139 | } else { 1140 | s1 = peg$FAILED; 1141 | } 1142 | if (s1 !== peg$FAILED) { 1143 | s2 = peg$parsecount_space(); 1144 | if (s2 !== peg$FAILED) { 1145 | peg$savedPos = peg$currPos; 1146 | s3 = peg$c54(s2); 1147 | if (s3) { 1148 | s3 = void 0; 1149 | } else { 1150 | s3 = peg$FAILED; 1151 | } 1152 | if (s3 !== peg$FAILED) { 1153 | peg$savedPos = s0; 1154 | s1 = peg$c55(s2); 1155 | s0 = s1; 1156 | } else { 1157 | peg$currPos = s0; 1158 | s0 = peg$FAILED; 1159 | } 1160 | } else { 1161 | peg$currPos = s0; 1162 | s0 = peg$FAILED; 1163 | } 1164 | } else { 1165 | peg$currPos = s0; 1166 | s0 = peg$FAILED; 1167 | } 1168 | 1169 | return s0; 1170 | } 1171 | 1172 | function peg$parsesamedent() { 1173 | var s0, s1, s2, s3; 1174 | 1175 | s0 = peg$currPos; 1176 | s1 = []; 1177 | s2 = peg$parsenewline(); 1178 | if (s2 !== peg$FAILED) { 1179 | while (s2 !== peg$FAILED) { 1180 | s1.push(s2); 1181 | s2 = peg$parsenewline(); 1182 | } 1183 | } else { 1184 | s1 = peg$FAILED; 1185 | } 1186 | if (s1 !== peg$FAILED) { 1187 | s2 = peg$parsecount_space(); 1188 | if (s2 !== peg$FAILED) { 1189 | peg$savedPos = peg$currPos; 1190 | s3 = peg$c56(s2); 1191 | if (s3) { 1192 | s3 = void 0; 1193 | } else { 1194 | s3 = peg$FAILED; 1195 | } 1196 | if (s3 !== peg$FAILED) { 1197 | s1 = [s1, s2, s3]; 1198 | s0 = s1; 1199 | } else { 1200 | peg$currPos = s0; 1201 | s0 = peg$FAILED; 1202 | } 1203 | } else { 1204 | peg$currPos = s0; 1205 | s0 = peg$FAILED; 1206 | } 1207 | } else { 1208 | peg$currPos = s0; 1209 | s0 = peg$FAILED; 1210 | } 1211 | 1212 | return s0; 1213 | } 1214 | 1215 | function peg$parseoutdent() { 1216 | var s0, s1; 1217 | 1218 | s0 = peg$currPos; 1219 | s1 = peg$c57; 1220 | if (s1 !== peg$FAILED) { 1221 | peg$savedPos = s0; 1222 | s1 = peg$c58(); 1223 | } 1224 | s0 = s1; 1225 | 1226 | return s0; 1227 | } 1228 | 1229 | function peg$parsecount_space() { 1230 | var s0, s1, s2; 1231 | 1232 | s0 = peg$currPos; 1233 | s1 = []; 1234 | s2 = peg$parseS(); 1235 | while (s2 !== peg$FAILED) { 1236 | s1.push(s2); 1237 | s2 = peg$parseS(); 1238 | } 1239 | if (s1 !== peg$FAILED) { 1240 | peg$savedPos = s0; 1241 | s1 = peg$c59(s1); 1242 | } 1243 | s0 = s1; 1244 | 1245 | return s0; 1246 | } 1247 | 1248 | 1249 | 1250 | var INDENT = [0]; 1251 | 1252 | INDENT.top = function () { 1253 | return this[this.length - 1]; 1254 | } 1255 | 1256 | function formatGroups(g) { 1257 | 1258 | var result = {}; 1259 | 1260 | g.forEach(function (i) { 1261 | if (result[i.key]) { 1262 | throw "Line: " + i.line + ", Col: " + i.col + ". Repeated key: " + i.key; 1263 | } 1264 | result[i.key] = i.value; 1265 | }); 1266 | return result; 1267 | } 1268 | 1269 | 1270 | 1271 | 1272 | peg$result = peg$startRuleFunction(); 1273 | 1274 | if (peg$result !== peg$FAILED && peg$currPos === input.length) { 1275 | return peg$result; 1276 | } else { 1277 | if (peg$result !== peg$FAILED && peg$currPos < input.length) { 1278 | peg$fail({ type: "end", description: "end of input" }); 1279 | } 1280 | 1281 | throw peg$buildException( 1282 | null, 1283 | peg$maxFailExpected, 1284 | peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null, 1285 | peg$maxFailPos < input.length 1286 | ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1) 1287 | : peg$computeLocation(peg$maxFailPos, peg$maxFailPos) 1288 | ); 1289 | } 1290 | } 1291 | 1292 | return { 1293 | SyntaxError: peg$SyntaxError, 1294 | parse: peg$parse 1295 | }; 1296 | })(); 1297 | 1298 | I18n._languages = [] 1299 | 1300 | // The rest of the library 1301 | 1302 | Object.defineProperty(I18n, 'language', { 1303 | get: function () { 1304 | return this._language; 1305 | }, 1306 | set: function (value) { 1307 | if (value !== this._language) { 1308 | this._loadLanguage(value); 1309 | } 1310 | } 1311 | }); 1312 | 1313 | I18n._loadLanguage = function (name) { 1314 | if (this._languages[name]) { 1315 | this._setupLanguage(name); 1316 | } 1317 | this._translating = true; 1318 | var xhr = new XMLHttpRequest(); 1319 | var url = 'data/' + src; 1320 | xhr.open('GET', 'data/i18n/' + name); 1321 | xhr.onload = function() { 1322 | this._translating = false; 1323 | if (xhr.status < 400) { 1324 | I18n._onLoad(name, I18n.parse(xhr.responseText)); 1325 | } 1326 | }; 1327 | } 1328 | 1329 | I18n._onLoad = function (language, data) { 1330 | this._languages[name] = data; 1331 | this._setupLanguage(name); 1332 | } 1333 | 1334 | I18n._setupLanguage = function (language) { 1335 | this._language = language; 1336 | 1337 | } 1338 | 1339 | I18n._textFile = null; 1340 | 1341 | I18n.dump = function () { 1342 | var text = this._generateDumpText(); 1343 | var data = new Blob([text], {type: 'text/plain'}); 1344 | if (this._textFile !== null) { 1345 | window.URL.revokeObjectURL(this._textFile); 1346 | } 1347 | this._textFile = window.URL.createObjectURL(data); 1348 | this._download(); 1349 | } 1350 | 1351 | I18n._generateDumpText = function () { 1352 | var data = this._readData(); 1353 | var result = this._formatData(data); 1354 | return result; 1355 | } 1356 | 1357 | I18n._download = function () { 1358 | var downloadLink = document.createElement("a"); 1359 | downloadLink.download = 'text.yaml'; 1360 | downloadLink.href = this._textFile; 1361 | downloadLink.target = '_blank'; 1362 | downloadLink.click(); 1363 | } 1364 | 1365 | I18n._readData = function () { 1366 | var result = {}; 1367 | var files = DataManager._databaseFile; 1368 | this._readActors(result); 1369 | this._readClasses(result); 1370 | this._readSkills(result); 1371 | this._readItems(result); 1372 | this._readWeapons(result); 1373 | this._readArmors(result); 1374 | this._readEnemies(result); 1375 | this._readTroops(result); 1376 | this._readStates(result); 1377 | this._readTilesets(result); 1378 | this._readCommonEvents(result); 1379 | this._readSystem(result); 1380 | this._readTypes(result); 1381 | this._readTerms(result); 1382 | return result; 1383 | } 1384 | 1385 | I18n._readActors = function (result) { 1386 | result['actors'] = {}; 1387 | $dataActors.forEach(function (i) { 1388 | if (i) { 1389 | result['actors'][i.id] = { 1390 | name: i.name, 1391 | nickname: i.nickname, 1392 | profile: i.profile, 1393 | note: i.note 1394 | }; 1395 | } 1396 | }); 1397 | } 1398 | 1399 | I18n._readClasses = function (result) { 1400 | result['classes'] = {}; 1401 | $dataClasses.forEach(function (i) { 1402 | if (i) { 1403 | result['classes'][i.id] = { name: i.name, note: i.note }; 1404 | } 1405 | }); 1406 | } 1407 | 1408 | I18n._readSkills = function (result) { 1409 | result['skills'] = {}; 1410 | $dataSkills.forEach(function (i) { 1411 | if (i) { 1412 | result['skills'][i.id] = { 1413 | name: i.name, 1414 | description: i.description, 1415 | note: i.note, 1416 | message1: i.message1, 1417 | message2: i.message2 1418 | }; 1419 | } 1420 | }); 1421 | } 1422 | 1423 | I18n._readItems = function (result) { 1424 | result['items'] = {}; 1425 | $dataItems.forEach(function (i) { 1426 | if (i) { 1427 | result['items'][i.id] = { 1428 | name: i.name, 1429 | description: i.description, 1430 | note: i.note 1431 | }; 1432 | } 1433 | }); 1434 | } 1435 | 1436 | I18n._readWeapons = function (result) { 1437 | result['weapons'] = {}; 1438 | $dataWeapons.forEach(function (i) { 1439 | if (i) { 1440 | result['weapons'][i.id] = { 1441 | name: i.name, 1442 | description: i.description, 1443 | note: i.note 1444 | }; 1445 | } 1446 | }); 1447 | } 1448 | 1449 | I18n._readArmors = function (result) { 1450 | result['armors'] = {}; 1451 | $dataArmors.forEach(function (i) { 1452 | if (i) { 1453 | result['armors'][i.id] = { 1454 | name: i.name, 1455 | description: i.description, 1456 | note: i.note 1457 | }; 1458 | } 1459 | }); 1460 | } 1461 | 1462 | I18n._readEnemies = function (result) { 1463 | result['enemies'] = {}; 1464 | $dataEnemies.forEach(function (i) { 1465 | if (i) { 1466 | result['enemies'][i.id] = { 1467 | name: i.name, 1468 | note: i.note 1469 | }; 1470 | } 1471 | }); 1472 | } 1473 | 1474 | I18n._readTroops = function (result) { 1475 | var troops = {}; 1476 | $dataTroops.forEach(function (i) { 1477 | if (i) { 1478 | var pages = I18n._readAllEventPages(i.pages); 1479 | if (pages.length > 0) { 1480 | troops[i.id] = pages; 1481 | } 1482 | } 1483 | }); 1484 | if (Object.keys(troops).length > 0) { 1485 | result['troops'] = troops; 1486 | } 1487 | } 1488 | 1489 | I18n._readStates = function (result) { 1490 | result['states'] = {}; 1491 | $dataStates.forEach(function (i) { 1492 | if (i) { 1493 | result['states'][i.id] = { 1494 | name: i.name, 1495 | note: i.note, 1496 | message1: i.message1, 1497 | message2: i.message2, 1498 | message3: i.message3, 1499 | message4: i.message4 1500 | }; 1501 | } 1502 | }); 1503 | } 1504 | 1505 | I18n._readTilesets = function (result) { 1506 | result['tilesets'] = {}; 1507 | $dataTilesets.forEach(function (i) { 1508 | if (i) { 1509 | result['tilesets'][i.id] = { 1510 | note: i.note 1511 | }; 1512 | } 1513 | }); 1514 | } 1515 | 1516 | I18n._readCommonEvents = function (result) { 1517 | commonEvents = {}; 1518 | $dataCommonEvents.forEach(function (i) { 1519 | if (i) { 1520 | process = I18n._readEventPage(i.list); 1521 | if (process.length > 0) { 1522 | commonEvents[i.id] = process; 1523 | } 1524 | } 1525 | }); 1526 | if (Object.keys(commonEvents).length > 0) { 1527 | result['commonEvents'] = commonEvents; 1528 | } 1529 | } 1530 | 1531 | I18n._readAllEventPages = function (pages) { 1532 | var result = []; 1533 | pages.forEach(function (i, index) { 1534 | var process = I18n._readEventPage(i.list); 1535 | console.log(i.list); 1536 | if (process.length > 0) { 1537 | result[index] = process; 1538 | } 1539 | }); 1540 | return result; 1541 | } 1542 | 1543 | I18n._readEventPage = function (list) { 1544 | var result = []; 1545 | list.forEach(function (i, index) { 1546 | switch (i.code) { 1547 | case 401: 1548 | result[index] = i.parameters; 1549 | break; 1550 | case 102: 1551 | result[index] = i.parameters[0]; 1552 | break; 1553 | case 402: 1554 | result[index] = i.parameters[1]; 1555 | break; 1556 | case 405: 1557 | result[index] = i.parameters; 1558 | break; 1559 | case 320: 1560 | result[index] = i.parameters[1]; 1561 | break; 1562 | case 324: 1563 | result[index] = i.parameters[1]; 1564 | break; 1565 | case 325: 1566 | result[index] = i.parameters[1]; 1567 | break; 1568 | case 355: 1569 | result[index] = i.parameters; 1570 | break; 1571 | case 356: 1572 | result[index] = i.parameters; 1573 | break; 1574 | default: 1575 | break; 1576 | } 1577 | }); 1578 | return result; 1579 | } 1580 | 1581 | I18n._readSystem = function (result) { 1582 | result['system'] = { 1583 | currencyUnit: $dataSystem.currencyUnit, 1584 | gameTitle: $dataSystem.gameTitle, 1585 | locale: $dataSystem.locale 1586 | }; 1587 | } 1588 | 1589 | I18n._readTypes = function (result) { 1590 | result['types'] = { 1591 | armorTypes: $dataSystem.armorTypes, 1592 | elements: $dataSystem.elements, 1593 | equipTypes: $dataSystem.equipTypes, 1594 | weaponTypes: $dataSystem.weaponTypes, 1595 | skillTypes: $dataSystem.skillTypes 1596 | }; 1597 | } 1598 | 1599 | I18n._readTerms = function (result) { 1600 | result['terms'] = $dataSystem.terms; 1601 | } 1602 | 1603 | 1604 | I18n._formatData = function (data) { 1605 | return this._makeData(0, data); 1606 | } 1607 | 1608 | I18n._makeData = function (indent, data) { 1609 | if (typeof data == 'string') { 1610 | return this._makeStringData(indent, data); 1611 | } 1612 | return this._makeObjectData(indent, data); 1613 | } 1614 | 1615 | I18n._makeStringData = function (indent, data) { 1616 | var arr = data.split('\n'); 1617 | if (arr.length == 1) { 1618 | return '"' + data.replace(/"/g, '"e;') + '"'; 1619 | } 1620 | var s = this._makeIndent(indent); 1621 | var val = arr.map(function (i) { 1622 | if (i.charAt(0) == ' ') { 1623 | i = i.replace(' ', '&space;'); 1624 | } 1625 | if (i.charAt(0) == '\t') { 1626 | i = i.replace('\t', '&tab;'); 1627 | } 1628 | return s + i; 1629 | }).join('\n'); 1630 | return '\n' + val; 1631 | } 1632 | 1633 | I18n._makeObjectData = function (indent, data) { 1634 | if (!data || Object.keys(data).length == 0) { 1635 | return '""'; 1636 | } 1637 | var s = this._makeIndent(indent); 1638 | var lines = []; 1639 | for (var p in data) { 1640 | if (typeof data[p] !== 'function') { 1641 | var sd = this._makeData(indent + 1, data[p]); 1642 | lines.push( '\n' + s + '"' + p.replace(/"/g, '"e;') + '":' + sd); 1643 | } 1644 | } 1645 | return lines.join(''); 1646 | } 1647 | 1648 | I18n._makeIndent = function (indent) { 1649 | var result = ''; 1650 | for (var i = 0; i < indent; ++i) { 1651 | result += ' '; 1652 | } 1653 | return result; 1654 | } 1655 | --------------------------------------------------------------------------------