Exemple #1
0
def _create_colors(color_list):
    color_palettes = GameFile.objects.get(
        folder="assets/archetypes", filename="compiledcolorpalettelists.msgpack"
    ).content
    colors = _create_generic("Colors", color_list, Color)

    click.echo("Creating Colors Values...")
    color_values_created = 0
    with click.progressbar(color_palettes) as pbar:
        for color_palette in pbar:
            for color_variations, color_id in color_palette["colorVariations"]:

                _, was_created = ColorValue.objects.get_or_create(
                    color=colors[color_id],
                    color_type=color_palette["name"],
                    defaults={
                        "shade": color_variations[0],
                        "base": color_variations[1],
                        "hlight": color_variations[2],
                    },
                )

                if was_created:
                    color_values_created += 1
    print_result("color values", color_values_created)

    return colors
Exemple #2
0
def _create_generic(name, index_list, klass):
    click.echo(f"Creating {name}...")
    created = 0
    objects = {}
    with click.progressbar(index_list) as pbar:
        for index in pbar:
            obj, was_created = klass.objects.get_or_create(game_id=index)

            objects[obj.game_id] = obj

            if was_created:
                created += 1
    print_result(name, created)

    return objects
Exemple #3
0
def _create_items(items_list, subtitles):
    compiled_items = GameFile.objects.get(
        folder="assets/archetypes", filename="compileditems.msgpack"
    ).content

    click.echo("Creating Items...")
    items_created = 0
    items_disabled = 0
    items = {}
    with click.progressbar(items_list, show_pos=True) as pbar:
        for item in pbar:
            string_item_id = str(item["item_id"])

            item_obj, was_created = Item.objects.get_or_create(
                game_id=item["item_id"],
                string_id=compiled_items[string_item_id]["stringID"],
            )
            item_obj.name = compiled_items[string_item_id]["name"]
            item_obj.item_subtitle = subtitles[item["subtitle_id"]]
            item_obj.mint_value = compiled_items[string_item_id]["coinValue"]
            item_obj.max_stack = compiled_items[string_item_id]["maxStackSize"]
            item_obj.can_be_sold = item_obj.game_id not in settings.BOUNDLESS_NO_SELL

            # items that cannot be dropped or minted are not normally obtainable
            can_drop = compiled_items[string_item_id]["canDrop"]
            is_active = (
                can_drop
                and item_obj.mint_value is not None
                and item_obj.game_id not in settings.BOUNDLESS_BLACKLISTED_ITEMS
            )

            if not was_created and (not is_active and item_obj.active):
                items_disabled += 1
            item_obj.active = is_active
            item_obj.save()

            items[item_obj.game_id] = item_obj

            if was_created:
                items_created += 1

    print_result("item", items_created)
    print_result("item", items_disabled, "disabled")

    return items
Exemple #4
0
def _create_recipe_groups(recipes):
    recipe_groups_created = 0
    click.echo("Importing recipe groups...")
    with click.progressbar(recipes["groups"]) as pbar:
        for group in pbar:
            display_name = LocalizedString.objects.get(
                string_id=group["groupDisplayName"])
            recipe_group, created = RecipeGroup.objects.get_or_create(
                name=group["groupName"],
                defaults={"display_name": display_name})

            members = []
            for member_id in group["groupMembers"]:
                members.append(Item.objects.get(game_id=member_id))
            recipe_group.members.set(members)

            if created:
                recipe_groups_created += 1
            else:
                recipe_group.display_name = display_name
                recipe_group.save()
    print_result("recipe groups", recipe_groups_created)
Exemple #5
0
def _create_localization_data(strings, data):
    click.echo("Processing localization data...")
    for lang_name, lang_data in strings.items():
        _create_localized_names(lang_name, lang_data, data)

        click.echo(f"Creating localized strings for {lang_name}...")
        strings_content = GameFile.objects.get(
            folder="assets/archetypes/strings", filename=f"{lang_name}.msgpack"
        ).content

        strings_created = 0
        with click.progressbar(strings_content.items()) as pbar:
            for string_id, text in pbar:
                string, _ = LocalizedString.objects.get_or_create(string_id=string_id)

                string_text, created = LocalizedStringText.objects.get_or_create(
                    string=string, lang=lang_name, defaults={"text": text}
                )
                string_text.text = text
                string_text.save()

                if created:
                    strings_created += 1
        print_result("localized strings", strings_created)
Exemple #6
0
def run(force=False, **kwargs):
    recipes = GameFile.objects.get(folder="assets/archetypes",
                                   filename="recipes.msgpack").content

    _create_recipe_groups(recipes)

    recipes_created = 0
    click.echo("Importing crafting recipes...")
    with click.progressbar(recipes["recipes"]) as pbar:
        for recipe_dict in pbar:
            attrs = {
                "heat":
                recipe_dict["heat"],
                "craft_xp":
                recipe_dict["craftXP"],
                "machine":
                recipe_dict.get("machine"),
                "output":
                Item.objects.get(game_id=recipe_dict["outputItem"]),
                "can_hand_craft":
                recipe_dict["canHandCraft"],
                "machine_level":
                recipe_dict["machineLevel"],
                "power":
                recipe_dict["powerRequired"],
                "group_name":
                recipe_dict["recipeGroupName"],
                "knowledge_unlock_level":
                recipe_dict["knowledgeUnlockLevel"],
                "required_event":
                recipe_dict.get("onlyDuringTimeLimitedEvents"),
                "required_backer_tier":
                recipe_dict.get("minBackerTierNeeded")
                or recipe_dict.get("accountFlagBitMaskNeeded"),
            }
            recipe, created = Recipe.objects.get_or_create(
                game_id=recipe_dict["ID"], defaults=attrs)

            recipe.tints.set(_get_tints(recipe_dict["tintTakenFrom"]))
            recipe.requirements.set(
                _get_requirements(recipe_dict.get("prerequisites", [])))
            recipe.levels.set(_get_levels(recipe_dict))

            if created:
                recipes_created += 1
            else:
                for attr_name, attr_value in attrs.items():
                    setattr(recipe, attr_name, attr_value)
                recipe.save()

    print_result("recipes", recipes_created)

    cleaned_up = 0
    cleaned_up += RecipeRequirement.objects.filter(
        recipe__isnull=True).delete()[0]
    cleaned_up += RecipeLevel.objects.filter(recipe__isnull=True).delete()[0]
    cleaned_up += RecipeInput.objects.filter(
        recipelevel__isnull=True).delete()[0]

    if cleaned_up > 0:
        click.echo(f"Cleaned up {cleaned_up} dangling recipe models")
Exemple #7
0
def _create_localized_names(lang_name, lang_data, data):
    click.echo(f"Creating localized names for {lang_name}...")

    total = (
        len(lang_data["items"])
        + len(lang_data["colors"])
        + len(lang_data["metals"])
        + len(lang_data["subtitles"])
    )
    with click.progressbar(length=total) as pbar:
        localizations_created = 0
        for index, name in lang_data["colors"].items():
            l, was_created = LocalizedName.objects.get_or_create(
                game_obj=data["colors"][int(index)], lang=lang_name
            )
            l.name = name
            l.save()

            if was_created:
                localizations_created += 1

            pbar.update(1)
            pbar.render_progress()

        for index, name in lang_data["metals"].items():
            l, was_created = LocalizedName.objects.get_or_create(
                game_obj=data["metals"][int(index)], lang=lang_name
            )
            l.name = name
            l.save()

            if was_created:
                localizations_created += 1

            pbar.update(1)
            pbar.render_progress()

        for index, name in lang_data["items"].items():
            l, was_created = LocalizedName.objects.get_or_create(
                game_obj=data["items"][int(index)], lang=lang_name
            )
            l.name = name
            l.save()

            if was_created:
                localizations_created += 1

            pbar.update(1)
            pbar.render_progress()

        for index, name in lang_data["subtitles"].items():
            l, was_created = LocalizedName.objects.get_or_create(
                game_obj=data["subtitles"][int(index)], lang=lang_name
            )
            l.name = name
            l.save()

            if was_created:
                localizations_created += 1

            pbar.update(1)
            pbar.render_progress()
    print_result("localized names", localizations_created)
Exemple #8
0
def run(**kwargs):  # pylint: disable=too-many-locals
    emoji_list = _get_emoji_list()

    emoji_nametable = GameFile.objects.get(folder="assets/gui/emoji",
                                           filename="emoji.json").content

    emoji_created = 0
    click.echo("Importing emojis...")
    with click.progressbar(range(len(emoji_layer_data) // 2),
                           show_pos=True,
                           show_percent=True) as pbar:
        for index in pbar:
            name, layers = (
                emoji_layer_data[2 * index],
                emoji_layer_data[(2 * index) + 1],
            )

            image = get_emoji(name, layers)
            emoji_image = get_django_image(image, f"{name}.png")

            emoji, created = Emoji.objects.get_or_create(
                name=name,
                defaults={"image": emoji_image},
            )

            if not created:
                if emoji.image is not None and emoji.image.name:
                    emoji.image.delete()
                emoji.image = emoji_image
            if emoji.image_small is not None and emoji.image_small.name:
                emoji.image_small.delete()
            emoji.image_small = make_thumbnail(emoji_image)

            alt_names = emoji_nametable.get(name)

            try:
                int(emoji.name, 16)
            except ValueError:
                emoji.category = "BOUNDLESS"
            else:
                lookup = emoji.name.upper()

                for emoji_dict in emoji_list:
                    if lookup in emoji_dict["codePoint"].split(" "):
                        emoji.category = GROUP_TO_CATEGORY[emoji_dict["group"]]

            if emoji.category is None:
                emoji.category = Emoji.EmojiCategory.UNCATEGORIZED

            emoji.active = alt_names is not None
            emoji.save()

            if alt_names is not None:
                for alt_name in alt_names:
                    EmojiAltName.objects.get_or_create(emoji=emoji,
                                                       name=alt_name)

            if created:
                emoji_created += 1

    print_result("emojis", emoji_created)
    click.echo("Purging CDN cache...")
    purge_static_cache(["emoji"])
Exemple #9
0
def run(**kwargs):  # pylint: disable=too-many-locals
    skilltrees = GameFile.objects.get(folder="assets/archetypes",
                                      filename="skilltrees.msgpack").content

    click.echo("Importing skills...")
    with click.progressbar(skilltrees.items()) as pbar:
        skill_groups_created = 0
        skills_created = 0

        for skill_group_name, skill_group_dict in pbar:
            attrs = {
                "skill_type":
                skill_group_dict["type"],
                "display_name":
                LocalizedString.objects.get(
                    string_id=skill_group_dict["displayName"]),
                "unlock_level":
                skill_group_dict["unlockAtLevel"],
            }

            skill_group, created = SkillGroup.objects.get_or_create(
                name=skill_group_name, defaults=attrs)

            if created:
                skill_groups_created += 1
            else:
                for attr_name, attr_value in attrs.items():
                    setattr(skill_group, attr_name, attr_value)
                skill_group.save()

            for skill_dict in skill_group_dict["skills"]:
                name = f"{skill_dict['icon']}.png"
                image = get_image(
                    f"gui/sprites/distance_maps_bw/icons/skills/{name}")

                attrs = {
                    "group":
                    skill_group,
                    "number_unlocks":
                    skill_dict["num"],
                    "cost":
                    skill_dict["cost"],
                    "order":
                    skill_dict["order"],
                    "category":
                    skill_dict["category"],
                    "link_type":
                    skill_dict["linkType"],
                    "description":
                    LocalizedString.objects.get(
                        string_id=skill_dict["description"]),
                    "display_name":
                    LocalizedString.objects.get(
                        string_id=skill_dict["displayName"]),
                    "bundle_prefix":
                    skill_dict["bundlePrefix"],
                    "affected_by_other_skills":
                    skill_dict["affectedByOtherSkills"],
                    "icon":
                    get_django_image(image, name),
                }

                skill, created = Skill.objects.get_or_create(
                    name=skill_dict["name"], defaults=attrs)

                if created:
                    skills_created += 1
                else:
                    _set_skill_attrs(skill, attrs)
                    skill.save()
        print_result("skill groups", skill_groups_created)
        print_result("skills", skills_created)

    click.echo("Purging CDN cache...")
    purge_static_cache(["skills"])