From e3aed7d1754bc97c8b364f52eff97260748d766a Mon Sep 17 00:00:00 2001 From: lowercasedonkey <lowercasedonkey@gmail.com> Date: Mon, 24 Aug 2020 20:25:11 -0400 Subject: [PATCH] market controls --- src/Corporation/corporateMarket.tw | 3 +- src/markets/marketUI.js | 82 +++++++++++++++++++++++++++++ src/pregmod/wetwareCPUs.tw | 3 +- src/uncategorized/slaveMarkets.tw | 3 +- src/utility/slaveCreationWidgets.tw | 24 --------- 5 files changed, 85 insertions(+), 30 deletions(-) create mode 100644 src/markets/marketUI.js diff --git a/src/Corporation/corporateMarket.tw b/src/Corporation/corporateMarket.tw index 285a7aece6d..0fcb02f061b 100644 --- a/src/Corporation/corporateMarket.tw +++ b/src/Corporation/corporateMarket.tw @@ -106,8 +106,7 @@ while you browse. <<set _slaveCost = 500*Math.trunc(_slaveCost/500)>> The offered price is <<print cashFormat(_slaveCost)>>.<<if $slavesSeen > $slaveMarketLimit>> You have cast such a wide net for slaves this week that it is becoming more expensive to find more for sale. Your reputation helps determine your reach within the slave market.<</if>> <br> -<<setLocalPronouns $activeSlave>> -<<buyingFromMarketControls>> +<<includeDOM App.UI.buyingFromMarketControls($activeSlave, _slaveCost)>> <<link "End corporate slave sales here and return this sector to standard markets">> <<set $corp.Market = 0>> diff --git a/src/markets/marketUI.js b/src/markets/marketUI.js new file mode 100644 index 00000000000..bb31c710d37 --- /dev/null +++ b/src/markets/marketUI.js @@ -0,0 +1,82 @@ +App.UI.buyingFromMarketControls = function(slave, slaveCost) { + const {him, his} = getPronouns(slave); + const el = document.createElement("p"); + App.UI.DOM.appendNewElement( + "div", + el, + App.UI.DOM.link( + `Decline to purchase ${him} and check out another slave`, + () => { + V.slavesSeen += 1; + }, + [], + passage() + ) + ); + if (V.cash >= slaveCost) { + App.UI.DOM.appendNewElement( + "div", + el, + App.UI.DOM.link( + `Buy ${him} and check out other slaves to order`, + () => { + cashX(forceNeg(slaveCost), "slaveTransfer", slave); + V.newSlaves.push(slave); + V.introType = "multi"; + V.slavesSeen += 1; + }, + [], + passage() + ) + ); + if (V.newSlaves.length === 0) { + App.UI.DOM.appendNewElement( + "div", + el, + App.UI.DOM.link( + `Buy ${his} slave contract`, + () => { + cashX(forceNeg(slaveCost), "slaveTransfer", slave); + V.newSlaves.push(slave); + V.nextButton = "Continue"; + V.nextLink = "AS Dump"; + V.returnTo = "Main"; + }, + [], + passage() + ) + ); + } else { + App.UI.DOM.appendNewElement( + "div", + el, + App.UI.DOM.link( + `Buy ${him} and finish your order of slaves`, + () => { + cashX(forceNeg(_slaveCost), "slaveTransfer", slave); + V.newSlaves.push(slave); + }, + [], + "Bulk Slave Intro" + ) + ); + } + } else { + App.UI.DOM.appendNewElement("span", el, `You lack the necessary funds to buy this slave.`, "note"); + } + if (V.newSlaves.length > 0) { + App.UI.DOM.appendNewElement( + "div", + el, + App.UI.DOM.link( + `Finish your order of slaves`, + () => { }, + [], + "Bulk Slave Intro" + ) + ); + } + + el.append(App.Desc.longSlave(V.activeSlave, {market: V.slaveMarket})); + return el; +}; diff --git a/src/pregmod/wetwareCPUs.tw b/src/pregmod/wetwareCPUs.tw index b99cc1d29c5..f467247b81a 100644 --- a/src/pregmod/wetwareCPUs.tw +++ b/src/pregmod/wetwareCPUs.tw @@ -19,5 +19,4 @@ <br><br>The price is <<print cashFormat(_slaveCost)>>.<<if $slavesSeen > $slaveMarketLimit>> You have cast such a wide net for slaves this week that it is becoming more expensive to find more for sale. Your reputation helps determine your reach within the slave market.<</if>> -<<setLocalPronouns $activeSlave>> -<<buyingFromMarketControls>> +<<includeDOM App.UI.buyingFromMarketControls($activeSlave, _slaveCost)>> diff --git a/src/uncategorized/slaveMarkets.tw b/src/uncategorized/slaveMarkets.tw index a3dd396b858..d3976e658ca 100644 --- a/src/uncategorized/slaveMarkets.tw +++ b/src/uncategorized/slaveMarkets.tw @@ -183,5 +183,4 @@ You visit the slave markets off the arcology plaza. It's always preferable to ex <<set _slaveCost = 500*Math.trunc(_slaveCost/500)>> The offered price is <<print cashFormat(_slaveCost)>>.<<if $slavesSeen > $slaveMarketLimit>> You have cast such a wide net for slaves this week that it is becoming more expensive to find more for sale. Your reputation helps determine your reach within the slave market.<</if>> -<<setLocalPronouns $activeSlave>> -<<buyingFromMarketControls>> +<<includeDOM App.UI.buyingFromMarketControls($activeSlave, _slaveCost)>> diff --git a/src/utility/slaveCreationWidgets.tw b/src/utility/slaveCreationWidgets.tw index c8b4198ca34..a5f750d8e5e 100644 --- a/src/utility/slaveCreationWidgets.tw +++ b/src/utility/slaveCreationWidgets.tw @@ -772,30 +772,6 @@ <</switch>> <</widget>> -/% - % Shows controls for buying and advancing the queue for buying slaves from a school - % Arguments: none - % Call as <<buyingFromMarketControls>> - %/ -<<widget "buyingFromMarketControls">> -<br>[["Decline to purchase " + $him + " and check out another slave"|passage()][$slavesSeen += 1]] -<<if $cash >= _slaveCost>> - <br>[["Buy " + $him + " and check out other slaves to order"|passage()][cashX(forceNeg(_slaveCost), "slaveTransfer", $activeSlave),$newSlaves.push($activeSlave), $introType = "multi", $slavesSeen+=1]] - <<if $newSlaves.length == 0>> - <br>[["Buy " + $his + " slave contract"|New Slave Intro][cashX(forceNeg(_slaveCost), "slaveTransfer", $activeSlave),$nextButton = "Continue",$nextLink = "AS Dump",$returnTo = "Main"]] - <<else>> - <br>[["Buy " + $him + " and finish your order of slaves"|Bulk Slave Intro][cashX(forceNeg(_slaveCost), "slaveTransfer", $activeSlave), $newSlaves.push($activeSlave)]] - <</if>> -<<else>> - <br>//You lack the necessary funds to buy this slave.// -<</if>> -<<if $newSlaves.length > 0>> - <br>[[Finish your order of slaves|Bulk Slave Intro]] -<</if>> -<br><br> -<<includeDOM App.Desc.longSlave(V.activeSlave, {market: V.slaveMarket})>> -<</widget>> - /% % Shows controls for buying and advancing the queue for buying slaves from a school % Arguments: -- GitLab