Skip to content

Commit

Permalink
Chemistry codex - VueUI edition (Aurorastation#9413)
Browse files Browse the repository at this point in the history
Mostly contains fuzzy search what should make search experence nice and responsive. Data generation assumes rections do not change.
  • Loading branch information
Karolis2011 authored Jul 25, 2020
1 parent 4f1b29f commit 7cbc3bd
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 6 deletions.
1 change: 1 addition & 0 deletions aurorastation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -2131,6 +2131,7 @@
#include "code\modules\modular_computers\file_system\programs\pai\signaler.dm"
#include "code\modules\modular_computers\file_system\programs\pai\translator.dm"
#include "code\modules\modular_computers\file_system\programs\research\ai_restorer.dm"
#include "code\modules\modular_computers\file_system\programs\research\chemistry_codex.dm"
#include "code\modules\modular_computers\file_system\programs\research\ntmonitor.dm"
#include "code\modules\modular_computers\file_system\programs\security\camera.dm"
#include "code\modules\modular_computers\file_system\programs\security\digitalwarrant.dm"
Expand Down
10 changes: 8 additions & 2 deletions code/_helpers/lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,18 @@
return TRUE
return FALSE

/proc/is_path_in_list(var/check_path, var/list/L)
for(var/path in L)
if(ispath(check_path, path))
return TRUE
return FALSE

//Checks for specific types in a list
/proc/is_type_in_list(var/datum/A, var/list/L)
for(var/type in L)
if(istype(A, type))
return 1
return 0
return TRUE
return FALSE

/proc/instances_of_type_in_list(var/datum/A, list/L, strict = FALSE)
. = 0
Expand Down
66 changes: 66 additions & 0 deletions code/controllers/subsystems/chemistry.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ var/datum/controller/subsystem/chemistry/SSchemistry
var/list/datum/reagent/chemical_reagents

var/tmp/list/processing_holders = list()
var/list/codex_data = list()
var/list/codex_ignored_reaction_path = list(/datum/chemical_reaction/slime)
var/list/codex_ignored_result_path = list(/datum/reagent/drink, /datum/reagent/alcohol, /datum/reagent/paint)

/datum/controller/subsystem/chemistry/proc/has_valid_specific_heat(var/datum/reagent/R) //Used for unit tests. Same as check_specific_heat but returns a boolean instead.

Expand Down Expand Up @@ -82,6 +85,7 @@ var/datum/controller/subsystem/chemistry/SSchemistry
/datum/controller/subsystem/chemistry/Initialize()
initialize_chemical_reagents()
initialize_chemical_reactions()
initialize_codex_data()
var/pre_secret_len = chemical_reactions.len
log_ss("chemistry", "Found [chemical_reagents.len] reagents, [pre_secret_len] reactions.")
load_secret_chemicals()
Expand Down Expand Up @@ -186,3 +190,65 @@ var/datum/controller/subsystem/chemistry/SSchemistry
chemical_reactions[rtype] += D
if(D.type)
chemical_reactions_clean[D.type] = D

// Creates data for chemical codex
/datum/controller/subsystem/chemistry/proc/initialize_codex_data()
codex_data = list()
for(var/chem_path in chemical_reactions_clean)
if(codex_ignored_reaction_path && is_path_in_list(chem_path, codex_ignored_reaction_path))
continue
var/datum/chemical_reaction/CR = new chem_path
if(!CR.result)
continue
if(codex_ignored_result_path && is_path_in_list(CR.result, codex_ignored_result_path))
continue
var/datum/reagent/R = new CR.result
var/reactionData = list(id = CR.id)
reactionData["result"] = list(
name = R.name,
description = R.description,
amount = CR.result_amount
)

reactionData["reagents"] = list()
for(var/reagent in CR.required_reagents)
var/datum/reagent/required_reagent = reagent
reactionData["reagents"] += list(list(
name = initial(required_reagent.name),
amount = CR.required_reagents[reagent]
))

reactionData["catalysts"] = list()
for(var/reagent_path in CR.catalysts)
var/datum/reagent/required_reagent = reagent_path
reactionData["catalysts"] += list(list(
name = initial(required_reagent.name),
amount = CR.catalysts[reagent_path]
))

reactionData["inhibitors"] = list()
for(var/reagent_path in CR.inhibitors)
var/datum/reagent/required_reagent = reagent_path
var/inhibitor_amount = CR.inhibitors[reagent_path] ? CR.inhibitors[reagent_path] : "Any"
reactionData["inhibitors"] += list(list(
name = initial(required_reagent.name),
amount = inhibitor_amount
))

reactionData["temp_min"] = list()
for(var/reagent_path in CR.required_temperatures_min)
var/datum/reagent/required_reagent = reagent_path
reactionData["temp_min"] += list(list(
name = initial(required_reagent.name),
temp = CR.required_temperatures_min[reagent_path]
))

reactionData["temp_max"] = list()
for(var/reagent_path in CR.required_temperatures_max)
var/datum/reagent/required_reagent = reagent_path
reactionData["temp_max"] += list(list(
name = initial(required_reagent.name),
temp = CR.required_temperatures_max[reagent_path]
))

codex_data += list(reactionData)
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/datum/computer_file/program/chemistry_codex
filename = "chemcodex"
filedesc = "Chemistry codex"
program_icon_state = "generic"
extended_desc = "Useful program to view chemical reactions and how to make them."
size = 14
required_access_run = access_medical
required_access_download = access_medical
available_on_ntnet = TRUE

/datum/computer_file/program/chemistry_codex/ui_interact(mob/user)
var/datum/vueui/ui = SSvueui.get_open_ui(user, src)
if (!ui)
ui = new /datum/vueui/modularcomputer(user, src, "mcomputer-chemcodex", 450, 600, filedesc)
ui.open()

/datum/computer_file/program/chemistry_codex/vueui_transfer(oldobj)
SSvueui.transfer_uis(oldobj, src, "mcomputer-chemcodex", 450, 600, filedesc)
return TRUE

// Gathers data for ui. This is not great vueui example, all data sent from server is static.
/datum/computer_file/program/chemistry_codex/vueui_data_change(var/list/data, var/mob/user, var/datum/vueui/ui)
. = ..()
data = . || data || list()
// Gather data for computer header
var/headerdata = get_header_data(data["_PC"])
if(headerdata)
data["_PC"] = headerdata
. = data

// Here goes listification
if(data["reactions"] == null)
. = data
data["reactions"] = SSchemistry.codex_data
8 changes: 4 additions & 4 deletions code/modules/reagents/Chemistry-Recipes.dm
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@
name = "Diethylamine"
id = "diethylamine"
result = /datum/reagent/diethylamine
required_reagents = list (/datum/reagent/ammonia = 1, /datum/reagent/alcohol/ethanol = 1)
required_reagents = list(/datum/reagent/ammonia = 1, /datum/reagent/alcohol/ethanol = 1)
result_amount = 2

/datum/chemical_reaction/space_cleaner
Expand Down Expand Up @@ -2079,7 +2079,7 @@
result_amount = 6

/datum/chemical_reaction/drink/beepsky_smash
name = "Beepksy Smash"
name = "Beepsky Smash"
id = "beepksysmash"
result = /datum/reagent/alcohol/ethanol/beepskysmash
required_reagents = list(/datum/reagent/drink/limejuice = 1, /datum/reagent/alcohol/ethanol/whiskey = 1, /datum/reagent/iron = 1)
Expand All @@ -2103,14 +2103,14 @@
name = "The Manly Dorf"
id = "manlydorf"
result = /datum/reagent/alcohol/ethanol/manly_dorf
required_reagents = list (/datum/reagent/alcohol/ethanol/beer = 1, /datum/reagent/alcohol/ethanol/ale = 2)
required_reagents = list(/datum/reagent/alcohol/ethanol/beer = 1, /datum/reagent/alcohol/ethanol/ale = 2)
result_amount = 3

/datum/chemical_reaction/drink/hooch
name = "Hooch"
id = "hooch"
result = /datum/reagent/alcohol/ethanol/hooch
required_reagents = list (/datum/reagent/sugar = 1, /datum/reagent/alcohol/ethanol/moonshine = 1, /datum/reagent/fuel = 1)
required_reagents = list(/datum/reagent/sugar = 1, /datum/reagent/alcohol/ethanol/moonshine = 1, /datum/reagent/fuel = 1)
result_amount = 3

/datum/chemical_reaction/drink/irish_coffee
Expand Down
6 changes: 6 additions & 0 deletions html/changelogs/example copy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
author: Karolis2011

delete-after: True

changes:
- rscadd: "Added chemical codex program, that tells chemists about possible reactions."
4 changes: 4 additions & 0 deletions vueui/src/assets/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,8 @@ a, .button, button, input[type=submit], input[type=button], input[type=reset], i

.blue {
color: green;
}

.highlight {
color: darkblue;
}
73 changes: 73 additions & 0 deletions vueui/src/components/view/mcomputer/chemcodex.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<template>
<div>
<vui-input-search :input="s.reactions" v-model="output" :keys="['result.name', 'reagents.name', 'result.description']" autofocus :threshold="threshold" include-score/>
<vui-button @click="desc = !desc">Toggle descriptions</vui-button>
<div class="recipe-block" v-for="reac in output" :key="reac.item.id" :style="{opacity: 1 - (reac.score * score_multiplier)}">
<h2 class="highlight">{{ reac.item.result.name }} ({{ u(reac.item.result.amount) }})</h2>
<p v-show="desc">{{ reac.item.result.description }}</p>
<h3 class="highlight">Required Reagents</h3>
<span v-for="r in reac.item.reagents" :key="'re'+r.name+reac.item.result.name">{{ r.name }}: {{ u(r.amount) }}<br></span>
<template v-if="reac.item.catalysts.length">
<h3 class="highlight">Catalysts</h3>
<span v-for="r in reac.item.catalysts" :key="'ca'+r.name+reac.item.result.name">{{ r.name }}: {{ u(r.amount) }}<br></span>
</template>
<template v-if="reac.item.inhibitors.length">
<h3 class="highlight">Inhibitors</h3>
<span v-for="r in reac.item.inhibitors" :key="'in'+r.name+reac.item.result.name">{{ r.name }}: {{ u(r.amount) }}<br></span>
</template>
<template v-if="reac.item.temp_min.length">
<h3 class="highlight">Minimum required temparatures</h3>
<span v-for="t in reac.item.temp_min" :key="'tm'+t.name+reac.item.result.name">{{ t.name }}: {{ t.temp }}&deg;K<br></span>
</template>
<template v-if="reac.item.temp_max.length">
<h3 class="highlight">Maximum required temparatures</h3>
<span v-for="t in reac.item.temp_max" :key="'tx'+t.name+reac.item.result.name">{{ t.name }}: {{ t.temp }}&deg;K<br></span>
</template>
</div>
</div>
</template>

<script>
export default {
data() {
return {
s: this.$root.$data.state,
output: [],
threshold: 0.3,
desc: true
}
},
methods: {
u(num) {
if(num == 1) {
return `${num} unit`
} else {
return `${num} units`
}
}
},
computed: {
score_multiplier() {
return 1 / this.threshold
}
}
}
</script>

<style lang="scss" scoped>
.recipe-block {
h2, h3 {
padding: 2px 0;
}
background-color: rgba(0, 0, 0, 0);
border-bottom: 2px solid transparent;
transition: background-color 0.2s, color 0.2s border-bottom 0.2s;
padding: 2px;
&:hover {
background-color: rgba(0, 0, 0, 0.5);
border-bottom: 2px solid #4f7c9e;
}
}
</style>

0 comments on commit 7cbc3bd

Please sign in to comment.