Commit 53d8e362 authored by rockyl's avatar rockyl

增加偏移量参数设置

parent ce8ed08c
...@@ -82,6 +82,7 @@ const relativePosPrefixMap = { ...@@ -82,6 +82,7 @@ const relativePosPrefixMap = {
async function execute(psdFile, options) { async function execute(psdFile, options) {
const tree = await getTree(psdFile); const tree = await getTree(psdFile);
const offset = options ? options.offset : {x: 0, y: 0};
let viewRoot = { let viewRoot = {
name: path.basename(psdFile.name, '.psd'), name: path.basename(psdFile.name, '.psd'),
...@@ -92,7 +93,9 @@ async function execute(psdFile, options) { ...@@ -92,7 +93,9 @@ async function execute(psdFile, options) {
const assets = []; const assets = [];
const imageHashMap = {}; const imageHashMap = {};
const {width: stageWidth, height: stageHeight} = tree; let {width: stageWidth, height: stageHeight} = tree;
stageWidth -= offset.x || 0;
stageHeight -= offset.y || 0;
await walkNode(tree, async function (node, parent) { await walkNode(tree, async function (node, parent) {
let {name} = node; let {name} = node;
...@@ -101,6 +104,7 @@ async function execute(psdFile, options) { ...@@ -101,6 +104,7 @@ async function execute(psdFile, options) {
let properties = { let properties = {
width, height, alpha, visible, width, height, alpha, visible,
}; };
const isSecondLayer = !parent.origin.parent;
if (name.includes('|')) { if (name.includes('|')) {
try { try {
...@@ -126,10 +130,10 @@ async function execute(psdFile, options) { ...@@ -126,10 +130,10 @@ async function execute(psdFile, options) {
if(!hasValue){ if(!hasValue){
switch(fieldChar){ switch(fieldChar){
case 'l': case 'l':
value = x; value = x - offset.x;
break; break;
case 't': case 't':
value = y; value = y - offset.y;
break; break;
case 'r': case 'r':
value = stageWidth - width; value = stageWidth - width;
...@@ -183,10 +187,10 @@ async function execute(psdFile, options) { ...@@ -183,10 +187,10 @@ async function execute(psdFile, options) {
}; };
let dealLater = true; let dealLater = true;
if (x !== 0) { if (x !== 0) {
properties.x = x; properties.x = x - (isSecondLayer ? offset.x : 0);
} }
if (y !== 0) { if (y !== 0) {
properties.y = y; properties.y = y - (isSecondLayer ? offset.y : 0);
} }
if (typeTool) { if (typeTool) {
......
This diff is collapsed.
...@@ -88,6 +88,7 @@ const relativePosPrefixMap = { ...@@ -88,6 +88,7 @@ const relativePosPrefixMap = {
async function execute(psdFile, options) { async function execute(psdFile, options) {
const tree = await getTree(psdFile); const tree = await getTree(psdFile);
const offset = options ? options.offset : {x: 0, y: 0};
let viewRoot = { let viewRoot = {
name: path.basename(psdFile.name, '.psd'), name: path.basename(psdFile.name, '.psd'),
...@@ -98,7 +99,9 @@ async function execute(psdFile, options) { ...@@ -98,7 +99,9 @@ async function execute(psdFile, options) {
const assets = []; const assets = [];
const imageHashMap = {}; const imageHashMap = {};
const {width: stageWidth, height: stageHeight} = tree; let {width: stageWidth, height: stageHeight} = tree;
stageWidth -= offset.x || 0;
stageHeight -= offset.y || 0;
await walkNode(tree, async function (node, parent) { await walkNode(tree, async function (node, parent) {
let {name} = node; let {name} = node;
...@@ -107,6 +110,7 @@ async function execute(psdFile, options) { ...@@ -107,6 +110,7 @@ async function execute(psdFile, options) {
let properties = { let properties = {
width, height, alpha, visible, width, height, alpha, visible,
}; };
const isSecondLayer = !parent.origin.parent;
if (name.includes('|')) { if (name.includes('|')) {
try { try {
...@@ -132,10 +136,10 @@ async function execute(psdFile, options) { ...@@ -132,10 +136,10 @@ async function execute(psdFile, options) {
if(!hasValue){ if(!hasValue){
switch(fieldChar){ switch(fieldChar){
case 'l': case 'l':
value = x; value = x - offset.x;
break; break;
case 't': case 't':
value = y; value = y - offset.y;
break; break;
case 'r': case 'r':
value = stageWidth - width; value = stageWidth - width;
...@@ -189,10 +193,10 @@ async function execute(psdFile, options) { ...@@ -189,10 +193,10 @@ async function execute(psdFile, options) {
}; };
let dealLater = true; let dealLater = true;
if (x !== 0) { if (x !== 0) {
properties.x = x; properties.x = x - (isSecondLayer ? offset.x : 0);
} }
if (y !== 0) { if (y !== 0) {
properties.y = y; properties.y = y - (isSecondLayer ? offset.y : 0);
} }
if (typeTool) { if (typeTool) {
......
This diff is collapsed.
...@@ -88,6 +88,7 @@ ...@@ -88,6 +88,7 @@
async function execute(psdFile, options) { async function execute(psdFile, options) {
const tree = await getTree(psdFile); const tree = await getTree(psdFile);
const offset = options ? options.offset : {x: 0, y: 0};
let viewRoot = { let viewRoot = {
name: path.basename(psdFile.name, '.psd'), name: path.basename(psdFile.name, '.psd'),
...@@ -98,7 +99,9 @@ ...@@ -98,7 +99,9 @@
const assets = []; const assets = [];
const imageHashMap = {}; const imageHashMap = {};
const {width: stageWidth, height: stageHeight} = tree; let {width: stageWidth, height: stageHeight} = tree;
stageWidth -= offset.x || 0;
stageHeight -= offset.y || 0;
await walkNode(tree, async function (node, parent) { await walkNode(tree, async function (node, parent) {
let {name} = node; let {name} = node;
...@@ -107,6 +110,7 @@ ...@@ -107,6 +110,7 @@
let properties = { let properties = {
width, height, alpha, visible, width, height, alpha, visible,
}; };
const isSecondLayer = !parent.origin.parent;
if (name.includes('|')) { if (name.includes('|')) {
try { try {
...@@ -132,10 +136,10 @@ ...@@ -132,10 +136,10 @@
if(!hasValue){ if(!hasValue){
switch(fieldChar){ switch(fieldChar){
case 'l': case 'l':
value = x; value = x - offset.x;
break; break;
case 't': case 't':
value = y; value = y - offset.y;
break; break;
case 'r': case 'r':
value = stageWidth - width; value = stageWidth - width;
...@@ -189,10 +193,10 @@ ...@@ -189,10 +193,10 @@
}; };
let dealLater = true; let dealLater = true;
if (x !== 0) { if (x !== 0) {
properties.x = x; properties.x = x - (isSecondLayer ? offset.x : 0);
} }
if (y !== 0) { if (y !== 0) {
properties.y = y; properties.y = y - (isSecondLayer ? offset.y : 0);
} }
if (typeTool) { if (typeTool) {
......
This diff is collapsed.
...@@ -29,6 +29,7 @@ const relativePosPrefixMap = { ...@@ -29,6 +29,7 @@ const relativePosPrefixMap = {
export async function execute(psdFile, options) { export async function execute(psdFile, options) {
const tree = await getTree(psdFile); const tree = await getTree(psdFile);
const offset = options ? options.offset : {x: 0, y: 0};
let viewRoot = { let viewRoot = {
name: path.basename(psdFile.name, '.psd'), name: path.basename(psdFile.name, '.psd'),
...@@ -39,7 +40,9 @@ export async function execute(psdFile, options) { ...@@ -39,7 +40,9 @@ export async function execute(psdFile, options) {
const assets = []; const assets = [];
const imageHashMap = {}; const imageHashMap = {};
const {width: stageWidth, height: stageHeight} = tree; let {width: stageWidth, height: stageHeight} = tree;
stageWidth -= offset.x || 0;
stageHeight -= offset.y || 0;
await walkNode(tree, async function (node, parent) { await walkNode(tree, async function (node, parent) {
let {name} = node; let {name} = node;
...@@ -48,6 +51,7 @@ export async function execute(psdFile, options) { ...@@ -48,6 +51,7 @@ export async function execute(psdFile, options) {
let properties = { let properties = {
width, height, alpha, visible, width, height, alpha, visible,
}; };
const isSecondLayer = !parent.origin.parent;
const {width: parentWidth, height: parentHeight} = parent; const {width: parentWidth, height: parentHeight} = parent;
...@@ -75,10 +79,10 @@ export async function execute(psdFile, options) { ...@@ -75,10 +79,10 @@ export async function execute(psdFile, options) {
if(!hasValue){ if(!hasValue){
switch(fieldChar){ switch(fieldChar){
case 'l': case 'l':
value = x; value = x - offset.x;
break; break;
case 't': case 't':
value = y; value = y - offset.y;
break; break;
case 'r': case 'r':
value = stageWidth - width; value = stageWidth - width;
...@@ -132,10 +136,10 @@ export async function execute(psdFile, options) { ...@@ -132,10 +136,10 @@ export async function execute(psdFile, options) {
}; };
let dealLater = true; let dealLater = true;
if (x !== 0) { if (x !== 0) {
properties.x = x; properties.x = x - (isSecondLayer ? offset.x : 0);
} }
if (y !== 0) { if (y !== 0) {
properties.y = y; properties.y = y - (isSecondLayer ? offset.y : 0);
} }
if (typeTool) { if (typeTool) {
......
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