def extract_attackable_npcs(compressed_json_file_path: Union[Path, str]):
    """Main function to extract attackble NPC definition files

    :param compressed_json_file_path: Compressed cache file
    """
    attackable_npcs = {}

    # Load and decompress the compressed definition file
    definitions = osrs_cache_data.CacheDefinitionFiles(
        compressed_json_file_path)
    definitions.decompress_cache_file()

    # Loop all entries in the decompressed and loaded definition file
    for id_number in definitions:
        json_data = definitions[id_number]
        if "Attack" in json_data["options"]:
            # Skip entries with variable menu list color in name
            if "<col" in json_data["name"]:
                continue
            # Save the attackable NPC
            attackable_npcs[id_number] = json_data

    # Save all extracted attackable NPCs to JSON file
    out_fi = Path(config.DATA_PATH / "attackable-npcs.json")
    with open(out_fi, "w") as f:
        json.dump(attackable_npcs, f)
예제 #2
0
def extract_summary_file(compressed_json_file_path: Union[Path, str],
                         cache_name: str):
    """Main function to extract item/npc/object summary information (ID and name).

    :param compressed_json_file_path: Compressed cache file.
    :param cache_name: The name of the cache (items, npcs or objects).
    """
    summary_data = {}

    # Load and decompress the compressed definition file
    definitions = osrs_cache_data.CacheDefinitionFiles(
        compressed_json_file_path)
    definitions.decompress_cache_file()

    # Loop all entries in the decompressed and loaded definition file
    for id_number in definitions:
        json_data = definitions[id_number]
        id = json_data["id"]
        name = json_data["name"]
        # Check if there is a non-valid name
        if "<col" in json_data["name"]:
            continue
        summary_data[id] = {"id": id, "name": name}

    # Save all extracted entries to a JSON file
    if cache_name == "items":
        out_fi = Path(config.DOCS_PATH / "items-summary.json")
    elif cache_name == "npcs":
        out_fi = Path(config.DOCS_PATH / "npcs-summary.json")
    elif cache_name == "objects":
        out_fi = Path(config.DOCS_PATH / "objects-summary.json")

    with open(out_fi, "w") as f:
        json.dump(summary_data, f)
예제 #3
0
def extract_item_inventory_actions(compressed_json_file_path: Union[Path,
                                                                    str]):
    """Main function for extracting OSRS model ID numbers.

    :param compressed_json_file_path: File system location of compressed cache definition files.
    """
    inventory_actions = collections.defaultdict(int)

    # Load and decompress the compressed definition file
    definitions = osrs_cache_data.CacheDefinitionFiles(
        compressed_json_file_path)
    definitions.decompress_cache_file()

    # Loop all entries in the decompressed and loaded definition file
    for id_number in definitions:
        json_data = definitions[id_number]
        for option in json_data["interfaceOptions"]:
            inventory_actions[option] += 1

    inventory_actions = sorted(inventory_actions.items(),
                               key=lambda x: int(x[1]),
                               reverse=True)
    for action, count in inventory_actions:
        if not action:
            action = "None"
        print(f"{action:<24} {count}")
예제 #4
0
def test_osrs_cache_extract_model_ids(path_to_cache_dir: Path, definition_id,
                                      cache_type, expected):
    path_to_cache_file = path_to_cache_dir / f"{cache_type}.json"
    definitions = osrs_cache_data.CacheDefinitionFiles(path_to_cache_file)
    definitions.decompress_cache_file()
    json_data = definitions[definition_id]
    model_data = extract_model_ids.extract_model_ids(json_data, cache_type)[0]
    assert model_data["model_id"] == expected
예제 #5
0
def test_osrs_cache_extract_model_ids_list(path_to_cache_dir: Path, definition_id, cache_type, expected):
    path_to_cache_file = path_to_cache_dir / f"{cache_type}.json"
    definitions = osrs_cache_data.CacheDefinitionFiles(path_to_cache_file)
    definitions.decompress_cache_file()
    json_data = definitions[definition_id]
    model_data = extract_summary_model_ids.extract_model_ids_list(json_data)
    model_data_key = list(model_data.keys())[0]
    model_data = model_data[model_data_key]
    assert model_data["model_ids"] == expected
def main(path_to_cache_definitions: Path):
    """Main function for extracting OSRS model ID numbers that map to names.

    :param path_to_cache_definitions: File location of compressed cache definition files.
    """
    all_models = {}

    # Loop the three cache dump files (items, npcs, objects)
    for cache_file in osrs_cache_constants.CACHE_DUMP_FILES:
        # Set the path to the compressed JSON files
        compressed_json_file = Path(path_to_cache_definitions / cache_file)

        # Set the current cache dump type
        cache_type = PurePath(cache_file)
        cache_type = str(cache_type.with_suffix(""))

        # Load and decompress the compressed definition file
        definitions = osrs_cache_data.CacheDefinitionFiles(
            compressed_json_file)
        definitions.decompress_cache_file()

        # Loop all entries in the decompressed and loaded definition file
        for id_number in definitions:
            # Fetch the decompressed JSON data
            json_data = definitions[id_number]

            # Name check (it is of no use if it is empty/null, so exclude)
            if json_data["name"] in SKIP_EMPTY_NAMES:
                continue

            # Process cache definition based on type (item, npc, object)
            # Items: Have single interger model IDs
            # NPCs: Have list of interger model IDs
            # Objects: Have list of integer model IDs
            if cache_type == "items":
                extracted_models = extract_model_ids_int(json_data)
            elif cache_type == "npcs":
                extracted_models = extract_model_ids_list(json_data)
            elif cache_type == "objects":
                extracted_models = extract_model_ids_list(json_data)

            # Add extracted models to all_models dictionary
            all_models.update(extracted_models)

    # Save all extracted models ID numbers to JSON file
    out_fi = Path(config.DOCS_PATH / "models-summary.json")
    with open(out_fi, "w") as f:
        json.dump(all_models, f, indent=4)
def main(path_to_cache_definitions: Path):
    """Main function for extracting OSRS model ID numbers.

    :param path_to_cache_definitions: File system location of compressed cache definition files.
    """
    models_dict = {}

    # Loop the three cache dump files (items, npcs, objects)
    for cache_file in osrs_cache_constants.CACHE_DUMP_FILES:
        # Set the path to the compressed JSON files
        compressed_json_file = Path(path_to_cache_definitions / cache_file)

        # Set the current cache dump type
        cache_type = PurePath(cache_file)
        cache_type = str(cache_type.with_suffix(""))

        # Load and decompress the compressed definition file
        definitions = osrs_cache_data.CacheDefinitionFiles(
            compressed_json_file)
        definitions.decompress_cache_file()

        # Loop all entries in the decompressed and loaded definition file
        for id_number in definitions:
            # Extract model ID numbers
            model_list = extract_model_ids(definitions[id_number], cache_type)

            # Loop the extracted model IDs
            if model_list:
                for model in model_list:
                    # Generate a unique key (e.g., items_10_2361, an item with ID of 10 and model ID of 2361)
                    key = f"{model['type']}_{model['type_id']}_{model['model_id']}"
                    # Add to the dict for outputting
                    models_dict[key] = model

    # Save all extracted models ID numbers to JSON file
    out_fi = Path(config.DOCS_PATH / "models-summary.json")
    with open(out_fi, "w") as f:
        json.dump(models_dict, f, indent=4)
예제 #8
0
def test_osrs_cache_data_decompression(path_to_cache_dir: Path, cache_type,
                                       expected):
    path_to_cache_file = path_to_cache_dir / f"{cache_type}.json"
    definitions = osrs_cache_data.CacheDefinitionFiles(path_to_cache_file)
    definitions.decompress_cache_file()
    assert len(definitions) == expected