Commit 10ae6f6e authored by 李维's avatar 李维

Bug fix

parent c58b3a1c
......@@ -208,9 +208,9 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
this.refresh();
/* Remove this when commit */
// if(location.href.indexOf("localhost") != -1) {
// (<any> window).axios.post(`http://www.datalist.com.cn:8060/json/save/${this.KEY}`, this.item)
// }
if(location.href.indexOf("localhost") != -1) {
(<any> window).axios.post(`http://www.datalist.com.cn:8060/json/save/${this.KEY}`, this.item)
}
/* Remove this when commit */
console.log("保存", this.item)
......
......@@ -275,8 +275,10 @@ export default class Cartoon {
// console.log(`Get remote image from [${url}]`)
return new Promise((resovle, reject) => {
this.getSpriteFrimeByUrl(url).then((fr)=>{
let sx = width / fr.getRect().width;
let sy = height / fr.getRect().height;
let relWidth = fr.getRect().width;
let relHeight = fr.getRect().height;
let sx = width / relWidth;
let sy = height / relHeight;
let s = 1;
if(fillType) {
s = Math.max(sx, sy)
......@@ -287,15 +289,20 @@ export default class Cartoon {
// fr.width = s * fr.getRect().width;
// fr.height = s * fr.getRect().height;
node.getComponent(cc.Sprite).spriteFrame = fr;
resovle()
resovle([relWidth, relHeight])
})
})
}
mountLocalImageToNode(name, node, width, height, fillType) {
// console.log(`Get local image from [Canvas/res/img/${name}]`)
let relWidth = null;
let relHeight = null;
if(name) {
const sf = cc.find('Canvas/res/img/' + name).getComponent(cc.Sprite).spriteFrame;
relWidth = fr.getRect().width;
relHeight = fr.getRect().height;
let sx = width / sf.getRect().width;
let sy = height / sf.getRect().height;
let s = 1;
......@@ -307,7 +314,10 @@ export default class Cartoon {
node.setScale(s)
node.getComponent(cc.Sprite).spriteFrame = sf;
}
return node;
return new Promise((resolve, reject) => {
resovle([relWidth, relHeight])
});
}
mountImageToNode(url, node, width, height, fillType) {
......@@ -315,10 +325,7 @@ export default class Cartoon {
if(urlreg.test(url)) {
return this.mountRemoteImageToNode(url, node, width, height, fillType)
} else {
this.mountLocalImageToNode(url, node, width, height, fillType)
return new Promise((resolve, reject)=>{
resolve()
})
return this.mountLocalImageToNode(url, node, width, height, fillType)
}
}
......
......@@ -469,7 +469,15 @@ export default class GameLogic {
if(item.type == 'Image') {
let image = bubble.node.getChildByName("image_container")
image.active = true;
this.g_cartoon.mountImageToNode(item.image_url, image, 160, 80)
this.g_cartoon.mountImageToNode(item.image_url, image, 160, 80).then(([width, height]) => {
let s = width / height
let r = 165
let h = Math.floor(Math.sqrt(r*r / (s*s + 1)))
let w = s * h
image.scaleX = w / width;
image.scaleY = h / height;
})
} else {
let text = bubble.node.getChildByName("text_container")
text.active = true;
......
......@@ -110,15 +110,14 @@ cc.Class({
},
getData(cb) {
cb(this.getDefaultData());
// cc.loader.load( "http://www.datalist.com.cn:8060/json/DataKey_dfzx_ppp", function( err, res) {
// console.log(res)
// if(err) {
// cb(this.getDefaultData());
// } else {
// cb(JSON.parse(res));
// }
// });
// cb(this.getDefaultData());
cc.loader.load( "http://www.datalist.com.cn:8060/json/DataKey_dfzx_ppp", function( err, res) {
if(err) {
cb(this.getDefaultData());
} else {
cb(JSON.parse(res));
}
});
},
getDefaultData() {
......
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