Skip to content

Commit

Permalink
Merge pull request #1375 from pau-tomas/feature/scene_type_plugins
Browse files Browse the repository at this point in the history
Add ability to have scene type plugins
  • Loading branch information
chrismaltby authored Apr 6, 2024
2 parents 08ade63 + 7191c0d commit cc6b2c0
Show file tree
Hide file tree
Showing 33 changed files with 293 additions and 82 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ignore all .inc files:
**/*.inc
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add 'Color Only' mode. Roughly doubles the amount of tiles available for backgrounds and sprites though game will no longer run on original GB (DMG) hardware
- Add event "Replace Tile At Position" and "Replace Tile From Sequence" to update background tiles, calling "Replace Tile From Sequence" repeatedly will cycle through animation frames
- Add new asset folder "Tilesets" for use in "Replace Tile" events
- Add ability for plugins to define additional scene types by including defined types (e.g. `"sceneTypes": [{"key": "RACING", "label": "Racing 2D"}]`) in `engine.json` [@pau-tomas](https://github.com/pau-tomas)

### Changed

Expand Down
42 changes: 34 additions & 8 deletions appData/src/gb/engine.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
],
"cType": "define",
"defaultValue": "INPUT_B"
},
},
{
"key": "INPUT_PLATFORM_INTERACT",
"label": "FIELD_INPUT_INTERACT",
Expand All @@ -35,11 +35,11 @@
["INPUT_A", "A"],
["INPUT_B", "B"],
["INPUT_UP", "FIELD_DIRECTION_UP"],
["INPUT_DOWN", "FIELD_DIRECTION_DOWN"]
["INPUT_DOWN", "FIELD_DIRECTION_DOWN"]
],
"cType": "define",
"defaultValue": "INPUT_A"
},
},
{
"key": "plat_min_vel",
"label": "FIELD_MIN_VEL",
Expand Down Expand Up @@ -79,7 +79,7 @@
"defaultValue": 4000,
"min": 0,
"max": 16384
},
},
{
"key": "plat_walk_acc",
"label": "FIELD_WALK_ACC",
Expand Down Expand Up @@ -119,7 +119,7 @@
"defaultValue": 16384,
"min": 0,
"max": 32768
},
},
{
"key": "plat_grav",
"label": "FIELD_GRAVITY",
Expand All @@ -129,7 +129,7 @@
"defaultValue": 1792,
"min": 0,
"max": 8192
},
},
{
"key": "plat_hold_grav",
"label": "FIELD_GRAVITY_JUMP",
Expand All @@ -139,7 +139,7 @@
"defaultValue": 512,
"min": 0,
"max": 8192
},
},
{
"key": "plat_max_fall_vel",
"label": "FIELD_MAX_FALL_VEL",
Expand Down Expand Up @@ -171,7 +171,7 @@
],
"cType": "define",
"defaultValue": "INPUT_A"
},
},
{
"key": "topdown_grid",
"label": "FIELD_GRID_SIZE",
Expand All @@ -196,5 +196,31 @@
"cType": "UBYTE",
"defaultValue": 0
}
],
"sceneTypes": [
{
"key": "TOPDOWN",
"label": "GAMETYPE_TOP_DOWN"
},
{
"key": "PLATFORM",
"label": "GAMETYPE_PLATFORMER"
},
{
"key": "ADVENTURE",
"label": "GAMETYPE_ADVENTURE"
},
{
"key": "SHMUP",
"label": "GAMETYPE_SHMUP"
},
{
"key": "POINTNCLICK",
"label": "GAMETYPE_POINT_N_CLICK"
},
{
"key": "LOGO",
"label": "GAMETYPE_LOGO"
}
]
}
12 changes: 12 additions & 0 deletions appData/src/gb/include/data/scene_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef SCENE_TYPES_H
#define SCENE_TYPES_H

typedef enum {
SCENE_TYPE_TOPDOWN = 0,
SCENE_TYPE_PLATFORM,
SCENE_TYPE_ADVENTURE,
SCENE_TYPE_SHMUP,
SCENE_TYPE_POINTNCLICK,
SCENE_TYPE_LOGO,
} scene_type_e;
#endif
10 changes: 1 addition & 9 deletions appData/src/gb/include/gbs_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,11 @@
#include <stdint.h>
#include <stdbool.h>

#include "data/scene_types.h"
#include "bankdata.h"
#include "parallax.h"
#include "collision.h"

typedef enum {
SCENE_TYPE_TOPDOWN = 0,
SCENE_TYPE_PLATFORM,
SCENE_TYPE_ADVENTURE,
SCENE_TYPE_SHMUP,
SCENE_TYPE_POINTNCLICK,
SCENE_TYPE_LOGO
} scene_type_e;

typedef enum {
LCD_simple,
LCD_parallax,
Expand Down
5 changes: 3 additions & 2 deletions src/app/project/initProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,11 @@ API.events.watch.ui.removed.subscribe(() => {
store.dispatch(projectActions.loadUI());
});

// Watch Engine Fields
// Watch Engine Schema

API.events.watch.engineSchema.changed.subscribe((_, fields) => {
API.events.watch.engineSchema.changed.subscribe((_, fields, sceneTypes) => {
store.dispatch(engineActions.setEngineFields(fields));
store.dispatch(engineActions.setScenetypes(sceneTypes));
});

// Script Event Defs
Expand Down
3 changes: 3 additions & 0 deletions src/bin/gb-studio-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import initElectronL10N from "lib/lang/initElectronL10N";
import { loadEngineFields } from "lib/project/engineFields";
import loadAllScriptEventHandlers from "lib/project/loadScriptEventHandlers";
import { validateEjectedBuild } from "lib/compiler/validate/validateEjectedBuild";
import { loadSceneTypes } from "lib/project/sceneTypes";

const rmdir = promisify(rimraf);

Expand All @@ -35,6 +36,7 @@ const main = async (

// Load engine fields
const engineFields = await loadEngineFields(projectRoot);
const sceneTypes = await loadSceneTypes(projectRoot);

// Use OS default tmp
const tmpPath = os.tmpdir();
Expand All @@ -57,6 +59,7 @@ const main = async (
projectRoot,
engineFields,
scriptEventHandlers,
sceneTypes,
tmpPath,
progress,
warnings,
Expand Down
25 changes: 13 additions & 12 deletions src/components/forms/SceneTypeSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { FC, useMemo } from "react";
import React, { FC } from "react";
import { Select } from "ui/form/Select";
import l10n from "shared/lib/lang/l10n";
import l10n, { L10NKey } from "shared/lib/lang/l10n";
import { useAppSelector } from "store/hooks";

interface SceneTypeSelectProps {
name: string;
Expand All @@ -13,22 +14,22 @@ interface SceneTypeOption {
label: string;
}

export const getOptions: () => SceneTypeOption[] = () => [
{ value: "TOPDOWN", label: l10n("GAMETYPE_TOP_DOWN") },
{ value: "PLATFORM", label: l10n("GAMETYPE_PLATFORMER") },
{ value: "ADVENTURE", label: l10n("GAMETYPE_ADVENTURE") },
{ value: "SHMUP", label: l10n("GAMETYPE_SHMUP") },
{ value: "POINTNCLICK", label: l10n("GAMETYPE_POINT_N_CLICK") },
{ value: "LOGO", label: l10n("GAMETYPE_LOGO") },
];

export const SceneTypeSelect: FC<SceneTypeSelectProps> = ({
name,
value,
onChange,
}) => {
const options = useMemo(getOptions, []);
const sceneTypes = useAppSelector((state) => state.engine.sceneTypes);

const options = sceneTypes.map((t) => {
return {
value: t.key,
label: l10n(t.label as L10NKey),
} as SceneTypeOption;
});

const currentValue = options.find((o) => o.value === value);

return (
<Select
name={name}
Expand Down
2 changes: 1 addition & 1 deletion src/components/music/helpers/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ const player = {
setOnIntervalCallback: (cb: (position: PlaybackPosition) => void) => {
onIntervalCallback = cb;
},
reset
reset,
};

export default player;
47 changes: 23 additions & 24 deletions src/components/pages/SettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import { SearchableSettingRow } from "ui/form/SearchableSettingRow";
import { SettingRowInput, SettingRowLabel } from "ui/form/SettingRow";
import { SearchableCard } from "ui/cards/SearchableCard";
import { FontSelect } from "components/forms/FontSelect";
import { getOptions as getSceneTypeOptions } from "components/forms/SceneTypeSelect";
import { SpriteSheetSelect } from "components/forms/SpriteSheetSelect";
import { ColorAnimationText } from "components/settings/ColorAnimationText";
import { MusicDriverSelect } from "components/forms/MusicDriverSelect";
Expand All @@ -53,6 +52,7 @@ import { ColorModeSelect } from "components/forms/ColorModeSelect";
const SettingsPage: FC = () => {
const dispatch = useAppDispatch();
const settings = useAppSelector((state) => state.project.present.settings);
const sceneTypes = useAppSelector((state) => state.engine.sceneTypes);
const [searchTerm, setSearchTerm] = useState<string>("");
const [scrollToId, setScrollToId] = useState<string>("");
const groupedFields = useGroupedEngineFields();
Expand All @@ -68,7 +68,6 @@ const SettingsPage: FC = () => {
},
[dispatch]
);
const sceneTypes = useMemo(getSceneTypeOptions, []);
const windowSize = useWindowSize();
const showMenu = (windowSize.width || 0) >= 750;

Expand Down Expand Up @@ -498,28 +497,28 @@ const SettingsPage: FC = () => {
>
<CardAnchor id="settingsPlayer" />
<CardHeading>{l10n("SETTINGS_PLAYER_DEFAULT_SPRITES")}</CardHeading>
{sceneTypes
.filter((s) => s.value !== "LOGO")
.map((sceneType) => (
<SearchableSettingRow
key={sceneType.value}
searchTerm={searchTerm}
searchMatches={[sceneType.label]}
>
<SettingRowLabel>{sceneType.label}</SettingRowLabel>
<SettingRowInput>
<SpriteSheetSelect
name={`defaultPlayerSprite__${sceneType.value}`}
value={defaultPlayerSprites[sceneType.value] || ""}
optional
optionalLabel={l10n("FIELD_NONE")}
onChange={(value) =>
onEditDefaultPlayerSprites(sceneType.value, value)
}
/>
</SettingRowInput>
</SearchableSettingRow>
))}
{sceneTypes.map((sceneType) => (
<SearchableSettingRow
key={sceneType.key}
searchTerm={searchTerm}
searchMatches={[l10n(sceneType.label as L10NKey)]}
>
<SettingRowLabel>
{l10n(sceneType.label as L10NKey)}
</SettingRowLabel>
<SettingRowInput>
<SpriteSheetSelect
name={`defaultPlayerSprite__${sceneType.key}`}
value={defaultPlayerSprites[sceneType.key] || ""}
optional
optionalLabel={l10n("FIELD_NONE")}
onChange={(value) =>
onEditDefaultPlayerSprites(sceneType.key, value)
}
/>
</SettingRowInput>
</SearchableSettingRow>
))}
</SearchableCard>

<SearchableCard
Expand Down
4 changes: 2 additions & 2 deletions src/lang/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
"FIELD_LAST_OPTION_CANCELS": "Ostatnia opcja ustawia wartość na '0'",
"FIELD_LAST_OPTION_CANCELS_DESC": "Ustawienie dla ostatniej opcji - jej wybranie ustawi wartość zmiennej na '0'",
"FIELD_CANCEL_IF_B": "Ustaw wartość '0' jeżeli 'B' zostanie naciśnięte.",
"FIELD_CANCEL_IF_B_DESC": "Ustawienie dla przycisku 'B', naciśnięcie zamknie menu oraz ustawi wartość zmiennej na '0'.",
"FIELD_CANCEL_IF_B_DESC": "Ustawienie dla przycisku 'B', naciśnięcie zamknie menu oraz ustawi wartość zmiennej na '0'.",
"FIELD_NUMBER_OF_OPTIONS": "Ilość opcji wyboru",
"FIELD_NUMBER_OF_OPTIONS_DESC": "Ustawienie ilości wymaganych opcji.",
"FIELD_LAYOUT": "Schemat wyboru",
Expand Down Expand Up @@ -1235,7 +1235,7 @@
"WARNING_TOO_MANY_UNIQUE_PROJECTILES": "Duża ilość pocisków na scenie: \"{name}\". Scena zawiera {num} pocisków, natomiast maksymalna ilość wynosi {max}.",
"WARNING_ENGINE_PLUGIN_OUT_OF_DATE": "Wtyczka \"{pluginName}\" została stworzona dla starszej wersji GB Studio i może nie działać poprawnie. Wtyczka korzysta z silnika w wersji \"{pluginEngineVersion}\" natomiast GB Studio używa silnika w wersji \"{expectedEngineVersion}\".",
"WARNING_ENGINE_PLUGIN_MISSING_MANIFEST": "Wtyczka \"{pluginName}\" bazuje na nieznanej wersji silnika i może nie działać poprawnie. Autorzy wtyczki mogą naprawić ten problem, sprawdzając, czy plik `engine/engine.json` istnieje w folderze wtyczki i zawiera przynajmniej wpis `{\"version\": \"{expectedEngineVersion}\"}`.",

"// 12": "Errors -------------------------------------------------------",

"ERROR_PLEASE_ENTER_PROJECT_NAME": "Wprowadź nazwę projektu",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ OR

- Only relevant to / required by the main process and would not be needed by the renderer windows

Files in this directory
Files in this directory

- CAN import functions and types from shared/lib
- CANNOT import functions from renderer/lib
Expand Down
8 changes: 7 additions & 1 deletion src/lib/compiler/buildProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import makeBuild from "./makeBuild";
import { binjgbRoot } from "consts";
import copy from "lib/helpers/fsCopy";
import type { ProjectData } from "store/features/project/projectActions";
import type { EngineFieldSchema } from "store/features/engine/engineState";
import type {
EngineFieldSchema,
SceneTypeSchema,
} from "store/features/engine/engineState";
import { ScriptEventHandlers } from "lib/project/loadScriptEventHandlers";
import { validateEjectedBuild } from "lib/compiler/validate/validateEjectedBuild";

Expand All @@ -16,6 +19,7 @@ type BuildOptions = {
profile: boolean;
engineFields: EngineFieldSchema[];
scriptEventHandlers: ScriptEventHandlers;
sceneTypes: SceneTypeSchema[];
outputRoot: string;
debugEnabled?: boolean;
progress: (msg: string) => void;
Expand All @@ -31,6 +35,7 @@ const buildProject = async (
profile = false,
engineFields = [],
scriptEventHandlers,
sceneTypes = [],
outputRoot = "/tmp/testing",
debugEnabled = false,
progress = (_msg: string) => {},
Expand All @@ -41,6 +46,7 @@ const buildProject = async (
projectRoot,
engineFields,
scriptEventHandlers,
sceneTypes,
tmpPath,
debugEnabled,
progress,
Expand Down
Loading

0 comments on commit cc6b2c0

Please sign in to comment.