implement session saving, fix some bugs, version 1.1.8
This commit is contained in:
@@ -8,6 +8,8 @@ export default class GameSettings {
|
||||
this.keyOpenInventory = 'KeyE';
|
||||
this.keyPlayerList = 'Tab';
|
||||
|
||||
this.session = null;
|
||||
|
||||
this.thirdPersonView = 0;
|
||||
this.fov = 70;
|
||||
this.viewBobbing = true;
|
||||
@@ -30,6 +32,15 @@ export default class GameSettings {
|
||||
if (value.match(/^[0-9]+$/)) {
|
||||
value = parseInt(value);
|
||||
}
|
||||
if (value === 'true') {
|
||||
value = true;
|
||||
}
|
||||
if (value === 'false') {
|
||||
value = false;
|
||||
}
|
||||
if (value === 'null') {
|
||||
value = null;
|
||||
}
|
||||
this[prop] = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import PlayerControllerMultiplayer from "./network/controller/PlayerControllerMu
|
||||
|
||||
export default class Minecraft {
|
||||
|
||||
static VERSION = "1.1.7"
|
||||
static VERSION = "1.1.8"
|
||||
static URL_GITHUB = "https://github.com/labystudio/js-minecraft";
|
||||
static PROTOCOL_VERSION = 47; //758;
|
||||
|
||||
@@ -50,16 +50,21 @@ export default class Minecraft {
|
||||
this.fps = 0;
|
||||
this.maxFps = 0;
|
||||
|
||||
let username = "Player" + Math.floor(Math.random() * 100);
|
||||
let profile = new GameProfile(UUID.randomUUID(), username);
|
||||
this.session = new Session(profile, "");
|
||||
|
||||
// Tick timer
|
||||
this.timer = new Timer(20);
|
||||
|
||||
this.settings = new GameSettings();
|
||||
this.settings.load();
|
||||
|
||||
// Load session from settings
|
||||
if (this.settings.session === null) {
|
||||
let username = "Player" + Math.floor(Math.random() * 100);
|
||||
let profile = new GameProfile(UUID.randomUUID(), username);
|
||||
this.setSession(new Session(profile, ""));
|
||||
} else {
|
||||
this.setSession(Session.fromJson(this.settings.session));
|
||||
}
|
||||
|
||||
// Create window and world renderer
|
||||
this.window = new GameWindow(this, canvasWrapperId);
|
||||
|
||||
@@ -119,6 +124,10 @@ export default class Minecraft {
|
||||
if (networkHandler.getNetworkManager().isConnected()) {
|
||||
networkHandler.getNetworkManager().close();
|
||||
}
|
||||
|
||||
// Reset header and footer
|
||||
this.ingameOverlay.playerListOverlay.setHeader(null);
|
||||
this.ingameOverlay.playerListOverlay.setFooter(null);
|
||||
}
|
||||
this.playerController = null;
|
||||
|
||||
@@ -469,8 +478,19 @@ export default class Minecraft {
|
||||
return !this.hasInGameFocus() && this.loadingScreen === null && this.isSingleplayer();
|
||||
}
|
||||
|
||||
setSession(session) {
|
||||
setSession(session, save = false) {
|
||||
this.session = session;
|
||||
|
||||
// Save session
|
||||
if (save) {
|
||||
this.settings.session = session.toJson();
|
||||
this.settings.save();
|
||||
}
|
||||
}
|
||||
|
||||
updateAccessToken(token) {
|
||||
this.session.setAccessToken(token);
|
||||
this.setSession(this.session, true);
|
||||
}
|
||||
|
||||
getSession() {
|
||||
|
||||
@@ -86,7 +86,9 @@ export default class PlayerEntity extends EntityLiving {
|
||||
let prevMoveForward = this.moveForward;
|
||||
let prevJumping = this.jumping;
|
||||
|
||||
this.updateKeyboardInput();
|
||||
if (this === this.minecraft.player) {
|
||||
this.updateKeyboardInput();
|
||||
}
|
||||
|
||||
// Toggle jumping
|
||||
if (!prevJumping && this.jumping) {
|
||||
|
||||
@@ -125,11 +125,9 @@ export default class PlayerListOverlay extends Gui {
|
||||
let indexX = Math.floor(i / rows);
|
||||
let indexY = i % rows;
|
||||
|
||||
let entryX = x + indexX * columnWidth + indexX * 5 - 1;
|
||||
let entryX = x + indexX * columnWidth + indexX * 5;
|
||||
let entryY = y + indexY * FontRenderer.FONT_HEIGHT;
|
||||
|
||||
let rightX = entryX + columnWidth - 1;
|
||||
|
||||
// Check if index is inside of range
|
||||
if (i < playerInfoMap.size) {
|
||||
let pingX = entryX + columnWidth - 1;
|
||||
@@ -140,7 +138,7 @@ export default class PlayerListOverlay extends Gui {
|
||||
stack,
|
||||
entryX,
|
||||
entryY,
|
||||
entryX + columnWidth,
|
||||
entryX + columnWidth - 1,
|
||||
entryY + (FontRenderer.FONT_HEIGHT - 1),
|
||||
'rgba(255,255,255,0.13)'
|
||||
);
|
||||
|
||||
@@ -22,10 +22,10 @@ export default class PlayerRenderer extends EntityRenderer {
|
||||
}
|
||||
|
||||
rebuild(entity) {
|
||||
let firstPerson = this.worldRenderer.minecraft.settings.thirdPersonView === 0;
|
||||
let itemId = firstPerson ? this.worldRenderer.itemToRender : entity.inventory.getItemInSelectedSlot();
|
||||
let hasItem = itemId !== 0;
|
||||
let isSelf = entity === this.worldRenderer.minecraft.player;
|
||||
let firstPerson = this.worldRenderer.minecraft.settings.thirdPersonView === 0;
|
||||
let itemId = firstPerson && isSelf ? this.worldRenderer.itemToRender : entity.inventory.getItemInSelectedSlot();
|
||||
let hasItem = itemId !== 0;
|
||||
|
||||
if (firstPerson && hasItem && isSelf) {
|
||||
super.rebuild(entity);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import GameProfile from "./GameProfile.js";
|
||||
|
||||
export default class Session {
|
||||
|
||||
constructor(profile, accessToken) {
|
||||
@@ -5,6 +7,10 @@ export default class Session {
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
|
||||
setAccessToken(accessToken) {
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
|
||||
getProfile() {
|
||||
return this.profile;
|
||||
}
|
||||
@@ -13,4 +19,19 @@ export default class Session {
|
||||
return this.accessToken;
|
||||
}
|
||||
|
||||
toJson() {
|
||||
return JSON.stringify({
|
||||
profile: {
|
||||
uuid: this.profile.uuid.toString(),
|
||||
username: this.profile.username
|
||||
},
|
||||
accessToken: this.accessToken
|
||||
});
|
||||
}
|
||||
|
||||
static fromJson(json) {
|
||||
let data = JSON.parse(json);
|
||||
return new Session(new GameProfile(data.profile.uuid, data.profile.username), data.accessToken);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user