def on_block_build_attempt(self, x, y, z): cont = True if self.qb_recording and not self.qb_record_origin: self.qb_record_origin = (x, y, z) self.qb_record_dir = self.get_direction() if self.qb_recording == Q_COPYING: self.send_chat('Now place the opposite corner block!') else: self.send_chat('Now start building!') cont = False elif self.qb_recording == Q_COPYING: blocks = get_blocks(self.protocol.map, self.qb_record_origin, (x, y, z), self.qb_record_colors) blocks = shift_origin_all(blocks, self.qb_record_origin) blocks = rotate_all(blocks, self.qb_record_dir, EAST) self.qb_recorded = dict(blocks) self.qb_recording = Q_STOPPED self.send_chat('Copied area to buffer!') cont = False if self.qb_building: if self.qb_building == Q_BUILD_RECORDED: structure = rotate_all(self.qb_recorded, EAST, self.get_direction()) color = DIRT_COLOR if self.qb_record_colors else self.color else: self.qb_points -= self.qb_info.get('cost', 0) vx = AVX.fromfile(qb_fname(self.qb_info['name'])) structure = vx.tosparsedict() structure = shift_origin_all(structure, self.qb_info['origin']) structure = rotate_all(structure, EAST, self.get_direction()) color = DIRT_COLOR if vx.has_colors else self.color self.protocol.cbc_add( self.quickbuild_generator((x, y, z), structure, color)) self.qb_building = Q_OFF self.qb_info = None self.send_chat('Building structure!') cont = False if self.qb_recording == Q_ORIGINATING: new_origin = (x, y, z) shift = shift_origin(self.qb_record_origin, new_origin) self.qb_recorded = dict( shift_origin_all(self.qb_recorded, shift)) self.qb_record_origin = new_origin self.send_chat('New origin saved!') cont = False if not cont: return False return connection.on_block_build_attempt(self, x, y, z)
def qbsave(connection, name, cost=None, *description): fname = qb_fname(name) if not fname: return 'Invalid save name. Only alphanumeric characters allowed.' if not connection.qb_recorded: return 'Nothing is recorded yet!' shift = map(min, zip(*connection.qb_recorded.iterkeys())) origin = [-x for x in shift] info = {'colored': connection.qb_record_colors, 'origin': origin} if cost is not None: info['cost'] = int(cost) if description: info['description'] = ' '.join(description) qb_update_info(fname + '.txt', info) recorded = dict(shift_origin_all(connection.qb_recorded, shift)) AVX.fromsparsedict(recorded, info['colored']).save(fname) return 'Saved buffer to %s.avx' % name
def qbsave(connection, name, cost = None, *description): fname = qb_fname(name) if not fname: return 'Invalid save name. Only alphanumeric characters allowed.' if not connection.qb_recorded: return 'Nothing is recorded yet!' shift = map(min, zip(*connection.qb_recorded.iterkeys())) origin = [-x for x in shift] info = {'colored': connection.qb_record_colors , 'origin': origin} if cost is not None: info['cost'] = int(cost) if description: info['description'] = ' '.join(description) qb_update_info(fname + '.txt', info) recorded = dict(shift_origin_all(connection.qb_recorded, shift)) AVX.fromsparsedict(recorded, info['colored']).save(fname) return 'Saved buffer to %s.avx' % name
def qbload(connection, name): fname = qb_fname(name) if not fname: return 'Invalid load name. Only alphanumeric characters allowed.' qbclear(connection) settings = qb_get_info(fname + '.txt') if not settings.has_key('origin'): return 'Invalid information for file %s' % name recorded = AVX.fromfile(fname).tosparsedict() connection.qb_recorded = dict(shift_origin_all(recorded, settings['origin'])) return 'Loaded %s.avx to buffer.' % name
def on_block_build_attempt(self, x, y, z): cont = True if self.qb_recording and not self.qb_record_origin: self.qb_record_origin = (x, y, z) self.qb_record_dir = self.get_direction() if self.qb_recording == Q_COPYING: self.send_chat('Now place the opposite corner block!') else: self.send_chat('Now start building!') cont = False elif self.qb_recording == Q_COPYING: blocks = get_blocks(self.protocol.map, self.qb_record_origin, (x,y,z), self.qb_record_colors) blocks = shift_origin_all(blocks, self.qb_record_origin) blocks = rotate_all(blocks, self.qb_record_dir, EAST) self.qb_recorded = dict(blocks) self.qb_recording = Q_STOPPED self.send_chat('Copied area to buffer!') cont = False if self.qb_building: if self.qb_building == Q_BUILD_RECORDED: structure = rotate_all(self.qb_recorded, EAST, self.get_direction()) color = DIRT_COLOR if self.qb_record_colors else self.color else: self.qb_points -= self.qb_info.get('cost', 0) vx = AVX.fromfile(qb_fname(self.qb_info['name'])) structure = vx.tosparsedict() structure = shift_origin_all(structure, self.qb_info['origin']) structure = rotate_all(structure, EAST, self.get_direction()) color = DIRT_COLOR if vx.has_colors else self.color self.protocol.cbc_add(self.quickbuild_generator((x, y, z), structure, color)) self.qb_building = Q_OFF self.qb_info = None self.send_chat('Building structure!') cont = False if self.qb_recording == Q_ORIGINATING: new_origin = (x,y,z) shift = shift_origin(self.qb_record_origin, new_origin) self.qb_recorded = dict(shift_origin_all(self.qb_recorded, shift)) self.qb_record_origin = new_origin self.send_chat('New origin saved!') cont = False if not cont: return False return connection.on_block_build_attempt(self, x, y, z)
def qbload(connection, name): fname = qb_fname(name) if not fname: return 'Invalid load name. Only alphanumeric characters allowed.' qbclear(connection) settings = qb_get_info(fname + '.txt') if not settings.has_key('origin'): return 'Invalid information for file %s' % name recorded = AVX.fromfile(fname).tosparsedict() connection.qb_recorded = dict( shift_origin_all(recorded, settings['origin'])) return 'Loaded %s.avx to buffer.' % name