Mercurial > libervia-backend
annotate frontends/src/tools/games.py @ 2144:1d3f73e065e1
core, jp: component handling + client handling refactoring:
- SàT can now handle components
- plugin have now a "modes" key in PLUGIN_INFO where they declare if they can be used with clients and or components. They default to be client only.
- components are really similar to clients, but with some changes in behaviour:
* component has "entry point", which is a special plugin with a componentStart method, which is called just after component is connected
* trigger end with a different suffixes (e.g. profileConnected vs profileConnectedComponent), so a plugin which manage both clients and components can have different workflow
* for clients, only triggers of plugins handling client mode are launched
* for components, only triggers of plugins needed in dependencies are launched. They all must handle component mode.
* component have a sendHistory attribute (False by default) which can be set to True to allow saving sent messages into history
* for convenience, "client" is still used in method even if it can now be a component
* a new "component" boolean attribute tells if we have a component or a client
* components have to add themselve Message protocol
* roster and presence protocols are not added for components
* component default port is 5347 (which is Prosody's default port)
- asyncCreateProfile has been renamed for profileCreate, both to follow new naming convention and to prepare the transition to fully asynchronous bridge
- createProfile has a new "component" attribute. When used to create a component, it must be set to a component entry point
- jp: added --component argument to profile/create
- disconnect bridge method is now asynchronous, this way frontends can know when disconnection is finished
- new PI_* constants for PLUGIN_INFO values (not used everywhere yet)
- client/component connection workflow has been moved to their classes instead of being a host methods
- host.messageSend is now client.sendMessage, and former client.sendMessage is now client.sendMessageData.
- identities are now handled in client.identities list, so it can be updated dynamically by plugins (in the future, frontends should be able to update them too through bridge)
- profileConnecting* profileConnected* profileDisconnected* and getHandler now all use client instead of profile
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 12 Feb 2017 17:55:43 +0100 |
parents | 2daf7b4c6756 |
children | 8b37a62336c3 |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
1 #!/usr/bin/env python2 |
141
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
590
diff
changeset
|
4 # SAT: a jabber client |
1766 | 5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org) |
141
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
590
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
590
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
590
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
590
diff
changeset
|
10 # (at your option) any later version. |
141
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
590
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
590
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
590
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
590
diff
changeset
|
15 # GNU Affero General Public License for more details. |
141
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
590
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
590
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
141
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
682
2805fa3f4bdf
tools: moved src/tools/games.py to src/tools/frontends/
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
20 """This library help manage general games (e.g. card games) and it is shared by the frontends""" |
141
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 |
590
56531f9e9ac7
Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
22 SUITS_ORDER = ['pique', 'coeur', 'trefle', 'carreau', 'atout'] # I have switched the usual order 'trefle' and 'carreau' because card are more easy to see if suit colour change (black, red, black, red) |
56531f9e9ac7
Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
23 VALUES_ORDER = [str(i) for i in xrange(1, 11)] + ["valet", "cavalier", "dame", "roi"] |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
24 |
141
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
26 class TarotCard(object): |
141
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 """This class is used to represent a car logically""" |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 def __init__(self, tuple_card): |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 """@param tuple_card: tuple (suit, value)""" |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 self.suit, self.value = tuple_card |
590
56531f9e9ac7
Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
32 self.bout = self.suit == "atout" and self.value in ["1", "21", "excuse"] |
141
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 if self.bout or self.value == "roi": |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 self.points = 4.5 |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 elif self.value == "dame": |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 self.points = 3.5 |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 elif self.value == "cavalier": |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 self.points = 2.5 |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 elif self.value == "valet": |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 self.points = 1.5 |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 else: |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 self.points = 0.5 |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 def get_tuple(self): |
590
56531f9e9ac7
Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
45 return (self.suit, self.value) |
141
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 @staticmethod |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 def from_tuples(tuple_list): |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 result = [] |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 for card_tuple in tuple_list: |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 result.append(TarotCard(card_tuple)) |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 return result |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 def __cmp__(self, other): |
590
56531f9e9ac7
Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
55 if other is None: |
141
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 return 1 |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 if self.suit != other.suit: |
590
56531f9e9ac7
Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
58 idx1 = SUITS_ORDER.index(self.suit) |
56531f9e9ac7
Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
59 idx2 = SUITS_ORDER.index(other.suit) |
141
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 return idx1.__cmp__(idx2) |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 if self.suit == 'atout': |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 if self.value == other.value == 'excuse': |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 return 0 |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 if self.value == 'excuse': |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 return -1 |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 if other.value == 'excuse': |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 return 1 |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 return int(self.value).__cmp__(int(other.value)) |
590
56531f9e9ac7
Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
69 # at this point we have the same suit which is not 'atout' |
56531f9e9ac7
Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
70 idx1 = VALUES_ORDER.index(self.value) |
56531f9e9ac7
Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
71 idx2 = VALUES_ORDER.index(other.value) |
141
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 return idx1.__cmp__(idx2) |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 def __str__(self): |
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 return "[%s,%s]" % (self.suit, self.value) |
716
30eb49e4e05d
frontends tools: added symbols for MUC user activity identification
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
76 |
30eb49e4e05d
frontends tools: added symbols for MUC user activity identification
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
77 |
30eb49e4e05d
frontends tools: added symbols for MUC user activity identification
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
78 # These symbols are diplayed by Libervia next to the player's nicknames |
1379
da2ea16fabc6
quick_frontend: display MUC games symbols
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
79 SYMBOLS = {"Radiocol": [u"♬"], "Tarot": [u"♠", u"♣", u"♥", u"♦"]} |