예제 #1
0
def build_all_resources():
    mod_structure.cleanup_build_target("resource_directory")
    mod_structure.cleanup_build_target("gui")
    mod_structure.cleanup_build_target("minecraft_resource_pack")
    mod_structure.cleanup_build_target("minecraft_behavior_pack")
    overall_result = 0

    for resource in make_config.get_project_value("resources", fallback=[]):
        if "path" not in resource or "type" not in resource:
            print("skipped invalid source json", resource, file=sys.stderr)
            overall_result = 1
            continue
        for source_path in make_config.get_project_paths(resource["path"]):
            if not exists(source_path):
                print("skipped non-existing resource path",
                      resource["path"],
                      file=sys.stderr)
                overall_result = 1
                continue
            resource_type = resource["type"]
            if resource_type not in ("resource_directory", "gui",
                                     "minecraft_resource_pack",
                                     "minecraft_behavior_pack"):
                print("skipped invalid resource with type",
                      resource_type,
                      file=sys.stderr)
                overall_result = 1
                continue
            resource_name = resource[
                "target"] if "target" in resource else basename(source_path)
            resource_name += "{}"

            if resource_type in ("resource_directory", "gui"):
                target = mod_structure.new_build_target(
                    resource_type,
                    resource_name,
                    declare={
                        "resourceType": {
                            "resource_directory": "resource",
                            "gui": "gui"
                        }[resource_type]
                    })
            else:
                target = mod_structure.new_build_target(
                    resource_type,
                    resource_name,
                    exclude=True,
                    declare_default={
                        "resourcePacksDir":
                        mod_structure.get_target_directories(
                            "minecraft_resource_pack")[0],
                        "behaviorPacksDir":
                        mod_structure.get_target_directories(
                            "minecraft_behavior_pack")[0]
                    })
            clear_directory(target)
            copy_directory(source_path, target)
    mod_structure.update_build_config_list("resources")
    return overall_result
예제 #2
0
def task_exclude_directories():
    config = get_make_config()
    for path in config.get_project_value("excludeFromRelease", []):
        for exclude in config.get_project_paths(os.path.join("output", path)):
            if os.path.isdir(exclude):
                clear_directory(exclude)
            elif os.path.isfile(exclude):
                os.remove(exclude)
    return 0
예제 #3
0
	def setup_default_config(self):
		self.read_or_create_build_config()
		if "defaultConfig" not in self.build_config or not isinstance(self.build_config["defaultConfig"], dict):
			self.build_config["defaultConfig"] = {}
		default_config = self.build_config["defaultConfig"]
		default_config["readme"] = "this build config is generated automatically by mod development toolchain"
		default_config["api"] = make_config.get_project_value("info.api", fallback="CoreEngine")
		default_config["buildType"] = "develop"
		self.write_build_config()
예제 #4
0
def task_build_info():
    import json
    from utils import shortcodes
    config = get_make_config()
    with open(config.get_project_path("output/mod.info"), "w") as info_file:
        info = dict(
            config.get_project_value("info",
                                     fallback={"name": "No was provided"}))
        if "icon" in info:
            del info["icon"]
        if "api" in info:
            del info["api"]

        info["version"] = shortcodes(info["version"])
        info["description"] = shortcodes(info["description"])

        info_file.write(json.dumps(info, indent=" " * 4))
    icon_path = config.get_project_value("info.icon")
    if icon_path is not None:
        copy_file(config.get_project_path(icon_path),
                  config.get_project_path("output/mod_icon.png"))
    return 0
예제 #5
0
def build_all_scripts():
    mod_structure.cleanup_build_target("script_source")
    mod_structure.cleanup_build_target("script_library")
    overall_result = 0

    from functools import cmp_to_key

    def libraries_first(a, b):
        la = a["type"] == "library"
        lb = b["type"] == "library"

        if la == lb:
            return 0
        elif la:
            return -1
        else:
            return 1

    sources = make_config.get_project_value("sources", fallback=[])
    sources = sorted(sources, key=cmp_to_key(libraries_first))

    for item in sources:
        _source = item["source"]
        _target = item["target"] if "target" in item else None
        _type = item["type"]
        _language = item["language"]

        if _type not in ("main", "launcher", "library", "preloader"):
            print(f"skipped invalid source with type {_type}")
            overall_result = 1
            continue

        for source_path in make_config.get_project_paths(_source):
            if not exists(source_path):
                print(f"skipped non-existing source path {_source}")
                overall_result = 1
                continue

            target_type = "script_library" if _type == "library" else "script_source"
            target_path = _target if _target is not None else f"{splitext(basename(source_path))[0]}.js"

            # translate make.json source type to build.config source type
            declare = {
                "sourceType": {
                    "main": "mod",
                    "launcher": "launcher",
                    "preloader": "preloader",
                    "library": "library"
                }[_type]
            }

            if "api" in item:
                declare["api"] = item["api"]

            try:
                dot_index = target_path.rindex(".")
                target_path = target_path[:dot_index] + "{}" + target_path[
                    dot_index:]
            except ValueError:
                target_path += "{}"

            destination_path = mod_structure.new_build_target(
                target_type, target_path, source_type=_type, declare=declare)
            mod_structure.update_build_config_list("compile")

            if (isfile(source_path)):
                copy_file(source_path, destination_path)
            else:
                overall_result += build_source(source_path, destination_path)

    return overall_result