FlatMMO+ Dim

FlatMMO+ Dim the screen

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         FlatMMO+ Dim
// @namespace    com.dounford.flatmmo.dim
// @version      1.0.2
// @description  FlatMMO+ Dim the screen
// @author       Dounford
// @license      MIT
// @match        *://flatmmo.com/play.php*
// @grant        none
// @require      https://update.greasyfork.org/scripts/544062/FlatMMOPlus.js
// ==/UserScript==
 
(function() {
    'use strict';
 
    class DimPlugin extends FlatMMOPlusPlugin {
        constructor() {
            super("dim", {
                about: {
                    name: GM_info.script.name,
                    version: GM_info.script.version,
                    author: GM_info.script.author,
                    description: GM_info.script.description
                },
                config: [
                    {
                        id: "whereToDim",
                        label: "Dim Location",
                        type: "select",
                        options: [
                            {value: "everywhere", label: "Everywhere"},
                            {value: "clouds", label: "Clouds"},
                            {value: "nowhere", label: "Nowhere"}
                        ],
                        default: "clouds"
                    },
                    {
						id: "dimIntensity",
						label: "Dim Intensity",
						type: "range",
						min: 0,
						max: 100,
						step: 1,
						default: 50,
					},
                ]
            });

            this.dim = 0;
        }

        onLogin() {
            
        }
        
        onConfigsChanged() {
            this.changedConfigs.forEach(config => {
				switch (config) {
					case "whereToDim": {
                        const where = this.config.whereToDim;
						if(where === "nowhere") {
                            this.dim = 0;
                        } else if (where === "everywhere" || (where === "clouds" && current_map === "m1000_999_sky")) {
                            this.changeIntensity()
                        }
					} break;
					case "dimIntensity": {
						this.changeIntensity();
					} break;
				}
			})
        }

        //Called when the player changes map
        onMapChanged(mapBefore, mapAfter) {
            if(this.config.whereToDim !== "clouds") {return};
            if(mapAfter === "m1000_999_sky") {
                this.changeIntensity();
            }
            if(mapBefore === "m1000_999_sky") {
                this.dim = 0;
            }
        }

        onPaint() {
            ctx.fillStyle = `rgba(0, 0, 0, ${this.dim})`;
            ctx.fillRect(0, 0, canvas.width, canvas.height);
        }

        changeIntensity() {
            this.dim = this.config.dimIntensity / 100;
        }
    }
    
    const plugin = new DimPlugin();
    FlatMMOPlus.registerPlugin(plugin);
 
})();