FlatMMO+ Dim

FlatMMO+ Dim the screen

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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);
 
})();