Add warnings if phaser has next card too long and increase it's virtual HP consumption #151

Open
esavkin wants to merge 2 commits from esavkin/web2019:148-phaser-fix into master
5 changed files with 97 additions and 38 deletions

6
package-lock.json generated
View File

@ -2815,9 +2815,9 @@
"dev": true "dev": true
}, },
"node_modules/caniuse-lite": { "node_modules/caniuse-lite": {
"version": "1.0.30001690", "version": "1.0.30001696",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001690.tgz", "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001696.tgz",
"integrity": "sha512-5ExiE3qQN6oF8Clf8ifIDcMRCRE/dMGcETG/XGMD8/XiXm6HXQgQTh1yZYLXXpSOsEUlJm1Xr7kGULZTuGtP/w==", "integrity": "sha512-pDCPkvzfa39ehJtJ+OwGT/2yvT2SbjfHhiIW2LWOAcMQ7BzwxT/XuyUp4OTOd0XFWA6BKw0JalnBHgSi5DGJBQ==",
"dev": true, "dev": true,
"funding": [ "funding": [
{ {

File diff suppressed because one or more lines are too long

View File

@ -480,7 +480,7 @@ const useCart = ((set, get) => ({
let itemsCopy = Array.from(crate.items); let itemsCopy = Array.from(crate.items);
const disabled = !!get().crateParams(crate.crate_mode).warnings_disabled; const disabled = !!get().crateParams(crate.crate_mode).warnings_disabled;
itemsCopy = FillResources(itemsCopy, disabled); itemsCopy = FillResources(itemsCopy, disabled);
itemsCopy = TriggerWarnings(itemsCopy, disabled); itemsCopy = TriggerWarnings(itemsCopy, disabled, crate);
const [crate_warnings, occupied] = TriggerCrateWarnings(crate); const [crate_warnings, occupied] = TriggerCrateWarnings(crate);
return { return {
...crate, ...crate,

View File

@ -30,14 +30,14 @@ const find_next_source_index = (data, index, source) => {
} }
const not_enough_resource_trigger = (name) => { const not_enough_resource_trigger = (name) => {
return (_data, _index, counters) => { return (_data, _index, counters, _crate) => {
const resource = find_in_counters(counters, name); const resource = find_in_counters(counters, name);
return resource.occupied > resource.max; return resource.occupied > resource.max;
} }
} }
const no_source_trigger = (name) => { const no_source_trigger = (name) => {
return (data, index, _counters) => { return (data, index, _counters, _crate) => {
const occupied = item_occupied_counters[name](data[index]); const occupied = item_occupied_counters[name](data[index]);
if (occupied > 0) if (occupied > 0)
return !find_previous_source(data, index, name); return !find_previous_source(data, index, name);
@ -46,12 +46,20 @@ const no_source_trigger = (name) => {
} }
const wiring_constraint = (name) => { const wiring_constraint = (name) => {
return (data, index, _counters) => { return (data, index, _counters, _crate) => {
const next = find_next_source_index(data, index, name); const next = find_next_source_index(data, index, name);
return next - index === 1; return next - index === 1;
} }
} }
const phaser_next_card_long = (data, index, counters, crate) => {
const nbrOccupied = resource_counters.hp(crate.items, -1);
const nbrHP = useShopStore.getState().crateParams(crate.crate_mode).hp;
return (index < data.length - 1) ? (
(data[index+1].consumes && data[index+1].consumes.depth && data[index+1].consumes.depth >= 8.5)
) : (nbrOccupied >= nbrHP && nbrHP > 0)
}
const Types = { const Types = {
"eem_resource": { "eem_resource": {
level: "warning", level: "warning",
@ -88,22 +96,27 @@ const Types = {
trigger: wiring_constraint("eem"), trigger: wiring_constraint("eem"),
message: "Due to wiring constraints, the carrier can only connect to EEM cards immediately at its right, without crossing another carrier." message: "Due to wiring constraints, the carrier can only connect to EEM cards immediately at its right, without crossing another carrier."
}, },
"phaser_next_card_long": {
level: "reminder",
trigger: phaser_next_card_long,
message: "The next card may interfere with this Phaser. Consider placing a shorter card right after this Phaser."
},
"default": { "default": {
level: "warning", level: "warning",
trigger: (_a, _b, _c) => { trigger: (_a, _b, _c, _d) => {
return true; return true;
}, },
message: 'This item has unimplemented warning' message: 'This item has unimplemented warning'
} }
} }
export function TriggerWarnings(data, disabled) { export function TriggerWarnings(data, disabled, crate) {
return data.map((element, index) => { return data.map((element, index) => {
if (!element.warnings) return element; if (!element.warnings) return element;
element.show_warnings = disabled ? [] :element.warnings element.show_warnings = disabled ? [] :element.warnings
.map((warning, _) => { .map((warning, _) => {
if (!!Types[warning]) if (!!Types[warning])
return Types[warning].trigger(data, index, element.counted_resources) ? {trigger: undefined, name: warning, ...Types[warning]} : null; return Types[warning].trigger(data, index, element.counted_resources, crate) ? {trigger: undefined, name: warning, ...Types[warning]} : null;
else else
return Types.default; return Types.default;
}) })
@ -143,6 +156,22 @@ const crate_warnings = {
const nbrHPDesktop = useShopStore.getState().crate_modes.desktop.hp; const nbrHPDesktop = useShopStore.getState().crate_modes.desktop.hp;
return crate.crate_mode === useShopStore.getState().crate_modes.rack.id && occupied < nbrHPDesktop; return crate.crate_mode === useShopStore.getState().crate_modes.rack.id && occupied < nbrHPDesktop;
} }
},
"phaser_not_fit": {
message: "Phaser cards require additional space immediately after them, but the current crate lacks sufficient room. This may disrupt placement of subsequent cards. Consider removing cards, repositioning shorter cards after Phaser(s), or using a larger crate.",
Outdated
Review

"they may additional space"?

"they may additional space"?
Outdated
Review

And why "may interfere"? It's pretty clear whether they do or not.

And why "*may* interfere"? It's pretty clear whether they do or not.
level: "warning",
trigger: (crate, occupied) => {
const nbrHP = useShopStore.getState().crateParams(crate.crate_mode).hp;
const stacked_phasers = crate.items.filter((elem, index, data) => {
return (elem.name_codename === "Phaser") && ((index < data.length - 1) ? (
(data[index + 1].consumes && data[index + 1].consumes.depth && data[index + 1].consumes.depth >= 8.5)
) : (occupied >= nbrHP && nbrHP > 0))
}
).length;
// #!debug
console.log(stacked_phasers, occupied)
return stacked_phasers > 0 && (occupied + stacked_phasers*2 >= nbrHP) && nbrHP >0;
}
} }
} }

View File

@ -229,7 +229,8 @@ const shop_data = {
"eem_wiring_constraint" "eem_wiring_constraint"
], ],
consumes: { consumes: {
hp: 8 hp: 8,
depth: 20
} }
}, },
'kaslisoc': { 'kaslisoc': {
@ -307,7 +308,8 @@ const shop_data = {
"eem_wiring_constraint" "eem_wiring_constraint"
], ],
consumes: { consumes: {
hp: 8 hp: 8,
depth: 20
} }
}, },
'vhdcicarrier': { 'vhdcicarrier': {
@ -332,7 +334,8 @@ const shop_data = {
"eem_wiring_constraint" "eem_wiring_constraint"
], ],
consumes: { consumes: {
hp: 8 hp: 8,
depth: 16
} }
}, },
'bnc-dio': { 'bnc-dio': {
@ -403,7 +406,8 @@ const shop_data = {
], ],
consumes: { consumes: {
hp: 8, hp: 8,
eem: 1 eem: 1,
depth: 7
} }
}, },
'sma-dio': { 'sma-dio': {
@ -468,7 +472,8 @@ const shop_data = {
], ],
consumes: { consumes: {
hp: 4, hp: 4,
eem: 1 eem: 1,
depth: 7
} }
}, },
'mcx-dio': { 'mcx-dio': {
@ -559,7 +564,8 @@ const shop_data = {
], ],
consumes: { consumes: {
hp: 4, hp: 4,
eem: 2 eem: 2,
depth: 23
} }
}, },
'rj45-dio': { 'rj45-dio': {
@ -645,7 +651,8 @@ const shop_data = {
], ],
consumes: { consumes: {
hp: 4, hp: 4,
eem: 2 eem: 2,
depth: 7
} }
}, },
'urukul': { 'urukul': {
@ -710,7 +717,8 @@ const shop_data = {
consumes: { consumes: {
hp: 4, hp: 4,
eem: 2, eem: 2,
clk: 1 clk: 1,
depth: 16
} }
}, },
'urukul_4412': { 'urukul_4412': {
@ -748,7 +756,8 @@ const shop_data = {
consumes: { consumes: {
hp: 4, hp: 4,
eem: 2, eem: 2,
clk: 1 clk: 1,
depth: 16
} }
}, },
'phaser': { 'phaser': {
@ -777,12 +786,14 @@ const shop_data = {
size: 'small', size: 'small',
warnings: [ warnings: [
"no_eem_source", "no_eem_source",
"no_clk_source" "no_clk_source",
"phaser_next_card_long"
], ],
consumes: { consumes: {
hp: 4, hp: 4,
eem: 1, eem: 1,
clk: 1 clk: 1,
depth: 16 // heatsink 8.5
} }
}, },
'zotino': { 'zotino': {
@ -824,7 +835,8 @@ const shop_data = {
consumes: { consumes: {
hp: 4, hp: 4,
eem: 1, eem: 1,
tec: 1 tec: 1,
depth: 16
}, },
resources: [ resources: [
{name: "idc", max: 4} {name: "idc", max: 4}
@ -852,7 +864,8 @@ const shop_data = {
], ],
consumes: { consumes: {
hp: 4, hp: 4,
eem: 1 eem: 1,
depth: 17
}, },
resources: [ resources: [
{name: "idc", max: 4} {name: "idc", max: 4}
@ -878,7 +891,8 @@ const shop_data = {
], ],
consumes: { consumes: {
hp: 8, hp: 8,
idc: 1 idc: 1,
depth: 6
} }
}, },
'hvamp32': { 'hvamp32': {
@ -906,7 +920,8 @@ const shop_data = {
], ],
consumes: { consumes: {
hp: 4, hp: 4,
idc: 4 idc: 4,
depth: 16
} }
}, },
'idc-sma-adapter': { 'idc-sma-adapter': {
@ -929,7 +944,8 @@ const shop_data = {
], ],
consumes: { consumes: {
hp: 4, hp: 4,
idc: 1 idc: 1,
depth: 6
} }
}, },
'idc-mcx-adapter': { 'idc-mcx-adapter': {
@ -974,7 +990,8 @@ const shop_data = {
"idc_resource" "idc_resource"
], ],
consumes: { consumes: {
hp: 4 hp: 4,
depth: 5
}, },
resources: [ resources: [
{name: "idc", max: 4} {name: "idc", max: 4}
@ -1029,7 +1046,8 @@ const shop_data = {
], ],
consumes: { consumes: {
hp: 8, hp: 8,
eem: 2 eem: 2,
depth: 16
} }
}, },
'koster': { 'koster': {
@ -1055,7 +1073,8 @@ const shop_data = {
], ],
consumes: { consumes: {
hp: 4, hp: 4,
eem: 2 eem: 2,
depth: 7.5
} }
}, },
'clocker': { 'clocker': {
@ -1088,7 +1107,8 @@ const shop_data = {
consumes: { consumes: {
hp: 4, hp: 4,
eem: 1, eem: 1,
clk: 1 clk: 1,
depth: 7
}, },
resources: [ resources: [
{name: "clk", max: 6} {name: "clk", max: 6}
@ -1125,7 +1145,8 @@ const shop_data = {
], ],
consumes: { consumes: {
hp: 4, hp: 4,
eem: 1 eem: 1,
depth: 16
}, },
}, },
'fast_servo': { 'fast_servo': {
@ -1159,7 +1180,8 @@ const shop_data = {
], ],
consumes: { consumes: {
hp: 4, hp: 4,
eem: 1 eem: 1,
depth: 16
}, },
}, },
'mirny': { 'mirny': {
@ -1192,7 +1214,8 @@ const shop_data = {
consumes: { consumes: {
hp: 4, hp: 4,
eem: 1, eem: 1,
clk: 1 clk: 1,
depth: 16
}, },
}, },
'almazny': { 'almazny': {
@ -1220,7 +1243,8 @@ const shop_data = {
consumes: { consumes: {
hp: 8, hp: 8,
eem: 1, eem: 1,
clk: 1 clk: 1,
depth: 16
}, },
}, },
'thermostat-eem': { 'thermostat-eem': {
@ -1248,6 +1272,7 @@ const shop_data = {
consumes: { consumes: {
hp: 4, hp: 4,
eem: 1, eem: 1,
depth: 16
} }
}, },
'thermostat2ch': { 'thermostat2ch': {
@ -1266,7 +1291,8 @@ const shop_data = {
], ],
size: 'small', size: 'small',
consumes: { consumes: {
hp: 4 hp: 4,
depth: 12
}, },
resources: [ resources: [
{name: "tec", max: 2} {name: "tec", max: 2}
@ -1295,7 +1321,8 @@ const shop_data = {
consumes: { consumes: {
hp: 8, hp: 8,
eem: 1, eem: 1,
clk: 1 clk: 1,
depth: 8
}, },
}, },
'pounder': { 'pounder': {
@ -1329,7 +1356,8 @@ const shop_data = {
consumes: { consumes: {
hp: 8, hp: 8,
eem: 1, eem: 1,
clk: 1 clk: 1,
depth: 16
} }
}, },
'eem_pwr_mod': { 'eem_pwr_mod': {
@ -1354,6 +1382,7 @@ const shop_data = {
warnings: [], warnings: [],
consumes: { consumes: {
hp: 8, hp: 8,
depth: 20
}, },
}, },
'kirdy': { 'kirdy': {
@ -1385,6 +1414,7 @@ const shop_data = {
warnings: [], warnings: [],
consumes: { consumes: {
hp: 8, hp: 8,
depth: 16
}, },
}, },
}, },