Skip to content

Commit

Permalink
Color lock and other options added to web settings, currently non-fun…
Browse files Browse the repository at this point in the history
…ctional
  • Loading branch information
ericbuzan committed Oct 5, 2017
1 parent 3e78818 commit 9f7d40c
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 78 deletions.
8 changes: 0 additions & 8 deletions color_tests/color_combo_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<<<<<<< Updated upstream
from enum import Enum

class Colors(Enum):
Expand Down Expand Up @@ -35,11 +34,4 @@ class Colors(Enum):
bad = True
if not bad:
print(quad)
=======
import common

for t in [2,3,17]:
for i in range(20):
teams = common.generate_team_colors(t)
print([x.name for x in teams])
>>>>>>> Stashed changes
24 changes: 14 additions & 10 deletions color_tests/colortest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import psmove
import colorsys
import time
from math import sqrt

def hsv2rgb(h, s, v):
return tuple(int(color * 255) for color in colorsys.hsv_to_rgb(h, s, v))
Expand Down Expand Up @@ -78,17 +79,20 @@ def hsv2rgb(h, s, v):
'653700'] #BROWN =

def colorhex(hex):
r = int(hex[0:2],16)
g = int(hex[2:4],16)
b = int(hex[4:6],16)
return (r,g,b)
r = int(hex[0:2],16)
g = int(hex[2:4],16)
b = int(hex[4:6],16)
return (r,g,b)


s=0
while True:
for i,move in enumerate(moves):
color = colorhex(joustwheel[(s+i)%12])
move.set_leds(*color)
move.update_leds()
time.sleep(0.01)
#s += 1
for i,move in enumerate(moves):
color = colorhex(joustwheel[(s+i)%12])
move.set_leds(*color)
move.update_leds()
move.poll()
ax,ay,az = tuple(move.get_accelerometer_frame(psmove.Frame_SecondHalf))
print('%+1.1f %+1.1f %+1.1f %+1.1f' % (ax,ay,az,sqrt(sum([ax**2, ay**2, az**2]))))
#time.sleep(.1)
#s += 1
1 change: 1 addition & 0 deletions colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class Colors(Enum):
White = (255,255,255)
White80 = (200,200,200)
White60 = (150,150,150)
White40 = (100,100,100)
White20 = (50,50,50)
Red = (255,0,0)
Red60 = (150,0,0)
Expand Down
13 changes: 11 additions & 2 deletions common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@

#Human speeds[slow, mid, fast]
SLOW_WARNING = [0.1, 0.15, 0.28]
SLOW_MAX = [0.5, 0.8, 1]
SLOW_MAX = [0.25, 0.8, 1]
FAST_WARNING = [0.5, 0.6, 0.8]
FAST_MAX = [1, 1.4, 1.8]

#SLOW_WARNING = [0.1, 0.15, 0.28]
#SLOW_MAX = [0.5, 0.8, 1]
#FAST_WARNING = [0.5, 0.6, 0.8]
#FAST_MAX = [1, 1.4, 1.8]

WERE_SLOW_WARNING = [0.2, 0.3, 0.4]
WERE_SLOW_MAX = [0.7, 0.9, 1.1]
WERE_FAST_WARNING = [0.6, 0.7, 0.9]
Expand Down Expand Up @@ -122,5 +127,9 @@ def rgb_bytes(self):
'enforce_minimum',
'sensitivity',
'play_instructions',
'random_modes'
'random_modes',
'color_lock',
'color_lock_choices',
'red_on_kill',
'random_teams'
]
48 changes: 26 additions & 22 deletions joust.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def track_move(move_serial, move_num, game_mode, team, team_color_enum, dead_mov
elif dead_move.value == 1 and werewolf_reveal.value > 0:
if move.poll():
ax, ay, az = move.get_accelerometer_frame(psmove.Frame_SecondHalf)
#total = sqrt(sum([ax**2, ay**2, az**2]))
total = sum([ax, ay, az])
total = sqrt(sum([ax**2, ay**2, az**2]))
#total = sum([ax, ay, az])
if move_last_value is not None:
change_real = abs(move_last_value - total)
change_arr[0] = change_arr[1]
Expand Down Expand Up @@ -285,26 +285,30 @@ def choose_werewolf(self, were_num):
self.teams[werewolf] = (self.teams[werewolf] * -1) - 1

def generate_random_teams(self, num_teams):
team_pick = list(range(num_teams))
print (str(team_pick))
traitor_pick = True
copy_serials = self.move_serials[:]

while len(copy_serials) >= 1:
#for serial in self.move_serials:
serial = random.choice(copy_serials)
copy_serials.remove(serial)
random_choice = random.choice(team_pick)
if self.game_mode == common.Games.Traitor and traitor_pick:
self.teams[serial] = (random_choice * -1) - 1
else:
self.teams[serial] = random_choice
## print("doing random choice")
## print(random_choice)
team_pick.remove(random_choice)
if not team_pick:
traitor_pick = False
team_pick = list(range(num_teams))
#in FFA, each player is a different team so no need to randomize
if num_teams == len(self.move_serials):
for i,move in enumerate(self.move_serials):
self.teams[serial] = i
else:
team_pick = list(range(num_teams))
traitor_pick = True
copy_serials = self.move_serials[:]

while len(copy_serials) >= 1:
#for serial in self.move_serials:
serial = random.choice(copy_serials)
copy_serials.remove(serial)
random_choice = random.choice(team_pick)
if self.game_mode == common.Games.Traitor and traitor_pick:
self.teams[serial] = (random_choice * -1) - 1
else:
self.teams[serial] = random_choice
## print("doing random choice")
## print(random_choice)
team_pick.remove(random_choice)
if not team_pick:
traitor_pick = False
team_pick = list(range(num_teams))

def track_moves(self):
for move_num, move_serial in enumerate(self.move_serials):
Expand Down
14 changes: 11 additions & 3 deletions piparty.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,15 @@ def initialize_settings(self):
'random_modes': [common.Games.JoustFFA.pretty_name],
'play_audio': True,
'move_can_be_admin': True,
'enforce_minimum': True
'enforce_minimum': True,
'red_on_kill': True,
'random_teams': True,
'color_lock': False,
'color_lock_choices':{
2: ['Magenta','Green'],
3: ['Orange','Turquoise','Purple'],
4: ['Yellow','Green','Blue','Purple']
}
})
try:
#catch either file opening or yaml loading failing
Expand All @@ -517,8 +525,8 @@ def initialize_settings(self):
except:
pass

for setting in common.REQUIRED_SETTINGS:
if setting not in temp_settings.keys():
for setting in temp_settings.keys():
if setting not in common.REQUIRED_SETTINGS:
temp_settings.pop(setting)
#random mode games can't be empty
if temp_settings['random_modes'] == []:
Expand Down
69 changes: 52 additions & 17 deletions templates/settings.html
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
{% extends "basic.html" %}
{% block header %}
<script>
//used to forcibly leave settings page if in game
//no longer needed since settings can update while in game
//they just take effect in the next round
function updateStatus(){
function randomize(){
clicked = $(':focus')[0].id;
$.ajax({
url: 'updateStatus',
url: clicked,
timeout: 2000,
success: function(rawdata){
info = JSON.parse(rawdata);
if (info.game_status != 'menu'){
window.location.replace("/");
}
console.log(rawdata)
teams = JSON.parse(rawdata);
$('.'+clicked).each(function(){
$(this).val(teams.pop());
})
},
error: function(){
console.log('something broke!')
}
});
};

//$(document).ready(function(){
// updateStatus();
// setInterval(updateStatus,1000);
//});
$(document).ready(function(){
$('.rand').click(function(){
randomize()
});

$('#random_mode_options').hide();
$('#random_toggle').click(function(){
$('#random_mode_options').toggle();
});

$('#color_lock_options').hide();
$('#color_lock_toggle').click(function(){
$('#color_lock_options').toggle();
});
});
</script>
<style>
p{line-height: 200%}
span {line-height: 200%}
</style>
{% endblock %}

Expand Down Expand Up @@ -55,15 +66,39 @@ <h3>Admin Settings</h3>
{{ form.play_audio(checked=settings.play_audio) }} {{form.play_audio.label}}
</p>
<p>
{{ form.random_teams(checked=settings.random_teams) }} {{form.random_teams.label}}
</p>
<p>
{{ form.color_lock(checked=settings.color_lock) }} {{form.color_lock.label}}
</p>
<p>
{{ form.red_on_kill }} {{form.red_on_kill.label}}
</p>
<p>
{{ form.sensitivity }} {{form.sensitivity.label}}
</p>
<p id="random">
Random Mode Game Selection<br />
<p>
Random Mode Game Selection <button type="button" id="random_toggle">Show/Hide</button><br />
<span id="random_mode_options">
{% for item in form.random_modes %}
{{ item(checked=item.data in settings.random_modes) }} {{ item.label }} <br />
{% endfor %}
</p>
<input type="submit" value="Save Settings">
</span></p>
<p>
Color Lock Selection <button type="button" id="color_lock_toggle">Show/Hide</button><br />
<span id="color_lock_options">
Dual Teams<br/>
{% for i in range(2) %}{{ form.color_lock_choices[i](class_="rand2") }} {% endfor %}<br/>
<button type="button" class="rand" id="rand2">Randomize</button><br/>
Tri Teams<br/>
{% for i in range(2,5) %}{{ form.color_lock_choices[i](class_="rand3") }} {% endfor %}<br/>
<button type="button" class="rand" id="rand3">Randomize</button><br/>
Quad Teams<br/>
{% for i in range(5,9) %}{{ form.color_lock_choices[i](class_="rand4") }} {% endfor %}<br/>
<button type="button" class="rand" id="rand4">Randomize</button><br/>
</span></p>

<br/><input type="submit" value="Save Settings">
</form>
<a href="/"><button type="button">Go Back</button></a>
</div>
Expand Down
Loading

0 comments on commit 9f7d40c

Please sign in to comment.