|
7 | 7 | def beet_default(ctx: Context): |
8 | 8 | if "observer" not in ctx.meta: |
9 | 9 | return |
| 10 | + |
| 11 | + # # check cache |
| 12 | + cache = ctx.cache["observer"] |
| 13 | + cached_dp = False |
| 14 | + cached_rp = False |
| 15 | + dp_path = None |
| 16 | + rp_path = None |
| 17 | + if ctx.data: |
| 18 | + dp_path = cache.get_path(f"{ctx.directory} saved_data_pack") |
| 19 | + if dp_path.is_dir(): |
| 20 | + ctx.data.load(f"{dp_path}") |
| 21 | + cached_dp = True |
| 22 | + if ctx.assets: |
| 23 | + rp_path = cache.get_path(f"{ctx.directory} saved_resource_pack") |
| 24 | + if rp_path.is_dir(): |
| 25 | + ctx.assets.load(f"{rp_path}") |
| 26 | + cached_rp = True |
| 27 | + if cached_dp and cached_rp: |
| 28 | + return |
| 29 | + |
10 | 30 | # get default directories |
11 | 31 | if "default_dir" not in ctx.meta["observer"]: |
12 | 32 | # default dir not defined |
@@ -46,5 +66,13 @@ def beet_default(ctx: Context): |
46 | 66 | dp_dir = overlay["directory"] |
47 | 67 | rp_dir = overlay["directory"] |
48 | 68 | # compare build pack and overlay pack |
49 | | - gen_dp_overlays(ctx, ctx_overlay, dp_dir, save) |
50 | | - gen_rp_overlays(ctx, ctx_overlay, rp_dir, save) |
| 69 | + if not cached_dp and ctx.data: |
| 70 | + gen_dp_overlays(ctx, ctx_overlay, dp_dir, save) |
| 71 | + if not cached_rp and ctx.assets: |
| 72 | + gen_rp_overlays(ctx, ctx_overlay, rp_dir, save) |
| 73 | + |
| 74 | + # save to cache |
| 75 | + if not cached_dp and ctx.data: |
| 76 | + ctx.data.save(path=dp_path) |
| 77 | + if not cached_rp and ctx.assets: |
| 78 | + ctx.assets.save(path=rp_path) |
0 commit comments