Commit 50ca08f1 authored by 李维's avatar 李维

feat: 添加聚合组概念

parent f34552a8
......@@ -295,13 +295,22 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (!isIn) {
this.onMeetFail(node);
} else {
// 未碰撞到
// 判定碰撞坐标和区域
let { targetData, targetItem } = this.checkSuccess(node)
let { targetData, targetItem } = this.checkSuccess(node);
if (!targetData) {
this.onMeetFail(node);
} else {
if (node.data.text != targetData.text) {
let targetGroup = (targetData.aggregationGroup != null && targetData.aggregationGroup > 0) ? targetData.aggregationGroup : 0;
let nodeGroup = (node.data.aggregationGroup != null && node.data.aggregationGroup > 0) ? node.data.aggregationGroup : 0;
let isMatch = false;
if (targetGroup === 0) {
// 无聚合组:必须文本与槽位完全对应
isMatch = (node.data.text === targetData.text);
} else {
// 有聚合组:只要拖放的单词属于该组,且槽位属于同一组即可(同组内位置可互换)
isMatch = (nodeGroup === targetGroup);
}
if (!isMatch) {
this.onMeetFail(node);
} else {
targetItem.active = false;
......@@ -311,23 +320,24 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
}
// 检测碰撞成功需要重新编写
// 检测碰撞:找到距离最近的、尚未被占用的目标槽位
checkSuccess(node) {
// 左上角坐标
let targetData = null;
let targetItem = null;
let minDis = 999999;
let items = this.layout_target.children;
items.forEach((item, i) => {
if (!item.active) return; // 已占用的槽位不再参与匹配
let data = item.data;
if (!data) return;
let dis = this.getDistances(item, node);
if (dis < 100 && dis < minDis) {
minDis = dis;
targetData = data;
targetItem = item;
}
})
return { targetData, targetItem }
});
return { targetData, targetItem };
}
private changepoints(data, bgImg) {
......
......@@ -1956,6 +1956,7 @@ export class HotZoneItem extends MySprite {
audio_url;
pic_url;
text;
aggregationGroup: number = 0;
private _itemType;
private shapeRect: ShapeRect;
......
......@@ -41,6 +41,18 @@
</nz-radio-group>
</div>
<div style="margin-top: 5px; margin-bottom: 5px">
<span>聚合组:</span>
<nz-select style="width: 100%;" [(ngModel)]="it.aggregationGroup" nzPlaceHolder="选择聚合组">
<nz-option [nzValue]="0" nzLabel="不聚合"></nz-option>
<nz-option [nzValue]="1" nzLabel="聚合组1"></nz-option>
<nz-option [nzValue]="2" nzLabel="聚合组2"></nz-option>
<nz-option [nzValue]="3" nzLabel="聚合组3"></nz-option>
<nz-option [nzValue]="4" nzLabel="聚合组4"></nz-option>
<nz-option [nzValue]="5" nzLabel="聚合组5"></nz-option>
</nz-select>
</div>
<div *ngIf="it.itemType == 'pic'">
<app-upload-image-with-preview
[picUrl]="it?.pic_url"
......
......@@ -249,6 +249,7 @@ export class CustomHotZoneComponent implements OnInit, OnDestroy, OnChanges {
item.y = this.canvasHeight / 2;
item.itemType = this.defaultItemType;
item.aggregationGroup = saveData && saveData.aggregationGroup != null ? saveData.aggregationGroup : 0;
if (saveData) {
......@@ -449,6 +450,7 @@ export class CustomHotZoneComponent implements OnInit, OnDestroy, OnChanges {
item.pic_url = data.pic_url;
item.text = data.text;
item.itemType = data.itemType;
item.aggregationGroup = data.aggregationGroup != null ? data.aggregationGroup : 0;
this.refreshItem(item);
console.log('item: ', item);
......@@ -875,6 +877,7 @@ export class CustomHotZoneComponent implements OnInit, OnDestroy, OnChanges {
text: hotZoneArr[i].text,
audio_url: hotZoneArr[i].audio_url,
itemType: hotZoneArr[i].itemType,
aggregationGroup: hotZoneArr[i].aggregationGroup != null ? hotZoneArr[i].aggregationGroup : 0,
fontSize: this.hotZoneFontObj.size,
fontName: this.hotZoneFontObj.name,
fontColor: this.hotZoneFontObj.color,
......
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