def __init__(self, game, *args, **kwargs): Screen.__init__(self, *args, **kwargs) self.backdrop = common_res.bg_ingame self.flash_alpha = 0.0 self.game = game self.ui_class = game.ui_meta.ui_class self.gameui = self.ui_class(parent=False, game=game, **r2d((0, 0, 820, 720))) # add when game starts self.events_box = GameScreen.EventsBox(parent=self) self.chat_box = GameScreen.ChatBox(parent=self) self.panel = GameScreen.RoomControlPanel(parent=self) self.btn_exit = Button(parent=self, caption=u'退出房间', zindex=1, **r2d((730, 670, 75, 25))) @self.btn_exit.event def on_click(): box = ConfirmBox(u'真的要离开吗?', buttons=ConfirmBox.Presets.OKCancel, parent=self) @box.event def on_confirm(val): if val: Executive.call('exit_game', ui_message, [])
def set_header(self, missed_planet): if missed_planet: self.header['res'] = '# res not set\n' self.header['orientation'] = '# orientation not set\n' self.header['aspect'] = '# aspect tip, rotate not set\n' self.header['rNorm'] = '# rNorm not set\n' else: self.header['orientation'] = '# orientation: {}\n'.format( repr(self.config.orientation)) self.header[ 'aspect'] = '# aspect tip, rotate: {:.4f} {:.4f}\n'.format( utils.r2d(self.tip), utils.r2d(self.rotate)) self.header['rNorm'] = '# rNorm: {}\n'.format(self.rNorm) if self.bType: self.header['bType'] = '# bType: {}\n'.format(self.bType) if self.outType: self.header['outType'] = '# outType: {}\n'.format( self.outType) if self.outType == 'image': self.header['imgSize'] = '# imgSize: {}\n'.format( self.imSize) resolution = utils.r2asec( math.atan( abs(self.b[1][0] - self.b[0][0]) * self.rNorm / self.config.distance)) print('resolution = ', resolution) self.header['res'] = '# res: {} arcsec\n'.format( resolution) self.header['gtype'] = '# gtype: {}\n'.format(self.config.gtype) self.header['radii'] = '# radii: {:.1f} {:.1f} km\n'.format( self.config.Req, self.config.Rpol) self.header['distance'] = '# distance: {} km\n'.format( self.config.distance)
def __init__(self, parent=None): Control.__init__(self, parent=parent, **r2d((0, 0, 820, 720))) self.btn_getready = Button( parent=self, caption=u'准备', **r2d((360, 80, 100, 35)) ) self.ready = False l = [] class MyPP(PlayerPortrait): # this class is INTENTIONALLY put here # to make cached avatars get gc'd cached_avatar = {} for x, y, color in parent.ui_class.portrait_location: l.append(MyPP('NONAME', parent=self, x=x, y=y, color=color)) self.portraits = l @self.btn_getready.event def on_click(): if self.ready: Executive.call('cancel_ready', ui_message, []) self.ready = False self.btn_getready.caption = u'准备' self.btn_getready.update() else: Executive.call('get_ready', ui_message, []) #self.btn_getready.state = Button.DISABLED self.ready = True self.btn_getready.caption = u'取消准备' self.btn_getready.update()
def __init__(self, game, *args, **kwargs): Screen.__init__(self, *args, **kwargs) self.backdrop = common_res.bg_ingame self.flash_alpha = 0.0 self.game = game self.ui_class = game.ui_meta.ui_class self.gameui = self.ui_class( parent=False, game=game, **r2d((0, 0, 820, 720)) ) # add when game starts self.events_box = GameScreen.EventsBox(parent=self) self.chat_box = GameScreen.ChatBox(parent=self) self.panel = GameScreen.RoomControlPanel(parent=self) self.btn_exit = Button( parent=self, caption=u'退出房间', zindex=1, **r2d((730, 670, 75, 25)) ) @self.btn_exit.event def on_click(): box = ConfirmBox(u'真的要离开吗?', buttons=ConfirmBox.Presets.OKCancel, parent=self) @box.event def on_confirm(val): if val: Executive.call('exit_game', ui_message, [])
def __init__(self, parent=None): Control.__init__(self, parent=parent, **r2d((0, 0, 820, 720))) self.btn_getready = Button(parent=self, caption=u'准备', **r2d((360, 80, 100, 35))) self.ready = False l = [] class MyPP(PlayerPortrait): # this class is INTENTIONALLY put here # to make cached avatars get gc'd cached_avatar = {} for x, y, color in parent.ui_class.portrait_location: l.append(MyPP('NONAME', parent=self, x=x, y=y, color=color)) self.portraits = l @self.btn_getready.event def on_click(): if self.ready: Executive.call('cancel_ready', ui_message, []) self.ready = False self.btn_getready.caption = u'准备' self.btn_getready.update() else: Executive.call('get_ready', ui_message, []) #self.btn_getready.state = Button.DISABLED self.ready = True self.btn_getready.caption = u'取消准备' self.btn_getready.update()
def print_a_step(self): s = '\ttype: %s, gamma = %.2f deg, lat = %.2f deg, lng = %.2f |g| = %.2f\n' % ( self.gtype, u.r2d(self.gamma), u.r2d( self.pclat), u.r2d(self.delta_lng), self.gmag * 1000.0) s += '\tr = [%.2f, %.2f, %.2f] km, |r| = %.2f km\n' % ( self.r[_X], self.r[_Y], self.r[_Z], self.rmag) s += '\tn = [%.4f, %.4f, %.4f]' % (self.n[_X], self.n[_Y], self.n[_Z]) print(s) return s
def __str__(self): s = '-------------------------Geoid---------------------------\n' s += 'type: %s, gamma = %.2f deg, lat = %.2f deg, lng = %.2f\n' % ( self.gtype, u.r2d(self.gamma), u.r2d( self.pclat), u.r2d(self.delta_lng)) s += 'r = [%.2f, %.2f, %.2f] km, |r| = %.2f km\n' % ( self.r[_X], self.r[_Y], self.r[_Z], self.rmag) s += 'n = [%.4f, %.4f, %.4f]\n' % (self.n[_X], self.n[_Y], self.n[_Z]) s += 't = [%.4f, %.4f, %.4f]\n' % (self.t[_X], self.t[_Y], self.t[_Z]) s += 'g = [%.6f, %.6f], |g| = %.6f\n' % (self.g[0], self.g[1], self.gmag) s += '---------------------------------------------------------\n' return s
def findEdge(atm, b, rNorm, tip, rotate, gtype, printdot=False): tmp = (b[0]**2 + b[1]**2) try: zQ_Trial = np.arange(math.sqrt(1.0 - tmp) * 1.01, 0.0, -0.005) except ValueError: return None, None pclat_zQ_Trial = [] r_zQ_Trial = [] r_pclat_zQ_Trial = [] hitPlanet = False geoid = shape.Shape(gtype) for zQ in zQ_Trial: if printdot: print('.', end='') sys.stdout.flush() # Q b_vec = np.array([b[0], b[1], zQ]) # --> P b_vec = rotate2planet(rotate, tip, b_vec) r1 = np.linalg.norm(b_vec) * rNorm r_zQ_Trial.append(r1) # get planetocentric latitude/longitude pclat = utils.r2d( math.asin(np.dot(b_vec, yHat) / np.linalg.norm(b_vec))) delta_lng = utils.r2d( math.atan2(np.dot(b_vec, xHat), np.dot(b_vec, zHat))) pclat_zQ_Trial.append(pclat) r2 = geoid.calcShape(atm, rNorm, pclat, delta_lng) r_pclat_zQ_Trial.append(r2) if r1 <= r2: hitPlanet = True break if not hitPlanet: return None, None # interpolate to value xx = np.flipud(np.array(r_zQ_Trial) - np.array(r_pclat_zQ_Trial)) yy = np.flipud(np.array(zQ_Trial[0:len(r_zQ_Trial)])) try: zQ = np.interp(0.0, xx, yy) b = np.array([b[0], b[1], zQ]) edge = rNorm * rotate2planet(rotate, tip, b) except ValueError: b = None edge = None del zQ_Trial, pclat_zQ_Trial, r_zQ_Trial, r_pclat_zQ_Trial, geoid, xx, yy return edge, b # same vector but in P and Q coordinate systems
def findEdge(atm, b, rNorm, tip, rotate, gtype, printdot=False): tmp = (b[0]**2 + b[1]**2) try: zQ_Trial = np.arange(math.sqrt(1.0 - tmp) * 1.01, 0.0, -0.005) except ValueError: return None, None pclat_zQ_Trial = [] r_zQ_Trial = [] r_pclat_zQ_Trial = [] hitPlanet = False geoid = shape.Shape(gtype) for zQ in zQ_Trial: if printdot: print('.', end='') sys.stdout.flush() # Q b_vec = np.array([b[0], b[1], zQ]) # --> P b_vec = rotate2planet(rotate, tip, b_vec) r1 = np.linalg.norm(b_vec) * rNorm r_zQ_Trial.append(r1) # get planetocentric latitude/longitude pclat = utils.r2d(math.asin(np.dot(b_vec, yHat) / np.linalg.norm(b_vec))) delta_lng = utils.r2d(math.atan2(np.dot(b_vec, xHat), np.dot(b_vec, zHat))) pclat_zQ_Trial.append(pclat) r2 = geoid.calcShape(atm, rNorm, pclat, delta_lng) r_pclat_zQ_Trial.append(r2) if r1 <= r2: hitPlanet = True break if not hitPlanet: return None, None # interpolate to value xx = np.flipud(np.array(r_zQ_Trial) - np.array(r_pclat_zQ_Trial)) yy = np.flipud(np.array(zQ_Trial[0:len(r_zQ_Trial)])) try: zQ = np.interp(0.0, xx, yy) b = np.array([b[0], b[1], zQ]) edge = rNorm * rotate2planet(rotate, tip, b) except ValueError: b = None edge = None del zQ_Trial, pclat_zQ_Trial, r_zQ_Trial, r_pclat_zQ_Trial, geoid, xx, yy return edge, b # same vector but in P and Q coordinate systems
def on_message(self, _type, *args): rst = handle_chat(_type, args) if rst: self.chat_box.append(rst) elif _type == 'game_started': self.remove_control(self.panel) self.gameui.init() self.add_control(self.gameui) self.game.start() # utils.hub_interrupt(self.game.start) elif _type == 'end_game': self.remove_control(self.gameui) self.add_control(self.panel) g = args[0] elif _type == 'client_game_finished': g = args[0] g.ui_meta.ui_class.show_result(g) elif _type in ('game_left', 'fleed'): GameHallScreen().switch() elif _type == 'game_joined': # last game ended, this is the auto # created game self.game = game = args[0] self.panel.btn_getready.state = Button.NORMAL self.gameui = self.ui_class( parent=False, game=self.game, **r2d((0, 0, 820, 720)) ) SoundManager.switch_bgm(common_res.bgm_hall) self.backdrop = common_res.bg_ingame self.set_color(Colors.green) self.events_box.clear() elif _type == 'game_crashed': ConfirmBox(u'游戏逻辑已经崩溃,请退出房间!\n这是不正常的状态,你可以报告bug。', parent=self) elif _type == 'observe_request': uid, uname = args[0] box = ConfirmBox( u'玩家 %s 希望旁观你的游戏,是否允许?\n旁观玩家可以看到你的手牌。' % uname, parent=self, buttons=((u'允许', True), (u'不允许', False)), default=False ) @box.event def on_confirm(val, uid=uid): Executive.call('observe_grant', ui_message, [uid, val]) else: Screen.on_message(self, _type, *args)
def on_message(self, _type, *args): rst = handle_chat(_type, args) if rst: self.chat_box.append(rst) elif _type == 'game_started': self.remove_control(self.panel) self.gameui.init() self.add_control(self.gameui) self.game.start() # utils.hub_interrupt(self.game.start) elif _type == 'end_game': self.remove_control(self.gameui) self.add_control(self.panel) g = args[0] elif _type == 'client_game_finished': g = args[0] g.ui_meta.ui_class.show_result(g) elif _type in ('game_left', 'fleed'): GameHallScreen().switch() elif _type == 'game_joined': # last game ended, this is the auto # created game self.game = game = args[0] self.panel.btn_getready.state = Button.NORMAL self.gameui = self.ui_class(parent=False, game=self.game, **r2d((0, 0, 820, 720))) SoundManager.switch_bgm(common_res.bgm_hall) self.backdrop = common_res.bg_ingame self.set_color(Colors.green) self.events_box.clear() elif _type == 'game_crashed': ConfirmBox(u'游戏逻辑已经崩溃,请退出房间!\n这是不正常的状态,你可以报告bug。', parent=self) elif _type == 'observe_request': uid, uname = args[0] box = ConfirmBox(u'玩家 %s 希望旁观你的游戏,是否允许?\n旁观玩家可以看到你的手牌。' % uname, parent=self, buttons=((u'允许', True), (u'不允许', False)), default=False) @box.event def on_confirm(val, uid=uid): Executive.call('observe_grant', ui_message, [uid, val]) else: Screen.on_message(self, _type, *args)
def __init__(self, parent=None): Control.__init__(self, parent=parent, **r2d((0, 0, 820, 720))) self.btn_getready = Button(parent=self, caption=u"准备", **r2d((360, 80, 100, 35))) self.btn_invite = Button(parent=self, caption=u"邀请", **r2d((360, 40, 100, 35))) self.ready = False l = [] class MyPP(PlayerPortrait): # this class is INTENTIONALLY put here # to make cached avatars get gc'd cached_avatar = {} for x, y, color in parent.ui_class.portrait_location: l.append(MyPP("NONAME", parent=self, x=x, y=y, color=color)) self.portraits = l @self.btn_getready.event def on_click(): if self.ready: Executive.call("cancel_ready", ui_message, []) self.ready = False self.btn_getready.caption = u"准备" self.btn_getready.update() else: Executive.call("get_ready", ui_message, []) # self.btn_getready.state = Button.DISABLED self.ready = True self.btn_getready.caption = u"取消准备" self.btn_getready.update() @self.btn_invite.event # noqa def on_click(): GameScreen.InvitePanel(self.parent.game.gameid, parent=self)
def __init__(self, game, *a, **k): self.game = game game.event_observer = UIEventHook Control.__init__(self, *a, **k) self.char_portraits = None self.deck_indicator = DeckIndicator(parent=self, x=30, y=680, width=50, height=25) self.handcard_area = HandCardArea(parent=self, x=238, y=9, zindex=3, width=93 * 5 + 42, height=145) self.deck_area = PortraitCardArea( parent=self, width=1, height=1, x=self.width // 2, y=self.height // 2, zindex=4 ) self.btn_afk = Button(parent=self, caption=u"让⑨帮你玩", zindex=1, color=Colors.blue, **r2d((730, 640, 75, 25))) self.gameintro_icon = GameIntroIcon(parent=self, game=game, **r2d((780, 610, 25, 25))) self.afk = False @self.btn_afk.event def on_click(): v = not self.afk self.afk = v self.btn_afk.color = (Colors.blue, Colors.orange)[v] self.btn_afk.update() @self.handcard_area.event def on_selection_change(): self.dispatch_event("on_selection_change") self.dropcard_area = DropCardArea(parent=self, x=0, y=324, zindex=3, width=820, height=125) class Animations(pyglet.graphics.Batch, Control): def __init__(self, **k): pyglet.graphics.Batch.__init__(self) Control.__init__(self, x=0, y=0, width=0, height=0, zindex=2, **k) def hit_test(self, x, y): return False self.animations = Animations(parent=self) self.selecting_player = 0
def set_header(self, missed_planet): if missed_planet: self.header['res'] = '# res not set\n' self.header['orientation'] = '# orientation not set\n' self.header['aspect'] = '# aspect tip, rotate not set\n' self.header['rNorm'] = '# rNorm not set\n' else: self.header['orientation'] = '# orientation: {}\n'.format(repr(self.config.orientation)) self.header['aspect'] = '# aspect tip, rotate: {:.4f} {:.4f}\n'.format(utils.r2d(self.tip), utils.r2d(self.rotate)) self.header['rNorm'] = '# rNorm: {}\n'.format(self.rNorm) if self.bType: self.header['bType'] = '# bType: {}\n'.format(self.bType) if self.outType: self.header['outType'] = '# outType: {}\n'.format(self.outType) if self.outType == 'image': self.header['imgSize'] = '# imgSize: {}\n'.format(self.imSize) resolution = utils.r2asec(math.atan(abs(self.b[1][0] - self.b[0][0]) * self.rNorm / self.config.distance)) print('resolution = ', resolution) self.header['res'] = '# res: {} arcsec\n'.format(resolution) self.header['gtype'] = '# gtype: {}\n'.format(self.config.gtype) self.header['radii'] = '# radii: {:.1f} {:.1f} km\n'.format(self.config.Req, self.config.Rpol) self.header['distance'] = '# distance: {} km\n'.format(self.config.distance)
def compute_ds(atm, b, orientation=None, gtype=None, verbose=False, plot=True): """Computes the path length through the atmosphere given: b = impact parameter (fractional distance to outer edge at that latitude in observer's coordinates) orientation = position angle of the planet [0]='tip', [1]='subearth latitude' """ if gtype is None: gtype = atm.config.gtype if orientation is None: orientation = atm.config.orientation path = Ray() req = atm.layerProperty[atm.config.LP['R']] # radius of layers along equator rNorm = req[0] nr = atm.layerProperty[atm.config.LP['N']] # refractive index of layers P = atm.gas[atm.config.C['P']] if (b[0]**2 + b[1]**2) > 1.0: return path mu = math.sqrt(1.0 - b[0]**2 - b[1]**2) f = 1.0 - atm.config.Rpol / atm.config.Req tip, rotate = computeAspect(orientation, f) if verbose: print('intersection: ({:.3f}, {:.3f}) '.format(b[0], b[1]), end='') print('aspect: ({:%.4f}, {:.4f})'.format(tip * 180.0 / np.pi, rotate * 180.0 / np.pi)) print('Finding atmospheric edge', end='') edge, b = findEdge(atm, b, rNorm, tip, rotate, gtype) if edge is None: return path r1 = np.linalg.norm(edge) # get planetocentric latitude/longitude pclat = utils.r2d(math.asin(np.dot(edge, yHat) / np.linalg.norm(edge))) delta_lng = utils.r2d(math.atan2(np.dot(edge, xHat), np.dot(edge, zHat))) geoid = shape.Shape(gtype) r2 = geoid.calcShape(atm, rNorm, pclat, delta_lng) if verbose: print(' within {:.2f} m'.format(abs(r1 - r2) * 100.0)) geoid.printShort() if plot: plotStuff(atm=atm, r=rNorm, b=b, gtype=gtype, delta_lng=delta_lng, geoid=geoid, tip=tip, rotate=rotate) # initialize - everything below is in planetocentric coordinates, so need to rotate s-vector start = np.array([0.0, 0.0, -1.0]) start = rotate2planet(rotate, tip, start) s = [start] n = [geoid.n] r = [geoid.r] t_inc = [math.acos(-np.dot(s[-1], n[-1]))] # incident angle_0 nratio = nr[0] / nr[1] # refractive index ratio_0 t_tran = [math.asin(nratio * math.sin(t_inc[-1]))] # transmitted angle_0 # return array initialization, use a value to keep indexing numbering for loop ds = [0.0] layer4ds = [0.0] r4ds = [0.0] # not needed, but for information P4ds = [0.0] # not needed, but for information doppler = [] # loop while in atmosphere i = 0 # loops over the path layer = 0 # keeps track which physical layer you are in inAtmosphere = True direction = 'ingress' while inAtmosphere: if verbose: print('------------------') print('\tstep {d}: layer {d} {s} '.format(i, layer, direction)) print('\ts = [{:.4f}, {:.4f}, {:.4f}], ds = {:.4f}'.format(s[-1][_X], s[-1][_Y], s[-1][_Z], ds[-1])) geoid.print_a_step() print('\tt_inc, tran: {:.8f} -> {:.8f}'.format(utils.r2d(t_inc[-1]), utils.r2d(t_tran[-1]))) # update s-vector s.append(nratio * s[i] + raypathdir[direction] * (nratio * math.cos(t_inc[i]) * n[i] - math.cos(t_tran[i]) * n[i])) rNowMag = geoid.rmag rNextMag = geoid.calcShape(atm, req[layer + raypathdir[direction]], pclat, delta_lng) rdots = np.dot(r[i], s[i + 1]) vw = np.interp(pclat, atm.config.vwlat, atm.config.vwdat) / 1000.0 dopp = 1.0 - (atm.config.omega_m * rNowMag * math.cos(utils.d2r(pclat)) + vw) * math.sin(utils.d2r(delta_lng)) / 3.0E5 # get ds, checking for exit, errors and warnings... try: dsp = -rdots + math.sqrt(rdots**2.0 + rNextMag**2.0 - rNowMag**2.0) dsm = -rdots - math.sqrt(rdots**2.0 + rNextMag**2.0 - rNowMag**2.0) if direction == 'ingress': ds_step = dsm elif direction == 'egress': ds_step = dsp except ValueError: # tangent layer (probably) if direction == 'ingress': print('In tangent layer ', end='') direction = 'tangent' ds_step = -2.0 * rdots if ds_step > rNorm: inAtmosphere = False print('Error: tangent ds too large') break rNextMag = rNowMag else: inAtmosphere = False break if ds_step < 0.0: # What is correct here? Is this true for egress, or only in error? 8/1/14 I commented out if statement, # but only print statement was indented print('Error: ds < 0 ({}: r.s={}, ds={}, [{},{}])'.format(direction, rdots, ds_step, dsp, dsm)) inAtmosphere = False break if atm.config.limb == 'sec': # overwrite ds_step with secant version ds_step = abs(rNextMag - rNowMag) / mu # append to return arrays ds.append(ds_step) layer4ds.append(layer) r4ds.append(rNowMag) P4ds.append(atm.gas[atm.config.C['P']][layer]) doppler.append(dopp) # get next step, double-check r value (and compute n, etc) rnext = r[i] + ds[i + 1] * s[i + 1] pclat = utils.r2d(math.asin(np.dot(rnext, yHat) / np.linalg.norm(rnext))) delta_lng = utils.r2d(math.atan2(np.dot(rnext, xHat), np.dot(rnext, zHat))) r2 = geoid.calcShape(atm, req[layer + raypathdir[direction]], pclat, delta_lng) if abs(r2 - rNextMag) > 2.0 and layer != 0: print('Warning: {} != {} ({} km) at layer {}'.format(r2, rNextMag, r2 - rNextMag, layer)) r.append(rnext) # which is also geoid.r, or should be n.append(geoid.n) # get new incident angle layer += raypathdir[direction] if direction == 'tangent': direction = 'egress' t_inc.append(np.pi / 2.0) else: try: t_inc.append(math.acos(-raypathdir[direction] * np.dot(s[i + 1], n[i + 1]))) except ValueError: print('t_inc ValueError |s_(i+1)| = {}, |n_(i+1)| = {} - set to previous'.format(np.linalg.norm(s[i + 1]), np.linalg.norm(n[i + 1]))) t_inc.append(t_inc[i]) inAtmosphere = False break i += 1 # get refractive index ratio and check for exit try: nratio = nr[layer] / nr[layer + raypathdir[direction]] nratio = 1.0 try: t_tmp = math.asin(nratio * math.sin(t_inc[-1])) except ValueError: t_tmp = nratio * np.pi / 2.0 t_tran.append(t_tmp) except IndexError: inAtmosphere = False # ## end loop ### # Get rid of the first entry, which was just used to make indexing in loop consistent del ds[0], layer4ds[0], r4ds[0], P4ds[0] dsmu = [] for i in range(min(len(ds), len(r4ds)) - 1): if abs(r4ds[i] - r4ds[i + 1]) < 1E-6: dsmuappend = 0.001 else: dsmuappend = ds[i] / (r4ds[i] - r4ds[i + 1]) dsmu.append(dsmuappend) path.update(ds=ds, layer4ds=layer4ds, r4ds=r4ds, P4ds=P4ds, doppler=doppler, tip=tip, rotate=rotate, rNorm=rNorm) if plot: plt.figure('test_ds') plt.plot(dsmu) plt.plot([0, 1499], [1.0 / mu, 1.0 / mu]) plotStuff(r=np.array(r), ray=path) del s, r, n, ds, layer4ds, r4ds, P4ds, geoid, req, nr return path
def on_message(self, _type, *args): rst = handle_chat(_type, args) if rst: self.chat_box.append(rst) return elif _type == 'game_started': from utils import notify notify(u'东方符斗祭 - 游戏提醒', u'游戏已开始,请注意。') self.remove_control(self.panel) self.gameui.init() self.add_control(self.gameui) self.game.start() elif _type == 'end_game': self.remove_control(self.gameui) self.add_control(self.panel) g = args[0] elif _type == 'client_game_finished': g = args[0] g.ui_meta.ui_class.show_result(g) elif _type in ('game_left', 'fleed'): GameHallScreen().switch() elif _type == 'game_joined': # last game ended, this is the auto # created game self.game = args[0] self.panel.btn_getready.state = Button.NORMAL self.gameui = self.ui_class( parent=False, game=self.game, **r2d((0, 0, 820, 720)) ) SoundManager.switch_bgm(common_res.bgm_hall) self.backdrop = common_res.bg_ingame self.set_color(Colors.green) self.events_box.clear() elif _type == 'game_crashed': ConfirmBox( u'游戏逻辑已经崩溃,请退出房间!\n' u'这是不正常的状态,你可以报告bug。\n' u'游戏ID:%d' % self.game.gameid, parent=self ) from __main__ import do_crashreport do_crashreport() elif _type == 'observe_request': uid, uname = args[0] box = ConfirmBox( u'玩家 %s 希望旁观你的游戏,是否允许?\n' u'旁观玩家可以看到你的手牌。' % uname, parent=self, buttons=((u'允许', True), (u'不允许', False)), default=False ) @box.event def on_confirm(val, uid=uid): Executive.call('observe_grant', ui_message, [uid, val]) elif _type == 'observer_enter': obuid, obname, uname = args[0] self.chat_box.append( u'|B|R>> |r|c0000ffff%s|r[|c9100ffff%d|r]|r趴在了|c0000ffff%s|r身后\n' % (obname, obuid, uname) ) elif _type == 'observer_leave': obuid, obname, uname = args[0] self.chat_box.append( u'|B|R>> |r|c0000ffff%s|r飘走了\n' % obname ) else: Screen.on_message(self, _type, *args)
def printShort(self): s = '%s: gamma = %.2f, lat = %.2f, lng = %.2f, |r|=%.2f km\n' % (self.gtype, u.r2d(self.gamma), u.r2d(self.pclat), u.r2d(self.delta_lng), self.rmag) print(s) return s
def print_a_step(self): s = '\ttype: %s, gamma = %.2f deg, lat = %.2f deg, lng = %.2f |g| = %.2f\n' % (self.gtype, u.r2d(self.gamma), u.r2d(self.pclat), u.r2d(self.delta_lng), self.gmag * 1000.0) s += '\tr = [%.2f, %.2f, %.2f] km, |r| = %.2f km\n' % (self.r[_X], self.r[_Y], self.r[_Z], self.rmag) s += '\tn = [%.4f, %.4f, %.4f]' % (self.n[_X], self.n[_Y], self.n[_Z]) print(s) return s
def __init__(self, game, *a, **k): self.selection_change = ObservableEvent() self.game = game Control.__init__(self, can_focus=True, *a, **k) self.keystrokes = '\x00' self.char_portraits = None self.deck_indicator = DeckIndicator( parent=self, x=30, y=660, width=50, height=25, ) self.handcard_area = HandCardArea( parent=self, view=self, x=238, y=9, zindex=3, width=93 * 5 + 42, height=145, ) self.deck_area = PortraitCardArea( parent=self, width=1, height=1, x=self.width // 2, y=self.height // 2, zindex=4, ) self.btn_afk = OptionButton(parent=self, zindex=1, conf=( (u'让⑨帮你玩', Colors.blue, False), (u'⑨在帮你玩', Colors.orange, True), ), **r2d((30, 625, 75, 25))) self.gameintro_icon = GameIntroIcon(parent=self, game=game, **r2d((690, 630, 25, 25))) self.dropcard_area = DropCardArea( parent=self, x=0, y=324, zindex=3, width=820, height=125, ) class Animations(pyglet.graphics.Batch, Control): def __init__(self, **k): pyglet.graphics.Batch.__init__(self) Control.__init__(self, x=0, y=0, width=0, height=0, zindex=2, **k) self.animations = [] def delete(self): Control.delete(self) for a in self.animations: a.delete() def hit_test(self, x, y): return False self.animations = Animations(parent=self) self.selecting_player = 0 self.action_params = {}
def __init__(self, game, *a, **k): self.game = game game.event_observer = UIEventHook Control.__init__(self, can_focus=True, *a, **k) self.keystrokes = '\x00' self.char_portraits = None self.deck_indicator = DeckIndicator( parent=self, x=30, y=680, width=50, height=25, ) self.handcard_area = HandCardArea( parent=self, x=238, y=9, zindex=3, width=93 * 5 + 42, height=145, ) self.deck_area = PortraitCardArea( parent=self, width=1, height=1, x=self.width // 2, y=self.height // 2, zindex=4, ) self.btn_afk = Button(parent=self, caption=u'让⑨帮你玩', zindex=1, color=Colors.blue, **r2d((730, 640, 75, 25))) self.gameintro_icon = GameIntroIcon(parent=self, game=game, **r2d((780, 610, 25, 25))) self.afk = False @self.btn_afk.event def on_click(): v = not self.afk self.afk = v self.btn_afk.color = (Colors.blue, Colors.orange)[v] self.btn_afk.update() @self.handcard_area.event def on_selection_change(): self.dispatch_event('on_selection_change') self.dropcard_area = DropCardArea( parent=self, x=0, y=324, zindex=3, width=820, height=125, ) class Animations(pyglet.graphics.Batch, Control): def __init__(self, **k): pyglet.graphics.Batch.__init__(self) Control.__init__(self, x=0, y=0, width=0, height=0, zindex=2, **k) def hit_test(self, x, y): return False self.animations = Animations(parent=self) self.selecting_player = 0
def compute_ds(atm, b, orientation=None, gtype=None, verbose=False, plot=True): """Computes the path length through the atmosphere given: b = impact parameter (fractional distance to outer edge at that latitude in observer's coordinates) orientation = position angle of the planet [0]='tip', [1]='subearth latitude' """ if gtype is None: gtype = atm.config.gtype if orientation is None: orientation = atm.config.orientation path = Ray() req = atm.layerProperty[ atm.config.LP['R']] # radius of layers along equator rNorm = req[0] nr = atm.layerProperty[atm.config.LP['N']] # refractive index of layers P = atm.gas[atm.config.C['P']] if (b[0]**2 + b[1]**2) > 1.0: return path mu = math.sqrt(1.0 - b[0]**2 - b[1]**2) f = 1.0 - atm.config.Rpol / atm.config.Req tip, rotate = computeAspect(orientation, f) if verbose: print('intersection: ({:.3f}, {:.3f}) '.format(b[0], b[1]), end='') print('aspect: ({:%.4f}, {:.4f})'.format(tip * 180.0 / np.pi, rotate * 180.0 / np.pi)) print('Finding atmospheric edge', end='') edge, b = findEdge(atm, b, rNorm, tip, rotate, gtype) if edge is None: return path r1 = np.linalg.norm(edge) # get planetocentric latitude/longitude pclat = utils.r2d(math.asin(np.dot(edge, yHat) / np.linalg.norm(edge))) delta_lng = utils.r2d(math.atan2(np.dot(edge, xHat), np.dot(edge, zHat))) geoid = shape.Shape(gtype) r2 = geoid.calcShape(atm, rNorm, pclat, delta_lng) if verbose: print(' within {:.2f} m'.format(abs(r1 - r2) * 100.0)) geoid.printShort() if plot: plotStuff(atm=atm, r=rNorm, b=b, gtype=gtype, delta_lng=delta_lng, geoid=geoid, tip=tip, rotate=rotate) # initialize - everything below is in planetocentric coordinates, so need to rotate s-vector start = np.array([0.0, 0.0, -1.0]) start = rotate2planet(rotate, tip, start) s = [start] n = [geoid.n] r = [geoid.r] t_inc = [math.acos(-np.dot(s[-1], n[-1]))] # incident angle_0 nratio = nr[0] / nr[1] # refractive index ratio_0 t_tran = [math.asin(nratio * math.sin(t_inc[-1]))] # transmitted angle_0 # return array initialization, use a value to keep indexing numbering for loop ds = [0.0] layer4ds = [0.0] r4ds = [0.0] # not needed, but for information P4ds = [0.0] # not needed, but for information doppler = [] # loop while in atmosphere i = 0 # loops over the path layer = 0 # keeps track which physical layer you are in inAtmosphere = True direction = 'ingress' while inAtmosphere: if verbose: print('------------------') print('\tstep {d}: layer {d} {s} '.format(i, layer, direction)) print('\ts = [{:.4f}, {:.4f}, {:.4f}], ds = {:.4f}'.format( s[-1][_X], s[-1][_Y], s[-1][_Z], ds[-1])) geoid.print_a_step() print('\tt_inc, tran: {:.8f} -> {:.8f}'.format( utils.r2d(t_inc[-1]), utils.r2d(t_tran[-1]))) # update s-vector s.append( nratio * s[i] + raypathdir[direction] * (nratio * math.cos(t_inc[i]) * n[i] - math.cos(t_tran[i]) * n[i])) rNowMag = geoid.rmag rNextMag = geoid.calcShape(atm, req[layer + raypathdir[direction]], pclat, delta_lng) rdots = np.dot(r[i], s[i + 1]) vw = np.interp(pclat, atm.config.vwlat, atm.config.vwdat) / 1000.0 dopp = 1.0 - (atm.config.omega_m * rNowMag * math.cos(utils.d2r(pclat)) + vw) * math.sin(utils.d2r(delta_lng)) / 3.0E5 # get ds, checking for exit, errors and warnings... try: dsp = -rdots + math.sqrt(rdots**2.0 + rNextMag**2.0 - rNowMag**2.0) dsm = -rdots - math.sqrt(rdots**2.0 + rNextMag**2.0 - rNowMag**2.0) if direction == 'ingress': ds_step = dsm elif direction == 'egress': ds_step = dsp except ValueError: # tangent layer (probably) if direction == 'ingress': print('In tangent layer ', end='') direction = 'tangent' ds_step = -2.0 * rdots if ds_step > rNorm: inAtmosphere = False print('Error: tangent ds too large') break rNextMag = rNowMag else: inAtmosphere = False break if ds_step < 0.0: # What is correct here? Is this true for egress, or only in error? 8/1/14 I commented out if statement, # but only print statement was indented print('Error: ds < 0 ({}: r.s={}, ds={}, [{},{}])'.format( direction, rdots, ds_step, dsp, dsm)) inAtmosphere = False break if atm.config.limb == 'sec': # overwrite ds_step with secant version ds_step = abs(rNextMag - rNowMag) / mu # append to return arrays ds.append(ds_step) layer4ds.append(layer) r4ds.append(rNowMag) P4ds.append(atm.gas[atm.config.C['P']][layer]) doppler.append(dopp) # get next step, double-check r value (and compute n, etc) rnext = r[i] + ds[i + 1] * s[i + 1] pclat = utils.r2d( math.asin(np.dot(rnext, yHat) / np.linalg.norm(rnext))) delta_lng = utils.r2d( math.atan2(np.dot(rnext, xHat), np.dot(rnext, zHat))) r2 = geoid.calcShape(atm, req[layer + raypathdir[direction]], pclat, delta_lng) if abs(r2 - rNextMag) > 2.0 and layer != 0: print('Warning: {} != {} ({} km) at layer {}'.format( r2, rNextMag, r2 - rNextMag, layer)) r.append(rnext) # which is also geoid.r, or should be n.append(geoid.n) # get new incident angle layer += raypathdir[direction] if direction == 'tangent': direction = 'egress' t_inc.append(np.pi / 2.0) else: try: t_inc.append( math.acos(-raypathdir[direction] * np.dot(s[i + 1], n[i + 1]))) except ValueError: print( 't_inc ValueError |s_(i+1)| = {}, |n_(i+1)| = {} - set to previous' .format(np.linalg.norm(s[i + 1]), np.linalg.norm(n[i + 1]))) t_inc.append(t_inc[i]) inAtmosphere = False break i += 1 # get refractive index ratio and check for exit try: nratio = nr[layer] / nr[layer + raypathdir[direction]] nratio = 1.0 try: t_tmp = math.asin(nratio * math.sin(t_inc[-1])) except ValueError: t_tmp = nratio * np.pi / 2.0 t_tran.append(t_tmp) except IndexError: inAtmosphere = False # ## end loop ### # Get rid of the first entry, which was just used to make indexing in loop consistent del ds[0], layer4ds[0], r4ds[0], P4ds[0] dsmu = [] for i in range(min(len(ds), len(r4ds)) - 1): if abs(r4ds[i] - r4ds[i + 1]) < 1E-6: dsmuappend = 0.001 else: dsmuappend = ds[i] / (r4ds[i] - r4ds[i + 1]) dsmu.append(dsmuappend) path.update(ds=ds, layer4ds=layer4ds, r4ds=r4ds, P4ds=P4ds, doppler=doppler, tip=tip, rotate=rotate, rNorm=rNorm) if plot: plt.figure('test_ds') plt.plot(dsmu) plt.plot([0, 1499], [1.0 / mu, 1.0 / mu]) plotStuff(r=np.array(r), ray=path) del s, r, n, ds, layer4ds, r4ds, P4ds, geoid, req, nr return path
def printShort(self): s = '%s: gamma = %.2f, lat = %.2f, lng = %.2f, |r|=%.2f km\n' % ( self.gtype, u.r2d(self.gamma), u.r2d( self.pclat), u.r2d(self.delta_lng), self.rmag) print(s) return s
def __init__(self, game, *a, **k): self.selection_change = ObservableEvent() self.game = game Control.__init__(self, can_focus=True, *a, **k) self.keystrokes = '\x00' self.char_portraits = None self.deck_indicator = DeckIndicator( parent=self, x=30, y=660, width=50, height=25, ) self.handcard_area = HandCardArea( parent=self, view=self, x=238, y=9, zindex=3, width=93*5+42, height=145, ) self.deck_area = PortraitCardArea( parent=self, width=1, height=1, x=self.width//2, y=self.height//2, zindex=4, ) self.btn_afk = OptionButton( parent=self, zindex=1, conf=( (u'让⑨帮你玩', Colors.blue, False), (u'⑨在帮你玩', Colors.orange, True), ), **r2d((30, 625, 75, 25)) ) self.gameintro_icon = GameIntroIcon( parent=self, game=game, **r2d((690, 630, 25, 25)) ) self.dropcard_area = DropCardArea( parent=self, x=0, y=324, zindex=3, width=820, height=125, ) class Animations(pyglet.graphics.Batch, Control): def __init__(self, **k): pyglet.graphics.Batch.__init__(self) Control.__init__( self, x=0, y=0, width=0, height=0, zindex=2, **k ) self.animations = [] def delete(self): Control.delete(self) for a in self.animations: a.delete() def hit_test(self, x, y): return False self.animations = Animations(parent=self) self.selecting_player = 0 self.action_params = {}
def __str__(self): s = '-------------------------Geoid---------------------------\n' s += 'type: %s, gamma = %.2f deg, lat = %.2f deg, lng = %.2f\n' % (self.gtype, u.r2d(self.gamma), u.r2d(self.pclat), u.r2d(self.delta_lng)) s += 'r = [%.2f, %.2f, %.2f] km, |r| = %.2f km\n' % (self.r[_X], self.r[_Y], self.r[_Z], self.rmag) s += 'n = [%.4f, %.4f, %.4f]\n' % (self.n[_X], self.n[_Y], self.n[_Z]) s += 't = [%.4f, %.4f, %.4f]\n' % (self.t[_X], self.t[_Y], self.t[_Z]) s += 'g = [%.6f, %.6f], |g| = %.6f\n' % (self.g[0], self.g[1], self.gmag) s += '---------------------------------------------------------\n' return s
def on_message(self, _type, *args): rst = handle_chat(_type, args) if rst: self.chat_box.append(rst) return elif _type == 'game_started': from utils import notify notify(u'东方符斗祭 - 游戏提醒', u'游戏已开始,请注意。') self.remove_control(self.panel) self.add_control(self.gameui) self.gameui.init() self.game.start() elif _type == 'end_game': self.remove_control(self.gameui) self.add_control(self.panel) g = args[0] elif _type == 'client_game_finished': g = args[0] g.ui_meta.ui_class.show_result(g) elif _type in ('game_left', 'fleed'): GameHallScreen().switch() elif _type == 'game_joined': # last game ended, this is the auto # created game self.game = args[0] self.panel.btn_getready.state = Button.NORMAL self.gameui = self.ui_class( parent=False, game=self.game, **r2d((0, 0, 820, 720)) ) SoundManager.switch_bgm(common_res.bgm_hall) self.backdrop = common_res.bg_ingame.get() self.set_color(Colors.green) self.events_box.clear() elif _type == 'game_crashed': ConfirmBox( u'游戏逻辑已经崩溃,请退出房间!\n' u'这是不正常的状态,你可以报告bug。\n' u'游戏ID:%d' % self.game.gameid, parent=self ) from __main__ import do_crashreport do_crashreport() elif _type == 'observe_request': uid, uname = args[0] box = ConfirmBox( u'玩家 %s 希望旁观你的游戏,是否允许?\n' u'旁观玩家可以看到你的手牌。' % uname, parent=self, buttons=((u'允许', True), (u'不允许', False)), default=False ) @box.event def on_confirm(val, uid=uid): Executive.call('observe_grant', ui_message, [uid, val]) elif _type == 'observer_enter': obuid, obname, uname = args[0] self.chat_box.append( u'|B|R>> |r|c0000ffff%s|r[|c9100ffff%d|r]|r趴在了|c0000ffff%s|r身后\n' % (obname, obuid, uname) ) elif _type == 'observer_leave': obuid, obname, uname = args[0] self.chat_box.append( u'|B|R>> |r|c0000ffff%s|r飘走了\n' % obname ) else: Screen.on_message(self, _type, *args)