8#include "absl/status/status.h"
9#include "absl/strings/str_cat.h"
15absl::StatusOr<NpcTable>
ParseNpcs(std::string_view text) {
17 const absl::Status parsed =
ParseText(text, file);
21 absl::StatusOr<std::map<uint32_t, npcs::Kind>> kinds =
ById(file.kinds());
23 return kinds.status();
25 NpcTable table{.kinds = *std::move(kinds),
26 .spawns = {file.spawns().begin(), file.spawns().end()}};
27 for (
const auto& [
id, kind] : table.
kinds) {
28 if (kind.look().skin() == 0) {
29 return absl::InvalidArgumentError(
30 absl::StrCat(
"the ", kind.name(),
" has no skin"));
33 for (
const npcs::Spawn& spawn : table.
spawns) {
absl::StatusOr< std::map< uint32_t, Entry > > ById(const google::protobuf::RepeatedPtrField< Entry > &entries)
absl::Status ParseText(std::string_view text, google::protobuf::Message &message)
absl::StatusOr< NpcTable > ParseNpcs(std::string_view text)
absl::Status CheckSpawn(const std::map< uint32_t, Kind > &kinds, const Spawn &spawn)
Whether a spawn names a kind we have, in a land we have.
The kinds of NPC, by id, and where each NPC stands.
std::vector< npcs::Spawn > spawns
std::map< uint32_t, npcs::Kind > kinds