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 <core/board.h>
11 #include <core/color.h>
12 #include <core/repository.h>
13 #include <core/type.h>
14 #include <core/variantloader.h>
17 #include "behaviour.h"
18 #include "moveserializer.h"
20 #include "validator.h"
24 using namespace Crazyhouse
;
26 #define LOAD_TYPE(NAME) \
27 NAME = requestInterface<IType>(chess->getComponent("type/" #NAME))
29 namespace Crazyhouse
{
36 const IColor
* players
[2];
39 extern "C" KDE_EXPORT Repository
*
40 taguacrazyhouse_initrepo(IVariantLoader
* loader
) {
41 Repository
* repo
= new Repository
;
42 Repository
* chess
= loader
->getRepository("chess");
44 repo
->setProxy(chess
);
46 // get chess state factory
47 Component
* chess_state_comp
= chess
->getComponent("state");
48 IState
* chess_state
= requestInterface
<IState
>(chess_state_comp
);
50 // create crazyhouse behaviour
51 const IBehaviour
* behaviour
= new Behaviour(chess_state
->behaviour());
53 // create crazyhouse state factory
54 Component
* state_component
= 0;
55 bool ok
= QMetaObject::invokeMethod(chess_state_comp
, "clone",
56 Q_RETURN_ARG(Component
*, state_component
),
57 Q_ARG(const IBehaviour
*, behaviour
),
58 Q_ARG(Component
*, chess
->getComponent("extra/castling_rules")),
59 Q_ARG(Point
, chess_state
->board()->size()));
60 kDebug() << "cloning prototype state" << ok
;
61 State
* state
= new State(requestInterface
<IState
>(state_component
));
64 repo
->addComponent("state", state
);
66 // set animator factory
67 IAnimatorFactory
* chess_animator_factory
=
68 requestInterface
<IAnimatorFactory
>(chess
->getComponent("animator_factory"));
69 repo
->addComponent("animator_factory", new AnimatorFactory(chess_animator_factory
));
72 IValidator
* validator
= requestInterface
<IValidator
>(chess
->getComponent("validator"));
73 repo
->addComponent("validator", new Validator(validator
));
75 // set move serializers
76 Repository::ComponentMap serializers
= chess
->listComponents("move_serializer");
77 for (Repository::ComponentMap::const_iterator it
= serializers
.begin(),
78 end
= serializers
.end(); it
!= end
; ++it
) {
79 IMoveSerializer
* s
= requestInterface
<IMoveSerializer
>(it
.value());
80 if (s
) repo
->addComponent("move_serializer/" + it
.key(), new MoveSerializer(s
));
89 players
[0] = White::self();
90 players
[1] = Black::self();