From d2153aee875e16befb54d7b5434483d683ff71ff Mon Sep 17 00:00:00 2001 From: Misa Date: Sun, 22 Aug 2021 20:51:21 -0700 Subject: [PATCH] Refactor warp dir switching to separate function This is so the same code can be used to go in reverse instead of copy-pasting it. --- desktop_version/src/editor.cpp | 67 +++++++++++++++++++++------------- desktop_version/src/editor.h | 1 + 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/desktop_version/src/editor.cpp b/desktop_version/src/editor.cpp index 214ca7d3..4dd2fa1b 100644 --- a/desktop_version/src/editor.cpp +++ b/desktop_version/src/editor.cpp @@ -1748,6 +1748,44 @@ void editorclass::switch_enemy(const bool reversed) notedelay = 45; } +void editorclass::switch_warpdir(const bool reversed) +{ + static const int modulus = 4; + const edlevelclass* const room = getroomprop(levx, levy); + + int warpdir = room->warpdir; + + if (reversed) + { + --warpdir; + } + else + { + ++warpdir; + } + + warpdir = (warpdir % modulus + modulus) % modulus; + setroomwarpdir(levx, levy, warpdir); + + switch (warpdir) + { + default: + note = "Room warping disabled"; + break; + case 1: + note = "Room warps horizontally"; + break; + case 2: + note = "Room warps vertically"; + break; + case 3: + note = "Room warps in all directions"; + break; + } + + notedelay = 45; +} + bool editorclass::load(std::string& _path) { tinyxml2::XMLDocument doc; @@ -4791,32 +4829,9 @@ void editorinput(void) if(key.keymap[SDLK_w]) { - ed.setroomwarpdir(ed.levx, ed.levy, (ed.getroomprop(ed.levx, ed.levy)->warpdir+1)%4); - if(ed.getroomprop(ed.levx, ed.levy)->warpdir==0) - { - ed.note="Room warping disabled"; - ed.notedelay=45; - graphics.backgrounddrawn=false; - } - else if(ed.getroomprop(ed.levx, ed.levy)->warpdir==1) - { - ed.note="Room warps horizontally"; - ed.notedelay=45; - graphics.backgrounddrawn=false; - } - else if(ed.getroomprop(ed.levx, ed.levy)->warpdir==2) - { - ed.note="Room warps vertically"; - ed.notedelay=45; - graphics.backgrounddrawn=false; - } - else if(ed.getroomprop(ed.levx, ed.levy)->warpdir==3) - { - ed.note="Room warps in all directions"; - ed.notedelay=45; - graphics.backgrounddrawn=false; - } - ed.keydelay=6; + ed.switch_warpdir(false); + graphics.backgrounddrawn = false; + ed.keydelay = 6; } if(key.keymap[SDLK_e]) { diff --git a/desktop_version/src/editor.h b/desktop_version/src/editor.h index 79a85bbd..ac3eecd3 100644 --- a/desktop_version/src/editor.h +++ b/desktop_version/src/editor.h @@ -190,6 +190,7 @@ class editorclass{ void switch_tilecol(const bool reversed); void clamp_tilecol(const int rx, const int ry, const bool wrap); void switch_enemy(const bool reversed); + void switch_warpdir(const bool reversed); bool load(std::string& _path); bool save(std::string& _path);