Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
feat: marked unfinished files, rebuild file structure, config works
Browse files Browse the repository at this point in the history
  • Loading branch information
xiazeyu committed Jan 5, 2018
1 parent be5531d commit 62555a9
Show file tree
Hide file tree
Showing 21 changed files with 76 additions and 75 deletions.
File renamed without changes.
File renamed without changes.
18 changes: 7 additions & 11 deletions src/cLive2DApp.js → src/_cLive2DApp.js
Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 14 additions & 12 deletions src/lib/configManager.js → src/config/configMgr.js
Expand Up @@ -4,6 +4,9 @@
* @description The container of configeration.
*/


'use strict';

import _ from 'lodash';

let currConfig = {};
Expand Down Expand Up @@ -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);

}

Expand Down
28 changes: 28 additions & 0 deletions 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,
}
Empty file removed src/configValidater.js
Empty file.
28 changes: 13 additions & 15 deletions src/index.js
Expand Up @@ -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
Expand All @@ -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);
});
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 0 additions & 22 deletions src/lib/live2d.core.js

This file was deleted.

File renamed without changes.
12 changes: 0 additions & 12 deletions src/tmplate/innerHTML.html

This file was deleted.

File renamed without changes.
File renamed without changes.
15 changes: 13 additions & 2 deletions src/utils/wpPublicPath.js → src/wpPublicPath.js
Expand Up @@ -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/,
Expand All @@ -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__}`);
}
2 changes: 1 addition & 1 deletion webpack.config.js
Expand Up @@ -10,7 +10,7 @@ const isProd = e => e === 'prod';
module.exports = env => {return{

entry: [
'./src/utils/wpPublicPath.js',
'./src/wpPublicPath.js',
'./src/index.js',
],

Expand Down

0 comments on commit 62555a9

Please sign in to comment.