Choose colony rules on New and preserve saved rules on load
This commit is contained in:
1 parent
e6a01bedcc
commit
180506d414
7 files changed
+277
-25
No files matched your search
+19
-14
@@ -19,25 +19,24 @@ RulesManifest supported_rules() {
|
||||
return std::move(*manifest);
|
||||
}
|
||||
|
||||
void validate_supported(const WorldCheckpoint& candidate, const RulesManifest& rules) {
|
||||
void validate_supported(const WorldCheckpoint& candidate) {
|
||||
const auto valid = validate_colony_checkpoint(candidate);
|
||||
if (!valid) throw std::runtime_error(valid.error().message);
|
||||
if (!candidate.world || candidate.world->width() != first_colony_map_size ||
|
||||
candidate.world->height() != first_colony_map_size) {
|
||||
throw std::runtime_error("This viewer opens worlds with a 32 by 32 map.");
|
||||
}
|
||||
if (candidate.rules != rules) {
|
||||
throw std::runtime_error("This viewer requires the installed default colony rules.");
|
||||
}
|
||||
}
|
||||
|
||||
WorldCheckpoint validated_initial(WorldCheckpoint candidate, const RulesManifest& rules) {
|
||||
validate_supported(candidate, rules);
|
||||
WorldCheckpoint validated_initial(WorldCheckpoint candidate) {
|
||||
validate_supported(candidate);
|
||||
return candidate;
|
||||
}
|
||||
|
||||
WorldCheckpoint initial_colony(std::size_t workers) {
|
||||
auto identity = Void::Uuid::try_v4();
|
||||
if (!identity) throw std::runtime_error("Could not create a world identity.");
|
||||
return {make_first_colony(workers), *identity, 1, supported_rules()};
|
||||
WorldCheckpoint initial_colony(std::size_t workers, ColonyProfile profile = ColonyProfile::Default) {
|
||||
auto candidate = make_colony_checkpoint(profile, workers);
|
||||
if (!candidate) throw std::runtime_error(candidate.error().message);
|
||||
return std::move(*candidate);
|
||||
}
|
||||
|
||||
RuntimeOptions suspended(RuntimeOptions options) {
|
||||
@@ -59,7 +58,7 @@ ViewerSession::ViewerSession(std::size_t workers, ViewerSessionOptions options)
|
||||
ViewerSession::ViewerSession(WorldCheckpoint initial, std::size_t workers, ViewerSessionOptions options)
|
||||
: workers_(workers), command_capacity_(options.command_capacity),
|
||||
supported_rules_(supported_rules()),
|
||||
runtime_(validated_initial(std::move(initial), supported_rules_), suspended(std::move(options.runtime))),
|
||||
runtime_(validated_initial(std::move(initial)), suspended(std::move(options.runtime))),
|
||||
files_(std::move(options.files)) {
|
||||
if (command_capacity_ == 0) throw std::invalid_argument("The command queue must have capacity.");
|
||||
}
|
||||
@@ -74,6 +73,12 @@ bool ViewerSession::can_submit() const {
|
||||
return !guest_ && !changing_world_ && runtime_.view().state == RuntimeState::Running;
|
||||
}
|
||||
|
||||
bool ViewerSession::can_host_legacy() const {
|
||||
const auto current = runtime_.view();
|
||||
return !guest_ && !changing_world_ && current.state == RuntimeState::Running &&
|
||||
current.snapshot->rules && *current.snapshot->rules == supported_rules_;
|
||||
}
|
||||
|
||||
std::optional<std::uint64_t> ViewerSession::submit(SessionPayload payload) {
|
||||
if (!can_submit()) return std::nullopt;
|
||||
for (const auto& intent : intents_) {
|
||||
@@ -111,7 +116,7 @@ LoadTicket ViewerSession::begin_change() {
|
||||
}
|
||||
|
||||
void ViewerSession::validate_candidate(const WorldCheckpoint& candidate) const {
|
||||
validate_supported(candidate, supported_rules_);
|
||||
validate_supported(candidate);
|
||||
}
|
||||
|
||||
void ViewerSession::replace(WorldCheckpoint candidate) {
|
||||
@@ -120,8 +125,8 @@ void ViewerSession::replace(WorldCheckpoint candidate) {
|
||||
installing_.emplace(Installing{ticket, std::move(candidate)});
|
||||
}
|
||||
|
||||
void ViewerSession::new_colony() {
|
||||
replace(initial_colony(workers_));
|
||||
void ViewerSession::new_colony(ColonyProfile profile) {
|
||||
replace(initial_colony(workers_, profile));
|
||||
}
|
||||
|
||||
void ViewerSession::load(const std::filesystem::path& path) {
|
||||
|
||||
Reference in new issue
Block a user