Skip to content

Commit

Permalink
Merge pull request #1433 from tomo666/develop
Browse files Browse the repository at this point in the history
Fix Hardcoded strings for L10N ready
  • Loading branch information
chrismaltby authored May 28, 2024
2 parents cf713b8 + b6f3246 commit ac2404e
Show file tree
Hide file tree
Showing 13 changed files with 168 additions and 76 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Darkened conditional event header colours in dark theme
- Patron list in credits now fetches most up to date list of members from GitHub if an internet connection is available
- Previous "Name in Credits" tier members on Patreon are now still shown even after their membership has finished (your support is still very much appreciated!)
- Updated Japanese localisation. [@tomo666](https://github.com/tomo666)
- Update GBVM script view in debugger to show human readable labels

### Fixed
Expand Down
10 changes: 6 additions & 4 deletions src/components/forms/ActorSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type ActorOption = Option & {

const allCustomEventActors = Array.from(Array(10).keys()).map((i) => ({
id: String(i),
name: `Actor ${String.fromCharCode("A".charCodeAt(0) + i)}`,
letter: String.fromCharCode("A".charCodeAt(0) + i),
}));

export const ActorSelect = ({
Expand Down Expand Up @@ -77,13 +77,15 @@ export const ActorSelect = ({
if (context.type === "script" && customEvent) {
setOptions([
{
label: "Player",
label: l10n("FIELD_PLAYER"),
value: "player",
spriteSheetId: playerSpriteSheetId,
},
...allCustomEventActors.map((actor) => {
return {
label: customEvent.actors[actor.id]?.name ?? actor.name,
label:
customEvent.actors[actor.id]?.name ??
`${l10n("FIELD_ACTOR")} ${actor.letter}`,
value: actor.id,
};
}),
Expand All @@ -106,7 +108,7 @@ export const ActorSelect = ({
]
: []),
{
label: "Player",
label: l10n("FIELD_PLAYER"),
value: "player",
spriteSheetId: playerSpriteSheetId,
},
Expand Down
37 changes: 19 additions & 18 deletions src/components/forms/ColorModeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Select,
SelectCommonProps,
} from "ui/form/Select";
import l10n from "shared/lib/lang/l10n";

interface ColorModeSelectProps extends SelectCommonProps {
name: string;
Expand All @@ -18,35 +19,35 @@ export interface ColorModeOption {
label: string;
}

const colorModeOptions: ColorModeOption[] = [
{
value: "mono",
label: "Monochrome",
},
{
value: "mixed",
label: "Color + Monochrome",
},
{
value: "color",
label: "Color Only",
},
];

export const ColorModeSelect: FC<ColorModeSelectProps> = ({
value,
onChange,
}) => {
const [currentValue, setCurrentValue] = useState<Option>();
const colorModeOptionsInfo: { [key: string]: string } = useMemo(
() => ({
mono: "GB, GB Color, Pocket",
mixed: "GB, GB Color, Pocket",
color: "GB Color, Pocket",
mono: l10n("FIELD_COLOR_MODE_MONO_INFO"),
mixed: l10n("FIELD_COLOR_MODE_COLOR_MONO_INFO"),
color: l10n("FIELD_COLOR_MODE_COLOR_ONLY_INFO"),
}),
[]
);

const colorModeOptions: ColorModeOption[] = [
{
value: "mono",
label: l10n("FIELD_COLOR_MODE_MONO"),
},
{
value: "mixed",
label: l10n("FIELD_COLOR_MODE_COLOR_MONO"),
},
{
value: "color",
label: l10n("FIELD_COLOR_MODE_COLOR_ONLY"),
},
];

useEffect(() => {
const currentColorMode = colorModeOptions.find((e) => e.value === value);
if (currentColorMode) {
Expand Down
9 changes: 5 additions & 4 deletions src/components/forms/ObjPaletteSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Select,
SingleValueWithPreview,
} from "ui/form/Select";
import l10n from "shared/lib/lang/l10n";

interface ObjPaletteSelectProps {
name: string;
Expand All @@ -22,12 +23,12 @@ interface ObjPaletteOption {
const options: ObjPaletteOption[] = [
{
value: "OBP0",
label: "Palette 0: OBP0",
label: "0: OBP0",
colors: ["E8F8E0", "B0F088", "", "202850"],
},
{
value: "OBP1",
label: "Palette 1: OBP1",
label: "1: OBP1",
colors: ["E8F8E0", "509878", "", "202850"],
},
];
Expand All @@ -53,7 +54,7 @@ export const ObjPaletteSelect: FC<ObjPaletteSelectProps> = ({
<PaletteBlock type="sprite" colors={option.colors} size={20} />
}
>
{option.label}
{l10n("FIELD_PALETTE")} {option.label}
</OptionLabelWithPreview>
);
}}
Expand All @@ -68,7 +69,7 @@ export const ObjPaletteSelect: FC<ObjPaletteSelectProps> = ({
/>
}
>
{currentValue?.label}
{l10n("FIELD_PALETTE")} {currentValue?.label}
</SingleValueWithPreview>
),
}}
Expand Down
17 changes: 9 additions & 8 deletions src/components/forms/PaletteIndexSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { FC, useEffect, useState } from "react";
import React, { FC, useEffect, useMemo, useState } from "react";
import { useAppSelector } from "store/hooks";
import { DMG_PALETTE } from "consts";
import l10n from "shared/lib/lang/l10n";
import {
paletteSelectors,
getLocalisedDMGPalette,
getLocalisedPalettesLookup,
sceneSelectors,
} from "store/features/entities/entitiesState";
import { Palette } from "shared/lib/entities/entitiesTypes";
Expand Down Expand Up @@ -41,11 +41,12 @@ export const PaletteIndexSelect: FC<PaletteIndexSelectProps> = ({
sceneSelectors.selectById(state, previewAsSceneId)
);
const palettesLookup = useAppSelector((state) =>
paletteSelectors.selectEntities(state)
getLocalisedPalettesLookup(state)
);
const defaultSpritePaletteIds = useAppSelector(
(state) => state.project.present.settings.defaultSpritePaletteIds
);
const dmgPalette = useMemo(getLocalisedDMGPalette, []);

useEffect(() => {
setOptions(
Expand Down Expand Up @@ -81,14 +82,14 @@ export const PaletteIndexSelect: FC<PaletteIndexSelectProps> = ({
preview={
<PaletteBlock
type="sprite"
colors={option.palette?.colors || DMG_PALETTE.colors}
colors={option.palette?.colors || dmgPalette.colors}
size={20}
/>
}
>
{option.label}
{": "}
{option.palette?.name || DMG_PALETTE.name}
{option.palette?.name || dmgPalette.name}
</OptionLabelWithPreview>
);
}}
Expand All @@ -98,14 +99,14 @@ export const PaletteIndexSelect: FC<PaletteIndexSelectProps> = ({
preview={
<PaletteBlock
type="sprite"
colors={currentValue?.palette?.colors || DMG_PALETTE.colors}
colors={currentValue?.palette?.colors || dmgPalette.colors}
size={20}
/>
}
>
{currentValue?.label}
{": "}
{currentValue?.palette?.name || DMG_PALETTE.name}
{currentValue?.palette?.name || dmgPalette.name}
</SingleValueWithPreview>
),
}}
Expand Down
38 changes: 21 additions & 17 deletions src/components/forms/PaletteSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, { FC, useEffect, useState } from "react";
import React, { FC, useEffect, useMemo, useState } from "react";
import { useAppSelector } from "store/hooks";
import styled from "styled-components";
import { DMG_PALETTE } from "consts";
import { paletteSelectors } from "store/features/entities/entitiesState";
import {
getLocalisedDMGPalette,
getLocalisedPalettes,
} from "store/features/entities/entitiesState";
import { Palette } from "shared/lib/entities/entitiesTypes";
import PaletteBlock from "components/forms/PaletteBlock";
import {
Expand All @@ -13,7 +15,6 @@ import {
SelectCommonProps,
} from "ui/form/Select";
import l10n from "shared/lib/lang/l10n";
import { paletteName } from "shared/lib/entities/entitiesHelpers";

interface PaletteSelectProps extends SelectCommonProps {
name: string;
Expand Down Expand Up @@ -53,10 +54,11 @@ export const PaletteSelect: FC<PaletteSelectProps> = ({
keepLabel,
...selectProps
}) => {
const palettes = useAppSelector((state) => paletteSelectors.selectAll(state));
const palettes = useAppSelector((state) => getLocalisedPalettes(state));
const [options, setOptions] = useState<PaletteOption[]>([]);
const [currentPalette, setCurrentPalette] = useState<Palette>();
const [currentValue, setCurrentValue] = useState<PaletteOption>();
const dmgPalette = useMemo(getLocalisedDMGPalette, []);

useEffect(() => {
setOptions(
Expand Down Expand Up @@ -84,18 +86,18 @@ export const PaletteSelect: FC<PaletteSelectProps> = ({
label: optionalLabel || "None",
palette:
palettes.find((p) => p.id === optionalDefaultPaletteId) ||
DMG_PALETTE,
dmgPalette,
},
] as PaletteOption[])
: ([] as PaletteOption[]),
{
value: DMG_PALETTE.id,
label: DMG_PALETTE.name,
palette: DMG_PALETTE as Palette,
value: dmgPalette.id,
label: dmgPalette.name,
palette: dmgPalette,
},
palettes.map((palette, index) => ({
palettes.map((palette) => ({
value: palette.id,
label: paletteName(palette, index),
label: palette.name,
palette,
}))
)
Expand All @@ -108,15 +110,16 @@ export const PaletteSelect: FC<PaletteSelectProps> = ({
optional,
optionalDefaultPaletteId,
optionalLabel,
dmgPalette,
]);

useEffect(() => {
if (value === DMG_PALETTE.id) {
setCurrentPalette(DMG_PALETTE as Palette);
if (value === dmgPalette.id) {
setCurrentPalette(dmgPalette);
} else {
setCurrentPalette(palettes.find((v) => v.id === value));
}
}, [palettes, value]);
}, [dmgPalette, palettes, value]);

useEffect(() => {
if (canKeep && value === "keep") {
Expand All @@ -137,7 +140,7 @@ export const PaletteSelect: FC<PaletteSelectProps> = ({
});
} else if (optional) {
const optionalPalette =
palettes.find((p) => p.id === optionalDefaultPaletteId) || DMG_PALETTE;
palettes.find((p) => p.id === optionalDefaultPaletteId) || dmgPalette;
setCurrentValue({
value: "",
label: optionalLabel || "None",
Expand All @@ -146,8 +149,8 @@ export const PaletteSelect: FC<PaletteSelectProps> = ({
} else {
setCurrentValue({
value: "",
label: DMG_PALETTE.name,
palette: DMG_PALETTE as Palette,
label: dmgPalette.name,
palette: dmgPalette,
});
}
}, [
Expand All @@ -160,6 +163,7 @@ export const PaletteSelect: FC<PaletteSelectProps> = ({
keepLabel,
value,
canRestore,
dmgPalette,
]);

const onSelectChange = (newValue: Option) => {
Expand Down
14 changes: 7 additions & 7 deletions src/components/forms/PaletteSelectButton.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React, { FC, useEffect, useRef, useState } from "react";
import styled from "styled-components";
import { paletteSelectors } from "store/features/entities/entitiesState";
import {
getLocalisedDMGPalette,
getLocalisedPaletteById,
} from "store/features/entities/entitiesState";
import PaletteBlock from "components/forms/PaletteBlock";
import { SelectMenu, selectMenuStyleProps } from "ui/form/Select";
import { RelativePortal } from "ui/layout/RelativePortal";
import { PaletteSelect } from "./PaletteSelect";
import navigationActions from "store/features/navigation/navigationActions";
import { DMG_PALETTE } from "consts";
import { useAppDispatch, useAppSelector } from "store/hooks";

type PaletteSelectProps = {
Expand Down Expand Up @@ -77,13 +79,11 @@ export const PaletteSelectButton: FC<PaletteSelectProps> = ({
}) => {
const buttonRef = useRef<HTMLButtonElement>(null);
const timerRef = useRef<number | null>(null);

const palette =
useAppSelector((state) =>
paletteSelectors.selectById(
state,
value || optionalDefaultPaletteId || ""
)
) || DMG_PALETTE;
getLocalisedPaletteById(state, value || optionalDefaultPaletteId || "")
) || getLocalisedDMGPalette();
const [isOpen, setIsOpen] = useState<boolean>(false);
const [buttonFocus, setButtonFocus] = useState<boolean>(false);
const dispatch = useAppDispatch();
Expand Down
2 changes: 1 addition & 1 deletion src/components/sprites/SpriteEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ export const SpriteEditor = ({
</FormSectionTitle>
{!isDefaultState && (
<FormRow>
<FormField name="stateName" label="State Name">
<FormField name="stateName" label={l10n("FIELD_STATE_NAME")}>
<AnimationStateSelect
name="stateName"
value={spriteState.name}
Expand Down
3 changes: 2 additions & 1 deletion src/components/world/BrushToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import {
} from "./BrushToolbarIcons";
import { RelativePortal } from "ui/layout/RelativePortal";
import { useAppDispatch, useAppSelector } from "store/hooks";
import { paletteName } from "shared/lib/entities/entitiesHelpers";

interface BrushToolbarProps {
hasFocusForKeyboardShortcuts: () => boolean;
Expand Down Expand Up @@ -569,7 +570,7 @@ const BrushToolbar = ({ hasFocusForKeyboardShortcuts }: BrushToolbarProps) => {
active={paletteIndex === selectedPalette}
title={`${l10n("TOOL_PALETTE_N", {
number: paletteIndex + 1,
})} (${paletteIndex + 1}) - ${palettes[paletteIndex]?.name}`}
})} (${paletteIndex + 1}) - ${paletteName(palettes[paletteIndex], -1)}`}
>
<PaletteBlock
colors={palettes[paletteIndex]?.colors ?? []}
Expand Down
Loading

0 comments on commit ac2404e

Please sign in to comment.