t.design = design
cmd_THING_HAT_DESIGN.argtypes = 'int:pos string'
+def cmd_THING_DESIGN(game, design, pw, connection_id):
+ player = game.get_player(connection_id)
+ if not player:
+ raise GameError('need to be logged in for this')
+ if not player.carrying:
+ raise GameError('need to carry a thing to re-draw it')
+ if not game.can_do_thing_with_pw(player.carrying, pw):
+ raise GameError('wrong password for thing')
+ if not hasattr(player.carrying, 'design'):
+ raise GameError('carried thing not designable')
+ size = player.carrying.design_size
+ if len(design) != size.y * size.x:
+ raise GameError('design for carried thing of wrong length')
+ player.carrying.design = design
+ game.changed = True
+ game.record_change(player.carrying.position, 'other')
+cmd_THING_DESIGN.argtypes = 'string string'
+
+def cmd_GOD_THING_DESIGN(game, thing_id, design):
+ t = game.get_thing(thing_id)
+ if not t:
+ raise GameError('thing of ID %s not found' % thing_id)
+ if not hasattr(t, 'design'):
+ raise GameError('thing of ID %s not designable' % thing_id)
+ if len(design) != t.design_size.y * t.design_size.x:
+ raise GameError('design for thing of ID %s of wrong length' % thing_id)
+ t.design = design
+cmd_GOD_THING_DESIGN.argtypes = 'int:pos string'
+
+# TODO: refactor similar god and player commands
+
def cmd_THING_DOOR_KEY(game, key_id, door_id):
key = game.get_thing(key_id)
if not key:
quote(t.thing_char)), c_id)
if hasattr(t, 'installable') and not t.portable:
self.io.send('THING_INSTALLED %s' % (t.id_), c_id)
- if hasattr(t, 'design'):
+ if t.type_ == 'Hat':
self.io.send('THING_HAT %s %s' % (t.id_,
quote(t.design)), c_id)
+ elif hasattr(t, 'design'):
+ self.io.send('THING_DESIGN %s %s %s'
+ % (t.id_, t.design_size, quote(t.design)),
+ c_id)
for t in [t for t in player.seen_things if t.carrying]:
# send this last so all carryable things are already created
self.io.send('THING_CARRYING %s %s' % (t.id_, t.carrying.id_),
elif t.type_ == 'Hat':
write(f, 'THING_HAT_DESIGN %s %s' % (t.id_,
quote(t.design)))
+ elif hasattr(t, 'design'):
+ write(f, 'GOD_THING_DESIGN %s %s' % (t.id_, quote(t.design)))
elif t.type_ == 'MusicPlayer':
write(f, 'THING_MUSICPLAYER_SETTINGS %s %s %s %s' %
(t.id_, int(t.playing), t.playlist_index, int(t.repeat)))
+class Thing_SignSpawner(ThingSpawner):
+ child_type = 'Sign'
+
+
+
+class Thing_Sign(ThingInstallable):
+ symbol_hint = '?'
+ design_size = YX(16, 36)
+
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self.design = 'x' * self.design_size.y * self.design_size.x
+
+
+
class Thing_DoorSpawner(ThingSpawner):
child_type = 'Door'
design = ' +--+ ' + ' | | ' + '======'
spinnable = True
cookable = True
+ design_size = YX(3, 6)
def spin(self):
new_design = ''
<button id="switch_to_password"></button>
<button id="switch_to_enter_face"></button>
<button id="switch_to_enter_hat"></button>
+ <button id="switch_to_enter_design"></button>
</td>
</tr>
<tr>
<li><input id="key_switch_to_drop_thing" type="text" value="u" />
<li><input id="key_switch_to_enter_face" type="text" value="f" />
<li><input id="key_switch_to_enter_hat" type="text" value="H" />
+<li><input id="key_switch_to_enter_design" type="text" value="D" />
<li><input id="key_switch_to_take_thing" type="text" value="z" />
<li><input id="key_switch_to_chat" type="text" value="t" />
<li><input id="key_switch_to_play" type="text" value="p" />
},
'enter_face': {
'short': 'edit face',
- 'intro': '@ enter face line (enter nothing to abort):',
+ 'intro': '@ enter face line:',
'long': 'Draw your face as ASCII art. The string you enter must be 18 characters long, and will be divided on display into 3 lines of 6 characters each, from top to bottom. Eat cookies to extend the ASCII characters available for drawing.'
},
+ 'enter_design': {
+ 'short': 'edit design',
+ 'intro': '@ enter design:',
+ 'long': 'Enter design for carried thing as ASCII art.'
+ },
'enter_hat': {
'short': 'edit hat',
- 'intro': '@ enter hat line (enter nothing to abort):',
- 'long': 'Draw your hat as ASCII art. The string you enter must be 18 characters long, and will be divided on display into 3 lines of 6 characters each, from top to bottom..'
+ 'intro': '@ enter hat line:',
+ 'long': 'Draw your hat as ASCII art. The string you enter must be 18 characters long, and will be divided on display into 3 lines of 6 characters each, from top to bottom. Eat cookies to extend the ASCII characters available for drawing.'
},
'write': {
'short': 'edit tile',
} else if (tokens[0] === 'THING_HAT') {
let t = game.get_thing_temp(tokens[1]);
t.hat = tokens[2];
+ } else if (tokens[0] === 'THING_DESIGN') {
+ let t = game.get_thing_temp(tokens[1]);
+ t.design = [parser.parse_yx(tokens[2]), tokens[3]];
} else if (tokens[0] === 'THING_CHAR') {
let t = game.get_thing_temp(tokens[1]);
t.thing_char = tokens[2];
mode_drop_thing: new Mode('drop_thing', true),
mode_enter_face: new Mode('enter_face', true),
mode_enter_hat: new Mode('enter_hat', true),
+ mode_enter_design: new Mode('enter_design', true),
mode_admin_enter: new Mode('admin_enter', true),
mode_admin: new Mode('admin'),
mode_control_pw_pw: new Mode('control_pw_pw', true),
this.mode_control_tile_draw.available_modes = ["admin_enter"]
this.mode_control_tile_draw.available_actions = ["toggle_tile_draw"];
this.mode_edit.available_modes = ["write", "annotate", "portal", "name_thing",
- "password", "chat", "study", "play",
- "admin_enter", "enter_face", "enter_hat"]
+ "enter_design", "password", "chat", "study",
+ "play", "admin_enter", "enter_face",
+ "enter_hat"]
this.mode_edit.available_actions = ["move", "flatten", "install",
"toggle_map_mode"]
this.inputEl = document.getElementById("input");
return fail('not carrying anything droppable');
} else if (mode_name == 'enter_hat' && !game.player.hat) {
return fail('not wearing hat to edit', 'edit');
+ } else if (mode_name == 'enter_design' && (!game.player.carrying
+ || !game.player.carrying.design)) {
+ return fail('not carrying designable to edit', 'edit');
}
if (mode_name == 'admin_enter' && this.is_admin) {
mode_name = 'admin';
directed_moves['DOWNRIGHT'] = [1, 0];
}
}
- console.log(directed_moves);
let select_range = {};
for (const direction in directed_moves) {
const move = directed_moves[direction];
} else if (this.mode.name == 'enter_hat') {
this.inputEl.value = game.player.hat.slice(start, end);
}
+ } else if (this.mode.name == 'enter_design') {
+ const width = game.player.carrying.design[0][1];
+ const start = this.ascii_draw_stage * width;
+ const end = (this.ascii_draw_stage + 1) * width;
+ this.inputEl.value = game.player.carrying.design[1].slice(start, end);
}
},
recalc_input_lines: function() {
this.inputEl.value = "";
this.switch_mode('play');
},
- enter_ascii_art: function(command) {
- if (this.inputEl.value.length > 6) {
- this.log_msg('? wrong input length, must be max 6; try again');
+ enter_ascii_art: function(command, height, width, with_pw=false) {
+ if (this.inputEl.value.length > width) {
+ this.log_msg('? wrong input length, must be max ' + width + '; try again');
return;
- } else if (this.inputEl.value.length < 6) {
- while (this.inputEl.value.length < 6) {
+ } else if (this.inputEl.value.length < width) {
+ while (this.inputEl.value.length < width) {
this.inputEl.value += ' ';
}
}
this.log_msg(' ' + this.inputEl.value);
this.full_ascii_draw += this.inputEl.value;
this.ascii_draw_stage += 1;
- if (this.ascii_draw_stage < 3) {
+ if (this.ascii_draw_stage < height) {
this.restore_input_values();
} else {
- server.send([command, this.full_ascii_draw]);
+ if (with_pw) {
+ server.send([command, this.full_ascii_draw, this.password]);
+ } else {
+ server.send([command, this.full_ascii_draw]);
+ }
this.full_ascii_draw = '';
this.ascii_draw_stage = 0;
this.inputEl.value = '';
info_to_cache += t.face.slice(6, 12) + '\n';
info_to_cache += t.face.slice(12, 18) + '\n';
}
+ if (t.design) {
+ const line_length = t.design[0][1];
+ if (t.type_ == 'Sign') {
+ info_to_cache += '-'.repeat(line_length + 4) + '\n';
+ }
+ const regexp = RegExp('.{1,' + line_length + '}', 'g');
+ const lines = t.design[1].match(regexp);
+ console.log(lines);
+ for (const line of lines) {
+ info_to_cache += '| ' + line + ' |\n';
+ }
+ if (t.type_ == 'Sign') {
+ info_to_cache += '-'.repeat(line_length + 4) + '\n';
+ }
+ }
}
}
let terrain_char = game.map[position_i]
server.send(['LOGIN', tui.inputEl.value]);
tui.inputEl.value = "";
} else if (tui.mode.name == 'enter_face' && event.key == 'Enter') {
- tui.enter_ascii_art('PLAYER_FACE');
+ tui.enter_ascii_art('PLAYER_FACE', 3, 6);
} else if (tui.mode.name == 'enter_hat' && event.key == 'Enter') {
- tui.enter_ascii_art('PLAYER_HAT');
+ tui.enter_ascii_art('PLAYER_HAT', 3, 6);
+ } else if (tui.mode.name == 'enter_design' && event.key == 'Enter') {
+ tui.enter_ascii_art('THING_DESIGN',
+ game.player.carrying.design[0][0],
+ game.player.carrying.design[0][1], true);
} else if (tui.mode.name == 'command_thing' && event.key == 'Enter') {
server.send(['TASK:COMMAND', tui.inputEl.value]);
tui.inputEl.value = "";
cmd_GOD_PLAYERS_HAT_CHARS, cmd_PLAYER_HAT,
cmd_TERRAIN_TAG, cmd_THING_DOOR_KEY,
cmd_THING_CRATE_ITEM, cmd_MAP_CONTROL_PRESETS,
- cmd_THING_SPAWNPOINT_CREATED)
+ cmd_THING_SPAWNPOINT_CREATED, cmd_GOD_THING_DESIGN,
+ cmd_THING_DESIGN)
from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE, Task_PICK_UP,
Task_DROP, Task_FLATTEN_SURROUNDINGS, Task_DOOR,
Task_INTOXICATE, Task_COMMAND, Task_INSTALL,
Thing_Cookie, Thing_CookieSpawner, Thing_Psychedelic,
Thing_PsychedelicSpawner, Thing_DoorKey,
Thing_Crate, Thing_CrateSpawner, Thing_Stimulant,
- Thing_StimulantSpawner)
+ Thing_StimulantSpawner, Thing_Sign,
+ Thing_SignSpawner)
from plomrogue.config import config
game = Game(config['savefile'])
game.register_command(cmd_THING_HAT_DESIGN)
game.register_command(cmd_THING_DOOR_KEY)
game.register_command(cmd_THING_CRATE_ITEM)
+game.register_command(cmd_THING_DESIGN)
+game.register_command(cmd_GOD_THING_DESIGN)
game.register_command(cmd_MAP_CONTROL_PRESETS)
game.register_command(cmd_THING_SPAWNPOINT_CREATED)
game.register_task(Task_WAIT)
game.register_thing_type(Thing_CrateSpawner)
game.register_thing_type(Thing_Stimulant)
game.register_thing_type(Thing_StimulantSpawner)
+game.register_thing_type(Thing_Sign)
+game.register_thing_type(Thing_SignSpawner)
game.read_savefile()
game.io.start_loop()
for port in config['servers']:
},
'enter_face': {
'short': 'edit face',
- 'intro': '@ enter face line (enter nothing to abort):',
+ 'intro': '@ enter face line:',
'long': 'Draw your face as ASCII art. The string you enter must be 18 characters long, and will be divided on display into 3 lines of 6 characters each, from top to bottom..'
},
+ 'enter_design': {
+ 'short': 'edit design',
+ 'intro': '@ enter design:',
+ 'long': 'Enter design for carried thing as ASCII art.'
+ },
'enter_hat': {
'short': 'edit hat',
- 'intro': '@ enter hat line (enter nothing to abort):',
- 'long': 'Draw your face as ASCII art. The string you enter must be 18 characters long, and will be divided on display into 3 lines of 6 characters each, from top to bottom. Eat cookies to extend the ASCII characters available for drawing.'
+ 'intro': '@ enter hat line:',
+ 'long': 'Draw your hat as ASCII art. The string you enter must be 18 characters long, and will be divided on display into 3 lines of 6 characters each, from top to bottom. Eat cookies to extend the ASCII characters available for drawing.'
},
'write': {
'short': 'edit tile',
t.hat = hat
cmd_THING_HAT.argtypes = 'int:pos string'
+def cmd_THING_DESIGN(game, thing_id, size, design):
+ t = game.get_thing_temp(thing_id)
+ t.design = [size, design]
+cmd_THING_DESIGN.argtypes = 'int:pos yx_tuple string'
+
def cmd_THING_CHAR(game, thing_id, c):
t = game.get_thing_temp(thing_id)
t.thing_char = c
self.register_command(cmd_THING_CHAR)
self.register_command(cmd_THING_FACE)
self.register_command(cmd_THING_HAT)
+ self.register_command(cmd_THING_DESIGN)
self.register_command(cmd_THING_CARRYING)
self.register_command(cmd_THING_INSTALLED)
self.register_command(cmd_TERRAIN)
mode_drop_thing = Mode('drop_thing', has_input_prompt=True)
mode_enter_face = Mode('enter_face', has_input_prompt=True)
mode_enter_hat = Mode('enter_hat', has_input_prompt=True)
+ mode_enter_design = Mode('enter_design', has_input_prompt=True)
is_admin = False
tile_draw = False
"toggle_tile_draw"]
self.mode_edit.available_modes = ["write", "annotate", "portal",
"name_thing", "enter_face", "enter_hat",
- "password",
+ "enter_design", "password",
"chat", "study", "play", "admin_enter"]
self.mode_edit.available_actions = ["move", "flatten", "install",
"toggle_map_mode"]
'flatten': 'F',
'switch_to_enter_face': 'f',
'switch_to_enter_hat': 'H',
+ 'switch_to_enter_design': 'D',
'switch_to_take_thing': 'z',
'switch_to_drop_thing': 'u',
'teleport': 'p',
self.input_ = self.game.player.face[start:end]
elif self.mode.name == 'enter_hat':
self.input_ = self.game.player.hat[start:end]
+ elif self.mode.name == 'enter_design':
+ width = self.game.player.carrying.design[0].x
+ start = self.ascii_draw_stage * width
+ end = (self.ascii_draw_stage + 1) * width
+ self.input_ = self.game.player.carrying.design[1][start:end]
def send_tile_control_command(self):
self.send('SET_TILE_CONTROL %s %s' %
return fail('not carrying anything droppable')
if mode_name == 'enter_hat' and not hasattr(self.game.player, 'hat'):
return fail('not wearing hat to edit', 'edit')
+ if mode_name == 'enter_design' and\
+ (not self.game.player.carrying or
+ not hasattr(self.game.player.carrying, 'design')):
+ return fail('not carrying designable to edit', 'edit')
if mode_name == 'admin_enter' and self.is_admin:
mode_name = 'admin'
self.mode = getattr(self, 'mode_' + mode_name)
info_to_cache += t.face[0:6] + '\n'
info_to_cache += t.face[6:12] + '\n'
info_to_cache += t.face[12:18] + '\n'
+ if hasattr(t, 'design'):
+ import textwrap
+ line_length = t.design[0].x
+ wrapper = textwrap.TextWrapper(drop_whitespace=False,
+ width=line_length)
+ lines = wrapper.wrap(t.design[1])
+ if t.type_ == 'Sign':
+ info_to_cache += '-' * (line_length + 4) + '\n'
+ for line in lines:
+ info_to_cache += '| %s |\n' % line
+ if t.type_ == 'Sign':
+ info_to_cache += '-' * (line_length + 4) + '\n'
terrain_char = self.game.map_content[pos_i]
terrain_desc = '?'
if terrain_char in self.game.terrains:
self.input_ = ''
self.switch_mode('play')
- def enter_ascii_art(command):
- if len(self.input_) > 6:
- self.log_msg('? wrong input length, must be max 6; try again')
+ def enter_ascii_art(command, height, width, with_pw=False):
+ if len(self.input_) > width:
+ self.log_msg('? wrong input length, '
+ 'must be max %s; try again' % width)
return
- if len(self.input_) < 6:
- self.input_ += ' ' * (6 - len(self.input_))
+ if len(self.input_) < width:
+ self.input_ += ' ' * (width - len(self.input_))
self.log_msg(' ' + self.input_)
self.full_ascii_draw += self.input_
self.ascii_draw_stage += 1
- if self.ascii_draw_stage < 3:
+ if self.ascii_draw_stage < height:
self.restore_input_values()
else:
- self.send('%s %s' % (command, quote(self.full_ascii_draw)))
+ if with_pw:
+ self.send('%s %s %s' % (command, quote(self.full_ascii_draw),
+ quote(self.password)))
+ else:
+ self.send('%s %s' % (command, quote(self.full_ascii_draw)))
self.full_ascii_draw = ""
self.ascii_draw_stage = 0
self.input_ = ""
self.send('LOGIN ' + quote(self.input_))
self.input_ = ""
elif self.mode.name == 'enter_face' and key == '\n':
- enter_ascii_art('PLAYER_FACE')
+ enter_ascii_art('PLAYER_FACE', 3, 6)
elif self.mode.name == 'enter_hat' and key == '\n':
- enter_ascii_art('PLAYER_HAT')
+ enter_ascii_art('PLAYER_HAT', 3, 6)
+ elif self.mode.name == 'enter_design' and key == '\n':
+ enter_ascii_art('THING_DESIGN',
+ self.game.player.carrying.design[0].y,
+ self.game.player.carrying.design[0].x, True)
elif self.mode.name == 'take_thing' and key == '\n':
pick_selectable('PICK_UP')
elif self.mode.name == 'drop_thing' and key == '\n':