Adds retrieving, monitoring and storing of webclient settings
This commit is contained in:
parent
f2e53c873b
commit
221aa362ab
5 changed files with 99 additions and 4 deletions
|
|
@ -421,3 +421,58 @@ def unmonitor(session, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
kwargs["stop"] = True
|
kwargs["stop"] = True
|
||||||
monitor(session, *args, **kwargs)
|
monitor(session, *args, **kwargs)
|
||||||
|
|
||||||
|
def _on_webclient_setting_change(**kwargs):
|
||||||
|
"""
|
||||||
|
Called when the settings stored on the player changes.
|
||||||
|
Inform the interested clients of this change.
|
||||||
|
"""
|
||||||
|
session = kwargs["session"]
|
||||||
|
obj = kwargs["obj"]
|
||||||
|
fieldname = kwargs["fieldname"]
|
||||||
|
clientsettings = _GA(obj, fieldname)
|
||||||
|
|
||||||
|
session.msg(webclient_settings=clientsettings)
|
||||||
|
|
||||||
|
def webclient_settings(session, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Handles returning and monitoring stored settings relatede to the webclient.
|
||||||
|
|
||||||
|
Kwargs:
|
||||||
|
monitor (bool): If this is true, starts monitoring the settings for
|
||||||
|
changes too
|
||||||
|
"""
|
||||||
|
player = session.player
|
||||||
|
|
||||||
|
clientsettings = settings.WEBCLIENT_SETTINGS.copy()
|
||||||
|
storedsettings = player.db.webclient_settings or {}
|
||||||
|
clientsettings.update(storedsettings)
|
||||||
|
|
||||||
|
session.msg(webclient_settings=clientsettings)
|
||||||
|
|
||||||
|
if kwargs.get("monitor", False):
|
||||||
|
from evennia.scripts.monitorhandler import MONITOR_HANDLER
|
||||||
|
MONITOR_HANDLER.add(player, "webclient_settings",
|
||||||
|
_on_webclient_setting_change,
|
||||||
|
idstring=session.sessid, persistent=False,
|
||||||
|
session=session)
|
||||||
|
|
||||||
|
def set_webclient_settings(session, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Handles changing of a setting related to the webclient: the setting will
|
||||||
|
get saved to the player object.
|
||||||
|
|
||||||
|
Kwargs:
|
||||||
|
<setting>: A setting to save.
|
||||||
|
"""
|
||||||
|
|
||||||
|
player = session.player
|
||||||
|
|
||||||
|
clientsettings = settings.WEBCLIENT_SETTINGS.copy()
|
||||||
|
storedsettings = player.db.webclient_settings or {}
|
||||||
|
clientsettings.update(storedsettings)
|
||||||
|
|
||||||
|
for key, value in kwargs.iteritems():
|
||||||
|
clientsettings[key] = value
|
||||||
|
|
||||||
|
player.db.webclient_settings = clientsettings
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ from evennia.utils import logger
|
||||||
from evennia.utils.utils import make_iter, lazy_property
|
from evennia.utils.utils import make_iter, lazy_property
|
||||||
from evennia.commands.cmdsethandler import CmdSetHandler
|
from evennia.commands.cmdsethandler import CmdSetHandler
|
||||||
from evennia.server.session import Session
|
from evennia.server.session import Session
|
||||||
|
from evennia.scripts.monitorhandler import MONITOR_HANDLER
|
||||||
|
|
||||||
ClientSessionStore = importlib.import_module(settings.SESSION_ENGINE).SessionStore
|
ClientSessionStore = importlib.import_module(settings.SESSION_ENGINE).SessionStore
|
||||||
|
|
||||||
|
|
@ -258,6 +259,10 @@ class ServerSession(Session):
|
||||||
player.is_connected = False
|
player.is_connected = False
|
||||||
# this may be used to e.g. delete player after disconnection etc
|
# this may be used to e.g. delete player after disconnection etc
|
||||||
player.at_post_disconnect()
|
player.at_post_disconnect()
|
||||||
|
# remove any webclient settings monitors associated with this
|
||||||
|
# session
|
||||||
|
MONITOR_HANDLER.remove(player, "webclient_settings", self.sessid)
|
||||||
|
|
||||||
|
|
||||||
def get_player(self):
|
def get_player(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -623,6 +623,17 @@ STATICFILES_IGNORE_PATTERNS = ('README.md',)
|
||||||
# directory names shown in the templates directory.
|
# directory names shown in the templates directory.
|
||||||
WEBSITE_TEMPLATE = 'website'
|
WEBSITE_TEMPLATE = 'website'
|
||||||
WEBCLIENT_TEMPLATE = 'webclient'
|
WEBCLIENT_TEMPLATE = 'webclient'
|
||||||
|
# The default settings used by the webclient
|
||||||
|
WEBCLIENT_SETTINGS = {
|
||||||
|
"gagprompt": True, # Gags prompt from the output window and keep them
|
||||||
|
# together with the input bar
|
||||||
|
"helppopup": True, # Shows help files in a new popup window
|
||||||
|
"notification_popup": False, # Shows notifications of new messages as
|
||||||
|
# popup windows
|
||||||
|
"notification_sound": False # Plays a sound for notifications of new
|
||||||
|
# messages
|
||||||
|
}
|
||||||
|
|
||||||
# We setup the location of the website template as well as the admin site.
|
# We setup the location of the website template as well as the admin site.
|
||||||
TEMPLATES = [{
|
TEMPLATES = [{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
|
|
|
||||||
|
|
@ -239,6 +239,26 @@ function onPrompt(args, kwargs) {
|
||||||
|
|
||||||
// Called when the user logged in
|
// Called when the user logged in
|
||||||
function onLoggedIn() {
|
function onLoggedIn() {
|
||||||
|
Evennia.msg("webclient_settings", [], {"monitor": true});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when a setting changed
|
||||||
|
function onGotSetting(args, kwargs) {
|
||||||
|
$.each(kwargs, function(key, value) {
|
||||||
|
var elem = $("[data-setting='" + key + "']");
|
||||||
|
if (elem.length === 0) {
|
||||||
|
console.log("Could not find option: " + key);
|
||||||
|
} else {
|
||||||
|
elem.prop('checked', value);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when the user changed a setting from the interface
|
||||||
|
function onSettingCheckboxChanged() {
|
||||||
|
var name = $(this).data("setting");
|
||||||
|
var value = this.checked;
|
||||||
|
Evennia.msg("set_webclient_settings", [], {name: value});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Silences events we don't do anything with.
|
// Silences events we don't do anything with.
|
||||||
|
|
@ -378,6 +398,9 @@ $(document).ready(function() {
|
||||||
// Pressing the settings button
|
// Pressing the settings button
|
||||||
$("#optionsbutton").bind("click", doOpenSettings);
|
$("#optionsbutton").bind("click", doOpenSettings);
|
||||||
|
|
||||||
|
// Checking a checkbox in the settings dialog
|
||||||
|
$("[data-setting]").bind("change", onSettingCheckboxChanged);
|
||||||
|
|
||||||
// Pressing the close button on a dialog
|
// Pressing the close button on a dialog
|
||||||
$(".dialogclose").bind("click", doCloseDialog);
|
$(".dialogclose").bind("click", doCloseDialog);
|
||||||
|
|
||||||
|
|
@ -393,6 +416,7 @@ $(document).ready(function() {
|
||||||
Evennia.emitter.on("default", onDefault);
|
Evennia.emitter.on("default", onDefault);
|
||||||
Evennia.emitter.on("connection_close", onConnectionClose);
|
Evennia.emitter.on("connection_close", onConnectionClose);
|
||||||
Evennia.emitter.on("logged_in", onLoggedIn);
|
Evennia.emitter.on("logged_in", onLoggedIn);
|
||||||
|
Evennia.emitter.on("webclient_settings", onGotSetting);
|
||||||
// silence currently unused events
|
// silence currently unused events
|
||||||
Evennia.emitter.on("connection_open", onSilence);
|
Evennia.emitter.on("connection_open", onSilence);
|
||||||
Evennia.emitter.on("connection_error", onSilence);
|
Evennia.emitter.on("connection_error", onSilence);
|
||||||
|
|
|
||||||
|
|
@ -28,12 +28,12 @@
|
||||||
<div class="dialogtitle">Options<span class="dialogclose">×</span></div>
|
<div class="dialogtitle">Options<span class="dialogclose">×</span></div>
|
||||||
<div class="dialogcontent">
|
<div class="dialogcontent">
|
||||||
<h3>Output display</h3>
|
<h3>Output display</h3>
|
||||||
<label><input type="checkbox" name="checkbox" value="value">Gag prompts from output</label><br />
|
<label><input type="checkbox" data-setting="gagprompt" value="value">Gag prompts from output</label><br />
|
||||||
<label><input type="checkbox" name="checkbox" value="value">Help in popup window</label><br />
|
<label><input type="checkbox" data-setting="helppopup" value="value">Help in popup window</label><br />
|
||||||
<hr />
|
<hr />
|
||||||
<h3>Notifications</h3>
|
<h3>Notifications</h3>
|
||||||
<label><input type="checkbox" name="checkbox" value="value">Popup window</label><br />
|
<label><input type="checkbox" data-setting="notification_popup" value="value">Popup window</label><br />
|
||||||
<label><input type="checkbox" name="checkbox" value="value">Sound</label><br />
|
<label><input type="checkbox" data-setting="notification_sound" value="value">Sound</label><br />
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue