FlatMMO+ Dim

FlatMMO+ Dim the screen

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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