Advertisement
Guest User

SixLoves_Responsive.js 0.2.1

a guest
Jan 2nd, 2016
3,531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*jslint nomen:false*/
  2. /*global console*/
  3.  
  4. /*:
  5.  * @author David Wendt (fantranslation.org)
  6.  * @plugindesc Makes your game responsive. v0.2.1
  7.  *
  8.  * @param ArtScale
  9.  * @desc The intended scale of your art assets. (RPG Maker MV default: 1.5)
  10.  * @default 1.5
  11.  *
  12.  * @param MinWidth
  13.  * @desc The minimum width of the playfield, in virtual pixel units.
  14.  * @default 544
  15.  *
  16.  * @param MinHeight
  17.  * @desc The minimum height of the playfield, in virtual pixel units.
  18.  * @default 416
  19.  *
  20.  * @param MaxWidth
  21.  * @desc The maximum width of the playfield, in virtual pixel units.
  22.  * @default 816
  23.  *
  24.  * @param MaxHeight
  25.  * @desc The maximum height of the playfield, in virtual pixel units.
  26.  * @default 624
  27.  *
  28.  * @param DesignFPS
  29.  * @desc FPS that the game was originally designed for.
  30.  * @default 60
  31.  *
  32.  * @param UpdateFrameCap
  33.  * @desc Maximum number of updates to run per animation frame.
  34.  * @default 4
  35.  *
  36.  * @param EnableResolutionIndependence
  37.  * @desc Render the game at the resolution of your display & scale assets up.
  38.  * @default true
  39.  *
  40.  * @param DebugFPS
  41.  * @desc FPS that the game should run at, for debugging purposes.
  42.  * @default undefined
  43.  *
  44.  * @param DebugBreakOnNonadaptive
  45.  * @desc If "true", execution will halt on nonadaptive code.
  46.  * @default false
  47.  *
  48.  * @param DebugLogMessages
  49.  * @desc If "true", log classes containing legacy code needing to be updated.
  50.  * @default false
  51.  *
  52.  * @help
  53.  *
  54.  *      Adjusts various aspects of an RPG Maker MV game engine to improve
  55.  * flexibility in different ways. Adjusts viewport size, window sizing, and
  56.  * update frequency to ensure various the game adapts to various corner cases.
  57.  * For example, this plugin can adjust your game's playfield to fit the screen
  58.  * viewport it has, such that there are no letterboxing bars and the scale of
  59.  * rendered art assets corresponds to some physical quantity.
  60.  *
  61.  *  = Adaptive Viewport =
  62.  *
  63.  *      This plugin's main advantage is that you can design games with detailed
  64.  * art for high-density displays without forcing players on lower-density
  65.  * monitors to view excessively large sprites. Art is scaled up or down as
  66.  * needed such that the final result is at a visually appropriate size for any
  67.  * monitor.
  68.  *
  69.  *      You can also define a minimum size for your playfield. Viewports smaller
  70.  * than this will have their art assets shrunk further to ensure a minimum
  71.  * amount of virtual screen space is available to the user interface.
  72.  * Additionally, a maximum size can also be defined to prevent assets from
  73.  * becoming too small and the playfield too large. If these two parameters are
  74.  * in conflict, the maximum size will override the minimum size. (Such a
  75.  * situation may happen if the viewport is not tall enough for the minimum
  76.  * height, but wide enough to exceed maximum width.)
  77.  *
  78.  *      Maximum and minimum size defaults are set to the sizes of the default
  79.  * RPG Maker MV and VX Ace viewports, respectively. You may wish to adjust them
  80.  * based on your target platform. In that case, please keep in mind that the
  81.  * units for these parameters are specified in virtual units, so if you increase
  82.  * your ArtScale, the sizes specified here do not need to be increased. Or, if
  83.  * you reduce ArtScale (say if you liked MV's larger sprites), you don't need to
  84.  * change these either.
  85.  *
  86.  *      Please take caution when setting ArtScale as it increases or decreases
  87.  * the size of the whole game. Settings above 1.5 are highly discouraged unless
  88.  * you have already made the necessary code and design changes to increase the
  89.  * size of UI elements and text before using this plugin. Please do not make
  90.  * those changes, however, if you have not already, as we have a better approach
  91.  * involving true high-resolution support.
  92.  *
  93.  *      This plugin unlocks the high-resolution support built into PIXI.js, the
  94.  * 2D graphics library used by RPG Maker MV. What this means is that the actual
  95.  * viewport presented to the user will match the resolution of their device, and
  96.  * existing low-resolution assets will be scaled to the selected art asset size.
  97.  * The only practical effect of this, however, is that text will render at
  98.  * higher resolution when needed. An additional plugin is required to support
  99.  * high-resolution or vector art asset loading.
  100.  *
  101.  *      (Note that "high resolution" does not mean "larger physical size" as RPG
  102.  * Maker tends to assume.)
  103.  *
  104.  *      In the event that the high-resolution support is causing a bug in your
  105.  * game, you may disable it by setting EnableResolutionIndependence to false,
  106.  * which will refrain from increasing the WebGL/canvas resolution. Note that
  107.  * this setting is independent from the ArtScale setting which is used to
  108.  * calculate viewport resolution.
  109.  *
  110.  *      This plugin creates a new method for Scenes and Windows called layout.
  111.  * This method is called to force the target object to adjust it's contents to
  112.  * fit a different screen size. Default implementations for the base game's
  113.  * scenes and windows will be created. Additional scenes and windows in other
  114.  * plugins or your own code should have layout methods created for them if the
  115.  * defaults are unsuitable. The default implementations will use existing layout
  116.  * properties where available. Developers of custom Window or Scene classes
  117.  * should take a look at what this plugin does to ensure nothing breaks when it
  118.  * is enabled.
  119.  *
  120.  *  = Adaptive Framerate =
  121.  *
  122.  *      The plugin additionally supports adjusting the speed of game logic to
  123.  * be framerate independent. As RPG Maker MV was not designed for this at all,
  124.  * we accomplish this by firing multiple update calls to catch up with where
  125.  * the game should be. Effectively, frames are reinterpreted as a physical unit
  126.  * of time equal to the reciprocal of the DesignFPS rate, or 1/60 seconds.
  127.  *
  128.  *      This facility is limited by the UpdateFrameCap, which prevents the game
  129.  * from running ridiculous numbers of updates in situations where the game
  130.  * hasn't been running at all. (According to web standards, the browser is
  131.  * permitted to ramp down framerates or even cease updates for an arbitrary
  132.  * amount of time.) It sets an effective minimum FPS floor equal to the
  133.  * DesignFPS divided by the UpdateFrameCap.
  134.  *
  135.  *      Please note that this functionality does not allow us to update at a
  136.  * faster clip than 60 FPS, even if your monitor supports it. We cannot update
  137.  * half a frame's worth of time with the standard RPG Maker MV codebase.
  138.  * However, we can modify existing update functions to support adaptive update
  139.  * rates.
  140.  *
  141.  *      To do this, you must alter the relevant update functions to accept a
  142.  * numerical parameter indicating how many updates are intended to be processed
  143.  * at once. This parameter MUST be allowed to be provided as a fraction and
  144.  * your update function must scale all animations by that amount. Because we
  145.  * provide frame counts as a multiple of the design framerate, you do not need
  146.  * to adjust your existing design parameters to match - e.g. if you set a
  147.  * character to move 10 pixels across the viewport per frame, and you designed
  148.  * and tested this existing functionality at 60FPS, you merely need to multiply
  149.  * by the provided number to get the number of pixels that the character should
  150.  * move.
  151.  *
  152.  *      Alongside accepting a frame count as a parameter, your update function
  153.  * should also return the amount of frames actually consumed. This is used to
  154.  * allow update functions to control the actual flow of update calls over time.
  155.  *
  156.  *      Note that your code should not attempt to call other functions that
  157.  * advance the flow of time on it's own. Instead, this module exports a
  158.  * function called "force_frame_adaptive" which accepts the current frameCount,
  159.  * the desired update function, and the object it's to be called on. It will
  160.  * then call that function, either once for frame_adaptive code, or multiple
  161.  * times for legacy code, to ensure that the flow of time remains consistent.
  162.  *
  163.  *      You can find this function in SixLoves_Responsive; if not present, you
  164.  * should not provide your own code. If your plugin is intended to run in both
  165.  * environments - repsonsive and non-responsive - then you should, in the case
  166.  * where the plugin is missing, use a fallback function that merely calls the
  167.  * code without any special legacy handling. You should not attempt to
  168.  * duplicate the legacy code handling in this plugin as it is subject to change
  169.  * and fairly complex.
  170.  *
  171.  *      Legacy autodetect relies on properly marking frame-adaptive update
  172.  * functions by use of a special variable on the function object, like so:
  173.  *
  174.  *      MySceneClass.prototype.update.frame_adaptive = true
  175.  *
  176.  *      This necessitates writing frame-adaptive code in a flexible manner that
  177.  * supports being called from non-frame-adaptive code. Look at the source code
  178.  * of this plugin for an example of this style.
  179.  *
  180.  *      Please note that this property is only inherited in the case where the
  181.  * function is unchanged from parent to child class. Overriding the function,
  182.  * either by declaring a new one on the child class's prototype or replacing
  183.  * the existing one on the parent class's prototype, will erase this property.
  184.  * Update functions must individually opt-in to this scheme. If you override a
  185.  * frame_adaptive function, you must also redeclare your frame_adaptive-ness.
  186.  *
  187.  *      For testing your own code, you may want to change DebugFPS to something
  188.  * other than the default "undefined", which will lock the game to an arbitrary
  189.  * FPS of your choosing. This will cause it to explicitly run faster or slower.
  190.  * For example, on a 60fps monitor, a DebugFPS of 30 should run half as fast
  191.  * and a DebugFPS of 120 should run twice as fast.
  192.  *
  193.  *      In exceptionally rare cases the design FPS may have been altered from
  194.  * the stock 60FPS. For example, a developer who already adjusted their code to
  195.  * work on faster or slower monitors may need to use this plugin. In this case
  196.  * you may change the DesignFPS to speed up or slow down the game at all
  197.  * possible refresh rates. Please note that you should probably not do this.
  198.  */
  199.  
  200. this.SixLoves_Responsive = this.SixLoves_Responsive || {};
  201.  
  202. (function (root, module) {
  203.     "use strict";
  204.    
  205.     var parameters = root.PluginManager.parameters('SixLoves_Responsive'),
  206.         enableResolutionIndependence = parameters.EnableResolutionIndependence === "false" ? false : true,
  207.         artScale = Number(parameters.ArtScale || 1.5),
  208.         minWidth = Number(parameters.MinWidth || 544),
  209.         minHeight = Number(parameters.MinHeight || 416),
  210.         maxWidth = Number(parameters.MaxWidth || 816),
  211.         maxHeight = Number(parameters.MaxHeight || 624),
  212.        
  213.         designFPS = Number(parameters.DesignFPS || 60),
  214.  
  215.         /* Debug shit */
  216.         debugFPS = (parameters.DebugFPS !== undefined &&
  217.                     parameters.DebugFPS !== "undefined") ? Number(parameters.DebugFPS) : undefined,
  218.         debugBreakOnNonAdaptive = (parameters.DebugBreakOnNonadaptive === undefined ||
  219.                                    parameters.DebugBreakOnNonadaptive === "false") ? false : true,
  220.         debugLogMessages = (parameters.DebugLogMessages === undefined ||
  221.                             parameters.DebugLogMessages === "false") ? false : true,
  222.         updateFrameCap = Number(parameters.UpdateFrameCap || 3),
  223.  
  224.         nonAdaptive = [],
  225.         nonResponsive = [],
  226.  
  227.         /* Preceding implementations of patched code. */
  228.         _SceneManager_initGraphics = root.SceneManager.initGraphics,
  229.         _Graphics_centerElement = root.Graphics._centerElement,
  230.  
  231.         /* The additional zoom factor from ArtScale pixels to physical pixels.
  232.          * So, for example...
  233.          *
  234.          *     DPI scale            ArtScale            pixelScaleDiscrepancy
  235.          *     1x                   1x                  1x
  236.          *     1x                   1.5x                0.6666x
  237.          *     1.5x                 1.5x                1x
  238.          *     2x                   1.5x                1.3333x
  239.          */
  240.         pixelScaleDiscrepancy;
  241.    
  242.     if (debugFPS !== undefined) {
  243.         console.warn("Debugging framerate is on. You should turn this off if you are not testing update logic.");
  244.     }
  245.  
  246.     /* == FRAME-RATE ADAPTIVE GAME LOGIC == */
  247.  
  248.     /* Helper function that repeatedly executes an update callback to emulate
  249.      * adaptive behavior.
  250.      */
  251.     function force_frame_adaptive(frameCount, updateCallback, updateThis) {
  252.         var framesExecuted = 0,
  253.             constructorName;
  254.  
  255.         if (updateCallback.frame_adaptive === true) {
  256.             framesExecuted = updateCallback.apply(updateThis, [frameCount]);
  257.  
  258.             //For whatever reason, a particular bit of code may not actually
  259.             //contain any frame-scalable effects but we still want to avoid
  260.             //running it multiple times. This bit here lets us mark code as
  261.             //frame-adaptive without changing it if we want.
  262.             if (framesExecuted === undefined) {
  263.                 return frameCount;
  264.             }
  265.  
  266.             return framesExecuted;
  267.         } else {
  268.             if (debugBreakOnNonAdaptive) {
  269.                 debugger;
  270.             }
  271.  
  272.             if (nonAdaptive.indexOf(updateThis.constructor.name) === -1) {
  273.                 nonAdaptive.push(updateThis.constructor.name);
  274.             }
  275.         }
  276.  
  277.         frameCount = Math.ceil(frameCount);
  278.  
  279.         while (framesExecuted < frameCount) {
  280.             framesExecuted += 1;
  281.             updateCallback.apply(updateThis);
  282.         }
  283.  
  284.         return framesExecuted;
  285.     }
  286.  
  287.     /* Returns the number of physical pixels per ArtScale pixel.
  288.      *
  289.      * Exposed as SixLoves_Responsive.get_artscale_pixel_ratio
  290.      */
  291.     function get_artscale_pixel_ratio() {
  292.         return pixelScaleDiscrepancy;
  293.     }
  294.  
  295.     /* Code which adjusts the gameloop to run at the same physical speed
  296.      * regardless of the rate at which the browser fires animation frames.
  297.      */
  298.     root.SceneManager.update = function (timeStamp) {
  299.         var frameSkip,
  300.             actualFrameSkip = 0;
  301.  
  302.         //Clear the debugging list of nonadaptive functions.
  303.         nonAdaptive = [];
  304.  
  305.         //Ensure we have a timestamp to compare to.
  306.         //We can't run any adaptive code until we have a delta.
  307.         if (this.lastTimeStamp === undefined) {
  308.             this.lastTimeStamp = timeStamp;
  309.             return this.requestUpdate();
  310.         }
  311.  
  312.         //accumulatedExcessTime is used to keep track of time that hasn't
  313.         //been consumed by the underlying frame update functions.
  314.         if (this.accumulatedExcessTime === undefined) {
  315.             this.accumulatedExcessTime = 0;
  316.         }
  317.  
  318.         //This tells us how many updates need to run since the last run.
  319.         frameSkip = (timeStamp - this.lastTimeStamp) / 1000 * designFPS;
  320.  
  321.         //Also, add in any excess time not accounted for by the previous update
  322.         //and apply our update cap.
  323.         frameSkip = Math.min(frameSkip + this.accumulatedExcessTime,
  324.                              module.updateFrameCap);
  325.  
  326.         if (debugFPS !== undefined) {
  327.             frameSkip = designFPS / debugFPS;
  328.         }
  329.  
  330.         try {
  331.             this.tickStart();
  332.             this.updateInputData();
  333.  
  334.             actualFrameSkip = force_frame_adaptive(frameSkip, this.updateMain, this);
  335.  
  336.             this.tickEnd();
  337.         } catch (e) {
  338.             this.catchException(e);
  339.         }
  340.  
  341.         if (nonAdaptive.length > 0 && debugLogMessages) {
  342.             console.warn("Please update classes " + nonAdaptive.join(", ") + " to support frame adaptive code.");
  343.         }
  344.  
  345.         //Store any frame time that the update function didn't use.
  346.         this.accumulatedExcessTime = Math.max(frameSkip - actualFrameSkip, 0);
  347.         this.lastTimeStamp = timeStamp;
  348.     };
  349.  
  350.     root.SceneManager.update.frame_adaptive = true;
  351.  
  352.     /* Adjust updateMain to also support frame_adaptive behavior.
  353.      *
  354.      * Note that if this function is NOT frame_adaptive, it WILL cause the game
  355.      * to constantly spin and request more and more animation frames, making
  356.      * the game spin out of control and die very quickly.
  357.      */
  358.     root.SceneManager.updateMain = function (frameCount) {
  359.         if (frameCount === undefined) {
  360.             frameCount = 1;
  361.         }
  362.  
  363.         this.changeScene();
  364.         frameCount = force_frame_adaptive(frameCount, this.updateScene, this);
  365.         this.renderScene();
  366.         this.requestUpdate();
  367.  
  368.         return frameCount;
  369.     };
  370.  
  371.     root.SceneManager.updateMain.frame_adaptive = true;
  372.  
  373.     /* Adjust updateScene to support frame_adaptive scenes.
  374.      *
  375.      * This also changes the scene starting logic a bit: scene starting always
  376.      * takes one update call regardless of how many frames actually passed.
  377.      */
  378.     root.SceneManager.updateScene = function (frameCount) {
  379.         if (frameCount === undefined) {
  380.             frameCount = 1;
  381.         }
  382.  
  383.         if (this._scene) {
  384.             if (!this._sceneStarted && this._scene.isReady()) {
  385.                 this._scene.start();
  386.                 this._sceneStarted = true;
  387.                 this.onSceneStart();
  388.             }
  389.             if (this.isCurrentSceneStarted()) {
  390.                 frameCount = force_frame_adaptive(frameCount, this._scene.update, this._scene);
  391.             }
  392.         }
  393.  
  394.         return frameCount;
  395.     };
  396.  
  397.     root.SceneManager.updateScene.frame_adaptive = true;
  398.  
  399.     /* == RESPONSIVE VIEWPORT LOGIC == */
  400.  
  401.     /* Code which resizes the Graphics viewport to match the screen, and scale
  402.      * art assets down to their appropriate physical size.
  403.      * (e.g. it allows high-DPI assets to be high-DPI when needed)
  404.      */
  405.     function adapt_to_viewport() {
  406.         var finalScale = artScale,
  407.             displayScale = window.devicePixelRatio || 1,
  408.             cssWidth = window.innerWidth,
  409.             cssHeight = window.innerHeight;
  410.        
  411.         if (cssWidth < minWidth || cssHeight < minHeight) {
  412.             finalScale = artScale / Math.min(cssWidth / minWidth,
  413.                                              cssHeight / minHeight);
  414.         }
  415.        
  416.         if (cssWidth > maxWidth || cssHeight > maxHeight) {
  417.             finalScale = artScale / Math.max(cssWidth / maxWidth,
  418.                                              cssHeight / maxHeight);
  419.         }
  420.  
  421.         //Allow turning off full DPI support
  422.         if (enableResolutionIndependence) {
  423.             pixelScaleDiscrepancy = displayScale / finalScale;
  424.         } else {
  425.             pixelScaleDiscrepancy = 1;
  426.         }
  427.  
  428.         root.Graphics.width = Math.round(cssWidth * finalScale);
  429.         root.Graphics.height = Math.round(cssHeight * finalScale);
  430.         root.Graphics.boxWidth = Math.round(cssWidth * finalScale);
  431.         root.Graphics.boxHeight = Math.round(cssHeight * finalScale);
  432.         root.Graphics.scale = 1 / finalScale;
  433.  
  434.         nonResponsive = [];
  435.  
  436.         if (root.SceneManager._scene) {
  437.             if (root.SceneManager._scene.layout) {
  438.                 root.SceneManager._scene.layout();
  439.  
  440.                 if (nonResponsive.length > 0 && debugLogMessages) {
  441.                     console.warn("Classes " + nonResponsive.join(", ") + " do not have a .layout method; some portions of the current scene may not render properly until the next scene transition.");
  442.                 }
  443.             } else {
  444.                 if (debugLogMessages) {
  445.                     console.warn("The current scene " + root.SceneManager._scene.constructor.name + " does not have a .layout method; the game will not render properly until the next scene transition.");
  446.                 }
  447.             }
  448.         }
  449.     }
  450.    
  451.     /* Monkey-patch the Scene Manager to fill the screen.
  452.      */
  453.     root.SceneManager.initGraphics = function () {
  454.         _SceneManager_initGraphics.apply(this);
  455.        
  456.         adapt_to_viewport();
  457.     };
  458.    
  459.     window.addEventListener("resize", adapt_to_viewport);
  460.    
  461.     function layout_all(children) {
  462.         var i;
  463.        
  464.         for (i = 0; i < children.length; i += 1) {
  465.             if (children[i].layout) {
  466.                 children[i].layout();
  467.             } else {
  468.                 if (nonResponsive.indexOf(children[1].constructor.name) === -1) {
  469.                     nonResponsive.push(children[1].constructor.name);
  470.                 }
  471.             }
  472.         }
  473.     }
  474.    
  475.     /* Adjust Window_Base to allocate window contents with a properly sized bitmap.
  476.      *
  477.      * This is the last piece in resolution-independence; windows will be able
  478.      * to draw content correctly...
  479.      */
  480.     root.Window_Base.prototype.createContents = function() {
  481.         this.contents = new Bitmap(this.contentsWidth(), this.contentsHeight(), pixelScaleDiscrepancy);
  482.         this.resetFontSettings();
  483.     };
  484.  
  485.     /* ...after these patches to Bitmap which will reframe literally all window
  486.      * drawing operations in terms of virtual/CSS pixels instead of physical
  487.      * pixels.
  488.      */
  489.     root.Bitmap.prototype.initialize = (function (old_impl) {
  490.         return function (width, height, drawingScale) {
  491.             var childArgs = Array.prototype.concat.call(arguments);
  492.  
  493.             if (drawingScale === undefined) {
  494.                 drawingScale = 1;
  495.             } else {
  496.                 //debugger;
  497.             }
  498.  
  499.             childArgs[0] = Math.floor(width * drawingScale);
  500.             childArgs[1] = Math.floor(height * drawingScale);
  501.  
  502.             old_impl.apply(this, childArgs);
  503.  
  504.             this._context.scale(drawingScale, drawingScale);
  505.             this._baseTexture.resolution = drawingScale;
  506.         }
  507.     }(root.Bitmap.prototype.initialize));
  508.  
  509.     /* Oh, and we also have to catch anyone resizing bitmaps, too. */
  510.     root.Bitmap.prototype.resize = function (width, height, drawingScale) {
  511.         if (drawingScale === undefined) {
  512.             drawingScale = 1;
  513.         }
  514.  
  515.         width = Math.floor(Math.max(width || 0, 1) * drawingScale);
  516.         height = Math.floor(Math.max(height || 0, 1) * drawingScale);
  517.         this._canvas.width = width;
  518.         this._canvas.height = height;
  519.         this._baseTexture.width = width;
  520.         this._baseTexture.height = height;
  521.         this._baseTexture.resolution = drawingScale;
  522.     };
  523.  
  524.     /* There's what I -think- is a bug in PIXI where setFrame
  525.      * sets the texture crop without taking resolution into
  526.      * account, so let's update the crop ourselves.
  527.      *
  528.      * Unfortunately the 2.x versions of PIXI are no longer updated so this is
  529.      * just gonna be our little secret. Also, I'm fairly sure this is not what
  530.      * PIXI upstream would prefer we do but I stopped caring.
  531.      */
  532.     PIXI.Texture.prototype.setFrame = function(frame)
  533.     {
  534.         this.noFrame = false;
  535.  
  536.         this.frame = frame;
  537.         this.width = frame.width;
  538.         this.height = frame.height;
  539.  
  540.         this.crop.x = frame.x;
  541.         this.crop.y = frame.y;
  542.         this.crop.width = frame.width;
  543.         this.crop.height = frame.height;
  544.  
  545.         if (!this.trim && (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height))
  546.         {
  547.             throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this);
  548.         }
  549.  
  550.         //It's only -after- that check that we can do this:
  551.         this.frame.width *= this.baseTexture.resolution;
  552.         this.frame.height *= this.baseTexture.resolution;
  553.         this.crop.width *= this.baseTexture.resolution;
  554.         this.crop.height *= this.baseTexture.resolution;
  555.  
  556.         this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded;
  557.  
  558.         if (this.trim)
  559.         {
  560.             this.width = this.trim.width;
  561.             this.height = this.trim.height;
  562.             this.frame.width = this.trim.width;
  563.             this.frame.height = this.trim.height;
  564.         }
  565.  
  566.         if (this.valid) this._updateUvs();
  567.  
  568.     };
  569.  
  570.     /* Finally, we have to configure our rendering canvas to be the physical
  571.      * resolution of the viewport, and not artscale units
  572.      *
  573.      * Also because high-DPI never really crossed canvas's mind we have to add
  574.      * some CSS to force the browser to shrink the canvas back down (or up, if
  575.      * ArtScale is larger than the actual pixel ratio)
  576.      */
  577.     root.Graphics._updateCanvas = function() {
  578.         var psd = pixelScaleDiscrepancy ? pixelScaleDiscrepancy : 1;
  579.  
  580.         this._canvas.width = this._width * psd;
  581.         this._canvas.height = this._height * psd;
  582.         this._canvas.style.zIndex = 1;
  583.         this._canvas.style.maxWidth = "100%";
  584.         this._canvas.style.maxHeight = "100%";
  585.         this._canvas.style.minWidth = "100%";
  586.         this._canvas.style.minHeight = "100%";
  587.  
  588.         //this._centerElement(this._canvas);
  589.         //Our lies are incompatible with this API
  590.  
  591.         this._canvas.style.position = 'absolute';
  592.         this._canvas.style.margin = 'auto';
  593.         this._canvas.style.top = 0;
  594.         this._canvas.style.left = 0;
  595.         this._canvas.style.right = 0;
  596.         this._canvas.style.bottom = 0;
  597.     };
  598.  
  599.     /* Tell the PIXI renderer about the pixel scale discrepancy so that it uses
  600.      * the extra resolution we've given/taken to/from it
  601.      */
  602.     root.Graphics._updateRenderer = function() {
  603.         var psd = pixelScaleDiscrepancy ? pixelScaleDiscrepancy : 1;
  604.  
  605.         if (this._renderer) {
  606.             this._renderer.resolution = psd;
  607.             this._renderer.renderSession.resolution = psd;
  608.             this._renderer.resize(this._width, this._height);
  609.         }
  610.     };
  611.  
  612.     module.layout_all = layout_all;
  613.     module.force_frame_adaptive = force_frame_adaptive;
  614.     module.get_artscale_pixel_ratio = get_artscale_pixel_ratio;
  615.    
  616.     module.updateFrameCap = updateFrameCap;
  617.    
  618.     module.status = "loaded";
  619.     module.version = "0.2.1";
  620. }(this, this.SixLoves_Responsive));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement