Skip to content

Commit

Permalink
Merge pull request #1393 from pau-tomas/fix/last_parallax_layer_length
Browse files Browse the repository at this point in the history
Some small fixes
  • Loading branch information
chrismaltby authored Apr 29, 2024
2 parents 5dda77e + 3c78c63 commit f76891b
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix issue where pasting a "Call Script" event could sometimes incorrectly say script has been modified if project hadn't been saved and reloaded first
- Fix issue where creating a new pattern in music editor would sometimes cause the other patterns in the song to play at a lower octave
- Fix issue where variables in Dialogue and Math inputs could appear above script tabs
- Fix calculation of last parallax layer height in editor input [@pau-tomas](https://github.com/pau-tomas)
- Fix compiler warning when using some unary operators in While loop [@pau-tomas](https://github.com/pau-tomas)

## [3.2.1] - 2024-02-27

Expand Down
10 changes: 7 additions & 3 deletions src/components/forms/ParallaxSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const updateParallaxHeight = (
return v;
});

// Calculcate new total height
// Calculate new total height
const layersHeight = newValue.reduce((memo, layer, layerIndex) => {
if (layerIndex < newValue.length - 1) {
return memo + layer.height;
Expand All @@ -154,7 +154,7 @@ const updateParallaxHeight = (
heightOverflow -= v.height - newHeight;
return {
...v,
height: newHeight,
height: i === value.length - 1 ? 0 : newHeight,
};
});
}
Expand Down Expand Up @@ -215,6 +215,10 @@ const ParallaxSelect = ({
[dispatch]
);

const lastLayerHeight = value?.reduce((memo, value) => {
return memo - value.height;
}, sceneHeight);

return (
<div>
<Select
Expand Down Expand Up @@ -242,7 +246,7 @@ const ParallaxSelect = ({
min={1}
value={
layerIndex === value.length - 1
? sceneHeight
? lastLayerHeight
: layer.height || undefined
}
placeholder="1"
Expand Down
13 changes: 11 additions & 2 deletions src/components/ui/util/HighlightWords.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,27 @@ const Wrapper = styled.span`
}
`;

const escapeRegExpString = (str: string) =>
str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");

export const HighlightWords = ({ text, words }: HighlightWordsProps) => {
if (!words.length) {
return <>{text}</>;
}

const regex = new RegExp(`(${words.join("|")})`, "gi");
const escapeWords = words.map(escapeRegExpString);

const regex = new RegExp(`(${escapeWords.join("|")})`, "gi");
const parts = text.split(regex);

return (
<Wrapper>
{parts.map((part, index) => {
if (words.some((word) => new RegExp(`\\b${word}\\b`, "i").test(part))) {
if (
escapeWords.some((word) =>
new RegExp(`\\b${word}\\b`, "i").test(part)
)
) {
return <span key={index}>{part}</span>;
}
return part;
Expand Down
9 changes: 8 additions & 1 deletion src/lib/compiler/scriptBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ type RPNHandler = {
stop: () => void;
};

const rpnUnaryOperators: ScriptBuilderRPNOperation[] = [
".ABS",
".NOT",
".B_NOT",
".ISQRT",
];

// - Helpers --------------

const isObject = (value: unknown): value is Record<string, unknown> => {
Expand Down Expand Up @@ -1267,7 +1274,7 @@ class ScriptBuilder {
},
operator: (op: ScriptBuilderRPNOperation) => {
rpnCmd(".R_OPERATOR", op);
if (op !== ".ABS") {
if (!rpnUnaryOperators.includes(op)) {
stack.pop();
}
return rpn;
Expand Down
16 changes: 16 additions & 0 deletions test/store/features/debugger/deguggerState.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import reducer, {
initialState,
DebuggerState,
} from "../../../../src/store/features/debugger/debuggerState";
import consoleActions from "../../../../src/store/features/console/consoleActions";

test("Should open the build log on any console errors", () => {
const state: DebuggerState = {
...initialState,
isLogOpen: false,
};
const action = consoleActions.stdErr("Failed to build");

const newState = reducer(state, action);
expect(newState.isLogOpen).toBe(true);
});
12 changes: 0 additions & 12 deletions test/store/features/navigation/navigationState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import reducer, {
} from "../../../../src/store/features/navigation/navigationState";
import actions from "../../../../src/store/features/navigation/navigationActions";
import entityActions from "../../../../src/store/features/entities/entitiesActions";
import consoleActions from "../../../../src/store/features/console/consoleActions";

test("Should be able to set section", () => {
const state: NavigationState = {
Expand Down Expand Up @@ -41,14 +40,3 @@ test("Should set navigation id to newly created palette", () => {
const newState = reducer(state, action);
expect(newState.id).toBe(newPaletteId);
});

test("Should switch to build page on any console errors", () => {
const state: NavigationState = {
...initialState,
section: "world",
};
const action = consoleActions.stdErr("Failed to build");

const newState = reducer(state, action);
expect(newState.section).toBe("build");
});

0 comments on commit f76891b

Please sign in to comment.