From 8f36ecdca1766ddd2a177fa46dc885c7f8e14130 Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Sun, 9 Aug 2020 20:16:23 +0200 Subject: [PATCH] Modules reorganization --- Makefile.am | 2 +- modules/base.scm | 21 ++++++++++++ modules/dungeon-master/dialogue.scm | 29 +++++++++++++++++ modules/dungeon-master/generators/terrain.scm | 22 +++++++++++++ .../dungeon-master}/generators/town.scm | 0 .../dungeon-master}/geom.scm | 0 .../dungeon-master}/geom/bowyer-watson.scm | 0 .../dungeon-master}/geom/point.scm | 0 .../dungeon-master}/geom/triangle.scm | 0 .../dungeon-master}/geom/voronoi.scm | 0 src/main.cpp | 4 +-- src/{mods.cpp => modules.cpp} | 32 +++++++++---------- src/{mods.h => modules.h} | 2 +- 13 files changed, 92 insertions(+), 20 deletions(-) create mode 100644 modules/base.scm create mode 100644 modules/dungeon-master/dialogue.scm create mode 100644 modules/dungeon-master/generators/terrain.scm rename {dungeon-master => modules/dungeon-master}/generators/town.scm (100%) rename {dungeon-master => modules/dungeon-master}/geom.scm (100%) rename {dungeon-master => modules/dungeon-master}/geom/bowyer-watson.scm (100%) rename {dungeon-master => modules/dungeon-master}/geom/point.scm (100%) rename {dungeon-master => modules/dungeon-master}/geom/triangle.scm (100%) rename {dungeon-master => modules/dungeon-master}/geom/voronoi.scm (100%) rename src/{mods.cpp => modules.cpp} (75%) rename src/{mods.h => modules.h} (96%) diff --git a/Makefile.am b/Makefile.am index 05cea95..fdf853c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,7 +2,7 @@ bin_PROGRAMS = dmaster dmaster_SOURCES = \ src/generators.cpp \ src/main.cpp \ - src/mods.cpp \ + src/modules.cpp \ src/paths.cpp dmaster_CPPFLAGS = \ @GUILE_CFLAGS@ \ diff --git a/modules/base.scm b/modules/base.scm new file mode 100644 index 0000000..ac69646 --- /dev/null +++ b/modules/base.scm @@ -0,0 +1,21 @@ +;;; Dungeon Master --- RPG Adventure Generator +;;; Copyright © 2019 Javier Sancho + +;;; Dungeon Master is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or +;;; (at your option) any later version. + +;;; Dungeon Master is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. + +;;; You should have received a copy of the GNU General Public License +;;; along with Dungeon Master. If not, see . + + +(use-modules (dungeon-master) + (dungeon-master generators terrain)) + +(register-scene-generator "Basic city" 'urban city-generator) diff --git a/modules/dungeon-master/dialogue.scm b/modules/dungeon-master/dialogue.scm new file mode 100644 index 0000000..059f9a8 --- /dev/null +++ b/modules/dungeon-master/dialogue.scm @@ -0,0 +1,29 @@ +;;; Dungeon Master --- RPG Adventure Generator +;;; Copyright © 2020 Javier Sancho +;;; +;;; Dungeon Master is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or +;;; (at your option) any later version. +;;; +;;; Dungeon Master is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with Dungeon Master. If not, see . + + +(define-module (dungeon-master dialogue) + #:use-module (ice-9 optargs) + #:export (run-dialogue)) + + +(define* (run-dialogue dialogue #:optional initial-scene) + (let ((scene (if initial-scene + (assoc-ref dialogue initial-scene) + (cdar dialogue)))) + (let-keywords scene #t (text) + (display text) + (newline)))) diff --git a/modules/dungeon-master/generators/terrain.scm b/modules/dungeon-master/generators/terrain.scm new file mode 100644 index 0000000..38668b5 --- /dev/null +++ b/modules/dungeon-master/generators/terrain.scm @@ -0,0 +1,22 @@ +;;; Dungeon Master --- RPG Adventure Generator +;;; Copyright © 2019 Javier Sancho + +;;; Dungeon Master is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or +;;; (at your option) any later version. + +;;; Dungeon Master is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. + +;;; You should have received a copy of the GNU General Public License +;;; along with Dungeon Master. If not, see . + + +(define-module (dungeon-master generators terrain) + #:export (city-generator)) + +(define (city-generator x) + (format #t "***~%~a~%***~%" x)) diff --git a/dungeon-master/generators/town.scm b/modules/dungeon-master/generators/town.scm similarity index 100% rename from dungeon-master/generators/town.scm rename to modules/dungeon-master/generators/town.scm diff --git a/dungeon-master/geom.scm b/modules/dungeon-master/geom.scm similarity index 100% rename from dungeon-master/geom.scm rename to modules/dungeon-master/geom.scm diff --git a/dungeon-master/geom/bowyer-watson.scm b/modules/dungeon-master/geom/bowyer-watson.scm similarity index 100% rename from dungeon-master/geom/bowyer-watson.scm rename to modules/dungeon-master/geom/bowyer-watson.scm diff --git a/dungeon-master/geom/point.scm b/modules/dungeon-master/geom/point.scm similarity index 100% rename from dungeon-master/geom/point.scm rename to modules/dungeon-master/geom/point.scm diff --git a/dungeon-master/geom/triangle.scm b/modules/dungeon-master/geom/triangle.scm similarity index 100% rename from dungeon-master/geom/triangle.scm rename to modules/dungeon-master/geom/triangle.scm diff --git a/dungeon-master/geom/voronoi.scm b/modules/dungeon-master/geom/voronoi.scm similarity index 100% rename from dungeon-master/geom/voronoi.scm rename to modules/dungeon-master/geom/voronoi.scm diff --git a/src/main.cpp b/src/main.cpp index 16c6fac..c9aa0f9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,7 +16,7 @@ */ #include -#include "mods.h" +#include "modules.h" using namespace irr; using namespace core; @@ -26,7 +26,7 @@ using namespace gui; int main () { - load_dmaster_mods (); + load_dmaster_modules (); IrrlichtDevice* device = createDevice (video::EDT_OPENGL, core::dimension2d (640, 480)); diff --git a/src/mods.cpp b/src/modules.cpp similarity index 75% rename from src/mods.cpp rename to src/modules.cpp index 7b9115e..63c8045 100644 --- a/src/mods.cpp +++ b/src/modules.cpp @@ -18,7 +18,7 @@ #include #include #include "generators.h" -#include "mods.h" +#include "modules.h" #include "paths.h" SCM @@ -51,39 +51,39 @@ scm_init_dungeon_master_module () void add_to_load_path (std::string path) { - // Add path to %load-path variable, needed for mods structured like modules + // Add path to %load-path variable, needed for modules loading std::string exp = "(add-to-load-path \"" + path + "\")"; scm_c_eval_string (exp.c_str ()); } void -load_dmaster_mods () +load_dmaster_modules () { scm_init_guile (); scm_init_dungeon_master_module (); std::set paths = get_dmaster_paths (); - DIR* mods_dir; - struct dirent* mod; + DIR* modules_dir; + struct dirent* module; std::string - mods_path, - mod_main; + modules_path, + module_main; for (const std::string &path : paths) { - mods_path = path + PATH_DELIM + "mods"; - add_to_load_path (mods_path); - mods_dir = opendir (mods_path.c_str ()); - if (mods_dir != NULL) + modules_path = path + PATH_DELIM + "modules"; + add_to_load_path (modules_path); + modules_dir = opendir (modules_path.c_str ()); + if (modules_dir != NULL) { - while (mod = readdir (mods_dir)) + while (module = readdir (modules_dir)) { - if (strstr (mod->d_name, ".scm") != NULL) { - mod_main = mods_path + PATH_DELIM + mod->d_name; - scm_primitive_load (scm_from_locale_string (mod_main.c_str ())); + if (strstr (module->d_name, ".scm") != NULL) { + module_main = modules_path + PATH_DELIM + module->d_name; + scm_primitive_load (scm_from_locale_string (module_main.c_str ())); } } } - closedir (mods_dir); + closedir (modules_dir); } } diff --git a/src/mods.h b/src/modules.h similarity index 96% rename from src/mods.h rename to src/modules.h index f8cd154..074163e 100644 --- a/src/mods.h +++ b/src/modules.h @@ -16,4 +16,4 @@ */ void -load_dmaster_mods (); +load_dmaster_modules (); -- 2.39.2