Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into upload-from-ms
Browse files Browse the repository at this point in the history
  • Loading branch information
Roundabout1 committed Mar 5, 2025
2 parents 0d3b5c0 + e32cbe2 commit db19827
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 106 deletions.
4 changes: 2 additions & 2 deletions resources/platform/tjc-ms1-mtrx-a2-1.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@
},
{
"name": "pattern",
"type": "Matrix5",
"type": "Matrix5x1",
"description": "Паттерн, который будет применен к строке на матрице."
},
{
Expand All @@ -287,7 +287,7 @@
},
{
"name": "pattern",
"type": "Matrix5",
"type": "Matrix1x5",
"description": "Паттерн, который будет применен к столбцу на матрице."
},
{
Expand Down
4 changes: 2 additions & 2 deletions resources/platform/tjc-ms1-mtrx-a3-1.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@
},
{
"name": "pattern",
"type": "Matrix5",
"type": "Matrix5x1",
"description": "Паттерн, который будет применен к строке на матрице."
},
{
Expand All @@ -287,7 +287,7 @@
},
{
"name": "pattern",
"type": "Matrix5",
"type": "Matrix1x5",
"description": "Паттерн, который будет применен к столбцу на матрице."
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,10 @@ export const ActionsModal: React.FC<ActionsModalProps> = ({

const platform = controller.platform[smId];
if (
!protoParameters.every((proto) => {
!protoParameters.every((proto, idx) => {
const { name, type = '' } = proto;
const value = parameters[name] ?? '';
const parameter = parameters[name] ?? { value: '', order: idx };
const value = parameter.value;
if (Array.isArray(value)) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,22 @@ export const ActionsModalParameters: React.FC<ActionsModalParametersProps> = ({
smId,
controller,
}) => {
const handleInputChange = (name: string, value: string | Variable) => {
const handleInputChange = (name: string, order: number, value: string | Variable) => {
setErrors((p) => ({ ...p, [name]: '' }));
parameters[name] = value;
if (parameters[name]) {
parameters[name].value = value;
} else {
parameters[name] = { value, order };
}
setParameters({ ...parameters });
};

const handleComponentAttributeChange = (name: string, component: string, attribute: string) => {
const handleComponentAttributeChange = (
name: string,
order: number,
component: string,
attribute: string
) => {
let inputValue: string | Variable = '';
if (component || attribute) {
inputValue = {
Expand All @@ -62,13 +71,13 @@ export const ActionsModalParameters: React.FC<ActionsModalParametersProps> = ({
// proto?.singletone || platform.staticComponents ? platform.staticActionDelimeter : '.';
// inputValue = `${component}${delimiter}${attribute}`;
}
handleInputChange(name, inputValue);
handleInputChange(name, order, inputValue);
};

const [isChecked, setIsChecked] = useState<Map<string, boolean>>(new Map());

const onChange = (parameter: string, row: number, col: number, value: number) => {
(parameters[parameter] as number[][])[row][col] = value;
(parameters[parameter].value as number[][])[row][col] = value;
setParameters({
...parameters,
});
Expand All @@ -90,9 +99,10 @@ export const ActionsModalParameters: React.FC<ActionsModalParametersProps> = ({
return (
<div className="flex flex-col gap-2">
<h3 className="mb-1 text-xl">Параметры:</h3>
{protoParameters.map((proto) => {
{protoParameters.map((proto, idx) => {
const { name, description = '', type = '' } = proto;
const value = parameters[name] ?? '';
const parameter = parameters[name] ?? { value: '', order: idx };
const value = parameter.value;
const error = errors[name];
const hint =
description + (type && `${description ? '\n' : ''}Тип: ${formatArgType(type)}`);
Expand All @@ -105,7 +115,7 @@ export const ActionsModalParameters: React.FC<ActionsModalParametersProps> = ({
className="w-[300px] pl-[50px]"
options={options}
value={options.find((o) => o.value === value)}
onChange={(opt) => handleInputChange(name, opt?.value ?? '')}
onChange={(opt) => handleInputChange(name, idx, opt?.value ?? '')}
/>
</ComponentFormFieldLabel>
);
Expand All @@ -114,7 +124,10 @@ export const ActionsModalParameters: React.FC<ActionsModalParametersProps> = ({
const { width, height } = getMatrixDimensions(type);
if (!value) {
const newMatrix = createEmptyMatrix(type);
parameters[name] = newMatrix.values;
parameters[name] = {
value: newMatrix.values,
order: idx,
};
}
if (Array.isArray(value) && Array.isArray(value[0])) {
return (
Expand All @@ -131,7 +144,7 @@ export const ActionsModalParameters: React.FC<ActionsModalParametersProps> = ({
{...{
width: width,
height: height,
values: parameters[name] as number[][],
values: parameters[name].value as number[][],
isClickable: true,
style: {
ledHeight: 16,
Expand Down Expand Up @@ -174,7 +187,7 @@ export const ActionsModalParameters: React.FC<ActionsModalParametersProps> = ({
checked={currentChecked}
onCheckedChange={() => {
setCheckedTo(name, !currentChecked);
handleInputChange(name, '');
handleInputChange(name, idx, '');
}}
/>
</div>
Expand All @@ -199,7 +212,9 @@ export const ActionsModalParameters: React.FC<ActionsModalParametersProps> = ({
<Select
containerClassName="w-[250px]"
options={componentOptions}
onChange={(opt) => handleComponentAttributeChange(name, opt?.value ?? '', '')}
onChange={(opt) =>
handleComponentAttributeChange(name, idx, opt?.value ?? '', '')
}
value={
componentOptions.find((o) => o.value === selectedParameterComponent) ?? null
}
Expand All @@ -213,6 +228,7 @@ export const ActionsModalParameters: React.FC<ActionsModalParametersProps> = ({
onChange={(opt) =>
handleComponentAttributeChange(
name,
idx,
selectedParameterComponent ?? '',
opt?.value ?? ''
)
Expand All @@ -235,7 +251,7 @@ export const ActionsModalParameters: React.FC<ActionsModalParametersProps> = ({
value={value as string}
name={name}
placeholder="Введите значение..."
onChange={(e) => handleInputChange(name, e.target.value)}
onChange={(e) => handleInputChange(name, idx, e.target.value)}
/>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const MatrixLed: React.FC<MatrixLedProps> = ({
width: ledWidth * 4,
}}
className={twMerge(
`border-1 border-border-contrast`,
'border-2 border-border-primary',
value === 0 && 'bg-matrix-inactive',
value >= 1 && 'bg-matrix-active',
isRounded && 'rounded'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export const MatrixWidget: React.FC<MatrixWidgetProps> = ({
<div className="flex shrink-0 flex-col">
{values.map((rowArr, rowIndex) => {
return (
<div className="flex shrink-0 flex-row">
<div key={`div-${rowIndex}`} className="flex shrink-0 flex-row">
{rowArr.map((value, colIndex) => {
return (
<MatrixLed
key={`${rowIndex}-${colIndex}-${value}`}
key={`mtrx-${rowIndex}-${colIndex}-${value}`}
{...{
style,
isClickable,
Expand Down
93 changes: 49 additions & 44 deletions src/renderer/src/components/NodeModal/components/Action.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useMemo } from 'react';

import { twMerge } from 'tailwind-merge';

Expand Down Expand Up @@ -51,6 +51,12 @@ export const Action: React.FC<ActionProps> = (props) => {
onChange();
};

const sortedComponent = useMemo(() => {
if (!data.args) return [];

return Object.entries(data.args).sort(([, param], [, param2]) => param.order - param2.order);
}, [data.args]);

return (
<div
className={twMerge('flex gap-2 p-2 hover:bg-bg-hover', isSelected && 'bg-bg-active')}
Expand All @@ -73,51 +79,50 @@ export const Action: React.FC<ActionProps> = (props) => {
<div>{data.method}</div>
<div>(</div>
<div className="flex items-center gap-[2px]">
{data.args === undefined ||
Object.entries(data.args).map(([id, value], index) => {
const protoComponent =
platform.data.components[platform.resolveComponentType(data.component)];
if (!protoComponent) {
return <>{serializeParameter(index, value)}</>;
}
const protoMethod = protoComponent.methods[data.method];
const protoParameters = protoMethod.parameters;

if (!protoParameters) return <>{serializeParameter(index, value)}</>;

const parameter = protoParameters.find((param) => param.name === id);

if (!parameter || !parameter.type) return <>{serializeParameter(index, value)}</>;

if (typeof parameter.type === 'string' && parameter.type.startsWith('Matrix')) {
const dimensions = getMatrixDimensions(parameter.type);

if (Array.isArray(value) && typeof value[0][0] === 'number') {
return (
<>
{index !== 0 && ', '}
<MatrixWidget
key={`${smId}-${dimensions.width}-${dimensions.height}`}
width={dimensions.width}
height={dimensions.height}
values={value}
isClickable={false}
onChange={() => undefined}
style={{
ledWidth: 2,
ledHeight: 2,
margin: 0,
border: 1,
isRounded: false,
}}
/>
</>
);
}
{sortedComponent.map(([id, value], index) => {
const protoComponent =
platform.data.components[platform.resolveComponentType(data.component)];
if (!protoComponent) {
return <>{serializeParameter(index, value.value)}</>;
}
const protoMethod = protoComponent.methods[data.method];
const protoParameters = protoMethod.parameters;

if (!protoParameters) return <>{serializeParameter(index, value.value)}</>;

const parameter = protoParameters.find((param) => param.name === id);

if (!parameter || !parameter.type) return <>{serializeParameter(index, value.value)}</>;

if (typeof parameter.type === 'string' && parameter.type.startsWith('Matrix')) {
const dimensions = getMatrixDimensions(parameter.type);

if (Array.isArray(value.value) && typeof value.value[0][0] === 'number') {
return (
<>
{index !== 0 && ', '}
<MatrixWidget
key={`${smId}-${dimensions.width}-${dimensions.height}`}
width={dimensions.width}
height={dimensions.height}
values={value.value}
isClickable={false}
onChange={() => undefined}
style={{
ledWidth: 2,
ledHeight: 2,
margin: 0,
border: 1,
isRounded: false,
}}
/>
</>
);
}
}

return <>{serializeParameter(index, value)}</>;
})}
return <>{serializeParameter(index, value.value)}</>;
})}
</div>
<div>)</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/src/lib/data/EditorModel/EditorModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class EditorModel {
act.component = newComponentId;
}
for (const argId in act.args) {
const arg = act.args[argId];
const arg = act.args[argId].value;
if (typeof arg === 'string') {
arg.replace(oldComponentId, newComponentId);
} else if (isVariable(arg)) {
Expand Down Expand Up @@ -178,7 +178,7 @@ export class EditorModel {
act.component = newComponentId;
}
for (const argId in act.args) {
const arg = act.args[argId];
const arg = act.args[argId].value;
if (typeof arg === 'string') {
arg.replace(oldComponentId, newComponentId);
} else if (isVariable(arg)) {
Expand Down
Loading

0 comments on commit db19827

Please sign in to comment.