def statistics(self): statistics = s11n.from_json(self._model.statistics) statistics['race_percents'] = dict( (RACE(int(key)), value) for key, value in statistics['race_percents'].items()) statistics['person_race_percents'] = dict( (RACE(int(key)), value) for key, value in statistics['person_race_percents'].items()) statistics['race_cities'] = dict( (RACE(int(key)), value) for key, value in statistics['race_cities'].items()) statistics['terrain_percents'] = dict( (MAP_STATISTICS(int(key)), value) for key, value in statistics['terrain_percents'].items()) return statistics
def handle(self, *args, **options): LINGUISTICS_FORMATTERS = {key.value: linguistics_logic.ui_format(key.ui_text) for key in linguistics_keys.LEXICON_KEY.records if key.ui_text is not None} with open(game_settings.JS_CONSTNATS_FILE_LOCATION, 'w') as f: f.write(jinja2.render('game/js_constants.js', context={'actor_type': s11n.to_json({a.name: a.value for a in ACTOR_TYPE.records}), 'gender_to_text': s11n.to_json(dict(GENDER.select('value', 'text'))), 'gender_to_str': s11n.to_json(dict(GENDER.select('value', 'name'))), 'person_type_to_text': s11n.to_json(dict(PERSON_TYPE.select('value', 'text'))), 'race_to_text': s11n.to_json(dict(RACE.select('value', 'text'))), 'race_to_str': s11n.to_json(dict(RACE.select('value', 'name'))), 'game_state': s11n.to_json(dict(GAME_STATE.select('name', 'value'))), 'ARTIFACT_TYPE': artifacts_relations.ARTIFACT_TYPE, 'NO_EFFECT': artifacts_relations.ARTIFACT_EFFECT.NO_EFFECT, 'EFFECTS': EFFECTS, 'ARTIFACT_RARITY': artifacts_relations.RARITY, 'CARD_RARITY': cards_relations.RARITY, 'CARDS_EFFECTS': cards_effects.EFFECTS, 'ABILITY_TYPE': ABILITY_TYPE, 'SPRITES': SPRITES, 'CELL_SIZE': map_settings.CELL_SIZE, 'LINGUISTICS_FORMATTERS': LINGUISTICS_FORMATTERS }))
def handle(self, *args, **options): with open(game_settings.JS_CONSTNATS_FILE_LOCATION, 'w') as f: f.write( jinja2.render( 'game/js_constants.js', context={ 'actor_type': s11n.to_json( {a.name: a.value for a in ACTOR_TYPE.records}), 'gender_to_text': s11n.to_json(dict(GENDER.select('value', 'text'))), 'gender_to_str': s11n.to_json(dict(GENDER.select('value', 'name'))), 'person_type_to_text': s11n.to_json(dict(PERSON_TYPE.select('value', 'text'))), 'race_to_text': s11n.to_json(dict(RACE.select('value', 'text'))), 'race_to_str': s11n.to_json(dict(RACE.select('value', 'name'))), 'game_state': s11n.to_json(dict(GAME_STATE.select('name', 'value'))), 'ARTIFACT_TYPE': artifacts_relations.ARTIFACT_TYPE, 'NO_EFFECT': artifacts_relations.ARTIFACT_EFFECT.NO_EFFECT, 'EFFECTS': EFFECTS, 'ARTIFACT_RARITY': artifacts_relations.RARITY, 'CARD_RARITY': cards_relations.RARITY, 'CARDS_EFFECTS': cards_effects.EFFECTS, 'ABILITY_TYPE': ABILITY_TYPE, 'SPRITES': SPRITES, 'CELL_SIZE': map_settings.CELL_SIZE }).encode('utf-8'))
def handle(self, *args, **options): with open(game_settings.JS_CONSTNATS_FILE_LOCATION, 'w') as f: f.write(jinja2.render('game/js_constants.js', context={'actor_type': s11n.to_json({a.name: a.value for a in ACTOR_TYPE.records}), 'gender_to_text': s11n.to_json(dict(GENDER.select('value', 'text'))), 'gender_to_str': s11n.to_json(dict(GENDER.select('value', 'name'))), 'person_type_to_text': s11n.to_json(dict(PERSON_TYPE.select('value', 'text'))), 'race_to_text': s11n.to_json(dict(RACE.select('value', 'text'))), 'race_to_str': s11n.to_json(dict(RACE.select('value', 'name'))), 'game_state': s11n.to_json(dict(GAME_STATE.select('name', 'value'))), 'ARTIFACT_TYPE': artifacts_relations.ARTIFACT_TYPE, 'NO_EFFECT': artifacts_relations.ARTIFACT_EFFECT.NO_EFFECT, 'EFFECTS': EFFECTS, 'ARTIFACT_RARITY': artifacts_relations.RARITY, 'CARD_RARITY': cards_relations.RARITY, 'CARDS_EFFECTS': cards_effects.EFFECTS, 'ABILITY_TYPE': ABILITY_TYPE, 'SPRITES': SPRITES, 'CELL_SIZE': map_settings.CELL_SIZE }).encode('utf-8'))
def __init__(self, data): self._data = data if not self._data: self._data.update( {race.value: 1.0 / len(RACE.records) for race in RACE.records}) self._races = { RACE(int(race_id)): percents for race_id, percents in self._data.iteritems() }
def deserialize(cls, data): obj = cls() obj.person_id = data['person_id'] obj.person_name = data['person_name'] obj.person_race = RACE(data['person_race']) obj.person_type = PERSON_TYPE(data['person_type']) obj.person_gender = GENDER(data['person_gender']) obj.place_id = data['place_id'] if 'old_place_name_forms' in data: obj.old_place_name_forms = utg_words.Word.deserialize(data['old_place_name_forms']) else: obj.old_place_name_forms = names.generator().get_fast_name('название утрачено') return obj
class EditNameForm(forms.Form): race = fields.TypedChoiceField(label=u'раса', choices=RACE.choices(), coerce=RACE.get_from_name) gender = fields.TypedChoiceField(label=u'пол', choices=GENDER.choices(), coerce=GENDER.get_from_name) name = WordField(word_type=utg_relations.WORD_TYPE.NOUN, label=u'имя', skip_markers=(utg_relations.NOUN_FORM.COUNTABLE, ), show_properties=False) def clean(self): cleaned_data = super(EditNameForm, self).clean() name = cleaned_data.get('name') if name is not None: for name_form in cleaned_data['name'].forms: if len(name_form) > models.Hero.MAX_NAME_LENGTH: raise ValidationError( u'Слишком длинное имя, максимальное число символов: %d' % modelsHero.MAX_NAME_LENGTH) if len(name_form) < conf.heroes_settings.NAME_MIN_LENGHT: raise ValidationError( u'Слишком короткое имя, минимальное число символов: %d' % conf.heroes_settings.NAME_MIN_LENGHT) if NAME_REGEX.match(name_form) is None: print name_form raise ValidationError( u'Имя героя может содержать только следующие символы: %s' % conf.heroes_settings.NAME_SYMBOLS_DESCRITION) name.properties = name.properties.clone( cleaned_data['gender'].utg_id) return cleaned_data @classmethod def get_initials(cls, hero): return { 'gender': hero.gender, 'race': hero.race, 'name': hero.utg_name }
def test_get_next_races__demographics_pressure(self): person_1 = self.p1.persons[0] person_2 = self.p2.persons[0] person_2.race = RACE.random(exclude=(person_1.race,)) old_races = races.Races() old_next_races = old_races.get_next_races((person_1, person_2)) self.assertTrue(1 - E < sum(old_next_races.values()) < 1 + E ) person_1.attrs.demographics_pressure = 2 new_next_races = old_races.get_next_races((person_1, person_2)) self.assertTrue(old_next_races[person_1.race] < new_next_races[person_1.race]) self.assertTrue(old_next_races[person_2.race] > new_next_races[person_2.race]) self.assertTrue(1 - E < sum(new_next_races.values()) < 1 + E )
def test_get_next_races__demographics_pressure(self): person_1 = self.p1.persons[0] person_2 = self.p2.persons[0] person_2.race = RACE.random(exclude=(person_1.race, )) old_races = races.Races() old_next_races = old_races.get_next_races((person_1, person_2)) self.assertTrue(1 - E < sum(old_next_races.values()) < 1 + E) person_1.attrs.demographics_pressure = 2 new_next_races = old_races.get_next_races((person_1, person_2)) self.assertTrue( old_next_races[person_1.race] < new_next_races[person_1.race]) self.assertTrue( old_next_races[person_2.race] > new_next_races[person_2.race]) self.assertTrue(1 - E < sum(new_next_races.values()) < 1 + E)
def deserialize(cls, data): return cls(races={ RACE(int(race_id)): percents for race_id, percents in data.items() })
def handle(self, *args, **options): region = options['region'] if not region: region = map_settings.GEN_REGION_OUTPUT % map_info_storage.version output = options['output'] if not output: output = '/tmp/the-tale-map.png' with open(region) as region_file: data = json.loads(region_file.read()) terrain = data['terrain'] buildings = data['buildings'].values() places = data['places'].values() roads = data['roads'].values() width = data['width'] height = data['height'] roads_map = get_roads_map(width, height, roads, {place['id']: place for place in places}) image = PIL.Image.new( 'RGBA', (width * map_settings.CELL_SIZE, height * map_settings.CELL_SIZE)) texture = PIL.Image.open(map_settings.TEXTURE_PATH) for y, row in enumerate(terrain): for x, cell in enumerate(row): terrain_type = TERRAIN(cell) draw_sprite(image, texture, terrain_type.name, x, y) if roads_map[y][x]: draw_sprite(image, texture, terrain_type.name, x, y, base=True) road_sprite = get_road_sprite_info(roads_map, x, y) draw_sprite(image, texture, road_sprite['name'], x, y, rotate=road_sprite['rotate']) for place_info in places: size = place_info['size'] race = RACE(place_info['race']) if size < 3: verbose_size = 'small' elif size < 6: verbose_size = 'medium' elif size < 9: verbose_size = 'large' else: verbose_size = 'capital' sprite_name = ('city_%s_%s' % (race.name.lower(), verbose_size)).upper() draw_sprite(image, texture, sprite_name, place_info['pos']['x'], place_info['pos']['y']) for building_info in buildings: x, y = building_info['pos']['x'], building_info['pos']['y'] draw_sprite(image, texture, TERRAIN(terrain[y][x]).name, x, y, base=True) sprite_name = 'BUILDING_%s' % BUILDING_TYPE( building_info['type']).name draw_sprite(image, texture, sprite_name, x, y) image.crop(OUTPUT_RECTANGLE).resize(REAL_SIZE, PIL.Image.ANTIALIAS).save(output)