2 Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
10 #include "components.h"
14 #include <core/component.h>
15 #include <core/animator.h>
16 #include <core/color.h>
17 #include <core/moveserializer.h>
18 #include <core/namer.h>
19 #include <core/policy.h>
20 #include <core/state.h>
21 #include <core/validator.h>
23 Components::Components(Variant
* variant
) {
27 void Components::setVariant(Variant
* variant
) {
29 kError() << "Creating a component collection using a null variant";
31 m_variant
= std::auto_ptr
<Variant
>(variant
);
33 m_animator_factory
= requestComponent
<IAnimatorFactory
>(
34 m_variant
.get(), "animator_factory");
35 m_state
= requestComponent
<IState
>(
36 m_variant
.get(), "state");
38 Repository::ComponentMap serializers
=
39 m_variant
->repository()->listComponents("move_serializer/");
40 for (Repository::ComponentMap::iterator it
= serializers
.begin(),
41 end
= serializers
.end(); it
!= end
; ++it
) {
42 IMoveSerializer
* s
= requestInterface
<IMoveSerializer
>(it
.value());
43 if (s
) m_move_serializers
[it
.key()] = s
;
46 m_namer
= requestComponent
<INamer
>(m_variant
.get(), "namer");
47 m_policy
= requestComponent
<IPolicy
>(m_variant
.get(), "policy");
48 m_validator
= requestComponent
<IValidator
>(m_variant
.get(), "validator");
50 Repository::ComponentMap players
=
51 m_variant
->repository()->listComponents("player");
52 for (Repository::ComponentMap::iterator it
= players
.begin(),
53 end
= players
.end(); it
!= end
; ++it
) {
55 int index
= it
.key().toInt(&ok
);
57 IColor
* color
= requestInterface
<IColor
>(it
.value());
60 m_players
[index
] = color
;
64 IAnimator
* Components::createAnimator(TaguaAPI
* api
) const {
65 return m_animator_factory
->create(api
, m_namer
);
68 IState
* Components::createState() const {
69 return m_state
->clone();
72 IMoveSerializer
* Components::moveSerializer(const QString
& type
) {
73 return m_move_serializers
[type
];
76 INamer
* Components::namer() { return m_namer
; }
78 IPolicy
* Components::policy() { return m_policy
; }
80 IValidator
* Components::validator() { return m_validator
; }
82 IColor
* Components::player(int index
) { return m_players
[index
]; }
84 QMap
<int, IColor
*> Components::players() { return m_players
; }
86 Variant
* Components::variant() { return m_variant
.get(); }