I scripted several modules that store cookie-like values in localstorage, or even send a player’s in-game data to third-party database. It definitely means that my web game needs to show a cookie policy and ask a permission for collecting a user’s preference and data before utilizing the resources. Is there any project that I can find as references for the cookie permission UX? Or any other suggestions or feedbacks?
Here are some example scripts related to localstorage and data-sending:
// initialize code called once per entity
BooleanButton.prototype.initialize = function() {
this.boolean = true;
this.element = this.entity.element;
this.entity.button.on("click", this.toggle, this);
this.entity.on("set:default", this.setDefault, this);
// The property this.value will be equally used in any element in settings
// that may differ based on the type of a button.
// In this case, a boolean button will return this.boolean when a user requests its value.
this.__defineGetter__('value', function() { return this.boolean; });
};
BooleanButton.prototype.postInitialize = function() {
this.entity.fire("requestDefault");
};
BooleanButton.prototype.setDefault = function(value) {
const parseBoolean = (str) => str === 'true';
this.boolean = parseBoolean(value);
this.setBoolean(this.boolean);
};
BooleanButton.prototype.toggle = function() {
this.boolean = !this.boolean;
this.setBoolean(this.boolean);
};
BooleanButton.prototype.setBoolean = function(_boolean) {
if (this.element.type === "image")
switch (_boolean) {
case false: this.element.spriteFrame = 0; break;
case true: this.element.spriteFrame = 1; break;
}
this.entity.fire("set:value", this.value);
};
const Settings = pc.createScript('settings');
Settings.attributes.add('options', {
type: 'json',
array: true,
schema: [{
name: 'name',
title: 'Name',
type: 'string',
}, {
name: 'val',
title: 'Default Value',
type: 'string',
}, {
name: 'entity',
title: 'UI Entity',
type: 'entity',
}]
});
// initialize code called once per entity
Settings.prototype.initialize = function() {
this.options.forEach((option) => {
let storedVal = localStorage.getItem(option.name);
option.entity.on("set:value", (_value) => localStorage.setItem(option.name, _value), this);
option.entity.on("requestDefault", () => option.entity.fire("set:default", (storedVal? storedVal: option.val)), this);
if (!storedVal) localStorage.setItem(option.name, option.val);
});
};
// initialize code called once per entity
Network.prototype.initialize = function() {
this.app.network = this;
const parseBoolean = (str) => str === 'true';
let enableDataTranmission = parseBoolean(localStorage.getItem("enableDataTranmission"));
if (enableDataTranmission) {
this.socket = io(/* Security Issue */);
this.on("socket:emit", (str, ...args) => {
args = args.filter(arg => arg);
if (this.socket && this.socket.connected && typeof str == "string")
this.socket.emit(str, args);
}, this);
this.socket.on("connect", () => {
console.log(this.socket);
});
this.socket.on("disconnect", (reason) => {
console.log(reason);
});
}
};