Free Hero Mesh

Check-in [9769459c6a]
Login
This is a mirror of the main repository for Free Hero Mesh. New tickets and changes will not be accepted at this mirror.
Overview
Comment:Implement load/import/export move lists.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 9769459c6a64949dfe1f221ebc80c42e89f1306f
User & Date: user on 2021-02-07 00:16:39
Other Links: manifest | tags
Context
2021-02-07
04:39
Implement rewrite_class_def (untested so far) check-in: 9f93963467 user: user tags: trunk
00:16
Implement load/import/export move lists. check-in: 9769459c6a user: user tags: trunk
2021-02-06
02:30
Implement MRU selection bindings in editor check-in: ec992367da user: user tags: trunk
Changes

Modified bindings.doc from [0668d41b57] to [852bf6010f].

79
80
81
82
83
84
85












86
87
88
89
90
91
92

'^o' <location>
  List objects at the specified coordinates, to examine their values.

'^s'
  Toggle solution replay.














=== Editor commands ===

'^c'
  Display the class selection menu.

'mR' <number>







>
>
>
>
>
>
>
>
>
>
>
>







79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

'^o' <location>
  List objects at the specified coordinates, to examine their values.

'^s'
  Toggle solution replay.

'mi' <command>
  Import a move list. The argument is a operating system command, that
  when executed will write the move list to stdout, with one byte per
  move (the Hero Mesh key codes).

'ml' <blob>
  Load a move list from a SQL blob.

'mx' <command>
  Export a move list. The argument is a operating system command that
  will receive the move list (in the same format as above) on stdin.


=== Editor commands ===

'^c'
  Display the class selection menu.

'mR' <number>

Modified game.c from [bcb10cb33f] to [627e7b922e].

509
510
511
512
513
514
515









































516
517
518
519
520
521
522
  while(n!=VOIDLINK && objects[n]->up!=VOIDLINK) n=objects[n]->up;
  if(!classes[objects[n]->class]->gamehelp) return;
  s=sqlite3_mprintf("\x0C\x0E%s:%d\\ %s\x0B\x0F%s",classes[objects[n]->class]->name,objects[n]->image,classes[objects[n]->class]->name,classes[objects[n]->class]->gamehelp);
  if(!s) fatal("Allocation failed\n");
  modal_draw_popup(s);
  sqlite3_free(s);
}










































static int game_command(int prev,int cmd,int number,int argc,sqlite3_stmt*args,void*aux) {
  switch(cmd) {
    case '\' ': // Play a move
      if(solution_replay) {
        screen_message("You cannot play your own moves during the solution replay");
        return -3;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
  while(n!=VOIDLINK && objects[n]->up!=VOIDLINK) n=objects[n]->up;
  if(!classes[objects[n]->class]->gamehelp) return;
  s=sqlite3_mprintf("\x0C\x0E%s:%d\\ %s\x0B\x0F%s",classes[objects[n]->class]->name,objects[n]->image,classes[objects[n]->class]->name,classes[objects[n]->class]->gamehelp);
  if(!s) fatal("Allocation failed\n");
  modal_draw_popup(s);
  sqlite3_free(s);
}

static void do_import_moves(const char*arg) {
  FILE*fp;
  int i;
  if(!arg || !arg[strspn(arg," \t")]) return;
  fp=popen(arg,"r");
  if(!fp) {
    screen_message("Unable to open pipe for reading");
    return;
  }
  replay_list=realloc(replay_list,0x10000);
  if(!replay_list) fatal("Allocation failed");
  replay_mark=0;
  replay_size=0xFFFF;
  i=fread(replay_list,1,0xFFFD,fp);
  if(i&~0xFFFF) i=0;
  replay_count=i;
  pclose(fp);
}

static void do_export_moves(const char*arg) {
  FILE*fp;
  int i;
  if(!arg || !arg[strspn(arg," \t")]) return;
  fp=popen(arg,"w");
  if(!fp) {
    screen_message("Unable to open pipe for writing");
    return;
  }
  if(replay_count) fwrite(replay_list,1,replay_count,fp);
  pclose(fp);
}

static void do_load_moves(sqlite3_stmt*st) {
  int i=sqlite3_column_bytes(st,1);
  if(i&~0xFFFF) return;
  if(replay_size<i) replay_list=realloc(replay_list,replay_size=i);
  if(!replay_list) fatal("Allocation failed");
  replay_count=i;
  if(i) memcpy(replay_list,sqlite3_column_blob(st,1),i);
}

static int game_command(int prev,int cmd,int number,int argc,sqlite3_stmt*args,void*aux) {
  switch(cmd) {
    case '\' ': // Play a move
      if(solution_replay) {
        screen_message("You cannot play your own moves during the solution replay");
        return -3;
580
581
582
583
584
585
586














587
588
589
590
591
592
593
    case '^s': // Toggle solution replay
      solution_replay^=1;
      if(replay_count) replay_count=0,begin_level(level_id); else load_replay();
      return 1;
    case 'go': // Select level
      begin_level(number);
      return 1;














    default:
      return prev;
  }
}

static void set_caption(void) {
  const char*r;







>
>
>
>
>
>
>
>
>
>
>
>
>
>







621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
    case '^s': // Toggle solution replay
      solution_replay^=1;
      if(replay_count) replay_count=0,begin_level(level_id); else load_replay();
      return 1;
    case 'go': // Select level
      begin_level(number);
      return 1;
    case 'mi': // Move list import
      if(argc<2 || solution_replay) break;
      if(replay_pos) begin_level(level_id);
      do_import_moves(sqlite3_column_text(args,1));
      return 1;
    case 'ml': // Move list load
      if(argc<2 || solution_replay) break;
      if(replay_pos) begin_level(level_id);
      do_load_moves(args);
      return 1;
    case 'mx': // Move list export
      if(argc<2) break;
      do_export_moves(sqlite3_column_text(args,1));
      return 0;
    default:
      return prev;
  }
}

static void set_caption(void) {
  const char*r;