From ff0674b95fb613e2e113d8c78fe4d7599f23808b Mon Sep 17 00:00:00 2001 From: Sketch <75850871+SketchMaster2001@users.noreply.github.com> Date: Sat, 29 Jun 2024 18:05:38 -0400 Subject: [PATCH] feat: Add Concierge Mii actions --- .../81cfa0d8b36c_add_conciergemiiactions.py | 151 ++++++++++++++++++ models.py | 39 ++++- templates/concierge_action.html | 9 ++ theunderground/concierge.py | 6 +- theunderground/forms.py | 19 ++- url1/mii.py | 2 +- 6 files changed, 218 insertions(+), 8 deletions(-) create mode 100644 migrations/versions/81cfa0d8b36c_add_conciergemiiactions.py diff --git a/migrations/versions/81cfa0d8b36c_add_conciergemiiactions.py b/migrations/versions/81cfa0d8b36c_add_conciergemiiactions.py new file mode 100644 index 00000000..71e00744 --- /dev/null +++ b/migrations/versions/81cfa0d8b36c_add_conciergemiiactions.py @@ -0,0 +1,151 @@ +"""Add ConciergeMiiActions + +Revision ID: 81cfa0d8b36c +Revises: 357b58eaf27b +Create Date: 2024-06-29 17:47:17.413325 + +""" + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "81cfa0d8b36c" +down_revision = "357b58eaf27b" +branch_labels = None +depends_on = None + + +def upgrade(): + # We need some workarounds to cast the integer value to the enum. + # First drop the null constraint. + op.alter_column( + "concierge_miis", "action", existing_type=sa.INTEGER(), nullable=True + ) + + # Set everything to null + op.execute( + """ + UPDATE concierge_miis + SET action = NULL; + """ + ) + + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table("concierge_miis", schema=None) as batch_op: + batch_op.alter_column( + "action", + existing_type=sa.INTEGER(), + type_=sa.Enum( + "NormalMaleA", + "NormalFemaleS", + "NormalMaleS", + "NormalFemaleS2", + "NormalMaleS2", + "CheerfulMaleA", + "CheerfulFemaleS", + "CheerfulMaleS", + "SaluteMaleA", + "SaluteFemaleS", + "SaluteMaleS", + "ForeignerA", + "ForeignerS", + "CelebrityA", + "CelebrityS", + "CelebrationA", + "CelebrationS", + "AmazingA", + "AmazingS", + "GreetingS", + "ApologyS", + "Zundoko", + "Takeshi", + name="conciergemiiactions", + ), + existing_nullable=False, + postgresql_using="action::text::conciergemiiactions", + ) + + # ### end Alembic commands ### + + # Now set all columns to the default (NormalMaleA) + op.execute( + """ + UPDATE concierge_miis + SET action = 'NormalMaleA'; + """ + ) + + # Finally re-add the constraint. + op.alter_column( + "concierge_miis", + "action", + existing_type=sa.Enum(name="conciergemiiactions"), + nullable=False, + ) + + +def downgrade(): + # Just reverse the upgrade + op.alter_column( + "concierge_miis", + "action", + existing_type=sa.Enum(name="conciergemiiactions"), + nullable=True, + ) + + # Set everything to null + op.execute( + """ + UPDATE concierge_miis + SET action = NULL; + """ + ) + + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table("concierge_miis", schema=None) as batch_op: + batch_op.alter_column( + "action", + existing_type=sa.Enum( + "NormalMaleA", + "NormalFemaleS", + "NormalMaleS", + "NormalFemaleS2", + "NormalMaleS2", + "CheerfulMaleA", + "CheerfulFemaleS", + "CheerfulMaleS", + "SaluteMaleA", + "SaluteFemaleS", + "SaluteMaleS", + "ForeignerA", + "ForeignerS", + "CelebrityA", + "CelebrityS", + "CelebrationA", + "CelebrationS", + "AmazingA", + "AmazingS", + "GreetingS", + "ApologyS", + "Zundoko", + "Takeshi", + name="conciergemiiactions", + ), + type_=sa.INTEGER(), + existing_nullable=False, + ) + + # ### end Alembic commands ### + + op.execute( + """ + UPDATE concierge_miis + SET action = 1; + """ + ) + + op.alter_column( + "concierge_miis", "action", existing_type=sa.INTEGER(), nullable=False + ) diff --git a/models.py b/models.py index 13bedf30..b84f10e3 100644 --- a/models.py +++ b/models.py @@ -59,12 +59,49 @@ class PayPosters(db.Model): aspect = db.Column(db.Boolean, nullable=False) +class ConciergeMiiActions(enum.Enum): + NormalMaleA = 1 + NormalFemaleS = 2 + NormalMaleS = 3 + NormalFemaleS2 = 4 + NormalMaleS2 = 5 + CheerfulMaleA = 6 + CheerfulFemaleS = 7 + CheerfulMaleS = 8 + SaluteMaleA = 9 + SaluteFemaleS = 10 + SaluteMaleS = 11 + ForeignerA = 12 + ForeignerS = 13 + CelebrityA = 14 + CelebrityS = 15 + CelebrationA = 16 + CelebrationS = 17 + AmazingA = 18 + AmazingS = 19 + GreetingS = 20 + ApologyS = 21 + Zundoko = 24 + Takeshi = 25 + + @classmethod + def choices(cls): + return [(choice, choice.name) for choice in cls] + + @classmethod + def coerce(cls, item): + return cls(int(item)) if not isinstance(item, cls) else item + + def __str__(self): + return str(self.value) + + class ConciergeMiis(db.Model): mii_id = db.Column( db.Integer, db.ForeignKey("mii_data.mii_id"), primary_key=True, unique=True ) clothes = db.Column(db.Integer, nullable=False) - action = db.Column(db.Integer, nullable=False) + action = db.Column(db.Enum(ConciergeMiiActions), nullable=False) prof = db.Column(db.String(129), nullable=False) movie_id = db.Column(db.Integer, nullable=False) voice = db.Column(db.Boolean, default=False, nullable=False) diff --git a/templates/concierge_action.html b/templates/concierge_action.html index 718d3d2c..8d9caf23 100644 --- a/templates/concierge_action.html +++ b/templates/concierge_action.html @@ -7,6 +7,15 @@ {% block content %}