KayelGee / control-concealer

MIT License
1 stars 1 forks source link

GM Settings: Hide Editing for Players #3

Open apoapostolov opened 4 years ago

apoapostolov commented 4 years ago

Please add a DM-only Settings with an option to hide button that allow players to change their controls personally. This is needed for newbie players who mess with controls or do not understand Development and Production levels, for OCD people who don't like to see additional controls, and for games where the DM wants to edit one setup and then propagate it to all players.

KayelGee commented 4 years ago

So if I understand you correctly you want the GM to setup production and development and copy his settings to the players while disallowing the players to change the settings afterwards. Correct?

dirkson commented 3 years ago

I'd also like to see this. One thing I'd like to add is that it might be more ideal to have a third "player" tab, since the controls a GM needs while playing may be different than the ones the players need.

GizmoNomical commented 2 years ago

This is a simple fix I added to limit the module's functionality to only GM users. I didn't want players fiddling with things, but I liked what the module added and how it cleaned up my screen for development.

Simply wrap the contents of the async add_controls() function with a simple if statement.

if(game.user.isGM)
{
function's code
}

This will stop the buttons from being loaded for players, while allowing GM's to see them and use the module still.

Of course this is not a pretty fix, and could probably be done better, and prior to even initializing the module, but it works.

Enjoy!

async add_controls(html){
        if (game.user.isGM) {
            const myVar = 'Example value to be passed to handlebars';
            const path = '/modules/control-concealer/templates';
            // Get the handlebars output
            const myHtml = await renderTemplate(`${path}/controlConcealerUI.html`, {myVar});
            const main_controls = html.find(".main-controls");
            main_controls.prepend(myHtml);          
            let config_button=html.find("#control-concealer .control-concealer-config");
            let dev_button=html.find("#control-concealer .control-concealer-dev");
            let prod_button=html.find("#control-concealer .control-concealer-prod");
            config_button.click(()=>{this.changeEditMode()});
            dev_button.click(()=>{ 
                if(this.edit) return ui.notifications.error(game.i18n.localize("CONTROLCONCEALER.error.EditActive"));
                this.view = "dev";
                $(document).find(".scene-control.active").click();
                this.updateButtons();
            });
            prod_button.click(()=>{
                if(config_button.hasClass('active')) return ui.notifications.error(game.i18n.localize("CONTROLCONCEALER.error.EditActive"));
                this.view = "prod";
                $(document).find(".scene-control.active").click();
                this.updateButtons();
            });
            this.updateButtons();
            }
        }
KayelGee commented 2 years ago

Disabling the edit buttons for players could be added as a setting for the module. @GizmoNomical just a tip if you reverse your logic you can do the following, which is usually easier to read because you're reducing unnecessary nesting:

async add_controls(html){
   if (!game.user.isGM) return;
GizmoNomical commented 2 years ago

Ahh yes!, that's what I get for trying to hack/debug/alter someone's code at nearly 3am. LoL ;-)

That is much simpler logic to follow, for sure. I just wanted to offer up a quick solution to this suggestion, as it was something I really needed to be able to use the module. Lack of sleep will make the simplest things complicated it seems. haha

I'm sure this little logic switch could be placed much further up in the code as well, but I didn't spend much time tracing the execution path, just found the button creation and bypassed it. Luckily the rest of your code is written to function fine as long as the buttons aren't manipulated.

Thanks again for the great module! It makes a huge difference when you are running nearly 100 mods.