An open API service indexing awesome lists of open source software.

https://github.com/frederoxdev/regolith-generators


https://github.com/frederoxdev/regolith-generators

regolith-filter

Last synced: 11 months ago
JSON representation

Awesome Lists containing this project

README

          

# Regolith Generators

Intended to be the regolith alternative to the [bridge. generator scripts](https://bridge-core.app/guide/advanced/generator-scripts/index.html)

### Install Filter
```
regolith install regolith_generators
```

## Use-cases

Place `.ts` files directly into your BP/RP and this filter will run each one with Deno. More convenient than making filters for one off scripts.

### Bulk file generation

```ts
// BP/blocks/ExampleBlockGenerator.ts
import { createFile } from "jsr:@frederoxdev/regolith-generators"

const blockNames = ["foo", "bar"];

blockNames.forEach(id => {
createFile({
"format_version": "1.21.70",
"minecraft:block": {
"description": {
"identifier": `studio_name:${id}`,
},
"components": {
// do whatever ...
}
}
}, `BP/blocks/${id}.json`)
// ^ Must pass in a file name here since generating multiple
});
```

### One off file generation

```ts
// RP/textures/item_texture.ts
import { createFile } from "jsr:@frederoxdev/regolith-generators"
import { join, extname, basename } from "jsr:@std/path";
import { walkSync } from "jsr:@std/fs";

const projectNamespace = "foo";
const studioBase = `bar/baz`;
const texturesFolder = join(Deno.cwd(), "RP", "textures", studioBase, "items");

const textureData: Record = {};

for (const entry of walkSync(texturesFolder, { exts: [".png"], includeFiles: true })) {
const textureName = basename(entry.path, extname(entry.path));
const relativePath = entry.path.replaceAll("\\", "/").split("/RP/")[1];
const noExtensionPath = relativePath.replace(extname(relativePath), "");

textureData[`${projectNamespace}:${textureName}`] = {
"textures": noExtensionPath
}
}

createFile({
resource_pack_name: "pack.name",
texture_name: 'atlas.items',
texture_data: textureData,
});
// ^ No file path has to be provided for one off files
```