mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-17 14:59:16 +02:00
Added Player, Server, Terminal, and engine javascript files. Implemented basic terminal UI. Implemented main menu tabs (only added Character and Terminal for now
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
//Netburner Player class
|
||||
|
||||
netburner.Player = {
|
||||
var Player = {
|
||||
//Skills and stats
|
||||
hacking_skill: 1,
|
||||
strength: 1,
|
||||
@@ -40,8 +40,8 @@ netburner.Player = {
|
||||
lifetime_money: 0,
|
||||
|
||||
//Servers
|
||||
discoveredServers = [],
|
||||
purchasedServers = [],
|
||||
//discoveredServers = [],
|
||||
//purchasedServers = [],
|
||||
|
||||
//Achievements and achievement progress
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//Netburner Server class
|
||||
// Parent class for a Server object. PlayerServer and NPCServer inherit from this
|
||||
netburner.Server = {
|
||||
var Server = {
|
||||
//Connection information
|
||||
ip: "0.0.0.0",
|
||||
isOnline: false,
|
||||
@@ -11,7 +11,7 @@ netburner.Server = {
|
||||
max_ram: 1, //GB
|
||||
ram_used: 0,
|
||||
|
||||
scripts = [];
|
||||
//scripts = [],
|
||||
|
||||
//Manual hack state information
|
||||
is_hacking: false,
|
||||
|
||||
30
src/Terminal.js
Normal file
30
src/Terminal.js
Normal file
@@ -0,0 +1,30 @@
|
||||
//Terminal
|
||||
var post = function(input) {
|
||||
$("#terminal-input").before('<tr class="posted"><td style="color: #66ff33;">' + input + '</td></tr>');
|
||||
window.scrollTo(0, document.body.scrollHeight);
|
||||
}
|
||||
|
||||
//command is checked on enter key press
|
||||
$(document).keyup(function(event) {
|
||||
if (event.keyCode == 13) {
|
||||
var command = $('input[class=terminal-input]').val();
|
||||
if (command.length > 0) {
|
||||
post("> " + command);
|
||||
$('input[class=terminal-input]').val("");
|
||||
|
||||
//Execute command function here
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var executeCommand = function(command) {
|
||||
var commandArray = command.split();
|
||||
|
||||
if (commandArray.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (commandArray[0]) {
|
||||
case
|
||||
}
|
||||
}
|
||||
215
src/engine.js
Normal file
215
src/engine.js
Normal file
@@ -0,0 +1,215 @@
|
||||
|
||||
var Engine = {
|
||||
|
||||
//Clickable objects
|
||||
Clickables: {
|
||||
hackButton: null,
|
||||
|
||||
//Load, save, and delete
|
||||
saveButton: null,
|
||||
loadButton: null,
|
||||
deleteButton: null,
|
||||
|
||||
//Main menu buttons
|
||||
terminalMainMenuButton: null,
|
||||
characterMainMenuButton: null,
|
||||
},
|
||||
|
||||
//Display objects
|
||||
Display: {
|
||||
//Progress bar
|
||||
progress: null,
|
||||
|
||||
//Display for status text (such as "Saved" or "Loaded")
|
||||
statusText: null,
|
||||
|
||||
hacking_skill: null,
|
||||
|
||||
//Main menu content
|
||||
terminalContent: null,
|
||||
characterContent: null,
|
||||
|
||||
//Character info
|
||||
characterInfo: null,
|
||||
},
|
||||
|
||||
//Time variables (milliseconds unix epoch time)
|
||||
_timeThen: new Date().getTime(),
|
||||
_timeNow: new Date().getTime(),
|
||||
|
||||
_ticks: 0, //Total ticks
|
||||
_idleSpeed: 200, //Speed (in ms) at which the main loop is updated
|
||||
|
||||
//Display a status update text
|
||||
_lastStatus: null,
|
||||
displayStatusText: function(text) {
|
||||
Engine.Display.statusText.innerHTML = text;
|
||||
|
||||
clearTimeout(Engine._lastStatus);
|
||||
//Wipe status message after 3 seconds
|
||||
Engine._lastStatus = setTimeout(function() {
|
||||
Engine.Display.statusText.innerHTML = "";
|
||||
}, 3000);
|
||||
},
|
||||
|
||||
//Save function
|
||||
saveFile: function() {
|
||||
var tempSaveFile = JSON.stringify(Player);
|
||||
|
||||
window.localStorage.setItem("netburnerSave", tempSaveFile);
|
||||
|
||||
Engine.displayStatusText("Saved!");
|
||||
},
|
||||
|
||||
//Load saved game function
|
||||
loadSave: function() {
|
||||
//Check to see if file exists
|
||||
if (!window.localStorage.getItem("netburnerSave")) {
|
||||
Engine.displayStatusText("No save file present for load!");
|
||||
} else {
|
||||
var tempSaveFile = window.localStorage.getItem("netburnerSave");
|
||||
Player = JSON.parse(tempSaveFile);
|
||||
Engine.displayStatusText("Loaded successfully!");
|
||||
}
|
||||
},
|
||||
|
||||
//Delete saved game function
|
||||
deleteSave: function() {
|
||||
if (!window.localStorage.getItem("netburnerSave")) {
|
||||
Engine.displayStatusText("No save file present for deletion");
|
||||
} else {
|
||||
window.localStorage.removeItem("netburnerSave");
|
||||
Engine.displayStatusText("Deleted successfully!");
|
||||
}
|
||||
},
|
||||
|
||||
/* Load content when a main menu button is clicked */
|
||||
loadTerminalContent: function() {
|
||||
Engine.hideAllContent();
|
||||
Engine.Display.terminalContent.style.visibility = "visible";
|
||||
},
|
||||
|
||||
loadCharacterContent: function() {
|
||||
Engine.hideAllContent();
|
||||
Engine.Display.characterContent.style.visibility = "visible";
|
||||
Engine.displayCharacterInfo();
|
||||
},
|
||||
|
||||
//Helper function that hides all content
|
||||
hideAllContent: function() {
|
||||
Engine.Display.terminalContent.style.visibility = "hidden";
|
||||
Engine.Display.characterContent.style.visibility = "hidden";
|
||||
},
|
||||
|
||||
/* Display character info */
|
||||
displayCharacterInfo: function() {
|
||||
Engine.Display.characterInfo.innerHTML = 'Money: $' + Player.money + '<br><br>' +
|
||||
'Hacking Level: ' + Player.hacking_skill + '<br><br>' +
|
||||
'Strength: ' + Player.strength + '<br><br>' +
|
||||
'Defense: ' + Player.defense + '<br><br>' +
|
||||
'Dexterity: ' + Player.dexterity + '<br><br>' +
|
||||
'Agility: ' + Player.agility + '<br><br>';
|
||||
},
|
||||
|
||||
/* Main Event Loop */
|
||||
idleTimer: function() {
|
||||
//Get time difference
|
||||
Engine._timeNow = new Date().getTime();
|
||||
var timeDifference = Engine._timeNow - Engine._timeThen - Engine._ticks;
|
||||
|
||||
while (timeDifference >= Engine._idleSpeed) {
|
||||
//Engine.Display.hacking_skill.innerHTML = Player.hacking_skill;
|
||||
|
||||
//Update timeDifference based on the idle speed
|
||||
timeDifference -= Engine._idleSpeed;
|
||||
|
||||
//Update the total tick counter
|
||||
Engine._ticks += Engine._idleSpeed;
|
||||
}
|
||||
|
||||
var idleTime = Engine._idleSpeed - timeDifference;
|
||||
|
||||
|
||||
// Once that entire "while loop" has run, we call the IdleTimer
|
||||
// function again, but this time with a timeout (delay) of
|
||||
// _idleSpeed minus timeDifference
|
||||
setTimeout(Engine.idleTimer, idleTime);
|
||||
|
||||
},
|
||||
|
||||
/* Initialization */
|
||||
init: function() {
|
||||
//Hacking button
|
||||
//Engine.Clickables.hackButton = document.getElementById("hackbutton");
|
||||
|
||||
//Event Listener for hacking button
|
||||
//Engine.Clickables.hackButton.addEventListener("click", function() {
|
||||
// ++Player.hacking_skill;
|
||||
|
||||
//Returns false so that once the code runs, the button won't try to do
|
||||
//anything else
|
||||
// return false;
|
||||
//});
|
||||
|
||||
//Hacking Skill Display
|
||||
//Engine.Display.hacking_skill = document.getElementById("hackingskill");
|
||||
|
||||
//Status display
|
||||
//Engine.Display.statusText = document.getElementById("status");
|
||||
|
||||
//Load, save, and delete buttons
|
||||
//Engine.Clickables.saveButton = document.getElementById("save");
|
||||
//Engine.Clickables.saveButton.addEventListener("click", function() {
|
||||
// Engine.saveFile();
|
||||
// return false;
|
||||
//});
|
||||
|
||||
//Engine.Clickables.loadButton = document.getElementById("load");
|
||||
//Engine.Clickables.loadButton.addEventListener("click", function() {
|
||||
// Engine.loadSave();
|
||||
// return false;
|
||||
//});
|
||||
|
||||
//Engine.Clickables.deleteButton = document.getElementById("delete");
|
||||
//Engine.Clickables.deleteButton.addEventListener("click", function() {
|
||||
// Engine.deleteSave();
|
||||
// return false;
|
||||
//});
|
||||
|
||||
//Main menu buttons and content
|
||||
Engine.Clickables.terminalMainMenuButton = document.getElementById("terminal-menu-link");
|
||||
Engine.Clickables.terminalMainMenuButton.addEventListener("click", function() {
|
||||
Engine.loadTerminalContent();
|
||||
return false;
|
||||
});
|
||||
|
||||
Engine.Clickables.characterMainMenuButton = document.getElementById("character-menu-link");
|
||||
Engine.Clickables.characterMainMenuButton.addEventListener("click", function() {
|
||||
Engine.loadCharacterContent();
|
||||
return false;
|
||||
});
|
||||
|
||||
Engine.Display.terminalContent = document.getElementById("terminal-container");
|
||||
Engine.Display.characterContent = document.getElementById("character-container");
|
||||
Engine.Display.characterContent.style.visibility = "hidden";
|
||||
|
||||
//Character info
|
||||
Engine.Display.characterInfo = document.getElementById("character-info");
|
||||
Engine.displayCharacterInfo();
|
||||
|
||||
//Message at the top of terminal
|
||||
post("Netburner v1.0");
|
||||
|
||||
//Run main loop
|
||||
Engine.idleTimer();
|
||||
}
|
||||
};
|
||||
|
||||
window.onload = function() {
|
||||
Engine.init();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user