Skip to content

Commit

Permalink
Revert "JSON for playable species+apts, jobs, combos"
Browse files Browse the repository at this point in the history
This reverts commit 46ea769.
  • Loading branch information
greensnark committed Apr 23, 2015
1 parent 46ea769 commit 010c3af
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 153 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Expand Up @@ -31,6 +31,3 @@
[submodule "crawl-ref/source/contrib/sdl2-mixer"]
path = crawl-ref/source/contrib/sdl2-mixer
url = git://github.com/crawl/crawl-sdl2-mixer
[submodule "crawl-ref/source/contrib/rapidjson"]
path = crawl-ref/source/contrib/rapidjson
url = git://github.com/crawl/rapidjson
13 changes: 6 additions & 7 deletions crawl-ref/source/Makefile
Expand Up @@ -104,7 +104,7 @@ include Makefile.obj


CFOTHERS := -pipe $(EXTERNAL_FLAGS)
CFWARN :=
CFWARN :=
CFWARN_L := -Wall -Wformat-security -Wundef

DEFINES := $(EXTERNAL_DEFINES)
Expand Down Expand Up @@ -222,7 +222,7 @@ ifeq ($(uname_S),Darwin)
BUILD_SDL2 = YesPlease
BUILD_SDL2IMAGE = YesPlease
ifdef SOUND
ifndef WIN32
ifndef WIN32
BUILD_SDL2MIXER = YesPlease
endif
endif
Expand All @@ -245,7 +245,7 @@ ifdef BUILD_ALL
BUILD_SDL2 = YesPlease
BUILD_SDL2IMAGE = YesPlease
ifdef SOUND
ifndef WIN32
ifndef WIN32
BUILD_SDL2MIXER = YesPlease
endif
endif
Expand Down Expand Up @@ -386,9 +386,8 @@ DATADIR := data
SAVEDIR := ~/.crawl
endif

RAPIDJSON_I := contrib/rapidjson/include

INCLUDES_L += -Iutil -I. -I$(RAPIDJSON_I)
INCLUDES_L += -Iutil -I.

ifdef APPLE_GCC

Expand Down Expand Up @@ -725,7 +724,7 @@ SDL2_LDFLAGS := $(shell $(PKGCONFIG) sdl2 --libs-only-L) $(shell $(PKGCONFIG) sd
endif

ifdef SOUND
ifndef WIN32
ifndef WIN32
LIBS += -lSDL2_mixer
endif
endif
Expand Down Expand Up @@ -1018,7 +1017,7 @@ endif

ifdef BUILD_PCRE
DEFINES += -DREGEX_PCRE
else
else
ifdef USE_PCRE
DEFINES += -DREGEX_PCRE
LIBS += -lpcre
Expand Down
1 change: 0 additions & 1 deletion crawl-ref/source/contrib/rapidjson
Submodule rapidjson deleted from 7f4337
17 changes: 12 additions & 5 deletions crawl-ref/source/initfile.cc
Expand Up @@ -4255,7 +4255,7 @@ enum commandline_option_type
CLO_NO_GDB, CLO_NOGDB,
CLO_THROTTLE,
CLO_NO_THROTTLE,
CLO_PLAYABLE_JSON, // JSON metadata for species, jobs, combos.
CLO_LIST_COMBOS, // List species, jobs, and legal combos, in that order.
#ifdef USE_TILE_WEB
CLO_WEBTILES_SOCKET,
CLO_AWAIT_CONNECTION,
Expand All @@ -4273,8 +4273,7 @@ static const char *cmd_ops[] =
"builddb", "help", "version", "seed", "save-version", "sprint",
"extra-opt-first", "extra-opt-last", "sprint-map", "edit-save",
"print-charset", "tutorial", "wizard", "explore", "no-save",
"gdb", "no-gdb", "nogdb", "throttle", "no-throttle",
"playable-json",
"gdb", "no-gdb", "nogdb", "throttle", "no-throttle", "list-combos",
#ifdef USE_TILE_WEB
"webtiles-socket", "await-connection", "print-webtiles-options",
#endif
Expand Down Expand Up @@ -4893,9 +4892,17 @@ bool parse_args(int argc, char **argv, bool rc_only)
crawl_state.dump_maps = true;
break;

case CLO_PLAYABLE_JSON:
fprintf(stdout, "%s", playable_metadata_json().c_str());
case CLO_LIST_COMBOS:
{
auto join = [](const vector<string> &vs) {
return comma_separated_line(vs.begin(), vs.end(), ",", ",");
};
fprintf(stdout, "%s\n%s\n%s\n",
join(playable_species_names()).c_str(),
join(playable_job_names()).c_str(),
join(playable_combo_names()).c_str());
end(0);
}

case CLO_TEST:
crawl_state.test = true;
Expand Down
2 changes: 1 addition & 1 deletion crawl-ref/source/main.cc
Expand Up @@ -552,7 +552,7 @@ static void _show_commandline_options_help()
#ifndef TARGET_OS_WINDOWS
puts(" -gdb/-no-gdb produce gdb backtrace when a crash happens (default:on)");
#endif
puts(" -playable-json list playable species + apts, jobs, and character combos.");
puts(" -list-combos list playable species, jobs, and character combos.");

#if defined(TARGET_OS_WINDOWS) && defined(USE_TILE_LOCAL)
text_popup(help, L"Dungeon Crawl command line help");
Expand Down
137 changes: 3 additions & 134 deletions crawl-ref/source/playable.cc
Expand Up @@ -8,28 +8,24 @@
#include <algorithm>
#include <vector>

#define RAPIDJSON_HAS_STDSTRING 1
#include <rapidjson/writer.h>

#include "playable.h"
#include "jobs.h"
#include "newgame.h"
#include "ng-restr.h"
#include "species.h"
#include "skills.h"

string combo_type::abbr() const
{
return string(get_species_abbrev(species)) + get_job_abbrev(job);
}

template <typename Enum, typename Predicate>
vector<Enum> filter_enum(Enum max, Predicate filter)
auto filter_enum(Enum max, Predicate filter) -> vector<decltype(max)>
{
vector<Enum> things;
vector<decltype(max)> things;
for (int i = 0; i < max; ++i)
{
const Enum thing(static_cast<Enum>(i));
const decltype(max) thing(static_cast<decltype(max)>(i));
if (filter(thing))
things.push_back(thing);
}
Expand Down Expand Up @@ -88,130 +84,3 @@ vector<string> playable_combo_names()
return stringify(playable_combos(),
[](combo_type c) { return c.abbr(); });
}

// JSON output:

typedef rapidjson::Writer<rapidjson::StringBuffer> json_writer;

static void _species_apts(json_writer &w, species_type sp)
{
w.StartObject();
for (int i = SK_FIRST_SKILL; i < NUM_SKILLS; ++i)
{
const skill_type sk(static_cast<skill_type>(i));
const int apt(species_apt(sk, sp));
if (apt != UNUSABLE_SKILL)
{
w.Key(skill_name(sk));
w.Int(species_apt(sk, sp));
}
}
w.EndObject();
}

static void _species_modifiers(json_writer &w, species_type sp)
{
w.StartObject();
w.Key("xp");
w.Int(species_exp_modifier(sp));
w.Key("hp");
w.Int(species_hp_modifier(sp));
w.Key("mp");
w.Int(species_mp_modifier(sp));
w.Key("stealth");
w.Int(species_stealth_modifier(sp));
w.Key("mr");
w.Int(species_mr_modifier(sp));
w.EndObject();
}

static void _species_metadata(json_writer &w, species_type sp)
{
w.StartObject();
w.Key("name");
w.String(species_name(sp));
w.Key("abbr");
w.String(get_species_abbrev(sp));
w.Key("apts");
_species_apts(w, sp);
w.Key("modifiers");
_species_modifiers(w, sp);
w.EndObject();
}

static void _species_metadata_array(json_writer &w)
{
w.StartArray();
for (species_type sp : playable_species())
_species_metadata(w, sp);
w.EndArray();
}

static void _job_metadata(json_writer &w, job_type job)
{
w.StartObject();
w.Key("name");
w.String(get_job_name(job));
w.Key("abbr");
w.String(get_job_abbrev(job));
w.EndObject();
}

static void _job_metadata_array(json_writer &w)
{
w.StartArray();
for (job_type job : playable_jobs())
_job_metadata(w, job);
w.EndArray();
}

static void _combo_array(json_writer &w)
{
w.StartArray();
for (const string &combo_abbr : playable_combo_names())
w.String(combo_abbr);
w.EndArray();
}

/*! @brief Returns a JSON object (encoded as a string) of the form
* @code
* { "species": [...], "jobs": [...], "combos": [...] }
* @endcode
*
* Species are objects of the form:
* @code
* { "name": "Vine Stalker", "abbr": "VS", "apts": {...}, "modifiers": {...} }
* @endcode
*
* Jobs are objects of the form:
* @code
* { "name": "Fire Elementalist", "abbr": "FE" }
* @endcode
*
* Combos is an array of combo abbreviation strings.
*
* Aptitudes (apts) is an object of the form:
* @code
* { "<skill-name>": <aptitude> }
* @endcode
*
* Modifiers is an object of the form:
* @code
* { "<modifier-name>": <modifier> }
* @endcode
* where <modifier-name>: hp, mp, exp, stealth, mr.
*/
string playable_metadata_json()
{
rapidjson::StringBuffer sb_metadata;
json_writer writer(sb_metadata);
writer.StartObject();
writer.Key("species");
_species_metadata_array(writer);
writer.Key("jobs");
_job_metadata_array(writer);
writer.Key("combos");
_combo_array(writer);
writer.EndObject();
return sb_metadata.GetString();
}
2 changes: 0 additions & 2 deletions crawl-ref/source/playable.h
Expand Up @@ -24,6 +24,4 @@ vector<string> playable_job_names();
vector<string> playable_species_names();
vector<string> playable_combo_names();

string playable_metadata_json();

#endif

0 comments on commit 010c3af

Please sign in to comment.