Advertisement
Guest User

Untitled

a guest
Jan 28th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // SilvMinimap.js
  3. // Version: 1.12
  4. // Requires plugin: SilvKeys (place this one below it)
  5. //=============================================================================
  6. /*:
  7.  * @plugindesc v1.12 Minimap. <SilvMinimap>
  8.  * @author Silver
  9.  * @param -- General --
  10.  *
  11.  * @param Map Style
  12.  * @desc Is the minimap scaled to fit? Or does it zoom and scroll? Autofit/Scroll
  13.  * @default Scroll
  14.  *
  15.  * @param Global Map Zoom
  16.  * @desc Only applies if MapStyle is set to: Scroll. Determines the default zoom level for all maps. A value of 1 means 1:1.
  17.  * @default 0.25
  18.  *
  19.  * @param Minimap Opacity
  20.  * @desc 0 = invisible, 255 = fully opaque.
  21.  * @default 255
  22.  *
  23.  * @param -- Positioning & Size --
  24.  *
  25.  * @param X
  26.  * @desc x-location of minimap window. If window-alignment is set to Right, this will act as an offset value instead
  27.  * @default -2
  28.  *
  29.  * @param Y
  30.  * @desc y-location of minimap window. If window-alignment is set to Top, this will act as an offset value instead
  31.  * @default 2
  32.  *
  33.  * @param Horizontal Alignment
  34.  * @desc Left/Right
  35.  * @default Right
  36.  *
  37.  * @param Vertical Alignment
  38.  * @desc Top/Bottom
  39.  * @default Bottom
  40.  *
  41.  * @param Width
  42.  * @desc width of the minimap
  43.  * @default 320
  44.  *
  45.  * @param Height
  46.  * @desc height of the minimap
  47.  * @default 320
  48.  *
  49.  * @param Border Width
  50.  * @desc Border width of the minimap
  51.  * @default 12
  52.  *
  53.  * @param Border Height
  54.  * @desc Border height of the minimap
  55.  * @default 12
  56.  *
  57.  * @param -- Player Blip --
  58.  *
  59.  * @param Render Player Blip
  60.  * @desc Render the player blip in the minimap (=usually the center icon)? true/false
  61.  * @default true
  62.  *
  63.  * @param Player Blip Graphic
  64.  * @desc Name of the image (in /img/minimap/) to use as the blip. or use :player to use the realtime-player-graphic.
  65.  * @default :player
  66.  *
  67.  * @param Player Icon Width
  68.  * @desc Standard Window Padding
  69.  * @default 16
  70.  *
  71.  * @param Player Icon Height
  72.  * @desc Standard Window Padding
  73.  * @default 16
  74.  *
  75.  * @param Player Blink Delay
  76.  * @desc Blinks the player icon (in frames). Set to 0 to disable. Does nothing if "Draw Player Icon" is set to false
  77.  * @default 0
  78.  *
  79.  * @param -- Menu --
  80.  *
  81.  * @param Menu Key
  82.  * @desc The key used to show the map-menu. Use none to disable.
  83.  * @default m
  84.  *
  85.  * @param Menu Player Description
  86.  * @desc The description of the player marker in the menu. Spaces are allowed.
  87.  * @default You
  88.  *
  89.  * @param Menu Zoom
  90.  * @desc Map Zoomlevel for the menu
  91.  * @default 0.3. A value of 1 means 1:1
  92.  *
  93.  * @param Menu Left Window Width
  94.  * @desc Width of the left window
  95.  * @default 240
  96.  *
  97.  * @param Menu Topright Window Height
  98.  * @desc Height of the topright window
  99.  * @default 510
  100.  *
  101.  * @param Menu Event Render Size
  102.  * @desc How big the events are that are drawn onto the menu map
  103.  * @default 24
  104.  *
  105.  * @param Menu Player Icon Size
  106.  * @desc How big the player is drawn onto the menu map
  107.  * @default 64
  108.  *
  109.  * @param Menu Min Manual Zoom
  110.  * @desc How far the player can zoom out
  111.  * @default 0.20
  112.  *
  113.  * @param Menu Max Manual Zoom
  114.  * @desc How far the player can zoom in
  115.  * @default 10.0
  116.  *
  117.  * @param Menu Zoomin Key
  118.  * @desc Key for zooming in. 33 = pageup
  119.  * @default pageup
  120.  *
  121.  * @param Menu Zoomout Key
  122.  * @desc Key for zooming out. 34 = pagedown
  123.  * @default pagedown
  124.  *
  125.  * @param Menu Reset Zoom Key
  126.  * @desc Key for resetting the zoom. 36 = home
  127.  * @default home
  128.  *
  129.  * @param Menu Reset Scroll Key
  130.  * @desc Key to reset the mapscroll
  131.  * @default end
  132.  *
  133.  * @param -- Passability Map --
  134.  *
  135.  * @param Passability Overlay Opacity
  136.  * @desc 0 = invisible, 255 = fully opaque. 0-255
  137.  * @default 128
  138.  *
  139.  * @param Passability Color
  140.  * @desc Color for walkable tiles
  141.  * @default #6B8E23
  142.  *
  143.  * @param Impassability Color
  144.  * @desc Color for unwalkable tiles
  145.  * @default #FF0000
  146.  *
  147.  * @param -- Map Generator --
  148.  *
  149.  * @param Map Gen Tag Colors
  150.  * @desc 0-7, use a ####### value to ignore that terrain-tag. Default: lightgreen, blue, brown, darkgreen, lightbrown
  151.  * @default #6B8E23 #00008B #8B4513 #006400 #F4A460 ####### ####### #FFFFFF
  152.  *
  153.  * @param Overworld Gen Tag Colors
  154.  * @desc 0-7, use a ####### value to ignore that terrain-tag. Default: lightgreen, blue, brown, darkgreen, lightbrown
  155.  * @default #6B8E23 #00008B #8B4513 #006400 #F4A460 ####### ####### #FFFFFF
  156.  *
  157.  * @param -- The rest --
  158.  *
  159.  * @param Allow Teleportation
  160.  * @desc By default, allow teleportation to events/poi's that support it? true/false
  161.  * @default true
  162.  *
  163.  * @param Standard Padding
  164.  * @desc Standard Window Padding. Best to leave at 0
  165.  * @default 0
  166.  *
  167.  * @param Window Skin
  168.  * @desc Name of the window skin to use for this window
  169.  * @default Window_Minimap
  170.  *
  171.  * @param Fill Color
  172.  * @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.
  173.  * @default 0 0 0 255
  174.  *
  175.  * @param Maintain Aspect Ratio
  176.  * @desc Maintains minimap aspect ratio if set to true. true/false
  177.  * @default true
  178.  *
  179.  * @param Fadeout Speed
  180.  * @desc How fast the minimap fades out
  181.  * @default 3
  182.  *
  183.  * @param Global Required Item
  184.  * @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
  185.  * @default 0
  186.  *
  187.  * @param Event Render Size
  188.  * @desc How big the events are that are drawn onto the minimap
  189.  * @default 16
  190.  *
  191.  * @param Auto Clear POI
  192.  * @desc Automatically clear POI's between map transfers? true/false
  193.  * @default false
  194.  *
  195.  * @param Render Minimap Overlay
  196.  * @desc If enabled, add the image: /img/minimap/Overlay.png and it will be drawn on top of the minimap. true/false
  197.  * @default true
  198.  *
  199.  * @param -- Fog of War --
  200.  *
  201.  * @param FoW Enabled
  202.  * @desc Enable Fog of War? Can be overridden on a per-map-basis. true/false
  203.  * @default false
  204.  *
  205.  * @param Default FoW Overlay
  206.  * @desc The default Fog of War (PNG) overlay image name in "<project>/img/minimap/"
  207.  * @default FoW
  208.  *
  209.  * @param Default FoW Radius
  210.  * @desc How far into the FoW the player can see.
  211.  * @default 5
  212.  *
  213.  * @param -- Manual Scrolling --
  214.  *
  215.  * @param Allow Manual Scrolling
  216.  * @desc true/false
  217.  * @default true
  218.  *
  219.  * @param Manual Scrollspeed
  220.  * @desc How fast the map is scrolled
  221.  * @default 24
  222.  *
  223.  * @param Manual Scroll Key Up
  224.  * @desc Key for scrolling the map upwards. Default: u  http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
  225.  * @default u
  226.  *
  227.  * @param Manual Scroll Key Right
  228.  * @desc Key for scrolling the map upwards. Default: k
  229.  * @default k
  230.  *
  231.  * @param Manual Scroll Key Down
  232.  * @desc Key for scrolling the map upwards. Default: j
  233.  * @default j
  234.  *
  235.  * @param Manual Scroll Key Left
  236.  * @desc Key for scrolling the map upwards. Default: h
  237.  * @default h
  238.  *
  239.  * @param -- Advanced & Debug --
  240.  *
  241.  * @param Player Sprite Sourceframe Width
  242.  * @desc Width of the playersprite sourceframe
  243.  * @default 48
  244.  *
  245.  * @param Player Sprite Sourceframe Height
  246.  * @desc Heigth of the playersprite sourceframe
  247.  * @default 48
  248.  *
  249.  * @param Frame Skip
  250.  * @desc Skips some minimap calculations&rendering if set to value > 0 to safe performance. The value equals the amount of frames skipped.
  251.  * @default 0
  252.  *
  253.  * @param Mapshot Filename Length
  254.  * @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
  255.  * @default 3
  256.  *
  257.  * @param Debug Mode
  258.  * @desc Prints extra info if set to true. true/false
  259.  * @default false
  260.  *
  261.  * @param Render Debug Grid
  262.  * @desc Draws a debug grid. Requires "/img/Minimap/DebugGrid.png" which is 48x48 in size. Drains a lot of performance!
  263.  * @default false
  264.  *
  265.  * @param Debug Grid Image
  266.  * @desc Name of the debug-grid image
  267.  * @default DebugGrid01
  268.  *
  269.  * @help
  270.  * 1. Make a mapshot of your map. You may use http://forums.rpgmakerweb.com/index.php?/topic/49711-orange-mapshot/
  271.  * 2. Install this script: http://pastebin.com/FF6jh3S0 and make sure to put it above the minimap script.
  272.  * 3. Copy the files to:
  273.  * 4. /img/minimap/Overlay.png
  274.  * 5. /img/minimap/DebugGrid01.png
  275.  * 6. /img/system/Window_Minimap.png
  276.  * 7. Place your mapshots in the /img/minimap/ directory and rename them 001.png, 002.png etc. (matching the id of your map)
  277.  *
  278.  * - If you prefer to use automatic generated maps instead, use the map-notetags and you then obviously do not require mapshots of course.
  279.  * - To enable Fog of War, copy the new FoW.png to the <project>/img/minimap/ folder and set the parameter "FoW Enabled" to true. And make sure that the current map has a minimap of course ;).
  280.  *   FoW also works for generated maps. POI's and Events however will always be displayed on top of the FoW. This is intended.
  281.  *
  282.  *--------------------------------------
  283.  * Yanfly's Main Menu Manager Setup (optional)
  284.  *--------------------------------------
  285.  *
  286.  * 1. Download & Install YEP_MainMenuManager.js
  287.  * 2. Configure the parameters as follow:
  288.  * Menu Name: "Map"
  289.  * Menu Symbol: silvMap
  290.  * Menu Show: true
  291.  * Menu Enabled: Silv.Minimap.Menu.Enabled
  292.  * Menu Main Bind: this.commandSilvMap.bind(this)
  293.  *
  294.  *--------------------------------------
  295.  * Map notetags (most are case sensitive!)
  296.  *--------------------------------------
  297.  * <mm_req_itm:item_id1 item_id2 etc>
  298.  * Example: <mm_req_itm:1, 2, 3>
  299.  *
  300.  * <mm_mapstyle:Scroll/Autofit>
  301.  * Examples:
  302.  * <mm_mapstyle:Scroll>
  303.  * <mm_mapstyle:AutoFit>
  304.  *
  305.  * <mm_frameskip:value>
  306.  * Example: <mm_frameskip:1>
  307.  * Note: overrides the global frameskip parameter for this map
  308.  *
  309.  * <mm_mapzoom:value>
  310.  * Example: <mm_mapzoom:0.15>
  311.  * Note: overrides the global mapzoom parameter for this map
  312.  *
  313.  * <mm_allowmanualscroll:value>
  314.  * Example: <mm_allowmanualscroll:false>
  315.  * Allowed values: true/false
  316.  * Note: overrides the global "Allow Manual Scrolling" parameter for this map
  317.  *
  318.  * <mm_menuzoom:value>
  319.  * Example: <mm_menuzoom:0.75>
  320.  * Note: overrides the global "Menu Zoom" parameter for this map
  321.  *
  322.  * <mm_size:x y>
  323.  * Example: <mm_size:128 128>
  324.  * Note: overrides the global "Width" and "Height" parameters for this map
  325.  *
  326.  * Allow/disallow teleportation.
  327.  * <mm_tp_allow:value>
  328.  * Example: <mm_tp_allow:false>
  329.  * Note: overrides the global "Allow Teleportation" parameter for this map
  330.  *
  331.  * Generate a worldmap-minimap if there is no image (does increase load-time, the first time, for the map)
  332.  * <mm_generate_worldmap>
  333.  * <mm_generate_overworld>
  334.  *
  335.  * Generate regular map (same as mm_generate_overworld but uses a different parameter-color-generator-tag)
  336.  * <mm_generate_map>
  337.  *
  338.  * Generate and overlay a generated passability-map on top of the minimap
  339.  * <mm_generate_passability_overlay>
  340.  *
  341.  * Change the player-blip
  342.  * <mm_player_blip:value>
  343.  * Example to use the realtime player graphic:
  344.  * <mm_player_blip::player>
  345.  * Example to use a custom blip graphic:
  346.  * <mm_player_blip:myCustomPlayerBlip>
  347.  * Note that in the above example, the game requires the image /img/minimap/myCustomPlayerBlip.png"
  348.  *
  349.  * Use another map's mapshot (handy for duplicate maps)
  350.  * <mm_mapshot:map_id>
  351.  * Example: <mm_mapshot:2>
  352.  * Note: leading zero's are optional but not required.
  353.  *
  354.  * To use a different map-image for the map-scene:
  355.  * <mm_menu_bg:imageName>
  356.  * Example: <mm_menu_bg:myFantasticMap>
  357.  * Note1: Must be in png-format
  358.  * Note2: Must be placed in the same folder that also stores the mapshots
  359.  * Note3: If the size differs from the real mapshot (or generated map) then positioning of objects like the player-location may occur. So respect the original size!
  360.  *
  361.  * <mm_fow_enabled:value> // value: true/false
  362.  * Example: <mm_fow_enabled:false>
  363.  * Note: overrides the default "FoW Enabled" parameter
  364.  *
  365.  * <mm_fow_ov:value> // value: name of PNG-image placed in <project>/img/minimap/
  366.  * Example: <mm_fow_enabled:FoW2>
  367.  * Note: overrides the default "Default FoW Overlay" parameter
  368.  *
  369.  * <mm_fow_radius:value> // value is an integer value with a minimum value of 0.
  370.  *
  371.  * <mm_fow_completion:value> // an integer value (positive or negative) that will add/subtract to the total amount of 'explorable' tiles count for the Fog of War. This will only affect the completion % (how many tiles the player revealed for that map).
  372.  *
  373.  *--------------------------------------
  374.  * Event notetags (not case sensitive)
  375.  *--------------------------------------
  376.  * mm_show
  377.  *
  378.  *--------------------------------------
  379.  * Plugin Commands (not case-sensitive)
  380.  *--------------------------------------
  381.  * Minimap Hide
  382.  * Minimap Show
  383.  * Minimap FadeOut
  384.  * Minimap FadeReset
  385.  * Minimap Refresh
  386.  * Minimap RefreshEvents
  387.  * Minimap IncreaseScroll <x> <y>
  388.  * Minimap SetScroll <x> <y>
  389.  * Minimap DeletePOI <poi_id>
  390.  * Minimap Generate_Passability_Overlay <true/false>
  391.  * Minimap Gen_Pass_Ov <true/false>
  392.  * Minimap ShowMapMenu
  393.  * Minimap SetPlayerBlip <filename/:player>
  394.  *
  395.  * Minimap SetFollowTarget <type> <value>
  396.  * Minimap setcamera <type> <value>
  397.  * Allowed types: player, event, coordinate
  398.  * Note: the player-type has no value parameter.
  399.  * Examples:
  400.  * Minimap SetFollowTarget player
  401.  * Minimap SetFollowTarget event 1
  402.  * Minimap SetFollowTarget coordinate 10 20
  403.  *
  404.  * Minimap POIDesc <description>
  405.  * Example: Minimap POIDesc An Awesome City!
  406.  *
  407.  * Minimap POI_TP <poi_id x_offset y_offset direction fadeType>
  408.  * Example: Minimap POI_TP 1 1 0 0 0
  409.  * Note that teleporting with both offsets set to 0, will teleport the player straight into the center of the poi.
  410.  *
  411.  * Adding POI's (advanced plugin command!):
  412.  * 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
  413.  * Example that draws Actor1_3 on tile 10,10:
  414.  * Minimap AddPOI 1 A_Friend 10 10 img/enemies/ Actor1_3 0 0 254 225 64 64
  415.  * Note:
  416.  * - The real_x & real_y are in maptiles and not in coordinates. 0,0 is in the upper left corner.
  417.  * - name-value replaces underscores _  with spaces.
  418.  *
  419.  * Minimap FoWShowTile x y
  420.  * Minimap FoWHideTile x y
  421.  * Example: Minimap FoWShowTile 10 15
  422.  * Note: no sanity-checks are performed for these 2 plugin commands. So for example: if you show/hide a tile outside of the map boundaries or supply a NaN-value or other weird value for the x&y, it's your problem.
  423.  *
  424.  * Minimap FoWChangeTiles x1 y1 x2 y2 reveal // reveal: true/false
  425.  * Example to reveal all tiles between 10,10 and 15,15:
  426.  * Minimap FoWChangeTiles 10 10 15 15 true
  427.  *
  428.  * Minimap FoWRevealTiles x1, y1, x2, y2
  429.  * Minimap FoWHideTiles x1, y1, x2, y2
  430.  * Minimap FoWRevealAll
  431.  *
  432.  * To fully cover the map again in FoW:
  433.  * Minimap FoWReset value // value is optional and defaults to true. value: true/false. When the value is set to false, the minimap won't remove the FoW around the player immediately after this plugin command.
  434.  * Minimap FoWHideAll     // is same as "Minimap FoWReset" shown above.
  435.  *--------------------------------------
  436.  * Event comment-tags (case sentitive!)
  437.  *--------------------------------------
  438.  * To show an event on the minimap:
  439.  * <mm_show>
  440.  *
  441.  * To add a description to an event (for the minimap-scene)
  442.  * <mm_desc>
  443.  *
  444.  * To add teleport to the event:
  445.  * <mm_tp:offset_x offset_y direction fadeType>
  446.  * Example: <mm_tp:1 0 2 0>
  447.  * Notes:
  448.  *        - Offset is the offset in tiles with the event-location itself being 0 0
  449.  *        - Possible direction values: 2 (down), 4 (left), 6 (right), 8 (up). Or use a value of 0 to maintain the current player-facing-direction
  450.  *        - Possible fadeType values: 0 (black), 1 (white), 2 (none)
  451.  *
  452.  *
  453.  * Note to other scripters: You can access the variable that contains the window through this: "Silv.Minimap.Window" w/o the quotes.
  454.  *
  455.  *
  456.  *--------------------------------------
  457.  * Script Calls & Event triggers (for advanced users & scripters ONLY!)
  458.  *--------------------------------------
  459.  * Getting a reference to the minimap window:
  460.  * Silv.Minimap.Window
  461.  *
  462.  * Retrieving the Fog of War completion status:
  463.  * Silv.Minimap.getFowCompletion(mapId);
  464.  * Note 1: mapId is optional (if a map is active) and when left out, it will be replaced with the id of the current map.
  465.  * Note 2: It will return an object
  466.  *
  467.  * Silv.Minimap.Window.onFullyRevealedMap(x, y) is called whenever the map is fully revealed (no more Fog of War tiles left) by the player and the x, y are the coordinates of the last revealed tile.
  468.  *
  469.  *--------------------------------------
  470.  * #Version #History:
  471.  *--------------------------------------
  472.  * v1.12 (28 January 2016)
  473.  *   - Fixed a crash when the height of the map was bigger than it's width.
  474.  *
  475.  * v1.11 (03 January 2016) [Updated Parameters]
  476.  *   - Added Fog of War with new plugin commands. It obviously also works with looping maps, comes with persistence and you can determine what maps have FoW and which don't.
  477.  *     - You can optionally customize the Fog overlay image on a per-map-basis.
  478.  *     - Added a sample Fog of War overlay-image (FoW.png) to the forum post. I made it using the "The Gimp".
  479.  *     - New map-notetags: <mm_fow_enabled:value> <mm_fow_ov:value> <mm_fow_radius:value> <mm_fow_completion:value>
  480.  *     - Added a script-call to retrieve the FoW completion status: Silv.Minimap.getFowCompletion(mapId);
  481.  *     - Performs well even on super large (overworld) maps. It does use ~60-120MB of RAM on super large maps and only takes up to ~17kb of savegame file-size for super large maps.
  482.  *  - Added a new help section: "Script Calls & Event triggers".
  483.  *
  484.  * v1.10 (30 December 2015)
  485.  *   - Added the requested option to use a custom map-scene-image that is different from the actual map displayed in the minimap.
  486.  *   - Added a new mapnotetag: <mm_menu_bg:customImageName>
  487.  *
  488.  * v1.09 (27 December 2015)
  489.  *   - Fixed a crash that occurred when events (other than the last one) were deleted (in the map-editor) leaving behind null-values in the $dataMap.
  490.  *   - Renamed the plugin-command alias (before, there was a possible compatibility issue with some of my other scripts).
  491.  *   - Minor refactoring again and applied my new coding standards. Aliases are now stored outside of the anonymous function in a single variable.
  492.  *
  493.  * v1.08 (22 December 2015)
  494.  *   - Fixed a crash when getting onto a vehicle in the overworld when no minimap was active (line 1099) and when getting off a vehicle.
  495.  *   - Improved error reporting
  496.  *   - Switched to the Imported-variable. Thus this plugin now requires Silvers Key plugin 1.02!
  497.  *
  498.  * v1.07 (12 December 2015)
  499.  *   - New feature: Automatically shows vehicles on the minimap as the playerblip when entering a vehicle. Only applies if "Player Blip Graphic" is set to :player .
  500.  *   - Fixed a crash when generating an overworld map without a minimap-image and with the passability-overlay enabled.
  501.  *   - Is now compatible with dynamic map/dungeon generators. You can now recreate the minimap by calling: Silv.Minimap.setup(); after generating your random map.
  502.  *
  503.  * v1.06 (06 December 2015)
  504.  *   - This plugin is now compatible with Yanfly's "Main Menu Manager" plugin. It also automatically disables (or even hides if you want) the map-menu-command if
  505.  *     you do not have an active minimap or simply do not possess the required items.
  506.  *   - Added a new mapnotetag: <mm_mapshot:map_id>. This one is used to display a mapshot from a different map in the current map. Handy in case you have duplicate maps
  507.  *     to prevent ending up with duplicate minimap images in your project folder.
  508.  *   - Removed a console.log() that I forgot to remove in 1.05 before release.
  509.  *
  510.  * v1.05 (30 November 2015)
  511.  *   - I accidentally had some global variables declared above the window-initialization, I made them local now to save memory and to prevent incompatibility issues with other scripts.
  512.  *   - Fixed a crash when fading the scene without an active minimap.
  513.  *
  514.  * v1.04 (27 November 2015) [Updated Parameters]
  515.  *   - Disabled strict-mode (Either Javascript or RPG Maker seems not to support this fully...).
  516.  *   - Fixed a typo that caused the minimap to not resize in height.
  517.  *   - Grouped the player-blink parameters together and removed the unused "Draw Player Icon" parameter (v.1.03 only removed it partially).
  518.  *   - New feature: focus the minimap-camera onto (moving-)events, coordinates or the player.
  519.  *   - Minor refactoring.
  520.  *
  521.  * v1.03 (26 November 2015) [Updated Parameters]
  522.  *   - New feature: Use custom player blip.
  523.  *     - 2 new parameters: "Render Player Blip" & "Player Blip Graphic" and new mapnotetag: <mm_player_blip::player> and a new plugin parameter "Minimap setplayerblip <value>".
  524.  *     - Removed parameter "Draw Player Icon".
  525.  *   - Added a parameter to change minimap-opacity.
  526.  *   - Added plugin commands and map-notetags to switch between AutoScroll and Autofit map-modes, <mm_mapstyle:Scroll/Autofit>
  527.  *
  528.  * v1.02 (25 November 2015) [Updated Parameters]
  529.  *   - Enabled strict mode.
  530.  *   - Added the 'Minimap ShowMapMenu' plugin-command.
  531.  *   - 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>].
  532.  *   - New feature: generate passability overlay. Also comes with new map-notetag & plugin command. Supports 4-direction-passability.
  533.  *   - 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).
  534.  *   - Fixed the minimap-visibility again (it was still not properly fixed in v1.01).
  535.  *   - Now requires Silvers Keybinding script 1.01 instead of 1.00.
  536.  *
  537.  * v1.01 (24 November 2015) [Updated Parameters]
  538.  *   - Fixed the player-blip becoming invisible when walking on grass. Because of this I had to add 2 more advanced parameters.
  539.  *   - Fixed: The minimap no longer automatically shows itself again when it was manually hidden after opening a menu.
  540.  *   - Updated the version number to 1.01 (it was still 0.91) in the plugin description.
  541.  *   - Cleaned up some more out-commented code.
  542.  *   - Fixed: minimap can now hide again when it contains POI's.
  543.  *   - 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.
  544.  *
  545.  * v1.00 (23 November 2015)
  546.  *   - First release.
  547.  *
  548.  * v0.90-0.92 (November 2015)
  549.  *   - First alpha release.
  550.  *
  551.  */
  552. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  553. // Script start
  554. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  555. // Imported
  556. var Imported = Imported || {};
  557. Imported.SILV_Minimap = 1.12;
  558.  
  559. // Dependency check
  560. if (!('SILV_Keys' in Imported) || Imported.SILV_Keys < 1.02) { throw new Error('ERROR: Silvers Minimap requires Silvers KeyMapper v1.02 or higher. It must be placed above the minimap script.'); }
  561.  
  562. // Get Plugin #Parameters
  563. var Silv = Silv || {};
  564. Silv.Parameters = $plugins.filter(function(p) { return p.description.contains('<SilvMinimap>'); })[0].parameters;
  565. Silv.Minimap = Silv.Minimap || {};
  566. Silv.Minimap.Menu = Silv.Minimap.Menu || {};
  567. Silv.Minimap.Generator = Silv.Minimap.Generator || {};
  568. // Non-parameters
  569. Silv.Minimap.Window = null;
  570. Silv.Minimap.POI = {};
  571. Silv.Minimap.Events = []; // Is an array of objects [{ Game_Event, Sprite_Character }]. USe .event and .sprite to retrieve the values.
  572. Silv.Minimap.ScreenIsFading = false;
  573. Silv.Minimap.Menu.Bmp = null;
  574. Silv.Minimap.Menu.Markers = [];
  575. Silv.Minimap.Menu.Enabled = false;
  576. Silv.Minimap.WasLoadedFromSave = false;
  577. 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.
  578. Silv.Minimap.TP_Dest = null;
  579. Silv.Minimap.CreateFunctionIsLocked = false;
  580. Silv.Minimap.Visible = true;
  581. Silv.Minimap.FoWData = {};
  582. // General
  583. Silv.Minimap.MapStyle = Silv.Parameters['Map Style'].toLowerCase();
  584. Silv.Minimap.GlobalMapZoom = parseFloat(Silv.Parameters['Global Map Zoom']);
  585. Silv.Minimap.Window_Opacity = parseInt(Silv.Parameters['Minimap Opacity']);
  586. // Positioning & Size
  587. Silv.Minimap.Window_X = parseInt(Silv.Parameters['X']);
  588. Silv.Minimap.Window_Y = parseInt(Silv.Parameters['Y']);
  589. Silv.Minimap.WindowWidth = parseInt(Silv.Parameters['Width']);
  590. Silv.Minimap.WindowHeight = parseInt(Silv.Parameters['Height']);
  591. Silv.Minimap.BorderWidth = parseInt(Silv.Parameters['Border Width']);
  592. Silv.Minimap.BorderHeight = parseInt(Silv.Parameters['Border Height']);
  593. Silv.Minimap.WindowHorizontalAlignment = Silv.Parameters['Horizontal Alignment'].toLowerCase();
  594. Silv.Minimap.WindowVerticalAlignment = Silv.Parameters['Vertical Alignment'].toLowerCase();
  595. // Player Blip
  596. Silv.Minimap.PlayerBlipEnabled = Silv.Parameters['Render Player Blip'].toLowerCase() === 'true';
  597. Silv.Minimap.PlayerBlipGraphic = Silv.Parameters['Player Blip Graphic'].toLowerCase();
  598. Silv.Minimap.PlayerIconWidth = parseInt(Silv.Parameters['Player Icon Width']);
  599. Silv.Minimap.PlayerIconHeight = parseInt(Silv.Parameters['Player Icon Height']);
  600. Silv.Minimap.PlayerBlinks = parseInt(Silv.Parameters['Player Blink Delay']) > 0; // note: is not directly a parameter but uses one to calculate the value instead
  601. Silv.Minimap.PlayerBlinkDelay = parseInt(Silv.Parameters['Player Blink Delay']);
  602. // Menu
  603. Silv.Minimap.Menu.MenuKey = Silv.Keys.fromStringParam(Silv.Parameters['Menu Key']);
  604. Silv.Minimap.Menu.PlayerDesc = Silv.Parameters['Menu Player Description'];
  605. Silv.Minimap.Menu.Zoom = parseFloat(Silv.Parameters['Menu Zoom']);
  606. Silv.Minimap.Menu.WindowWidth_Left = parseInt(Silv.Parameters['Menu Left Window Width']);
  607. Silv.Minimap.Menu.WindowHeight_MapSection = parseInt(Silv.Parameters['Menu Topright Window Height']);
  608. Silv.Minimap.Menu.EventRenderSize = parseInt(Silv.Parameters['Menu Event Render Size']);
  609. Silv.Minimap.Menu.PlayerIconSize = parseInt(Silv.Parameters['Menu Player Icon Size']);
  610. Silv.Minimap.Menu.ManualZoom_Min = parseFloat(Silv.Parameters['Menu Min Manual Zoom']);
  611. Silv.Minimap.Menu.ManualZoom_Max = parseFloat(Silv.Parameters['Menu Max Manual Zoom']);
  612. Silv.Minimap.Menu.ManualZoomKey_In = Silv.Keys.fromStringParam(Silv.Parameters['Menu Zoomin Key']);
  613. Silv.Minimap.Menu.ManualZoomKey_Out = Silv.Keys.fromStringParam(Silv.Parameters['Menu Zoomout Key']);
  614. Silv.Minimap.Menu.ManualZoomKey_Reset = Silv.Keys.fromStringParam(Silv.Parameters['Menu Reset Zoom Key']);
  615. Silv.Minimap.Menu.ManualScrollKey_Reset = Silv.Keys.fromStringParam(Silv.Parameters['Menu Reset Scroll Key']);
  616. // Passability Map
  617. Silv.Minimap.PassabilityOverlayOpacity = parseInt(Silv.Parameters['Passability Overlay Opacity']);
  618. Silv.Minimap.PassabilityColor = Silv.Parameters['Passability Color'];
  619. Silv.Minimap.ImpassabilityColor = Silv.Parameters['Impassability Color'];
  620. // Generator
  621. Silv.Minimap.Generator.MapColors = Silv.Parameters['Map Gen Tag Colors'].split(' ');
  622. Silv.Minimap.Generator.OverworldColors = Silv.Parameters['Overworld Gen Tag Colors'].split(' ');
  623. // The Rest
  624. Silv.Minimap.AllowTeleportation = Silv.Parameters['Allow Teleportation'].toLowerCase() === 'true';
  625. Silv.Minimap.StandardPadding = parseInt(Silv.Parameters['Standard Padding']);
  626. Silv.Minimap.WindowSkin = Silv.Parameters['Window Skin'];
  627. Silv.Minimap.MapBGFillColor = Silv.Parameters['Fill Color'].split(' ');
  628. Silv.Minimap.MaintainAspectRatio = Silv.Parameters['Maintain Aspect Ratio'].toLowerCase() === 'true';
  629. Silv.Minimap.FadeoutSpeed = parseInt(Silv.Parameters['Fadeout Speed']);
  630. Silv.Minimap.GlobalRequiredItem = parseInt(Silv.Parameters['Global Required Item']);
  631. Silv.Minimap.EventRenderSize = parseInt(Silv.Parameters['Event Render Size']);
  632. Silv.Minimap.AutoClearPOI = Silv.Parameters['Auto Clear POI'].toLowerCase() === 'true';
  633. Silv.Minimap.DrawOverlay = Silv.Parameters['Render Minimap Overlay'].toLowerCase() === 'true';
  634. // Fog of War
  635. Silv.Minimap.FoWEnabled = Silv.Parameters['FoW Enabled'].toLowerCase() === 'true';
  636. Silv.Minimap.DefaultFoWBmpName = Silv.Parameters['Default FoW Overlay'];
  637. Silv.Minimap.DefaultFoWRadius = parseInt(Silv.Parameters['Default FoW Radius']);
  638. // Manual Scrolling
  639. Silv.Minimap.AllowManualScrolling = Silv.Parameters['Allow Manual Scrolling'].toLowerCase() === 'true';
  640. Silv.Minimap.ManualScrollspeed = parseFloat(Silv.Parameters['Manual Scrollspeed']);
  641. Silv.Minimap.ManualScrollKeyUp = Silv.Keys.fromStringParam(Silv.Parameters['Manual Scroll Key Up']);
  642. Silv.Minimap.ManualScrollKeyRight = Silv.Keys.fromStringParam(Silv.Parameters['Manual Scroll Key Right']);
  643. Silv.Minimap.ManualScrollKeyDown = Silv.Keys.fromStringParam(Silv.Parameters['Manual Scroll Key Down']);
  644. Silv.Minimap.ManualScrollKeyLeft = Silv.Keys.fromStringParam(Silv.Parameters['Manual Scroll Key Left']);
  645. // Advanced & Debug
  646. Silv.Minimap.PlayerSpriteSrcFrame_Width = parseInt(Silv.Parameters['Player Sprite Sourceframe Width']);
  647. Silv.Minimap.PlayerSpriteSrcFrame_Height = parseInt(Silv.Parameters['Player Sprite Sourceframe Height']);
  648. Silv.Minimap.FrameSkip = parseInt(Silv.Parameters['Frame Skip']);
  649. Silv.Minimap.MapFilenameLength = parseInt(Silv.Parameters['Mapshot Filename Length']);
  650. Silv.Minimap.DebugMode = Silv.Parameters['Debug Mode'].toLowerCase() === 'true';
  651. Silv.Minimap.DrawDebugGrid = Silv.Parameters['Render Debug Grid'].toLowerCase() === 'true';
  652. Silv.Minimap.DebugGridImage = Silv.Parameters['Debug Grid Image'];
  653.  
  654. // Alias
  655. Silv.Alias = Silv.Alias || {};
  656. if (!Silv.AddAlias)
  657. {
  658.     Silv.AddAlias = function(alias, original_method)
  659.     {
  660.         if (Silv.Alias[alias]) { throw new Error('Alias already exists: ' + alias); }
  661.         Silv.Alias[alias] = original_method;
  662.     };
  663. }
  664.  
  665. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  666. (function()
  667. {
  668. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  669. // #Utilities & Misc
  670. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  671. // Example: lpad('2', '0') // result: '002'
  672. function lpad_mapname(word, padStr)
  673. {
  674.     word = String(word);
  675.     while (word.length < Silv.Minimap.MapFilenameLength) word = padStr + word;
  676.     return word;
  677. }
  678.  
  679. function minimapFolderPath()
  680. {
  681.     var path = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, "/img/minimap/");
  682.     if (path.match(/^\/([A-Z]\:)/)) { path = path.slice(1); }
  683.     path = decodeURIComponent(path);
  684.     return path;
  685. }
  686.  
  687. function getFullMinimapPath(filename)
  688. {
  689.     return minimapFolderPath() + filename;
  690. }
  691.  
  692. // filename example: '002.png'
  693. function minimapImageExists(filename)
  694. {
  695.     var fs = require('fs');
  696.     return fs.existsSync(getFullMinimapPath(filename));
  697. }
  698.  
  699. function dataMapGetEventByID(ev_id)
  700. {
  701.     for(var i=1; i< $dataMap.events.length; i++)
  702.     {
  703.         // $dataMap.events may contain null-values when placing several events in the editor and then deleting an even (other than the last one). Therefore the ($dataMap.events[i] !== null) check is required.
  704.         if (($dataMap.events[i] !== null) && $dataMap.events[i].id == ev_id) { return $dataMap.events[i]; }
  705.     }
  706.     return null;
  707. }
  708.  
  709. ImageManager.loadMinimap = function(filename, hue)
  710. {
  711.     return this.loadBitmap('img/minimap/', filename, hue, false);
  712. };
  713.  
  714. // Do not just show the minimap on top of a faded-out screen.
  715. Silv.AddAlias('mm_Game_Screen_updateFadeOut', Game_Screen.prototype.updateFadeOut);
  716. Game_Screen.prototype.updateFadeOut = function()
  717. {
  718.     Silv.Alias.mm_Game_Screen_updateFadeOut.apply(this, arguments);
  719.    
  720.     if (this._brightness < 255) // (this._fadeOutDuration > 0)
  721.     {
  722.         Silv.Minimap.ScreenIsFading = true;
  723.         if (Silv.Minimap.Window !== null)
  724.         {
  725.             Silv.Minimap.Window.opacity = this._brightness;
  726.             Silv.Minimap.Window.contents.paintOpacity  = this._brightness;
  727.         }
  728.     }
  729.     else
  730.     {
  731.         Silv.Minimap.ScreenIsFading = false;
  732.     }
  733. };
  734. //------------------------------------------------------------------------------------------------------------------------------------
  735. // Store a reference to the player graphic.
  736. //------------------------------------------------------------------------------------------------------------------------------------
  737. Silv.AddAlias('mm_Spriteset_Map_createCharacters', Spriteset_Map.prototype.createCharacters);
  738. Spriteset_Map.prototype.createCharacters = function()
  739. {
  740.     Silv.Alias.mm_Spriteset_Map_createCharacters.apply(this, arguments);
  741.    
  742.     for (var i = this._characterSprites.length - 1; i >= 0; i--)
  743.     {
  744.         if (this._characterSprites[i]._character == $gamePlayer)
  745.         {
  746.             Spriteset_Map.prototype.playerSprite = this._characterSprites[i];
  747.             break;
  748.         }  
  749.     }
  750. };
  751. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  752. // Automatically create a event-Notetag from event-comments on the active page
  753. // Example usage: console.log($gameMap.event(1).event.silvNote);
  754. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  755. Silv.AddAlias('mm_Game_Event_setupPage',  Game_Event.prototype.setupPage);
  756. Game_Event.prototype.setupPage = function()
  757. {
  758.     Silv.Alias.mm_Game_Event_setupPage.apply(this, arguments);
  759.     this.silvCreateNote();
  760. };
  761.  
  762. Game_Event.prototype.silvCreateNote = function()
  763. {
  764.     this.silvNote = '';
  765.     if (typeof this.page() === 'undefined') { return; }
  766.    
  767.     var list = this.list();
  768.     var str = null;
  769.     for (var commandProperty in list)
  770.     {
  771.         if (list.hasOwnProperty(commandProperty))
  772.         {
  773.             var command = list[commandProperty];
  774.             var commandCode = command.code;
  775.             if (commandCode == 108) // 108: new comment-item, always the first line.
  776.             {
  777.                 if (str !== null) { this.silvNote += str; }
  778.                 str = command.parameters[0];
  779.             }
  780.             else if (commandCode == 408) // 408: comment-line, but not the first one.
  781.             {
  782.                 this.silvNote += command.parameters[0];
  783.             }
  784.             else if (str) // It's not a comment-code, so add the previous str (if any) to the note.
  785.             {
  786.                 this.silvNote += str;
  787.                 str = null;
  788.             }
  789.         }
  790.     }
  791.     if (this.silvNote !== '') { this.extractSilvMetadata(); }
  792. };
  793.  
  794. // <mm_tp:1> will result in: '1'
  795. // <mm_tp:1> will result in: ['1', '0'];
  796. Game_Event.prototype.extractSilvMetadata = function() {
  797.     var re = /<([^<>:]+)(:?)([^>]*)>/g;
  798.     this.meta = {};
  799.     for (;;)
  800.     {
  801.         var match = re.exec(this.silvNote);
  802.         if (match)
  803.         {
  804.             if (match[2] === ':')
  805.             {
  806.                 var value = match[3];
  807.                 if (match[3].indexOf(' ') >= 0) { value = match[3].split(' '); }
  808.                
  809.                 this[match[1]] = value;
  810.             }
  811.             else
  812.             {
  813.                 this[match[1]] = true;
  814.             }
  815.         }
  816.         else
  817.         {
  818.             break;
  819.         }
  820.     }
  821. };
  822. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  823. // Minimap Window
  824. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  825. function Window_Minimap() { this.initialize.apply(this, arguments); }
  826. // Inherit from base window
  827. Window_Minimap.prototype = Object.create(Window_Base.prototype);
  828. // Set Constructor
  829. Window_Minimap.prototype.constructor = Window_Minimap;
  830.  
  831. Window_Minimap.prototype.loadWindowskin = function() { this.windowskin = ImageManager.loadSystem(Silv.Minimap.WindowSkin); };
  832. Window_Minimap.prototype.standardPadding = function() { return Silv.Minimap.StandardPadding; };
  833. //Window_Minimap.prototype.standardFontSize = function() { return Silv.Minimap.FontSize; }
  834. Window_Minimap.prototype.bmpPreloadTotal = 1; // The amount of images to preload before the minimap can be rendered.
  835.  
  836.  
  837. // #Initialization
  838. Window_Minimap.prototype.initialize = function(x, y, width, height, mapName, minimapType)
  839. {
  840.     this.mapName = mapName;
  841.     this.minimapType = minimapType;
  842.     if ('mm_size' in $dataMap.meta)
  843.     {
  844.         var newSize = $dataMap.meta.mm_size.split(' ');
  845.         this.width = parseInt(newSize[0]);
  846.         this.height = parseInt(newSize[1]);
  847.     }
  848.    
  849.     Window_Base.prototype.initialize.call(this, x, y, width, height);
  850.     this._helpWindow = null;
  851.     this._handlers = {};
  852.     this._touching = false;
  853.     this.deactivate();
  854.  
  855.     this.bmpPreloadCnt = 0;
  856.     this.finishedBmpPreloading = false;
  857.    
  858.     // Fog of War
  859.     if ('mm_fow_enabled' in $dataMap.meta)
  860.     {
  861.         this.fowEnabled = $dataMap.meta.mm_fow_enabled.toLowerCase() === 'true';
  862.     }
  863.     else
  864.     {
  865.         this.fowEnabled = Silv.Minimap.FoWEnabled;
  866.     }
  867.     this.fowBmpName = ('mm_fow_ov' in $dataMap.meta) ? $dataMap.meta.mm_fow_ov : Silv.Minimap.DefaultFoWBmpName;
  868.     if (typeof Silv.Minimap.FoWData[$gameMap._mapId] === 'undefined') // This if-statement must be placed before preloading the FoW-bitmap
  869.     {
  870.         this.resetFoWData();
  871.         this.fowRequiresRefresh = false;
  872.     }
  873.     else
  874.     {
  875.         this.fowRequiresRefresh = true;
  876.     }
  877.     this.fowOriginalBmp = ImageManager.loadMinimap(this.fowBmpName);
  878.     this.fowOriginalBmp.addLoadListener(function() { this.onFinishOriginalFoWBmpLoad(); }.bind(this));
  879.     this.fowRadius = ('mm_fow_radius' in $dataMap.meta) ? parseInt($dataMap.meta.mm_fow_radius) : Silv.Minimap.DefaultFoWRadius;
  880.    
  881.     this.originalMapBmp = null;
  882.     this.passabilityBmp = null;
  883.     this.drawPassabilityOverlay = false;
  884.     this.isFadingOut = false;
  885.     this.isFadedOut = false;
  886.     this.setDrawMapBmp();
  887.     this.overlayBmp = ImageManager.loadMinimap('Overlay');
  888.     this.drawAreaWidth = this.contents.width - Silv.Minimap.BorderWidth * 2;
  889.     this.drawAreaHeight = this.contents.height - Silv.Minimap.BorderHeight * 2;
  890.     this.mapWidth = parseFloat($gameMap.width());
  891.     this.mapHeight = parseFloat($gameMap.height());
  892.     this.setAspectRatio();
  893.     this.playerBlinkCnt = Silv.Minimap.PlayerBlinkDelay;
  894.     this.playerBlink_IsVisible = true;
  895.     this.frameSkip = Silv.Minimap.FrameSkip;
  896.     this.frameSkipCnt = 0;
  897.     Silv.Minimap.Menu.Enabled = true;
  898.     this.mapZoom = ('mm_mapzoom' in $dataMap.meta) ? parseFloat($dataMap.meta.mm_mapzoom) : Silv.Minimap.GlobalMapZoom;
  899.     this.mapZoomInverse = 1 / this.mapZoom;
  900.     this.isFirstProcessedUpdate = true;
  901.     this.requiresDrawing = true; // as in AFTER isReady().
  902.     this.isManualScrolling = false;
  903.     this.allowManualScroll = ('mm_allowmanualscroll' in $dataMap.meta) ? $dataMap.meta.mm_allowmanualscroll.toLowerCase() === 'true' : Silv.Minimap.AllowManualScrolling;
  904.     this.mapScroll = {x: 0, y: 0, adjustment_x: 0, adjustment_y: 0};
  905.     this.lastPlayerLoc = {x: $gamePlayer._realX, y: $gamePlayer._realY};
  906.     this.menuZoom = ('mm_menuzoom' in $dataMap.meta) ? $dataMap.meta.mm_menuzoom.toLowerCase() === 'true' : Silv.Minimap.Menu.Zoom;
  907.     this.allowTeleportation = ('mm_tp_allow' in $dataMap.meta) ? $dataMap.meta.mm_tp_allow.toLowerCase() === 'true' : Silv.Minimap.AllowTeleportation;
  908.     this.playerFrame = { x:0, y:0, width:Silv.Minimap.PlayerSpriteSrcFrame_Width, height:Silv.Minimap.PlayerSpriteSrcFrame_Height };
  909.     this.mapStyle = ('mm_mapstyle' in $dataMap.meta) ? $dataMap.meta.mm_mapstyle.toLowerCase() : Silv.Minimap.MapStyle;
  910.     this.cameraFocusType = 'player'; // player / event / coordinate
  911.     this.cameraFocusObject = null; // null / reference to event / {x:real_x, y:real_y}
  912.     this.vehicleCharSprite = null;
  913.     this.menuBG = ('mm_menu_bg' in $dataMap.meta) ? ImageManager.loadMinimap($dataMap.meta.mm_menu_bg) : null;
  914.    
  915.     this.initPlayerBlip();
  916.    
  917.     this.loadEvents();
  918.     this.debugGridBmp = ImageManager.loadMinimap(Silv.Minimap.DebugGridImage);
  919.        
  920.     // The update must be called AFTER all the initialization code.
  921.     this.update();
  922. };
  923.  
  924. Window_Minimap.prototype.finishBmpLoad = function()
  925. {
  926.     this.bmpPreloadCnt++;
  927.     if (this.bmpPreloadCnt === this.bmpPreloadTotal) { this.finishedBmpPreloading = true; }
  928. };
  929.  
  930. Window_Minimap.prototype.setOpacity = function()
  931. {
  932.     this.opacity = Silv.Minimap.Window_Opacity;
  933. };
  934.  
  935. Window_Minimap.prototype.initPlayerBlip = function()
  936. {
  937.     this.playerBlipEnabled = Silv.Minimap.PlayerBlipEnabled;
  938.     this.playerBlipGfx = Silv.Minimap.PlayerBlipGraphic;
  939.     this.playerBlipBmp = null;
  940.    
  941.     if ('mm_player_blip' in $dataMap.meta) { this.setPlayerBlip($dataMap.meta.mm_player_blip); }
  942.     else { this.setPlayerBlip(Silv.Minimap.PlayerBlipGraphic); }
  943. };
  944. //----------------------------------------------------------------------------------------------------
  945. // Set Drawing Bitmaps
  946. //----------------------------------------------------------------------------------------------------
  947. Window_Minimap.prototype.setDrawMapBmp = function()
  948. {
  949.     switch (this.minimapType)
  950.     {
  951.         case 'regular':
  952.             if (this.originalMapBmp === null)
  953.             {
  954.                 this.originalMapBmp = ImageManager.loadMinimap(this.mapName);
  955.                 this.mapBmp = ImageManager.loadMinimap(this.mapName);
  956.             }
  957.             else if (this.originalMapBmp.isReady())
  958.             {
  959.                 this.mapBmp = new Bitmap(this.originalMapBmp.width, this.originalMapBmp.height);
  960.                 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...
  961.                 this.requiresDrawing = false;
  962.             }
  963.             break;
  964.         case 'generate_map':
  965.             this.mapBmp  = this.generateMap(Silv.Minimap.Generator.MapColors);
  966.             this.originalMapBmp = this.generateMap(Silv.Minimap.Generator.MapColors);
  967.             this.requiresDrawing = false;
  968.             break;
  969.         case 'generate_overworld':
  970.             this.mapBmp = this.generateMap(Silv.Minimap.Generator.OverworldColors);
  971.             this.originalMapBmp = this.generateMap(Silv.Minimap.Generator.OverworldColors);
  972.             this.requiresDrawing = false;
  973.             break;
  974.         default:
  975.             throw new Error('Window_Minimap.prototype.GetMapBmp has invalid switch-value: ' + this.minimapType);
  976.     }
  977.    
  978.     if (this.drawPassabilityOverlay)
  979.     {
  980.         if (this.originalMapBmp.isReady()) { this.bltPassabilityOverlay(); }
  981.         else { this.passabilityRequiresRedraw = true; }
  982.     }
  983. };
  984. //----------------------------------------------------------------------------------------------------
  985. // #Show & #Hide
  986. //----------------------------------------------------------------------------------------------------
  987. Window_Minimap.prototype.hide = function()
  988. {
  989.     Window_Base.prototype.hide.apply(this, arguments);
  990.     Silv.Minimap.Visible = false;
  991. };
  992.  
  993. Window_Minimap.prototype.show = function()
  994. {
  995.     Window_Base.prototype.show.apply(this, arguments);
  996.     Silv.Minimap.Visible = true;
  997. };
  998. //----------------------------------------------------------------------------------------------------
  999. // #Passability #Overlay
  1000. //----------------------------------------------------------------------------------------------------
  1001. Window_Minimap.prototype.bltPassabilityOverlay = function()
  1002. {
  1003.     // Generate the bitmap if it wasn't done already
  1004.     if (this.passabilityBmp === null) { this.passabilityBmp = this.generatePassabilityBmp(); }
  1005.    
  1006.     // Blt the overlay on top of the this.mapBmp
  1007.     this.mapBmp.blt(this.passabilityBmp, 0, 0, this.passabilityBmp.width, this.passabilityBmp.height, 0, 0);
  1008.    
  1009.     this.passabilityRequiresRedraw = false;
  1010. };
  1011.  
  1012. Window_Minimap.prototype.setPassabilityOverlay = function(enabled)
  1013. {
  1014.     this.drawPassabilityOverlay = enabled;
  1015.     this.setDrawMapBmp();
  1016. };
  1017.  
  1018. // 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.
  1019. Window_Minimap.prototype.generatePassabilityBmp = function()
  1020. {
  1021.     var tile_w = $gameMap.tileWidth();
  1022.     var tile_h = $gameMap.tileHeight();
  1023.     var bmp = new Bitmap($gameMap.width() * tile_w, $gameMap.height() * tile_h);
  1024.     bmp.paintOpacity = Silv.Minimap.PassabilityOverlayOpacity;
  1025.     var borderTickness = 8;
  1026.    
  1027.     for (var y=0; y<$dataMap.height; y++)
  1028.     {
  1029.         for (var x=0; x<$dataMap.width; x++)
  1030.         {
  1031.             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)};
  1032.            
  1033.             if (!passability[2] && !passability[4] && !passability[6] && !passability[8])
  1034.             {
  1035.                 bmp.fillRect(x * tile_w, y * tile_h, tile_w, tile_h, Silv.Minimap.ImpassabilityColor);
  1036.             }
  1037.             else
  1038.             {
  1039.                 bmp.paintOpacity = 255;
  1040.                 if (!passability[8]) { bmp.fillRect(x * tile_w, y * tile_h, tile_w, borderTickness, Silv.Minimap.ImpassabilityColor); } // top
  1041.                 if (!passability[6]) { bmp.fillRect(x * tile_w + tile_w - borderTickness, y * tile_h, borderTickness, tile_h, Silv.Minimap.ImpassabilityColor); } // right
  1042.                 if (!passability[2]) { bmp.fillRect(x * tile_w, y * tile_h + tile_h - borderTickness, tile_w, borderTickness, Silv.Minimap.ImpassabilityColor); } // bottom
  1043.                 if (!passability[4]) { bmp.fillRect(x * tile_w, y * tile_h, borderTickness, tile_h, Silv.Minimap.ImpassabilityColor); } // left
  1044.                 bmp.paintOpacity = Silv.Minimap.PassabilityOverlayOpacity;
  1045.                
  1046.                 bmp.fillRect(x * tile_w, y * tile_h, tile_w, tile_h, Silv.Minimap.PassabilityColor);
  1047.             }
  1048.         }
  1049.     }
  1050.     return bmp;
  1051. };
  1052.  
  1053. //----------------------------------------------------------------------------------------------------
  1054. // #Generate Maps
  1055. //----------------------------------------------------------------------------------------------------
  1056. Window_Minimap.prototype.generateMap = function(colors)
  1057. {
  1058.     var tile_w = $gameMap.tileWidth();
  1059.     var tile_h = $gameMap.tileHeight();
  1060.     var bmp = new Bitmap($gameMap.width() * tile_w, $gameMap.height() * tile_h);
  1061.    
  1062.     for (var y=0; y<$dataMap.height; y++)
  1063.     {
  1064.         for (var x=0; x<$dataMap.width; x++)
  1065.         {
  1066.             bmp.fillRect(x * tile_w, y * tile_h, tile_w, tile_h, colors[$gameMap.terrainTag(x, y)]); // Default: lightgreen, blue, brown, darkgreen, lightbrown
  1067.         }
  1068.     }
  1069.     return bmp;
  1070. };
  1071.  
  1072. //----------------------------------------------------------------------------------------------------
  1073. // <Asorted>
  1074. //----------------------------------------------------------------------------------------------------
  1075. Window_Minimap.prototype.showMapMenuScene = function()
  1076. {
  1077.     Silv.Minimap.Window.pushMapScene();
  1078. };
  1079.  
  1080. Window_Minimap.prototype.clamp = function(value, min, max)
  1081. {
  1082.     return Math.min(Math.max(value, min), max);
  1083. };
  1084.    
  1085. // This function requires this.mapBmp to be fully initialized.
  1086. // #Aspect #Ratio #AspectRatio
  1087. Window_Minimap.prototype.setAspectRatio = function()
  1088. {
  1089.     // this.mapAspRatInfo.scaleDelta_x is the difference in size between the mapwidth (in pixels, NOT in tiles) and the minimap (render)width.
  1090.     this.mapAspRatInfo = { w: 0.0, h: 0.0, offset_x: 0.0, offset_y: 0.0, scaleDelta_x: 0.0, scaleDelta_y: 0.0 };
  1091.     var w = $gameMap.width();
  1092.     var h = $gameMap.height();
  1093.    
  1094.     // Map Aspect Ratio
  1095.     if (!Silv.Minimap.MaintainAspectRatio || (w == h))
  1096.     {
  1097.         this.mapAspRatInfo.w = 1.0;
  1098.         this.mapAspRatInfo.h = 1.0;
  1099.     }
  1100.     else if (w > h)
  1101.     {
  1102.         this.mapAspRatInfo.w = 1.0;
  1103.         this.mapAspRatInfo.h = h / parseFloat(w);
  1104.     }
  1105.     else // if (h > w)
  1106.     {
  1107.         this.mapAspRatInfo.w = w / parseFloat(h);
  1108.         this.mapAspRatInfo.h = 1.0;
  1109.     }
  1110.    
  1111.     this.mapAspRatInfo.scaleDelta_x = this.drawAreaWidth / parseFloat($gameMap.width() * $gameMap.tileWidth());
  1112.     this.mapAspRatInfo.scaleDelta_y = this.drawAreaHeight / parseFloat($gameMap.height() * $gameMap.tileHeight());
  1113. };
  1114.  
  1115. // #Events
  1116. Window_Minimap.prototype.loadEvents = function()
  1117. {
  1118.     Silv.Minimap.Events = [];
  1119.     for (var ev_idx = 1; ev_idx < $dataMap.events.length; ev_idx++) // Note: start at 1. Because the first one is always null.
  1120.     {
  1121.         if ($dataMap.events[ev_idx] !== null)
  1122.         {
  1123.             var ev = $gameMap.event(ev_idx);
  1124.            
  1125.             // Check Event Note
  1126.             if ($dataMap.events[ev_idx].note !== '' || ('mm_show' in ev))
  1127.             {
  1128.                 var cmds = $dataMap.events[ev_idx].note.toLowerCase().split(' ');
  1129.                 if ((cmds.indexOf('mm_show') > -1) ||  ('mm_show' in ev))
  1130.                 {
  1131.                     var new_ev = {event: ev, sprite: this.getEventCharacterSprite(ev.eventId())};
  1132.                     Silv.Minimap.Events.push(new_ev); // Add event to the array so we can render it on the minimap
  1133.                 }
  1134.             }
  1135.         }
  1136.     }
  1137.     if (Silv.Minimap.DebugMode) { console.log('Loaded Events:'); console.log(Silv.Minimap.Events); }
  1138. };
  1139.  
  1140. Window_Minimap.prototype.getEventCharacterSprite = function(ev_id)
  1141. {
  1142.     for (var i=0; i < SceneManager._scene._spriteset._characterSprites.length; i++)
  1143.     {
  1144.         var eventSprite = SceneManager._scene._spriteset._characterSprites[i];
  1145.         if (eventSprite._character.eventId() == ev_id)
  1146.         {
  1147.             return eventSprite;
  1148.         }
  1149.     }
  1150.     throw new Error('getEventCharacterSprite() did not find a match for ev_id: ' + ev_id);
  1151. };
  1152.    
  1153. // #update
  1154. Window_Minimap.prototype.update = function()
  1155. {
  1156.     // Do nothing if some images haven't finished loading yet
  1157.     if (!this.finishedBmpPreloading) { return; }
  1158.    
  1159.     if (!this.skipFrame() && (this.originalMapBmp === null || this.originalMapBmp.isReady()))
  1160.     {
  1161.         Window_Base.prototype.update.call(this);
  1162.         this.updateFadeOut();
  1163.         this.updateInput();
  1164.         if (Silv.Minimap.PlayerBlinks) { this.updatePlayerBlink(); }
  1165.         this.updateMapScroll(this.isFirstProcessedUpdate);
  1166.         this.playerInfo = this.getPlayerBitmap();
  1167.         if (this.requiresDrawing) { this.setDrawMapBmp(); }
  1168.         this.drawMinimap();
  1169.         this.lastPlayerLoc.x  = $gamePlayer._realX;
  1170.         this.lastPlayerLoc.y  = $gamePlayer._realY;
  1171.         this.isFirstProcessedUpdate = false;
  1172.        
  1173.         // Teleport
  1174.         if (Silv.Minimap.TP_Dest !== null)
  1175.         {
  1176.             this.teleport(Silv.Minimap.TP_Dest);
  1177.             Silv.Minimap.TP_Dest = null;
  1178.         }
  1179.        
  1180.         if (this.passabilityRequiresRedraw && this.originalMapBmp.isReady()) { this.bltPassabilityOverlay(); }
  1181.     }
  1182.    
  1183.     if (Input.isTriggered(Silv.Minimap.Menu.MenuKey)) { this.showMapMenuScene(); }
  1184. };
  1185.  
  1186. //----------------------------------------------------------------------------------------------------
  1187. // Get #Player #Blip Bitmap
  1188. //----------------------------------------------------------------------------------------------------
  1189. Window_Minimap.prototype.getPlayerBitmap = function()
  1190. {
  1191.     if (this.vehicleCharSprite === null)
  1192.     {
  1193.         var playerSpr = Spriteset_Map.prototype.playerSprite;
  1194.         // Player is not in bush, so return the regular player-graphic
  1195.         if (playerSpr._bushDepth == 0 || playerSpr._lowerBody === null)
  1196.         {
  1197.             return { bmp:playerSpr._bitmap, src:playerSpr._frame };
  1198.         }
  1199.  
  1200.         // Create Bush graphic (which is divided into 2 graphics by the RM-code..)
  1201.         var playerBmp = new Bitmap(Silv.Minimap.PlayerSpriteSrcFrame_Width, Silv.Minimap.PlayerSpriteSrcFrame_Height);
  1202.         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,
  1203.                       0, Silv.Minimap.PlayerSpriteSrcFrame_Height - playerSpr._bushDepth, Silv.Minimap.PlayerIconSize, Silv.Minimap.PlayerIconSize);
  1204.         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,
  1205.                       0, 0, Silv.Minimap.PlayerIconSize, Silv.Minimap.PlayerIconSize);
  1206.        
  1207.         return {bmp:playerBmp, src:this.playerFrame};
  1208.     }
  1209.     else // return vehicle instead
  1210.     {
  1211.         return { bmp:this.vehicleCharSprite._bitmap, src:this.vehicleCharSprite._frame };
  1212.     }
  1213. };
  1214. //----------------------------------------------------------------------------------------------------
  1215. // #Vehicle Compatibility for Player Blip Bitmap
  1216. //----------------------------------------------------------------------------------------------------
  1217. Silv.AddAlias('mm_Game_Vehicle_getOnVehicle', Game_Vehicle.prototype.getOn);
  1218. Game_Vehicle.prototype.getOn = function()
  1219. {
  1220.     Silv.Alias.mm_Game_Vehicle_getOnVehicle.apply(this, arguments);
  1221.    
  1222.     if (Silv.Minimap.Window)
  1223.     {
  1224.         var charSprites = SceneManager._scene._spriteset._characterSprites;
  1225.         for (var i = charSprites.length - 1; i >= 0; i--)
  1226.         {
  1227.             if (charSprites[i]._character == this)
  1228.             {
  1229.                 Silv.Minimap.Window.vehicleCharSprite = charSprites[i];
  1230.                 break;
  1231.             }
  1232.         }
  1233.        
  1234.         if (Silv.Minimap.Window.vehicleCharSprite === null)
  1235.         {
  1236.             console.log("ERROR: can't find vehicle sprite for:");
  1237.             console.log(this);
  1238.             throw new Error("ERROR: Couldn't find vehicle sprite.");
  1239.         }
  1240.     }
  1241. };
  1242.  
  1243. Silv.AddAlias('mm_Game_Vehicle_getOffVehicle', Game_Vehicle.prototype.getOff);
  1244. Game_Vehicle.prototype.getOff = function()
  1245. {
  1246.     Silv.Alias.mm_Game_Vehicle_getOffVehicle.apply(this, arguments);
  1247.     if (Silv.Minimap.Window) { Silv.Minimap.Window.vehicleCharSprite = null; }
  1248. };
  1249. //----------------------------------------------------------------------------------------------------
  1250. Window_Minimap.prototype.updateInput = function()
  1251. {
  1252.     if (Input.isPressed(Silv.Minimap.ManualScrollKeyUp))    { Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x, Silv.Minimap.Window.mapScroll.y - Silv.Minimap.ManualScrollspeed); }
  1253.     if (Input.isPressed(Silv.Minimap.ManualScrollKeyRight)) { Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x + Silv.Minimap.ManualScrollspeed, Silv.Minimap.Window.mapScroll.y); }
  1254.     if (Input.isPressed(Silv.Minimap.ManualScrollKeyDown))  { Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x, Silv.Minimap.Window.mapScroll.y + Silv.Minimap.ManualScrollspeed); }
  1255.     if (Input.isPressed(Silv.Minimap.ManualScrollKeyLeft))  { Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x - Silv.Minimap.ManualScrollspeed, Silv.Minimap.Window.mapScroll.y); }
  1256. };
  1257.  
  1258. Window_Minimap.prototype.teleport = function(tp_info)
  1259. {
  1260.     var direction = $gamePlayer._direction;
  1261.     if (tp_info[2] != 0) { direction = parseInt(tp_info[2]); }
  1262.  
  1263.     $gamePlayer.reserveTransfer($gameMap._mapId, tp_info[0], tp_info[1], direction, parseInt(tp_info[3]));
  1264. };
  1265.  
  1266. Window_Minimap.prototype.playerLocChanged = function()
  1267. {
  1268.     return this.lastPlayerLoc.x != $gamePlayer._realX || this.lastPlayerLoc.y != $gamePlayer._realY;
  1269. };
  1270.  
  1271. //----------------------------------------------------------------------------------------------------
  1272. // #Scroll
  1273. //----------------------------------------------------------------------------------------------------
  1274. Window_Minimap.prototype.updateMapScroll = function(force)
  1275. {
  1276.     switch (this.cameraFocusType)
  1277.     {
  1278.         case 'player':
  1279.             if (this.playerLocChanged() || force) // Only update mapscroll if the player changed location. This way manual-scrolling is made possible.
  1280.             {
  1281.                 this.isManualScrolling = false;
  1282.                 this.scrollToMapObject($gamePlayer._realX, $gamePlayer._realY);
  1283.             }
  1284.             break;
  1285.         case 'event':
  1286.             this.isManualScrolling = false;
  1287.             this.scrollToMapObject(this.cameraFocusObject._realX, this.cameraFocusObject._realY);
  1288.             break;
  1289.         case 'coordinate':
  1290.             this.isManualScrolling = false;
  1291.             this.scrollToMapObject(this.cameraFocusObject.x, this.cameraFocusObject.y);
  1292.             break;
  1293.         default:
  1294.             throw new Error('Invalid switch-value in updateMapScroll(). Value: ' + this.cameraFocusType);
  1295.     }
  1296. };
  1297.  
  1298. Window_Minimap.prototype.setCameraFollowTarget = function(followType, value)
  1299. {
  1300.     this.cameraFocusType = followType; // Must be set before calling updateMapScroll()
  1301.     switch (followType)
  1302.     {
  1303.         case 'player':
  1304.             this.cameraFocusObject = null;
  1305.             this.updateMapScroll(true); // refresh the camera to focus on the player. Because he may not be moving when this was called.
  1306.             break;
  1307.         case 'event':
  1308.             this.cameraFocusObject = $gameMap.event(parseInt(value));
  1309.             if (typeof this.cameraFocusObject === 'undefined') { throw 'setCameraFollowTarget() invalid event-id: ' + value; }
  1310.             break;
  1311.         case 'coordinate':
  1312.             if (Object.prototype.toString.call( value ) !== '[object Array]') { throw 'setCameraFollowTarget() value-param must be an array. Received type: ' + typeof value; }
  1313.             this.cameraFocusObject = { x:value[0], y:value[1] };
  1314.             break;
  1315.         default:
  1316.             throw new Error('Invalid switch-value in setCameraFollowTarget(). Value: ' + followType);
  1317.     }
  1318.    
  1319. };
  1320.  
  1321. Window_Minimap.prototype.scrollToMapObject = function(real_x, real_y)
  1322. {
  1323.     this.setMapScroll(real_x * $gameMap.tileWidth() - (this.drawAreaWidth / 2 * this.mapZoomInverse), real_y * $gameMap.tileHeight() - (this.drawAreaHeight / 2 * this.mapZoomInverse));
  1324. };
  1325.  
  1326. Window_Minimap.prototype.setMapScroll = function(scroll_x, scroll_y)
  1327. {
  1328.     var old_x = this.mapScroll.x = scroll_x;
  1329.     var source_w = this.drawAreaWidth * this.mapZoomInverse;
  1330.     this.mapScroll.x = this.clamp(this.mapScroll.x, 0, this.mapBmp.width - source_w);
  1331.     this.mapScroll.adjustment_x = old_x - this.mapScroll.x; // clamp difference
  1332.    
  1333.     var old_y = this.mapScroll.y = scroll_y;
  1334.     var source_h = this.drawAreaHeight * this.mapZoomInverse;
  1335.     this.mapScroll.y = this.clamp(this.mapScroll.y, 0, this.mapBmp.height - source_h);
  1336.     this.mapScroll.adjustment_y = old_y - this.mapScroll.y; // clamp difference
  1337. };
  1338. //----------------------------------------------------------------------------------------------------
  1339.  
  1340. Window_Minimap.prototype.manualScroll = function(scroll_x, scroll_y)
  1341. {
  1342.     this.setMapScroll(scroll_x, scroll_y);
  1343.     this.isManualScrolling = true;
  1344. };
  1345.  
  1346. // Skips frame (returns true) if frameSkipCnt > frameSkip
  1347. Window_Minimap.prototype.skipFrame = function()
  1348. {
  1349.     if (this.frameSkip === 0) { return false; } // process frame
  1350.    
  1351.     this.frameSkipCnt++;
  1352.     if (this.frameSkipCnt < this.frameSkip)
  1353.     {
  1354.         return true; // skip frame
  1355.     }
  1356.     else
  1357.     {
  1358.         this.frameSkipCnt = 0;
  1359.         return false; // process frame
  1360.     }
  1361. };
  1362.  
  1363. Window_Minimap.prototype.updatePlayerBlink = function()
  1364. {
  1365.     this.playerBlinkCnt--;
  1366.     if (this.playerBlinkCnt <= 0)      
  1367.     {  
  1368.         this.playerBlinkCnt = Silv.Minimap.PlayerBlinkDelay;
  1369.         this.playerBlink_IsVisible = !this.playerBlink_IsVisible;
  1370.     }
  1371. };
  1372.  
  1373. //----------------------------------------------------------------------------------------------------
  1374. // Window Fading
  1375. //----------------------------------------------------------------------------------------------------
  1376. Window_Minimap.prototype.updateFadeOut = function()
  1377. {
  1378.     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.
  1379.     if (this.isFadingOut) { this.fadeOut(); }
  1380. };
  1381.  
  1382. Window_Minimap.prototype.fadeOut = function()
  1383. {
  1384.     this.opacity = this.contentsOpacity -= Silv.Minimap.FadeoutSpeed;
  1385.     this.isFadedOut = (this.opacity <= 0);
  1386. };
  1387.  
  1388. Window_Minimap.prototype.resetFade = function()
  1389. {
  1390.     this.isFadingOut = false;
  1391.     this.fadeOutCnt = 0;
  1392.     this.opacity = this.contentsOpacity  = 255;
  1393.     this.isFadedOut = false;
  1394. };
  1395.  
  1396. Window_Minimap.prototype.fadeOutInstantly = function()
  1397. {
  1398.     this.opacity = this.contentsOpacity = 0;
  1399.     this.isFadedOut = true;
  1400. };
  1401.  
  1402. //----------------------------------------------------------------------------------------------------
  1403. // #Menu
  1404. //----------------------------------------------------------------------------------------------------
  1405. // This method is required for compatibility with Yanfly's Main Menu Manager.
  1406. Scene_Menu.prototype.commandSilvMap = function()
  1407. {
  1408.     Silv.Minimap.Window.pushMapScene();
  1409. };
  1410.  
  1411. Silv.AddAlias('mm_Scene_Map_callMenu', Scene_Map.prototype.callMenu);
  1412. Scene_Map.prototype.callMenu = function()
  1413. {
  1414.     if (Silv.Minimap.Menu.Enabled) { Silv.Minimap.Window.createMenuData(); }
  1415.     Silv.Alias.mm_Scene_Map_callMenu.apply(this, arguments);
  1416. };
  1417.  
  1418. Window_Minimap.prototype.createMenuData = function()
  1419. {
  1420.     this.createMenuBmp();
  1421.     this.createMenuMarkers();
  1422. };
  1423.  
  1424. Window_Minimap.prototype.pushMapScene = function()
  1425. {
  1426.     this.createMenuData();
  1427.     if (Silv.Minimap.Menu.Enabled)
  1428.     {
  1429.         if (Silv.Minimap.Menu.Bmp !== null) { SceneManager.push(Scene_MiniMap); }
  1430.         else { throw new Error('pushMapScene() was called, the minimap-menu was enabled BUT Silv.Minimap.Menu.Bmp equals null?'); }
  1431.     }
  1432.     else
  1433.     {
  1434.         throw new Error('pushMapScene() was called but the Minimap (menu) was not enabled.');
  1435.     }
  1436. };
  1437. //----------------------------------------------------------------------------------------------------
  1438. // Create #Menu Bitmap
  1439. //----------------------------------------------------------------------------------------------------
  1440. Window_Minimap.prototype.createMenuBmp = function()
  1441. {
  1442.     Silv.Minimap.Menu.Bmp = new Bitmap(this.mapBmp.width * this.menuZoom, this.mapBmp.height * this.menuZoom);
  1443.    
  1444.     this.tileInfo = {
  1445.             w: $gameMap.tileWidth(), hw: $gameMap.tileWidth() / 2.0, zhw: ($gameMap.tileWidth() / 2.0) * this.menuZoom,
  1446.             h: $gameMap.tileHeight(), hh: $gameMap.tileHeight() / 2.0, zhh: ($gameMap.tileHeight() / 2.0) * this.menuZoom
  1447.         };
  1448.    
  1449.     // Draw Map
  1450.     var backgroundBmp = (this.menuBG) ? this.menuBG : this.mapBmp;
  1451.     Silv.Minimap.Menu.Bmp.blt(backgroundBmp, 0, 0, backgroundBmp.width, backgroundBmp.height, 0, 0, Silv.Minimap.Menu.Bmp.width, Silv.Minimap.Menu.Bmp.height);
  1452.    
  1453.     // Draw Debug Grid
  1454.     if (Silv.Minimap.DrawDebugGrid)
  1455.     {
  1456.         for (var i=0; i < $gameMap.width(); i++)
  1457.         {
  1458.             for (var j=0; j < $gameMap.height(); j++)
  1459.             {
  1460.                 var debugTileLoc = this.translateLocationMenu(this, i, j, this.tileInfo.w * this.menuZoom, this.tileInfo.h * this.menuZoom);
  1461.                 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);
  1462.             }
  1463.         }
  1464.     }
  1465.    
  1466.     // Draw POI's
  1467.     for (var i = 0; i < this.getAllPOI().length; i++)
  1468.     {
  1469.         var poi = this.getPOIByIdx(i);
  1470.         var poiLoc = this.translateLocationMenu(this, poi.real_x, poi.real_y, poi.destSize.w, poi.destSize.h);
  1471.         Silv.Minimap.Menu.Bmp.blt(poi.bmp, poi.src.x, poi.src.y, poi.src.w, poi.src.h,
  1472.                                   poiLoc.x, poiLoc.y, poi.destSize.w, poi.destSize.h);
  1473.     }
  1474.    
  1475.     // Draw Events
  1476.     for (var i=0; i < Silv.Minimap.Events.length; i++)
  1477.     {
  1478.         var ev = Silv.Minimap.Events[i].event;
  1479.         var ev_sprite = Silv.Minimap.Events[i].sprite;
  1480.         var evMapLoc = this.translateLocationMenu(this, ev._realX, ev._realY, Silv.Minimap.Menu.EventRenderSize, Silv.Minimap.Menu.EventRenderSize);
  1481.         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);
  1482.     }
  1483.    
  1484.     // Draw Player
  1485.     if (this.playerBlipEnabled)
  1486.     {
  1487.         this.drawPlayerBlip(Silv.Minimap.Menu.Bmp, this.translateLocationMenu, this.playerInfo.src.x, this.playerInfo.src.y, this.playerInfo.src.width, this.playerInfo.src.height,
  1488.                             Silv.Minimap.Menu.PlayerIconSize, Silv.Minimap.Menu.PlayerIconSize);
  1489.     }
  1490. };
  1491. //----------------------------------------------------------------------------------------------------
  1492. // Menu Create #Markers
  1493. //----------------------------------------------------------------------------------------------------
  1494. Window_Minimap.prototype.createMenuMarkers = function()
  1495. {
  1496.     Silv.Minimap.Menu.Markers = [];
  1497.    
  1498.     // Player
  1499.     var playerMapLoc = this.translateLocationMenu(this, $gamePlayer._realX, $gamePlayer._realY, Silv.Minimap.Menu.PlayerIconSize, Silv.Minimap.Menu.PlayerIconSize);
  1500.     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});
  1501.    
  1502.     // POI's
  1503.     for (var i = 0; i < this.getAllPOI().length; i++)
  1504.     {
  1505.         var poi = this.getPOIByIdx(i);
  1506.         var poiLoc = this.translateLocationMenu(this, poi.real_x, poi.real_y, poi.destSize.w, poi.destSize.h);
  1507.        
  1508.         var tp = poi.tp.slice(0); // slice(0) clones it
  1509.         if (this.allowTeleportation && (poi.tp !== null))
  1510.         {
  1511.             tp[0] = parseInt(tp[0]) + parseInt(poi.real_x);
  1512.             tp[1] = parseInt(tp[1]) + parseInt(poi.real_y);
  1513.         }
  1514.        
  1515.         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});
  1516.     }
  1517.    
  1518.     // Events
  1519.     for (var i=0; i < Silv.Minimap.Events.length; i++)
  1520.     {
  1521.         var ev = Silv.Minimap.Events[i].event;
  1522.         var dataMapEvent = dataMapGetEventByID(ev._eventId);
  1523.         if (dataMapEvent)
  1524.         {
  1525.             var evMapLoc = this.translateLocationMenu(this, ev._realX, ev._realY, Silv.Minimap.Menu.EventRenderSize, Silv.Minimap.Menu.EventRenderSize);
  1526.            
  1527.             var desc = '';
  1528.             if ('mm_desc' in ev) { desc = ev.mm_desc.join(' '); }
  1529.            
  1530.             var tp = null;
  1531.             if (this.allowTeleportation && ('mm_tp' in ev))
  1532.             {
  1533.                 tp = ev.mm_tp.slice(0); // slice(0) clones it
  1534.                 tp[0] = parseInt(tp[0]) + parseInt(ev._x);
  1535.                 tp[1] = parseInt(tp[1]) + parseInt(ev._y);
  1536.             }
  1537.  
  1538.             Silv.Minimap.Menu.Markers.push({ text:dataMapEvent.name, map_x:evMapLoc.x, map_y:evMapLoc.y, w:Silv.Minimap.Menu.EventRenderSize, h:Silv.Minimap.Menu.EventRenderSize, desc:desc, tp:tp });
  1539.         }
  1540.     }
  1541. };
  1542. //----------------------------------------------------------------------------------------------------
  1543. // #FoW / #Fog of War
  1544. //----------------------------------------------------------------------------------------------------
  1545. Window_Minimap.prototype.onFinishOriginalFoWBmpLoad = function()
  1546. {
  1547.     this.cloneOriginalFoWBmpToCurrent();
  1548.    
  1549.     this.fowSection_w = this.fowCurrentBmp.width;
  1550.     this.fowSection_h = this.fowCurrentBmp.height;
  1551.    
  1552.     this.finishBmpLoad();
  1553.    
  1554.     if (this.fowRequiresRefresh)
  1555.     {
  1556.         this.refreshFoWBmp();
  1557.         this.fowRequiresRefresh = false;
  1558.     }
  1559.    
  1560.     // The line below reveals the tiles around the player for when the player enters a map for the first time
  1561.     if (this.fowEnabled) { this.updateFoW(); }
  1562. };
  1563.  
  1564. // 'Clone' the original bitmap over the current one.
  1565. Window_Minimap.prototype.cloneOriginalFoWBmpToCurrent = function()
  1566. {
  1567.     this.fowCurrentBmp = new Bitmap($gameMap.width() * $gameMap.tileWidth(), $gameMap.height() * $gameMap.tileHeight());//new Bitmap(this.fowOriginalBmp.width, this.fowOriginalBmp.height);
  1568.     this.fowCurrentBmp.blt(this.fowOriginalBmp, 0, 0, this.fowOriginalBmp.width, this.fowOriginalBmp.height, 0, 0, this.fowCurrentBmp.width, this.fowCurrentBmp.height);
  1569. };
  1570.  
  1571. // Renders the current FoW bmp onto the specified bmp
  1572. // src_x and src_y are the UNSCALED x&y source-locations of the this.fowCurrentBmp.
  1573. Window_Minimap.prototype.applyFoWSection = function(toThisBmp, borderOffset_x, borderOffset_y, src_x, src_y, scale_x, scale_y, isAutoFitMode, src_w, src_h)
  1574. {
  1575.     var srcCalcBmp = isAutoFitMode ? this.fowCurrentBmp : toThisBmp;
  1576.    
  1577.     var dest_w = toThisBmp.width - borderOffset_x * 2;
  1578.     var dest_h = toThisBmp.height - borderOffset_y * 2;
  1579.    
  1580.     if (src_w === null) { src_w = srcCalcBmp.width / scale_x; }
  1581.     if (src_x + src_w > this.fowCurrentBmp.width) { src_w -= (src_x + src_w) - this.fowCurrentBmp.width; }
  1582.     if (src_h === null) { src_h = srcCalcBmp.height / scale_y; }
  1583.     if (src_y + src_h > this.fowCurrentBmp.height) { src_h -= (src_y + src_h) - this.fowCurrentBmp.height; }
  1584.    
  1585.     toThisBmp.blt(this.fowCurrentBmp, src_x, src_y, src_w, src_h, borderOffset_x, borderOffset_y, dest_w, dest_h);
  1586. };
  1587.  
  1588. // Note: does NOT reset the this.fowCurrentBmp
  1589. Window_Minimap.prototype.resetFoWData = function()
  1590. {
  1591.     Silv.Minimap.FoWData[$gameMap._mapId] = {};
  1592.    
  1593.     // Create a new 2d array: Silv.Minimap.FoWData[$gameMap._mapId].tiles[x][y]
  1594.     Silv.Minimap.FoWData[$gameMap._mapId].tiles = new Array($gameMap.width()); 
  1595.     var mapHeight = $gameMap.height();
  1596.     for (var i=0; i<Silv.Minimap.FoWData[$gameMap._mapId].tiles.length; i++) { Silv.Minimap.FoWData[$gameMap._mapId].tiles[i] = new Array(mapHeight); }
  1597.    
  1598.     // Fill the arrays with: false instead of the default undefined.
  1599.     // Note that the loop must start with x instead of y because of how the length in the 2nd loop is calculated
  1600.     for(var x=0; x<Silv.Minimap.FoWData[$gameMap._mapId].tiles.length; x++)
  1601.     {
  1602.         for(var y=0; y<Silv.Minimap.FoWData[$gameMap._mapId].tiles[x].length; y++)
  1603.         {
  1604.             Silv.Minimap.FoWData[$gameMap._mapId].tiles[x][y] = false;
  1605.         }
  1606.     }
  1607.    
  1608.     // Create the Completion Data
  1609.     this.resetFoWCompletion();
  1610. };
  1611.  
  1612. Window_Minimap.prototype.resetFoWCompletion = function()
  1613. {
  1614.     var adjust = ('mm_fow_completion' in $dataMap.meta) ? adjust = parseInt($dataMap.meta.mm_fow_completion) : 0;
  1615.    
  1616.     var totalTileCnt = $gameMap.width() * $gameMap.height() + adjust;
  1617.     Silv.Minimap.FoWData[$gameMap._mapId].completion =
  1618.     {
  1619.         totalTiles:totalTileCnt,
  1620.         emptyTileCnt:totalTileCnt,
  1621.         completedTileCnt:0,
  1622.         completePerc:0.00
  1623.     };
  1624. };
  1625.  
  1626. // Reveal tiles when the player arrived on a new tile
  1627. Silv.AddAlias('mm_Game_Player_updateMove', Game_Player.prototype.updateMove);
  1628. Game_Player.prototype.updateMove = function()
  1629. {
  1630.     Silv.Alias.mm_Game_Player_updateMove.apply(this, arguments);
  1631.     if (!this.isMoving()) { this.preUpdateFoW(); }
  1632. };
  1633.  
  1634. // Reveal tiles after a transfer
  1635. // code below wont work because the image isnt loaded at that point anyway, like ever
  1636. // Silv.AddAlias('mm_Game_Player_clearTransferInfo', Game_Player.prototype.clearTransferInfo);
  1637. // Game_Player.prototype.clearTransferInfo = function()
  1638. // {
  1639.     // Silv.Alias.mm_Game_Player_clearTransferInfo.apply(this, arguments);
  1640.     // this.preUpdateFoW();
  1641. // };
  1642.  
  1643. Game_Player.prototype.preUpdateFoW = function()
  1644. {
  1645.     if (Silv.Minimap.Window && Silv.Minimap.Window.fowEnabled) { Silv.Minimap.Window.updateFoW(); }
  1646. };
  1647.  
  1648. Window_Minimap.prototype.updateFoW = function()
  1649. {
  1650.     // Do nothing if the player has no radius and also do nothing if the bitmaps have not yet finished loading
  1651.     if ((this.fowRadius < 1) || !this.finishedBmpPreloading) { return; }
  1652.    
  1653.     //Reveal the tiles within the player's radius, if not already revealed.
  1654.     for (var delta_y = -this.fowRadius + 1; delta_y<this.fowRadius; delta_y++)
  1655.     {
  1656.         for (var delta_x = -this.fowRadius + 1; delta_x<this.fowRadius; delta_x++)
  1657.         {
  1658.             if (Math.abs(delta_x) + Math.abs(delta_y) < this.fowRadius) // this if-statement transforms the 'reveal-square' into a 45 degree rotated 'reveal-square'
  1659.             {
  1660.                 var x = this.clamp($gamePlayer._x + delta_x, 0, $gameMap.width() - 1);
  1661.                 var y = this.clamp($gamePlayer._y + delta_y, 0, $gameMap.height() - 1);
  1662.                 this.updateFoWTile(x, y, true);
  1663.             }
  1664.         }
  1665.     }
  1666. };
  1667.  
  1668. Window_Minimap.prototype.updateFoWTile = function(x, y, value)
  1669. {
  1670.     if (Silv.Minimap.FoWData[$gameMap._mapId].tiles[x][y] !== value)
  1671.     {
  1672.         Silv.Minimap.FoWData[$gameMap._mapId].tiles[x][y] = value;
  1673.         (value) ? this.fowRevealTileInBmp(x, y) : this.fowHideTileInBmp(x, y);
  1674.        
  1675.         // Modify completion data
  1676.         var completionValue = (value) ? 1 : -1;
  1677.         Silv.Minimap.FoWData[$gameMap._mapId].completion.emptyTileCnt     -= completionValue;
  1678.         Silv.Minimap.FoWData[$gameMap._mapId].completion.completedTileCnt += completionValue;
  1679.         Silv.Minimap.FoWData[$gameMap._mapId].completion.completePerc      = Math.min(1.0, Silv.Minimap.FoWData[$gameMap._mapId].completion.completedTileCnt / parseFloat(Silv.Minimap.FoWData[$gameMap._mapId].completion.totalTiles));
  1680.         if (Silv.Minimap.FoWData[$gameMap._mapId].completion.completePerc === 1.0) { this.onFullyRevealedMap(x, y); }
  1681.     }
  1682. };
  1683.  
  1684. Window_Minimap.prototype.fowRevealTileInBmp = function(x, y)
  1685. {
  1686.     var tile_w = $gameMap.tileWidth();
  1687.     var tile_h = $gameMap.tileHeight();
  1688.     this.fowCurrentBmp.clearRect(x * tile_w, y * tile_h, tile_w, tile_h);
  1689. };
  1690.  
  1691. Window_Minimap.prototype.fowHideTileInBmp = function(x, y)
  1692. {
  1693.     var tile_w = $gameMap.tileWidth();
  1694.     var tile_h = $gameMap.tileHeight();
  1695.     var dest_x = x * tile_w;
  1696.     var dest_y = y * tile_h;
  1697.     var zoom_x = this.fowOriginalBmp.width / parseFloat(this.fowCurrentBmp.width);
  1698.     var zoom_y = this.fowOriginalBmp.height / parseFloat(this.fowCurrentBmp.height);
  1699.    
  1700.     this.fowCurrentBmp.blt(this.fowOriginalBmp, dest_x * zoom_x, dest_y * zoom_y, tile_w * zoom_x, tile_h * zoom_y, dest_x, dest_y, tile_w, tile_h);
  1701. };
  1702.  
  1703. // Recalculates the entire this.fowCurrentBmp from the Silv.Minimap.FoWData
  1704. Window_Minimap.prototype.refreshFoWBmp = function()
  1705. {
  1706.     this.cloneOriginalFoWBmpToCurrent();
  1707.     for (var y=0; y<$gameMap.height(); y++)
  1708.     {
  1709.         for (var x=0; x<$gameMap.width(); x++)
  1710.         {
  1711.             if (Silv.Minimap.FoWData[$gameMap._mapId].tiles[x][y]) { this.fowRevealTileInBmp(x, y); }
  1712.         }
  1713.     }
  1714. };
  1715.  
  1716. // Reveals OR hides all the tiles between 2 tile-coordinates. Note that the tile-coordinates itself are also included.
  1717. Window_Minimap.prototype.fowChangeTilesBetweenCoords = function(x1, y1, x2, y2, value)
  1718. {
  1719.     for (var y=y1; y<=y2; y++)
  1720.     {
  1721.         for (var x=x1; x<=x2; x++)
  1722.         {
  1723.             this.updateFoWTile(x, y, value);
  1724.         }
  1725.     }
  1726. };
  1727.  
  1728. Window_Minimap.prototype.getFowCompletion = function(mapId)
  1729. {
  1730.     if (!mapId) { mapId = $gameMap._mapId; }
  1731.     if (!Silv.Minimap.FoWData[mapId]) { return 0; }
  1732.     return Silv.Minimap.FoWData[mapId].completion;
  1733. };
  1734.  
  1735. Window_Minimap.prototype.fowRevealEntireMap = function()
  1736. {
  1737.     for(var y=0; y<Silv.Minimap.FoWData[$gameMap._mapId].tiles.length; y++)
  1738.     {
  1739.         for(var x=0; x<Silv.Minimap.FoWData[$gameMap._mapId].tiles[y].length; x++)
  1740.         {
  1741.             Silv.Minimap.FoWData[$gameMap._mapId].tiles[x][y] = true;
  1742.         }
  1743.     }
  1744.    
  1745.     // Reveal Bitmap
  1746.     this.fowCurrentBmp = new Bitmap(this.fowCurrentBmp.width, this.fowCurrentBmp.height);
  1747.    
  1748.     // Modify completion data
  1749.     Silv.Minimap.FoWData[$gameMap._mapId].completion.emptyTileCnt     = 0;
  1750.     Silv.Minimap.FoWData[$gameMap._mapId].completion.completedTileCnt = Silv.Minimap.FoWData[$gameMap._mapId].completion.totalTiles;
  1751.     Silv.Minimap.FoWData[$gameMap._mapId].completion.completePerc     = 1.0;
  1752.     this.onFullyRevealedMap($gameMap.width() - 1, $gameMap.height() - 1);
  1753. };
  1754.  
  1755. Window_Minimap.prototype.fowHideEntireMap = function(revealTilesAroundPlayer)
  1756. {
  1757.     this.resetFoWData();
  1758.     this.cloneOriginalFoWBmpToCurrent();
  1759.     if (revealTilesAroundPlayer) { this.updateFoW(); }
  1760. };
  1761.  
  1762. Window_Minimap.prototype.onFullyRevealedMap = function(x, y){};
  1763.  
  1764. //----------------------------------------------------------------------------------------------------
  1765. // #Rendering #Drawing
  1766. //----------------------------------------------------------------------------------------------------
  1767. Window_Minimap.prototype.setPlayerBlip = function(filename)
  1768. {
  1769.     this.usePlayerBlipGfx = (filename == ':player');
  1770.     if (this.usePlayerBlipGfx) { this.playerBlipBmp = null; }
  1771.     else { this.playerBlipBmp = ImageManager.loadMinimap(filename); }
  1772. };
  1773.  
  1774. Window_Minimap.prototype.drawPlayerBlip = function(destBmp, translateFunc, src_x, src_y, src_w, src_h, dest_w, dest_h)
  1775. {
  1776.     var playerMapLoc = translateFunc(this, $gamePlayer._realX, $gamePlayer._realY, dest_w, dest_h);
  1777.     if (this.usePlayerBlipGfx)
  1778.     {
  1779.         destBmp.blt(this.playerInfo.bmp, src_x, src_y, src_w, src_h, playerMapLoc.x, playerMapLoc.y, dest_w, dest_h);
  1780.     }
  1781.     else
  1782.     {
  1783.         // Use custom player blip graphic
  1784.         if (this.playerBlipBmp.isReady())
  1785.         {
  1786.             destBmp.blt(this.playerBlipBmp, 0, 0, this.playerBlipBmp.width, this.playerBlipBmp.height, playerMapLoc.x, playerMapLoc.y, dest_w, dest_h);
  1787.         }
  1788.     }
  1789. };
  1790.  
  1791. Window_Minimap.prototype.drawMinimap = function()
  1792. {
  1793.     this.contents.clear();
  1794.    
  1795.     // BG fill colour, if applicable
  1796.     this.contents.fillRect(Silv.Minimap.BorderWidth, Silv.Minimap.BorderHeight, this.drawAreaWidth, this.drawAreaHeight, Silv.Minimap.MapBGFillColor);
  1797.    
  1798.     switch(this.mapStyle)
  1799.     {
  1800.         case 'autofit':
  1801.             this.drawstyleAutofit();
  1802.             break;
  1803.         case 'scroll':
  1804.             this.drawstyleScroll();
  1805.             break; 
  1806.         default:
  1807.             throw new Error('Window_Minimap.prototype.drawMinimap invalid switch value: ' + this.mapStyle);
  1808.     }
  1809. };
  1810.  
  1811. Window_Minimap.prototype.drawstyleAutofit = function()
  1812. {
  1813.     // Opacity
  1814.     this.contents.paintOpacity = this.opacity = Silv.Minimap.Window_Opacity;
  1815.    
  1816.     var destination_w = this.drawAreaWidth  * this.mapAspRatInfo.w;
  1817.     var destination_h = this.drawAreaHeight * this.mapAspRatInfo.h;
  1818.    
  1819.     // Calculate the aspect ratio offsets
  1820.     this.mapAspRatInfo.offset_x = 0.0; // to center the map
  1821.     this.mapAspRatInfo.offset_y = 0.0; // to center the map
  1822.     if (this.mapAspRatInfo.w < 1.0) { this.mapAspRatInfo.offset_x = (this.drawAreaWidth  - destination_w) / 2.0; }
  1823.     if (this.mapAspRatInfo.h < 1.0) { this.mapAspRatInfo.offset_y = (this.drawAreaHeight - destination_h) / 2.0; }
  1824.    
  1825.     // This variable saves on calculations further down the road during this update
  1826.     // w = width, hw=  half width, zhw = zoomed half width
  1827.     this.tileInfo = {
  1828.             w: $gameMap.tileWidth(), hw: $gameMap.tileWidth() / 2.0, zhw: ($gameMap.tileWidth() / 2.0) * this.mapAspRatInfo.w,
  1829.             h: $gameMap.tileHeight(), hh: $gameMap.tileHeight() / 2.0, zhh: ($gameMap.tileHeight() / 2.0) * this.mapAspRatInfo.h
  1830.         };
  1831.    
  1832.     // Draw Map
  1833.     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);
  1834.     if (this.fowEnabled) { this.applyFoWSection(this.contents, Silv.Minimap.BorderWidth, Silv.Minimap.BorderHeight, 0, 0, this.mapAspRatInfo.w, this.mapAspRatInfo.h, true, null, null); }
  1835.  
  1836.     // Debug Grid (if applicable)
  1837.     if (Silv.Minimap.DrawDebugGrid)
  1838.     {
  1839.         for (var i=0; i < $gameMap.width(); i++)
  1840.         {
  1841.             for (var j=0; j < $gameMap.height(); j++)
  1842.             {
  1843.                 var debugTileLoc = this.translateLocationAutofit(this, i, j, this.tileInfo.w * this.mapAspRatInfo.w, this.tileInfo.h * this.mapAspRatInfo.h);
  1844.                 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);
  1845.             }
  1846.         }
  1847.     }
  1848.    
  1849.     // Draw POI's
  1850.     for (var i = 0; i < this.getAllPOI().length; i++)
  1851.     {
  1852.         var poi = this.getPOIByIdx(i);
  1853.         var poiLoc = this.translateLocationAutofit(this, poi.real_x, poi.real_y, poi.destSize.w, poi.destSize.h);
  1854.         this.contents.blt(poi.bmp, poi.src.x, poi.src.y, poi.src.w, poi.src.h,
  1855.                           poiLoc.x, poiLoc.y, poi.destSize.w, poi.destSize.h);
  1856.     }
  1857.    
  1858.     // Draw Events
  1859.     for (var i=0; i < Silv.Minimap.Events.length; i++)
  1860.     {
  1861.         var ev = Silv.Minimap.Events[i].event;
  1862.         var ev_sprite = Silv.Minimap.Events[i].sprite;
  1863.         var evMapLoc = this.translateLocationAutofit(this, ev._realX, ev._realY, Silv.Minimap.EventRenderSize, Silv.Minimap.EventRenderSize);
  1864.         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);
  1865.     }
  1866.    
  1867.     // Draw Player
  1868.     if (this.playerBlipEnabled && this.playerBlink_IsVisible)
  1869.     {
  1870.         this.drawPlayerBlip(this.contents, this.translateLocationAutofit, this.playerInfo.src.x, this.playerInfo.src.y, this.playerInfo.src.width, this.playerInfo.src.height,
  1871.                             Silv.Minimap.PlayerIconWidth, Silv.Minimap.PlayerIconHeight);
  1872.     }
  1873.    
  1874.     // Overlay (if applicable)
  1875.     if (Silv.Minimap.DrawOverlay) { this.drawOverlay(); }
  1876. };
  1877.  
  1878. Window_Minimap.prototype.drawstyleScroll = function()
  1879. {
  1880.     // Opacity
  1881.     this.contents.paintOpacity = this.opacity = Silv.Minimap.Window_Opacity;
  1882.    
  1883.     // 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
  1884.     if (this.mapScroll.x < 0 || this.drawAreaWidth  * this.mapZoomInverse > this.mapBmp.width ||
  1885.         this.mapScroll.y < 0 || this.drawAreaHeight * this.mapZoomInverse > this.mapBmp.height)
  1886.         {
  1887.             this.drawstyleAutofit();
  1888.             return;
  1889.         }
  1890.    
  1891.     // This variable saves on calculations further down the road during this update
  1892.     // w = width, hw=  half width, zhw = zoomed half width
  1893.     this.tileInfo = {
  1894.             w: $gameMap.tileWidth(), hw: $gameMap.tileWidth() / 2.0, zhw: ($gameMap.tileWidth() / 2.0) * this.mapZoom,
  1895.             h: $gameMap.tileHeight(), hh: $gameMap.tileHeight() / 2.0, zhh: ($gameMap.tileHeight() / 2.0) * this.mapZoom
  1896.         };
  1897.    
  1898.     // Draw Map
  1899.     // var map_src_rect = { x:0.0, y:0.0, w:0.0, h:0.0};
  1900.     // map_src_rect.x = this.mapScroll.x;
  1901.     // map_src_rect.y = this.mapScroll.y;
  1902.     // map_src_rect.w = this.drawAreaWidth * this.mapZoomInverse;
  1903.     // map_src_rect.h = this.drawAreaHeight * this.mapZoomInverse;
  1904.     // Draw Map
  1905.     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);
  1906.     if (this.fowEnabled) { this.applyFoWSection(this.contents, Silv.Minimap.BorderWidth, Silv.Minimap.BorderHeight, this.mapScroll.x - 0, this.mapScroll.y - 0, this.mapZoom, this.mapZoom, false, this.drawAreaWidth * this.mapZoomInverse, this.drawAreaHeight * this.mapZoomInverse); }
  1907.    
  1908.     // Debug Grid (if applicable)
  1909.     if (Silv.Minimap.DrawDebugGrid)
  1910.     {
  1911.         for (var i=0; i < $gameMap.width(); i++)
  1912.         {
  1913.             for (var j=0; j < $gameMap.height(); j++)
  1914.             {
  1915.                 var debugTileLoc = this.translateLocationScroll(this, i, j, this.tileInfo.w * this.mapZoom, this.tileInfo.h * this.mapZoom);
  1916.                 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);
  1917.             }
  1918.         }
  1919.     }
  1920.    
  1921.     // Draw POI's
  1922.     for (var i = 0; i < this.getAllPOI().length; i++)
  1923.     {
  1924.         var poi = this.getPOIByIdx(i);
  1925.         var poiLoc = this.translateLocationScroll(this, poi.real_x, poi.real_y, poi.destSize.w, poi.destSize.h);
  1926.         this.contents.blt(poi.bmp, poi.src.x, poi.src.y, poi.src.w, poi.src.h,
  1927.                           poiLoc.x, poiLoc.y, poi.destSize.w, poi.destSize.h);
  1928.     }
  1929.  
  1930.     // Draw Events
  1931.     for (var i=0; i < Silv.Minimap.Events.length; i++)
  1932.     {
  1933.         var ev = Silv.Minimap.Events[i].event;
  1934.         var ev_sprite = Silv.Minimap.Events[i].sprite;
  1935.         var evMapLoc = this.translateLocationScroll(this, ev._realX, ev._realY, Silv.Minimap.EventRenderSize, Silv.Minimap.EventRenderSize);
  1936.         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);
  1937.     }
  1938.    
  1939.     // Draw Player
  1940.     if (this.playerBlipEnabled && this.playerBlink_IsVisible)
  1941.     {
  1942.         this.drawPlayerBlip(this.contents, this.translateLocationScroll, this.playerInfo.src.x, this.playerInfo.src.y, this.playerInfo.src.width, this.playerInfo.src.height,
  1943.                             Silv.Minimap.PlayerIconWidth, Silv.Minimap.PlayerIconHeight);
  1944.     }
  1945.    
  1946.     // Overlay (if applicable)
  1947.     if (Silv.Minimap.DrawOverlay) { this.drawOverlay(); }
  1948. };
  1949.  
  1950. Window_Minimap.prototype.drawOverlay = function()
  1951. {
  1952.     this.contents.blt(this.overlayBmp, 0, 0, this.overlayBmp.width, this.overlayBmp.height, 0, 0, this.width, this.height);
  1953. };
  1954. //----------------------------------------------------------------------------------------------------
  1955. // #Translate functions
  1956. // Important: Because the translate functions are assigned to a variable, the this-keyword will be undefined! Therefore 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.
  1957. // For more info see: http://stackoverflow.com/questions/4011793/this-is-undefined-in-javascript-class-methods
  1958. //----------------------------------------------------------------------------------------------------
  1959. // returns {x, y}
  1960. Window_Minimap.prototype.translateLocationScroll = function(that, obj_real_x, obj_real_y, obj_w, obj_h)
  1961. {
  1962.     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;
  1963.     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;
  1964.     return {x: obj_x, y: obj_y};
  1965. };
  1966.  
  1967. // returns {x, y}
  1968. Window_Minimap.prototype.translateLocationAutofit = function(that, obj_real_x, obj_real_y, obj_w, obj_h)
  1969. {
  1970.     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;
  1971.     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;
  1972.     return {x: obj_x, y: obj_y};
  1973. };
  1974.  
  1975. // returns {x, y}
  1976. Window_Minimap.prototype.translateLocationMenu = function(that, obj_real_x, obj_real_y, obj_w, obj_h)
  1977. {
  1978.     var obj_x = (obj_real_x * that.tileInfo.w + that.tileInfo.hw) * that.menuZoom - obj_w / 2.0;
  1979.     var obj_y = (obj_real_y * that.tileInfo.h + that.tileInfo.hh) * that.menuZoom - obj_h / 2.0;
  1980.     return {x: obj_x, y: obj_y};
  1981. };
  1982. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1983. // #POI
  1984. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1985. function MM_POI() { this.initialize.apply(this, arguments); }
  1986. // Set Constructor
  1987. MM_POI.prototype.constructor = MM_POI;
  1988.  
  1989. // Initialization
  1990. // real_x & real_y are in tiles
  1991. 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)
  1992. {
  1993.   this.id = poi_id;
  1994.   this.name = name;
  1995.   this.desc = desc;
  1996.   this.real_x = real_x;
  1997.   this.real_y = real_y;
  1998.   this.folderPath = folderPath; // Required for saving&loading
  1999.   this.filename = filename; // Required for saving&loading
  2000.   this.bmp = ImageManager.loadBitmap(folderPath, filename, 0, false);
  2001.   this.src = { x:source_x, y:source_y, w:source_w, h:source_h };
  2002.   this.destSize = { w:draw_w, h:draw_h };
  2003.   this.tp = null;
  2004. };
  2005.  
  2006. // Note: Does not include the Bitmap
  2007. MM_POI.prototype.makeSaveContents = function()
  2008. {
  2009.     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 };
  2010. };
  2011.  
  2012. // Retrieves all the POI's for the current active $gameMap
  2013. Window_Minimap.prototype.getAllPOI = function()
  2014. {
  2015.     return Silv.Minimap.POI[$gameMap._mapId];
  2016. };
  2017.  
  2018. // Retrieves the specified POI by index for the current active $gameMap. Note this is NOT by POI id, this is by index.
  2019. Window_Minimap.prototype.getPOIByIdx = function(index)
  2020. {
  2021.     return Silv.Minimap.POI[$gameMap._mapId][index];
  2022. };
  2023.  
  2024. Window_Minimap.prototype.getPOIByID = function(id)
  2025. {
  2026.     for (var i=0; i<Silv.Minimap.POI[$gameMap._mapId].length; i++)
  2027.     {
  2028.         if (Silv.Minimap.POI[$gameMap._mapId][i].id == id) { return Silv.Minimap.POI[$gameMap._mapId][i]; }
  2029.     }
  2030.     throw new Error('getPOIByID(' + id + ') not found.');
  2031. };
  2032. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2033. // #Create the Minimap window
  2034. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2035. //----------------------------------------------------------------------------------------------------
  2036. // Scene Map (alias): Create Display Objects
  2037. //----------------------------------------------------------------------------------------------------
  2038. Silv.AddAlias('mm_Scene_Map_createDisplayObjects', Scene_Map.prototype.createDisplayObjects);
  2039. Scene_Map.prototype.createDisplayObjects = function()
  2040. {
  2041.     Silv.Alias.mm_Scene_Map_createDisplayObjects.apply(this, arguments);
  2042.     Silv.Minimap.setup();
  2043. };
  2044. //----------------------------------------------------------------------------------------------------
  2045. // Setup Minimap
  2046. // Call this method to create or re-create the minimap, if required. It does only create a minimap
  2047. // if it passes all the checks.
  2048. // Example: Silv.Minimap.setup();
  2049. //----------------------------------------------------------------------------------------------------
  2050. Silv.Minimap.setup = function()
  2051. {
  2052.     var didMapChange = $gameMap._mapId != this.LastMapID;
  2053.     if (didMapChange)
  2054.     {
  2055.         if (this.WasLoadedFromSave)
  2056.         {
  2057.             this.WasLoadedFromSave = false;
  2058.         }
  2059.         else
  2060.         {
  2061.             if (this.AutoClearPOI) { this.POI[$gameMap._mapId] = []; }
  2062.         }
  2063.     }
  2064.    
  2065.     // Create empty POI array if it's not defined yet for this map
  2066.     if (typeof this.POI[$gameMap._mapId] === 'undefined') { this.POI[$gameMap._mapId] = []; }
  2067.  
  2068.     SceneManager._scene.attemptToCreateMinimap();
  2069.     this.LastMapID = $gameMap._mapId;
  2070. };
  2071. //----------------------------------------------------------------------------------------------------
  2072. // Attempt To Create Minimap
  2073. //----------------------------------------------------------------------------------------------------
  2074. Scene_Map.prototype.attemptToCreateMinimap = function()
  2075. {
  2076.     var mapName = lpad_mapname($gameMap._mapId, '0') + '.png';
  2077.     if ('mm_mapshot' in $dataMap.meta)
  2078.     {
  2079.         if (Silv.Minimap.DebugMode) { console.log('A mapshot-notetag was found:' + $dataMap.meta.mm_mapshot + '.'); }
  2080.         mapName = lpad_mapname($dataMap.meta.mm_mapshot, '0') + '.png';
  2081.     }
  2082.    
  2083.     var createMinimap = false;
  2084.     var minimapType = null;
  2085.     var hasRequiredItems = this.MinimapHasRequiredItems();
  2086.    
  2087.     if (Silv.Minimap.Window !== null)
  2088.     {
  2089.         // #Dispose
  2090.         // 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.
  2091.         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...
  2092.         Silv.Minimap.Window = null;
  2093.         Silv.Minimap.Menu.Enabled = false;
  2094.         Silv.Minimap.Menu.Bmp = null;
  2095.         Silv.Minimap.Menu.Markers = [];
  2096.     }
  2097.    
  2098.     var windowWasVisible = Silv.Minimap.Visible;
  2099.     if (minimapImageExists(mapName))
  2100.     {
  2101.         if (hasRequiredItems)
  2102.         {
  2103.             createMinimap = true;
  2104.             minimapType = 'regular';
  2105.         }
  2106.     }
  2107.     else
  2108.     {
  2109.         if (Silv.Minimap.DebugMode) { console.log('No minimap \'' + mapName + '\' found for map with map-id: ' + $gameMap._mapId + '.'); }
  2110.        
  2111.         if (hasRequiredItems)
  2112.         {
  2113.             if (('mm_generate_worldmap' in $dataMap.meta) || ('mm_generate_overworld' in $dataMap.meta))
  2114.             {
  2115.                 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.'); }
  2116.                 createMinimap = true;
  2117.                 minimapType = 'generate_overworld';
  2118.             } else if ('mm_generate_map' in $dataMap.meta)
  2119.             {
  2120.                 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.'); }
  2121.                 createMinimap = true;
  2122.                 minimapType = 'generate_map';
  2123.             }
  2124.         }
  2125.     }
  2126.    
  2127.     if (createMinimap)
  2128.     {
  2129.         this.createMinimapWindow(mapName.replace('.png', ''), minimapType);
  2130.         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.
  2131.         if ('mm_generate_passability_overlay' in $dataMap.meta) { Silv.Minimap.Window.setPassabilityOverlay(true); }
  2132.     }
  2133.     // else
  2134.     // {
  2135.         //'Dispose'
  2136.         //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.
  2137.         // Silv.Minimap.Window = null;
  2138.     // }
  2139. };
  2140. //----------------------------------------------------------------------------------------------------
  2141. // Scene_Base: Remove Window
  2142. //----------------------------------------------------------------------------------------------------
  2143. // Omg why does RPG Maker not have this method by default...
  2144. Scene_Base.prototype.removeWindow = function(window)
  2145. {
  2146.     var index = this.children.indexOf(window);
  2147.     if (index > -1) { this.children.splice(index, 1); }
  2148. };
  2149. //----------------------------------------------------------------------------------------------------
  2150. // Create Minimap Window
  2151. //----------------------------------------------------------------------------------------------------
  2152. Scene_Map.prototype.createMinimapWindow = function(mapname, minimapType)
  2153. {
  2154.     var x = 0;
  2155.     if (Silv.Minimap.WindowHorizontalAlignment == 'right') { x = Graphics.width - Silv.Minimap.WindowWidth; }
  2156.     var y = 0;
  2157.     if (Silv.Minimap.WindowVerticalAlignment == 'bottom') { y = Graphics.height - Silv.Minimap.WindowHeight; }
  2158.    
  2159.     Silv.Minimap.Window = new Window_Minimap(x + Silv.Minimap.Window_X, y + Silv.Minimap.Window_Y, Silv.Minimap.WindowWidth, Silv.Minimap.WindowHeight, mapname, minimapType);
  2160.     Silv.Minimap.Window.resetFade();
  2161.    
  2162.     // override frameskip (map-specific frameskip)
  2163.     if ('mm_frameskip' in $dataMap.meta)
  2164.     {
  2165.         Silv.Minimap.Window.frameSkip = parseInt($dataMap.meta.mm_frameskip);
  2166.         if (Silv.Minimap.DebugMode) { console.log('Global frameskip: ' + Silv.Minimap.FrameSkip + ' was overriden by the map-specific frameskip of: ' + $dataMap.meta.mm_frameskip + '.'); }
  2167.     }
  2168.    
  2169.     this.addChildAt(Silv.Minimap.Window, 1);
  2170. };
  2171. //----------------------------------------------------------------------------------------------------
  2172. // Has Required Items
  2173. //----------------------------------------------------------------------------------------------------
  2174. Scene_Map.prototype.MinimapHasRequiredItems = function()
  2175. {
  2176.     // Check global item
  2177.     if (Silv.Minimap.GlobalRequiredItem > 0)
  2178.     {
  2179.         if (!$gameParty.hasItem($dataItems[Silv.Minimap.GlobalRequiredItem], false))
  2180.         {
  2181.             if (Silv.Minimap.DebugMode) { console.log('Minimap (or mapshot-notetag) was found but party does not possess the required global item: ' + $dataItems[Silv.Minimap.GlobalRequiredItem].name); }
  2182.             return false;
  2183.         }
  2184.     }
  2185.    
  2186.     // Check map-specific items
  2187.     if ('mm_req_itm' in $dataMap.meta)
  2188.     {
  2189.         var req_item_ids = $dataMap.meta.mm_req_itm.split(' ').filter(Boolean); // .filter(Boolean) removes empty strings from array
  2190.         for (var i = 0; i < req_item_ids.length; i++)
  2191.         {
  2192.             if (!$gameParty.hasItem($dataItems[req_item_ids[i]], false))
  2193.             {
  2194.                 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); }
  2195.                 return false;
  2196.             }
  2197.         }
  2198.     }
  2199.    
  2200.     return true;
  2201. };
  2202. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2203. // Saving & Loading #Save #Saving #Loading
  2204. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2205. Silv.AddAlias('mm_DataManager_makeSaveContents', DataManager.makeSaveContents);
  2206. DataManager.makeSaveContents = function()
  2207. {
  2208.     contents = Silv.Alias.mm_DataManager_makeSaveContents.apply(this, arguments);
  2209.    
  2210.     contents.minimap = {};
  2211.     contents.minimap.poi = {};
  2212.    
  2213.     // POI
  2214.     for (var mapID in Silv.Minimap.POI)
  2215.     {
  2216.         if (Silv.Minimap.POI.hasOwnProperty(mapID))
  2217.         {
  2218.             if(Silv.Minimap.POI[mapID].length > 0) { contents.minimap.poi[mapID] = []; }
  2219.             for(var poi_idx=0; poi_idx<Silv.Minimap.POI[mapID].length; poi_idx++)
  2220.             {
  2221.                 contents.minimap.poi[mapID].push(Silv.Minimap.Window.getPOIByIdx(poi_idx).makeSaveContents());
  2222.             }
  2223.         }
  2224.     }
  2225.    
  2226.     // FoW
  2227.     contents.minimap.fowData = Silv.Minimap.FoWData;
  2228.    
  2229.     return contents;
  2230. };
  2231.  
  2232. Silv.AddAlias('mm_DataManager_extractSaveContents', DataManager.extractSaveContents);
  2233. DataManager.extractSaveContents = function(contents)
  2234. {
  2235.     Silv.Alias.mm_DataManager_extractSaveContents.apply(this, arguments);
  2236.  
  2237.     // POI
  2238.     Silv.Minimap.POI = {};
  2239.     for (var mapID in contents.minimap.poi)
  2240.     {
  2241.         if (contents.minimap.poi.hasOwnProperty(mapID))
  2242.         {
  2243.             if(contents.minimap.poi[mapID].length > 0) { Silv.Minimap.POI[mapID] = []; }
  2244.             for(var poi_idx=0; poi_idx<contents.minimap.poi[mapID].length; poi_idx++)
  2245.             {
  2246.                 var poi = contents.minimap.poi[mapID][poi_idx];
  2247.                 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);
  2248.                 newPOI.tp = poi.tp;
  2249.                 Silv.Minimap.POI[mapID].push(newPOI);
  2250.             }
  2251.         }
  2252.     }
  2253.    
  2254.     // FoW
  2255.     Silv.Minimap.FoWData = contents.minimap.fowData;
  2256.    
  2257.     // Prevent the minimap from autoclearing it's POI's (if AutoClearPOI is enabled) when loading a savegame
  2258.     Silv.Minimap.WasLoadedFromSave = true;
  2259. };
  2260. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2261. // #Plugin Command
  2262. // Note: The items are separated by spaces. The command is the first word and any following words are args. args is an array.
  2263. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2264. Silv.AddAlias('mm_Game_Interpreter_pluginCommand', Game_Interpreter.prototype.pluginCommand);
  2265. Game_Interpreter.prototype.pluginCommand = function(command, args)
  2266. {
  2267.     Silv.Alias.mm_Game_Interpreter_pluginCommand.apply(this, arguments);
  2268.     if (command.toLowerCase() == 'minimap') { PluginCommand(command, args); }
  2269. };
  2270.  
  2271. function PluginCommand(cmd, args)
  2272. {
  2273.     if (Silv.Minimap.Window === null) { throw new Error('Minimap Plugin Commands can not be used when there is no active minimap. Either create one from a mapshot or generate one automatically'); }
  2274.    
  2275.     switch(args[0].toLowerCase())
  2276.     {
  2277.         case 'hide':
  2278.             Silv.Minimap.Window.hide();
  2279.             break;
  2280.         case 'show':
  2281.             Silv.Minimap.Window.show();
  2282.             break;
  2283.         case 'fadeout':
  2284.             Silv.Minimap.Window.isFadingOut = true;
  2285.             break;
  2286.         case 'fadereset':
  2287.             Silv.Minimap.Window.resetFade();
  2288.             break;
  2289.         case 'refresh':
  2290.             SceneManager._scene.attemptToCreateMinimap(false);
  2291.             break;
  2292.         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
  2293.             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])));
  2294.             SceneManager._scene.attemptToCreateMinimap(false);
  2295.             break;
  2296.         case 'deletepoi':
  2297.             Silv.Minimap.POI[$gameMap._mapId] = Silv.Minimap.POI[$gameMap._mapId].filter(function(poi) { return poi.id != args[1]; });
  2298.             break;
  2299.         case 'poidesc':
  2300.               Silv.Minimap.Window.getPOIByID(parseInt(args[1])).desc = args.join(' ').substr(2 + args[0].length + args[1].length);
  2301.             break;
  2302.         case 'poi_tp': // POI_TP <poi_id x_offset, y_offset, direction, fadeType>
  2303.             Silv.Minimap.Window.getPOIByID(parseInt(args[1])).tp = [parseInt(args[2]), parseInt(args[3]), parseInt(args[4]), parseInt(args[5])];
  2304.             break;
  2305.         case 'refreshevents':
  2306.             Silv.Minimap.Window.loadEvents();
  2307.             break;
  2308.         case 'increasescroll':
  2309.             Silv.Minimap.Window.manualScroll(Silv.Minimap.Window.mapScroll.x + parseFloat(args[1]), Silv.Minimap.Window.mapScroll.y + parseFloat(args[2]));
  2310.             break;
  2311.         case 'setscroll':
  2312.             Silv.Minimap.Window.manualScroll(parseFloat(args[1]), parseFloat(args[2]));
  2313.             break;
  2314.         case 'generate_passability_overlay':
  2315.         case 'gen_pass_ov':
  2316.             Silv.Minimap.setPassabilityOverlay(args[1].toLowerCase() == 'true');
  2317.             break;
  2318.         case 'showmapmenu':
  2319.             Silv.Minimap.Window.showMapMenuScene();
  2320.             break;
  2321.         case 'setplayerblip':
  2322.             Silv.Minimap.Window.setPlayerBlip(args[1]);
  2323.             break;
  2324.         case 'setmapstyle':
  2325.             Silv.Minimap.Window.mapStyle = args[1].toLowerCase();
  2326.             break;
  2327.         case 'setfollowtarget':
  2328.         case 'setcamera':
  2329.             var followType = args[1].toLowerCase();
  2330.             if (followType == 'coordinate')
  2331.             {
  2332.                 Silv.Minimap.Window.setCameraFollowTarget(followType, [parseInt(args[2]), parseInt(args[3])]);
  2333.             }
  2334.             else
  2335.             {
  2336.                 Silv.Minimap.Window.setCameraFollowTarget(followType, args[2]);
  2337.             }
  2338.             break;
  2339.         case 'fowshowtile':
  2340.             if (Silv.Minimap.Window && Silv.Minimap.Window.fowEnabled) { Silv.Minimap.Window.updateFoWTile(parseInt(args[1]), parseInt(args[2]), true); }
  2341.             break;
  2342.         case 'fowhidetile':
  2343.             if (Silv.Minimap.Window && Silv.Minimap.Window.fowEnabled) { Silv.Minimap.Window.updateFoWTile(parseInt(args[1]), parseInt(args[2]), false); }
  2344.             break;
  2345.         case 'fowrevealtiles':
  2346.             if (Silv.Minimap.Window && Silv.Minimap.Window.fowEnabled) { Silv.Minimap.Window.fowChangeTilesBetweenCoords(parseInt(args[1]), parseInt(args[2]), parseInt(args[3]), parseInt(args[4]), true); }
  2347.             break;
  2348.         case 'fowhidetiles':
  2349.             if (Silv.Minimap.Window && Silv.Minimap.Window.fowEnabled) { Silv.Minimap.Window.fowChangeTilesBetweenCoords(parseInt(args[1]), parseInt(args[2]), parseInt(args[3]), parseInt(args[4]), false); }
  2350.             break;
  2351.         case 'fowchangetiles':
  2352.             if (Silv.Minimap.Window && Silv.Minimap.Window.fowEnabled) { Silv.Minimap.Window.fowChangeTilesBetweenCoords(parseInt(args[1]), parseInt(args[2]), parseInt(args[3]), parseInt(args[4]), (args[5].toLowerCase() === 'true')); }
  2353.             break;
  2354.         case 'fowrevealall':
  2355.             if (Silv.Minimap.Window && Silv.Minimap.Window.fowEnabled) { Silv.Minimap.Window.fowRevealEntireMap(); }
  2356.             break;
  2357.         case 'fowreset':
  2358.         case 'fowhideall':
  2359.             var showTilesAroundPlayer = (typeof args[1] === 'undefined') ? true : (args[1].toLowerCase() === 'true');
  2360.             if (Silv.Minimap.Window && Silv.Minimap.Window.fowEnabled) { Silv.Minimap.Window.fowHideEntireMap(showTilesAroundPlayer); }
  2361.             break;
  2362.         default:
  2363.             throw new Error('Minimap, unknown Plugin Command: ' + args[0]);
  2364.     }
  2365. }
  2366. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2367. })();
  2368. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2369. // Map Menu #Scene
  2370. // Note: Must be placed outside of the })();
  2371. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2372. function Scene_MiniMap() { this.initialize.apply(this, arguments); }
  2373.  
  2374. Scene_MiniMap.prototype = Object.create(Scene_MenuBase.prototype);
  2375. Scene_MiniMap.prototype.constructor = Scene_MiniMap;
  2376.  
  2377. Scene_MiniMap.prototype.initialize = function()
  2378. {
  2379.     Scene_MenuBase.prototype.initialize.call(this);
  2380.     SoundManager.playOk();
  2381. };
  2382.  
  2383. Scene_MiniMap.prototype.create = function()
  2384. {
  2385.     Scene_MenuBase.prototype.create.call(this);
  2386.     this.createLeftWindow();
  2387.     this.createMapSectionWindow();
  2388.     this.createMapHelpWindow();
  2389.     this.refreshHelpWindow();
  2390. };
  2391.  
  2392. Scene_MiniMap.prototype.createLeftWindow = function()
  2393. {
  2394.     this._window_left = new Window_MinimapMenuLeft(0, 0);
  2395.     this._window_left.setHandler('ok',     this.onRangeOk.bind(this));
  2396.     this._window_left.setHandler('cancel', this.popScene.bind(this));
  2397.     this._window_left.setHandler('index_changed', this.index_changed.bind(this));
  2398.     this.addWindow(this._window_left);
  2399. };
  2400.  
  2401. Scene_MiniMap.prototype.createMapSectionWindow = function()
  2402. {
  2403.     var wx = this._window_left.width;
  2404.     var ww = Graphics.boxWidth - wx;
  2405.     this._mapSectionWindow = new Window_MapSection(wx, 0, ww);
  2406.     this._mapSectionWindow.setHandler('cancel', this.onEditCancel.bind(this));
  2407.     this._window_left.setMapWindow(this._mapSectionWindow);
  2408.     this.addWindow(this._mapSectionWindow);
  2409. };
  2410.  
  2411. Scene_MiniMap.prototype.createMapHelpWindow = function()
  2412. {
  2413.     var wx = this._mapSectionWindow.x;
  2414.     var wy = this._mapSectionWindow.height;
  2415.     var ww = this._mapSectionWindow.width;
  2416.     var wh = Graphics.boxHeight - wy;
  2417.     this._mapHelpWindow = new Window_Base(wx, wy, ww, wh);
  2418.     this.addWindow(this._mapHelpWindow);
  2419. };
  2420.  
  2421. Scene_MiniMap.prototype.index_changed = function()
  2422. {
  2423.     this.refreshHelpWindow();
  2424. };
  2425.  
  2426. Scene_MiniMap.prototype.onRangeOk = function()
  2427. {
  2428.     this._mapSectionWindow.activate();
  2429.     this._mapSectionWindow.select(0);
  2430.     this.refreshHelpWindow();
  2431. };
  2432.  
  2433. Scene_MiniMap.prototype.onEditCancel = function()
  2434. {
  2435.     this._window_left.activate();
  2436.     this._mapSectionWindow.deselect();
  2437.     this.refreshHelpWindow();
  2438. };
  2439.  
  2440. Scene_MiniMap.prototype.refreshHelpWindow = function()
  2441. {
  2442.     this._mapHelpWindow.contents.clear();
  2443.     this._mapHelpWindow.drawTextEx(this.helpText(), 4, 0);
  2444. };
  2445.  
  2446. Scene_MiniMap.prototype.helpText = function()
  2447. {
  2448.     var marker = this._window_left.marker();
  2449.     var tp_text = '';
  2450.     if (marker.tp !== null) { tp_text = '\nTeleports you to: ' + marker.tp[0] + ',' + marker.tp[1]; }
  2451.     return this._window_left.marker().desc + tp_text;
  2452. };
  2453. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2454. // Left Window #leftwindow
  2455. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2456. function Window_MinimapMenuLeft() { this.initialize.apply(this, arguments); }
  2457.  
  2458. Window_MinimapMenuLeft.prototype = Object.create(Window_Selectable.prototype);
  2459. Window_MinimapMenuLeft.prototype.constructor = Window_MinimapMenuLeft;
  2460.  
  2461. Window_MinimapMenuLeft.lastTopRow = 0;
  2462. Window_MinimapMenuLeft.lastIndex  = 0;
  2463.  
  2464. Window_MinimapMenuLeft.prototype.initialize = function(x, y)
  2465. {
  2466.     var width = this.windowWidth();
  2467.     var height = this.windowHeight();
  2468.     Window_Selectable.prototype.initialize.call(this, x, y, width, height);
  2469.     this.refresh();
  2470.     this.setTopRow(Window_MinimapMenuLeft.lastTopRow);
  2471.     this.select(Window_MinimapMenuLeft.lastIndex);
  2472.     this.activate();
  2473. };
  2474.  
  2475. Window_MinimapMenuLeft.prototype.windowWidth = function()
  2476. {
  2477.     return Silv.Minimap.Menu.WindowWidth_Left;
  2478. };
  2479.  
  2480. Window_MinimapMenuLeft.prototype.windowHeight = function()
  2481. {
  2482.     return Graphics.boxHeight;
  2483. };
  2484.  
  2485. Window_MinimapMenuLeft.prototype.maxItems = function()
  2486. {
  2487.     return Silv.Minimap.Menu.Markers.length;
  2488. };
  2489.  
  2490. Window_MinimapMenuLeft.prototype.update = function()
  2491. {
  2492.     Window_Selectable.prototype.update.call(this);
  2493.     if (this._mapWindow) { this._mapWindow.setMarker(this.marker()); }
  2494.     if (this.index() != Window_MinimapMenuLeft.lastIndex)
  2495.     {
  2496.         Window_MinimapMenuLeft.lastIndex = this.index();
  2497.         this.callHandler('index_changed');
  2498.     }
  2499.    
  2500.     if (Input.isTriggered('ok'))
  2501.     {
  2502.         var marker = this.marker();
  2503.         if(marker.tp !== null)
  2504.         {
  2505.             // Add the teleport location to the minimap and dequeue this scene to return to the previous scene
  2506.             SoundManager.playOk();
  2507.             Silv.Minimap.TP_Dest = marker.tp;
  2508.             SceneManager.pop();
  2509.         }
  2510.     }
  2511.    
  2512.     if (Input.isTriggered(Silv.Minimap.Menu.MenuKey))
  2513.     {
  2514.         SoundManager.playCancel();
  2515.         SceneManager.pop();
  2516.     }
  2517. };
  2518.  
  2519. Window_MinimapMenuLeft.prototype.marker = function()
  2520. {
  2521.     return Silv.Minimap.Menu.Markers[this.index()];
  2522. };
  2523.  
  2524. Window_MinimapMenuLeft.prototype.refresh = function()
  2525. {
  2526.     this.createContents();
  2527.     this.drawAllItems();
  2528. };
  2529.  
  2530. Window_MinimapMenuLeft.prototype.drawItem = function(index)
  2531. {
  2532.     var rect = this.itemRectForText(index);
  2533.     var text = Silv.Minimap.Menu.Markers[index].text;
  2534.     this.drawText(text, rect.x, rect.y, rect.width);
  2535. };
  2536.  
  2537. Window_MinimapMenuLeft.prototype.isCancelTriggered = function()
  2538. {
  2539.     return (Window_Selectable.prototype.isCancelTriggered());
  2540. };
  2541.  
  2542. Window_MinimapMenuLeft.prototype.processCancel = function()
  2543. {
  2544.     Window_Selectable.prototype.processCancel.call(this);
  2545.     Window_MinimapMenuLeft.lastTopRow = this.topRow();
  2546.     Window_MinimapMenuLeft.lastIndex = this.index();
  2547. };
  2548.  
  2549. Window_MinimapMenuLeft.prototype.setMapWindow = function(mapWindow)
  2550. {
  2551.     this._mapWindow = mapWindow;
  2552.     this.update();
  2553. };
  2554. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2555. // Map Section Window
  2556. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2557. function Window_MapSection() { this.initialize.apply(this, arguments); }
  2558.  
  2559. Window_MapSection.prototype = Object.create(Window_Selectable.prototype);
  2560. Window_MapSection.prototype.constructor = Window_MapSection;
  2561.  
  2562. Window_MapSection.prototype.initialize = function(x, y, width)
  2563. {
  2564.     var height = Silv.Minimap.Menu.WindowHeight_MapSection;
  2565.     Window_Selectable.prototype.initialize.call(this, x, y, width, height);
  2566.     this._marker = 1;
  2567.     this.mapScroll = {x:0, y:0};
  2568.     this.mapZoom = 1.0;
  2569.     this.centerLoc = {x:width / 2.0, y: height / 2.0};
  2570.     this.refresh();
  2571. };
  2572.  
  2573. // Hide the cursor
  2574. Window_MapSection.prototype.updateCursor = function()
  2575. {
  2576.     this.setCursorRect(0, 0, 0, 0);
  2577. };
  2578.  
  2579. Window_MapSection.prototype.maxItems = function() { return 0; };
  2580.  
  2581. Window_MapSection.prototype.refresh = function()
  2582. {
  2583.     this.contents.clear();
  2584.     this.drawMap();
  2585. };
  2586.  
  2587. // Prevent anything from being drawn in the base-class
  2588. Window_MapSection.prototype.drawAllItems = function(){};
  2589.  
  2590. Window_MapSection.prototype.drawMap = function()
  2591. {
  2592.     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);
  2593. };
  2594.  
  2595. Window_MapSection.prototype.centerOnMarker = function(marker)
  2596. {
  2597.     this.mapScroll.x = this.centerLoc.x - marker.map_x - marker.w / 2.0;
  2598.     this.mapScroll.y = this.centerLoc.y - marker.map_y - marker.h / 2.0;
  2599.     this.refresh();
  2600. };
  2601.  
  2602. Window_MapSection.prototype.setMarker = function(marker)
  2603. {
  2604.     if (this._marker !== marker)
  2605.     {
  2606.         this._marker = marker;
  2607.         this.centerOnMarker(marker);
  2608.     }
  2609. };
  2610.  
  2611. Window_MapSection.prototype.update = function()
  2612. {
  2613.     Window_Selectable.prototype.update.call(this);
  2614.     if (this.active) {
  2615.         if (Input.isPressed('up')) { this.mapScroll.y += 10; this.refresh(); }
  2616.         if (Input.isPressed('right')) { this.mapScroll.x -= 10; this.refresh(); }
  2617.         if (Input.isPressed('down')) { this.mapScroll.y -= 10; this.refresh(); }
  2618.         if (Input.isPressed('left')) { this.mapScroll.x += 10; this.refresh(); }
  2619.         if (Input.isPressed(Silv.Minimap.Menu.ManualScrollKey_Reset)) { this.mapScroll.x = 0; this.mapScroll.y = 0; this.refresh(); }
  2620.        
  2621.         if (Input.isPressed(Silv.Minimap.Menu.ManualZoomKey_In))
  2622.         {
  2623.             this.mapZoom += 0.05;
  2624.             if (this.mapZoom > Silv.Minimap.Menu.ManualZoom_Max) { this.mapZoom = Silv.Minimap.Menu.ManualZoom_Max; }
  2625.             this.refresh();
  2626.         }
  2627.         if (Input.isPressed(Silv.Minimap.Menu.ManualZoomKey_Out))
  2628.         {
  2629.             this.mapZoom -= 0.05;
  2630.             if (this.mapZoom < Silv.Minimap.Menu.ManualZoom_Min) { this.mapZoom = Silv.Minimap.Menu.ManualZoom_Min; }
  2631.             this.refresh();
  2632.         }
  2633.         if  (Input.isPressed(Silv.Minimap.Menu.ManualZoomKey_Reset)) { this.mapZoom = 1.0; this.refresh(); }
  2634.     }
  2635. };
  2636. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2637. // This is the end of this awesome script! Why did you even read this line ;)
  2638. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement