You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
3.7 KiB
TypeScript

import { FigurePrompts } from "types";
import { randomSelect, randomSelectNoRepeat } from "./random";
import { CHARACTER, ROLE } from "prompts/general";
import {
ENVIRONMENT_LOCATION,
ENVIRONMENT_SKY,
ENVIRONMENT_TIME,
} from "prompts/environment";
import {
HAIR_BANGS,
HAIR_BRAID,
HAIR_COLOR,
HAIR_LENGTH,
HAIR_ORNAMENT,
HAIR_STYLE,
} from "prompts/hair";
import { EYE_COLOR, EYE_STATUS, EYE_STYLE } from "prompts/eye";
import { FACIAL_EXPRESSION, FACIAL_FEATURE } from "prompts/facial";
import {
BODY_BREASTS,
BODY_CLOTHING,
BODY_LEG_ORNAMENTS,
BODY_SHOES,
} from "prompts/body";
import { ORNAMENTS } from "prompts/ornament";
export const initPrompts = (p?: FigurePrompts): FigurePrompts => {
const _p: FigurePrompts = {
base: p?.base || [],
style: p?.style || [],
character: p?.character || '1 girl',
role: p?.role,
action: p?.action,
environmentTime: p?.environmentTime || randomSelect(ENVIRONMENT_TIME),
environmentSky: p?.environmentSky || randomSelect(ENVIRONMENT_SKY),
environmentLocation:
p?.environmentLocation || randomSelect(ENVIRONMENT_LOCATION),
hairLength: p?.hairLength || randomSelect(HAIR_LENGTH),
hairColor: p?.hairColor,
hairStyle: p?.hairStyle,
hairBraid: p?.hairBraid,
hairBangs: p?.hairBangs,
hairOrnament: p?.hairOrnament,
eyeColor: p?.eyeColor || randomSelect(EYE_COLOR, 0.5),
eyeStyle: p?.eyeStyle || randomSelect(EYE_STYLE, 0.5),
eyeStatus: p?.eyeStatus || randomSelect(EYE_STATUS, 0.8),
facialFeature: p?.facialFeature,
facialExpression:
p?.facialExpression,
bodyBreasts: p?.bodyBreasts,
bodyClothing: p?.bodyClothing,
bodyLegOrnaments:
p?.bodyLegOrnaments,
bodyShoes: p?.bodyShoes,
ornaments: p?.ornaments,
};
return _p;
};
export const mergeArray = (
arr1: any[] | undefined,
arr2: any[] | undefined
) => {
const arr = [] as any[];
if (Array.isArray(arr1)) {
arr.push(...arr1);
} else if (arr1) {
arr.push(arr1);
}
if (Array.isArray(arr2)) {
arr.push(...arr2);
} else if (arr2) {
arr.push(arr2);
}
return arr;
};
export const mergePrompts = (
p1: FigurePrompts,
p2: FigurePrompts
): FigurePrompts => {
const _p: FigurePrompts = {
base: mergeArray(p1.base, p2.base),
style: mergeArray(p1.style, p2.style),
character: p2.character || p1.character,
role: mergeArray(p1.role, p2.role),
action: p2.action || p1.action,
environmentTime: p2.environmentTime || p1.environmentTime,
environmentSky: p2.environmentSky || p1.environmentSky,
environmentLocation: p2.environmentLocation || p1.environmentLocation,
hairLength: p2.hairLength || p1.hairLength,
hairColor: p2.hairColor || p1.hairColor,
hairStyle: p2.hairStyle || p1.hairStyle,
hairBraid: p2.hairBraid || p1.hairBraid,
hairBangs: p2.hairBangs || p1.hairBangs,
hairOrnament: p2.hairOrnament || p1.hairOrnament,
eyeColor: p2.hairColor || p1.hairColor,
eyeStyle: p2.eyeStyle || p1.eyeStyle,
eyeStatus: p2.eyeStatus || p1.eyeStyle,
facialFeature: p2.facialFeature || p1.facialFeature,
facialExpression: p2.facialExpression || p1.facialExpression,
bodyBreasts: p2.bodyBreasts || p1.bodyBreasts,
bodyClothing: p2.bodyClothing || p1.bodyClothing,
bodyLegOrnaments: p2.bodyLegOrnaments || p1.bodyLegOrnaments,
bodyShoes: p2.bodyShoes || p1.bodyShoes,
ornaments: mergeArray(p1.ornaments, p2.ornaments),
};
return _p;
};
export const getPrompts = (p: FigurePrompts): string[] => {
const prompts = [] as string[];
Object.values(p).forEach((value) => {
if (typeof value === "string") prompts.push(value);
else if (Array.isArray(value)) prompts.push(...value);
});
return prompts;
};