modular expansion adding

This commit is contained in:
Alberto Xamin 2020-12-16 21:10:53 +01:00
parent d3bf18c9a2
commit 996b4608ca
No known key found for this signature in database
GPG Key ID: 4F026F48309500A2
4 changed files with 31 additions and 5 deletions

View File

@ -201,6 +201,14 @@ def chat_message(sid, msg):
ses.game.reset()
elif '/startgame' in msg and not ses.game.started:
ses.game.start_game()
elif '/addex' in msg and not ses.game.started:
cmd = msg.split()
if len(cmd) == 2:
if cmd[1] not in ses.game.available_expansions:
ses.game.available_expansions.append(cmd[1])
ses.game.notify_room()
else:
sio.emit('chat_message', room=sid, data={'color': f'','text':f'{msg} bad format'})
elif '/gameinfo' in msg:
sio.emit('chat_message', room=sid, data={'color': f'','text':f'info: {ses.game.__dict__}'})
elif '/meinfo' in msg:

View File

@ -1,7 +1,12 @@
from bang.expansions.dodge_city import cards, characters
class DodgeCity():
def get_characters():
from bang.expansions.dodge_city import characters
return characters.all_characters()
def get_cards():
return cards.get_starting_deck()
from bang.expansions.dodge_city import cards
return cards.get_starting_deck()
class HighNoon():
pass

View File

@ -23,6 +23,7 @@ class Game:
self.initial_players = 0
self.password = ''
self.expansions = []
self.available_expansions = ['dodge_city']
self.shutting_down = False
self.is_competitive = False
self.disconnect_bot = True
@ -37,6 +38,7 @@ class Game:
'is_competitive': self.is_competitive,
'disconnect_bot': self.disconnect_bot,
'expansions': self.expansions,
'available_expansions': self.available_expansions
})
def toggle_expansion(self, expansion_name):

View File

@ -33,7 +33,10 @@
</div>
<div v-if="!started">
<h3>{{$t("expansions")}}</h3>
<PrettyCheck @click.native="toggleExpansions('dodge_city')" :disabled="!isRoomOwner" v-model="useDodgeCity" class="p-switch p-fill" style="margin-top:5px; margin-bottom:3px;">Dodge City</PrettyCheck>
<div v-for="ex in togglable_expansions" v-bind:key="ex">
<PrettyCheck @click.native="toggleExpansions(ex)" :disabled="!isRoomOwner" :value="is_toggled_expansion(ex)" class="p-switch p-fill" style="margin-top:5px; margin-bottom:3px;">{{get_expansion_name(ex)}}</PrettyCheck>
<br>
</div>
<h3>{{$t('mods')}}</h3>
<PrettyCheck @click.native="toggleCompetitive" :disabled="!isRoomOwner" v-model="is_competitive" class="p-switch p-fill" style="margin-top:5px; margin-bottom:3px;">{{$t('mod_comp')}}</PrettyCheck>
<br>
@ -90,7 +93,8 @@ export default {
selectedInfo: null,
privateRoom: false,
password: '',
useDodgeCity: false,
togglable_expansions: [],
expansions: [],
hasToSetUsername: false,
is_competitive: false,
disconnect_bot: false,
@ -103,7 +107,8 @@ export default {
this.privateRoom = data.password !== ''
this.is_competitive = data.is_competitive
this.disconnect_bot = data.disconnect_bot
this.useDodgeCity = data.expansions.indexOf('dodge_city') !== -1
this.togglable_expansions = data.available_expansions
this.expansions = data.expansions
this.players = data.players.map(x => {
return {
name: x.name,
@ -168,6 +173,12 @@ export default {
}
},
methods: {
is_toggled_expansion(ex) {
return this.expansions.indexOf(ex) !== -1
},
get_expansion_name(ex) {
return ex.replace('_', ' ').replace(/\w\S*/g, m => m.charAt(0).toUpperCase()+m.substr(1).toLowerCase())
},
leaveRoom() {
window.location.replace(window.location.origin)
},