添加持久化逻辑
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { G_ShowScoreTips } from "../views/GUITips";
|
||||
import { DOBlock } from "./DOBlock";
|
||||
|
||||
const { regClass, property } = Laya;
|
||||
|
||||
@@ -15,18 +16,14 @@ export class Block extends Laya.Script {
|
||||
@property(Number)
|
||||
public YGroup: number = 0;
|
||||
|
||||
private selected: boolean = false
|
||||
private newSelect: boolean = false
|
||||
private preset: boolean = false//预设格子
|
||||
private checked: boolean = false//正确格子
|
||||
private showNumber: number = 0;
|
||||
private correctNumber: number = 0;
|
||||
private score: number = 0
|
||||
private note_numbers: Array<number> = new Array()
|
||||
|
||||
private label_show: Laya.Label;
|
||||
private tips_labels: Array<Laya.Label> = new Array();
|
||||
private animator: Laya.Animator2D
|
||||
|
||||
private selected: boolean = false
|
||||
private newSelect: boolean = false
|
||||
|
||||
private data: DOBlock
|
||||
|
||||
public onInit(XIndex: number, YIndex: number, XGroup: number, YGroup: number, label_obj: Laya.Box, handler: any, func: any): void {
|
||||
this.XIndex = XIndex;
|
||||
@@ -68,69 +65,43 @@ export class Block extends Laya.Script {
|
||||
}
|
||||
}
|
||||
|
||||
public setBlock(preset: boolean, showNumber: number, correctNumber: number): void {
|
||||
this.preset = preset;
|
||||
this.checked = preset;
|
||||
this.showNumber = showNumber;
|
||||
this.correctNumber = correctNumber;
|
||||
this.score = 0
|
||||
public setBlock(data: DOBlock): void {
|
||||
this.data = data;
|
||||
this.updateBlock();
|
||||
}
|
||||
|
||||
public getIsPreset(): boolean {
|
||||
return this.preset;
|
||||
}
|
||||
|
||||
public getIsChecked(): boolean {
|
||||
return this.checked;
|
||||
}
|
||||
|
||||
public getShowNumber(): number {
|
||||
return this.showNumber;
|
||||
public getData(): DOBlock {
|
||||
return this.data
|
||||
}
|
||||
|
||||
public setShowNumber(showNumber: number): boolean {
|
||||
if (this.checked == false) {
|
||||
if (showNumber == this.correctNumber)
|
||||
this.checked = true;
|
||||
this.showNumber = showNumber;
|
||||
if (this.checked || showNumber == 0) {//正确或者擦除
|
||||
this.note_numbers = new Array()
|
||||
}
|
||||
this.score = 0
|
||||
if (this.data.get_checked() == false) {
|
||||
this.data.set_show(showNumber)
|
||||
var score: number = 0
|
||||
if (this.newSelect) {
|
||||
this.newSelect = false
|
||||
if (this.checked) {
|
||||
this.score = 150
|
||||
G_ShowScoreTips(this.score.toString(), this.owner)
|
||||
if (this.data.get_checked()) {
|
||||
score = 150
|
||||
this.data.set_score(score)
|
||||
G_ShowScoreTips(score.toString(), this.owner)
|
||||
}
|
||||
}
|
||||
this.updateBlock();
|
||||
this.updateBlock()
|
||||
}
|
||||
return this.checked
|
||||
}
|
||||
|
||||
public getCorrectNumber(): number {
|
||||
return this.correctNumber;
|
||||
}
|
||||
|
||||
public getScore(): number {
|
||||
return this.score
|
||||
return this.data.get_checked()
|
||||
}
|
||||
|
||||
public addNoteNumber(noteNumber: number): void {
|
||||
if (this.note_numbers.indexOf(noteNumber) < 0) {
|
||||
this.note_numbers.push(noteNumber)
|
||||
this.updateBlock();
|
||||
if (this.data.add_note(noteNumber)) {
|
||||
this.updateBlock()
|
||||
}
|
||||
}
|
||||
|
||||
updateBlock(): void {
|
||||
for (var i=0; i<this.tips_labels.length; i++)
|
||||
this.tips_labels[i].text = ""
|
||||
if (this.showNumber > 0) {
|
||||
this.label_show.text = this.showNumber.toString();
|
||||
if (this.checked) {
|
||||
if (this.data.get_show() > 0) {
|
||||
this.label_show.text = this.data.get_show().toString()
|
||||
if (this.data.get_checked()) {
|
||||
this.label_show.color = "#000000"
|
||||
}
|
||||
else {
|
||||
@@ -139,8 +110,9 @@ export class Block extends Laya.Script {
|
||||
}
|
||||
else {
|
||||
this.label_show.text = "";
|
||||
for (var i=0; i<this.note_numbers.length; i++) {
|
||||
var value = this.note_numbers[i]
|
||||
var note_numbers = this.data.get_notes()
|
||||
for (var i=0; i<note_numbers.length; i++) {
|
||||
var value = note_numbers[i]
|
||||
var label = this.tips_labels[value-1]
|
||||
label.text = value.toString()
|
||||
if (this.selected) {
|
||||
|
||||
Reference in New Issue
Block a user