diff --git a/examples/config-variants/__main__.py b/examples/config-variants/__main__.py new file mode 100644 index 0000000..906a59d --- /dev/null +++ b/examples/config-variants/__main__.py @@ -0,0 +1,57 @@ +from itertools import tee +from os.path import dirname, join +from time import time +from typing import Iterable, Union + +from icmtoolchain import GLOBALS, iterate_config_directories +from icmtoolchain.cli import execute_task +from icmtoolchain.config import FileConfig +from icmtoolchain.language import MakeAssetData, MakeDataConfig +from icmtoolchain.parser import parse_arguments +from icmtoolchain.project_graph import Artifact, ProjectGraph +from icmtoolchain.shell import attention, success +from icmtoolchain.task import TASKS + +startup_millis = time() +build_command = "--release ensureProjectExists clearOutput --force buildScripts compileNative compileJava buildResources buildInfo buildPackage" +targets = parse_arguments(list(build_command.split(" ")), TASKS, lambda name, target, callables: attention(f"No such task: {name}.")) + +class IsolatedWorkspace(MakeDataConfig): + def __init__(self, path: str, projects: Iterable[MakeDataConfig]): + workspace_config = FileConfig(join(path, "workspace.json")) + super().__init__(GLOBALS.TOOLCHAIN_CONFIG.path, workspace_config) + self.dependencies = projects + + def obtain_project_data(self) -> None: + return None + + def iterate_dependencies(self) -> Iterable[Union[MakeDataConfig, Artifact]]: + return self.dependencies + + def iterate_assets(self) -> Iterable[MakeAssetData]: + return [] + +workspace_path = dirname(__file__) +dependencies = iterate_config_directories(workspace_path) +workspace = IsolatedWorkspace(workspace_path, dependencies) +graph = ProjectGraph(workspace) +graph.collect_dependencies(workspace) +graph.resolve_dependencies() + +for edge in graph.traverse_dependencies(): + if isinstance(edge.project, IsolatedWorkspace): + continue + GLOBALS.shutdown_project() + assert isinstance(edge.project, MakeDataConfig) + GLOBALS.make_config = edge.project + targets, tasks = tee(targets) + while True: + try: + callable = next(tasks) + except StopIteration: + break + else: + execute_task(callable) + +startup_millis = time() - startup_millis +success(f"Tasks successfully completed in {startup_millis:.2f}s!") diff --git a/examples/config-variants/build-config/build.config b/examples/config-variants/build-config/build.config new file mode 100644 index 0000000..9ce507c --- /dev/null +++ b/examples/config-variants/build-config/build.config @@ -0,0 +1,28 @@ +{ + "defaultConfig": { + "buildType": "develop", + "libraryDir": "library/" + }, + "buildDirs": [ + { + "dir": "script/", + "targetSource": "main.js" + } + ], + "compile": [ + { + "sourceType": "launcher", + "path": "launcher.js" + }, + { + "sourceType": "mod", + "path": "main.js" + } + ], + "resources": [ + { + "resourceType": "resource", + "path": "resources/" + } + ] +} diff --git a/examples/config-variants/build-config/launcher.js b/examples/config-variants/build-config/launcher.js new file mode 100644 index 0000000..405f472 --- /dev/null +++ b/examples/config-variants/build-config/launcher.js @@ -0,0 +1,4 @@ +ConfigureMultiplayer({ + isClientOnly: false +}); +Launch(); diff --git a/examples/config-variants/build-config/mod.info b/examples/config-variants/build-config/mod.info new file mode 100644 index 0000000..4cf6324 --- /dev/null +++ b/examples/config-variants/build-config/mod.info @@ -0,0 +1,4 @@ +{ + "name": "Core Engine Mod", + "author": "Horizon Team" +} diff --git a/examples/config-variants/build-config/resources/terrain-atlas/oxidized_log_side_0.png b/examples/config-variants/build-config/resources/terrain-atlas/oxidized_log_side_0.png new file mode 100644 index 0000000..e4f7219 Binary files /dev/null and b/examples/config-variants/build-config/resources/terrain-atlas/oxidized_log_side_0.png differ diff --git a/examples/config-variants/build-config/resources/terrain-atlas/oxidized_log_side_1.png b/examples/config-variants/build-config/resources/terrain-atlas/oxidized_log_side_1.png new file mode 100644 index 0000000..e9ae5ff Binary files /dev/null and b/examples/config-variants/build-config/resources/terrain-atlas/oxidized_log_side_1.png differ diff --git a/examples/config-variants/build-config/resources/terrain-atlas/oxidized_log_top_0.png b/examples/config-variants/build-config/resources/terrain-atlas/oxidized_log_top_0.png new file mode 100644 index 0000000..4f73d9f Binary files /dev/null and b/examples/config-variants/build-config/resources/terrain-atlas/oxidized_log_top_0.png differ diff --git a/examples/config-variants/build-config/script/.includes b/examples/config-variants/build-config/script/.includes new file mode 100644 index 0000000..184f447 --- /dev/null +++ b/examples/config-variants/build-config/script/.includes @@ -0,0 +1,6 @@ +header.js + +# Helpful features +feature/block.js + +translation.js diff --git a/examples/config-variants/build-config/script/feature/block.js b/examples/config-variants/build-config/script/feature/block.js new file mode 100644 index 0000000..b780c9b --- /dev/null +++ b/examples/config-variants/build-config/script/feature/block.js @@ -0,0 +1,51 @@ +const BLOCK_TYPE_RADIACTIVE_LOG = Block.createSpecialType({ + base: 1, + solid: true, + renderlayer: EBlockRenderLayer.BLEND, + lightopacity: 7, + explosionres: 4.0, + translucency: 1.0, + lightlevel: 15, + sound: "wood" +}); + +IDRegistry.genBlockID("oxidized_log"); +Block.createBlock("oxidized_log", [{ + name: "Oxidized Log", + texture: [ + ["oxidized_log_top", 0], + ["oxidized_log_top", 0], + ["oxidized_log_side", 0] + ], + inCreative: true +}, { + name: "Oxidized Log", + texture: [ + ["oxidized_log_side", 1], + ["oxidized_log_side", 1], + ["oxidized_log_top", 0], + ["oxidized_log_top", 0], + ["oxidized_log_side", 1] + ], + inCreative: true +}, { + name: "Oxidized Log", + texture: [ + ["oxidized_log_side", 1], + ["oxidized_log_side", 1], + ["oxidized_log_side", 1], + ["oxidized_log_side", 1], + ["oxidized_log_top", 0] + ], + inCreative: true +}], BLOCK_TYPE_RADIACTIVE_LOG); + +Callback.addCallback("ItemUse", function(coords, item, block, isExternal, playerUid) { + if (block.id == BlockID.oxidized_log) { + let source = BlockSource.getDefaultForActor(playerUid); + if (source != null) { + let data = source.getBlockData(coords.x, coords.y, coords.z); + source.setBlock(coords.x, coords.y, coords.z, BlockID.oxidized_log, data >= 2 ? 0 : ++data); + } + } +}); diff --git a/examples/config-variants/build-config/script/header.js b/examples/config-variants/build-config/script/header.js new file mode 100644 index 0000000..fb0b719 --- /dev/null +++ b/examples/config-variants/build-config/script/header.js @@ -0,0 +1,15 @@ +let ticking = 0; + +Callback.addCallback("LocalTick", function() { + ticking++; + if (ticking % 20 == 0) { + if (ticking == 1200) { + ticking = 0; + } + Game.tipMessage(ticking / 20); + } +}); + +Callback.addCallback("LocalLevelLoaded", function() { + ticking = 0; +}); diff --git a/examples/config-variants/build-config/script/translation.js b/examples/config-variants/build-config/script/translation.js new file mode 100644 index 0000000..ce01c2b --- /dev/null +++ b/examples/config-variants/build-config/script/translation.js @@ -0,0 +1,3 @@ +Translation.addTranslation("Oxidized Log", { + ru: "Окислевшееся бревно" +}); diff --git a/examples/config-variants/build-config/script/tsconfig.json b/examples/config-variants/build-config/script/tsconfig.json new file mode 100644 index 0000000..f14e5f7 --- /dev/null +++ b/examples/config-variants/build-config/script/tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "..\\.toolchain.tsconfig.json", + "compilerOptions": { + "outFile": "C:\\Users\\RislaeD\\AppData\\Local\\icmtoolchain\\Cache\\build\\build-config-871a6\\sources\\main.js" + }, + "exclude": [], + "include": [ + "header.js", + "feature/block.js", + "translation.js" + ] +} diff --git a/examples/config-variants/make-json-mod/launcher.js b/examples/config-variants/make-json-mod/launcher.js new file mode 100644 index 0000000..405f472 --- /dev/null +++ b/examples/config-variants/make-json-mod/launcher.js @@ -0,0 +1,4 @@ +ConfigureMultiplayer({ + isClientOnly: false +}); +Launch(); diff --git a/examples/config-variants/make-json-mod/make.json b/examples/config-variants/make-json-mod/make.json new file mode 100644 index 0000000..4004ecc --- /dev/null +++ b/examples/config-variants/make-json-mod/make.json @@ -0,0 +1,27 @@ +{ + "info": { + "name": "Toolchain Mod", + "author": "Horizon Team" + }, + "sources": [ + { + "type": "launcher", + "source": "launcher.js" + }, + { + "type": "main", + "source": "script/", + "target": "main.js" + }, + { + "type": "library", + "source": "library/*" + } + ], + "resources": [ + { + "type": "resource_directory", + "path": "resources/" + } + ] +} diff --git a/examples/config-variants/make-json-mod/resources/terrain-atlas/oxidized_log_side_0.png b/examples/config-variants/make-json-mod/resources/terrain-atlas/oxidized_log_side_0.png new file mode 100644 index 0000000..e4f7219 Binary files /dev/null and b/examples/config-variants/make-json-mod/resources/terrain-atlas/oxidized_log_side_0.png differ diff --git a/examples/config-variants/make-json-mod/resources/terrain-atlas/oxidized_log_side_1.png b/examples/config-variants/make-json-mod/resources/terrain-atlas/oxidized_log_side_1.png new file mode 100644 index 0000000..e9ae5ff Binary files /dev/null and b/examples/config-variants/make-json-mod/resources/terrain-atlas/oxidized_log_side_1.png differ diff --git a/examples/config-variants/make-json-mod/resources/terrain-atlas/oxidized_log_top_0.png b/examples/config-variants/make-json-mod/resources/terrain-atlas/oxidized_log_top_0.png new file mode 100644 index 0000000..4f73d9f Binary files /dev/null and b/examples/config-variants/make-json-mod/resources/terrain-atlas/oxidized_log_top_0.png differ diff --git a/examples/config-variants/make-json-mod/script/.includes b/examples/config-variants/make-json-mod/script/.includes new file mode 100644 index 0000000..184f447 --- /dev/null +++ b/examples/config-variants/make-json-mod/script/.includes @@ -0,0 +1,6 @@ +header.js + +# Helpful features +feature/block.js + +translation.js diff --git a/examples/config-variants/make-json-mod/script/feature/block.js b/examples/config-variants/make-json-mod/script/feature/block.js new file mode 100644 index 0000000..b780c9b --- /dev/null +++ b/examples/config-variants/make-json-mod/script/feature/block.js @@ -0,0 +1,51 @@ +const BLOCK_TYPE_RADIACTIVE_LOG = Block.createSpecialType({ + base: 1, + solid: true, + renderlayer: EBlockRenderLayer.BLEND, + lightopacity: 7, + explosionres: 4.0, + translucency: 1.0, + lightlevel: 15, + sound: "wood" +}); + +IDRegistry.genBlockID("oxidized_log"); +Block.createBlock("oxidized_log", [{ + name: "Oxidized Log", + texture: [ + ["oxidized_log_top", 0], + ["oxidized_log_top", 0], + ["oxidized_log_side", 0] + ], + inCreative: true +}, { + name: "Oxidized Log", + texture: [ + ["oxidized_log_side", 1], + ["oxidized_log_side", 1], + ["oxidized_log_top", 0], + ["oxidized_log_top", 0], + ["oxidized_log_side", 1] + ], + inCreative: true +}, { + name: "Oxidized Log", + texture: [ + ["oxidized_log_side", 1], + ["oxidized_log_side", 1], + ["oxidized_log_side", 1], + ["oxidized_log_side", 1], + ["oxidized_log_top", 0] + ], + inCreative: true +}], BLOCK_TYPE_RADIACTIVE_LOG); + +Callback.addCallback("ItemUse", function(coords, item, block, isExternal, playerUid) { + if (block.id == BlockID.oxidized_log) { + let source = BlockSource.getDefaultForActor(playerUid); + if (source != null) { + let data = source.getBlockData(coords.x, coords.y, coords.z); + source.setBlock(coords.x, coords.y, coords.z, BlockID.oxidized_log, data >= 2 ? 0 : ++data); + } + } +}); diff --git a/examples/config-variants/make-json-mod/script/header.js b/examples/config-variants/make-json-mod/script/header.js new file mode 100644 index 0000000..fb0b719 --- /dev/null +++ b/examples/config-variants/make-json-mod/script/header.js @@ -0,0 +1,15 @@ +let ticking = 0; + +Callback.addCallback("LocalTick", function() { + ticking++; + if (ticking % 20 == 0) { + if (ticking == 1200) { + ticking = 0; + } + Game.tipMessage(ticking / 20); + } +}); + +Callback.addCallback("LocalLevelLoaded", function() { + ticking = 0; +}); diff --git a/examples/config-variants/make-json-mod/script/translation.js b/examples/config-variants/make-json-mod/script/translation.js new file mode 100644 index 0000000..ce01c2b --- /dev/null +++ b/examples/config-variants/make-json-mod/script/translation.js @@ -0,0 +1,3 @@ +Translation.addTranslation("Oxidized Log", { + ru: "Окислевшееся бревно" +}); diff --git a/examples/config-variants/make-json-mod/script/tsconfig.json b/examples/config-variants/make-json-mod/script/tsconfig.json new file mode 100644 index 0000000..b71fe75 --- /dev/null +++ b/examples/config-variants/make-json-mod/script/tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "..\\.toolchain.tsconfig.json", + "compilerOptions": { + "outFile": "C:\\Users\\RislaeD\\AppData\\Local\\icmtoolchain\\Cache\\build\\make-json-mod-eabc9\\sources\\main.js" + }, + "exclude": [], + "include": [ + "header.js", + "feature/block.js", + "translation.js" + ] +} diff --git a/examples/config-variants/make-json-modpack/make.json b/examples/config-variants/make-json-modpack/make.json new file mode 100644 index 0000000..89299d3 --- /dev/null +++ b/examples/config-variants/make-json-modpack/make.json @@ -0,0 +1,7 @@ +{ + "modpack": "modpack.json", + "dependencies": [ + "../build-config", + "../make-json-mod" + ] +} diff --git a/examples/config-variants/make-json-modpack/modpack.json b/examples/config-variants/make-json-modpack/modpack.json new file mode 100644 index 0000000..747f0b5 --- /dev/null +++ b/examples/config-variants/make-json-modpack/modpack.json @@ -0,0 +1,5 @@ +{ + "name": "toolchain-modpack", + "displayedName": "Toolchain Modpack", + "author": "Horizon Team" +} diff --git a/examples/config-variants/make-json-pack/graphics/background/raccoon.png b/examples/config-variants/make-json-pack/graphics/background/raccoon.png new file mode 100644 index 0000000..aac64da Binary files /dev/null and b/examples/config-variants/make-json-pack/graphics/background/raccoon.png differ diff --git a/examples/config-variants/make-json-pack/make.json b/examples/config-variants/make-json-pack/make.json new file mode 100644 index 0000000..a2f6b1b --- /dev/null +++ b/examples/config-variants/make-json-pack/make.json @@ -0,0 +1,8 @@ +{ + "manifest": "manifest.json", + "pack": { + "graphics": { + "background": ["graphics/background/*"] + } + } +} diff --git a/examples/config-variants/make-json-pack/manifest.json b/examples/config-variants/make-json-pack/manifest.json new file mode 100644 index 0000000..25feb6d --- /dev/null +++ b/examples/config-variants/make-json-pack/manifest.json @@ -0,0 +1,5 @@ +{ + "game": "Toolchain", + "pack": "Horizon Pack", + "developer": "Horizon Team" +} diff --git a/examples/config-variants/modpack-json/modpack.json b/examples/config-variants/modpack-json/modpack.json new file mode 100644 index 0000000..afd7a29 --- /dev/null +++ b/examples/config-variants/modpack-json/modpack.json @@ -0,0 +1,5 @@ +{ + "name": "innercore-modpack", + "displayedName": "Inner Core Modpack", + "author": "Horizon Team" +} diff --git a/examples/config-variants/modpack-json/mods/build-config b/examples/config-variants/modpack-json/mods/build-config new file mode 120000 index 0000000..7b6b087 --- /dev/null +++ b/examples/config-variants/modpack-json/mods/build-config @@ -0,0 +1 @@ +../../build-config \ No newline at end of file diff --git a/examples/config-variants/modpack-json/mods/make-json-mod b/examples/config-variants/modpack-json/mods/make-json-mod new file mode 120000 index 0000000..3c8f937 --- /dev/null +++ b/examples/config-variants/modpack-json/mods/make-json-mod @@ -0,0 +1 @@ +../../make-json-mod \ No newline at end of file