Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
feat: extend plugin API supports get scene inEditor (#351)
Browse files Browse the repository at this point in the history
* feat: plugin api scene public

* refactor: redefine as inEditor

* refactor: renaming as `inEditor`

* refactor: component params

* refactor: rename function
  • Loading branch information
airslice committed Nov 16, 2022
1 parent af55f1a commit ec0b81d
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/components/molecules/Visualizer/Plugin/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export function commonReearth({
layersInViewport,
layers,
sceneProperty,
inEditor,
tags,
camera,
clock,
Expand Down Expand Up @@ -260,6 +261,7 @@ export function commonReearth({
cameraViewport: () => GlobalThis["reearth"]["visualizer"]["camera"]["viewport"];
captureScreen: GlobalThis["reearth"]["scene"]["captureScreen"];
getLocationFromScreen: GlobalThis["reearth"]["scene"]["getLocationFromScreen"];
inEditor: () => GlobalThis["reearth"]["scene"]["inEditor"];
enableScreenSpaceCameraController: GlobalThis["reearth"]["camera"]["enableScreenSpaceController"];
lookHorizontal: GlobalThis["reearth"]["camera"]["lookHorizontal"];
lookVertical: GlobalThis["reearth"]["camera"]["lookVertical"];
Expand Down Expand Up @@ -311,6 +313,9 @@ export function commonReearth({
return clock();
},
scene: {
get inEditor() {
return inEditor();
},
get property() {
return sceneProperty();
},
Expand Down
5 changes: 5 additions & 0 deletions src/components/molecules/Visualizer/Plugin/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export type Props = {
engine: EngineContext;
engineName: string;
sceneProperty?: any;
inEditor: boolean;
tags?: Tag[];
camera?: CameraPosition;
clock: Clock | undefined;
Expand Down Expand Up @@ -101,6 +102,7 @@ export function Provider({
engine: { api, builtinPrimitives },
engineName,
sceneProperty,
inEditor,
tags,
camera,
clock,
Expand Down Expand Up @@ -151,6 +153,7 @@ export function Provider({

const getLayers = useGet(layers);
const getSceneProperty = useGet(sceneProperty);
const getInEditor = useGet(inEditor);
const getTags = useGet(tags ?? []);
const getCamera = useGet(camera);
const getClock = useGet(clock);
Expand All @@ -177,6 +180,7 @@ export function Provider({
events: ev,
layers: getLayers,
sceneProperty: getSceneProperty,
inEditor: getInEditor,
tags: getTags,
camera: getCamera,
clock: getClock,
Expand Down Expand Up @@ -222,6 +226,7 @@ export function Provider({
ev,
getLayers,
getSceneProperty,
getInEditor,
getTags,
getCamera,
getClock,
Expand Down
1 change: 1 addition & 0 deletions src/components/molecules/Visualizer/Plugin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export type LatLngHeight = {

export type Scene = {
/** Current scene property */
readonly inEditor: boolean;
readonly property?: any;
readonly overrideProperty: (property: any) => void;
readonly captureScreen: (type?: string, encoderOptions?: number) => string | undefined;
Expand Down
3 changes: 3 additions & 0 deletions src/components/molecules/Visualizer/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default ({
isEditable,
isBuilt,
isPublished,
inEditor,
rootLayer,
selectedLayerId: outerSelectedLayerId,
selectedBlockId: outerSelectedBlockId,
Expand All @@ -62,6 +63,7 @@ export default ({
isEditable?: boolean;
isBuilt?: boolean;
isPublished?: boolean;
inEditor?: boolean;
rootLayer?: Layer;
selectedLayerId?: string;
selectedBlockId?: string;
Expand Down Expand Up @@ -251,6 +253,7 @@ export default ({
{
engineName: engineType || "",
sceneProperty: overriddenSceneProperty,
inEditor: !!inEditor,
tags,
camera: innerCamera,
clock: innerClock,
Expand Down
3 changes: 3 additions & 0 deletions src/components/molecules/Visualizer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export type Props = {
selectedBlockId?: string;
pluginBaseUrl?: string;
isPublished?: boolean;
inEditor?: boolean;
widgetAlignEditorActivated?: boolean;
onWidgetUpdate?: WidgetAlignSystemProps["onWidgetUpdate"];
onWidgetAlignSystemUpdate?: WidgetAlignSystemProps["onWidgetAlignSystemUpdate"];
Expand All @@ -89,6 +90,7 @@ export default function Visualizer({
clusterProperty,
pluginBaseUrl,
isPublished,
inEditor,
selectedLayerId: outerSelectedLayerId,
selectedBlockId: outerSelectedBlockId,
zoomedLayerId,
Expand Down Expand Up @@ -144,6 +146,7 @@ export default function Visualizer({
isEditable: props.isEditable,
isBuilt: props.isBuilt,
isPublished,
inEditor,
rootLayer,
selectedLayerId: outerSelectedLayerId,
selectedBlockId: outerSelectedBlockId,
Expand Down
1 change: 1 addition & 0 deletions src/components/molecules/Visualizer/storybook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export function Provider({ children }: { children?: ReactNode }) {
export const context: ProviderProps = {
engineName: "cesium",
engine: {},
inEditor: false,
hideLayer: act("layers.hide"),
showLayer: act("layers.show"),
selectLayer: act("layers.select"),
Expand Down
4 changes: 3 additions & 1 deletion src/components/organisms/EarthEditor/CanvasArea/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import useHooks from "./hooks";
export type Props = {
className?: string;
isBuilt?: boolean;
inEditor?: boolean;
};

// TODO: ErrorBoudaryでエラーハンドリング

const CanvasArea: React.FC<Props> = ({ className, isBuilt }) => {
const CanvasArea: React.FC<Props> = ({ className, isBuilt, inEditor }) => {
const {
rootLayerId,
selectedBlockId,
Expand Down Expand Up @@ -61,6 +62,7 @@ const CanvasArea: React.FC<Props> = ({ className, isBuilt }) => {
engine="cesium"
isEditable={!isBuilt}
isBuilt={!!isBuilt}
inEditor={!!inEditor}
rootLayer={rootLayer}
widgets={widgets}
selectedLayerId={selectedLayerId}
Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/EarthEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const EarthEditor: React.FC<Props> = () => {
header={<Header />}
left={<LeftMenu />}
centerTop={<PrimitiveHeader />}
center={<CanvasArea />}
center={<CanvasArea inEditor />}
right={<RightMenu />}
/>
</DndProvider>
Expand Down

0 comments on commit ec0b81d

Please sign in to comment.