From c1e26e7ba807cc13aec98a3e476f7ac2c52c9e9f Mon Sep 17 00:00:00 2001 From: Egor Savkin Date: Mon, 12 Aug 2024 17:29:35 +0800 Subject: [PATCH 1/2] Add warnings for the phaser being obstacled by next card --- static/js/shop/shop_store.js | 2 +- static/js/shop/warnings.js | 41 +++++++++++++++--- static/js/shop_data.js | 84 ++++++++++++++++++++++++------------ 3 files changed, 93 insertions(+), 34 deletions(-) diff --git a/static/js/shop/shop_store.js b/static/js/shop/shop_store.js index d02e9fd..14d9cce 100644 --- a/static/js/shop/shop_store.js +++ b/static/js/shop/shop_store.js @@ -480,7 +480,7 @@ const useCart = ((set, get) => ({ let itemsCopy = Array.from(crate.items); const disabled = !!get().crateParams(crate.crate_mode).warnings_disabled; itemsCopy = FillResources(itemsCopy, disabled); - itemsCopy = TriggerWarnings(itemsCopy, disabled); + itemsCopy = TriggerWarnings(itemsCopy, disabled, crate); const [crate_warnings, occupied] = TriggerCrateWarnings(crate); return { ...crate, diff --git a/static/js/shop/warnings.js b/static/js/shop/warnings.js index 7562c23..010c60a 100644 --- a/static/js/shop/warnings.js +++ b/static/js/shop/warnings.js @@ -30,14 +30,14 @@ const find_next_source_index = (data, index, source) => { } const not_enough_resource_trigger = (name) => { - return (_data, _index, counters) => { + return (_data, _index, counters, _crate) => { const resource = find_in_counters(counters, name); return resource.occupied > resource.max; } } const no_source_trigger = (name) => { - return (data, index, _counters) => { + return (data, index, _counters, _crate) => { const occupied = item_occupied_counters[name](data[index]); if (occupied > 0) return !find_previous_source(data, index, name); @@ -46,12 +46,20 @@ const no_source_trigger = (name) => { } const wiring_constraint = (name) => { - return (data, index, _counters) => { + return (data, index, _counters, _crate) => { const next = find_next_source_index(data, index, name); 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 = { "eem_resource": { level: "warning", @@ -88,22 +96,27 @@ const Types = { 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." }, + "phaser_next_card_long": { + level: "reminder", + trigger: phaser_next_card_long, + message: "Next card may interfere with this Phaser. Consider placing a short card after this Phaser." + }, "default": { level: "warning", - trigger: (_a, _b, _c) => { + trigger: (_a, _b, _c, _d) => { return true; }, message: 'This item has unimplemented warning' } } -export function TriggerWarnings(data, disabled) { +export function TriggerWarnings(data, disabled, crate) { return data.map((element, index) => { if (!element.warnings) return element; element.show_warnings = disabled ? [] :element.warnings .map((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 return Types.default; }) @@ -143,6 +156,22 @@ const crate_warnings = { const nbrHPDesktop = useShopStore.getState().crate_modes.desktop.hp; return crate.crate_mode === useShopStore.getState().crate_modes.rack.id && occupied < nbrHPDesktop; } + }, + "phaser_not_fit": { + message: "Since one or more Phasers may interfere with their next cards, they may additional space, that wouldn't fit into the crate. Consider removing cards, placing short cards after Phaser(s), or choosing larger crate.", + level: "warning", + trigger: (crate, occupied) => { + const nbrHP = useShopStore.getState().crateParams(crate.crate_mode).hp; + const stacked_phasers = crate.items.filter((elem, index, data) => { + console.log(elem, index) + 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; + console.log(stacked_phasers, occupied) + return stacked_phasers > 0 && (occupied + stacked_phasers*2 >= nbrHP) && nbrHP >0; + } } } diff --git a/static/js/shop_data.js b/static/js/shop_data.js index 3e90801..e181f0c 100644 --- a/static/js/shop_data.js +++ b/static/js/shop_data.js @@ -221,7 +221,8 @@ const shop_data = { "eem_wiring_constraint" ], consumes: { - hp: 8 + hp: 8, + depth: 20 } }, 'kaslisoc': { @@ -297,7 +298,8 @@ const shop_data = { "eem_wiring_constraint" ], consumes: { - hp: 8 + hp: 8, + depth: 20 } }, 'vhdcicarrier': { @@ -322,7 +324,8 @@ const shop_data = { "eem_wiring_constraint" ], consumes: { - hp: 8 + hp: 8, + depth: 16 } }, 'bnc-dio': { @@ -393,7 +396,8 @@ const shop_data = { ], consumes: { hp: 8, - eem: 1 + eem: 1, + depth: 7 } }, 'sma-dio': { @@ -458,7 +462,8 @@ const shop_data = { ], consumes: { hp: 4, - eem: 1 + eem: 1, + depth: 7 } }, 'mcx-dio': { @@ -549,7 +554,8 @@ const shop_data = { ], consumes: { hp: 4, - eem: 2 + eem: 2, + depth: 23 } }, 'rj45-dio': { @@ -635,7 +641,8 @@ const shop_data = { ], consumes: { hp: 4, - eem: 2 + eem: 2, + depth: 7 } }, 'urukul': { @@ -700,7 +707,8 @@ const shop_data = { consumes: { hp: 4, eem: 2, - clk: 1 + clk: 1, + depth: 16 } }, 'urukul_4412': { @@ -738,7 +746,8 @@ const shop_data = { consumes: { hp: 4, eem: 2, - clk: 1 + clk: 1, + depth: 16 } }, 'phaser': { @@ -767,12 +776,14 @@ const shop_data = { size: 'small', warnings: [ "no_eem_source", - "no_clk_source" + "no_clk_source", + "phaser_next_card_long" ], consumes: { hp: 4, eem: 1, - clk: 1 + clk: 1, + depth: 16 // heatsink 8.5 } }, 'zotino': { @@ -814,7 +825,8 @@ const shop_data = { consumes: { hp: 4, eem: 1, - tec: 1 + tec: 1, + depth: 16 }, resources: [ {name: "idc", max: 4} @@ -842,7 +854,8 @@ const shop_data = { ], consumes: { hp: 4, - eem: 1 + eem: 1, + depth: 17 }, resources: [ {name: "idc", max: 4} @@ -866,7 +879,8 @@ const shop_data = { ], consumes: { hp: 8, - idc: 1 + idc: 1, + depth: 6 } }, 'hvamp32': { @@ -903,7 +917,8 @@ const shop_data = { ], consumes: { hp: 4, - idc: 4 + idc: 4, + depth: 16 } }, 'idc-sma-adapter': { @@ -924,7 +939,8 @@ const shop_data = { ], consumes: { hp: 4, - idc: 1 + idc: 1, + depth: 6 } }, 'hd68-idc-adapter': { @@ -946,7 +962,8 @@ const shop_data = { "idc_resource" ], consumes: { - hp: 4 + hp: 4, + depth: 5 }, resources: [ {name: "idc", max: 4} @@ -999,7 +1016,8 @@ const shop_data = { ], consumes: { hp: 8, - eem: 2 + eem: 2, + depth: 16 } }, 'koster': { @@ -1025,7 +1043,8 @@ const shop_data = { ], consumes: { hp: 4, - eem: 2 + eem: 2, + depth: 7.5 } }, 'clocker': { @@ -1056,7 +1075,8 @@ const shop_data = { consumes: { hp: 4, eem: 1, - clk: 1 + clk: 1, + depth: 7 }, resources: [ {name: "clk", max: 6} @@ -1093,7 +1113,8 @@ const shop_data = { ], consumes: { hp: 4, - eem: 1 + eem: 1, + depth: 16 }, }, 'fast_servo': { @@ -1127,7 +1148,8 @@ const shop_data = { ], consumes: { hp: 4, - eem: 1 + eem: 1, + depth: 16 }, }, 'mirny': { @@ -1158,7 +1180,8 @@ const shop_data = { consumes: { hp: 4, eem: 1, - clk: 1 + clk: 1, + depth: 16 }, }, 'almazny': { @@ -1186,7 +1209,8 @@ const shop_data = { consumes: { hp: 8, eem: 1, - clk: 1 + clk: 1, + depth: 16 }, }, 'thermostat-eem': { @@ -1214,6 +1238,7 @@ const shop_data = { consumes: { hp: 4, eem: 1, + depth: 16 } }, 'thermostat2ch': { @@ -1232,7 +1257,8 @@ const shop_data = { ], size: 'small', consumes: { - hp: 4 + hp: 4, + depth: 12 }, resources: [ {name: "tec", max: 2} @@ -1261,7 +1287,8 @@ const shop_data = { consumes: { hp: 8, eem: 1, - clk: 1 + clk: 1, + depth: 8 }, }, 'pounder': { @@ -1295,7 +1322,8 @@ const shop_data = { consumes: { hp: 8, eem: 1, - clk: 1 + clk: 1, + depth: 16 } }, 'eem_pwr_mod': { @@ -1320,6 +1348,7 @@ const shop_data = { warnings: [], consumes: { hp: 8, + depth: 20 }, }, 'kirdy': { @@ -1351,6 +1380,7 @@ const shop_data = { warnings: [], consumes: { hp: 8, + depth: 16 }, }, }, -- 2.44.1 From cc89d0b1fd61740e2c6dd8105d0568fddc3b07c9 Mon Sep 17 00:00:00 2001 From: Egor Savkin Date: Thu, 5 Sep 2024 11:52:53 +0800 Subject: [PATCH 2/2] Update bundle and remove debug messages from production build Signed-off-by: Egor Savkin --- static/js/shop.bundle.js | 2 +- static/js/shop/warnings.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/static/js/shop.bundle.js b/static/js/shop.bundle.js index 392d6b4..f30c322 100644 --- a/static/js/shop.bundle.js +++ b/static/js/shop.bundle.js @@ -1,2 +1,2 @@ /*! For license information please see shop.bundle.js.LICENSE.txt */ -(()=>{var e={146:(e,t,n)=>{"use strict";var r=n(363),o={childContextTypes:!0,contextType:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromError:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},a={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},i={$$typeof:!0,compare:!0,defaultProps:!0,displayName:!0,propTypes:!0,type:!0},l={};function s(e){return r.isMemo(e)?i:l[e.$$typeof]||o}l[r.ForwardRef]={$$typeof:!0,render:!0,defaultProps:!0,displayName:!0,propTypes:!0},l[r.Memo]=i;var c=Object.defineProperty,u=Object.getOwnPropertyNames,d=Object.getOwnPropertySymbols,p=Object.getOwnPropertyDescriptor,f=Object.getPrototypeOf,m=Object.prototype;e.exports=function e(t,n,r){if("string"!=typeof n){if(m){var o=f(n);o&&o!==m&&e(t,o,r)}var i=u(n);d&&(i=i.concat(d(n)));for(var l=s(t),g=s(n),h=0;h{"use strict";e.exports=function(e,t,n,r,o,a,i,l){if(!e){var s;if(void 0===t)s=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[n,r,o,a,i,l],u=0;(s=new Error(t.replace(/%s/g,(function(){return c[u++]})))).name="Invariant Violation"}throw s.framesToPop=1,s}}},678:function(e,t,n){var r,o;r=function(){"use strict";Array.isArray||(Array.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)});var e={},t={"==":function(e,t){return e==t},"===":function(e,t){return e===t},"!=":function(e,t){return e!=t},"!==":function(e,t){return e!==t},">":function(e,t){return e>t},">=":function(e,t){return e>=t},"<":function(e,t,n){return void 0===n?e=t?[]:r}};return e.is_logic=function(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)&&1===Object.keys(e).length},e.truthy=function(e){return!(Array.isArray(e)&&0===e.length||!e)},e.get_operator=function(e){return Object.keys(e)[0]},e.get_values=function(t){return t[e.get_operator(t)]},e.apply=function(n,r){if(Array.isArray(n))return n.map((function(t){return e.apply(t,r)}));if(!e.is_logic(n))return n;var o,a,i,l,s,c=e.get_operator(n),u=n[c];if(Array.isArray(u)||(u=[u]),"if"===c||"?:"==c){for(o=0;o0){var d=String(c).split("."),p=t;for(o=0;o{"use strict";var r=n(925);function o(){}function a(){}a.resetWarningCache=o,e.exports=function(){function e(e,t,n,o,a,i){if(i!==r){var l=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw l.name="Invariant Violation",l}}function t(){return e}e.isRequired=e;var n={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:a,resetWarningCache:o};return n.PropTypes=n,n}},556:(e,t,n)=>{e.exports=n(694)()},925:e=>{"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},551:(e,t,n)=>{"use strict";var r=n(540),o=n(982);function a(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,n=1;n