Skip to content

Commit

Permalink
add watchtower to ruin
Browse files Browse the repository at this point in the history
Signed-off-by: Rafał Safin <[email protected]>
  • Loading branch information
Rafał Safin committed Sep 10, 2024
1 parent 10fed82 commit 4f3ddab
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Generated by Django 5.1.1 on 2024-09-10 11:28

import django.contrib.postgres.fields
from django.db import migrations, models

import base.models.outline


class Migration(migrations.Migration):
dependencies = [
("base", "0086_alter_periodmodel_status"),
]

operations = [
migrations.AlterField(
model_name="outline",
name="initial_outline_buildings",
field=django.contrib.postgres.fields.ArrayField(
base_field=models.CharField(
choices=[
("headquarters", "Headquarters"),
("barracks", "Barracks"),
("stable", "Stable"),
("workshop", "Workshop"),
("academy", "Academy"),
("smithy", "Smithy"),
("rally_point", "Rally point"),
("statue", "Statue"),
("market", "Market"),
("timber_camp", "Timber camp"),
("clay_pit", "Clay pit"),
("iron_mine", "Iron mine"),
("farm", "Farm"),
("warehouse", "Warehouse"),
("wall", "Wall"),
("watchtower", "Watchtower"),
],
max_length=100,
),
default=base.models.outline.building_default_list,
size=None,
),
),
migrations.AlterField(
model_name="weightmodel",
name="building",
field=models.CharField(
blank=True,
choices=[
("headquarters", "Headquarters"),
("barracks", "Barracks"),
("stable", "Stable"),
("workshop", "Workshop"),
("academy", "Academy"),
("smithy", "Smithy"),
("rally_point", "Rally point"),
("statue", "Statue"),
("market", "Market"),
("timber_camp", "Timber camp"),
("clay_pit", "Clay pit"),
("iron_mine", "Iron mine"),
("farm", "Farm"),
("warehouse", "Warehouse"),
("wall", "Wall"),
("watchtower", "Watchtower"),
],
default=None,
max_length=50,
null=True,
),
),
]
3 changes: 2 additions & 1 deletion base/models/outline.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ class Outline(models.Model):
("iron_mine", gettext_lazy("Iron mine")),
("farm", gettext_lazy("Farm")),
("warehouse", gettext_lazy("Warehouse")),
("wall", gettext_lazy("wall")),
("wall", gettext_lazy("Wall")),
("watchtower", gettext_lazy("Watchtower")),
]

RUINED_VILLAGES_POINTS: list[tuple[str, str]] = [
Expand Down
3 changes: 2 additions & 1 deletion base/models/weight_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class WeightModel(models.Model):
("iron_mine", gettext_lazy("Iron mine")),
("farm", gettext_lazy("Farm")),
("warehouse", gettext_lazy("Warehouse")),
("wall", gettext_lazy("wall")),
("wall", gettext_lazy("Wall")),
("watchtower", gettext_lazy("Watchtower")),
]

target = models.ForeignKey(TargetVertex, on_delete=models.CASCADE, db_index=True)
Expand Down
7 changes: 6 additions & 1 deletion base/static/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,8 @@ const createBuildingsOptions = (
iron_mine,
farm,
warehouse,
wall
wall,
watchtower
) => {
return [
{
Expand Down Expand Up @@ -953,6 +954,10 @@ const createBuildingsOptions = (
label: wall,
value: "wall",
},
{
label: watchtower,
value: "watchtower",
},
];
};
const changeTextToSent = (element, msg) => {
Expand Down
2 changes: 1 addition & 1 deletion base/static/min.base.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ <h5 class="mb-0"><button class="btn btn-link collapsed py-2 text-left card-heade
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("id_target"), {lineNumbers: true,});
var instance = new SelectPure(".multi-select", {
options: createBuildingsOptions(`{% trans "Headquarters" %}`,`{% trans "Barracks" %}`,`{% trans "Stable" %}`,`{% trans "Workshop" %}`,`{% trans "Academy" %}`,`{% trans "Smithy" %}`,`{% trans "Rally point" %}`,`{% trans "Statue" %}`,`{% trans "Market" %}`,`{% trans "Timber camp" %}`,`{% trans "Clay pit" %}`,`{% trans "Iron mine" %}`,`{% trans "Farm" %}`,`{% trans "Warehouse" %}`,`{% trans "wall" %}`),
options: createBuildingsOptions(`{% trans "Headquarters" %}`,`{% trans "Barracks" %}`,`{% trans "Stable" %}`,`{% trans "Workshop" %}`,`{% trans "Academy" %}`,`{% trans "Smithy" %}`,`{% trans "Rally point" %}`,`{% trans "Statue" %}`,`{% trans "Market" %}`,`{% trans "Timber camp" %}`,`{% trans "Clay pit" %}`,`{% trans "Iron mine" %}`,`{% trans "Farm" %}`,`{% trans "Warehouse" %}`,`{% trans "Wall" %}`,`{% trans "Watchtower" %}`),
multiple: true,
value: JSON.parse(document.getElementById('initial-buildings').textContent),
icon: "fa fa-times",
Expand Down
Binary file modified locale/pl/LC_MESSAGES/django.mo
Binary file not shown.
46 changes: 27 additions & 19 deletions locale/pl/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-09-10 12:18+0200\n"
"POT-Creation-Date: 2024-09-10 13:01+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand All @@ -31,7 +31,7 @@ msgstr "Data"
msgid "World"
msgstr "Świat"

#: base/forms.py:51 base/models/outline.py:156 base/models/outline.py:323
#: base/forms.py:51 base/models/outline.py:157 base/models/outline.py:324
#: base/models/profile.py:35
msgid "Army collection"
msgstr "Zbiórka Wojska"
Expand Down Expand Up @@ -63,7 +63,7 @@ msgstr ""
msgid "Village in this line is duplicated: %s"
msgstr "Wioska w tej linii jest podwojona: %s"

#: base/forms.py:134 base/models/outline.py:157 base/models/outline.py:325
#: base/forms.py:134 base/models/outline.py:158 base/models/outline.py:326
#: base/models/profile.py:36
msgid "Deff collection "
msgstr "Zbiórka Obrona"
Expand Down Expand Up @@ -685,66 +685,71 @@ msgstr "Spichlerz"

#: base/models/outline.py:120 base/models/weight_model.py:45
#: base/templates/base/new_outline/new_outline_initial_period1.html:468
msgid "wall"
msgid "Wall"
msgstr "Mur"

#: base/models/outline.py:124
#: base/models/outline.py:121 base/models/weight_model.py:46
#: base/templates/base/new_outline/new_outline_initial_period1.html:468
msgid "Watchtower"
msgstr "Wieża Strażnicza"

#: base/models/outline.py:125
msgid "Average greater than 8k"
msgstr "Średnio powyżej 8k"

#: base/models/outline.py:125
#: base/models/outline.py:126
msgid "Average 5-8k"
msgstr "Średnio 5-8k"

#: base/models/outline.py:138
#: base/models/outline.py:139
msgid "Fakes only from off villages"
msgstr "Fejki tylko z wiosek z pełnym offem"

#: base/models/outline.py:139
#: base/models/outline.py:140
msgid "Fakes from all villages"
msgstr "Fejki z wszystkich wiosek"

#: base/models/outline.py:145
#: base/models/outline.py:146
msgid "(Default) Auto generated, fully equipped safe links"
msgstr "(Domyślne) Automatycznie wygenerowane bezpieczne linki"

#: base/models/outline.py:147
#: base/models/outline.py:148
msgid "Text simple directly in message"
msgstr "Tekst prosty bezpośrednio w wiadomości"

#: base/models/outline.py:148
#: base/models/outline.py:149
msgid "New text extended directly in message"
msgstr "Nowy tekst rozszerzony bezpośrednio w wiadomości"

#: base/models/outline.py:149
#: base/models/outline.py:150
msgid "Old text extended directly in message"
msgstr "Stary tekst rozszerzony bezpośrednio w wiadomości"

#: base/models/outline.py:150
#: base/models/outline.py:151
msgid "Text for deputy directly in message"
msgstr "Tekst dla zastępcy bezpośrednio w wiadomości"

#: base/models/outline.py:300 base/models/profile.py:60
#: base/models/outline.py:301 base/models/profile.py:60
msgid "Outline Targets"
msgstr "Cele Akcja"

#: base/models/outline.py:328
#: base/models/outline.py:329
msgid "Name"
msgstr "Nazwa"

#: base/models/outline.py:428
#: base/models/outline.py:429
msgid "Expires "
msgstr "Wygasa "

#: base/models/outline.py:433
#: base/models/outline.py:434
msgid "never"
msgstr "nigdy"

#: base/models/outline.py:445
#: base/models/outline.py:446
msgid "in"
msgstr "za"

#: base/models/outline.py:447
#: base/models/outline.py:448
msgid "days"
msgstr "dni"

Expand Down Expand Up @@ -3141,6 +3146,9 @@ msgstr "Wioska"
msgid "does not exists"
msgstr "nie istnieje"

#~ msgid "wall"
#~ msgstr "Mur"

#~ msgid "All targets below"
#~ msgstr "Wszystkie cele na stronie"

Expand Down
17 changes: 15 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ types-markdown = "^3.7.0.20240822"
types-python-dateutil = "^2.9.0.20240906"
types-pytz = "^2024.1.0.20240417"
types-requests = "^2.32.0.20240907"
parameterized = "^0.9.0"

[tool.poetry.group.docs.dependencies]
mkdocs = { extras = ["i18n"], version = "^1.6.1" }
Expand Down
1 change: 1 addition & 0 deletions rest_api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"farm",
"warehouse",
"wall",
"watchtower",
}


Expand Down
10 changes: 10 additions & 0 deletions rest_api/tests/test_serializer_buildings_are_supported.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from base.models import Outline, WeightModel
from rest_api.serializers import BUILDINGS
from utils.basic.ruin import RuinHandle


def test_buildings_from_serializer_match_from_ruin_and_models():
assert BUILDINGS == set(RuinHandle.BIG_LEVELS.keys())
assert BUILDINGS == set(RuinHandle.SMALL_LEVELS.keys())
assert BUILDINGS == set(building[0] for building in WeightModel.BUILDINGS)
assert BUILDINGS == set(building[0] for building in Outline.BUILDINGS)
2 changes: 2 additions & 0 deletions utils/basic/ruin.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class RuinHandle:
"farm": 30,
"warehouse": 30,
"wall": 20,
"watchtower": 20,
}
SMALL_LEVELS: dict[str, int] = {
"headquarters": 20,
Expand All @@ -52,6 +53,7 @@ class RuinHandle:
"farm": 25,
"warehouse": 24,
"wall": 20,
"watchtower": 10,
}
LEVEL_DICTIONARY: dict[tuple[int, int], int] = {
(20, 1): 0,
Expand Down
19 changes: 19 additions & 0 deletions utils/tests/test_outline_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@

from django.test import TestCase
from django.utils.translation import activate
from parameterized import parameterized

from base.models import Outline, WeightMaximum, WeightModel
from base.models import TargetVertex as Target
from base.models.player import Player
from base.models.result import Result
from base.tests.test_utils.initial_setup import create_initial_data_write_outline
from rest_api.serializers import BUILDINGS
from utils.avaiable_troops import get_legal_coords_outline
from utils.outline_complete import complete_outline_write
from utils.outline_initial import MakeOutline
Expand Down Expand Up @@ -989,6 +991,23 @@ def test_ruin_type_outline_headquarters(self):
self.assertEqual(created[2].state.nobleman_state, 0)
self.assertEqual(created[2].state.fake_limit, 4)

@parameterized.expand(sorted(BUILDINGS))
def test_ruin_type_outline_all_buidlings_are_supported(self, building: str):
self.outline.initial_outline_min_off = 500
self.outline.mode_split = "split"
self.outline.initial_outline_buildings = [building]
self.outline.initial_outline_catapult_max_value = 100
self.outline.initial_outline_off_left_catapult = 0
self.outline.save()
target = self.target()
target.ruin = True
target.exact_off = [0, 0, 0, 0]
target.exact_noble = [0, 0, 3, 0]
target.save()
complete_outline_write(self.outline, salt=self.salt)
created = self.weights()
self.assertGreaterEqual(len(created), 1)

def test_ruin_type_outline_smithy(self):
self.outline.initial_outline_min_off = 500
self.outline.mode_split = "split"
Expand Down

0 comments on commit 4f3ddab

Please sign in to comment.