-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require: | ||
- bolt.contrib.sandbox | ||
- overgen.define_custom_resources | ||
- overgen.define_compilation_unit_providers | ||
- overgen.define_module_globals | ||
data_pack: | ||
load: "src" | ||
pipeline: | ||
- mecha | ||
- overgen.remove_custom_resources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from dataclasses import dataclass | ||
from typing import Any, ClassVar, Iterable, List, Optional, Tuple, Union | ||
|
||
from beet import Context, DataPack, ResourcePack, TextFile, TextFileBase | ||
from beet.core.utils import FormatsRangeDict, normalize_string | ||
from mecha import CompilationDatabase, CompilationUnit, Mecha | ||
|
||
from bolt import Runtime | ||
|
||
|
||
class Overgen(TextFile): | ||
scope: ClassVar[tuple[str, ...]] = ("overgen",) | ||
extension: ClassVar[str] = ".bolt" | ||
|
||
|
||
def define_custom_resources(ctx: Context): | ||
ctx.data.extend_namespace.append(Overgen) | ||
|
||
|
||
def provide_compilation_units( | ||
pack: Union[ResourcePack, DataPack], | ||
match: Optional[List[str]] = None, | ||
) -> Iterable[Tuple[TextFileBase[Any], CompilationUnit]]: | ||
for resource_location in pack[Overgen].match(*match or ["*"]): | ||
file_instance = pack[Overgen][resource_location] | ||
|
||
yield file_instance, CompilationUnit( | ||
resource_location=resource_location, | ||
pack=pack.overlays[normalize_string(resource_location)], | ||
) | ||
|
||
|
||
def define_compilation_unit_providers(ctx: Context): | ||
mc = ctx.inject(Mecha) | ||
mc.providers = [provide_compilation_units] | ||
|
||
|
||
@dataclass | ||
class DeclareOverlayFormats: | ||
database: CompilationDatabase | ||
|
||
def __call__(self, min_inclusive: int, max_inclusive: int): | ||
pack = self.database[self.database.current].pack | ||
if pack is not None: | ||
pack.supported_formats = FormatsRangeDict( | ||
min_inclusive=min_inclusive, | ||
max_inclusive=max_inclusive, | ||
) | ||
|
||
|
||
def define_module_globals(ctx: Context): | ||
mc = ctx.inject(Mecha) | ||
declare_overlay_formats = DeclareOverlayFormats(mc.database) | ||
|
||
runtime = ctx.inject(Runtime) | ||
runtime.expose("declare_overlay_formats", declare_overlay_formats) | ||
|
||
|
||
def remove_custom_resources(ctx: Context): | ||
ctx.data[Overgen].clear() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
value = "abc" | ||
print(value) | ||
say this should be left untouched |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
declare_overlay_formats( | ||
min_inclusive=18, | ||
max_inclusive=19, | ||
) | ||
|
||
function ./foo: | ||
say stuff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Lectern snapshot | ||
|
||
## Data pack | ||
|
||
`@data_pack pack.mcmeta` | ||
|
||
```json | ||
{ | ||
"pack": { | ||
"pack_format": 18, | ||
"description": "" | ||
}, | ||
"overlays": { | ||
"entries": [ | ||
{ | ||
"formats": { | ||
"min_inclusive": 18, | ||
"max_inclusive": 19 | ||
}, | ||
"directory": "demo_stuff" | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
|
||
### demo | ||
|
||
`@function demo:foo` | ||
|
||
```mcfunction | ||
value = "abc" | ||
print(value) | ||
say this should be left untouched | ||
``` | ||
|
||
## Overlay `demo_stuff` | ||
|
||
`@overlay demo_stuff` | ||
|
||
### demo | ||
|
||
`@function demo:foo` | ||
|
||
```mcfunction | ||
say stuff | ||
``` | ||
|
||
`@endoverlay` |