mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
implemented new random shape generator
This commit is contained in:
parent
f0a75a8255
commit
308c6379eb
@ -320,6 +320,29 @@ export class HubGoals extends BasicSerializableObject {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
picks given number of colors that are close on the color wheel
|
||||||
|
*/
|
||||||
|
generateRandomColorSet() {
|
||||||
|
const colorWheel = [
|
||||||
|
enumColors.red,
|
||||||
|
enumColors.yellow,
|
||||||
|
enumColors.green,
|
||||||
|
enumColors.cyan,
|
||||||
|
enumColors.blue,
|
||||||
|
enumColors.purple,
|
||||||
|
enumColors.red,
|
||||||
|
enumColors.yellow,
|
||||||
|
];
|
||||||
|
const universalColors = [enumColors.black, enumColors.white, enumColors.uncolored];
|
||||||
|
const index = randomInt(0, colorWheel.length - 3);
|
||||||
|
const pickedColors = colorWheel.slice(index, index + 3);
|
||||||
|
pickedColors.push(randomChoice(universalColors));
|
||||||
|
return pickedColors;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {ShapeDefinition}
|
* @returns {ShapeDefinition}
|
||||||
*/
|
*/
|
||||||
@ -328,37 +351,43 @@ export class HubGoals extends BasicSerializableObject {
|
|||||||
/** @type {Array<import("./shape_definition").ShapeLayer>} */
|
/** @type {Array<import("./shape_definition").ShapeLayer>} */
|
||||||
let layers = [];
|
let layers = [];
|
||||||
|
|
||||||
// @ts-ignore
|
let availableColors = this.generateRandomColorSet();
|
||||||
const randomColor = () => randomChoice(Object.values(enumColors));
|
let pickedSymmetry = null; // pairs of quadrants that must be the same
|
||||||
// @ts-ignore
|
let availableShapes = [enumSubShape.rect, enumSubShape.circle, enumSubShape.star];
|
||||||
const randomShape = () => randomChoice(Object.values(enumSubShape));
|
if (Math.random() < 0.5) {
|
||||||
|
pickedSymmetry = [[0, 2], [1, 3]]; // radial symmetry
|
||||||
|
availableShapes.push(enumSubShape.windmill); // windmill looks good only in radial symmetry
|
||||||
|
} else {
|
||||||
|
const symmetries = [
|
||||||
|
[[0, 3], [1, 2]], // vertical axis
|
||||||
|
[[0, 1], [2, 3]], // horizontal axis
|
||||||
|
[[0, 2], [1], [3]], // diagonal axis
|
||||||
|
[[1, 3], [0], [2]], // other diagonal axis
|
||||||
|
]
|
||||||
|
pickedSymmetry = randomChoice(symmetries);
|
||||||
|
}
|
||||||
|
|
||||||
let anyIsMissingTwo = false;
|
// @ts-ignore
|
||||||
|
const randomColor = () => randomChoice(availableColors);
|
||||||
|
// @ts-ignore
|
||||||
|
const randomShape = () => randomChoice(availableShapes);
|
||||||
|
|
||||||
for (let i = 0; i < layerCount; ++i) {
|
for (let i = 0; i < layerCount; ++i) {
|
||||||
/** @type {import("./shape_definition").ShapeLayer} */
|
/** @type {import("./shape_definition").ShapeLayer} */
|
||||||
const layer = [null, null, null, null];
|
const layer = [null, null, null, null];
|
||||||
|
|
||||||
for (let quad = 0; quad < 4; ++quad) {
|
for (let j = 0; j < pickedSymmetry.length; ++j) {
|
||||||
layer[quad] = {
|
const group = pickedSymmetry[j];
|
||||||
subShape: randomShape(),
|
const shape = randomShape();
|
||||||
color: randomColor(),
|
const color = randomColor();
|
||||||
};
|
for (let k = 0; k < group.length; ++k) {
|
||||||
|
const quad = group[k];
|
||||||
|
layer[quad] = {
|
||||||
|
subShape: shape,
|
||||||
|
color: color,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sometimes shapes are missing
|
|
||||||
if (Math.random() > 0.85) {
|
|
||||||
layer[randomInt(0, 3)] = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sometimes they actually are missing *two* ones!
|
|
||||||
// Make sure at max only one layer is missing it though, otherwise we could
|
|
||||||
// create an uncreateable shape
|
|
||||||
if (Math.random() > 0.95 && !anyIsMissingTwo) {
|
|
||||||
layer[randomInt(0, 3)] = null;
|
|
||||||
anyIsMissingTwo = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
layers.push(layer);
|
layers.push(layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user