mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-20 21:25:47 +01:00
Attached Stock market Watchlist
This commit is contained in:
parent
c5841b65fe
commit
815762bddd
@ -564,6 +564,11 @@
|
|||||||
margin: 10px;
|
margin: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#stock-market-watchlist-filter {
|
||||||
|
width:50%;
|
||||||
|
margin-left:10px;
|
||||||
|
}
|
||||||
|
|
||||||
.stock-market-input {
|
.stock-market-input {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
padding: 4px;
|
padding: 4px;
|
||||||
|
@ -695,6 +695,9 @@
|
|||||||
<a id="stock-market-mode" class="a-link-button tooltip"></a>
|
<a id="stock-market-mode" class="a-link-button tooltip"></a>
|
||||||
<a id="stock-market-expand-tickers" class="a-link-button tooltip">Expand tickers</a>
|
<a id="stock-market-expand-tickers" class="a-link-button tooltip">Expand tickers</a>
|
||||||
<a id="stock-market-collapse-tickers" class="a-link-button tooltip">Collapse tickers</a>
|
<a id="stock-market-collapse-tickers" class="a-link-button tooltip">Collapse tickers</a>
|
||||||
|
<br><br>
|
||||||
|
<input id="stock-market-watchlist-filter" type="text" placeholder="Filter Stocks by symbol (comma-separated list)"> </input>
|
||||||
|
<a id="stock-market-watchlist-filter-update" class="a-link-button"> Update Watchlist </a>
|
||||||
<ul id="stock-market-list" style="list-style:none;">
|
<ul id="stock-market-list" style="list-style:none;">
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@ -933,7 +936,7 @@
|
|||||||
</label>
|
</label>
|
||||||
<input type="checkbox" name="settingsSuppressBuyAugmentationConfirmation" id="settingsSuppressBuyAugmentationConfirmation">
|
<input type="checkbox" name="settingsSuppressBuyAugmentationConfirmation" id="settingsSuppressBuyAugmentationConfirmation">
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<!-- Hospitalization Popup -->
|
<!-- Hospitalization Popup -->
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<label for="settingsSuppressHospitalizationPopup" class="tooltip">Suppress Hospitalization popup:
|
<label for="settingsSuppressHospitalizationPopup" class="tooltip">Suppress Hospitalization popup:
|
||||||
|
@ -173,6 +173,8 @@ function PlayerObject() {
|
|||||||
//Stock Market
|
//Stock Market
|
||||||
this.hasWseAccount = false;
|
this.hasWseAccount = false;
|
||||||
this.hasTixApiAccess = false;
|
this.hasTixApiAccess = false;
|
||||||
|
this.has4SData = false;
|
||||||
|
this.has4SDataTixApi = false;
|
||||||
|
|
||||||
//Gang
|
//Gang
|
||||||
this.gang = 0;
|
this.gang = 0;
|
||||||
@ -1700,7 +1702,7 @@ PlayerObject.prototype.hospitalize = function() {
|
|||||||
numeral(this.max_hp * CONSTANTS.HospitalCostPerHp).format('$0.000a')
|
numeral(this.max_hp * CONSTANTS.HospitalCostPerHp).format('$0.000a')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loseMoney(this.max_hp * CONSTANTS.HospitalCostPerHp);
|
this.loseMoney(this.max_hp * CONSTANTS.HospitalCostPerHp);
|
||||||
this.hp = this.max_hp;
|
this.hp = this.max_hp;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,10 @@ import {Reviver, Generic_toJSON,
|
|||||||
Generic_fromJSON} from "../utils/JSONReviver";
|
Generic_fromJSON} from "../utils/JSONReviver";
|
||||||
import {Page, routing} from "./ui/navigationTracking";
|
import {Page, routing} from "./ui/navigationTracking";
|
||||||
import numeral from "numeral/min/numeral.min";
|
import numeral from "numeral/min/numeral.min";
|
||||||
|
import {exceptionAlert} from "../utils/helpers/exceptionAlert";
|
||||||
import {getRandomInt} from "../utils/helpers/getRandomInt";
|
import {getRandomInt} from "../utils/helpers/getRandomInt";
|
||||||
|
import {KEY} from "../utils/helpers/keyCodes";
|
||||||
|
import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement";
|
||||||
import {removeElementById} from "../utils/uiHelpers/removeElementById";
|
import {removeElementById} from "../utils/uiHelpers/removeElementById";
|
||||||
import {yesNoBoxCreate, yesNoTxtInpBoxCreate,
|
import {yesNoBoxCreate, yesNoTxtInpBoxCreate,
|
||||||
yesNoBoxGetYesButton, yesNoBoxGetNoButton,
|
yesNoBoxGetYesButton, yesNoBoxGetNoButton,
|
||||||
@ -409,6 +412,7 @@ function stockMarketCycle() {
|
|||||||
for (var name in StockMarket) {
|
for (var name in StockMarket) {
|
||||||
if (StockMarket.hasOwnProperty(name)) {
|
if (StockMarket.hasOwnProperty(name)) {
|
||||||
var stock = StockMarket[name];
|
var stock = StockMarket[name];
|
||||||
|
if (!(stock instanceof Stock)) {continue;}
|
||||||
var thresh = 0.6;
|
var thresh = 0.6;
|
||||||
if (stock.b) {thresh = 0.4;}
|
if (stock.b) {thresh = 0.4;}
|
||||||
if (Math.random() < thresh) {
|
if (Math.random() < thresh) {
|
||||||
@ -834,14 +838,32 @@ function displayStockMarketContent() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var name in StockMarket) {
|
//Watchlish filter
|
||||||
if (StockMarket.hasOwnProperty(name)) {
|
var watchlistFilter = clearEventListeners("stock-market-watchlist-filter");
|
||||||
var stock = StockMarket[name];
|
var watchlistUpdateBtn = clearEventListeners("stock-market-watchlist-filter-update");
|
||||||
if (!(stock instanceof Stock)) {continue;} //orders property is an array
|
if (watchlistFilter && watchlistUpdateBtn) {
|
||||||
createStockTicker(stock);
|
//Initialize value in watchlist
|
||||||
|
if (StockMarket.watchlistFilter) {
|
||||||
|
watchlistFilter.value = StockMarket.watchlistFilter; //Remove whitespace
|
||||||
}
|
}
|
||||||
|
watchlistUpdateBtn.addEventListener("click", ()=> {
|
||||||
|
let filterValue = watchlistFilter.value.toString();
|
||||||
|
StockMarket.watchlistFilter = filterValue.replace(/\s/g, '');
|
||||||
|
if (stockMarketPortfolioMode) {
|
||||||
|
switchToPortfolioMode();
|
||||||
|
} else {
|
||||||
|
switchToDisplayAllMode();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
watchlistFilter.addEventListener("keyup", (e)=>{
|
||||||
|
e.preventDefault();
|
||||||
|
if (e.keyCode === KEY.ENTER) {watchlistUpdateBtn.click();}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
console.warn("Stock Market Watchlist DOM elements could not be found");
|
||||||
}
|
}
|
||||||
setStockTickerClickHandlers(); //Clicking headers opens/closes panels
|
|
||||||
|
createAllStockTickers();
|
||||||
stockMarketContentCreated = true;
|
stockMarketContentCreated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -849,8 +871,10 @@ function displayStockMarketContent() {
|
|||||||
for (var name in StockMarket) {
|
for (var name in StockMarket) {
|
||||||
if (StockMarket.hasOwnProperty(name)) {
|
if (StockMarket.hasOwnProperty(name)) {
|
||||||
var stock = StockMarket[name];
|
var stock = StockMarket[name];
|
||||||
updateStockTicker(stock, null);
|
if (stock instanceof Stock) {
|
||||||
updateStockOrderList(stock);
|
updateStockTicker(stock, null);
|
||||||
|
updateStockOrderList(stock);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -859,17 +883,34 @@ function displayStockMarketContent() {
|
|||||||
//Displays only stocks you have position/order in
|
//Displays only stocks you have position/order in
|
||||||
function switchToPortfolioMode() {
|
function switchToPortfolioMode() {
|
||||||
stockMarketPortfolioMode = true;
|
stockMarketPortfolioMode = true;
|
||||||
var stockList = document.getElementById("stock-market-list");
|
|
||||||
if (stockList == null) {return;}
|
|
||||||
var modeBtn = clearEventListeners("stock-market-mode");
|
var modeBtn = clearEventListeners("stock-market-mode");
|
||||||
if (modeBtn) {
|
if (modeBtn) {
|
||||||
modeBtn.innerHTML = "Switch to 'All stocks' Mode" +
|
modeBtn.innerHTML = "Switch to 'All stocks' Mode" +
|
||||||
"<span class='tooltiptext'>Displays all stocks on the WSE</span>";
|
"<span class='tooltiptext'>Displays all stocks on the WSE</span>";
|
||||||
modeBtn.addEventListener("click", switchToDisplayAllMode);
|
modeBtn.addEventListener("click", switchToDisplayAllMode);
|
||||||
}
|
}
|
||||||
while(stockList.firstChild) {stockList.removeChild(stockList.firstChild);}
|
createAllStockTickers();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Displays all stocks
|
||||||
|
function switchToDisplayAllMode() {
|
||||||
|
stockMarketPortfolioMode = false;
|
||||||
|
var modeBtn = clearEventListeners("stock-market-mode");
|
||||||
|
if (modeBtn) {
|
||||||
|
modeBtn.innerHTML = "Switch to 'Portfolio' Mode" +
|
||||||
|
"<span class='tooltiptext'>Displays only the stocks for which you have shares or orders</span>";
|
||||||
|
modeBtn.addEventListener("click", switchToPortfolioMode);
|
||||||
|
}
|
||||||
|
createAllStockTickers();
|
||||||
|
}
|
||||||
|
|
||||||
|
function createAllStockTickers() {
|
||||||
|
var stockList = document.getElementById("stock-market-list");
|
||||||
|
if (stockList == null) {
|
||||||
|
exceptionAlert("Error creating Stock Tickers UI. DOM element with ID 'stock-market-list' could not be found");
|
||||||
|
}
|
||||||
|
removeChildrenFromElement(stockList);
|
||||||
|
|
||||||
//Get Order book (create it if it hasn't been created)
|
|
||||||
var orderBook = StockMarket["Orders"];
|
var orderBook = StockMarket["Orders"];
|
||||||
if (orderBook == null) {
|
if (orderBook == null) {
|
||||||
var orders = {};
|
var orders = {};
|
||||||
@ -881,41 +922,30 @@ function switchToPortfolioMode() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
StockMarket["Orders"] = orders;
|
StockMarket["Orders"] = orders;
|
||||||
|
orderBook = StockMarket["Orders"];
|
||||||
|
}
|
||||||
|
|
||||||
|
let watchlist = null;
|
||||||
|
if (StockMarket.watchlistFilter != null && StockMarket.watchlistFilter !== "") {
|
||||||
|
let filter = StockMarket.watchlistFilter.replace(/\s/g, '');
|
||||||
|
watchlist = filter.split(",");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var name in StockMarket) {
|
for (var name in StockMarket) {
|
||||||
if (StockMarket.hasOwnProperty(name)) {
|
if (StockMarket.hasOwnProperty(name)) {
|
||||||
var stock = StockMarket[name];
|
var stock = StockMarket[name];
|
||||||
if (!(stock instanceof Stock)) {continue;} //orders property is an array
|
if (!(stock instanceof Stock)) {continue;} //orders property is an array
|
||||||
var stockOrders = orderBook[stock.symbol];
|
if (watchlist && !watchlist.includes(stock.symbol)) {continue;} //Watchlist filtering
|
||||||
if (stock.playerShares === 0 && stock.playerShortShares === 0 &&
|
|
||||||
stockOrders.length === 0) {continue;}
|
|
||||||
createStockTicker(stock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setStockTickerClickHandlers();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Displays all stocks
|
let stockOrders = orderBook[stock.symbol];
|
||||||
function switchToDisplayAllMode() {
|
if (stockMarketPortfolioMode) {
|
||||||
stockMarketPortfolioMode = false;
|
if (stock.playerShares === 0 && stock.playerShortShares === 0 &&
|
||||||
var stockList = document.getElementById("stock-market-list");
|
stockOrders.length === 0) {continue;}
|
||||||
if (stockList == null) {return;}
|
}
|
||||||
var modeBtn = clearEventListeners("stock-market-mode");
|
|
||||||
if (modeBtn) {
|
|
||||||
modeBtn.innerHTML = "Switch to 'Portfolio' Mode" +
|
|
||||||
"<span class='tooltiptext'>Displays only the stocks for which you have shares or orders</span>";
|
|
||||||
modeBtn.addEventListener("click", switchToPortfolioMode);
|
|
||||||
}
|
|
||||||
while(stockList.firstChild) {stockList.removeChild(stockList.firstChild);}
|
|
||||||
for (var name in StockMarket) {
|
|
||||||
if (StockMarket.hasOwnProperty(name)) {
|
|
||||||
var stock = StockMarket[name];
|
|
||||||
if (!(stock instanceof Stock)) {continue;} //orders property is an array
|
|
||||||
createStockTicker(stock);
|
createStockTicker(stock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setStockTickerClickHandlers();
|
setStockTickerClickHandlers(); //Clicking headers opens/closes panels
|
||||||
}
|
}
|
||||||
|
|
||||||
function createStockTicker(stock) {
|
function createStockTicker(stock) {
|
||||||
@ -1196,7 +1226,12 @@ function updateStockTicker(stock, increase) {
|
|||||||
var hdr = document.getElementById(tickerId + "-hdr");
|
var hdr = document.getElementById(tickerId + "-hdr");
|
||||||
|
|
||||||
if (hdr == null) {
|
if (hdr == null) {
|
||||||
if (!stockMarketPortfolioMode) {console.log("ERROR: Couldn't find ticker element for stock: " + stock.symbol);}
|
if (!stockMarketPortfolioMode) {
|
||||||
|
let watchlist = StockMarket.watchlistFilter;
|
||||||
|
if (watchlist !== "" && watchlist.includes(stock.symbol)) {
|
||||||
|
console.log("ERROR: Couldn't find ticker element for stock: " + stock.symbol);
|
||||||
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
hdr.innerHTML = stock.name + " - " + stock.symbol + " - " + numeral(stock.price).format('($0.000a)');
|
hdr.innerHTML = stock.name + " - " + stock.symbol + " - " + numeral(stock.price).format('($0.000a)');
|
||||||
@ -1280,7 +1315,13 @@ function updateStockOrderList(stock) {
|
|||||||
var tickerId = "stock-market-ticker-" + stock.symbol;
|
var tickerId = "stock-market-ticker-" + stock.symbol;
|
||||||
var orderList = document.getElementById(tickerId + "-order-list");
|
var orderList = document.getElementById(tickerId + "-order-list");
|
||||||
if (orderList == null) {
|
if (orderList == null) {
|
||||||
if (!stockMarketPortfolioMode) {console.log("ERROR: Could not find order list for " + stock.symbol);}
|
//Log only if its a valid error
|
||||||
|
if (!stockMarketPortfolioMode) {
|
||||||
|
let watchlist = StockMarket.watchlistFilter;
|
||||||
|
if (watchlist !== "" && watchlist.includes(stock.symbol)) {
|
||||||
|
console.log("ERROR: Could not find order list for " + stock.symbol);
|
||||||
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user