1 #include "cmdhelp/lua.hpp"
2 #include "core/advdumper.hpp"
3 #include "core/command.hpp"
4 #include "core/dispatch.hpp"
5 #include "core/instance.hpp"
6 #include "core/moviedata.hpp"
7 #include "core/project.hpp"
8 #include "core/queue.hpp"
9 #include "core/rom.hpp"
10 #include "core/ui-services.hpp"
11 #include "library/keyboard.hpp"
16 void fill_namemap(project_info
& p
, uint64_t id
, std::map
<uint64_t, std::string
>& namemap
,
17 std::map
<uint64_t, std::set
<uint64_t>>& childmap
)
19 namemap
[id
] = p
.get_branch_name(id
);
20 auto s
= p
.branch_children(id
);
22 fill_namemap(p
, i
, namemap
, childmap
);
26 void update_dumperinfo(emulator_instance
& inst
, std::map
<std::string
, dumper_information_1
>& new_dumpers
,
27 dumper_factory_base
* d
)
29 struct dumper_information_1 inf
;
32 std::set
<std::string
> mset
= d
->list_submodes();
34 inf
.modes
[i
] = d
->modename(i
);
35 inf
.active
= inst
.mdumper
->busy(d
);
36 inf
.hidden
= d
->hidden();
37 new_dumpers
[d
->id()] = inf
;
41 void do_flush_slotinfo();
43 void UI_get_branch_map(emulator_instance
& inst
, uint64_t& cur
, std::map
<uint64_t, std::string
>& namemap
,
44 std::map
<uint64_t, std::set
<uint64_t>>& childmap
)
46 auto project
= inst
.project
;
47 inst
.iqueue
->run([project
, &cur
, &namemap
, &childmap
]() {
48 auto p
= project
->get();
50 fill_namemap(*p
, 0, namemap
, childmap
);
51 cur
= p
->get_current_branch();
55 void UI_call_flush(emulator_instance
& inst
, std::function
<void(std::exception
&)> onerror
)
57 auto project
= inst
.project
;
58 inst
.iqueue
->run_async([project
]() {
59 auto p
= project
->get();
64 void UI_create_branch(emulator_instance
& inst
, uint64_t id
, const std::string
& name
,
65 std::function
<void(std::exception
&)> onerror
)
67 auto project
= inst
.project
;
68 inst
.iqueue
->run_async([project
, id
, name
]() {
69 auto p
= project
->get();
71 p
->create_branch(id
, name
);
76 void UI_rename_branch(emulator_instance
& inst
, uint64_t id
, const std::string
& name
,
77 std::function
<void(std::exception
&)> onerror
)
79 auto project
= inst
.project
;
80 auto supdater
= inst
.supdater
;
81 inst
.iqueue
->run_async([project
, supdater
, id
, name
]() {
82 auto p
= project
->get();
84 p
->set_branch_name(id
, name
);
90 void UI_reparent_branch(emulator_instance
& inst
, uint64_t id
, uint64_t pid
,
91 std::function
<void(std::exception
&)> onerror
)
93 auto project
= inst
.project
;
94 auto supdater
= inst
.supdater
;
95 inst
.iqueue
->run_async([project
, supdater
, id
, pid
]() {
96 auto p
= project
->get();
98 p
->set_parent_branch(id
, pid
);
104 void UI_delete_branch(emulator_instance
& inst
, uint64_t id
, std::function
<void(std::exception
&)> onerror
)
106 auto project
= inst
.project
;
107 inst
.iqueue
->run_async([project
, id
]() {
108 auto p
= project
->get();
110 p
->delete_branch(id
);
115 void UI_switch_branch(emulator_instance
& inst
, uint64_t id
, std::function
<void(std::exception
&)> onerror
)
117 auto project
= inst
.project
;
118 auto supdater
= inst
.supdater
;
119 inst
.iqueue
->run_async([project
, supdater
, id
]() {
120 auto p
= project
->get();
122 p
->set_current_branch(id
);
128 project_author_info
UI_load_author_info(emulator_instance
& inst
)
130 project_author_info x
;
131 inst
.iqueue
->run([&inst
, &x
]() {
132 project_info
* proj
= inst
.project
->get();
133 x
.is_project
= (proj
!= NULL
);
134 x
.autorunlua
= false;
136 x
.projectname
= proj
->name
;
137 x
.directory
= proj
->directory
;
138 x
.prefix
= proj
->prefix
;
139 x
.luascripts
= proj
->luascripts
;
140 x
.gamename
= proj
->gamename
;
141 for(auto i
: proj
->authors
)
142 x
.authors
.push_back(i
);
144 x
.prefix
= get_mprefix_for_project();
145 x
.gamename
= inst
.mlogic
->get_mfile().gamename
;
146 for(auto i
: inst
.mlogic
->get_mfile().authors
)
147 x
.authors
.push_back(i
);
153 void UI_save_author_info(emulator_instance
& inst
, project_author_info
& info
)
155 inst
.iqueue
->run([&inst
, info
]() {
156 project_info
* proj
= inst
.project
->get();
157 std::set
<std::string
> oldscripts
;
158 std::vector
<std::pair
<std::string
, std::string
>> _authors(info
.authors
.begin(), info
.authors
.end());
160 for(auto i
: proj
->luascripts
)
161 oldscripts
.insert(i
);
162 proj
->gamename
= info
.gamename
;
163 proj
->authors
= _authors
;
164 proj
->prefix
= info
.prefix
;
165 proj
->directory
= info
.directory
;
166 proj
->name
= info
.projectname
;
167 proj
->luascripts
= info
.luascripts
;
169 //For save status to immediately update.
171 inst
.supdater
->update();
172 inst
.dispatch
->title_change();
174 inst
.mlogic
->get_mfile().gamename
= info
.gamename
;
175 inst
.mlogic
->get_mfile().authors
= _authors
;
176 set_mprefix_for_project(info
.prefix
);
178 if(proj
&& info
.autorunlua
)
179 for(auto i
: info
.luascripts
)
180 if(!oldscripts
.count(i
))
181 inst
.command
->invoke(CLUA::run
.name
, i
);
185 dumper_information
UI_get_dumpers(emulator_instance
& inst
)
187 dumper_information x
;
188 inst
.iqueue
->run([&inst
, &x
]() {
189 std::set
<dumper_factory_base
*> dset
= dumper_factory_base::get_dumper_set();
191 update_dumperinfo(inst
, x
.dumpers
, i
);
196 void UI_start_dump(emulator_instance
& inst
, dumper_factory_base
& factory
, const std::string
& mode
,
197 const std::string
& prefix
)
199 inst
.iqueue
->run([&inst
, &factory
, mode
, prefix
]() {
200 inst
.mdumper
->start(factory
, mode
, prefix
);
204 void UI_end_dump(emulator_instance
& inst
, dumper_factory_base
& factory
)
206 inst
.iqueue
->run([&inst
, &factory
]() {
207 auto in
= inst
.mdumper
->get_instance(&factory
);
212 void UI_do_keypress(emulator_instance
& inst
, const keyboard::modifier_set
& mods
, keyboard::key_key
& key
,
216 inst
.iqueue
->run_async([mods
, _key
, polarity
]() {
217 _key
->set_state(mods
, polarity
? 1 : 0);
218 }, [](std::exception
& e
) {});
221 bool UI_has_movie(emulator_instance
& inst
)
224 inst
.iqueue
->run([&inst
, &ret
]() {
225 ret
= !!*inst
.mlogic
&& !inst
.rom
->isnull();
230 void UI_save_movie(emulator_instance
& inst
, std::ostringstream
& stream
)
232 inst
.iqueue
->run([&inst
, &stream
]() {
233 auto prj
= inst
.project
->get();
235 inst
.mlogic
->get_mfile().gamename
= prj
->gamename
;
236 inst
.mlogic
->get_mfile().authors
= prj
->authors
;
238 inst
.mlogic
->get_mfile().dyn
.active_macros
.clear();
239 inst
.mlogic
->get_mfile().save(stream
, inst
.mlogic
->get_rrdata(), false);
243 std::pair
<std::string
, std::string
> UI_lookup_platform_and_game(emulator_instance
& inst
)
247 inst
.iqueue
->run([&inst
, &plat
, &game
]() {
248 auto prj
= inst
.project
->get();
250 game
= prj
->gamename
;
252 game
= inst
.mlogic
->get_mfile().gamename
;
253 plat
= lookup_sysregion_mapping(inst
.mlogic
->get_mfile().gametype
->get_name());
255 return std::make_pair(plat
, game
);
258 std::string
UI_get_project_otherpath(emulator_instance
& inst
)
261 inst
.iqueue
->run([&inst
, &path
]() {
262 path
= inst
.project
->otherpath();
267 std::string
UI_get_project_moviepath(emulator_instance
& inst
)
270 inst
.iqueue
->run([&inst
, &path
]() {
271 path
= inst
.project
->moviepath();
276 bool UI_in_project_context(emulator_instance
& inst
)
279 inst
.iqueue
->run([&inst
, &pc
]() {
280 pc
= (inst
.project
->get() != NULL
);