Commit 9552a48b authored by rockyl's avatar rockyl

修改上下裁剪机制

parent 5cc49b8f
......@@ -88,6 +88,10 @@ async function execute(psdFile, options) {
const tree = await getTree(psdFile);
const {mode = 'none', singleView = true} = options;
let offset = {x: 0, y: 0};
let cutSize = {x: 0, y: 0};
if (mode !== 'none') {
cutSize.y = offsetAll;
}
switch (mode) {
case 'top':
offset.y = offsetAll;
......@@ -97,6 +101,8 @@ async function execute(psdFile, options) {
break;
}
const isCenter = mode === 'center';
let viewRoot = {
name: path.basename(psdFile.name, '.psd'),
type: 'node',
......@@ -106,6 +112,10 @@ async function execute(psdFile, options) {
const assets = [];
const imageHashMap = {};
let {width: stageWidthOrigin, height: stageHeightOrigin} = tree;
const stageWidth = stageWidthOrigin - cutSize.x || 0;
const stageHeight = stageHeightOrigin - cutSize.y || 0;
await walkNode(tree, async function (node, parent) {
let {name} = node;
const {x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
......@@ -113,17 +123,21 @@ async function execute(psdFile, options) {
let properties = {
width, height, alpha, visible,
};
const isSecondLayer = !parent.origin.parent;
const isSecondLayer = singleView && !parent.origin.parent || !singleView && parent.origin.parent && !parent.origin.parent.parent;
const shouldVerticalCenter = isSecondLayer && isCenter;
const {width: parentWidth, height: parentHeight} = parent;
if (name.includes('|')) {
if (name.includes('|') || shouldVerticalCenter) {
try {
let arr = name.split('|');
name = arr[0];
let paramsStr = arr[1];
let params = paramsStr.split(';');
let relativePos = params[0];
let relativePos;
if(paramsStr){
let params = paramsStr.split(';');
relativePos = params[0];
}else if(shouldVerticalCenter){
relativePos = 'v';
}
if (relativePos) {
let items = relativePos.split(',');
for (let item of items) {
......@@ -147,16 +161,16 @@ async function execute(psdFile, options) {
value = y - offset.y;
break;
case 'r':
value = parentWidth - (x - offset.x) - width;
value = stageWidth - (x - offset.x) - width;
break;
case 'b':
value = parentHeight - (y - offset.y) - height;
value = stageHeight - (y - offset.y) - height;
break;
case 'h':
value = x + width / 2 - parentWidth / 2;
value = x + width / 2 - stageWidthOrigin / 2;
break;
case 'v':
value = y + height / 2 - parentHeight / 2;
value = y + height / 2 - stageHeightOrigin / 2;
break;
}
}
......@@ -166,11 +180,11 @@ async function execute(psdFile, options) {
switch (fieldChar) {
case 'l':
case 'r':
value /= parentWidth;
value /= stageWidth;
break;
case 't':
case 'b':
value /= parentHeight;
value /= stageHeight;
break;
}
value = Math.floor(value * 100);
......
This diff is collapsed.
......@@ -94,6 +94,10 @@ async function execute(psdFile, options) {
const tree = await getTree(psdFile);
const {mode = 'none', singleView = true} = options;
let offset = {x: 0, y: 0};
let cutSize = {x: 0, y: 0};
if (mode !== 'none') {
cutSize.y = offsetAll;
}
switch (mode) {
case 'top':
offset.y = offsetAll;
......@@ -103,6 +107,8 @@ async function execute(psdFile, options) {
break;
}
const isCenter = mode === 'center';
let viewRoot = {
name: path.basename(psdFile.name, '.psd'),
type: 'node',
......@@ -112,6 +118,10 @@ async function execute(psdFile, options) {
const assets = [];
const imageHashMap = {};
let {width: stageWidthOrigin, height: stageHeightOrigin} = tree;
const stageWidth = stageWidthOrigin - cutSize.x || 0;
const stageHeight = stageHeightOrigin - cutSize.y || 0;
await walkNode(tree, async function (node, parent) {
let {name} = node;
const {x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
......@@ -119,17 +129,21 @@ async function execute(psdFile, options) {
let properties = {
width, height, alpha, visible,
};
const isSecondLayer = !parent.origin.parent;
const isSecondLayer = singleView && !parent.origin.parent || !singleView && parent.origin.parent && !parent.origin.parent.parent;
const shouldVerticalCenter = isSecondLayer && isCenter;
const {width: parentWidth, height: parentHeight} = parent;
if (name.includes('|')) {
if (name.includes('|') || shouldVerticalCenter) {
try {
let arr = name.split('|');
name = arr[0];
let paramsStr = arr[1];
let params = paramsStr.split(';');
let relativePos = params[0];
let relativePos;
if(paramsStr){
let params = paramsStr.split(';');
relativePos = params[0];
}else if(shouldVerticalCenter){
relativePos = 'v';
}
if (relativePos) {
let items = relativePos.split(',');
for (let item of items) {
......@@ -153,16 +167,16 @@ async function execute(psdFile, options) {
value = y - offset.y;
break;
case 'r':
value = parentWidth - (x - offset.x) - width;
value = stageWidth - (x - offset.x) - width;
break;
case 'b':
value = parentHeight - (y - offset.y) - height;
value = stageHeight - (y - offset.y) - height;
break;
case 'h':
value = x + width / 2 - parentWidth / 2;
value = x + width / 2 - stageWidthOrigin / 2;
break;
case 'v':
value = y + height / 2 - parentHeight / 2;
value = y + height / 2 - stageHeightOrigin / 2;
break;
}
}
......@@ -172,11 +186,11 @@ async function execute(psdFile, options) {
switch (fieldChar) {
case 'l':
case 'r':
value /= parentWidth;
value /= stageWidth;
break;
case 't':
case 'b':
value /= parentHeight;
value /= stageHeight;
break;
}
value = Math.floor(value * 100);
......
This diff is collapsed.
......@@ -94,6 +94,10 @@
const tree = await getTree(psdFile);
const {mode = 'none', singleView = true} = options;
let offset = {x: 0, y: 0};
let cutSize = {x: 0, y: 0};
if (mode !== 'none') {
cutSize.y = offsetAll;
}
switch (mode) {
case 'top':
offset.y = offsetAll;
......@@ -103,6 +107,8 @@
break;
}
const isCenter = mode === 'center';
let viewRoot = {
name: path.basename(psdFile.name, '.psd'),
type: 'node',
......@@ -112,6 +118,10 @@
const assets = [];
const imageHashMap = {};
let {width: stageWidthOrigin, height: stageHeightOrigin} = tree;
const stageWidth = stageWidthOrigin - cutSize.x || 0;
const stageHeight = stageHeightOrigin - cutSize.y || 0;
await walkNode(tree, async function (node, parent) {
let {name} = node;
const {x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
......@@ -119,17 +129,21 @@
let properties = {
width, height, alpha, visible,
};
const isSecondLayer = !parent.origin.parent;
const isSecondLayer = singleView && !parent.origin.parent || !singleView && parent.origin.parent && !parent.origin.parent.parent;
const shouldVerticalCenter = isSecondLayer && isCenter;
const {width: parentWidth, height: parentHeight} = parent;
if (name.includes('|')) {
if (name.includes('|') || shouldVerticalCenter) {
try {
let arr = name.split('|');
name = arr[0];
let paramsStr = arr[1];
let params = paramsStr.split(';');
let relativePos = params[0];
let relativePos;
if(paramsStr){
let params = paramsStr.split(';');
relativePos = params[0];
}else if(shouldVerticalCenter){
relativePos = 'v';
}
if (relativePos) {
let items = relativePos.split(',');
for (let item of items) {
......@@ -153,16 +167,16 @@
value = y - offset.y;
break;
case 'r':
value = parentWidth - (x - offset.x) - width;
value = stageWidth - (x - offset.x) - width;
break;
case 'b':
value = parentHeight - (y - offset.y) - height;
value = stageHeight - (y - offset.y) - height;
break;
case 'h':
value = x + width / 2 - parentWidth / 2;
value = x + width / 2 - stageWidthOrigin / 2;
break;
case 'v':
value = y + height / 2 - parentHeight / 2;
value = y + height / 2 - stageHeightOrigin / 2;
break;
}
}
......@@ -172,11 +186,11 @@
switch (fieldChar) {
case 'l':
case 'r':
value /= parentWidth;
value /= stageWidth;
break;
case 't':
case 'b':
value /= parentHeight;
value /= stageHeight;
break;
}
value = Math.floor(value * 100);
......
This diff is collapsed.
......@@ -48,6 +48,8 @@ export async function execute(psdFile, options) {
break;
}
const isCenter = mode === 'center';
let viewRoot = {
name: path.basename(psdFile.name, '.psd'),
type: 'node',
......@@ -57,9 +59,9 @@ export async function execute(psdFile, options) {
const assets = [];
const imageHashMap = {};
let {width: stageWidth, height: stageHeight} = tree;
stageWidth -= cutSize.x || 0;
stageHeight -= cutSize.y || 0;
let {width: stageWidthOrigin, height: stageHeightOrigin} = tree;
const stageWidth = stageWidthOrigin - cutSize.x || 0;
const stageHeight = stageHeightOrigin - cutSize.y || 0;
await walkNode(tree, async function (node, parent) {
let {name} = node;
......@@ -68,17 +70,23 @@ export async function execute(psdFile, options) {
let properties = {
width, height, alpha, visible,
};
const isSecondLayer = !parent.origin.parent;
const isSecondLayer = singleView && !parent.origin.parent || !singleView && parent.origin.parent && !parent.origin.parent.parent;
const shouldVerticalCenter = isSecondLayer && isCenter;
const {width: parentWidth, height: parentHeight} = parent;
if (name.includes('|')) {
if (name.includes('|') || shouldVerticalCenter) {
try {
let arr = name.split('|');
name = arr[0];
let paramsStr = arr[1];
let params = paramsStr.split(';');
let relativePos = params[0];
let relativePos;
if(paramsStr){
let params = paramsStr.split(';');
relativePos = params[0];
}else if(shouldVerticalCenter){
relativePos = 'v';
}
if (relativePos) {
let items = relativePos.split(',');
for (let item of items) {
......@@ -102,16 +110,16 @@ export async function execute(psdFile, options) {
value = y - offset.y;
break;
case 'r':
value = parentWidth - (x - offset.x) - width;
value = stageWidth - (x - offset.x) - width;
break;
case 'b':
value = parentHeight - (y - offset.y) - height;
value = stageHeight - (y - offset.y) - height;
break;
case 'h':
value = x + width / 2 - parentWidth / 2;
value = x + width / 2 - stageWidthOrigin / 2;
break;
case 'v':
value = y + height / 2 - parentHeight / 2;
value = y + height / 2 - stageHeightOrigin / 2;
break;
}
}
......@@ -121,11 +129,11 @@ export async function execute(psdFile, options) {
switch (fieldChar) {
case 'l':
case 'r':
value /= parentWidth;
value /= stageWidth;
break;
case 't':
case 'b':
value /= parentHeight;
value /= stageHeight;
break;
}
value = Math.floor(value * 100);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment