mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-08-27 07:52:19 +00:00
save/load custom character files
This commit is contained in:
parent
816d9a225f
commit
9fa3740b47
40
config.cpp
40
config.cpp
@ -3585,6 +3585,33 @@ EX void pick_player_shape() {
|
||||
dialog::display();
|
||||
}
|
||||
|
||||
EX void save_customchar(charstyle& cs, const string& fname) {
|
||||
FILE *f = fopen(fname.c_str(), "wt");
|
||||
if(!f) throw hstream_exception();
|
||||
fprintf(f, "%x\n", VERNUM_HEX);
|
||||
fprintf(f, "%d %d\n%08x %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
||||
cs.charid, cs.lefthanded,
|
||||
cs.skincolor, cs.haircolor, cs.dresscolor, cs.swordcolor, cs.dresscolor2, cs.uicolor, cs.eyecolor, cs.bowcolor, cs.bowcolor2);
|
||||
fprintf(f, "HyperRogue " VER " custom character file\n");
|
||||
fprintf(f, "Colors are: skin, hair, dress, sword, dress2, ui, eye, bow, bow2\n");
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
EX void load_customchar(charstyle& cs, const string& fname) {
|
||||
FILE *f = fopen(fname.c_str(), "rt");
|
||||
if(!f) throw hstream_exception();
|
||||
int vernum;
|
||||
fscanf(f, "%x", &vernum);
|
||||
int lh;
|
||||
fscanf(f, "%d %d\n%08x %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
||||
&cs.charid, &lh,
|
||||
&cs.skincolor, &cs.haircolor, &cs.dresscolor, &cs.swordcolor, &cs.dresscolor2, &cs.uicolor, &cs.eyecolor, &cs.bowcolor, &cs.bowcolor2);
|
||||
cs.lefthanded = lh;
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
EX string charfile = "custom.hch";
|
||||
|
||||
EX void showCustomizeChar() {
|
||||
|
||||
cc_footphase += hypot(mousex - lmousex, mousey - lmousey);
|
||||
@ -3619,9 +3646,19 @@ EX void showCustomizeChar() {
|
||||
|
||||
if(numplayers() > 1) dialog::addSelItem(XLAT("player"), its(multi::cpid+1), 'a');
|
||||
|
||||
dialog::addBoolItem(XLAT("left-handed"), cs.lefthanded, 'l');
|
||||
dialog::addBoolItem_action(XLAT("left-handed"), cs.lefthanded, 'l');
|
||||
|
||||
dialog::addBreak(50);
|
||||
dialog::addItem("save", 'S');
|
||||
dialog::add_action([&cs] {
|
||||
dialog::openFileDialog(charfile, XLAT("character file to save:"), ".hch",
|
||||
[&cs] { try { save_customchar(cs, charfile); return true; } catch(hstream_exception&) { addMessage("Failed to save!"); return false; } });
|
||||
});
|
||||
dialog::addItem("load", 'L');
|
||||
dialog::add_action([&cs] {
|
||||
dialog::openFileDialog(charfile, XLAT("character file to load:"), ".hch",
|
||||
[&cs] { try { load_customchar(cs, charfile); return true; } catch(hstream_exception&) { addMessage("Failed to load!"); return false; } });
|
||||
});
|
||||
dialog::addBack();
|
||||
dialog::display();
|
||||
|
||||
@ -3653,7 +3690,6 @@ EX void showCustomizeChar() {
|
||||
else if(uni == 'f') switchcolor(cs.dresscolor2, dresscolors2);
|
||||
else if(uni == 'u') switchcolor(cs.uicolor, eyecolors);
|
||||
else if(uni == 'e') switchcolor(cs.eyecolor, eyecolors);
|
||||
else if(uni == 'l') cs.lefthanded = !cs.lefthanded;
|
||||
else if(uni == 'b') switchcolor(cs.bowcolor, swordcolors);
|
||||
else if(uni == 'c') switchcolor(cs.bowcolor2, eyecolors);
|
||||
else if(doexiton(sym, uni)) popScreen();
|
||||
|
Loading…
x
Reference in New Issue
Block a user