- def write(f, msg):
- f.write(msg + '\n')
-
- with open(self.io.save_file, 'w') as f:
- # TODO: save tasks
- write(f, 'TURN %s' % self.turn)
- map_geometry_shape = self.get_map_geometry_shape()
- write(f, 'MAP %s %s' % (map_geometry_shape, self.map_geometry.size,))
- for y, line in self.map.lines():
- write(f, 'MAP_LINE %5s %s' % (y, quote(line)))
- for yx in self.annotations:
- write(f, 'ANNOTATE %s %s' % (yx, quote(self.annotations[yx])))
- for yx in self.portals:
- write(f, 'PORTAL %s %s' % (yx, quote(self.portals[yx])))
- for y, line in self.map_control.lines():
- write(f, 'MAP_CONTROL_LINE %5s %s' % (y, quote(line)))
- for tile_class in self.map_control_passwords:
- write(f, 'MAP_CONTROL_PW %s %s' % (tile_class,
- self.map_control_passwords[tile_class]))
+ def write(f, msg):
+ f.write(msg + '\n')
+
+ with open(self.io.save_file, 'w') as f:
+ write(f, 'TURN %s' % self.turn)
+ map_geometry_shape = self.get_map_geometry_shape()
+ # must come before MAP, otherwise first get_map uses the default
+ # TODO: refactor into MAP
+ write(f, 'MAP_CONTROL_PRESETS %s' % int(self.draw_control_presets))
+ write(f, 'MAP %s %s' % (map_geometry_shape, self.map_geometry.size,))
+ for terrain in self.terrains.values():
+ write(f, 'TERRAIN %s %s %s %s %s' % (quote(terrain.character),
+ quote(terrain.description),
+ int(terrain.blocks_light),
+ int(terrain.blocks_sound),
+ int(terrain.blocks_movement)))
+ if len(terrain.tags) > 0:
+ for tag in terrain.tags:
+ write(f, 'TERRAIN_TAG %s %s' % (quote(terrain.character),
+ quote(tag)))
+ for big_yx in [yx for yx in self.maps if self.maps[yx].modified]:
+ for y, line in self.maps[big_yx].lines():
+ write(f, 'MAP_LINE %s %5s %s' % (big_yx, y, quote(line)))
+ for big_yx in self.annotations:
+ for little_yx in self.annotations[big_yx]:
+ write(f, 'GOD_ANNOTATE %s %s %s' %
+ (big_yx, little_yx, quote(self.annotations[big_yx][little_yx])))
+ for big_yx in self.portals:
+ for little_yx in self.portals[big_yx]:
+ write(f, 'GOD_PORTAL %s %s %s' % (big_yx, little_yx,
+ quote(self.portals[big_yx][little_yx])))
+ for big_yx in [yx for yx in self.map_controls
+ if self.map_controls[yx].modified]:
+ for y, line in self.map_controls[big_yx].lines():
+ write(f, 'MAP_CONTROL_LINE %s %5s %s' % (big_yx, y, quote(line)))
+ for tile_class in self.map_control_passwords:
+ write(f, 'MAP_CONTROL_PW %s %s' % (tile_class,
+ self.map_control_passwords[tile_class]))
+ for pw in self.admin_passwords:
+ write(f, 'ADMIN_PASSWORD %s' % pw)
+ for name in self.faces:
+ write(f, 'GOD_PLAYER_FACE %s %s' % (quote(name),
+ quote(self.faces[name])))
+ for name in self.hats:
+ write(f, 'GOD_PLAYER_HAT %s %s' % (quote(name),
+ quote(self.hats[name])))
+ for name in self.players_hat_chars:
+ write(f, 'GOD_PLAYERS_HAT_CHARS %s %s' %
+ (quote(name), quote(self.players_hat_chars[name])))
+ for t in [t for t in self.things if not t.type_ == 'Player']:
+ write(f, 'THING %s %s %s %s' % (t.position[0],
+ t.position[1], t.type_, t.id_))
+ write(f, 'GOD_THING_PROTECTION %s %s' % (t.id_, quote(t.protection)))
+ if hasattr(t, 'name'):
+ write(f, 'GOD_THING_NAME %s %s' % (t.id_, quote(t.name)))
+ if hasattr(t, 'installable') and (not t.portable):
+ write(f, 'THING_INSTALLED %s' % t.id_)
+ if hasattr(t, 'design'):
+ if t.type_ != 'Hat':
+ write(f, 'GOD_THING_DESIGN_SIZE %s %s' % (t.id_,
+ t.design_size))
+ write(f, 'GOD_THING_DESIGN %s %s' % (t.id_, quote(t.design)))
+ if t.type_ == 'Door' and t.blocks_movement:
+ write(f, 'THING_DOOR_CLOSED %s %s' % (t.id_, int(t.locked)))
+ elif t.type_ == 'MusicPlayer':
+ write(f, 'THING_MUSICPLAYER_SETTINGS %s %s %s %s' %
+ (t.id_, int(t.playing), t.playlist_index, int(t.repeat)))
+ for item in t.playlist:
+ write(f, 'THING_MUSICPLAYER_PLAYLIST_ITEM %s %s %s' %
+ (t.id_, quote(item[0]), item[1]))
+ elif t.type_ == 'Bottle' and not t.full:
+ write(f, 'THING_BOTTLE_EMPTY %s' % t.id_)
+ elif t.type_ == 'DoorKey':
+ write(f, 'THING_DOOR_KEY %s %s' % (t.id_, t.door.id_))
+ elif t.type_ == 'Crate':
+ for item in t.content:
+ write(f, 'THING_CRATE_ITEM %s %s' % (t.id_, item.id_))
+ elif t.type_ == 'SpawnPoint':
+ timestamp = 0
+ if t.temporary:
+ timestamp = int(t.created_at.timestamp())
+ write(f, 'THING_SPAWNPOINT_CREATED %s %s' % (t.id_,
+ timestamp))
+ next_thing_id = self.new_thing_id()
+ for t in [t for t in self.things if t.type_ == 'Player']:
+ write(f, 'THING %s %s SpawnPoint %s'
+ % (t.position[0], t.position[1], next_thing_id))
+ write(f, 'GOD_THING_NAME %s %s' % (next_thing_id, t.name))
+ write(f, 'THING_SPAWNPOINT_CREATED %s %s'
+ % (next_thing_id, int(datetime.datetime.now().timestamp())))
+ next_thing_id += 1
+ write(f, 'SPAWN_POINT %s %s' % (self.spawn_point[0],
+ self.spawn_point[1]))
+
+
+
+ def get_map(self, big_yx, type_='normal'):
+ if type_ == 'normal':
+ maps = self.maps
+ elif type_ == 'control':
+ maps = self.map_controls
+ if big_yx not in maps:
+ maps[big_yx] = SaveableMap(self.map_geometry)
+ if self.draw_control_presets and type_ == 'control':
+ maps[big_yx].draw_presets(big_yx.y % 2)
+ return maps[big_yx]