display refactoring

This commit is contained in:
azykov@mail.ru
2026-09-03 11:52:44 +03:00
parent 51f9d44378
commit 557d22517a
10 changed files with 196 additions and 73 deletions
+17 -1
View File
@@ -11,7 +11,8 @@
"break_eternity.js": "^2.1.3", "break_eternity.js": "^2.1.3",
"elkjs": "^0.12.0", "elkjs": "^0.12.0",
"react": "^18.3.1", "react": "^18.3.1",
"react-dom": "^18.3.1" "react-dom": "^18.3.1",
"yaml": "^2.9.0"
}, },
"devDependencies": { "devDependencies": {
"@types/react": "^18.3.12", "@types/react": "^18.3.12",
@@ -1759,6 +1760,21 @@
"integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==", "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==",
"dev": true, "dev": true,
"license": "ISC" "license": "ISC"
},
"node_modules/yaml": {
"version": "2.9.0",
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.0.tgz",
"integrity": "sha512-2AvhNX3mb8zd6Zy7INTtSpl1F15HW6Wnqj0srWlkKLcpYl/gMIMJiyuGq2KeI2YFxUPjdlB+3Lc10seMLtL4cA==",
"license": "ISC",
"bin": {
"yaml": "bin.mjs"
},
"engines": {
"node": ">= 14.6"
},
"funding": {
"url": "https://github.com/sponsors/eemeli"
}
} }
} }
} }
+2 -1
View File
@@ -12,7 +12,8 @@
"break_eternity.js": "^2.1.3", "break_eternity.js": "^2.1.3",
"elkjs": "^0.12.0", "elkjs": "^0.12.0",
"react": "^18.3.1", "react": "^18.3.1",
"react-dom": "^18.3.1" "react-dom": "^18.3.1",
"yaml": "^2.9.0"
}, },
"devDependencies": { "devDependencies": {
"@types/react": "^18.3.12", "@types/react": "^18.3.12",
+6 -6
View File
@@ -6,6 +6,8 @@ import { Game } from '../engine/game';
import { ConverterCardInfo } from './ConverterCardInfo'; import { ConverterCardInfo } from './ConverterCardInfo';
import { Converter } from '../engine/behaviours/converter'; import { Converter } from '../engine/behaviours/converter';
import { Behaviour } from '../engine/behaviours/base'; import { Behaviour } from '../engine/behaviours/base';
import * as yaml from 'yaml';
interface Props { interface Props {
game: Game; game: Game;
@@ -71,15 +73,13 @@ export const BehaviourCard = forwardRef<HTMLDivElement, Props>(function NodeCard
</div> </div>
)) ))
} }
<div className="unit__links"> {/* <div className="unit__links">
{ {info.links.map((link) => <div key={`${link.target}/${link.resource}`}>→{link.target}/{link.resource}</div>)}
info.links.map((link) => <div key={`${link.target}/${link.resource}`}>→{link.target}/{link.resource}</div>) </div> */}
}
</div>
{ {
behaviour.kind === 'converter' && <ConverterCardInfo converter={behaviour as Converter} /> behaviour.kind === 'converter' && <ConverterCardInfo converter={behaviour as Converter} />
} }
<div className="unit__debug" style={{ fontSize: '8px', whiteSpace: 'pre' }}>{JSON.stringify(info.raw, undefined, 4)}</div> <div className="unit__debug" style={{ fontSize: '75%', whiteSpace: 'pre' }}>{yaml.stringify(info.raw, undefined, 4)}</div>
</div> </div>
); );
}); });
+1 -1
View File
@@ -7,7 +7,7 @@ type Props = {
export const ConverterCardInfo = function ({ converter }: Props) { export const ConverterCardInfo = function ({ converter }: Props) {
return <> return <>
<div className="unit__converter__progress"> <div className="unit__converter__progress">
<div className="unit__converter__progress_bar" style={{ width: `${converter.cycleTime.div(converter.cycleLength).toFixed(2)}%` }} /> <div className="unit__converter__progress_bar" style={{ width: `${converter.cycleTime.div(converter.cycleLength).mul(100).toFixed(2)}%` }} />
<div className="unit__converter__progress_info">{converter.cycleTime.toFixed(4)} of {converter.cycleLength.toFixed(4)}</div> <div className="unit__converter__progress_info">{converter.cycleTime.toFixed(4)} of {converter.cycleLength.toFixed(4)}</div>
</div> </div>
</> </>
-2
View File
@@ -95,8 +95,6 @@ export class Converter extends Behaviour {
return { return {
...info, ...info,
raw: { raw: {
cycleTime: this.cycleTime,
cycleLength: this.cycleLength,
inputRates: this.inputRates, inputRates: this.inputRates,
outputRates: this.outputRates, outputRates: this.outputRates,
}, },
+154 -46
View File
@@ -1,5 +1,3 @@
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');
:root { :root {
--bg: #201f1c; --bg: #201f1c;
--panel: #29271f; --panel: #29271f;
@@ -18,14 +16,19 @@
--display: 'Space Grotesk', ui-sans-serif, sans-serif; --display: 'Space Grotesk', ui-sans-serif, sans-serif;
} }
* { box-sizing: border-box; } * {
box-sizing: border-box;
}
html, body, #root { html,
body,
#root {
margin: 0; margin: 0;
height: 100%; height: 100%;
background: var(--bg); background: var(--bg);
color: var(--ink); color: var(--ink);
font-family: var(--mono); font-family: var(--mono);
font-size: 10pt;
} }
#app { #app {
@@ -49,7 +52,7 @@ html, body, #root {
.topbar__title { .topbar__title {
font-family: var(--display); font-family: var(--display);
font-weight: 700; font-weight: 700;
font-size: 15px; font-size: 150%;
letter-spacing: 0.06em; letter-spacing: 0.06em;
text-transform: uppercase; text-transform: uppercase;
color: var(--ink); color: var(--ink);
@@ -62,7 +65,6 @@ html, body, #root {
display: block; display: block;
font-family: var(--mono); font-family: var(--mono);
font-weight: 400; font-weight: 400;
font-size: 10px;
letter-spacing: 0.04em; letter-spacing: 0.04em;
color: var(--ink-dim); color: var(--ink-dim);
text-transform: none; text-transform: none;
@@ -71,23 +73,23 @@ html, body, #root {
.tick-counter { .tick-counter {
font-family: var(--mono); font-family: var(--mono);
font-size: 12px;
color: var(--ink-dim); color: var(--ink-dim);
background: var(--panel-2); background: var(--panel-2);
border: 1px solid var(--line); border: 1px solid var(--line);
padding: 6px 12px; padding: 6px 12px;
border-radius: 3px; border-radius: 3px;
} }
.tick-counter b { .tick-counter b {
color: var(--accent-converter); color: var(--accent-converter);
font-size: 14px;
} }
.spacer { flex: 1; } .spacer {
flex: 1;
}
.btn { .btn {
font-family: var(--mono); font-family: var(--mono);
font-size: 12px;
font-weight: 500; font-weight: 500;
letter-spacing: 0.03em; letter-spacing: 0.03em;
border: 1px solid var(--line); border: 1px solid var(--line);
@@ -98,9 +100,19 @@ html, body, #root {
cursor: pointer; cursor: pointer;
transition: border-color 0.12s, transform 0.05s; transition: border-color 0.12s, transform 0.05s;
} }
.btn:hover { border-color: var(--ink-dim); }
.btn:active { transform: translateY(1px); } .btn:hover {
.btn:focus-visible { outline: 2px solid var(--accent-converter); outline-offset: 2px; } border-color: var(--ink-dim);
}
.btn:active {
transform: translateY(1px);
}
.btn:focus-visible {
outline: 2px solid var(--accent-converter);
outline-offset: 2px;
}
.btn--primary { .btn--primary {
background: var(--accent-converter); background: var(--accent-converter);
@@ -108,7 +120,10 @@ html, body, #root {
color: #201f1c; color: #201f1c;
font-weight: 600; font-weight: 600;
} }
.btn--primary:hover { border-color: #f0c169; }
.btn--primary:hover {
border-color: #f0c169;
}
.btn--danger { .btn--danger {
background: transparent; background: transparent;
@@ -117,7 +132,10 @@ html, body, #root {
margin-top: 14px; margin-top: 14px;
width: 100%; width: 100%;
} }
.btn--danger:hover { background: rgba(193, 90, 78, 0.12); }
.btn--danger:hover {
background: rgba(193, 90, 78, 0.12);
}
.btn--ghost { .btn--ghost {
background: transparent; background: transparent;
@@ -129,12 +147,10 @@ html, body, #root {
.btn--icon { .btn--icon {
padding: 4px 8px; padding: 4px 8px;
font-size: 11px;
} }
select { select {
font-family: var(--mono); font-family: var(--mono);
font-size: 12px;
background: var(--panel-2); background: var(--panel-2);
color: var(--ink); color: var(--ink);
border: 1px solid var(--line); border: 1px solid var(--line);
@@ -169,14 +185,18 @@ select {
height: 900px; height: 900px;
} }
#world > svg { #world>svg {
position: absolute; position: absolute;
top: 0; left: 0; top: 0;
left: 0;
width: 1600px; width: 1600px;
height: 900px; height: 900px;
pointer-events: none; pointer-events: none;
} }
#world > svg line { pointer-events: stroke; }
#world>svg line {
pointer-events: stroke;
}
.node { .node {
position: absolute; position: absolute;
@@ -184,28 +204,45 @@ select {
border: 1px solid var(--line); border: 1px solid var(--line);
border-left: 4px solid var(--accent-storage); border-left: 4px solid var(--accent-storage);
border-radius: 4px; border-radius: 4px;
padding: 8px 10px; padding: 0.25em 0.5em;
cursor: grab; cursor: grab;
user-select: none; user-select: none;
box-shadow: 0 2px 6px rgba(0,0,0,0.35); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
touch-action: none; touch-action: none;
display: flex;
flex-direction: column;
gap: 0.25em;
} }
.node:active { cursor: grabbing; }
.node:active {
cursor: grabbing;
}
.node.is-selected { .node.is-selected {
border-left-width: 4px; border-left-width: 4px;
outline: 1.5px dashed var(--ink); outline: 1.5px dashed var(--ink);
outline-offset: 3px; outline-offset: 3px;
} }
.node--source { border-left-color: var(--accent-source); } .node--source {
.node--storage { border-left-color: var(--accent-storage); } border-left-color: var(--accent-source);
.node--converter { border-left-color: var(--accent-converter); } }
.node--consumer { border-left-color: var(--accent-consumer); }
.node--storage {
border-left-color: var(--accent-storage);
}
.node--converter {
border-left-color: var(--accent-converter);
}
.node--consumer {
border-left-color: var(--accent-consumer);
}
.unit__id { .unit__id {
font-family: var(--display); font-family: var(--display);
font-weight: 200; font-weight: 200;
font-size: 10px;
color: var(--ink); color: var(--ink);
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
@@ -215,7 +252,7 @@ select {
.unit__title { .unit__title {
font-family: var(--display); font-family: var(--display);
font-weight: 600; font-weight: 600;
font-size: 12.5px; font-size: 125%;
color: var(--ink); color: var(--ink);
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
@@ -223,15 +260,12 @@ select {
} }
.unit__kind { .unit__kind {
font-size: 9px;
letter-spacing: 0.05em; letter-spacing: 0.05em;
text-transform: uppercase; text-transform: uppercase;
color: var(--ink-dim); color: var(--ink-dim);
margin: 2px 0 6px;
} }
.unit__resources { .unit__resources {
font-size: 11px;
background: #171613; background: #171613;
border: 1px solid var(--line); border: 1px solid var(--line);
border-radius: 3px; border-radius: 3px;
@@ -241,7 +275,6 @@ select {
} }
.unit__links { .unit__links {
font-size: 11px;
background: #171613; background: #171613;
border: 1px solid var(--line); border: 1px solid var(--line);
border-radius: 3px; border-radius: 3px;
@@ -250,6 +283,37 @@ select {
white-space: nowrap; white-space: nowrap;
} }
.unit__converter__progress {
font-size: 75%;
background: #171613;
border: 1px solid var(--line);
border-radius: 3px;
padding: 1px 6px;
letter-spacing: 0.02em;
white-space: nowrap;
position: relative;
overflow: hidden;
min-height: 10px;
display: flex;
align-items: center;
justify-content: center;
}
.unit__converter__progress_bar {
position: absolute;
inset: 0;
z-index: 1;
background: linear-gradient(90deg, var(--accent-converter), #f0c169);
opacity: 0.3;
transition: width 0.15s ease-out;
}
.unit__converter__progress_info {
position: relative;
z-index: 2;
color: var(--ink);
}
.unit__sockets { .unit__sockets {
position: absolute; position: absolute;
top: 0; top: 0;
@@ -260,8 +324,14 @@ select {
justify-content: center; justify-content: center;
gap: 6px; gap: 6px;
} }
.unit__sockets--input { left: -5px; }
.unit__sockets--output { right: -5px; } .unit__sockets--input {
left: -5px;
}
.unit__sockets--output {
right: -5px;
}
.unit__socket { .unit__socket {
width: 10px; width: 10px;
@@ -287,6 +357,7 @@ select {
padding: 14px 16px; padding: 14px 16px;
border-bottom: 1px solid var(--line); border-bottom: 1px solid var(--line);
} }
.sidebar__section--grow { .sidebar__section--grow {
flex: 1; flex: 1;
border-bottom: none; border-bottom: none;
@@ -308,6 +379,7 @@ select {
max-height: 140px; max-height: 140px;
overflow-y: auto; overflow-y: auto;
} }
.sidebar__list li { .sidebar__list li {
padding: 6px 8px; padding: 6px 8px;
font-size: 11.5px; font-size: 11.5px;
@@ -318,8 +390,16 @@ select {
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
} }
.sidebar__list li:hover { background: var(--panel-2); color: var(--ink); }
.sidebar__list li.is-active { background: var(--panel-2); color: var(--accent-converter); } .sidebar__list li:hover {
background: var(--panel-2);
color: var(--ink);
}
.sidebar__list li.is-active {
background: var(--panel-2);
color: var(--accent-converter);
}
#sidebar-content { #sidebar-content {
padding: 16px 0 0; padding: 16px 0 0;
@@ -349,7 +429,9 @@ select {
font-size: 11px; font-size: 11px;
color: var(--ink-dim); color: var(--ink-dim);
} }
.field input, .field select {
.field input,
.field select {
font-family: var(--mono); font-family: var(--mono);
font-size: 12px; font-size: 12px;
background: var(--panel-2); background: var(--panel-2);
@@ -359,13 +441,21 @@ select {
padding: 7px 9px; padding: 7px 9px;
width: 100%; width: 100%;
} }
.field input:focus-visible, .field select:focus-visible {
.field input:focus-visible,
.field select:focus-visible {
outline: 2px solid var(--accent-converter); outline: 2px solid var(--accent-converter);
outline-offset: 1px; outline-offset: 1px;
} }
.coord-row { display: flex; gap: 8px; } .coord-row {
.coord-row input { width: 50%; } display: flex;
gap: 8px;
}
.coord-row input {
width: 50%;
}
.recipe-box { .recipe-box {
border: 1px solid var(--line); border: 1px solid var(--line);
@@ -374,6 +464,7 @@ select {
margin-bottom: 12px; margin-bottom: 12px;
background: var(--panel-2); background: var(--panel-2);
} }
.recipe-box__title { .recipe-box__title {
font-size: 10.5px; font-size: 10.5px;
text-transform: uppercase; text-transform: uppercase;
@@ -381,15 +472,32 @@ select {
color: var(--ink-dim); color: var(--ink-dim);
margin-bottom: 8px; margin-bottom: 8px;
} }
.recipe-row { .recipe-row {
display: flex; display: flex;
gap: 6px; gap: 6px;
margin-bottom: 6px; margin-bottom: 6px;
align-items: center; align-items: center;
} }
.recipe-row select { flex: 1.4; }
.recipe-row input { flex: 1; }
::-webkit-scrollbar { width: 9px; height: 9px; } .recipe-row select {
::-webkit-scrollbar-track { background: var(--bg); } flex: 1.4;
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; } }
.recipe-row input {
flex: 1;
}
::-webkit-scrollbar {
width: 9px;
height: 9px;
}
::-webkit-scrollbar-track {
background: var(--bg);
}
::-webkit-scrollbar-thumb {
background: var(--line);
border-radius: 5px;
}
+10 -10
View File
@@ -15,7 +15,7 @@ export const defaultGame: () => SerializedGame = () => ({
outputs: { outputs: {
pins: [ pins: [
{ {
resource: 'wood', resource: 'tree',
}, },
{ {
resource: 'stone', resource: 'stone',
@@ -24,7 +24,7 @@ export const defaultGame: () => SerializedGame = () => ({
}, },
rules: { rules: {
cycleLength: 1, cycleLength: 1,
outputRates: { wood: 1, stone: 0.1 }, outputRates: { tree: 1, stone: 0.1 },
} }
}, },
}, },
@@ -37,22 +37,22 @@ export const defaultGame: () => SerializedGame = () => ({
inputs: { inputs: {
pins: [ pins: [
{ {
resource: 'wood', resource: 'tree',
link: { target: 'forest.1', resource: 'wood' }, link: { target: 'forest.1', resource: 'tree' },
}, },
] ]
}, },
outputs: { outputs: {
pins: [ pins: [
{ {
resource: 'plank', resource: 'wood',
}, },
], ],
}, },
rules: { rules: {
cycleLength: 1.8, cycleLength: 1.8,
inputRates: { wood: 1 }, inputRates: { tree: 1 },
outputRates: { plank: 2 }, outputRates: { wood: 2 },
}, },
}, },
}, },
@@ -65,8 +65,8 @@ export const defaultGame: () => SerializedGame = () => ({
inputs: { inputs: {
pins: [ pins: [
{ {
resource: 'plank', resource: 'wood',
link: { target: 'sawmill.1', resource: 'plank' }, link: { target: 'sawmill.1', resource: 'wood' },
}, },
], ],
}, },
@@ -75,7 +75,7 @@ export const defaultGame: () => SerializedGame = () => ({
}, },
rules: { rules: {
cycleLength: 1, cycleLength: 1,
inputRates: { plank: 1 }, inputRates: { wood: 1 },
}, },
}, },
}, },
+1 -1
View File
@@ -1,5 +1,5 @@
import Decimal from "break_eternity.js"; import Decimal from "break_eternity.js";
export type Resource = 'wood' | 'plank' | 'stone'; export type Resource = 'tree' | 'wood' | 'stone';
export type Resources = Record<Resource, Decimal>; export type Resources = Record<Resource, Decimal>;
+3 -3
View File
@@ -4,8 +4,8 @@ import { Behaviour } from "../engine/behaviours/base";
const elk = new ELK(); const elk = new ELK();
const UNIT_WIDTH = 100; const UNIT_WIDTH = 200;
const NODE_HEIGHT = 90; const NODE_HEIGHT = 150;
export type GraphNode = { export type GraphNode = {
position: { x: number, y: number }; position: { x: number, y: number };
@@ -21,7 +21,7 @@ export async function build2dNodes(units: Unit[], area: { width: number, height:
layoutOptions: { layoutOptions: {
"elk.algorithm": "layered", "elk.algorithm": "layered",
"elk.direction": "LEFT", "elk.direction": "LEFT",
"elk.spacing.nodeNode": "60", "elk.spacing.nodeNode": "100",
"elk.layered.spacing.nodeNodeBetweenLayers": "100", "elk.layered.spacing.nodeNodeBetweenLayers": "100",
}, },
children: units.map((unit) => ({ children: units.map((unit) => ({
+2 -2
View File
@@ -8,8 +8,8 @@ export type ResourceDescription = {
} }
export const ResourceDescriptions: Record<ResourceDescription['id'], ResourceDescription> = { export const ResourceDescriptions: Record<ResourceDescription['id'], ResourceDescription> = {
wood: { id: 'wood', label: 'Дерево', color: '#b98249', icon: '🌲' }, tree: { id: 'tree', label: 'Дерево', color: '#b98249', icon: '🌲' },
plank: { id: 'plank', label: 'Доска', color: '#c9c209', icon: 'P' }, wood: { id: 'wood', label: 'Бревно', color: '#c9c209', icon: '🪵' },
// iron: { id: 'iron', label: 'Железо', color: '#9aa7b0', icon: '⛓' }, // iron: { id: 'iron', label: 'Железо', color: '#9aa7b0', icon: '⛓' },
stone: { id: 'stone', label: 'Камень', color: '#8a8a8a', icon: '🪨' }, stone: { id: 'stone', label: 'Камень', color: '#8a8a8a', icon: '🪨' },
// gold: { id: 'gold', label: 'Золото', color: '#d9b64e', icon: '💰' }, // gold: { id: 'gold', label: 'Золото', color: '#d9b64e', icon: '💰' },