1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-06-22 16:24:07 +00:00

rogueviz::fifteen:: used rv_hook and new map loading

This commit is contained in:
Zeno Rogue 2021-03-31 11:42:45 +02:00
parent 0af2877cc1
commit 7c8c4f3d04

View File

@ -5,7 +5,7 @@
* \brief fifteen+4 puzzle
*/
#include "../hyper.h"
#include "rogueviz.h"
namespace hr {
@ -24,8 +24,6 @@ map<cell*, celldata> fif;
eWall empty = waChasm;
bool in = false;
enum ePenMove { pmJump, pmRotate, pmAdd, pmMirrorFlip };
ePenMove pen;
@ -87,7 +85,6 @@ void scramble() {
}
bool draw_fifteen(cell *c, const shiftmatrix& V) {
if(!in) return false;
if(!fif.count(c)) { c->land = laNone; c->wall = waChasm; return false; }
check_move();
@ -258,59 +255,14 @@ void launch() {
start_game();
init_fifteen();
in = true;
showstartmenu = false;
mapeditor::drawplayer = false;
}
#if CAP_COMMANDLINE
int rugArgs() {
using namespace arg;
void enable();
if(0) ;
else if(argis("-fifteen")) {
PHASEFROM(3);
launch();
#if ISWEB
mapstream::loadMap("1");
#endif
}
else return 1;
return 0;
}
void o_key(o_funcs& v) {
if(in) v.push_back(named_dialog("edit the Fifteen puzzle", edit_fifteen));
}
auto fifteen_hook =
addHook(hooks_args, 100, rugArgs) +
addHook(hooks_o_key, 80, o_key) +
addHook(hooks_drawcell, 100, draw_fifteen) +
addHook(mapstream::hooks_savemap, 100, [] (fhstream& f) {
if(!in) return;
f.write<int>(isize(fif));
for(auto cd: fif) {
f.write(mapstream::cellids[cd.first]);
println(hlog, cd.first, " has id ", mapstream::cellids[cd.first]);
f.write(cd.second.target);
f.write(cd.second.targetdir);
if(nonorientable)
f.write(cd.second.targetmirror);
f.write(cd.second.current);
f.write(cd.second.currentdir);
if(nonorientable)
f.write(cd.second.currentmirror);
}
}) +
addHook(hooks_clearmemory, 40, [] () {
fif.clear();
}) +
addHook(mapstream::hooks_loadmap, 100, [] (fhstream& f) {
void load_fifteen(fhstream& f) {
int num;
if(!in) return;
f.read(num);
fif.clear();
println(hlog, "read num = ", num);
@ -331,6 +283,59 @@ auto fifteen_hook =
cd.currentdir = mapstream::fixspin(mapstream::relspin[at], cd.currentdir, c->type, f.vernum);
println(hlog, "assigned ", cd.current, " to ", c);
}
enable();
}
void o_key(o_funcs& v) {
v.push_back(named_dialog("edit the Fifteen puzzle", edit_fifteen));
}
void enable() {
rogueviz::rv_hook(hooks_o_key, 80, o_key);
rogueviz::rv_hook(hooks_drawcell, 100, draw_fifteen);
rogueviz::rv_hook(mapstream::hooks_savemap, 100, [] (fhstream& f) {
f.write<int>(15);
f.write<int>(isize(fif));
for(auto cd: fif) {
f.write(mapstream::cellids[cd.first]);
println(hlog, cd.first, " has id ", mapstream::cellids[cd.first]);
f.write(cd.second.target);
f.write(cd.second.targetdir);
if(nonorientable)
f.write(cd.second.targetmirror);
f.write(cd.second.current);
f.write(cd.second.currentdir);
if(nonorientable)
f.write(cd.second.currentmirror);
}
});
rogueviz::rv_hook(hooks_clearmemory, 40, [] () {
fif.clear();
});
}
#if CAP_COMMANDLINE
int rugArgs() {
using namespace arg;
if(0) ;
else if(argis("-fifteen")) {
PHASEFROM(3);
launch();
addHook(mapstream::hooks_loadmap_old, 100, load_fifteen);
#if ISWEB
mapstream::loadMap("1");
#endif
}
else return 1;
return 0;
}
auto fifteen_hook =
addHook(hooks_args, 100, rugArgs)
+ addHook(mapstream::hooks_loadmap, 100, [] (fhstream& f, int id) {
if(id == 15) load_fifteen(f);
});
#endif