From 907f8d6fdf847141c95cec302d153f0decd9428b Mon Sep 17 00:00:00 2001 From: antpb Date: Thu, 19 Oct 2023 01:52:55 -0500 Subject: [PATCH] 1.7.1 - Initial Plugin System (#63) * checking in working state hey pixel interface * working text block generationg * fix the fallbacks * pro * adds pro mirror block * add basic edit component * adds transform controls to edit component * add editor plugin provider * add plugin system * checking in working plugin system but broken render * dont lose the nights work * working editor state mirror block * standardize the id object * check in nights work * working context bridge * build commands * adds build script * build directory * fixes example mirror block. working state. * add empty build directories * add empty build directories * add ignore and keeps for build folders so script can build on a fresh pull * remove old file * adds ignore for the pro folder * remove pro * remove pro folder * set block object * remove pro cruft * remove more pro cruft * remove messy comments * adjusts readme * tested up to * fixes static method --- .gitignore | 5 + admin/three-object-viewer-settings/init.php | 2 +- blocks/environment/Edit.js | 47 +++--- .../components/ContextBridgeComponent.js | 44 ++++++ .../components/EditorPluginProvider.js | 31 ++++ .../components/EnvironmentFront.js | 25 ++- .../components/FrontPluginProvider.js | 33 ++++ blocks/environment/components/Player.js | 2 +- .../environment/components/ThreeObjectEdit.js | 148 +++++++++++++----- blocks/environment/editor.scss | 6 + blocks/environment/frontend.js | 61 ++++---- blocks/environment/index.js | 17 +- package.js | 39 +++++ package.json | 7 +- php/Plugin.php | 64 +++++++- plugin-build/.gitignore | 2 + plugin-build/.gitkeep | 0 pluginMachine.json | 10 +- readme.txt | 12 +- three-object-viewer.php | 23 ++- webpack.config.js | 33 +++- yarn.lock | 28 ++++ 22 files changed, 515 insertions(+), 124 deletions(-) create mode 100644 blocks/environment/components/ContextBridgeComponent.js create mode 100644 blocks/environment/components/EditorPluginProvider.js create mode 100644 blocks/environment/components/FrontPluginProvider.js create mode 100644 package.js create mode 100644 plugin-build/.gitignore create mode 100644 plugin-build/.gitkeep diff --git a/.gitignore b/.gitignore index adfd9fe..d297c64 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,9 @@ vendor/ vendor wordpress build +pro/ .phpunit.result.cache +plugin-build/pro/three-object-viewer/* +!plugin-build/pro/three-object-viewer/.gitkeep +plugin-build/free/three-object-viewer/* +!plugin-build/free/three-object-viewer/.gitkeep diff --git a/admin/three-object-viewer-settings/init.php b/admin/three-object-viewer-settings/init.php index 7018402..04a8625 100644 --- a/admin/three-object-viewer-settings/init.php +++ b/admin/three-object-viewer-settings/init.php @@ -88,7 +88,7 @@ function () { echo '
'; } ); -}); +}, 9); function three_encrypt($value = ""){ if( empty( $value ) ) { diff --git a/blocks/environment/Edit.js b/blocks/environment/Edit.js index c2bec47..091a4fb 100644 --- a/blocks/environment/Edit.js +++ b/blocks/environment/Edit.js @@ -21,11 +21,10 @@ import { import { Icon, moveTo, more, rotateLeft, resizeCornerNE } from "@wordpress/icons"; import * as THREE from "three"; import defaultEnvironment from "../../inc/assets/default_grid.glb"; - import ThreeObjectEdit from "./components/ThreeObjectEdit"; +import { EditorPluginProvider, useEditorPlugins, EditorPluginContext } from './components/EditorPluginProvider'; // Import the PluginProvider export default function Edit({ attributes, setAttributes, isSelected }) { - const ALLOWED_BLOCKS = allowed_blocks; const [focusPosition, setFocusPosition] = useState(new THREE.Vector3()); const [focusPoint, setFocus] = useState(new THREE.Vector3()); @@ -299,26 +298,30 @@ export default function Edit({ attributes, setAttributes, isSelected }) { /> {mainModel && ( - + <> + + + + )} diff --git a/blocks/environment/components/ContextBridgeComponent.js b/blocks/environment/components/ContextBridgeComponent.js new file mode 100644 index 0000000..7e0c08f --- /dev/null +++ b/blocks/environment/components/ContextBridgeComponent.js @@ -0,0 +1,44 @@ +import React, { useState, useEffect } from "react"; +import { useFrontPlugins, FrontPluginContext } from './FrontPluginProvider'; +import { useContextBridge } from "@react-three/drei"; + +//import contextBridgef +// add function for context +export function ContextBridgeComponent(props) { + const { plugins } = useFrontPlugins(); // From your own context + const [registeredThreeovBlocks, setRegisteredThreeovBlocks] = useState([]); + const ContextBridge = useContextBridge(FrontPluginContext); + + useEffect(() => { + if (plugins.length > 0) { + plugins.forEach((plugin) => { + // add the plugin to the registered blocks + setRegisteredThreeovBlocks((registeredThreeovBlocks) => [ + ...registeredThreeovBlocks, + plugin, + ]); + }); + } + }, [plugins]); + + return ( + + { + registeredThreeovBlocks.length > 0 && registeredThreeovBlocks.map((blockElement, index) => { + const BlockComponent = blockElement.type; + return ( + + + + ) + }) + } + + ) + +} diff --git a/blocks/environment/components/EditorPluginProvider.js b/blocks/environment/components/EditorPluginProvider.js new file mode 100644 index 0000000..e158d95 --- /dev/null +++ b/blocks/environment/components/EditorPluginProvider.js @@ -0,0 +1,31 @@ +import React, { useState, useContext, useEffect, useCallback } from "react"; + +export const EditorPluginContext = React.createContext(); + +export function EditorPluginProvider({ children }) { + + const [plugins, setPlugins] = useState([]); + + const registerEditorPlugin = useCallback((plugin) => { + setPlugins(prevPlugins => [...prevPlugins, plugin]); + }, []); + + useEffect(() => { + // Expose the registerPlugin method globally + window.registerEditorPlugin = registerEditorPlugin; + window.dispatchEvent(new Event('registerEditorPluginReady')); + + return () => { + // Cleanup + window.registerEditorPlugin = null; + }; + }, [registerEditorPlugin]); + + return ( + + {children} + + ); +} + +export const useEditorPlugins = () => useContext(EditorPluginContext); diff --git a/blocks/environment/components/EnvironmentFront.js b/blocks/environment/components/EnvironmentFront.js index 9f3b4d7..43e7849 100644 --- a/blocks/environment/components/EnvironmentFront.js +++ b/blocks/environment/components/EnvironmentFront.js @@ -1,6 +1,5 @@ import * as THREE from "three"; import { Fog } from 'three/src/scenes/Fog' -// import { Reflector } from 'three/examples/jsm/objects/Reflector'; import React, { Suspense, useRef, useState, useEffect, useMemo } from "react"; import { useLoader, useThree, useFrame, Canvas } from "@react-three/fiber"; import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader"; @@ -14,7 +13,8 @@ import axios from "axios"; import ReactNipple from 'react-nipple'; import ScrollableFeed from 'react-scrollable-feed' import { Resizable } from "re-resizable"; -import { Environment } from "@react-three/drei"; +import { Environment, useContextBridge } from "@react-three/drei"; +import { FrontPluginProvider, FrontPluginContext } from './FrontPluginProvider'; // Import the PluginProvider import { useAnimations, @@ -44,6 +44,7 @@ import { Portal } from "./core/front/Portal"; import { ThreeSky } from "./core/front/ThreeSky"; import { TextObject } from "./core/front/TextObject"; import { useKeyboardControls } from "./Controls"; +import { ContextBridgeComponent } from "./ContextBridgeComponent"; function isMobile() { return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); @@ -509,17 +510,6 @@ function SavedObject(props) { } }); - // Mirror logic. - // const mirror = new Reflector( - // new THREE.PlaneGeometry(10, 10), - // { - // color: new THREE.Color(0x7f7f7f), - // textureWidth: window.innerWidth * window.devicePixelRatio, - // textureHeight: window.innerHeight * window.devicePixelRatio - // } - // ) - // gltf.scene.add(mirror); - meshesToAdd.forEach((mesh) => { meshesScene.attach(mesh); }); @@ -670,19 +660,19 @@ export default function EnvironmentFront(props) { const [messageObject, setMessageObject] = useState({"tone": "happy", "message": "hello!"}); const [objectsInRoom, setObjectsInRoom] = useState([]); const [url, setURL] = useState(props.threeUrl ? props.threeUrl : (threeObjectPlugin + defaultEnvironment)); - + if (loaded === true) { - // find the element that contains the text "WEBXR NOT AVAILABLE" and hide it - // set an element const that selects the body of the document const elements = document.body.getElementsByTagName('*'); const webXRNotAvail = Array.from(elements).find((el) => el.textContent === 'WEBXR NOT AVAILABLE'); if (webXRNotAvail) { webXRNotAvail.style.display = "none"; } + if (props.deviceTarget === "vr") { return ( <> + { isVRCompatible() && } {/* */} {/* */} @@ -715,6 +706,7 @@ export default function EnvironmentFront(props) { background /> } + @@ -1913,6 +1905,7 @@ export default function EnvironmentFront(props) { {/* */} + {Object.values( props.npcsToAdd diff --git a/blocks/environment/components/FrontPluginProvider.js b/blocks/environment/components/FrontPluginProvider.js new file mode 100644 index 0000000..67c6c9b --- /dev/null +++ b/blocks/environment/components/FrontPluginProvider.js @@ -0,0 +1,33 @@ +import React, { createContext, useContext, useState, useEffect, useCallback } from "react"; +import { useThree } from '@react-three/fiber'; + +export const FrontPluginContext = React.createContext(); + +export function FrontPluginProvider({ children }) { + + const [plugins, setPlugins] = useState([]); + const { scene, camera } = useThree(); + + const registerFrontPlugin = useCallback((plugin) => { + setPlugins(prevPlugins => [...prevPlugins, plugin]); + }, []); + + useEffect(() => { + // Expose the registerPlugin method globally + window.registerFrontPlugin = registerFrontPlugin; + window.dispatchEvent(new Event('registerFrontPluginReady')); + + return () => { + // Cleanup + window.registerFrontPlugin = null; + }; + }, [registerFrontPlugin]); + + return ( + + {children} + + ); +} + +export const useFrontPlugins = () => useContext(FrontPluginContext); diff --git a/blocks/environment/components/Player.js b/blocks/environment/components/Player.js index e9434fe..79f2b65 100644 --- a/blocks/environment/components/Player.js +++ b/blocks/environment/components/Player.js @@ -273,7 +273,7 @@ export default function Player(props) { setTimeout(() => { fetchProfile() .then((response) => { - // You can handle the response here if needed + // handle the response here if needed }) .catch((err) => { // Handle the error here if needed diff --git a/blocks/environment/components/ThreeObjectEdit.js b/blocks/environment/components/ThreeObjectEdit.js index 4dec851..86f9658 100644 --- a/blocks/environment/components/ThreeObjectEdit.js +++ b/blocks/environment/components/ThreeObjectEdit.js @@ -14,7 +14,8 @@ import { Text, useAspect, Sky, - Environment + Environment, + useContextBridge } from "@react-three/drei"; import { VRMUtils, VRMLoaderPlugin } from "@pixiv/three-vrm"; import { GLTFAudioEmitterExtension } from "three-omi"; @@ -26,6 +27,7 @@ import { Resizable } from "re-resizable"; import defaultFont from "../../../inc/fonts/roboto.woff"; import audioIcon from "../../../inc/assets/audio_icon.png"; import lightIcon from "../../../inc/assets/light_icon.png"; +import { EditorPluginProvider, useEditorPlugins, EditorPluginContext } from './EditorPluginProvider'; // Import the PluginProvider const { registerStore } = wp.data; @@ -1390,6 +1392,22 @@ function PortalObject(model) { } function ThreeObject(props) { + const [registeredThreeovBlocks, setRegisteredThreeovBlocks] = useState([]); + + const { plugins } = useEditorPlugins(); // From your own context + + useEffect(() => { + if (plugins.length > 0) { + plugins.forEach((plugin) => { + // add the plugin to the registered blocks + setRegisteredThreeovBlocks((registeredThreeovBlocks) => [ + ...registeredThreeovBlocks, + plugin, + ]); + }); + } + }, [plugins]); + let skyobject; let skyobjectId; @@ -1583,9 +1601,64 @@ function ThreeObject(props) { gltf.scene.rotation.set(0, props.rotationY, 0); gltf.scene.scale.set(props.scale, props.scale, props.scale); // const copyGltf = useMemo(() => gltf.scene.clone(), [gltf.scene]) + const TransformController = ({ condition, wrap, children }) => + condition ? wrap(children) : children; return ( <> + {registeredThreeovBlocks.length > 0 && registeredThreeovBlocks.map((blockElement, index) => { + const BlockComponent = blockElement.type; + const blockPosition = wp.data + .select("core/block-editor") + .getBlockAttributes(blockElement.props.pluginObjectId); + if (blockPosition !== null) { + return ( props.focusID === blockElement.props.pluginObjectId ) ? ( + ( + { + const rot = new THREE.Euler(0, 0, 0, "XYZ"); + const scale = e?.target.worldScale; + rot.setFromQuaternion( + e?.target.worldQuaternion + ); + wp.data + .dispatch("core/block-editor") + .updateBlockAttributes(blockElement.props.pluginObjectId, { + positionX: e?.target.worldPosition.x, + positionY: e?.target.worldPosition.y, + positionZ: e?.target.worldPosition.z, + rotationX: rot.x, + rotationY: rot.y, + rotationZ: rot.z, + scaleX: scale.x, + scaleY: scale.y, + scaleZ: scale.z + }); + }} + > + {children} + + )} + > + + + ) : ( + + + + ); + } + })} {skyobject && } {spawnpoint && ( @@ -1975,41 +2049,43 @@ export default function ThreeObjectEdit(props) { boxSizing: "border-box" }} > - {/* */} - - {props.url && ( - - {props.hdr && - - } - {/* */} - - - )} - + + {/* */} + + {props.url && ( + + {props.hdr && + + } + {/* */} + + + )} + + ); diff --git a/blocks/environment/editor.scss b/blocks/environment/editor.scss index b153576..a09e4f1 100644 --- a/blocks/environment/editor.scss +++ b/blocks/environment/editor.scss @@ -15,6 +15,12 @@ margin-right:-160px; } +.pixel-modal .components-button { + background-color: white; + box-shadow: #0000005e 0px 5px 21px; + +} + #VRButton{ position: fixed !important; top: 20px !important; diff --git a/blocks/environment/frontend.js b/blocks/environment/frontend.js index 2190257..1d725f3 100644 --- a/blocks/environment/frontend.js +++ b/blocks/environment/frontend.js @@ -7,6 +7,7 @@ import Networking from "./components/Networking"; const threeApp = document.querySelectorAll( ".three-object-three-app-environment" ); + const modelsToAdd = document.querySelectorAll( ".three-object-three-app-model-block" ); @@ -36,6 +37,10 @@ const audiosToAdd = document.querySelectorAll( const lightsToAdd = document.querySelectorAll( ".three-object-three-app-light-block" ); + +// All blocks. +window.threeApp = threeApp[0].querySelectorAll("div"); + threeApp.forEach((threeApp) => { if (threeApp) { const hdr = document.querySelector( @@ -115,34 +120,34 @@ threeApp.forEach((threeApp) => { postSlug={postSlug} userData={userData} /> */} - - , + +\ , threeApp ); } diff --git a/blocks/environment/index.js b/blocks/environment/index.js index 228a183..1caacdd 100644 --- a/blocks/environment/index.js +++ b/blocks/environment/index.js @@ -2,9 +2,20 @@ import { registerBlockType } from "@wordpress/blocks"; import Edit from "./Edit"; import Save from "./Save"; import { useBlockProps } from "@wordpress/block-editor"; -import { useSelect, useDispatch } from '@wordpress/data'; -import { useEffect } from '@wordpress/element'; -import React, { Suspense, useRef, useMemo } from "react"; +import React from "react"; + +import { useState } from '@wordpress/element'; + +function Loading() { + return ( + +
+
+
Loading...
+
+ + ); +} const icon = ( { + const sourcePath = path.join(sourceDirectory, item); + const targetPath = path.join(targetDirectory, item); + fs.copySync(sourcePath, targetPath); +}); + +// If it's the pro build, include the 'pro' directory plus all free version files/directories +if (isPro) { + const sourcePro = path.join(sourceDirectory, 'pro'); + const targetPro = path.join(targetDirectory, 'pro'); + fs.copySync(sourcePro, targetPro); +} + +console.log(`Packaged the ${isPro ? 'pro' : 'free'} version to ${targetDirectory}`); diff --git a/package.json b/package.json index 9959bdc..0188192 100644 --- a/package.json +++ b/package.json @@ -8,14 +8,16 @@ "test": "yarn test:unit", "test:unit": "wp-scripts test-unit-js", "build": "wp-scripts build", + "build:pro": "ISPRO=true wp-scripts build && node package.js pro", + "build:free": "wp-scripts build && node package.js free", "test:ci": "wp-scripts test-unit-js --passWithNoTests", "format:js": "wp-scripts format-js", "lint:css": "wp-scripts lint-style", "lint:js": "wp-scripts lint-js", "start": "wp-scripts start", "rename": "node rename.js", - "make-pot": "vendor/bin/wp i18n make-pot . ./languages/three-object-viewer.pot --slug=three-object-viewer --domain=three-object-viewer", - "make-json": "vendor/bin/wp i18n make-json ./languages/ --no-purge" + "make-pot": "vendor/bin/wp i18n make-pot . ./languages/three-object-viewer.pot --slug=three-object-viewer --domain=three-object-viewer", + "make-json": "vendor/bin/wp i18n make-json ./languages/ --no-purge" }, "devDependencies": { "@babel/core": "^7", @@ -26,6 +28,7 @@ "browserify": "^17.0.0", "esbuild": "^0.15.5", "eslint": "^8.7.0", + "fs-extra": "^11.1.1", "lint-staged": "^13.0.3", "prettier": "^2.7.1", "prettier-standard": "^16.4.1", diff --git a/php/Plugin.php b/php/Plugin.php index a05a6c3..3b4c029 100644 --- a/php/Plugin.php +++ b/php/Plugin.php @@ -334,21 +334,62 @@ function call_alchemy_request( $request ) { } // The function that checks the bearer token. Make the bearer token a secret using get_option(). This is a crude example. - function check_bearer_token( $request ) { + function check_bearer_token( $request ) { $nonce = $request->get_header( 'X-WP-Nonce' ); if ( ! $nonce || ! wp_verify_nonce( $nonce, 'wp_rest' ) ) { return new \WP_Error( 'invalid_nonce', 'The nonce provided in the X-WP-Nonce header is invalid', array( 'status' => 401 ) ); } return true; - } - - + } + + /** + * Check if pro version is installed + */ + function threeobjectviewer_is_pro() { + if (file_exists(dirname(__DIR__) . '/pro')) { + return true; + } else { + return false; + } + } + /** * Enqueue block frontend JavaScript */ function threeobjectviewer_editor_assets() { $three_object_plugin = plugins_url() . '/three-object-viewer/build/'; $three_object_plugin_root = plugins_url() . '/three-object-viewer/'; + $current_user = wp_get_current_user(); + $vrm = wp_get_attachment_url($current_user->avatar); + if ( is_user_logged_in() && get_option('3ov_ai_allow') === "loggedIn" ) { + $user_data_passed = array( + 'userId' => $current_user->user_login, + 'inWorldName' => $current_user->in_world_name, + 'banner' => $current_user->custom_banner, + 'vrm' => $vrm, + 'profileImage' => get_avatar_url( $current_user->ID, ['size' => '500'] ), + 'nonce' => wp_create_nonce( 'wp_rest' ) + ); + } else if ( get_option('3ov_ai_allow') === "public") { + $user_data_passed = array( + 'userId' => $current_user->user_login, + 'inWorldName' => $current_user->in_world_name, + 'banner' => $current_user->custom_banner, + 'vrm' => $vrm, + 'profileImage' => get_avatar_url( $current_user->ID, ['size' => '500'] ), + 'nonce' => wp_create_nonce( 'wp_rest' ) + ); + } + else { + $user_data_passed = array( + 'userId' => $current_user->user_login, + 'inWorldName' => $current_user->in_world_name, + 'banner' => $current_user->custom_banner, + 'vrm' => $vrm, + 'profileImage' => get_avatar_url( $current_user->ID, ['size' => '500'] ), + ); + } + $DEFAULT_BLOCKS = [ 'three-object-viewer/three-portal-block', @@ -363,8 +404,21 @@ function threeobjectviewer_editor_assets() { 'three-object-viewer/three-video-block', 'three-object-viewer/spawn-point-block' ]; + // if in the directory above this one a folder named "pro" exists, add "three-mirror-block" to the array + // use the threeobjectviewer_is_pro function to check if pro + if ($this->threeobjectviewer_is_pro()) { + $PRO_BLOCKS = [ + 'three-object-viewer/three-mirror-block', + ]; + array_push( $DEFAULT_BLOCKS, $PRO_BLOCKS ); + } + $ALLOWED_BLOCKS = apply_filters( 'three-object-environment-inner-allowed-blocks', $DEFAULT_BLOCKS ); - + + $default_avatar = get_option('3ov_defaultAvatar'); + wp_localize_script( 'three-object-viewer-three-object-block-editor-script', 'defaultAvatar', $default_avatar ); + wp_localize_script( 'three-object-viewer-three-object-block-editor-script', 'userData', $user_data_passed ); + wp_enqueue_script( 'three-object-viewer-three-object-block-editor-script', 'three-object-viewer', ['wp-element', 'wp-data', 'wp-i18n', 'wp-hooks'], '', true ); wp_localize_script( 'three-object-viewer-three-object-block-editor-script', 'threeObjectPlugin', $three_object_plugin ); wp_localize_script( 'three-object-viewer-three-object-block-editor-script', 'threeObjectPluginRoot', $three_object_plugin_root ); diff --git a/plugin-build/.gitignore b/plugin-build/.gitignore new file mode 100644 index 0000000..5f21188 --- /dev/null +++ b/plugin-build/.gitignore @@ -0,0 +1,2 @@ +!.gitignore +!.gitkeep diff --git a/plugin-build/.gitkeep b/plugin-build/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/pluginMachine.json b/pluginMachine.json index cf1062f..94b51f8 100644 --- a/pluginMachine.json +++ b/pluginMachine.json @@ -6,6 +6,9 @@ "adminPages": [ "three-object-viewer-settings" ], + "proAdminPages": [ + "three-object-viewer-pro-settings" + ], "blocks": [ "three-object-block", "environment", @@ -19,6 +22,9 @@ "three-portal-block", "three-text-block", "spawn-point-block" + ], + "proBlocks": [ + "three-mirror-block" ] }, "buildIncludes": [ @@ -37,6 +43,8 @@ "blocks/three-video-block/init.php", "blocks/three-portal-block/init.php", "blocks/spawn-point-block/init.php", - "admin/three-object-viewer-settings/init.php" + "blocks/three-mirror-block/init.php", + "admin/three-object-viewer-settings/init.php", + "pro/admin/three-object-viewer-pro-settings/init.php" ] } \ No newline at end of file diff --git a/readme.txt b/readme.txt index 4f5c140..ddd72b5 100644 --- a/readme.txt +++ b/readme.txt @@ -1,8 +1,8 @@ === Three Object Viewer === Requires at least: 6.0 -Tested up to: 6.3 +Tested up to: 6.4 Requires PHP: 7.2 -Stable tag: 1.6.0 +Stable tag: 1.7.1 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html Author: antpb @@ -42,6 +42,14 @@ It can also be installed manually using a zip file. == Changelog == += 1.7.1 = +Fix: Change pro check to static + += 1.7 = +Added: Plugin system for custom 3OV blocks in Environment inner blocks. Experimental but getting very solid! Example plugin coming soon. +Fixed: fixed bug where state was changing on scroll of the page. +Fixed: Environment Editor states where values did not exist caused the editor to crash in some cases. + = 1.6 = Fixed: Player Controller - Respawn while falling works again. Added: Light Block - You can now control the individual lights in your worlds. Note: highly recommend not having more than two Libhg Blocks in a world for performance reasons. diff --git a/three-object-viewer.php b/three-object-viewer.php index 05bfe3c..585fef9 100644 --- a/three-object-viewer.php +++ b/three-object-viewer.php @@ -3,7 +3,7 @@ * Plugin Name: Three Object Viewer * Plugin URI: https://3ov.xyz/ * Description: A plugin for viewing 3D files with support for WebXR and Open Metaverse Interoperability GLTF Extensions. -* Version: 1.6.0 +* Version: 1.7.1 * Requires at least: 5.7 * Requires PHP: 7.1.0 * Author: antpb @@ -20,11 +20,10 @@ $main->init(); register_activation_hook( __FILE__, array( 'threeObjectViewer\MainOptions', 'my_plugin_activate' ) ); -define('THREEOV_PLUGIN_VERSION', '1.4.0'); +define('THREEOV_PLUGIN_VERSION', '1.7.1'); class MainOptions { - public static function my_plugin_activate() { if( ! get_option( '3ov_ai_enabled' ) ) { update_option( '3ov_ai_enabled', true ); @@ -85,6 +84,17 @@ public static function on_plugin_update() { update_option('3ov_plugin_version', THREEOV_PLUGIN_VERSION); } + /** + * Check if pro version is installed + */ + public static function threeov_is_pro() { + if ( file_exists( __DIR__ .'/pro' )) { + return true; + } else { + return false; + } + } + } MainOptions::check_plugin_update(); @@ -126,6 +136,13 @@ public static function on_plugin_update() { // Include spawn point include_once dirname( __FILE__ ) . '/blocks/spawn-point-block/init.php'; +if ( MainOptions::threeov_is_pro() ) { + // Include mirror block + include_once dirname( __FILE__ ) . '/pro/blocks/three-mirror-block/init.php'; + include_once dirname( __FILE__ ) . '/pro/admin/three-object-viewer-pro-settings/init.php'; +} + + /** * Include the autoloader */ diff --git a/webpack.config.js b/webpack.config.js index 6247b69..de676fd 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -2,6 +2,7 @@ const defaultConfig = require("@wordpress/scripts/config/webpack.config"); const path = require("path"); const isProduction = "production" === process.env.NODE_ENV; const { entryPoints } = require("./pluginMachine.json"); +const isPro = process.env.ISPRO === 'true'; const entry = {}; if (entryPoints.hasOwnProperty("blocks")) { @@ -13,6 +14,17 @@ if (entryPoints.hasOwnProperty("blocks")) { }); } +if (isPro) { + if (entryPoints.hasOwnProperty("proBlocks")) { + entryPoints.proBlocks.forEach((entryPoint) => { + entry[`block-${entryPoint}`] = path.resolve( + process.cwd(), + `pro/blocks/${entryPoint}/index.js` + ); + }); + } +} + if (entryPoints.hasOwnProperty("adminPages")) { entryPoints.adminPages.forEach((entryPoint) => { entry[`admin-page-${entryPoint}`] = path.resolve( @@ -22,11 +34,24 @@ if (entryPoints.hasOwnProperty("adminPages")) { }); } -entry[`./assets/js/blocks.frontend`] = - "./blocks/three-object-block/frontend.js"; +if (isPro) { + if (entryPoints.hasOwnProperty("proAdminPages")) { + entryPoints.proAdminPages.forEach((entryPoint) => { + entry[`admin-page-${entryPoint}`] = path.resolve( + process.cwd(), + `pro/admin/${entryPoint}/index.js` + ); + }); + } +} + +entry[`./assets/js/blocks.frontend`] = "./blocks/three-object-block/frontend.js"; -entry[`./assets/js/blocks.frontend-versepress`] = - "./blocks/environment/frontend.js"; +entry[`./assets/js/blocks.frontend-versepress`] = "./blocks/environment/frontend.js"; + +if (isPro) { + entry[`./assets/js/blocks.three-mirror-block`] = "./pro/blocks/three-mirror-block/three-mirror-block-front.js"; +} module.exports = { mode: isProduction ? "production" : "development", diff --git a/yarn.lock b/yarn.lock index b0ea489..90864cf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9566,6 +9566,15 @@ fs-exists-sync@^0.1.0: resolved "https://registry.yarnpkg.com/fs-exists-sync/-/fs-exists-sync-0.1.0.tgz#982d6893af918e72d08dec9e8673ff2b5a8d6add" integrity sha1-mC1ok6+RjnLQjeyehnP/K1qNat0= +fs-extra@^11.1.1: + version "11.1.1" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-11.1.1.tgz#da69f7c39f3b002378b0954bb6ae7efdc0876e2d" + integrity sha512-MGIE4HOvQCeUCzmlHs0vXpih4ysz4wg9qiSAu6cd42lVwPbTM1TjV7RusoyQqMmk/95gdQZX72u+YW+c3eEpFQ== + dependencies: + graceful-fs "^4.2.0" + jsonfile "^6.0.1" + universalify "^2.0.0" + fs-minipass@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/fs-minipass/-/fs-minipass-2.1.0.tgz#7f5036fdbf12c63c169190cbe4199c852271f9fb" @@ -10051,6 +10060,11 @@ graceful-fs@^4.1.10, graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1. resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.10.tgz#147d3a006da4ca3ce14728c7aefc287c367d7a6c" integrity sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA== +graceful-fs@^4.1.6, graceful-fs@^4.2.0: + version "4.2.11" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3" + integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ== + "graceful-readlink@>= 1.0.0": version "1.0.1" resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725" @@ -12000,6 +12014,15 @@ jsonc-parser@~2.2.0: resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-2.2.1.tgz#db73cd59d78cce28723199466b2a03d1be1df2bc" integrity sha512-o6/yDBYccGvTz1+QFevz6l6OBZ2+fMVu2JZ9CIhzsYRX4mjaK5IyX9eldUdCmga16zlgQxyrj5pt9kzuj2C02w== +jsonfile@^6.0.1: + version "6.1.0" + resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae" + integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ== + dependencies: + universalify "^2.0.0" + optionalDependencies: + graceful-fs "^4.1.6" + jsonify@~0.0.0: version "0.0.0" resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73" @@ -18108,6 +18131,11 @@ universalify@^0.1.2: resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66" integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg== +universalify@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717" + integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ== + unpipe@1.0.0, unpipe@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"