The Battle for Wesnoth  1.19.5+dev
controller.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2024
3  by Iris Morelle <shadowm2006@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  * @file
18  * Storyscreen controller (interface).
19  */
20 
21 #pragma once
22 
23 #include "storyscreen/parser.hpp"
24 
25 #include <memory>
26 #include <string>
27 #include <vector>
28 
29 namespace storyscreen
30 {
31 class part;
32 
33 class controller : private story_parser
34 {
35 public:
36  typedef std::shared_ptr<part> part_pointer_type;
37 
38  controller(const vconfig& data, const std::string& scenario_name);
39 
41  {
42  return parts_.at(index);
43  }
44 
45  int max_parts() const
46  {
47  return parts_.size();
48  }
49 
50 private:
51  /** Inherited from story_parser. */
52  virtual bool resolve_wml_helper(const std::string& key, const vconfig& node) override;
53 
54  std::string scenario_name_;
55 
56  // The part cache.
57  std::vector<part_pointer_type> parts_;
58 };
59 
60 } // end namespace storyscreen
part_pointer_type get_part(int index) const
Definition: controller.hpp:40
controller(const vconfig &data, const std::string &scenario_name)
Definition: controller.cpp:36
std::shared_ptr< part > part_pointer_type
Definition: controller.hpp:36
virtual bool resolve_wml_helper(const std::string &key, const vconfig &node) override
Inherited from story_parser.
Definition: controller.cpp:44
std::vector< part_pointer_type > parts_
Definition: controller.hpp:57
std::string scenario_name_
Definition: controller.hpp:54
Small helper class to encapsulate the common logic for parsing storyscreen WML.
Definition: parser.hpp:29
A variable-expanding proxy for the config class.
Definition: variable.hpp:45
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
Definition: unicode.cpp:70
std::string_view data
Definition: picture.cpp:178