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 %}
{{ form.hidden_tag() }} + {{ form.action.label(class_="label") }} +
+
{{ form.action }} +
+
+ +
+
+

{{ form.prof.label(class_="label") }}

{{ form.prof(class_="textarea") }}

{{ form.message1.label(class_="label") }}

diff --git a/theunderground/concierge.py b/theunderground/concierge.py index e60a6cd6..ceca3c9a 100644 --- a/theunderground/concierge.py +++ b/theunderground/concierge.py @@ -42,8 +42,8 @@ def add_concierge(mii_id): concierge_data = ConciergeMiis( mii_id=mii_id, clothes=1, # TODO: Allow disabling of custom clothes - action=1, # TODO: Allow changing of whatever the heck "action" is - prof=form.prof.data, # TODO: Add this. + action=form.action.data, + prof=form.prof.data, movie_id=form.movieid.data, voice=False, # The web console does not currently support this ) @@ -85,6 +85,7 @@ def edit_concierge(mii_id): mii_msg_infos = retrieved_data if form.validate_on_submit(): + mii_msg_infos[0][0].action = form.action.data mii_msg_infos[0][0].prof = form.prof.data mii_msg_infos[0][0].movie_id = form.movieid.data @@ -97,6 +98,7 @@ def edit_concierge(mii_id): return redirect(url_for("list_concierge")) else: # Populate the data + form.action.data = mii_msg_infos[0][0].action form.prof.data = mii_msg_infos[0][0].prof form.movieid.data = mii_msg_infos[0][0].movie_id for _, info in mii_msg_infos: diff --git a/theunderground/forms.py b/theunderground/forms.py index b3ac8d92..d21f9d69 100644 --- a/theunderground/forms.py +++ b/theunderground/forms.py @@ -3,16 +3,21 @@ from wtforms import ( StringField, SubmitField, - PasswordField, FileField, SelectField, TextAreaField, BooleanField, IntegerField, ) -from wtforms.validators import DataRequired, Length, ValidationError - -from models import RoomBGMTypes, RoomContentBGMTypes, ContentTypes, LinkTypes +from wtforms.validators import DataRequired, Length + +from models import ( + RoomBGMTypes, + RoomContentBGMTypes, + ContentTypes, + LinkTypes, + ConciergeMiiActions, +) """ Reference: @@ -165,6 +170,12 @@ class DeleteForm(FlaskForm): class ConciergeForm(FlaskForm): + action = SelectField( + "Mii Action", + choices=ConciergeMiiActions.choices(), + coerce=ConciergeMiiActions.coerce, + ) + prof = TextAreaField("Profession", validators=[DataRequired(), Length(max=129)]) message1 = TextAreaField("Message 1", validators=[DataRequired()]) message2 = TextAreaField("Message 2", validators=[DataRequired()]) diff --git a/url1/mii.py b/url1/mii.py index e132163a..b82ddea8 100644 --- a/url1/mii.py +++ b/url1/mii.py @@ -80,7 +80,7 @@ def mii_met(mii_id): "clothes": concierge_mii.clothes, "color1": mii_metadata.color1, "color2": mii_metadata.color2, - "action": concierge_mii.action, + "action": concierge_mii.action.value, "prof": concierge_mii.prof, "name": mii_metadata.name, "msginfo": msginfo,