implement save and load settings
This commit is contained in:
@@ -5,4 +5,24 @@ window.GameSettings = class {
|
||||
this.sprinting = 'ControlLeft';
|
||||
}
|
||||
|
||||
load() {
|
||||
for (let prop in this) {
|
||||
let nameEQ = prop + "=";
|
||||
let ca = document.cookie.split(';');
|
||||
for (let i = 0; i < ca.length; i++) {
|
||||
let c = ca[i];
|
||||
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
|
||||
if (c.indexOf(nameEQ) === 0) {
|
||||
this[prop] = c.substring(nameEQ.length, c.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
save() {
|
||||
for (let prop in this) {
|
||||
document.cookie = prop + "=" + (this[prop] || "") + "; path=/";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,6 +13,7 @@ window.Minecraft = class {
|
||||
this.timer = new Timer(20);
|
||||
|
||||
this.settings = new GameSettings();
|
||||
this.settings.load();
|
||||
|
||||
// Create window and world renderer
|
||||
this.window = new GameWindow(this, canvasWrapperId);
|
||||
@@ -139,6 +140,11 @@ window.Minecraft = class {
|
||||
return;
|
||||
}
|
||||
|
||||
// Close previous screen
|
||||
if (!(this.currentScreen === null)) {
|
||||
this.currentScreen.onClose();
|
||||
}
|
||||
|
||||
// Switch screen
|
||||
this.currentScreen = screen;
|
||||
|
||||
|
||||
@@ -18,6 +18,10 @@ window.GuiScreen = class extends Gui {
|
||||
this.buttonList = [];
|
||||
}
|
||||
|
||||
onClose() {
|
||||
|
||||
}
|
||||
|
||||
drawScreen(stack, mouseX, mouseY, partialTicks) {
|
||||
for (let i in this.buttonList) {
|
||||
let button = this.buttonList[i];
|
||||
|
||||
@@ -37,4 +37,9 @@ window.GuiControls = class extends GuiScreen {
|
||||
super.drawScreen(stack, mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
onClose() {
|
||||
// Save settings
|
||||
this.minecraft.settings.save();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,8 +3,7 @@ window.Tessellator = class {
|
||||
constructor() {
|
||||
this.material = new THREE.MeshBasicMaterial({
|
||||
vertexColors: THREE.VertexColors,
|
||||
//side: THREE.BackSide,
|
||||
side: THREE.DoubleSide,
|
||||
side: THREE.BackSide,
|
||||
transparent: true,
|
||||
depthTest: true
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user