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

Commit aa09c5d

Browse files
committed
feat: elementMgr functionally done
1 parent b342953 commit aa09c5d

File tree

4 files changed

+22
-26
lines changed

4 files changed

+22
-26
lines changed

src/cLive2DApp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ let opacityHover = 1;
4242
*/
4343

4444
import { config } from './config/configMgr';
45-
import { createElement, currWebGL } from './elementManager';
45+
import { createElement, currWebGL } from './elementMgr';
4646

4747
/**
4848
* Main function of live2d-widget

src/elementManager.js renamed to src/elementMgr.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let currWebGL = undefined;
1515

1616
/**
1717
* The current canvas element
18-
* @type {DOMString}
18+
* @type {HTMLElement}
1919
*/
2020

2121
let currCanvas;
@@ -29,9 +29,25 @@ function createElement(){
2929

3030
let newElem = document.createElement('div');
3131
newElem.id = config.name.div;
32-
newElem.innerHTML = htmlTemplate(config);
32+
newElem.innerHTML = htmlTemplate;
33+
let newCanvasElem = document.createElement('canvas');
34+
newCanvasElem.setAttribute('id', config.name.canvas);
35+
newCanvasElem.setAttribute('width', config.display.width * config.display.antialias);
36+
newCanvasElem.setAttribute('height', config.display.height * config.display.antialias);
37+
newCanvasElem.style.setProperty('position', 'fixed');
38+
newCanvasElem.style.setProperty('width', config.display.width);
39+
newCanvasElem.style.setProperty('height', config.display.height);
40+
newCanvasElem.style.setProperty('opacity', config.react.opacityDefault);
41+
newCanvasElem.style.setProperty(config.display.position, config.display.hOffset + 'px');
42+
newCanvasElem.style.setProperty('bottom', config.display.vOffset + 'px');
43+
newCanvasElem.style.setProperty('z-index', 99999);
44+
newCanvasElem.style.setProperty('pointer-events', 'none');
45+
if(config.dev.border) newCanvasElem.style.setProperty('border', 'dashed 1px #CCC');
46+
newElem.appendChild(newCanvasElem);
47+
3348
document.body.appendChild(newElem);
3449
currCanvas = document.getElementById(config.name.canvas);
50+
3551
initWebGL();
3652

3753
}
@@ -55,7 +71,7 @@ function initWebGL(){
5571
if(ctx) currWebGL = ctx;
5672
}catch(e){}
5773
}
58-
if(!gl){
74+
if(!currWebGL){
5975
console.error('Live2D widgets: Failed to create WebGL context.');
6076
if(!window.WebGLRenderingContext){
6177
console.error('Your browser may not support WebGL, check https://get.webgl.org/ for futher information.');

src/tmplate/innerHTML.html

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +0,0 @@
1-
function htmlTemplate(config){
2-
return `<canvas id="${config.name.canvas}" width="${config.display.widget * config.display.AA}" height="${config.display.height * config.display.AA}"></canvas>
3-
<style>
4-
#${config.name.canvas}{
5-
position: fixed;
6-
width: ${config.display.widget};
7-
height: ${config.display.height};
8-
opacity: ${config.react.opacityDefault};
9-
${config.display.position}: ${config.display.hOffset};
10-
bottom: ${config.display.vOffset};
11-
z-index: 99999;
12-
pointer-events: none;
13-
${config.dev.border ? 'border: dashed 1px #CCC;' : ''}
14-
}
15-
</style>`
16-
}
17-
18-
export {
19-
htmlTemplate,
20-
}

webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ module.exports = env => {return{
8080
use: [{
8181
loader: 'babel-loader',
8282
}],
83-
},/*
83+
},
8484
{test: /\.html$/,
8585
use: [{
8686
loader: 'html-loader',
8787
options: {
8888
minimize: true,
8989
},
9090
}],
91-
},*/
91+
},
9292
]
9393
},
9494
}}

0 commit comments

Comments
 (0)