Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============================================================================
- // SilvMinimap.js
- // Version: 1.03a
- // Requires plugin: SilvKeys (place this one below it)
- //=============================================================================
- /*:
- * @plugindesc v1.03a Minimap. <SilvMinimap>
- * @author Silver
- * @param -- General --
- *
- * @param Map Style
- * @desc Is the minimap scaled to fit? Or does it zoom and scroll? Autofit/Scroll
- * @default Scroll
- *
- * @param Global Map Zoom
- * @desc Only applies if MapStyle is set to: Scroll. Determines the default zoom level for all maps. A value of 1 means 1:1.
- * @default 0.25
- *
- * @param Render Player Blip
- * @desc Render the player blip in the minimap (=usually the center icon)? true/false
- * @default true
- *
- * @param Player Blip Graphic
- * @desc Name of the image (in /img/minimap/) to use as the blip. or use :player to use the realtime-player-graphic.
- * @default :player
- *
- * @param Minimap Opacity
- * @desc 0 = invisible, 255 = fully opaque.
- * @default 255
- *
- * @param -- Positioning & Size --
- *
- * @param X
- * @desc x-location of minimap window. If window-alignment is set to Right, this will act as an offset value instead
- * @default -2
- *
- * @param Y
- * @desc y-location of minimap window. If window-alignment is set to Top, this will act as an offset value instead
- * @default 2
- *
- * @param Horizontal Alignment
- * @desc Left/Right
- * @default Right
- *
- * @param Vertical Alignment
- * @desc Top/Bottom
- * @default Bottom
- *
- * @param Width
- * @desc width of the minimap
- * @default 320
- *
- * @param Height
- * @desc height of the minimap
- * @default 320
- *
- * @param Border Width
- * @desc Border width of the minimap
- * @default 12
- *
- * @param Border Height
- * @desc Border height of the minimap
- * @default 12
- *
- * @param -- Menu --
- *
- * @param Menu Key
- * @desc The key used to show the map-menu. Use none to disable.
- * @default m
- *
- * @param Menu Player Description
- * @desc The description of the player marker in the menu. Spaces are allowed.
- * @default You
- *
- * @param Menu Zoom
- * @desc Map Zoomlevel for the menu
- * @default 0.3. A value of 1 means 1:1
- *
- * @param Menu Left Window Width
- * @desc Width of the left window
- * @default 240
- *
- * @param Menu Topright Window Height
- * @desc Height of the topright window
- * @default 510
- *
- * @param Menu Event Render Size
- * @desc How big the events are that are drawn onto the menu map
- * @default 24
- *
- * @param Menu Player Icon Size
- * @desc How big the player is drawn onto the menu map
- * @default 64
- *
- * @param Menu Min Manual Zoom
- * @desc How far the player can zoom out
- * @default 0.20
- *
- * @param Menu Max Manual Zoom
- * @desc How far the player can zoom in
- * @default 10.0
- *
- * @param Menu Zoomin Key
- * @desc Key for zooming in. 33 = pageup
- * @default pageup
- *
- * @param Menu Zoomout Key
- * @desc Key for zooming out. 34 = pagedown
- * @default pagedown
- *
- * @param Menu Reset Zoom Key
- * @desc Key for resetting the zoom. 36 = home
- * @default home
- *
- * @param Menu Reset Scroll Key
- * @desc Key to reset the mapscroll
- * @default end
- *
- * @param -- Passability Map --
- *
- * @param Passability Overlay Opacity
- * @desc 0 = invisible, 255 = fully opaque. 0-255
- * @default 128
- *
- * @param Passability Color
- * @desc Color for walkable tiles
- * @default #6B8E23
- *
- * @param Impassability Color
- * @desc Color for unwalkable tiles
- * @default #FF0000
- *
- * @param -- Map Generator --
- *
- * @param Map Gen Tag Colors
- * @desc 0-7, use a ####### value to ignore that terrain-tag. Default: lightgreen, blue, brown, darkgreen, lightbrown
- * @default #6B8E23 #00008B #8B4513 #006400 #F4A460 ####### ####### #######
- *
- * @param Overworld Gen Tag Colors
- * @desc 0-7, use a ####### value to ignore that terrain-tag. Default: lightgreen, blue, brown, darkgreen, lightbrown
- * @default #6B8E23 #00008B #8B4513 #006400 #F4A460 ####### ####### #######
- *
- * @param -- The rest --
- *
- * @param Allow Teleportation
- * @desc By default, allow teleportation to events/poi's that support it? true/false
- * @default true
- *
- * @param Standard Padding
- * @desc Standard Window Padding. Best to leave at 0
- * @default 0
- *
- * @param Window Skin
- * @desc Name of the window skin to use for this window
- * @default Window_Minimap
- *
- * @param Player Icon Width
- * @desc Standard Window Padding
- * @default 16
- *
- * @param Player Icon Height
- * @desc Standard Window Padding
- * @default 16
- *
- * @param Draw Player Icon
- * @desc Draw player on the map? true/false
- * @default true
- *
- * @param Player Blink Delay
- * @desc Blinks the player icon (in frames). Set to 0 to disable. Does nothing if "Draw Player Icon" is set to false
- * @default 0
- *
- * @param Fill Color
- * @desc Color to fill the background of the minimap with for 'odd aspect ratios'. Use 0 0 0 0 to disable. R G B A.
- * @default 0 0 0 255
- *
- * @param Maintain Aspect Ratio
- * @desc Maintains minimap aspect ratio if set to true. true/false
- * @default true
- *
- * @param Fadeout Speed
- * @desc How fast the minimap fades out
- * @default 3
- *
- * @param Global Required Item
- * @desc Item ID of the item that the player must have in their INVENTORY for any map to be displayed. Requires map to be reloaded if item is acquired or call the plugin command "Minimap Refresh" (w/o quotes). A value of 0 disables this
- * @default 0
- *
- * @param Event Render Size
- * @desc How big the events are that are drawn onto the minimap
- * @default 16
- *
- * @param Auto Clear POI
- * @desc Automatically clear POI's between map transfers? true/false
- * @default false
- *
- * @param Render Minimap Overlay
- * @desc If enabled, add the image: /img/Minimap/Overlay.png and it will be drawn on top of the minimap. true/false
- * @default true
- *
- * @param -- Manual Scrolling --
- *
- * @param Allow Manual Scrolling
- * @desc true/false
- * @default true
- *
- * @param Manual Scrollspeed
- * @desc How fast the map is scrolled
- * @default 24
- *
- * @param Manual Scroll Key Up
- * @desc Key for scrolling the map upwards. Default: u http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
- * @default u
- *
- * @param Manual Scroll Key Right
- * @desc Key for scrolling the map upwards. Default: k
- * @default k
- *
- * @param Manual Scroll Key Down
- * @desc Key for scrolling the map upwards. Default: j
- * @default j
- *
- * @param Manual Scroll Key Left
- * @desc Key for scrolling the map upwards. Default: h
- * @default h
- *
- * @param -- Advanced & Debug --
- *
- * @param Player Sprite Sourceframe Width
- * @desc Width of the playersprite sourceframe
- * @default 48
- *
- * @param Player Sprite Sourceframe Height
- * @desc Heigth of the playersprite sourceframe
- * @default 48
- *
- * @param Frame Skip
- * @desc Skips some minimap calculations&rendering if set to value > 0 to safe performance. The value equals the amount of frames skipped.
- * @default 0
- *
- * @param Mapshot Filename Length
- * @desc Length of the mapshot filenames. A value of 3 would equal to: 001.png, 002.png, 016.png, etc. And a value of 2 would equal: 01.png, etc. A value of 0 disables it
- * @default 3
- *
- * @param Debug Mode
- * @desc Prints extra info if set to true. true/false
- * @default false
- *
- * @param Render Debug Grid
- * @desc Draws a debug grid. Requires "/img/Minimap/DebugGrid.png" which is 48x48 in size. Drains a lot of performance!
- * @default false
- *
- * @param Debug Grid Image
- * @desc Name of the debug-grid image
- * @default DebugGrid01
- *
- * @help
- * 1. Make a mapshot of your map. You may use http://forums.rpgmakerweb.com/index.php?/topic/49711-orange-mapshot/
- * 2. Install this script: http://pastebin.com/FF6jh3S0 and make sure to put it above the minimap script.
- * 3. Copy the files to:
- * 4. /img/minimap/Overlay.png
- * 5. /img/minimap/DebugGrid01.png
- * 6. /img/system/Window_Minimap.png
- * 7. Place your mapshots in the /img/minimap/ directory and rename them 001.png, 002.png etc. (matching the id of your map)
- *
- * If you prefer to use automatic generated maps instead, use the map-notetags and you then obviously do not require mapshots of course.
- *
- *--------------------------------------
- * Map notetags (most are case sensitive!)
- *--------------------------------------
- * <mm_req_itm:item_id1 item_id2 etc>
- * Example: <mm_req_itm:1, 2, 3>
- *
- * <mm_mapstyle:Scroll/Autofit>
- * Examples:
- * <mm_mapstyle:Scroll>
- * <mm_mapstyle:AutoFit>
- *
- * <mm_frameskip:value>
- * Example: <mm_frameskip:1>
- * Note: overrides the global frameskip parameter for this map
- *
- * <mm_mapzoom:value>
- * Example: <mm_mapzoom:0.15>
- * Note: overrides the global mapzoom parameter for this map
- *
- * <mm_allowmanualscroll:value>
- * Example: <mm_allowmanualscroll:false>
- * Allowed values: true/false
- * Note: overrides the global "Allow Manual Scrolling" parameter for this map
- *
- * <mm_menuzoom:value>
- * Example: <mm_menuzoom:0.75>
- * Note: overrides the global "Menu Zoom" parameter for this map
- *
- * <mm_size:x y>
- * Example: <mm_size:128 128>
- * Note: overrides the global "Width" and "Height" parameters for this map
- *
- * Allow/disallow teleportation.
- * <mm_tp_allow:value>
- * Example: <mm_tp_allow:false>
- * Note: overrides the global "Allow Teleportation" parameter for this map
- *
- * Generate a worldmap-minimap if there is no image (does increase load-time, the first time, for the map)
- * <mm_generate_worldmap>
- * <mm_generate_overworld>
- *
- * Geberate regular map
- * <mm_generate_map>
- *
- * Generate and overlay a generated passability-map on top of the minimap
- * <mm_generate_passability_overlay>
- *
- * Change the player-blip
- * <mm_player_blip:value>
- * Example to use the realtime player graphic:
- * <mm_player_blip::player>
- * Example to use a custom blip graphic:
- * <mm_player_blip:myCustomPlayerBlip>
- * Note that in the above example, the game requires the image /img/minimap/myCustomPlayerBlip.png"
- *
- *--------------------------------------
- * Event notetags (not case sensitive)
- *--------------------------------------
- * mm_show
- *
- *--------------------------------------
- * Plugin Commands (not case-sensitive)
- *--------------------------------------
- * Minimap Hide
- * Minimap Show
- * Minimap FadeOut
- * Minimap FadeReset
- * Minimap Refresh
- * Minimap RefreshEvents
- * Minimap IncreaseScroll <x> <y>
- * Minimap SetScroll <x> <y>
- * Minimap DeletePOI <poi_id>
- * Minimap Generate_Passability_Overlay <true/false>
- * Minimap Gen_Pass_Ov <true/false>
- * Minimap ShowMapMenu
- * Minimap SetPlayerBlip <filename/:player>
- *
- * Minimap POIDesc <description>
- * Example: Minimap POIDesc An Awesome City!
- *
- * Minimap POI_TP <poi_id x_offset y_offset direction fadeType>
- * Example: Minimap POI_TP 1 1 0 0 0
- * Note that teleporting with both offsets set to 0, will teleport the player straight into the center of the poi.
- *
- * Adding POI's (advanced plugin command!):
- * Minimap AddPOI unique_poi_id, name, real_x, real_y, bitmap folder, bitmap filename, s_x, s_y, s_w, s_h, draw_w, draw_h
- * Example that draws Actor1_3 on tile 10,10:
- * Minimap AddPOI 1 A_Friend 10 10 img/enemies/ Actor1_3 0 0 254 225 64 64
- * Note:
- * - The real_x & real_y are in maptiles and not in coordinates. 0,0 is in the upper left corner.
- * - name-value replaces underscores _ with spaces.
- *
- *
- *--------------------------------------
- * Event comment-tags (case sentitive!)
- *--------------------------------------
- * To show an event on the minimap:
- * <mm_show>
- *
- * To add a description to an event (for the minimap-scene)
- * <mm_desc>
- *
- * To add teleport to the event:
- * <mm_tp:offset_x offset_y direction fadeType>
- * Example: <mm_tp:1 0 2 0>
- * Notes:
- * - Offset is the offset in tiles with the event-location itself being 0 0
- * - Possible direction values: 2 (down), 4 (left), 6 (right), 8 (up). Or use a value of 0 to maintain the current player-facing-direction
- * - Possible fadeType values: 0 (black), 1 (white), 2 (none)
- *
- *
- * Note to other scripters: You can access the variable that contains the window through this: "Silv.Minimap.Window" w/o the quotes.
- *
- *
- *--------------------------------------
- * Version History:
- *--------------------------------------
- * v.1.03 (26 November 2015) [Updated Parameters]
- * - New feature: Use custom player blip.
- * - 2 new parameters: "Render Player Blip" & "Player Blip Graphic" and new mapnotetag: <mm_player_blip::player> and a new plugin parameter "Minimap setplayerblip <value>".
- * - Removed parameter "Draw Player Icon".
- * - Added a parameter to change minimap-opacity.
- * - Added plugin commands and map-notetags to switch between AutoScroll and Autofit map-modes, <mm_mapstyle:Scroll/Autofit>
- * v.1.02 (25 November 2015) [Updated Parameters]
- * - Enabled strict mode.
- * - Added the 'Minimap ShowMapMenu' plugin-command.
- * - New feature: can now generate overworld-minimaps (w/o requiring mapshots) with the map-notetag: <mm_generate_worldmap> or <mm_generate_overworld> or <mm_generate_map>].
- * - New feature: generate passability overlay. Also comes with new map-notetag & plugin command. Supports 4-direction-passability.
- * - New feature: You can now (optional) open the minimap-menu through a keybinding and also close it with that same keybinding (if the left-menu is active).
- * - Fixed the minimap-visibility again (it was still not properly fixed in v1.01).
- * - Now requires Silvers Keybinding script 1.01 instead of 1.00.
- *
- * v.1.01 (24 November 2015) [Updated Parameters]
- * - Fixed the player-blip becoming invisible when walking on grass. Because of this I had to add 2 more advanced parameters.
- * - Fixed: The minimap no longer automatically shows itself again when it was manually hidden after opening a menu.
- * - Updated the version number to 1.01 (it was still 0.91) in the plugin description.
- * - Cleaned up some more out-commented code.
- * - Fixed: minimap can now hide again when it contains POI's.
- * - Fixed a bug that would not 'dispose' the minimap-window when getting rid of a minimap within a scene because the Scene_Map still had a references in it's children to the map. This also increases performance.
- *
- * v1.00 (23 November 2015)
- * - First release.
- *
- * v0.90-0.92 (November 2015)
- * - First alpha release.
- *
- */
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Script start
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Enable strict mode
- "use strict";
- // Get Plugin #Parameters
- var Silv = Silv || {};
- Silv.Plugins = Silv.Plugins || {};
- Silv.Plugins.Minimap = 1.03;
- if (!('Keys' in Silv.Plugins) || Silv.Plugins.Keys < 1.01) { throw 'ERROR: Silvers Minimap requires Silvers KeyMapper v1.00 or higher. It must be placed above the minimap script.'; }
- Silv.Parameters = $plugins.filter(function(p) { return p.description.contains('<SilvMinimap>'); })[0].parameters;
- Silv.Minimap = Silv.Minimap || {};
- Silv.Minimap.Menu = Silv.Minimap.Menu || {};
- Silv.Minimap.Generator = Silv.Minimap.Generator || {};
- // Non-parameters
- Silv.Minimap.Window = null;
- Silv.Minimap.POI = {};
- Silv.Minimap.Events = new Array(); // Is an array of objects [{ Game_Event, Sprite_Character }]. USe .event and .sprite to retrieve the values.
- Silv.Minimap.ScreenIsFading = false;
- Silv.Minimap.Menu.Bmp = null;
- Silv.Minimap.Menu.Markers = new Array();
- Silv.Minimap.WasLoadedFromSave = false;
- Silv.Minimap.LastMapID = -1; // To detect when a different map is loaded. Because loading the menu-scene for example will reload the entire map again and also recreate the minimap, but we don't want to erase the POI's and such then.
- Silv.Minimap.TP_Dest = null;
- Silv.Minimap.CreateFunctionIsLocked = false;
- Silv.Minimap.Visible = true;
- // General
- Silv.Minimap.MapStyle = Silv.Parameters['Map Style'].toLowerCase();
- Silv.Minimap.GlobalMapZoom = parseFloat(Silv.Parameters['Global Map Zoom']);
- Silv.Minimap.PlayerBlipEnabled = Silv.Parameters['Render Player Blip'].toLowerCase() == 'true';
- Silv.Minimap.PlayerBlipGraphic = Silv.Parameters['Player Blip Graphic'].toLowerCase();
- Silv.Minimap.Window_Opacity = parseInt(Silv.Parameters['Minimap Opacity']);
- // Positioning & Size
- Silv.Minimap.Window_X = parseInt(Silv.Parameters['X']);
- Silv.Minimap.Window_Y = parseInt(Silv.Parameters['Y']);
- Silv.Minimap.WindowWidth = parseInt(Silv.Parameters['Width']);
- Silv.Minimap.WindowHeight = parseInt(Silv.Parameters['Height']);
- Silv.Minimap.BorderWidth = parseInt(Silv.Parameters['Border Width']);
- Silv.Minimap.BorderHeight = parseInt(Silv.Parameters['Border Height']);
- Silv.Minimap.WindowHorizontalAlignment = Silv.Parameters['Horizontal Alignment'].toLowerCase();
- Silv.Minimap.WindowVerticalAlignment = Silv.Parameters['Vertical Alignment'].toLowerCase();
- // Menu
- Silv.Minimap.Menu.MenuKey = Silv.Keys.fromStringParam(Silv.Parameters['Menu Key']);
- Silv.Minimap.Menu.PlayerDesc = Silv.Parameters['Menu Player Description'];
- Silv.Minimap.Menu.Zoom = parseFloat(Silv.Parameters['Menu Zoom']);
- Silv.Minimap.Menu.WindowWidth_Left = parseInt(Silv.Parameters['Menu Left Window Width']);
- Silv.Minimap.Menu.WindowHeight_MapSection = parseInt(Silv.Parameters['Menu Topright Window Height']);
- Silv.Minimap.Menu.EventRenderSize = parseInt(Silv.Parameters['Menu Event Render Size']);
- Silv.Minimap.Menu.PlayerIconSize = parseInt(Silv.Parameters['Menu Player Icon Size']);
- Silv.Minimap.Menu.ManualZoom_Min = parseFloat(Silv.Parameters['Menu Min Manual Zoom']);
- Silv.Minimap.Menu.ManualZoom_Max = parseFloat(Silv.Parameters['Menu Max Manual Zoom']);
- Silv.Minimap.Menu.ManualZoomKey_In = Silv.Keys.fromStringParam(Silv.Parameters['Menu Zoomin Key']);
- Silv.Minimap.Menu.ManualZoomKey_Out = Silv.Keys.fromStringParam(Silv.Parameters['Menu Zoomout Key']);
- Silv.Minimap.Menu.ManualZoomKey_Reset = Silv.Keys.fromStringParam(Silv.Parameters['Menu Reset Zoom Key']);
- Silv.Minimap.Menu.ManualScrollKey_Reset = Silv.Keys.fromStringParam(Silv.Parameters['Menu Reset Scroll Key']);
- // Passability Map
- Silv.Minimap.PassabilityOverlayOpacity = parseInt(Silv.Parameters['Passability Overlay Opacity']);
- Silv.Minimap.PassabilityColor = Silv.Parameters['Passability Color'];
- Silv.Minimap.ImpassabilityColor = Silv.Parameters['Impassability Color'];
- // Generator
- Silv.Minimap.Generator.MapColors = Silv.Parameters['Map Gen Tag Colors'].split(' ');
- Silv.Minimap.Generator.OverworldColors = Silv.Parameters['Overworld Gen Tag Colors'].split(' ');
- // The Rest
- Silv.Minimap.AllowTeleportation = Silv.Parameters['Allow Teleportation'].toLowerCase() == 'true';
- Silv.Minimap.StandardPadding = parseInt(Silv.Parameters['Standard Padding']);
- Silv.Minimap.WindowSkin = Silv.Parameters['Window Skin'];
- Silv.Minimap.PlayerIconWidth = parseInt(Silv.Parameters['Player Icon Width']);
- Silv.Minimap.PlayerIconHeight = parseInt(Silv.Parameters['Player Icon Height']);
- Silv.Minimap.PlayerBlinks = parseInt(Silv.Parameters['Player Blink Delay']) > 0;
- Silv.Minimap.PlayerBlinkDelay = parseInt(Silv.Parameters['Player Blink Delay']);
- Silv.Minimap.MapBGFillColor = Silv.Parameters['Fill Color'].split(' ');
- Silv.Minimap.MaintainAspectRatio = Silv.Parameters['Maintain Aspect Ratio'].toLowerCase() == 'true';
- Silv.Minimap.FadeoutSpeed = parseInt(Silv.Parameters['Fadeout Speed']);
- Silv.Minimap.GlobalRequiredItem = parseInt(Silv.Parameters['Global Required Item']);
- Silv.Minimap.EventRenderSize = parseInt(Silv.Parameters['Event Render Size']);
- Silv.Minimap.AutoClearPOI = Silv.Parameters['Auto Clear POI'].toLowerCase() == 'true';
- Silv.Minimap.DrawOverlay = Silv.Parameters['Render Minimap Overlay'].toLowerCase() == 'true';
- // Manual Scrolling
- Silv.Minimap.AllowManualScrolling = Silv.Parameters['Allow Manual Scrolling'].toLowerCase() == 'true';
- Silv.Minimap.ManualScrollspeed = parseFloat(Silv.Parameters['Manual Scrollspeed']);
- Silv.Minimap.ManualScrollKeyUp = Silv.Keys.fromStringParam(Silv.Parameters['Manual Scroll Key Up']);
- Silv.Minimap.ManualScrollKeyRight = Silv.Keys.fromStringParam(Silv.Parameters['Manual Scroll Key Right']);
- Silv.Minimap.ManualScrollKeyDown = Silv.Keys.fromStringParam(Silv.Parameters['Manual Scroll Key Down']);
- Silv.Minimap.ManualScrollKeyLeft = Silv.Keys.fromStringParam(Silv.Parameters['Manual Scroll Key Left']);
- // Advanced & Debug
- Silv.Minimap.PlayerSpriteSrcFrame_Width = parseInt(Silv.Parameters['Player Sprite Sourceframe Width']);
- Silv.Minimap.PlayerSpriteSrcFrame_Height = parseInt(Silv.Parameters['Player Sprite Sourceframe Height']);
- Silv.Minimap.FrameSkip = parseInt(Silv.Parameters['Frame Skip']);
- Silv.Minimap.MapFilenameLength = parseInt(Silv.Parameters['Mapshot Filename Length']);
- Silv.Minimap.DebugMode = Silv.Parameters['Debug Mode'].toLowerCase() == 'true';
- Silv.Minimap.DrawDebugGrid = Silv.Parameters['Render Debug Grid'].toLowerCase() == 'true';
- Silv.Minimap.DebugGridImage = Silv.Parameters['Debug Grid Image'];
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (function()
- {
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // #Utilities & Misc
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Example: lpad('2', '0') // result: '002'
- function lpad_mapname(word, padStr)
- {
- word = String(word);
- while (word.length < Silv.Minimap.MapFilenameLength) word = padStr + word;
- return word;
- }
- function minimapFolderPath()
- {
- var path = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, "/img/minimap/");
- if (path.match(/^\/([A-Z]\:)/)) { path = path.slice(1); }
- path = decodeURIComponent(path);
- return path;
- }
- // filename example: '002.png'
- function minimapImageExists(filename)
- {
- var filename = minimapFolderPath() + filename;
- var fs = require('fs');
- return fs.existsSync(filename);
- }
- function dataMapGetEventByID(ev_id)
- {
- for(var i=1; i< $dataMap.events.length; i++)
- {
- if ($dataMap.events[i].id == ev_id) { return $dataMap.events[i]; }
- }
- return null;
- }
- ImageManager.loadMinimap = function(filename, hue)
- {
- return this.loadBitmap('img/minimap/', filename, hue, false);
- };
- // Do not just show the minimap on top of a faded-out screen.
- var alias_silv_mm_updateFadeOut = Game_Screen.prototype.updateFadeOut;
- Game_Screen.prototype.updateFadeOut = function() {
- alias_silv_mm_updateFadeOut.call(this);
- if (this._brightness < 255) // (this._fadeOutDuration > 0)
- {
- Silv.Minimap.ScreenIsFading = true;
- Silv.Minimap.Window.opacity = this._brightness;
- Silv.Minimap.Window.contents.paintOpacity = this._brightness;
- }
- else
- {
- Silv.Minimap.ScreenIsFading = false;
- }
- };
- //------------------------------------------------------------------------------------------------------------------------------------
- // Store a reference to the player graphic.
- //------------------------------------------------------------------------------------------------------------------------------------
- var alias_silv_mm_createCharacters = Spriteset_Map.prototype.createCharacters;
- Spriteset_Map.prototype.createCharacters = function()
- {
- alias_silv_mm_createCharacters.call(this);
- for (var i = this._characterSprites.length - 1; i >= 0; i--)
- {
- if (this._characterSprites[i]._character == $gamePlayer)
- {
- Spriteset_Map.prototype.playerSprite = this._characterSprites[i];
- break;
- }
- }
- };
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Automatically create a event-Notetag from event-comments on the active page
- // Example usage: console.log($gameMap.event(1).event.silvNote);
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- var alias_silv_mm_Game_Event_setupPage = Game_Event.prototype.setupPage;
- Game_Event.prototype.setupPage = function()
- {
- alias_silv_mm_Game_Event_setupPage.call(this);
- this.silvCreateNote();
- };
- Game_Event.prototype.silvCreateNote = function()
- {
- this.silvNote = '';
- if (typeof this.page() === 'undefined') { return; }
- var list = this.list();
- var str = null;
- for (var commandProperty in list)
- {
- if (list.hasOwnProperty(commandProperty))
- {
- var command = list[commandProperty];
- var commandCode = command.code;
- if (commandCode == 108) // 108: new comment-item, always the first line.
- {
- if (str != null) { this.silvNote += str; }
- str = command.parameters[0];
- }
- else if (commandCode == 408) // 408: comment-line, but not the first one.
- {
- this.silvNote += command.parameters[0];
- }
- else if (str) // It's not a comment-code, so add the previous str (if any) to the note.
- {
- this.silvNote += str;
- str = null;
- }
- }
- }
- if (this.silvNote != '') {this.extractSilvMetadata()};
- };
- // <mm_tp:1> will result in: '1'
- // <mm_tp:1> will result in: ['1', '0'];
- Game_Event.prototype.extractSilvMetadata = function() {
- var re = /<([^<>:]+)(:?)([^>]*)>/g;
- this.meta = {};
- for (;;)
- {
- var match = re.exec(this.silvNote);
- if (match)
- {
- if (match[2] === ':')
- {
- var value = match[3];
- if (match[3].indexOf(' ') >= 0) { value = match[3].split(' '); }
- this[match[1]] = value;
- }
- else
- {
- this[match[1]] = true;
- }
- }
- else
- {
- break;
- }
- }
- };
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Minimap Window
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function Window_Minimap() { this.initialize.apply(this, arguments); }
- // Inherit from base window
- Window_Minimap.prototype = Object.create(Window_Base.prototype);
- // Set Constructor
- Window_Minimap.prototype.constructor = Window_Minimap;
- Window_Minimap.prototype.loadWindowskin = function() { this.windowskin = ImageManager.loadSystem(Silv.Minimap.WindowSkin); }
- Window_Minimap.prototype.standardPadding = function() { return Silv.Minimap.StandardPadding; }
- //Window_Minimap.prototype.standardFontSize = function() { return Silv.Minimap.FontSize; }
- var mapBmp;
- var originalMapBmp;
- var passabilityBmp;
- var drawPassabilityOverlay;
- var passabilityRequiresRedraw;
- var drawAreaWidth;
- var drawAreaHeight;
- var mapWidth
- var mapHeight;
- var playerBlinkCnt;
- var playerBlink_IsVisible;
- var frameSkip;
- var frameSkipCnt;
- var mapAspRatInfo;
- var mapZoom;
- var mapZoomInverse;
- var isManualScrolling;
- var allowManualScroll;
- var mapScroll;
- var lastPlayerLoc;
- var isFirstProcessedUpdate;
- var requiresDrawing; // as in AFTER isReady().
- var debugGridBmp;
- var overlayBmp;
- var menuZoom;
- var allowTeleportation;
- var playerFrame;
- var playerInfo;
- var minimapType;
- var mapStyle;
- var playerBlipEnabled;
- var playerBlipGfx;
- var playerBlipBmp;
- var usePlayerBlipGfx;
- // #Initialization
- Window_Minimap.prototype.initialize = function(x, y, width, height, minimapType)
- {
- this.minimapType = minimapType;
- if ('mm_size' in $dataMap.meta)
- {
- var newSize = $dataMap.meta.mm_size.split(' ');
- width = parseInt(newSize[0]);
- heigth = parseInt(newSize[1]);
- }
- Window_Base.prototype.initialize.call(this, x, y, width, height);
- this._helpWindow = null;
- this._handlers = {};
- this._touching = false;
- this.deactivate();
- this.originalMapBmp = null;
- this.passabilityBmp = null;
- this.drawPassabilityOverlay = false;
- this.isFadingOut = false;
- this.isFadedOut = false;
- this.setDrawMapBmp();
- this.overlayBmp = ImageManager.loadMinimap('Overlay');
- this.drawAreaWidth = this.contents.width - Silv.Minimap.BorderWidth * 2;
- this.drawAreaHeight = this.contents.height - Silv.Minimap.BorderHeight * 2;
- this.mapWidth = parseFloat($gameMap.width());
- this.mapHeight = parseFloat($gameMap.height());
- this.setAspectRatio();
- this.playerBlinkCnt = Silv.Minimap.PlayerBlinkDelay;
- this.playerBlink_IsVisible = true;
- this.frameSkip = Silv.Minimap.FrameSkip;
- this.frameSkipCnt = 0;
- if ('mm_mapzoom' in $dataMap.meta) { this.mapZoom = parseFloat($dataMap.meta.mm_mapzoom); }
- else { this.mapZoom = Silv.Minimap.GlobalMapZoom; }
- this.mapZoomInverse = 1 / this.mapZoom;
- this.isFirstProcessedUpdate = true;
- this.requiresDrawing = true;
- this.isManualScrolling = false;
- if ('mm_allowmanualscroll' in $dataMap.meta) { this.allowManualScroll = $dataMap.meta.mm_allowmanualscroll.toLowerCase() == 'true'; }
- else { this.allowManualScroll = Silv.Minimap.AllowManualScrolling; }
- this.mapScroll = {x: 0, y: 0, adjustment_x: 0, adjustment_y: 0};
- this.lastPlayerLoc = {x: $gamePlayer._realX, y: $gamePlayer._realY};
- if ('mm_menuzoom' in $dataMap.meta) { this.menuZoom = $dataMap.meta.mm_menuzoom.toLowerCase() == 'true'; }
- else { this.menuZoom = Silv.Minimap.Menu.Zoom; }
- if ('mm_tp_allow' in $dataMap.meta) { this.allowTeleportation = $dataMap.meta.mm_tp_allow.toLowerCase() == 'true'; }
- else { this.allowTeleportation = Silv.Minimap.AllowTeleportation; }
- this.playerFrame = {x:0, y:0, width:Silv.Minimap.PlayerSpriteSrcFrame_Width, height:Silv.Minimap.PlayerSpriteSrcFrame_Height};
- if ('mm_mapstyle' in $dataMap.meta) { this.mapStyle = $dataMap.meta.mm_mapstyle.toLowerCase(); }
- else { this.mapStyle = Silv.Minimap.MapStyle; }
- this.initPlayerBlip();
- this.loadEvents();
- this.debugGridBmp = ImageManager.loadMinimap(Silv.Minimap.DebugGridImage);
- // The update must be called AFTER all the initialization code.
- this.update();
- };
- Window_Minimap.prototype.setOpacity = function()
- {
- this.opacity = Silv.Minimap.Window_Opacity;
- };
- Window_Minimap.prototype.initPlayerBlip = function()
- {
- this.playerBlipEnabled = Silv.Minimap.PlayerBlipEnabled;
- this.playerBlipGfx = Silv.Minimap.PlayerBlipGraphic;
- this.playerBlipBmp = null;
- if ('mm_player_blip' in $dataMap.meta) { this.setPlayerBlip($dataMap.meta.mm_player_blip); }
- else { this.setPlayerBlip(Silv.Minimap.PlayerBlipGraphic); }
- };
- Window_Minimap.prototype.setDrawMapBmp = function()
- {
- switch (this.minimapType)
- {
- case 'regular':
- if(this.originalMapBmp == null)
- {
- this.originalMapBmp = ImageManager.loadMinimap(lpad_mapname($gameMap._mapId, '0'));
- this.mapBmp = ImageManager.loadMinimap(lpad_mapname($gameMap._mapId, '0'));
- }
- else if (this.originalMapBmp.isReady())
- {
- this.mapBmp = new Bitmap(this.originalMapBmp.width, this.originalMapBmp.height);
- this.mapBmp.blt(this.originalMapBmp, 0, 0, this.originalMapBmp.width, this.originalMapBmp.height, 0, 0); // Because nobody knows how to clone a bitmap, we do it like this...
- this.requiresDrawing = false;
- }
- break;
- case 'generate_map':
- this.mapBmp = this.generateMap(Silv.Minimap.Generator.MapColors);
- this.requiresDrawing = false;
- break;
- case 'generate_overworld':
- this.mapBmp = this.generateMap(Silv.Minimap.Generator.OverworldColors);
- this.requiresDrawing = false;
- break;
- default:
- throw 'Window_Minimap.prototype.GetMapBmp has invalid switch-value: ' + this.minimapType;
- }
- if (this.drawPassabilityOverlay)
- {
- if (this.originalMapBmp.isReady()) { this.bltPassabilityOverlay(); }
- else { this.passabilityRequiresRedraw = true; }
- }
- };
- //----------------------------------------------------------------------------------------------------
- // #Show & #Hide
- //----------------------------------------------------------------------------------------------------
- var alias_silv_mm_hide = Window_Minimap.prototype.hide;
- Window_Minimap.prototype.hide = function()
- {
- alias_silv_mm_hide.call(this);
- Silv.Minimap.Visible = false;
- }
- var alias_silv_mm_show = Window_Minimap.prototype.show;
- Window_Minimap.prototype.show = function()
- {
- alias_silv_mm_show.call(this);
- Silv.Minimap.Visible = true;
- }
- //----------------------------------------------------------------------------------------------------
- // #Passability #Overlay
- //----------------------------------------------------------------------------------------------------
- Window_Minimap.prototype.bltPassabilityOverlay = function()
- {
- // Generate the bitmap if it wasn't done already
- if (this.passabilityBmp == null) { this.passabilityBmp = this.generatePassabilityBmp(); }
- // Blt the overlay on top of the this.mapBmp
- this.mapBmp.blt(this.passabilityBmp, 0, 0, this.passabilityBmp.width, this.passabilityBmp.height, 0, 0);
- this.passabilityRequiresRedraw = false;
- };
- Window_Minimap.prototype.setPassabilityOverlay = function(enabled)
- {
- this.drawPassabilityOverlay = enabled;
- this.setDrawMapBmp();
- };
- // Dev note: this method can be severely optimized by replacing it with a modified version of the $GameMap.checkPassage(). Calling gameMap.isPassable() 4x per tile is not effective because internally it starts looping through them 4x instead of 1.
- Window_Minimap.prototype.generatePassabilityBmp = function()
- {
- var tile_w = $gameMap.tileWidth();
- var tile_h = $gameMap.tileHeight();
- var bmp = new Bitmap($gameMap.width() * tile_w, $gameMap.height() * tile_h);
- bmp.paintOpacity = Silv.Minimap.PassabilityOverlayOpacity;
- var borderTickness = 8;
- for (var y=0; y<$dataMap.height; y++)
- {
- for (var x=0; x<$dataMap.width; x++)
- {
- var passability = {2:$gameMap.isPassable(x, y, 2), 4:$gameMap.isPassable(x, y, 4), 6:$gameMap.isPassable(x, y, 6), 8:$gameMap.isPassable(x, y, 8)};
- if (!passability[2] && !passability[4] && !passability[6] && !passability[8])
- {
- bmp.fillRect(x * tile_w, y * tile_h, tile_w, tile_h, Silv.Minimap.ImpassabilityColor);
- }
- else
- {
- bmp.paintOpacity = 255;
- if (!passability[8]) { bmp.fillRect(x * tile_w, y * tile_h, tile_w, borderTickness, Silv.Minimap.ImpassabilityColor); } // top
- if (!passability[6]) { bmp.fillRect(x * tile_w + tile_w - borderTickness, y * tile_h, borderTickness, tile_h, Silv.Minimap.ImpassabilityColor); } // right
- if (!passability[2]) { bmp.fillRect(x * tile_w, y * tile_h + tile_h - borderTickness, tile_w, borderTickness, Silv.Minimap.ImpassabilityColor); } // bottom
- if (!passability[4]) { bmp.fillRect(x * tile_w, y * tile_h, borderTickness, tile_h, Silv.Minimap.ImpassabilityColor); } // left
- bmp.paintOpacity = Silv.Minimap.PassabilityOverlayOpacity;
- bmp.fillRect(x * tile_w, y * tile_h, tile_w, tile_h, Silv.Minimap.PassabilityColor);
- }
- }
- }
- return bmp;
- };
- //----------------------------------------------------------------------------------------------------
- // #Generate Maps
- //----------------------------------------------------------------------------------------------------
- Window_Minimap.prototype.generateMap = function(colors)
- {
- var tile_w = $gameMap.tileWidth();
- var tile_h = $gameMap.tileHeight();
- var bmp = new Bitmap($gameMap.width() * tile_w, $gameMap.height() * tile_h);
- for (var y=0; y<$dataMap.height; y++)
- {
- for (var x=0; x<$dataMap.width; x++)
- {
- bmp.fillRect(x * tile_w, y * tile_h, tile_w, tile_h, colors[$gameMap.terrainTag(x, y)]); // Default: lightgreen, blue, brown, darkgreen, lightbrown
- }
- }
- return bmp;
- };
- //----------------------------------------------------------------------------------------------------
- // <Asorted>
- //----------------------------------------------------------------------------------------------------
- Window_Minimap.prototype.showMapMenuScene = function()
- {
- Silv.Minimap.Window.pushMapScene();
- }
- Window_Minimap.prototype.clamp = function(value, min, max)
- {
- return Math.min(Math.max(value, min), max);
- };
- // This function requires this.mapBmp to be fully initialized.
- // #Aspect #Ratio #AspectRatio
- Window_Minimap.prototype.setAspectRatio = function()
- {
- // this.mapAspRatInfo.scaleDelta_x is the difference in size between the mapwidth (in pixels, NOT in tiles) and the minimap (render)width.
- this.mapAspRatInfo = { w: 0.0, h: 0.0, offset_x: 0.0, offset_y: 0.0, scaleDelta_x: 0.0, scaleDelta_y: 0.0 }
- var w = $gameMap.width();
- var h = $gameMap.height();
- // Map Aspect Ratio
- if (!Silv.Minimap.MaintainAspectRatio || (w == h))
- {
- this.mapAspRatInfo.w = 1.0;
- this.mapAspRatInfo.h = 1.0;
- }
- else if (w > h)
- {
- this.mapAspRatInfo.w = 1.0;
- this.mapAspRatInfo.h = h / parseFloat(w);
- }
- else // if (h > w)
- {
- this.mapAspRatInfo.w = w / parseFloat(h);
- this.mapAspRatInfo.h = 1.0;
- }
- this.mapAspRatInfo.scaleDelta_x = this.drawAreaWidth / parseFloat($gameMap.width() * $gameMap.tileWidth());
- this.mapAspRatInfo.scaleDelta_y = this.drawAreaHeight / parseFloat($gameMap.height() * $gameMap.tileHeight());
- };
- // #Events
- Window_Minimap.prototype.loadEvents = function()
- {
- Silv.Minimap.Events = new Array();
- for (var ev_idx = 1; ev_idx < $dataMap.events.length; ev_idx++) // Note: start at 1. Because the first one is always null.
- {
- if ($dataMap.events[ev_idx] != null)
- {
- var ev = $gameMap.event(ev_idx);
- // Check Event Note
- if ($dataMap.events[ev_idx].note != '' || ('mm_show' in ev))
- {
- var cmds = $dataMap.events[ev_idx].note.toLowerCase().split(' ');
- if ((cmds.indexOf('mm_show') > -1) || ('mm_show' in ev))
- {
- var new_ev = {event: ev, sprite: this.getEventCharacterSprite(ev.eventId())};
- Silv.Minimap.Events.push(new_ev); // Add event to the array so we can render it on the minimap
- }
- }
- }
- }
- if (Silv.Minimap.DebugMode) { console.log('Loaded Events:'); console.log(Silv.Minimap.Events); }
- };
- Window_Minimap.prototype.getEventCharacterSprite = function(ev_id)
- {
- for (var i=0; i < SceneManager._scene._spriteset._characterSprites.length; i++)
- {
- var eventSprite = SceneManager._scene._spriteset._characterSprites[i];
- if (eventSprite._character.eventId() == ev_id)
- {
- return eventSprite;
- }
- }
- throw 'getEventCharacterSprite() did not find a match for ev_id: ' + ev_id;
- };
- // #update
- Window_Minimap.prototype.update = function()
- {
- if (!this.skipFrame() && (this.originalMapBmp == null || this.originalMapBmp.isReady()))
- {
- Window_Base.prototype.update.call(this);
- this.updateFadeOut();
- this.updateInput();
- if (Silv.Minimap.PlayerBlinks) { this.updatePlayerBlink(); }
- this.updateMapScroll(this.isFirstProcessedUpdate);
- this.playerInfo = this.getPlayerBitmap();
- if (this.requiresDrawing) { this.setDrawMapBmp(); }
- this.drawMinimap();
- this.lastPlayerLoc.x = $gamePlayer._realX;
- this.lastPlayerLoc.y = $gamePlayer._realY;
- this.isFirstProcessedUpdate = false;
- // Teleport
- if (Silv.Minimap.TP_Dest != null)
- {
- this.teleport(Silv.Minimap.TP_Dest);
- Silv.Minimap.TP_Dest = null;
- }
- if (this.passabilityRequiresRedraw && this.originalMapBmp.isReady()) { this.bltPassabilityOverlay(); }
- }
- if (Input.isTriggered(Silv.Minimap.Menu.MenuKey)) { this.showMapMenuScene(); }
- };
- Window_Minimap.prototype.getPlayerBitmap = function()
- {
- var playerSpr = Spriteset_Map.prototype.playerSprite;
- // Player is not in bush, so return the regular player-graphic
- if (playerSpr._bushDepth == 0 || playerSpr._lowerBody == null) { return {bmp:playerSpr._bitmap, src:playerSpr._frame} };
- // Create Bush graphic (which is divided into 2 graphics by the RM-code..)
- var playerBmp = new Bitmap(Silv.Minimap.PlayerSpriteSrcFrame_Width, Silv.Minimap.PlayerSpriteSrcFrame_Height);
- playerBmp.blt(Spriteset_Map.prototype.playerSprite._lowerBody._bitmap, Spriteset_Map.prototype.playerSprite._lowerBody._frame.x, Spriteset_Map.prototype.playerSprite._lowerBody._frame.y, Spriteset_Map.prototype.playerSprite._lowerBody._frame.width, Spriteset_Map.prototype.playerSprite._lowerBody._frame.height,
- 0, Silv.Minimap.PlayerSpriteSrcFrame_Height - playerSpr._bushDepth, Silv.Minimap.PlayerIconSize, Silv.Minimap.PlayerIconSize);
- playerBmp.blt(Spriteset_Map.prototype.playerSprite._upperBody._bitmap, Spriteset_Map.prototype.playerSprite._upperBody._frame.x, Spriteset_Map.prototype.playerSprite._upperBody._frame.y, Spriteset_Map.prototype.playerSprite._upperBody._frame.width, Spriteset_Map.prototype.playerSprite._upperBody._frame.height,
- 0, 0, Silv.Minimap.PlayerIconSize, Silv.Minimap.PlayerIconSize);
- return {bmp:playerBmp, src:this.playerFrame};
- };
- Window_Minimap.prototype.updateInput = function()
- {
- if (Input.isPressed(Silv.Minimap.ManualScrollKeyUp)) { Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x, Silv.Minimap.Window.mapScroll.y - Silv.Minimap.ManualScrollspeed); }
- if (Input.isPressed(Silv.Minimap.ManualScrollKeyRight)) { Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x + Silv.Minimap.ManualScrollspeed, Silv.Minimap.Window.mapScroll.y); }
- if (Input.isPressed(Silv.Minimap.ManualScrollKeyDown)) { Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x, Silv.Minimap.Window.mapScroll.y + Silv.Minimap.ManualScrollspeed); }
- if (Input.isPressed(Silv.Minimap.ManualScrollKeyLeft)) { Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x - Silv.Minimap.ManualScrollspeed, Silv.Minimap.Window.mapScroll.y); }
- };
- Window_Minimap.prototype.teleport = function(tp_info)
- {
- var direction = $gamePlayer._direction;
- if (tp_info[2] != 0) { direction = parseInt(tp_info[2]); }
- $gamePlayer.reserveTransfer($gameMap._mapId, tp_info[0], tp_info[1], direction, parseInt(tp_info[3]));
- };
- Window_Minimap.prototype.playerLocChanged = function()
- {
- return this.lastPlayerLoc.x != $gamePlayer._realX || this.lastPlayerLoc.y != $gamePlayer._realY;
- };
- // #Scroll
- Window_Minimap.prototype.updateMapScroll = function(force)
- {
- if (this.playerLocChanged() || force) // Only update mapscroll if the player changed location. This way manual-scrolling is made possible.
- {
- this.isManualScrolling = false;
- this.setMapScroll($gamePlayer._realX * $gameMap.tileWidth() - (this.drawAreaWidth / 2 * this.mapZoomInverse), $gamePlayer._realY * $gameMap.tileHeight() - (this.drawAreaHeight / 2 * this.mapZoomInverse));
- }
- };
- Window_Minimap.prototype.setMapScroll = function(scroll_x, scroll_y)
- {
- var old_x = this.mapScroll.x = scroll_x;
- var source_w = this.drawAreaWidth * this.mapZoomInverse;
- this.mapScroll.x = this.clamp(this.mapScroll.x, 0, this.mapBmp.width - source_w);
- this.mapScroll.adjustment_x = old_x - this.mapScroll.x; // clamp difference
- var old_y = this.mapScroll.y = scroll_y;
- var source_h = this.drawAreaHeight * this.mapZoomInverse;
- this.mapScroll.y = this.clamp(this.mapScroll.y, 0, this.mapBmp.height - source_h);
- this.mapScroll.adjustment_y = old_y - this.mapScroll.y; // clamp difference
- };
- Window_Minimap.prototype.manualScroll = function(scroll_x, scroll_y)
- {
- this.setMapScroll(scroll_x, scroll_y);
- this.isManualScrolling = true;
- };
- // Skips frame (returns true) if frameSkipCnt > frameSkip
- Window_Minimap.prototype.skipFrame = function()
- {
- if (this.frameSkip == 0) { return false; } // process frame
- this.frameSkipCnt++;
- if (this.frameSkipCnt < this.frameSkip)
- {
- return true; // skip frame
- }
- else
- {
- this.frameSkipCnt = 0;
- return false; // process frame
- }
- };
- Window_Minimap.prototype.updatePlayerBlink = function()
- {
- this.playerBlinkCnt--;
- if (this.playerBlinkCnt <= 0)
- {
- this.playerBlinkCnt = Silv.Minimap.PlayerBlinkDelay;
- this.playerBlink_IsVisible = !this.playerBlink_IsVisible;
- }
- };
- //----------------------------------------------------------------------------------------------------
- // Window Fading
- //----------------------------------------------------------------------------------------------------
- Window_Minimap.prototype.updateFadeOut = function()
- {
- if (this.isFadedOut || Silv.Minimap.ScreenIsFading) { return; } // Do nothing if the minimap is already completely faded out or if the screen itself is being faded in/out.
- if (this.isFadingOut) { this.fadeOut(); }
- };
- Window_Minimap.prototype.fadeOut = function()
- {
- this.opacity = this.contentsOpacity -= Silv.Minimap.FadeoutSpeed;
- this.isFadedOut = (this.opacity <= 0);
- };
- Window_Minimap.prototype.resetFade = function()
- {
- this.isFadingOut = false;
- this.fadeOutCnt = 0;
- this.opacity = this.contentsOpacity = 255;
- this.isFadedOut = false;
- };
- Window_Minimap.prototype.fadeOutInstantly = function()
- {
- this.opacity = this.contentsOpacity = 0;
- this.isFadedOut = true;
- };
- //----------------------------------------------------------------------------------------------------
- // #Menu
- //----------------------------------------------------------------------------------------------------
- Window_Minimap.prototype.pushMapScene = function()
- {
- this.createMenuBmp();
- this.createMenuMarkers();
- SceneManager.push(Scene_MiniMap);
- };
- //----------------------------------------------------------------------------------------------------
- // Create Menu Bitmap
- //----------------------------------------------------------------------------------------------------
- Window_Minimap.prototype.createMenuBmp = function()
- {
- Silv.Minimap.Menu.Bmp = new Bitmap(this.mapBmp.width * this.menuZoom, this.mapBmp.height * this.menuZoom);
- this.tileInfo = {
- w: $gameMap.tileWidth(), hw: $gameMap.tileWidth() / 2.0, zhw: ($gameMap.tileWidth() / 2.0) * this.menuZoom,
- h: $gameMap.tileHeight(), hh: $gameMap.tileHeight() / 2.0, zhh: ($gameMap.tileHeight() / 2.0) * this.menuZoom
- };
- // Draw Map
- Silv.Minimap.Menu.Bmp.blt(this.mapBmp, 0, 0, this.mapBmp.width, this.mapBmp.height, 0, 0, Silv.Minimap.Menu.Bmp.width, Silv.Minimap.Menu.Bmp.height);
- // Draw Debug Grid
- if (Silv.Minimap.DrawDebugGrid)
- {
- for (var i=0; i < $gameMap.width(); i++)
- {
- for (j=0; j < $gameMap.height(); j++)
- {
- var debugTileLoc = this.translateLocationMenu(this, i, j, this.tileInfo.w * this.menuZoom, this.tileInfo.h * this.menuZoom);
- Silv.Minimap.Menu.Bmp.blt(this.debugGridBmp, 0, 0, this.tileInfo.w, this.tileInfo.h, debugTileLoc.x, debugTileLoc.y, this.tileInfo.w * this.menuZoom, this.tileInfo.h * this.menuZoom);
- }
- }
- }
- // Draw POI's
- for (var i = 0; i < this.getAllPOI().length; i++)
- {
- var poi = this.getPOIByIdx(i);
- var poiLoc = this.translateLocationMenu(this, poi.real_x, poi.real_y, poi.destSize.w, poi.destSize.h);
- Silv.Minimap.Menu.Bmp.blt(poi.bmp, poi.src.x, poi.src.y, poi.src.w, poi.src.h,
- poiLoc.x, poiLoc.y, poi.destSize.w, poi.destSize.h);
- }
- // Draw Events
- for (var i=0; i < Silv.Minimap.Events.length; i++)
- {
- var ev = Silv.Minimap.Events[i].event;
- var ev_sprite = Silv.Minimap.Events[i].sprite;
- var evMapLoc = this.translateLocationMenu(this, ev._realX, ev._realY, Silv.Minimap.Menu.EventRenderSize, Silv.Minimap.Menu.EventRenderSize);
- Silv.Minimap.Menu.Bmp.blt(ev_sprite._bitmap, ev_sprite._frame.x, ev_sprite._frame.y, ev_sprite._frame.width, ev_sprite._frame.height, evMapLoc.x, evMapLoc.y, Silv.Minimap.Menu.EventRenderSize, Silv.Minimap.Menu.EventRenderSize);
- }
- // Draw Player
- if (this.playerBlipEnabled)
- {
- this.drawPlayerBlip(Silv.Minimap.Menu.Bmp, this.translateLocationMenu, this.playerInfo.src.x, this.playerInfo.src.y, this.playerInfo.src.width, this.playerInfo.src.height,
- Silv.Minimap.Menu.PlayerIconSize, Silv.Minimap.Menu.PlayerIconSize);
- }
- };
- //----------------------------------------------------------------------------------------------------
- // Menu Create #Markers
- //----------------------------------------------------------------------------------------------------
- Window_Minimap.prototype.createMenuMarkers = function()
- {
- Silv.Minimap.Menu.Markers = new Array();
- // Player
- var playerMapLoc = this.translateLocationMenu(this, $gamePlayer._realX, $gamePlayer._realY, Silv.Minimap.Menu.PlayerIconSize, Silv.Minimap.Menu.PlayerIconSize);
- Silv.Minimap.Menu.Markers.push({text:'Player', map_x:playerMapLoc.x, map_y:playerMapLoc.y, w:Silv.Minimap.Menu.PlayerIconSize, h:Silv.Minimap.Menu.PlayerIconSize, desc:Silv.Minimap.Menu.PlayerDesc, tp:null});
- // POI's
- for (var i = 0; i < this.getAllPOI().length; i++)
- {
- var poi = this.getPOIByIdx(i);
- var poiLoc = this.translateLocationMenu(this, poi.real_x, poi.real_y, poi.destSize.w, poi.destSize.h);
- var tp = poi.tp.slice(0); // slice(0) clones it
- if (this.allowTeleportation && (poi.tp != null))
- {
- tp[0] = parseInt(tp[0]) + parseInt(poi.real_x);
- tp[1] = parseInt(tp[1]) + parseInt(poi.real_y);
- }
- Silv.Minimap.Menu.Markers.push({text:poi.name, map_x:poiLoc.x, map_y:poiLoc.y, w:poi.destSize.w, h:poi.destSize.h, desc:poi.desc, tp:tp});
- }
- // Events
- for (var i=0; i < Silv.Minimap.Events.length; i++)
- {
- var ev = Silv.Minimap.Events[i].event;
- var evMapLoc = this.translateLocationMenu(this, ev._realX, ev._realY, Silv.Minimap.Menu.EventRenderSize, Silv.Minimap.Menu.EventRenderSize);
- var desc = '';
- if ('mm_desc' in ev) { desc = ev.mm_desc.join(' '); }
- var tp = null;
- if (this.allowTeleportation && ('mm_tp' in ev))
- {
- tp = ev.mm_tp.slice(0); // slice(0) clones it
- tp[0] = parseInt(tp[0]) + parseInt(ev._x);
- tp[1] = parseInt(tp[1]) + parseInt(ev._y);
- }
- Silv.Minimap.Menu.Markers.push({text:dataMapGetEventByID(ev._eventId).name, map_x:evMapLoc.x, map_y:evMapLoc.y, w:Silv.Minimap.Menu.EventRenderSize, h:Silv.Minimap.Menu.EventRenderSize, desc:desc, tp:tp});
- }
- };
- //----------------------------------------------------------------------------------------------------
- // #Rendering #Drawing
- //----------------------------------------------------------------------------------------------------
- Window_Minimap.prototype.setPlayerBlip = function(filename)
- {
- this.usePlayerBlipGfx = (filename == ':player');
- if (this.usePlayerBlipGfx) { this.playerBlipBmp = null; }
- else { this.playerBlipBmp = ImageManager.loadMinimap(filename); }
- };
- Window_Minimap.prototype.drawPlayerBlip = function(destBmp, translateFunc, src_x, src_y, src_w, src_h, dest_w, dest_h)
- {
- var playerMapLoc = translateFunc(this, $gamePlayer._realX, $gamePlayer._realY, dest_w, dest_h);
- if (this.usePlayerBlipGfx)
- {
- destBmp.blt(this.playerInfo.bmp, src_x, src_y, src_w, src_h, playerMapLoc.x, playerMapLoc.y, dest_w, dest_h);
- }
- else
- {
- // Use custom player blip graphic
- if (this.playerBlipBmp.isReady())
- {
- destBmp.blt(this.playerBlipBmp, 0, 0, this.playerBlipBmp.width, this.playerBlipBmp.height, playerMapLoc.x, playerMapLoc.y, dest_w, dest_h);
- }
- }
- };
- Window_Minimap.prototype.drawMinimap = function()
- {
- this.contents.clear();
- // BG fill colour, if applicable
- this.contents.fillRect(Silv.Minimap.BorderWidth, Silv.Minimap.BorderHeight, this.drawAreaWidth, this.drawAreaHeight, Silv.Minimap.MapBGFillColor);
- switch(this.mapStyle)
- {
- case 'autofit':
- this.drawstyleAutofit();
- break;
- case 'scroll':
- this.drawstyleScroll();
- break;
- default:
- throw 'Window_Minimap.prototype.drawMinimap invalid switch value: ' + this.mapStyle;
- }
- };
- Window_Minimap.prototype.drawstyleAutofit = function()
- {
- // Opacity
- this.contents.paintOpacity = this.opacity = Silv.Minimap.Window_Opacity;
- var destination_w = this.drawAreaWidth * this.mapAspRatInfo.w;
- var destination_h = this.drawAreaHeight * this.mapAspRatInfo.h;
- // Calculate the aspect ratio offsets
- this.mapAspRatInfo.offset_x = 0.0; // to center the map
- this.mapAspRatInfo.offset_y = 0.0; // to center the map
- if (this.mapAspRatInfo.w < 1.0) { this.mapAspRatInfo.offset_x = (this.drawAreaWidth - destination_w) / 2.0; }
- if (this.mapAspRatInfo.h < 1.0) { this.mapAspRatInfo.offset_y = (this.drawAreaHeight - destination_h) / 2.0; }
- // This variable saves on calculations further down the road during this update
- // w = width, hw= half width, zhw = zoomed half width
- this.tileInfo = {
- w: $gameMap.tileWidth(), hw: $gameMap.tileWidth() / 2.0, zhw: ($gameMap.tileWidth() / 2.0) * this.mapAspRatInfo.w,
- h: $gameMap.tileHeight(), hh: $gameMap.tileHeight() / 2.0, zhh: ($gameMap.tileHeight() / 2.0) * this.mapAspRatInfo.h
- };
- // Draw Map
- this.contents.blt(this.mapBmp, 0, 0, this.mapBmp.width, this.mapBmp.height, Silv.Minimap.BorderWidth + this.mapAspRatInfo.offset_x, Silv.Minimap.BorderHeight + this.mapAspRatInfo.offset_y, destination_w, destination_h);
- // Debug Grid (if applicable)
- if (Silv.Minimap.DrawDebugGrid)
- {
- for (var i=0; i < $gameMap.width(); i++)
- {
- for (j=0; j < $gameMap.height(); j++)
- {
- var debugTileLoc = this.translateLocationAutofit(this, i, j, this.tileInfo.w * this.mapAspRatInfo.w, this.tileInfo.h * this.mapAspRatInfo.h);
- this.contents.blt(this.debugGridBmp, 0, 0, this.tileInfo.w, this.tileInfo.h, debugTileLoc.x, debugTileLoc.y, this.tileInfo.w * this.mapAspRatInfo.w, this.tileInfo.h * this.mapAspRatInfo.h);
- }
- }
- }
- // Draw POI's
- for (var i = 0; i < this.getAllPOI().length; i++)
- {
- var poi = this.getPOIByIdx(i);
- var poiLoc = this.translateLocationAutofit(this, poi.real_x, poi.real_y, poi.destSize.w, poi.destSize.h);
- this.contents.blt(poi.bmp, poi.src.x, poi.src.y, poi.src.w, poi.src.h,
- poiLoc.x, poiLoc.y, poi.destSize.w, poi.destSize.h);
- }
- // Draw Events
- for (var i=0; i < Silv.Minimap.Events.length; i++)
- {
- var ev = Silv.Minimap.Events[i].event;
- var ev_sprite = Silv.Minimap.Events[i].sprite;
- var evMapLoc = this.translateLocationAutofit(this, ev._realX, ev._realY, Silv.Minimap.EventRenderSize, Silv.Minimap.EventRenderSize);
- this.contents.blt(ev_sprite._bitmap, ev_sprite._frame.x, ev_sprite._frame.y, ev_sprite._frame.width, ev_sprite._frame.height, evMapLoc.x, evMapLoc.y, Silv.Minimap.EventRenderSize, Silv.Minimap.EventRenderSize);
- }
- // Draw Player
- if (this.playerBlipEnabled && this.playerBlink_IsVisible)
- {
- this.drawPlayerBlip(this.contents, this.translateLocationAutofit, this.playerInfo.src.x, this.playerInfo.src.y, this.playerInfo.src.width, this.playerInfo.src.height,
- Silv.Minimap.PlayerIconWidth, Silv.Minimap.PlayerIconHeight);
- }
- // Overlay (if applicable)
- if (Silv.Minimap.DrawOverlay) { this.drawOverlay(); }
- };
- Window_Minimap.prototype.drawstyleScroll = function()
- {
- // Opacity
- this.contents.paintOpacity = this.opacity = Silv.Minimap.Window_Opacity;
- // The minimap is so large it would require a source-map that is bigger. Because of this the entire map fits onto the minimap anyway so might as well switch to autofit instead of displaying a black image
- if (this.mapScroll.x < 0 || this.drawAreaWidth * this.mapZoomInverse > this.mapBmp.width ||
- this.mapScroll.y < 0 || this.drawAreaHeight * this.mapZoomInverse > this.mapBmp.height)
- {
- this.drawstyleAutofit();
- return;
- }
- // This variable saves on calculations further down the road during this update
- // w = width, hw= half width, zhw = zoomed half width
- this.tileInfo = {
- w: $gameMap.tileWidth(), hw: $gameMap.tileWidth() / 2.0, zhw: ($gameMap.tileWidth() / 2.0) * this.mapZoom,
- h: $gameMap.tileHeight(), hh: $gameMap.tileHeight() / 2.0, zhh: ($gameMap.tileHeight() / 2.0) * this.mapZoom
- };
- // Draw Map
- var map_src_rect = { x:0.0, y:0.0, w:0.0, h:0.0};
- map_src_rect.x = this.mapScroll.x;
- map_src_rect.y = this.mapScroll.y;
- map_src_rect.w = this.drawAreaWidth * this.mapZoomInverse;
- map_src_rect.h = this.drawAreaHeight * this.mapZoomInverse;
- this.contents.blt(this.mapBmp, this.mapScroll.x, this.mapScroll.y, this.drawAreaWidth * this.mapZoomInverse, this.drawAreaHeight * this.mapZoomInverse, Silv.Minimap.BorderWidth, Silv.Minimap.BorderHeight, this.drawAreaWidth, this.drawAreaHeight);
- // Debug Grid (if applicable)
- if (Silv.Minimap.DrawDebugGrid)
- {
- for (var i=0; i < $gameMap.width(); i++)
- {
- for (j=0; j < $gameMap.height(); j++)
- {
- var debugTileLoc = this.translateLocationScroll(this, i, j, this.tileInfo.w * this.mapZoom, this.tileInfo.h * this.mapZoom);
- this.contents.blt(this.debugGridBmp, 0, 0, this.tileInfo.w, this.tileInfo.h, debugTileLoc.x, debugTileLoc.y, this.tileInfo.w * this.mapZoom, this.tileInfo.h * this.mapZoom);
- }
- }
- }
- // Draw POI's
- for (var i = 0; i < this.getAllPOI().length; i++)
- {
- var poi = this.getPOIByIdx(i);
- var poiLoc = this.translateLocationScroll(this, poi.real_x, poi.real_y, poi.destSize.w, poi.destSize.h);
- this.contents.blt(poi.bmp, poi.src.x, poi.src.y, poi.src.w, poi.src.h,
- poiLoc.x, poiLoc.y, poi.destSize.w, poi.destSize.h);
- }
- // Draw Events
- for (var i=0; i < Silv.Minimap.Events.length; i++)
- {
- var ev = Silv.Minimap.Events[i].event;
- var ev_sprite = Silv.Minimap.Events[i].sprite;
- var evMapLoc = this.translateLocationScroll(this, ev._realX, ev._realY, Silv.Minimap.EventRenderSize, Silv.Minimap.EventRenderSize);
- this.contents.blt(ev_sprite._bitmap, ev_sprite._frame.x, ev_sprite._frame.y, ev_sprite._frame.width, ev_sprite._frame.height, evMapLoc.x, evMapLoc.y, Silv.Minimap.EventRenderSize, Silv.Minimap.EventRenderSize);
- }
- // Draw Player
- if (this.playerBlipEnabled && this.playerBlink_IsVisible)
- {
- this.drawPlayerBlip(this.contents, this.translateLocationScroll, this.playerInfo.src.x, this.playerInfo.src.y, this.playerInfo.src.width, this.playerInfo.src.height,
- Silv.Minimap.PlayerIconWidth, Silv.Minimap.PlayerIconHeight);
- }
- // Overlay (if applicable)
- if (Silv.Minimap.DrawOverlay) { this.drawOverlay(); }
- };
- Window_Minimap.prototype.drawOverlay = function()
- {
- this.contents.blt(this.overlayBmp, 0, 0, this.overlayBmp.width, this.overlayBmp.height, 0, 0, this.width, this.height);
- };
- //----------------------------------------------------------------------------------------------------
- // #Translate functions
- // Important: Because the translate functions are assigned to a variable, the this-keyword will be undefined! Therefor this can not be used and that's why I used "that" as a parameter :P. Also Silv.Minim.Window may be null so it must be a parameter.
- // For more info see: http://stackoverflow.com/questions/4011793/this-is-undefined-in-javascript-class-methods
- //----------------------------------------------------------------------------------------------------
- // returns {x, y}
- Window_Minimap.prototype.translateLocationScroll = function(that, obj_real_x, obj_real_y, obj_w, obj_h)
- {
- var obj_x = (obj_real_x * that.tileInfo.w + that.tileInfo.hw) * that.mapZoom - that.mapScroll.x * that.mapZoom - obj_w / 2.0 + Silv.Minimap.BorderWidth;
- var obj_y = (obj_real_y * that.tileInfo.h + that.tileInfo.hh) * that.mapZoom - that.mapScroll.y * that.mapZoom - obj_h / 2.0 + Silv.Minimap.BorderHeight;
- return {x: obj_x, y: obj_y};
- };
- // returns {x, y}
- Window_Minimap.prototype.translateLocationAutofit = function(that, obj_real_x, obj_real_y, obj_w, obj_h)
- {
- var obj_x = (obj_real_x * that.tileInfo.w + that.tileInfo.hw) * that.mapAspRatInfo.scaleDelta_x * that.mapAspRatInfo.w - obj_w / 2.0 + that.mapAspRatInfo.offset_x + Silv.Minimap.BorderWidth;
- var obj_y = (obj_real_y * that.tileInfo.h + that.tileInfo.hh) * that.mapAspRatInfo.scaleDelta_y * that.mapAspRatInfo.h - obj_h / 2.0 + that.mapAspRatInfo.offset_y + Silv.Minimap.BorderHeight;
- return {x: obj_x, y: obj_y};
- };
- // returns {x, y}
- Window_Minimap.prototype.translateLocationMenu = function(that, obj_real_x, obj_real_y, obj_w, obj_h)
- {
- var obj_x = (obj_real_x * that.tileInfo.w + that.tileInfo.hw) * that.menuZoom - obj_w / 2.0;
- var obj_y = (obj_real_y * that.tileInfo.h + that.tileInfo.hh) * that.menuZoom - obj_h / 2.0;
- return {x: obj_x, y: obj_y};
- };
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // #POI
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function MM_POI() { this.initialize.apply(this, arguments); }
- // Set Constructor
- MM_POI.prototype.constructor = MM_POI;
- // Initialization
- // real_x & real_y are in tiles
- MM_POI.prototype.initialize = function(poi_id, name, desc, real_x, real_y, folderPath, filename, source_x, source_y, source_w, source_h, draw_w, draw_h)
- {
- this.id = poi_id;
- this.name = name;
- this.desc = desc;
- this.real_x = real_x;
- this.real_y = real_y;
- this.folderPath = folderPath; // Required for saving&loading
- this.filename = filename; // Required for saving&loading
- this.bmp = ImageManager.loadBitmap(folderPath, filename, 0, false);
- this.src = { x:source_x, y:source_y, w:source_w, h:source_h };
- this.destSize = { w:draw_w, h:draw_h };
- this.tp = null;
- };
- // Note: Does not include the Bitmap
- MM_POI.prototype.makeSaveContents = function()
- {
- return { id:this.id, name:this.name, desc:this.desc, real_x:this.real_x, real_y:this.real_y, src:this.src, destSize:this.destSize, folderPath:this.folderPath, filename:this.filename, tp:this.tp };
- };
- // Retrieves all the POI's for the current active $gameMap
- Window_Minimap.prototype.getAllPOI = function()
- {
- return Silv.Minimap.POI[$gameMap._mapId];
- };
- // Retrieves the specified POI by index for the current active $gameMap. Note this is NOT by POI id, this is by index.
- Window_Minimap.prototype.getPOIByIdx = function(index)
- {
- return Silv.Minimap.POI[$gameMap._mapId][index];
- };
- Window_Minimap.prototype.getPOIByID = function(id)
- {
- for (var i=0; i<Silv.Minimap.POI[$gameMap._mapId].length; i++)
- {
- if (Silv.Minimap.POI[$gameMap._mapId][i].id == id) { return Silv.Minimap.POI[$gameMap._mapId][i]; }
- }
- throw 'getPOIByID(' + id + ') not found.';
- };
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // #Create the Minimap window
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //----------------------------------------------------------------------------------------------------
- // Scene Map (alias): Create Display Objects
- //----------------------------------------------------------------------------------------------------
- var alias_silver_mm_createDisplayObjects = Scene_Map.prototype.createDisplayObjects;
- Scene_Map.prototype.createDisplayObjects = function()
- {
- alias_silver_mm_createDisplayObjects.call(this);
- var didMapChange = $gameMap._mapId != Silv.Minimap.LastMapID;
- if (didMapChange)
- {
- if (Silv.Minimap.WasLoadedFromSave)
- {
- Silv.Minimap.WasLoadedFromSave = false;
- }
- else
- {
- if (Silv.Minimap.AutoClearPOI) { Silv.Minimap.POI[$gameMap._mapId] = new Array(); }
- }
- }
- // Create empty POI array if it's not defined yet for this map
- if (typeof Silv.Minimap.POI[$gameMap._mapId] === 'undefined') {Silv.Minimap.POI[$gameMap._mapId] = new Array() };
- this.attemptToCreateMinimap();
- Silv.Minimap.LastMapID = $gameMap._mapId;
- };
- //----------------------------------------------------------------------------------------------------
- // Attempt To Create Minimap
- //----------------------------------------------------------------------------------------------------
- Scene_Map.prototype.attemptToCreateMinimap = function()
- {
- var mapname = lpad_mapname($gameMap._mapId, '0') + '.png';
- var createMinimap = false;
- var minimapType = null;
- var hasRequiredItems = this.MinimapHasRequiredItems();
- if(Silv.Minimap.Window != null)
- {
- // 'Dispose'
- // This is required for values like "Silv.Minimap.Window.visible" to get 'reset' properly. Otherwise they keep the values from an old map which can lead to nasty bugs.
- this.removeWindow(Silv.Minimap.Window); // Required because the Scene_Map still holds a reference to the old minimap, effectively creating 2 or more minimaps if this method creates another one now...
- Silv.Minimap.Window = null;
- }
- var windowWasVisible = Silv.Minimap.Visible;
- if (minimapImageExists(mapname))
- {
- if (hasRequiredItems)
- {
- createMinimap = true;
- minimapType = 'regular';
- }
- }
- else
- {
- if (Silv.Minimap.DebugMode) { console.log('No minimap \'' + mapname + '\' found for map with map-id: ' + $gameMap._mapId + '.'); }
- if (hasRequiredItems)
- {
- if (('mm_generate_worldmap' in $dataMap.meta) || ('mm_generate_overworld' in $dataMap.meta))
- {
- if (Silv.Minimap.DebugMode && !$gameMap.isOverworld()) { console.log('Current map is NOT an overworld map but the minimap is set to treat it like a regular one.'); }
- createMinimap = true;
- minimapType = 'generate_overworld';
- } else if ('mm_generate_map' in $dataMap.meta)
- {
- if (Silv.Minimap.DebugMode && $gameMap.isOverworld()) { console.log('Current map is an overworld map but the minimap is set to treat it like an overworld map.'); }
- createMinimap = true;
- minimapType = 'generate_map';
- }
- }
- }
- if (createMinimap)
- {
- this.createMinimapWindow(minimapType);
- if (!windowWasVisible) { Silv.Minimap.Window.hide(); } // This is to prevent the minimap from showing itself again after opening a menu or when recreating the minimap while staying on the same map.
- if ('mm_generate_passability_overlay' in $dataMap.meta) { Silv.Minimap.Window.setPassabilityOverlay(true); }
- }
- // else
- // {
- //'Dispose'
- //This is required for values like "Silv.Minimap.Window.visible" to get 'reset' properly. Otherwise they keep the values from an old map which can lead to nasty bugs.
- // Silv.Minimap.Window = null;
- // }
- };
- //----------------------------------------------------------------------------------------------------
- // Scene_Base: Remove Window
- //----------------------------------------------------------------------------------------------------
- // Omg why does RPG Maker not have this method by default...
- Scene_Base.prototype.removeWindow = function(window)
- {
- var index = this.children.indexOf(window);
- if (index > -1) { this.children.splice(index, 1); }
- }
- //----------------------------------------------------------------------------------------------------
- // Create Minimap Window
- //----------------------------------------------------------------------------------------------------
- Scene_Map.prototype.createMinimapWindow = function(minimapType)
- {
- var x = 0;
- if (Silv.Minimap.WindowHorizontalAlignment == 'right') { x = Graphics.width - Silv.Minimap.WindowWidth; }
- var y = 0;
- if (Silv.Minimap.WindowVerticalAlignment == 'bottom') { y = Graphics.height - Silv.Minimap.WindowHeight; }
- Silv.Minimap.Window = new Window_Minimap(x + Silv.Minimap.Window_X, y + Silv.Minimap.Window_Y, Silv.Minimap.WindowWidth, Silv.Minimap.WindowHeight, minimapType);
- Silv.Minimap.Window.resetFade();
- // override frameskip (map-specific frameskip)
- if ('mm_frameskip' in $dataMap.meta)
- {
- Silv.Minimap.Window.frameSkip = parseInt($dataMap.meta.mm_frameskip);
- if (Silv.Minimap.DebugMode) { console.log('Global frameskip: ' + Silv.Minimap.FrameSkip + ' was overriden by the map-specific frameskip of: ' + $dataMap.meta.mm_frameskip + '.'); }
- }
- this.addChildAt(Silv.Minimap.Window, 1);
- };
- //----------------------------------------------------------------------------------------------------
- // Has Required Items
- //----------------------------------------------------------------------------------------------------
- Scene_Map.prototype.MinimapHasRequiredItems = function()
- {
- // Check global item
- if (Silv.Minimap.GlobalRequiredItem > 0)
- {
- if (!$gameParty.hasItem($dataItems[Silv.Minimap.GlobalRequiredItem], false))
- {
- if (Silv.Minimap.DebugMode) { console.log('Minimap was found but party does not possess the required global item: ' + $dataItems[Silv.Minimap.GlobalRequiredItem].name); }
- return false;
- }
- }
- // Check map-specific items
- if ('mm_req_itm' in $dataMap.meta)
- {
- var req_item_ids = $dataMap.meta.mm_req_itm.split(' ').filter(Boolean); // .filter(Boolean) removes empty strings from array
- for (var i = 0; i < req_item_ids.length; i++)
- {
- if (!$gameParty.hasItem($dataItems[req_item_ids[i]], false))
- {
- if (Silv.Minimap.DebugMode) { console.log('Minimap was found but party does not possess the required map-specific item: ' + $dataItems[req_item_ids[i]].name); }
- return false;
- }
- }
- }
- return true;
- };
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Saving & Loading #Save #Saving #Loading
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- var alias_silv_mm_makeSaveContents = DataManager.makeSaveContents;
- DataManager.makeSaveContents = function()
- {
- contents = alias_silv_mm_makeSaveContents.call(this);
- contents.minimap = {};
- contents.minimap.poi = {};
- // POI
- for (var mapID in Silv.Minimap.POI)
- {
- if (Silv.Minimap.POI.hasOwnProperty(mapID))
- {
- if(Silv.Minimap.POI[mapID].length > 0) { contents.minimap.poi[mapID] = new Array(); }
- for(var poi_idx=0; poi_idx<Silv.Minimap.POI[mapID].length; poi_idx++)
- {
- contents.minimap.poi[mapID].push(Silv.Minimap.Window.getPOIByIdx(poi_idx).makeSaveContents());
- }
- }
- }
- return contents;
- };
- var alias_silv_mm_extractSaveContents = DataManager.extractSaveContents;
- DataManager.extractSaveContents = function(contents)
- {
- alias_silv_mm_extractSaveContents.call(this, contents);
- Silv.Minimap.POI = {};
- // POI
- for (var mapID in contents.minimap.poi)
- {
- if (contents.minimap.poi.hasOwnProperty(mapID))
- {
- if(contents.minimap.poi[mapID].length > 0) { Silv.Minimap.POI[mapID] = new Array(); }
- for(var poi_idx=0; poi_idx<contents.minimap.poi[mapID].length; poi_idx++)
- {
- var poi = contents.minimap.poi[mapID][poi_idx];
- var newPOI = new MM_POI(poi.id, poi.name, poi.desc, poi.real_x, poi.real_y, poi.folderPath, poi.filename, poi.src.x, poi.src.y, poi.src.w, poi.src.h, poi.destSize.w, poi.destSize.h);
- newPOI.tp = poi.tp;
- Silv.Minimap.POI[mapID].push(newPOI);
- }
- }
- }
- // Prevent the minimap from autoclearing it's POI's (if AutoClearPOI is enabled) when loading a savegame
- Silv.Minimap.WasLoadedFromSave = true;
- };
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // #Plugin Command
- // Note: The items are separated by spaces. The command is the first word and any following words are args. args is an array.
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
- Game_Interpreter.prototype.pluginCommand = function(command, args)
- {
- _Game_Interpreter_pluginCommand.call(this, command, args);
- if (command.toLowerCase() == 'minimap') { PluginCommand(command, args); }
- };
- function PluginCommand(cmd, args)
- {
- switch(args[0].toLowerCase())
- {
- case 'hide':
- Silv.Minimap.Window.hide();
- break;
- case 'show':
- Silv.Minimap.Window.show();
- break;
- case 'fadeout':
- Silv.Minimap.Window.isFadingOut = true;
- break;
- case 'fadereset':
- Silv.Minimap.Window.resetFade();
- break;
- case 'refresh':
- SceneManager._scene.attemptToCreateMinimap(false);
- break;
- case 'addpoi': // addpoi id, name, desc, real_x, real_y, bitmap folder, bitmap filename, s_x, s_y, s_w, s_h, draw_w, draw_h
- Silv.Minimap.POI[$gameMap._mapId].push(new MM_POI(args[1], args[2].replace('_', ' '), '', parseFloat(args[3]), parseFloat(args[4]), args[5], args[6], parseInt(args[7]), parseInt(args[8]), parseInt(args[9]), parseInt(args[10]), parseInt(args[11]), parseInt(args[12])));
- SceneManager._scene.attemptToCreateMinimap(false);
- break;
- case 'deletepoi':
- Silv.Minimap.POI[$gameMap._mapId] = Silv.Minimap.POI[$gameMap._mapId].filter(function(poi) { return poi.id != args[1]; });
- break;
- case 'poidesc':
- Silv.Minimap.Window.getPOIByID(parseInt(args[1])).desc = args.join(' ').substr(2 + args[0].length + args[1].length);
- break;
- case 'poi_tp': // POI_TP <poi_id x_offset, y_offset, direction, fadeType>
- Silv.Minimap.Window.getPOIByID(parseInt(args[1])).tp = [parseInt(args[2]), parseInt(args[3]), parseInt(args[4]), parseInt(args[5])]
- break;
- case 'refreshevents':
- Silv.Minimap.Window.loadEvents();
- break;
- case 'increasescroll':
- Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x + parseFloat(args[1]), Silv.Minimap.Window.mapScroll.y + parseFloat(args[2]));
- break;
- case 'setscroll':
- Silv.Minimap.Window.manualScroll(parseFloat(args[1]), parseFloat(args[2]));
- break;
- case 'generate_passability_overlay':
- case 'gen_pass_ov':
- Silv.Minimap.setPassabilityOverlay(args[1].toLowerCase() == 'true');
- break;
- case 'showmapmenu':
- Silv.Minimap.Window.showMapMenuScene();
- break;
- case 'setplayerblip':
- Silv.Minimap.Window.setPlayerBlip(args[1]);
- break;
- case 'setmapstyle':
- Silv.Minimap.Window.mapStyle = args[1].toLowerCase();
- break;
- default:
- throw 'Minimap, unknown Plugin Command: ' + args[0];
- }
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- })();
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Map Menu #Scene
- // Note: Must be placed outside of the })();
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function Scene_MiniMap() { this.initialize.apply(this, arguments); }
- Scene_MiniMap.prototype = Object.create(Scene_MenuBase.prototype);
- Scene_MiniMap.prototype.constructor = Scene_MiniMap;
- Scene_MiniMap.prototype.initialize = function()
- {
- Scene_MenuBase.prototype.initialize.call(this);
- SoundManager.playOk();
- };
- Scene_MiniMap.prototype.create = function()
- {
- Scene_MenuBase.prototype.create.call(this);
- this.createLeftWindow();
- this.createMapSectionWindow();
- this.createMapHelpWindow();
- this.refreshHelpWindow();
- };
- Scene_MiniMap.prototype.createLeftWindow = function()
- {
- this._window_left = new Window_MinimapMenuLeft(0, 0);
- this._window_left.setHandler('ok', this.onRangeOk.bind(this));
- this._window_left.setHandler('cancel', this.popScene.bind(this));
- this._window_left.setHandler('index_changed', this.index_changed.bind(this));
- this.addWindow(this._window_left);
- };
- Scene_MiniMap.prototype.createMapSectionWindow = function()
- {
- var wx = this._window_left.width;
- var ww = Graphics.boxWidth - wx;
- this._mapSectionWindow = new Window_MapSection(wx, 0, ww);
- this._mapSectionWindow.setHandler('cancel', this.onEditCancel.bind(this));
- this._window_left.setMapWindow(this._mapSectionWindow);
- this.addWindow(this._mapSectionWindow);
- };
- Scene_MiniMap.prototype.createMapHelpWindow = function()
- {
- var wx = this._mapSectionWindow.x;
- var wy = this._mapSectionWindow.height;
- var ww = this._mapSectionWindow.width;
- var wh = Graphics.boxHeight - wy;
- this._mapHelpWindow = new Window_Base(wx, wy, ww, wh);
- this.addWindow(this._mapHelpWindow);
- };
- Scene_MiniMap.prototype.index_changed = function()
- {
- this.refreshHelpWindow();
- };
- Scene_MiniMap.prototype.onRangeOk = function()
- {
- this._mapSectionWindow.activate();
- this._mapSectionWindow.select(0);
- this.refreshHelpWindow();
- };
- Scene_MiniMap.prototype.onEditCancel = function()
- {
- this._window_left.activate();
- this._mapSectionWindow.deselect();
- this.refreshHelpWindow();
- };
- Scene_MiniMap.prototype.refreshHelpWindow = function()
- {
- this._mapHelpWindow.contents.clear();
- this._mapHelpWindow.drawTextEx(this.helpText(), 4, 0);
- };
- Scene_MiniMap.prototype.helpText = function()
- {
- var marker = this._window_left.marker();
- var tp_text = '';
- if (marker.tp != null) { tp_text = '\nTeleports you to: ' + marker.tp[0] + ',' + marker.tp[1]; }
- return this._window_left.marker().desc + tp_text;
- };
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Left Window #leftwindow
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function Window_MinimapMenuLeft() { this.initialize.apply(this, arguments); }
- Window_MinimapMenuLeft.prototype = Object.create(Window_Selectable.prototype);
- Window_MinimapMenuLeft.prototype.constructor = Window_MinimapMenuLeft;
- Window_MinimapMenuLeft.lastTopRow = 0;
- Window_MinimapMenuLeft.lastIndex = 0;
- Window_MinimapMenuLeft.prototype.initialize = function(x, y)
- {
- var width = this.windowWidth();
- var height = this.windowHeight();
- Window_Selectable.prototype.initialize.call(this, x, y, width, height);
- this.refresh();
- this.setTopRow(Window_MinimapMenuLeft.lastTopRow);
- this.select(Window_MinimapMenuLeft.lastIndex);
- this.activate();
- };
- Window_MinimapMenuLeft.prototype.windowWidth = function()
- {
- return Silv.Minimap.Menu.WindowWidth_Left;
- };
- Window_MinimapMenuLeft.prototype.windowHeight = function()
- {
- return Graphics.boxHeight;
- };
- Window_MinimapMenuLeft.prototype.maxItems = function()
- {
- return Silv.Minimap.Menu.Markers.length;
- };
- Window_MinimapMenuLeft.prototype.update = function()
- {
- Window_Selectable.prototype.update.call(this);
- if (this._mapWindow) { this._mapWindow.setMarker(this.marker()); }
- if (this.index() != Window_MinimapMenuLeft.lastIndex)
- {
- Window_MinimapMenuLeft.lastIndex = this.index();
- this.callHandler('index_changed');
- }
- if (Input.isTriggered('ok'))
- {
- var marker = this.marker();
- if(marker.tp != null)
- {
- // Add the teleport location to the minimap and dequeue this scene to return to the previous scene
- SoundManager.playOk();
- Silv.Minimap.TP_Dest = marker.tp;
- SceneManager.pop();
- }
- }
- if (Input.isTriggered(Silv.Minimap.Menu.MenuKey))
- {
- SoundManager.playCancel();
- SceneManager.pop();
- }
- };
- Window_MinimapMenuLeft.prototype.marker = function()
- {
- return Silv.Minimap.Menu.Markers[this.index()];
- };
- Window_MinimapMenuLeft.prototype.refresh = function()
- {
- this.createContents();
- this.drawAllItems();
- };
- Window_MinimapMenuLeft.prototype.drawItem = function(index)
- {
- var rect = this.itemRectForText(index);
- var text = Silv.Minimap.Menu.Markers[index].text;
- this.drawText(text, rect.x, rect.y, rect.width);
- };
- Window_MinimapMenuLeft.prototype.isCancelTriggered = function()
- {
- return (Window_Selectable.prototype.isCancelTriggered());
- };
- Window_MinimapMenuLeft.prototype.processCancel = function()
- {
- Window_Selectable.prototype.processCancel.call(this);
- Window_MinimapMenuLeft.lastTopRow = this.topRow();
- Window_MinimapMenuLeft.lastIndex = this.index();
- };
- Window_MinimapMenuLeft.prototype.setMapWindow = function(mapWindow)
- {
- this._mapWindow = mapWindow;
- this.update();
- };
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Map Section Window
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function Window_MapSection() { this.initialize.apply(this, arguments); }
- Window_MapSection.prototype = Object.create(Window_Selectable.prototype);
- Window_MapSection.prototype.constructor = Window_MapSection;
- Window_MapSection.prototype.initialize = function(x, y, width)
- {
- var height = Silv.Minimap.Menu.WindowHeight_MapSection;
- Window_Selectable.prototype.initialize.call(this, x, y, width, height);
- this._marker = 1;
- this.mapScroll = {x:0, y:0};
- this.mapZoom = 1.0;
- this.centerLoc = {x:width / 2.0, y: height / 2.0};
- this.refresh();
- };
- // Hide the cursor
- Window_MapSection.prototype.updateCursor = function()
- {
- this.setCursorRect(0,0,0,0);
- }
- Window_MapSection.prototype.maxItems = function() { return 0; };
- Window_MapSection.prototype.refresh = function()
- {
- this.contents.clear();
- this.drawMap();
- };
- // Prevent anything from being drawn in the base-class
- Window_MapSection.prototype.drawAllItems = function(){};
- Window_MapSection.prototype.drawMap = function()
- {
- this.contents.blt(Silv.Minimap.Menu.Bmp, 0, 0, Silv.Minimap.Menu.Bmp.width, Silv.Minimap.Menu.Bmp.height, this.mapScroll.x, this.mapScroll.y, Silv.Minimap.Menu.Bmp.width * this.mapZoom, Silv.Minimap.Menu.Bmp.height * this.mapZoom);
- };
- Window_MapSection.prototype.centerOnMarker = function(marker)
- {
- this.mapScroll.x = this.centerLoc.x - marker.map_x - marker.w / 2.0;
- this.mapScroll.y = this.centerLoc.y - marker.map_y - marker.h / 2.0;
- this.refresh();
- }
- Window_MapSection.prototype.setMarker = function(marker)
- {
- if (this._marker !== marker) {
- this._marker = marker;
- this.centerOnMarker(marker)
- }
- };
- Window_MapSection.prototype.update = function()
- {
- Window_Selectable.prototype.update.call(this);
- if (this.active) {
- if (Input.isPressed('up')) { this.mapScroll.y += 10; this.refresh(); }
- if (Input.isPressed('right')) { this.mapScroll.x -= 10; this.refresh(); }
- if (Input.isPressed('down')) { this.mapScroll.y -= 10; this.refresh(); }
- if (Input.isPressed('left')) { this.mapScroll.x += 10; this.refresh(); }
- if (Input.isPressed(Silv.Minimap.Menu.ManualScrollKey_Reset)) { this.mapScroll.x = 0; this.mapScroll.y = 0; this.refresh(); }
- if (Input.isPressed(Silv.Minimap.Menu.ManualZoomKey_In))
- {
- this.mapZoom += 0.05;
- if (this.mapZoom > Silv.Minimap.Menu.ManualZoom_Max) { this.mapZoom = Silv.Minimap.Menu.ManualZoom_Max; }
- this.refresh();
- }
- if (Input.isPressed(Silv.Minimap.Menu.ManualZoomKey_Out))
- {
- this.mapZoom -= 0.05;
- if (this.mapZoom < Silv.Minimap.Menu.ManualZoom_Min) { this.mapZoom = Silv.Minimap.Menu.ManualZoom_Min; }
- this.refresh();
- }
- if (Input.isPressed(Silv.Minimap.Menu.ManualZoomKey_Reset)) { this.mapZoom = 1.0; this.refresh(); }
- }
- };
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // This is the end of this awesome script! Why did you even read this line ;)
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement