package ru.m.puzzlez.core;

import flash.geom.Rectangle;

class GameUtil {

    public static function buildPreset(image:String):GamePreset {
        return {
            image:image,
            grid: {width: 8, height: 8},
            tableRect: new Rectangle(0, 0, 0, 0),
            imageRect: new Rectangle(0, 0, 2304, 2304),
        }
    }

    public static function buildState(preset:GamePreset):GameState {
        var parts:Array<Part> = [];
        var partWidth = preset.imageRect.width / preset.grid.width;
        var partHeight = preset.imageRect.height / preset.grid.height;
        var offset = 5;
        for (x in 0...preset.grid.width) {
            for (y in 0...preset.grid.height) {
                var id = (x << 16) + y;
                parts.push({
                    id: id,
                    gridX: x,
                    gridY: y,
                    rect: new Rectangle(offset + x * (partWidth + offset), offset + y * (partHeight + offset), partWidth, partHeight),
                });
            }
        }
        return {
            preset: preset,
            parts: parts,
        }
    }
}
