Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Huge updates #27

Merged
merged 16 commits into from
Nov 3, 2017
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion dist/bundle.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/device.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 44 additions & 36 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,6 @@ var url = require("url");

var generators = new Array();

var models = {
"Epsilon2.1": "Epsilon2.1/Epsilon2.1.model.json",
"Gantzert_Felixander": "Gantzert_Felixander/model.json",
"haru": "haru/haru.model.json",
"miku": "miku/miku.model.json",
"ni-j": "nito/ni-j.model.json",
"nico": "nito/nico.model.json",
"nito": "nito/nito.model.json",
"nipsilon": "nito/nipsilon.model.json",
"nietzsche": "nito/nietzche.model.json",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nito系列 (i.e. ni-j ,nico,nito, nipsilon, nietzche) 都用不了了

Copy link
Collaborator Author

@xiazeyu xiazeyu Oct 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--已查阅并更新
请仔细再次检查确保无误

"shizuku": "shizuku/shizuku.model.json",
"tsumiki": "tsumiki/tsumiki.model.json",
"wanko": "wanko/wanko.model.json",
"z16": "z16/z16.model.json",
"hibiki": "hibiki/hibiki.model.json",
"koharu": "koharu/koharu.model.json",
"haruto": "haruto/haruto.model.json",
"Unitychan": "Unitychan/unitychan.model.json",
"tororo": "tororo/tororo.model.json",
"hijiki": "hijiki/hijiki.model.json",
}

function registerFile(pathname, file) {
generators.push({
path: pathname,
Expand All @@ -42,38 +20,68 @@ function registerDir(pathname, dir) {
}, this);
}

hexo.extend.generator.register('live2d', function (locals) {
return generators;
});

registerDir('live2d/assets/', path.resolve(__dirname, './assets'));
registerFile('live2d/script.js', path.resolve(__dirname, './dist/bundle.js'))

hexo.extend.helper.register('live2d', function (config) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的 config 参数是否应该删除

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯,意思是这个hexo.helper只要传递一堆字符串就可以了吗?那个function(config)里的config变量是没用的?

var config = Object.assign(
{
model:"z16",
model: "z16",
width: 150,
height: 300,
mobileShow: "true",
mobileWidth: 75,
mobileHeight: 150,
position: "right",
horizontalOffset: 0,
bottomOffset: -20,
className: "live2d",
id: "live2dcanvas",
bottom: -20
},
config,
hexo.config.live2d
);

return `
<script type="text/javascript" src="/live2d/script.js"></script>
<canvas id="${config.id}" width="${config.width}" height="${config.height}" class="${config.className}"></canvas>
<style>
#${config.id} {
position: fixed;
right: 0px;
${config.position}: ${config.horizontalOffset}px;
z-index: 999;
pointer-events: none;
bottom: ${config.bottom}px;
bottom: ${config.bottomOffset}px;
}
</style>
<script>loadlive2d(${JSON.stringify(config.id)} ,${JSON.stringify(url.resolve("/live2d/assets/",models[config.model]))},0.5)</script>
<script src="live2d/device.min.js"></script>
<script type="text/javascript">
(function(){
if(device.mobile()){
if(${config.mobileShow}){
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

常见作者的pr“3.0”

document.getElementById("${config.id}").width = ${config.mobileWidth};
document.getElementById("${config.id}").height = ${config.mobileHeight};
document.write('<script type="text/javascript" src="/live2d/script.js"><\\/script>');
document.write('<script>loadlive2d(${JSON.stringify(config.id)}, ${JSON.stringify(url.resolve("/live2d/assets/", config.model + ".model.json"))}, 0.5)<\\/script>');
}
}else{
document.write('<script type="text/javascript" src="/live2d/script.js"><\\/script>');
document.write('<script>loadlive2d(${JSON.stringify(config.id)}, ${JSON.stringify(url.resolve("/live2d/assets/", config.model + ".model.json"))}, 0.5)<\\/script>');
}
})();
</script>
`
});
});


var config = Object.assign(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

更好地传递config

{
model: "z16",
},
config,
hexo.config.live2d
);

registerDir('live2d/assets/', path.resolve(__dirname, path.join('./assets/', config.model)));
registerFile('live2d/script.js', path.resolve(__dirname, './dist/bundle.js'));
registerFile('live2d/device.min.js', path.resolve(__dirname, './dist/device.min.js'));

hexo.extend.generator.register('live2d', function (locals) {
return generators;
});
Loading