Commits

Alexander Schremmer  committed bae7f0a

Make the game "clonable", i.e. allow to create a game with similar cards.

  • Participants
  • Parent commits f2d56e8

Comments (0)

Files changed (4)

File domination/gameengine.py

     def selected_cards_str(self):
         return ", ".join(unicode(c.name) for c in self.selected_cards)
 
+    @property
+    def selected_cards_keys(self):
+        return [c.__name__ for c in self.selected_cards]
+
     def deal_cards(self):
         self.deal_initial_decks()
         self.deal_supply_cards(self.selected_cards)

File domination/main.py

     while newname in app.games:
         ctr += 1
         newname = "%s (%i)" % (name, ctr)
+    if "card" in request.args:
+        enabled_cards = set(request.args.getlist("card"))
+        enabled_editions = set(c.edition.name for c in CardTypeRegistry.keys2classes(request.form.getlist('card_key')))
+    else:
+        enabled_cards = enabled_editions = ()
     return render_template("create_game.html", editions=editions,
-                           card_sets=transform_sets(card_sets), name=newname)
+                           card_sets=transform_sets(card_sets), name=newname, enabled_editions=enabled_editions,
+                           enabled_cards=enabled_cards)
 
 @app.route("/game/<name>", methods=['GET', 'POST'])
 @needs_login

File domination/templates/create_game.html

     <p>{% trans %}Editions:{% endtrans %}
       {% for edition in editions %}
       <input type="checkbox" name="edition" value="{{ edition.key }}"
-      {% if not edition.optional %}checked="checked" disabled="disabled"{% endif %}>
+      {% if not edition.optional %}checked="checked" disabled="disabled"{% else %}{% if edition.name in enabled_editions %}checked="checked"{% endif %}{% endif %}>
       {{ edition.name }}
       {% endfor %}
     </p>
             <span id="card-{{ cls.__name__ }}"></span>
             <span class="edition-{{ cls.edition.key }}"></span>
             <input type="checkbox" name="card_key" value="{{ cls.__name__ }}"
-            {% if not cls.implemented %}checked="checked" disabled="disabled"{% endif %}>
+            {% if cls.__name__ in enabled_cards %}checked="checked"{% endif %}>
           {% endcall %}
         {% endfor %}
       {% endfor %}

File domination/templates/index.html

   <table border="1">
     <tr><th>{% trans %}Name{% endtrans%}</th><th>{% trans %}State{% endtrans %}</th><th>{% trans %}Players{% endtrans %}</th><th>{% trans %}Cards{% endtrans %}</th><th>{% trans %}Round{% endtrans %}</th></tr>
     {% for runner in runners %}
-    <tr><td><a href="{{ url_for('game', name=runner.game.name) }}">{{ runner.game.name }}</a></td><td>{{ _(runner.state) }}</td><td>{{ runner.game.player_names }}</td><td>{{ runner.game.selected_cards_str }}
+    <tr><td><a href="{{ url_for('game', name=runner.game.name) }}">{{ runner.game.name }}</a></td><td>{{ _(runner.state) }}</td><td>{{ runner.game.player_names }}</td><td><a href="{{ url_for('create_game', card=runner.game.selected_cards_keys) }}" title="Create new game with these cards">{{ runner.game.selected_cards_str }}</a>
     </td><td>{{ runner.game.round }}</td></tr>
     {% else %}
     <tr><td colspan="5">{% trans %}None{% endtrans %}</td></tr>