-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PORT] Adds an app for tracking vendor stock from TG (#81582) (#586)
Co-authored-by: RimiNosha <[email protected]>
- Loading branch information
1 parent
7a173d0
commit 62076e6
Showing
10 changed files
with
153 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
code/modules/modular_computers/file_system/programs/restock_tracker.dm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/datum/computer_file/program/restock_tracker | ||
filename = "restockapp" | ||
filedesc = "Restock Tracker" | ||
category = PROGRAM_CATEGORY_SUPL | ||
program_icon_state = "restock" | ||
extended_desc = "An IoT-networked app listing all official vending machines found onboard and how well-stocked they are." | ||
requires_ntnet = TRUE | ||
size = 4 | ||
program_icon = "cash-register" | ||
tgui_id = "NtosRestock" | ||
|
||
/datum/computer_file/program/restock_tracker/ui_data() | ||
var/list/data = list() | ||
var/list/vending_list = list() | ||
var/id_increment = 1 | ||
for(var/obj/machinery/vending/vendor as anything in GLOB.vending_machines_to_restock) | ||
var/stock = vendor.total_loaded_stock() | ||
var/max_stock = vendor.total_max_stock() | ||
if(max_stock == 0 || (stock >= max_stock)) | ||
continue | ||
vending_list += list(list( | ||
"name" = vendor.name, | ||
"location" = get_area_name(vendor), | ||
"percentage" = (stock / max_stock) * 100, | ||
"id" = id_increment, | ||
)) | ||
id_increment++ | ||
data["vending_list"] = vending_list | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { NtosWindow } from '../layouts'; | ||
import { RestockTracker } from './RestockTracker'; | ||
|
||
export const NtosRestock = (props, context) => { | ||
return ( | ||
<NtosWindow width={575} height={560}> | ||
<NtosWindow.Content scrollable> | ||
<RestockTracker /> | ||
</NtosWindow.Content> | ||
</NtosWindow> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { sortBy } from 'common/collections'; | ||
import { round } from 'common/math'; | ||
|
||
import { useBackend } from '../backend'; | ||
import { ProgressBar, Section, Stack } from '../components'; | ||
import { Window } from '../layouts'; | ||
|
||
export const Restock = (props, context) => { | ||
return ( | ||
<Window width={575} height={560}> | ||
<Window.Content scrollable> | ||
<RestockTracker /> | ||
</Window.Content> | ||
</Window> | ||
); | ||
}; | ||
|
||
type VendingMachine = { | ||
id: string; | ||
name: string; | ||
location: string; | ||
percentage: number; | ||
}; | ||
|
||
type Data = { | ||
vending_list: VendingMachine[]; | ||
}; | ||
|
||
export const RestockTracker = (props, context) => { | ||
const { data } = useBackend<Data>(context); | ||
const vending_list = sortBy((vend: VendingMachine) => vend.percentage)( | ||
data.vending_list ?? [] | ||
); | ||
return ( | ||
<Section fill title="Vendor Stocking Status"> | ||
<Stack vertical> | ||
<Stack fill horizontal> | ||
<Stack.Item bold width="30%"> | ||
Vending Name | ||
</Stack.Item> | ||
<Stack.Item bold width="30%"> | ||
Location | ||
</Stack.Item> | ||
<Stack.Item bold width="40%"> | ||
Stock % | ||
</Stack.Item> | ||
</Stack> | ||
<hr /> | ||
{vending_list?.map((vend) => ( | ||
<Stack key={vend.id} fill horizontal> | ||
<Stack.Item wrap width="30%" height="100%"> | ||
{vend.name} | ||
</Stack.Item> | ||
<Stack.Item wrap width="30%" height="100%"> | ||
{vend.location} | ||
</Stack.Item> | ||
<Stack.Item | ||
wrap | ||
width="40%" | ||
textAlign={ | ||
vend.percentage > 75 | ||
? 'left' | ||
: vend.percentage > 45 | ||
? 'right' | ||
: 'center' | ||
}> | ||
<ProgressBar | ||
value={vend.percentage} | ||
minValue={0} | ||
maxValue={100} | ||
ranges={{ | ||
good: [75, 100], | ||
average: [45, 75], | ||
bad: [0, 45], | ||
}}> | ||
{round(vend.percentage, 0.01)} | ||
</ProgressBar> | ||
</Stack.Item> | ||
</Stack> | ||
))} | ||
</Stack> | ||
</Section> | ||
); | ||
}; |