diff --git a/src/lib/PlatformManager.js b/src/_PlatformManager.js similarity index 100% rename from src/lib/PlatformManager.js rename to src/_PlatformManager.js diff --git a/src/cDefine.js b/src/_cDefine.js similarity index 100% rename from src/cDefine.js rename to src/_cDefine.js diff --git a/src/cLive2DApp.js b/src/_cLive2DApp.js similarity index 96% rename from src/cLive2DApp.js rename to src/_cLive2DApp.js index aaf7d4b..bc74fad 100644 --- a/src/cLive2DApp.js +++ b/src/_cLive2DApp.js @@ -14,9 +14,8 @@ DrawDataID, BaseDataID, ParamID -} from './lib/live2d.min';*/ +} from './lib/live2d.min';*//* import './lib/live2d.min.js'; -import { config }from './lib/configManager.js'; import { createCanvas, initCanvas } from "./lib/canvasManager"; import { device } from 'current-device'; import { L2DTargetPoint, L2DViewMatrix, L2DMatrix44 } from "./lib/Live2DFramework"; @@ -39,8 +38,13 @@ let lastMouseY = 0; let headPos = 0.5; let opacityDefault = 0.7; let opacityHover = 1; +*/ + +import { config }from './config/configMgr.js'; export default () => { + console.log('config:'); + console.log(config); /* headPos = typeof iHeadPos === 'undefined' ? 0.5 : iHeadPos; opacityDefault = typeof iOpacityDefault === 'undefined' ? 0.7 : iOpacityDefault; @@ -348,15 +352,7 @@ function lookFront() function mouseEvent(e) { //e.preventDefault(); - if (e.type == "mousewheel") { - // if (e.clientX < 0 || canvas.clientWidth < e.clientX || - // e.clientY < 0 || canvas.clientHeight < e.clientY) - // { - // return; - // } - // if (e.wheelDelta > 0) modelScaling(1.1); - // else modelScaling(0.9); - } else if (e.type == "mousedown") { + if (e.type == "mousedown") { modelTapEvent(e); } else if (e.type == "mousemove") { modelTurnHead(e); diff --git a/src/cManager.js b/src/_cManager.js similarity index 100% rename from src/cManager.js rename to src/_cManager.js diff --git a/src/cModel.js b/src/_cModel.js similarity index 100% rename from src/cModel.js rename to src/_cModel.js diff --git a/src/lib/canvasManager.js b/src/_canvasManager.js similarity index 100% rename from src/lib/canvasManager.js rename to src/_canvasManager.js diff --git a/src/lib/webglcontext.js b/src/_webglcontext.js similarity index 100% rename from src/lib/webglcontext.js rename to src/_webglcontext.js diff --git a/src/lib/configManager.js b/src/config/configMgr.js similarity index 68% rename from src/lib/configManager.js rename to src/config/configMgr.js index 4e91698..8f29476 100644 --- a/src/lib/configManager.js +++ b/src/config/configMgr.js @@ -4,6 +4,9 @@ * @description The container of configeration. */ + +'use strict'; + import _ from 'lodash'; let currConfig = {}; @@ -36,28 +39,27 @@ const defaultOptions = { react: { opacityDefault: 0.7, opacityOnHover: 0.2, - myFunc: () => {console.log('(undefined) ┑( ̄Д  ̄)┍');}, - messageFunc: () => {console.log('(undefined) ┑( ̄Д  ̄)┍');}, + myFunc: (e) => {console.log('(undefined) ┑( ̄Д  ̄)┍');}, // e means the event }, debug: { log: false, mouseLog: false, mouseFunc: (x, y) => {console.log(`MouseFunc: ${x},${x}`);}, // only works when debug.mouseLog is on }, - checked: true, + _: true, } -function configApplyer(inUserConfig){ - console.log(_.defaults({ 'a': 1 }, { 'a': 3, 'b': 2 })); - if (!!!inUserConfig.checked) checkUserConfig(inUserConfig); - // TBD. -} +function configApplyer(userConfig){ -function checkUserConfig(inUserConfig){ - // TBD. -} + if (!(_.has(userConfig, '_'))){ + import(/* webpackMode: "lazy" */ './configValidater').then(f => { + f.configValidater(userConfig); + }).catch(err => { + console.error(err); + }); + } -function configDefaulter(){ + currConfig = _.defaultsDeep(userConfig, defaultOptions); } diff --git a/src/config/configValidater.js b/src/config/configValidater.js new file mode 100644 index 0000000..ed1d743 --- /dev/null +++ b/src/config/configValidater.js @@ -0,0 +1,28 @@ +// Created by xiazeyu. + +/** + * @description the validater for user's config + */ + + +'use strict'; + +import _ from 'lodash'; + +function configValidater(userConfig){ + + if (process.env.NODE_ENV === 'development') console.log('config: validating config...'); + + if(_.has(userConfig, 'model')){ + if(_.has(userConfig.model, 'jsonPath')){ + if(!_.isString(userConfig.model.jsonPath)){ + throw 'userConfig.model.jsonPath should be a string.'; + } + } + } + +} + +export { + configValidater, +} diff --git a/src/configValidater.js b/src/configValidater.js deleted file mode 100644 index e69de29..0000000 diff --git a/src/index.js b/src/index.js index 2a8010c..4fe2f59 100644 --- a/src/index.js +++ b/src/index.js @@ -4,16 +4,15 @@ // Celebrate for the 3.0 version! // //////////////////////////////////// -// Created by xiazeyu. - /** - * @description The entry file + * @description The entry point of live2d-widget */ + 'use strict'; import device from 'current-device'; -import { config, configApplyer }from './lib/configManager.js'; +import { config, configApplyer }from './config/configMgr'; /** * The public entry point @@ -24,21 +23,20 @@ export function init(userConfig){ userConfig = typeof userConfig === 'undefined' ? {} : userConfig; - if (process.env.NODE_ENV === 'development') { - console.log('Hey that, you are now in DEV MODE.'); - } - try{ - configApplyer(userConfig); - }catch(err){ - console.error(err); + if (process.env.NODE_ENV === 'development'){ + console.log('--- --- --- --- ---'); + console.log('Hey that, notice that you are now in DEV MODE.'); + console.log('--- --- --- --- ---'); } -/* + + configApplyer(userConfig); + if((!config.mobile.show)&&(device.mobile())){ return; } -*/ - import(/* webpackMode: "lazy" */ './cLive2DApp').then(_ => { - _.default(); + + import(/* webpackMode: "lazy" */ './_cLive2DApp').then(f => { + f.default(); }).catch(err => { console.error(err); }); diff --git a/src/lib/Live2DFramework.js b/src/lib/_Live2DFramework.js similarity index 100% rename from src/lib/Live2DFramework.js rename to src/lib/_Live2DFramework.js diff --git a/src/lib/Live2DFramework.official.js b/src/lib/_Live2DFramework.official.js similarity index 100% rename from src/lib/Live2DFramework.official.js rename to src/lib/_Live2DFramework.official.js diff --git a/src/lib/live2d.min.js b/src/lib/_live2d.min.js similarity index 100% rename from src/lib/live2d.min.js rename to src/lib/_live2d.min.js diff --git a/src/lib/live2d.core.js b/src/lib/live2d.core.js deleted file mode 100644 index 95dfc4e..0000000 --- a/src/lib/live2d.core.js +++ /dev/null @@ -1,22 +0,0 @@ -/** - * @description Fix global expose for Live2D core library - */ - - -export { - UtSystem, - UtDebug, - LDTransform, - LDGL, - Live2D, - Live2DModelWebGL, - Live2DModelJS, - Live2DMotion, - MotionQueueManager, - PhysicsHair, - AMotion, - PartsDataID, - DrawDataID, - BaseDataID, - ParamID -}; diff --git a/src/tmplate/innerHTML.dev.html b/src/tmplate/_innerHTML.html similarity index 100% rename from src/tmplate/innerHTML.dev.html rename to src/tmplate/_innerHTML.html diff --git a/src/tmplate/innerHTML.html b/src/tmplate/innerHTML.html deleted file mode 100644 index 890e7ae..0000000 --- a/src/tmplate/innerHTML.html +++ /dev/null @@ -1,12 +0,0 @@ - diff --git a/src/utils/MatrixStack.js b/src/utils/_MatrixStack.js similarity index 100% rename from src/utils/MatrixStack.js rename to src/utils/_MatrixStack.js diff --git a/src/utils/ModelSettingJson.js b/src/utils/_ModelSettingJson.js similarity index 100% rename from src/utils/ModelSettingJson.js rename to src/utils/_ModelSettingJson.js diff --git a/src/utils/wpPublicPath.js b/src/wpPublicPath.js similarity index 64% rename from src/utils/wpPublicPath.js rename to src/wpPublicPath.js index 7393569..1435f7b 100644 --- a/src/utils/wpPublicPath.js +++ b/src/wpPublicPath.js @@ -5,14 +5,19 @@ 'use strict'; -let currentScriptPath; +let currentScriptPath = null; try{ + // FF, Chrome + // use their API to get the path of current script + // a.b(); // console.log('Stage1'); let currentScriptElement = document.currentScript; currentScriptPath = currentScriptElement.getAttribute('src').replace(/[^/\\\\]+$/, ''); }catch(e){ + // IE 10 +, Safari and Opera 9 + // console.log('Stage2'); let stack = e.stack || e.sourceURL || e.stacktrace, rExtractUri = /(?:http|https|file):\/\/.*?\/.+?.js/, @@ -21,7 +26,13 @@ try{ currentScriptPath = currentScriptPath.replace(/[^/\\\\]+$/, ''); } +if (currentScriptPath === null){ + throw 'Cannot get currentScriptPath for wpPublicPath'; +} + +// expose the path to the global, +// and wp will finish the following work __webpack_public_path__ = currentScriptPath; if (process.env.NODE_ENV === 'development'){ - console.log(`webPack publicPath: ${__webpack_public_path__}`); + console.log(`wpPP: webPack publicPath: ${__webpack_public_path__}`); } diff --git a/webpack.config.js b/webpack.config.js index dc8c958..2be2d42 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -10,7 +10,7 @@ const isProd = e => e === 'prod'; module.exports = env => {return{ entry: [ - './src/utils/wpPublicPath.js', + './src/wpPublicPath.js', './src/index.js', ],