Skip to content
Snippets Groups Projects
Commit 1e0232e4 authored by Marco Zimmer's avatar Marco Zimmer
Browse files

+Repaired Stage Delete/Edit/Clone/Save +added RelationIndex to ValidationSets

parent 21e49b9e
No related branches found
No related tags found
No related merge requests found
......@@ -47,7 +47,7 @@ public static void GenerateDemoA()
// Set Solution
StageStatic.stage.solution.ValidationSet =
new List<SolutionOrganizer.SubSolution>
{ new SolutionOrganizer.SubSolution(new HashSet<string> { target_Id }, null, new LineFactHightDirectionComparer()) };
{ new SolutionOrganizer.SubSolution(new HashSet<string> { target_Id }, null, null, new LineFactHightDirectionComparer()) };
// Save
StageStatic.stage.store();
......
......@@ -599,13 +599,19 @@ public bool DynamiclySolved(
foreach (var ValidationSet in MinimalSolution.ValidationSet)
{
// List to relato to. Either all active facts or those defined in RelationIndex if not empty
var relateList = ValidationSet.RelationIndex.Count == 0 ? activeList :
ValidationSet.RelationIndex.Select(i => Solution_L[i]) // Select by Index
.SelectMany(i => i) // Flatten structure
.Select(URI => this[URI]); // Get Facts
// check by MasterIds
// ALL Masters must relate
var part_minimal =
ValidationSet.MasterIDs.Select(URI => MinimalSolution[URI]);
var part_solution =
activeList.Where(active => part_minimal.Contains(active, ValidationSet.Comparer.SetSearchRight()))
relateList.Where(active => part_minimal.Contains(active, ValidationSet.Comparer.SetSearchRight()))
.ToList(); // needed for some reason
var part_missing =
......@@ -621,12 +627,12 @@ public bool DynamiclySolved(
var part_consequential_minimal =
ValidationSet.SolutionIndex.Select(i => Solution_L[i]) // Select by Index
.SelectMany(i => i) // Flatten structure
.Select(URI => MinimalSolution[URI]); // Get Facts
.Select(URI => this[URI]); // Get Facts
var part_consequential_solution =
activeList.Where(active => part_consequential_minimal.Contains(active, ValidationSet.Comparer.SetSearchRight()));
relateList.Where(active => part_consequential_minimal.Contains(active, ValidationSet.Comparer.SetSearchRight()));
Solution_L.Last().Concat(part_consequential_solution.Select(fact => fact.Id).ToList());
Solution_L.Last().AddRange(part_consequential_solution.Select(fact => fact.Id).ToList());
MissingElementsCount += Convert.ToInt32(
part_consequential_solution.Count() == 0 && part_consequential_minimal.Count() != 0);
}
......
......@@ -28,6 +28,12 @@ public class SubSolution
//
// List<int> SolutionIndex: int{[],[0, SolutionOrganizer.ValidationSet.IndexOf(this) - 2]}
// marks LevelFacts found as solution in a previous entry
// to relate from in addition to MasterIDs
// or none if empty
//
// List<int> RelationIndex: int{[],[0, SolutionOrganizer.ValidationSet.IndexOf(this) - 2]}
// marks LevelFacts found as solution in a previous entry
// to relate to instead of all facts
// or none if empty
//
// Comparer FactComparer:
......@@ -35,6 +41,7 @@ public class SubSolution
public HashSet<string> MasterIDs = new HashSet<string>();
public List<int> SolutionIndex = new List<int>();
public List<int> RelationIndex = new List<int>();
[JsonIgnore]
public FactComparer Comparer = new FactEquivalentsComparer();
......@@ -51,7 +58,7 @@ public string ComparerString
public SubSolution() { }
public SubSolution(HashSet<string> MasterIDs, List<int> SolutionIndex, FactComparer Comparer)
public SubSolution(HashSet<string> MasterIDs, List<int> SolutionIndex, List<int> RelationIndex, FactComparer Comparer)
{
if (MasterIDs != null)
this.MasterIDs = MasterIDs;
......@@ -59,6 +66,9 @@ public SubSolution(HashSet<string> MasterIDs, List<int> SolutionIndex, FactCompa
if (SolutionIndex != null)
this.SolutionIndex = SolutionIndex;
if (RelationIndex != null)
this.RelationIndex = RelationIndex;
if (Comparer != null)
this.Comparer = Comparer;
}
......
......@@ -63,13 +63,13 @@ public Stage(string category, int number, string name, string description, strin
public Stage(Stage get, string category, int number, string name, string description, string scene, bool local = true)
{
InitOOP();
Stage cpy = new Stage();
// "DeepCopy" of ref-types, 'cause screw c# and ICloneable
load(ref cpy, get.name, null, get.use_install_folder);
this.hierarchie = cpy.hierarchie;
this.solution = cpy.solution;
this.player_record = cpy.player_record;
this.player_record_list = cpy.player_record_list;
InitFields(category, number, name, description, scene, local);
......@@ -80,11 +80,13 @@ public Stage(Stage get, string category, int number, string name, string descrip
player_record.name = player_record.name.Replace(get.record_name, record_name);
player_record.store(hierarchie, false);
foreach (var record in player_record_list.Values)
//this.player_record_list = cpy.player_record_list;
foreach (var record in cpy.player_record_list.Values)
{
record.load(hierarchie);
record.name = record.name.Replace(get.record_name, record_name);
record.store(hierarchie, false);
player_record_list.Add(record.name, record);
}
hierarchie.RemoveRange(hierarchie.Count - hierStage.Count, hierStage.Count);
......@@ -129,7 +131,7 @@ public void ClearPlay()
public void ClearALLRecords()
{
foreach (var record in player_record_list.Values)
foreach (var record in player_record_list.Values.ToList())
deletet_record(record, false);
player_record_list = new Dictionary<string, PlayerRecord>();
......@@ -175,8 +177,18 @@ public bool set_record(PlayerRecord record)
return true;
}
public void push_record(double seconds_s = -1)
public void push_record(double seconds_s = -1, bool force_push = false)
{
if(!force_push && StageStatic.devel && creatorMode)
// store solution space
{
SetMode(false);
store(false);
//push_record(seconds_s, false);
SetMode(true);
return;
}
hierarchie ??= new List<Directories>();
hierarchie.AddRange(hierStage.AsEnumerable());
......@@ -279,24 +291,14 @@ public static bool load(ref Stage set, string name, List<Directories> hierarchie
{
Stage ret = new Stage();
hierarchie ??= new List<Directories>();
hierarchie.AddRange(hierStage.AsEnumerable());
bool loadable = ShallowLoad(ref ret, name, hierarchie, use_install_folder);
if (!loadable)
{
hierarchie.RemoveRange(hierarchie.Count - hierStage.Count, hierStage.Count);
return false;
}
loadable = ret.DeepLoad();
if (!loadable)
{
hierarchie.RemoveRange(hierarchie.Count - hierStage.Count, hierStage.Count);
return false;
}
hierarchie.RemoveRange(hierarchie.Count - hierStage.Count, hierStage.Count);
set = ret;
return true;
}
......@@ -394,6 +396,7 @@ public void ResetSaves()
public bool CheckSolved()
{
double time_s = Time.timeSinceLevelLoadAsDouble;
bool solved =
factState.DynamiclySolved(solution, out _, out List<List<string>> hits);
......@@ -404,9 +407,10 @@ public bool CheckSolved()
if (solved && player_record.seconds > 0)
{
player_record.solved = solved;
player_record.solved = true;
push_record(time_s);
store(true); // reset player_record
player_record.solved = false;
}
return solved;
......
......@@ -52,9 +52,11 @@ public void Delete()
private bool _Clone(bool overwrite)
{
var error = StageStatic.Validate(category, id, name, description, scene);
if (overwrite && name == original_stage.name) {
error.name = false;
error.id = false;
if (overwrite) {
if(name == original_stage.name)
error.name = false;
if(id == original_stage.number)
error.id = false;
}
if (!error.pass) {
Error(error);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment