Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ollm/opencomic-ai-training/llms.txt

Use this file to discover all available pages before exploring further.

The options module is the default export from src/options.mts and acts as the central configuration manager for the entire dataset generation pipeline. It reads YAML config files from disk, recursively merges any file: field references (allowing large configs to be split across multiple files), creates a seeded main RandGenerator keyed 'options', prepares all output directories, and stores the resulting Options object in module-level state. Once an image is about to be generated, setCurrentImageRand() seeds a fresh per-image generator and randomize() resolves all Rand fields deterministically before any Krita calls are made.

options.load()

Reads and parses a YAML options file, resolves all file: includes, creates the main random generator, prepares output directories, and stores the result in module state.
function load(file: string): Options
file
string
required
Absolute path to the root YAML options file on disk.
What it does step by step:
  1. Reads and parses the YAML file at file using the yaml package.
  2. Recursively calls loadFiles() on every object and array in the parsed data. Any entry that contains a file: key is loaded from that path and merged (or spread, if the loaded file is an array) in place.
  3. Creates a RandGenerator via rand.randByKey('options', data.seed) and stores it as data.mainRand.
  4. For each entry in data.degradations, resolves the output.clean, output.degraded, and output.options paths via the resolve helper and creates any missing directories with fs.mkdirSync(..., { recursive: true }).
  5. Stores the completed Options object in the module-level options variable and returns it.
import options from './src/options.mjs';

const config = options.load('/absolute/path/to/config.yaml');
console.log(config.seed);      // e.g. 42
console.log(config.images);    // e.g. 1000
All Rand fields in the returned object are not yet resolved — they still hold their raw config values. Call setCurrentImageRand() and then randomize() before using any randomisable field.

options.setCurrentImageRand()

Seeds the per-image random generator so that randomize() produces a deterministic, image-specific sequence of values.
function setCurrentImageRand(image: number): void
image
number
required
The 1-based index of the image about to be generated.
Internally the seed is computed as:
const seed = image * 1009 + options.seed;
A new RandGenerator is created via rand.randByKey('image-' + image, seed) and stored as options.currentImageRand. The raw numeric seed is also stored as options.imageSeed.
This must be called before every call to options.randomize(). Because the seed is derived purely from the image index and the global seed, re-calling setCurrentImageRand(n) at any point will reproduce the same per-image sequence, which is useful for resuming interrupted runs.

options.randomize()

Recursively walks an options object and resolves all Rand values in place using the current image RNG.
function randomize(object: any, depth: number = -1, currentDepth: number = 0): any
object
any
required
The object (or sub-object) to randomize. Typically a deep clone of the raw Options config or one of its sub-sections such as options.base or options.postProcessing.
depth
number
How many levels deep to recurse. Pass -1 (the default) for unlimited depth.
currentDepth
number
Internal recursion counter. Do not pass this manually.
Resolution rules (in order of evaluation for each key/value):
Value shapeBehaviour
Key is probEvaluated by rand.prob() — resolved to true or false.
Array whose first element is a number, string, or nullIf it is a two-element all-numeric array it is treated as a [from, to] range; otherwise a single element is chosen at random.
Array of objects with if fieldThe first object whose if condition matches the current values map is selected; its value is then passed through rand.generate().
Array of objects with prob fieldFiltered by rand.probFilter() before recursing — items whose probability does not fire are removed.
Single object with weight or prob fieldResolved directly by rand.generate().
Key is brush without a name setAfter recursing, a brush preset name is drawn from krita.presets filtered by the resolved category and any disabled-brush lists (BRUSHES_WITH_STRANGE_PATTERNS, optionally BRUSHES_WITH_PIXELATED_EDGES).
Plain object (none of the above)Recurses into it (up to depth levels).
Pass depth: 1 when you only want the top-level list entries randomized without descending into their children — for example when resolving options.drawings to decide which drawing types are active for the current image.

options.setValues()

Flattens the leaf values of an object into a dot-notation key map. These entries are consulted by the if condition evaluator inside randomize().
function setValues(object: any, baseKey: string = ''): void
object
any
required
The object whose leaf values should be stored in the condition map.
baseKey
string
Optional dot-notation prefix to prepend to every key. Defaults to '' (no prefix). For example, passing 'inKrita.halftone' stores keys such as inKrita.halftone.angle.
All leaf values are written to the module-level values map (Map<string, any>). An if expression such as "base.colored == true" is split on spaces and the left operand is looked up in this map at condition-check time.

options.resetValues()

Clears the if-condition values map, discarding any values accumulated by previous setValues() calls.
function resetValues(): void
Call this at the start of each image to avoid stale condition values from a previous image bleeding into the current one. drawing.generateImage() calls resetValues() automatically at the top of each invocation.

options.get()

Returns the currently loaded Options object, or undefined if load() has not yet been called.
get: function(): Options | undefined
const config = options.get();
if (config) {
  console.log('Generating', config.images, 'images');
}

options.values (getter)

Returns the live Map<string, any> of flattened condition values populated by setValues().
get values(): Map<string, any>
This is exposed primarily for debugging — inspect it to see which keys are currently available for if expressions in your config.

Full usage example

The following shows the typical per-image lifecycle: load the config once at startup, then for every image set the per-image RNG, deep-clone the config, randomize it, and pass it to the drawing step.
import options from './src/options.mjs';
import drawing from './src/drawing.mjs';

// 1. Load config once at startup
const config = options.load('/path/to/config.yaml');
console.log(`Generating ${config.images} images with seed ${config.seed}`);

// 2. Loop over images
for (let image = 1; image <= config.images; image++) {

  // 3. Generate the image (setCurrentImageRand, resetValues, and randomize
  //    are all called internally by generateImage)
  await drawing.generateImage(image, (image, degradedImage) => {
    console.log(`  image ${image}, degraded variant ${degradedImage} saved`);
  });
}
In normal operation you do not need to call setCurrentImageRand(), resetValues(), or randomize() manually — drawing.generateImage() invokes all three internally before any drawing begins.

Build docs developers (and LLMs) love