Skip to content

Commit

Permalink
feat: asset module
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Oct 31, 2023
1 parent 66bddf7 commit 3e3fa7d
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 8 deletions.
8 changes: 8 additions & 0 deletions bolt/module.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
__all__ = [
"Module",
"AssetModule",
"CompiledModule",
"ModuleManager",
"ModuleCacheBackend",
Expand Down Expand Up @@ -85,6 +86,13 @@ class Module(TextFile):
extension: ClassVar[str] = ".bolt"


class AssetModule(TextFile):
"""Class representing a bolt module in a resource pack."""

scope: ClassVar[Tuple[str, ...]] = ("modules",)
extension: ClassVar[str] = ".bolt"


MacroLibrary = Dict[str, Dict[Tuple[str, AstMacro], Optional[Tuple[str, str]]]]


Expand Down
18 changes: 15 additions & 3 deletions bolt/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
CommandSpec,
CommandTree,
CompilationDatabase,
CompilationUnitProvider,
Diagnostic,
FileTypeCompilationUnitProvider,
Mecha,
Expand All @@ -36,7 +37,13 @@
from .helpers import get_bolt_helpers
from .loop_info import loop_info
from .memo import MemoHandler, MemoRegistry
from .module import CompiledModule, Module, ModuleCacheBackend, ModuleManager
from .module import (
AssetModule,
CompiledModule,
Module,
ModuleCacheBackend,
ModuleManager,
)
from .parse import get_bolt_parsers
from .utils import internal

Expand All @@ -54,6 +61,7 @@ class Runtime(CommandEmitter):
evaluate: "Evaluator"

spec: CommandSpec
module_provider: CompilationUnitProvider

def __init__(self, ctx: Union[Context, Mecha]):
super().__init__()
Expand All @@ -74,6 +82,7 @@ def __init__(self, ctx: Union[Context, Mecha]):
)

ctx.data.extend_namespace.append(Module)
ctx.assets.extend_namespace.append(AssetModule)

self.globals["ctx"] = ctx

Expand Down Expand Up @@ -126,7 +135,8 @@ def __init__(self, ctx: Union[Context, Mecha]):

self.spec = mc.spec

mc.providers.append(FileTypeCompilationUnitProvider([Module]))
self.module_provider = FileTypeCompilationUnitProvider([Module, AssetModule])
mc.providers.append(self.module_provider)

commands_json = files("bolt.resources").joinpath("commands.json").read_text()
command_tree = CommandTree.parse_raw(commands_json)
Expand Down Expand Up @@ -207,6 +217,8 @@ def finalize(self, ctx: Context):
finally:
for pack in [ctx.data, *ctx.data.overlays.values()]:
pack[Module].clear()
for pack in [ctx.assets, *ctx.assets.overlays.values()]:
pack[AssetModule].clear()
self.memo.finalize()


Expand Down Expand Up @@ -237,7 +249,7 @@ def root(self, node: AstRoot) -> Optional[AstRoot]:
compilation_unit, module = self.modules.match_ast(node)

if (
isinstance(self.modules.database.current, Module)
isinstance(self.modules.database.current, (Module, AssetModule))
and not module.executed
and module.resource_location
and not self.entrypoint_spec.match_file(module.resource_location)
Expand Down
9 changes: 9 additions & 0 deletions examples/bolt_assets/beet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require:
- bolt
resource_pack:
load: "src"
pipeline:
- mecha
meta:
bolt:
entrypoint: "*"
1 change: 1 addition & 0 deletions examples/bolt_assets/src/assets/demo/modules/foo.bolt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
model minecraft:block/stone {"parent": "block/cube"}
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ include = ["bolt/py.typed"]
[tool.poetry.dependencies]
python = "^3.10"
beet = ">=0.97.0"
mecha = ">=0.81.1"
mecha = ">=0.83.0"

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.2"
Expand Down
24 changes: 24 additions & 0 deletions tests/snapshots/examples__build_bolt_assets__0.pack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Lectern snapshot

## Resource pack

`@resource_pack pack.mcmeta`

```json
{
"pack": {
"pack_format": 18,
"description": ""
}
}
```

### minecraft

`@model minecraft:block/stone`

```json
{
"parent": "block/cube"
}
```

0 comments on commit 3e3fa7d

Please sign in to comment.