移动脚本目录

This commit is contained in:
2025-05-14 19:22:21 +08:00
parent 830bf2bb29
commit f229ce7fa0
12 changed files with 8 additions and 9 deletions

View File

@@ -1,128 +0,0 @@
import { G_ShowScoreTips } from "../views/GUITips";
import { DOBlock } from "./DOBlock";
const { regClass, property } = Laya;
@regClass()
export class Block extends Laya.Script {
declare owner : Laya.Button;
@property(Number)
public XIndex: number = 0;
@property(Number)
public YIndex: number = 0;
@property(Number)
public XGroup: number = 0;
@property(Number)
public YGroup: number = 0;
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;
this.YIndex = YIndex;
this.XGroup = XGroup;
this.YGroup = YGroup;
this.label_show = label_obj.getChildByName("label_show") as Laya.Label
var VBox = label_obj.getChildByName("VBox")
for (var i=0; i<VBox.numChildren; i++) {
var hbox = VBox.getChildAt(i);
for (var j=0; j<hbox.numChildren; j++) {
var Label = hbox.getChildAt(j) as Laya.Label
Label.text = ""
this.tips_labels.push(Label)
}
}
this.owner.on(Laya.Event.CLICK, handler, func);
this.animator = this.owner.getComponent(Laya.Animator2D)
}
public setSelected(selected: boolean): void {
this.selected = selected
if (selected)
this.newSelect = true
this.updateBlock()
}
public setButtonSkin(skin: string): void {
this.owner.skin = skin
}
public setFadeAnimation(): void {
if (this.animator) {
this.animator.play("fade_to_red")
Laya.timer.frameOnce(40, this, ()=>{
this.animator.stop()
})
}
}
public setBlock(data: DOBlock): void {
this.data = data;
this.updateBlock();
}
public getData(): DOBlock {
return this.data
}
public setShowNumber(showNumber: number): boolean {
if (this.data.get_checked() == false) {
this.data.set_show(showNumber)
var score: number = 0
if (this.newSelect) {
this.newSelect = false
if (this.data.get_checked()) {
score = 150
this.data.set_score(score)
G_ShowScoreTips(score.toString(), this.owner)
}
}
this.updateBlock()
}
return this.data.get_checked()
}
public addNoteNumber(noteNumber: number): void {
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.data.get_show() > 0) {
this.label_show.text = this.data.get_show().toString()
if (this.data.get_checked()) {
this.label_show.color = "#000000"
}
else {
this.label_show.color = "#ff0000"
}
}
else {
this.label_show.text = "";
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) {
label.color = "#ffffff"
}
else {
label.color = "#000000"
}
}
}
}
}

View File

@@ -1,3 +0,0 @@
{
"uuid": "abc6b60b-980b-4853-baa5-ac8506e00c4a"
}

View File

@@ -1,51 +0,0 @@
import { DOCandy } from "./DOCandy";
const { regClass, property } = Laya;
@regClass()
export class Candy extends Laya.Script {
declare owner : Laya.Button;
private label_show: Laya.Label;
private label_left: Laya.Label;
private data: DOCandy
public onInit(label_obj: Laya.Box, handler: any, func: any): void {
this.label_show = label_obj.getChildByName("label") as Laya.Label
this.label_left = label_obj.getChildByName("label_left") as Laya.Label
this.owner.on(Laya.Event.CLICK, handler, func)
}
public setCandy(data: DOCandy): void {
this.data = data
this.updateCandy()
}
public getData(): DOCandy {
return this.data
}
public setLeft(left: number): void {
this.data.set_left(left)
this.updateCandy()
}
updateCandy(): void {
if (this.data.get_show() > 0) {
this.label_show.text = this.data.get_show().toString()
}
else {
this.label_show.text = ""
}
if (this.data.get_left() > 0) {
this.label_left.text = this.data.get_left().toString();
this.owner.visible = true
}
else {
this.label_left.text = ""
this.owner.visible = false
this.label_show.text = ""
}
}
}

View File

@@ -1,3 +0,0 @@
{
"uuid": "067a5d3a-4d7c-48d7-bb01-db2682fd6c01"
}

View File

@@ -1,80 +0,0 @@
import { StorageManager } from "../models/StorageManager"
export class DOBlock {
private data: any
private preset: boolean = false//预设格子
private correct: number = 0;
private checked: boolean = false//是否正确
constructor(dataBlock: any, preset: boolean, correct: number) {
this.data = dataBlock
this.preset = preset
this.correct = correct
this.checked = preset || (dataBlock.show == correct)
}
//====================================持久化数据
public get_index(): number {
return this.data.index
}
public get_show(): number {
return this.data.show
}
public set_show(show: number): void {
this.data.show = show
if (show == this.get_correct())
this.checked = true
if (this.get_checked() || show == 0)
this.clean_notes()//正确或者擦除
StorageManager.getInstance().onChanged()
}
public get_score(): number {
return this.data.score
}
public set_score(score: number): void {
this.data.score = score
StorageManager.getInstance().onChanged()
}
public get_notes(): Array<number> {
return this.data.notes
}
public add_note(noteNumber: number): boolean {
var b = false
if (this.data.notes.indexOf(noteNumber) < 0) {
this.data.notes.push(noteNumber)
StorageManager.getInstance().onChanged()
b = true
}
return b
}
public clean_notes(): void {
if (this.data.notes.length > 0) {
this.data.notes = new Array()
StorageManager.getInstance().onChanged()
}
}
//====================================持久化数据
public get_preset(): boolean {
return this.preset
}
public get_correct(): number {
return this.correct
}
public get_checked(): boolean {
return this.checked
}
}

View File

@@ -1,3 +0,0 @@
{
"uuid": "aeb99474-1a9f-4a01-ac79-3416ec39a309"
}

View File

@@ -1,33 +0,0 @@
import { StorageManager } from "../models/StorageManager"
export class DOCandy {
private data: any
private show: number
constructor(dataCandy: any, show: number) {
this.data = dataCandy
this.show = show
}
//====================================持久化数据
public get_left(): number {
return this.data.left
}
public set_left(left: number): void {
this.data.left = left
StorageManager.getInstance().onChanged()
}
//====================================持久化数据
public get_show(): number {
return this.show
}
}

View File

@@ -1,3 +0,0 @@
{
"uuid": "0c3f05a2-7935-4847-8760-858002151854"
}

View File

@@ -1,139 +0,0 @@
import { StorageManager } from "../models/StorageManager"
import { DOBlock } from "./DOBlock"
import { DOCandy } from "./DOCandy"
export class DOStage {
private data: any
private blocks: Array<DOBlock> = new Array()
private candys: Array<DOCandy> = new Array()
private letterToNumber: any;
private numberToLetter: any;
constructor(dataStage: any, levelStr: string) {
this.data = dataStage
this.letterToNumber = new Map();
this.letterToNumber.set("A", 1);
this.letterToNumber.set("B", 2);
this.letterToNumber.set("C", 3);
this.letterToNumber.set("D", 4);
this.letterToNumber.set("E", 5);
this.letterToNumber.set("F", 6);
this.letterToNumber.set("G", 7);
this.letterToNumber.set("H", 8);
this.letterToNumber.set("I", 9);
this.numberToLetter = new Map();
this.numberToLetter.set(1, "a");
this.numberToLetter.set(2, "b");
this.numberToLetter.set(3, "c");
this.numberToLetter.set(4, "d");
this.numberToLetter.set(5, "e");
this.numberToLetter.set(6, "f");
this.numberToLetter.set(7, "g");
this.numberToLetter.set(8, "h");
this.numberToLetter.set(9, "i");
var blockMap: Map<number, any> = new Map()
for (var i=0; i<this.data.blocks.length; i++) {
var dataBlock = this.data.blocks[i]
blockMap.set(dataBlock.index, dataBlock)
}
if (levelStr.length != 81) {
console.log("levelStr error", levelStr.length)
}
var list = new Map();
for (var i=0; i<levelStr.length; i++) {
var letter = levelStr[i];
if (this.letterToNumber.has(letter)) {//预设格子 使用配置文件初始化
var show = this.letterToNumber.get(letter)
var dataBlock = StorageManager.createDataBlock(i, show)
var doBlock = new DOBlock(dataBlock, true, show)
this.blocks.push(doBlock)
}
else {
var show = this.letterToNumber.get(letter.toUpperCase())
var dataBlock = blockMap.get(i)
if (dataBlock) {//本地有持久化数据
var doBlock = new DOBlock(dataBlock, false, show)
this.blocks.push(doBlock)
}
else {
dataBlock = StorageManager.createDataBlock(i, 0)
this.data.blocks.push(dataBlock)
var doBlock = new DOBlock(dataBlock, false, show)
this.blocks.push(doBlock)
}
if (list.has(letter)) {
list.set(letter, list.get(letter)+1);
}
else {
list.set(letter, 1);
}
}
}
for (var i=1; i<=9; i++) {
var dataCandy = this.data.candys[i]
if (dataCandy) {
var doCandy = new DOCandy(dataCandy, i)
this.candys.push(doCandy)
}
else {
var left = 0;
var c = this.numberToLetter.get(i)
if (list.has(c))
left = list.get(c);
dataCandy = StorageManager.createDataCandy(left)
this.data.candys.push(dataCandy)
var doCandy = new DOCandy(dataCandy, i)
this.candys.push(doCandy)
}
}
}
//====================================持久化数据
public get_mistake(): number {
return this.data.mistake
}
public set_mistake(mistake: number): void {
this.data.mistake = mistake
StorageManager.getInstance().onChanged()
}
public get_difficulty(): number {
return this.data.difficulty
}
public get_duration(): number {
return this.data.duration
}
public set_duration(duration: number): void {//关卡计时
this.data.duration = duration
// StorageManager.getInstance().onChanged()
}
public get_note_open(): boolean {
return this.data.note_open
}
public set_note_open(note_open: boolean): void {
this.data.note_open = note_open
StorageManager.getInstance().onChanged()
}
//====================================持久化数据
public get_blocks(): Array<DOBlock> {
return this.blocks
}
public get_candys(): Array<DOCandy> {
return this.candys
}
}

View File

@@ -1,3 +0,0 @@
{
"uuid": "d88044d6-69d3-44d1-85bf-2d353609a8d2"
}