def layout(cell,extra_params=None): context.push() loadcell(cell) global pcell_updates for name,value in pcell_updates: context.bag[name]['value'] = value run(context.props['cbs'][name]) pcell_updates = [] #Must be called after pcell updates apply_params() if extra_params: assert(isinstance(extra_params,list)) for t in extra_params: context.params[t[0]] = t[2] print "inst params: " + str(context.params) p = pickle.dumps(frozenset(context.params.items())) h = hashlib.md5(p).hexdigest() cell_name = current_cell['cell_name'] + "@" + h[:10] if cell_name in cell_lib: context.pop() return cell_lib[cell_name] runtime.push_cell(cell_name) print skill.procedures[current_cell['func']]({'parameters' : context.params, 'lib' : {'name' : skill.variables['cdfgData']['id']['lib']['name']} , 'cell' : {'name' : skill.variables['cdfgData']['id']['cell']['name']}} ) context.pop() cell_lib[cell_name] = runtime.pop_cell() return cell_lib[cell_name]
def handleiconclick(self, vicon): if vicon == "trash": if panels.selectedtile is not None: panels.claimtile() self.clearselections() elif vicon == "zoomin": vista.zoomin() elif vicon == "zoomout": vista.zoomout() elif vicon == "menu": game.save() context.push(menu.Menu()) elif vicon == "music": noise.nexttrack() elif vicon == "heal": game.state.body.core.setbranchstatus() if self.healmode: self.clearselections() else: self.clearselections() if vista.icons["heal"].active: self.healmode = True elif vicon == "cut": if self.cutmode: self.clearselections() else: self.clearselections() if vista.icons["cut"].active: self.cutmode = True
def main(): vista.init() vista.addsplash() pygame.display.set_caption(_("Obb is loading.... Please wait")) noise.nexttrack() if settings.restart: game.restart() else: game.load() context.push(play.Play()) clock = pygame.time.Clock() savetime = settings.savetimer while context.top(): dt = clock.tick(settings.maxfps) * 0.001 * settings.gamespeed dt = min(dt, 1.0 / settings.minfps) con = context.top() events = pygame.event.get() keys = pygame.key.get_pressed() mousepos = pygame.mouse.get_pos() buttons = pygame.mouse.get_pressed() if settings.autosave: savetime -= dt if savetime < 0: game.save() settings.save() savetime = settings.savetimer for event in events: if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE): if settings.saveonquit: settings.save() game.save() pygame.quit() return if event.type == KEYDOWN and event.key == K_F12: vista.screencap() if event.type == KEYDOWN and event.key == K_F3: settings.showfps = not settings.showfps con.think(dt, events, keys, mousepos, buttons) con.draw() if settings.showfps: t = pygame.time.get_ticks() * 0.001 if int(t / 5.0) != int((t - dt) / 5.0): # Update once every 5 seconds fpsstring = "%.1ffps" % clock.get_fps() try: mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss // 1024 fpsstring += " %sMB" % mem except: pass pygame.display.set_caption("Obb - %s" % fpsstring) if settings.fullscreen: print(fpsstring) else: pygame.display.set_caption("Obb")
def main(): vista.init() pygame.display.set_caption("Obb is loading.... Please wait") savefile = data.filepath("savegame.pkl") noise.nexttrack() if settings.restart: context.push(play.Play()) else: try: context.push(cPickle.load(open(savefile, "rb"))) except: context.push(play.Play()) clock = pygame.time.Clock() savetime = settings.savetimer while context.top(): dt = min(clock.tick(settings.maxfps) * 0.001, 1./settings.minfps) if settings.fast: dt *= 2 con = context.top() events = pygame.event.get() keys = pygame.key.get_pressed() mousepos = pygame.mouse.get_pos() buttons = pygame.mouse.get_pressed() if settings.autosave: savetime -= dt if savetime < 0: cPickle.dump(con, open(savefile, "wb")) savetime = settings.savetimer for event in events: if event.type == QUIT: if settings.saveonquit: cPickle.dump(con, open(savefile, "wb")) return if event.type == KEYDOWN and event.key == K_ESCAPE: if settings.saveonquit: cPickle.dump(con, open(savefile, "wb")) return if event.type == KEYDOWN and event.key == K_F12: vista.screencap() if event.type == KEYDOWN and event.key == K_F9: # Manual save cPickle.dump(con, open(savefile, "wb")) con.think(dt, events, keys, mousepos, buttons) con.draw() if settings.showfps: pygame.display.set_caption("Obb - %.1ffps" % clock.get_fps()) if settings.fullscreen: print clock.get_fps() else: pygame.display.set_caption("Obb")
def main(): vista.init() pygame.display.set_caption("Obb is loading.... Please wait") savefile = data.filepath("savegame.pkl") noise.nexttrack() if settings.restart: context.push(play.Play()) else: try: context.push(cPickle.load(open(savefile, "rb"))) except: context.push(play.Play()) clock = pygame.time.Clock() savetime = settings.savetimer while context.top(): dt = min(clock.tick(settings.maxfps) * 0.001, 1. / settings.minfps) if settings.fast: dt *= 2 con = context.top() events = pygame.event.get() keys = pygame.key.get_pressed() mousepos = pygame.mouse.get_pos() buttons = pygame.mouse.get_pressed() if settings.autosave: savetime -= dt if savetime < 0: cPickle.dump(con, open(savefile, "wb")) savetime = settings.savetimer for event in events: if event.type == QUIT: if settings.saveonquit: cPickle.dump(con, open(savefile, "wb")) return if event.type == KEYDOWN and event.key == K_ESCAPE: if settings.saveonquit: cPickle.dump(con, open(savefile, "wb")) return if event.type == KEYDOWN and event.key == K_F12: vista.screencap() if event.type == KEYDOWN and event.key == K_F9: # Manual save cPickle.dump(con, open(savefile, "wb")) con.think(dt, events, keys, mousepos, buttons) con.draw() if settings.showfps: pygame.display.set_caption("Obb - %.1ffps" % clock.get_fps()) if settings.fullscreen: print clock.get_fps() else: pygame.display.set_caption("Obb")
def quitgame(self): context.pop(2) context.push(self) self.active = False
def think(self, dt, events, keys, mousepos, buttons): if vista.vrect.collidepoint(mousepos): edge = vista.grid.nearestedge(vista.screentoworld(mousepos)) if edge != self.edgepoint: if panels.selectedtile is not None: appspec = status.state.tiles[panels.selectedtile] self.parttobuild = game.state.body.canplaceapp(edge, appspec) elif panels.selectedorgan is not None: otype = panels.selectedorgan self.parttobuild = game.state.body.canplaceorgan(edge, otype) if self.parttobuild is not None: worldpos = vista.HexGrid.edgeworld(*edge) visible = game.state.body.mask.isvisible(worldpos) self.canbuild = game.state.body.canaddpart(self.parttobuild) and visible self.parttobuild.status = "ghost" if self.canbuild else "badghost" else: edge = None self.parttobuild = None self.edgepoint = edge for event in events: if event.type == KEYDOWN and event.key == K_SPACE: if settings.debugkeys: game.state.body.addrandompart() if event.type == KEYDOWN and event.key == K_BACKSPACE: if settings.debugkeys: game.state.body.addrandompart(20) if event.type == KEYDOWN and event.key == K_v: if settings.debugkeys: wpos = vista.screentoworld(mousepos) print("Visibility:", game.state.body.mask.visibility(wpos)) if event.type == KEYUP and event.key == K_x: if settings.debugkeys: if self.target is not None: self.target.die() if event.type == KEYUP and event.key == K_F11: context.push(makemap.MakeMap()) if event.type == KEYUP and event.key == K_F9: context.push(restart.Restart()) if event.type == MOUSEBUTTONDOWN and event.button == 1: self.clickat = event.pos if event.type == MOUSEBUTTONUP and event.button == 1: self.handleleftclick(mousepos) if event.type == MOUSEBUTTONUP and event.button == 3: self.handlerightclick(mousepos) if event.type == MOUSEBUTTONUP and event.button == 4 and settings.zoomonscroll: vista.zoomin() if event.type == MOUSEBUTTONUP and event.button == 5 and settings.zoomonscroll: vista.zoomout() if event.type == MOUSEMOTION and event.buttons[0]: self.handleleftdrag(event.pos, event.rel) if settings.showtips: tip.settip(self.choosetip(mousepos)) if keys[K_F5] and settings.debugkeys: game.state.body.addrandompart() if (keys[K_x] and settings.debugkeys) or self.cutmode: newtarget = self.pointchildbyedge(mousepos) if newtarget != self.target: if self.target is not None: self.target.setbranchstatus() self.target = newtarget if self.target is not None: self.target.setbranchstatus("target") elif self.healmode: game.state.body.sethealstatus() self.target = game.state.body.nearestorgan(vista.screentoworld(mousepos)) elif self.target is not None: self.target.setbranchstatus() self.target = None vista.think(dt, mousepos, keys) vista.icons["cut"].selected = self.cutmode vista.icons["heal"].selected = self.healmode game.state.think(dt) status.state.think(dt) tip.think(dt)
def execute(self, context): context.push() dict = context.eval(self.expr) context.update(dict) self.body.execute(context) context.pop()