Merge pull request #15023 from Runa-Dacino/fixairalarms

Fixes Air alarms showing "none" for Nitrogen, introduces some consistency
This commit is contained in:
Heroman3003
2023-06-16 04:47:02 +10:00
committed by GitHub
4 changed files with 59 additions and 73 deletions
+8 -7
View File
@@ -74,6 +74,7 @@
/// Keys are things like temperature and certain gasses. Values are lists, which contain, in order:
/// red warning minimum value, yellow warning minimum value, yellow warning maximum value, red warning maximum value
/// Use code\defines\gases.dm as reference for id/name. Please keep it consistent
var/list/TLV = list()
var/list/trace_gas = list("nitrous_oxide", "volatile_fuel") //list of other gases that this air alarm is able to detect
@@ -108,7 +109,7 @@
. = ..()
req_access = list(access_rd, access_atmospherics, access_engine_equip)
TLV["oxygen"] = list(-1.0, -1.0,-1.0,-1.0) // Partial pressure, kpa
TLV["carbon dioxide"] = list(-1.0, -1.0, 5, 10) // Partial pressure, kpa
TLV["carbon_dioxide"] = list(-1.0, -1.0, 5, 10) // Partial pressure, kpa
TLV["phoron"] = list(-1.0, -1.0, 0, 0.5) // Partial pressure, kpa
TLV["other"] = list(-1.0, -1.0, 0.5, 1.0) // Partial pressure, kpa
TLV["pressure"] = list(0,ONE_ATMOSPHERE*0.10,ONE_ATMOSPHERE*1.40,ONE_ATMOSPHERE*1.60) /* kpa */
@@ -146,7 +147,7 @@
// breathable air according to human/Life()
TLV["oxygen"] = list(16, 19, 135, 140) // Partial pressure, kpa
TLV["nitrogen"] = list(0, 0, 135, 140) // Partial pressure, kpa
TLV["carbon dioxide"] = list(-1.0, -1.0, 5, 10) // Partial pressure, kpa
TLV["carbon_dioxide"] = list(-1.0, -1.0, 5, 10) // Partial pressure, kpa
TLV["phoron"] = list(-1.0, -1.0, 0, 0.5) // Partial pressure, kpa
TLV["other"] = list(-1.0, -1.0, 0.5, 1.0) // Partial pressure, kpa
TLV["pressure"] = list(ONE_ATMOSPHERE * 0.80, ONE_ATMOSPHERE * 0.90, ONE_ATMOSPHERE * 1.10, ONE_ATMOSPHERE * 1.20) /* kpa */
@@ -273,7 +274,7 @@
pressure_dangerlevel = TEST_TLV_VALUES // not local because it's used in process()
LOAD_TLV_VALUES(TLV["oxygen"], environment.gas["oxygen"]*partial_pressure)
var/oxygen_dangerlevel = TEST_TLV_VALUES
LOAD_TLV_VALUES(TLV["carbon dioxide"], environment.gas["carbon_dioxide"]*partial_pressure)
LOAD_TLV_VALUES(TLV["carbon_dioxide"], environment.gas["carbon_dioxide"]*partial_pressure)
var/co2_dangerlevel = TEST_TLV_VALUES
LOAD_TLV_VALUES(TLV["phoron"], environment.gas["phoron"]*partial_pressure)
var/phoron_dangerlevel = TEST_TLV_VALUES
@@ -620,9 +621,9 @@
list("name" = "Oxygen", "command" = "o2_scrub", "val" = info["filter_o2"]),
list("name" = "Nitrogen", "command" = "n2_scrub", "val" = info["filter_n2"]),
list("name" = "Carbon Dioxide", "command" = "co2_scrub","val" = info["filter_co2"]),
list("name" = "Toxin" , "command" = "tox_scrub","val" = info["filter_phoron"]),
list("name" = "Phoron" , "command" = "tox_scrub","val" = info["filter_phoron"]),
list("name" = "Nitrous Oxide", "command" = "n2o_scrub","val" = info["filter_n2o"]),
list("name" = "Fuel", "command" = "fuel_scrub","val" = info["filter_fuel"])
list("name" = "Volatile Fuel", "command" = "fuel_scrub","val" = info["filter_fuel"])
)
))
data["scrubbers"] = scrubbers
@@ -641,7 +642,7 @@
var/list/selected
var/list/thresholds = list()
var/list/gas_names = list("oxygen", "carbon dioxide", "phoron", "other")
var/list/gas_names = list("oxygen", "carbon_dioxide", "phoron", "other") //Gas ids made to match code\defines\gases.dm
for(var/g in gas_names)
thresholds[++thresholds.len] = list("name" = g, "settings" = list())
selected = TLV[g]
@@ -844,4 +845,4 @@
// VOREStation Edit End
#undef LOAD_TLV_VALUES
#undef TEST_TLV_VALUES
#undef DECLARE_TLV_VALUES
#undef DECLARE_TLV_VALUES
+19 -4
View File
@@ -3,8 +3,23 @@ import { getGasColor, getGasFromId, getGasLabel } from './constants';
describe('gas helper functions', () => {
it('should get the proper gas label', () => {
const gasId = 'n2o';
// Testing for alphabetic gas id
const gasId = 'oxygen';
const gasLabel = getGasLabel(gasId);
expect(gasLabel).toBe('O₂');
});
it('should get the proper gas label', () => {
// Testing for underscore gas id
const gasId = 'nitrous_oxide';
const gasLabel = getGasLabel(gasId);
expect(gasLabel).toBe('N₂O');
});
it('should get the proper gas label', () => {
// Testing for wrong capitalization of two word gas
const gasId = 'nitrous oxide';
const gasLabel = getGasLabel(gasId); // This should set to Nitrous Oxide before checking
expect(gasLabel).toBe('N₂O');
});
@@ -23,7 +38,7 @@ describe('gas helper functions', () => {
});
it('should get the proper gas color', () => {
const gasId = 'n2o';
const gasId = 'nitrous_oxide';
const gasColor = getGasColor(gasId);
expect(gasColor).toBe('red');
@@ -37,11 +52,11 @@ describe('gas helper functions', () => {
});
it('should return the gas object if found', () => {
const gasId = 'n2o';
const gasId = 'nitrous_oxide';
const gas = getGasFromId(gasId);
expect(gas).toEqual({
id: 'n2o',
id: 'nitrous_oxide',
// path: '/datum/gas/antinoblium',
name: 'Nitrous Oxide',
label: 'N₂O',
+31 -61
View File
@@ -182,6 +182,9 @@ export const RADIO_CHANNELS = [
},
] as const;
/*
Entries must match /code/defines/gases.dm entries.
*/
const GASES = [
{
'id': 'oxygen',
@@ -190,13 +193,13 @@ const GASES = [
'color': 'blue',
},
{
'id': 'n2',
'id': 'nitrogen',
'name': 'Nitrogen',
'label': 'N₂',
'color': 'red',
'color': 'green',
},
{
'id': 'carbon dioxide',
'id': 'carbon_dioxide',
'name': 'Carbon Dioxide',
'label': 'CO₂',
'color': 'grey',
@@ -208,65 +211,17 @@ const GASES = [
'color': 'pink',
},
{
'id': 'water_vapor',
'name': 'Water Vapor',
'label': 'H₂O',
'color': 'grey',
},
{
'id': 'nob',
'name': 'Hyper-noblium',
'label': 'Hyper-nob',
'id': 'volatile_fuel',
'name': 'Volatile Fuel',
'label': 'EXP',
'color': 'teal',
},
{
'id': 'n2o',
'id': 'nitrous_oxide',
'name': 'Nitrous Oxide',
'label': 'N₂O',
'color': 'red',
},
{
'id': 'no2',
'name': 'Nitryl',
'label': 'NO₂',
'color': 'brown',
},
{
'id': 'tritium',
'name': 'Tritium',
'label': 'Tritium',
'color': 'green',
},
{
'id': 'bz',
'name': 'BZ',
'label': 'BZ',
'color': 'purple',
},
{
'id': 'stim',
'name': 'Stimulum',
'label': 'Stimulum',
'color': 'purple',
},
{
'id': 'pluox',
'name': 'Pluoxium',
'label': 'Pluoxium',
'color': 'blue',
},
{
'id': 'miasma',
'name': 'Miasma',
'label': 'Miasma',
'color': 'olive',
},
{
'id': 'hydrogen',
'name': 'Hydrogen',
'label': 'H₂',
'color': 'white',
},
{
'id': 'other',
'name': 'Other',
@@ -290,13 +245,18 @@ const GASES = [
// VOREStation Edit End
// Returns gas label based on gasId
// Checks GASES for both id (all chars lowercase)
// and name (each word start capitalized, to match standards in code\defines\gases.dm)
export const getGasLabel = (gasId: string, fallbackValue?: string) => {
if (!gasId) return fallbackValue || 'None';
const gasSearchString = gasId.toLowerCase();
const gasSearchId = gasId.toLowerCase();
const gasSearchName = gasId.replace(/(^\w{1})|(\s+\w{1})/g, (letter) =>
letter.toUpperCase()
);
for (let idx = 0; idx < GASES.length; idx++) {
if (GASES[idx].id === gasSearchString) {
if (GASES[idx].id === gasSearchId || GASES[idx].name === gasSearchName) {
return GASES[idx].label;
}
}
@@ -305,13 +265,18 @@ export const getGasLabel = (gasId: string, fallbackValue?: string) => {
};
// Returns gas color based on gasId
// Checks GASES for both id (all chars lowercase)
// and name (each word start capitalized, to match standards in code\defines\gases.dm)
export const getGasColor = (gasId: string) => {
if (!gasId) return 'black';
const gasSearchString = gasId.toLowerCase();
const gasSearchId = gasId.toLowerCase();
const gasSearchName = gasId.replace(/(^\w{1})|(\s+\w{1})/g, (letter) =>
letter.toUpperCase()
);
for (let idx = 0; idx < GASES.length; idx++) {
if (GASES[idx].id === gasSearchString) {
if (GASES[idx].id === gasSearchId || GASES[idx].name === gasSearchName) {
return GASES[idx].color;
}
}
@@ -320,13 +285,18 @@ export const getGasColor = (gasId: string) => {
};
// Returns gas object based on gasId
// Checks GASES for both id (all chars lowercase)
// and name (each word start capitalized, to match standards in code\defines\gases.dm)
export const getGasFromId = (gasId: string): Gas | undefined => {
if (!gasId) return;
const gasSearchString = gasId.toLowerCase();
const gasSearchId = gasId.toLowerCase();
const gasSearchName = gasId.replace(/(^\w{1})|(\s+\w{1})/g, (letter) =>
letter.toUpperCase()
);
for (let idx = 0; idx < GASES.length; idx++) {
if (GASES[idx].id === gasSearchString) {
if (GASES[idx].id === gasSearchId || GASES[idx].name === gasSearchName) {
return GASES[idx];
}
}
File diff suppressed because one or more lines are too long