1- using System ;
2- using System . Collections ;
3- using System . Collections . Generic ;
1+ using System . Collections . Generic ;
2+ using System . Linq ;
43using UnityEngine ;
54using Random = UnityEngine . Random ;
65
@@ -28,13 +27,17 @@ private void Awake()
2827
2928 public void PopulateCell ( )
3029 {
31- // At the beginning every module is possible
30+ // at the beginning every module is possible
3231 for ( var i = 0 ; i < levelGenerator . modules . Count ; i ++ )
3332 {
3433 possibleModules . Add ( levelGenerator . modules [ i ] ) ;
3534 }
3635 }
3736
37+ /// <summary>
38+ /// Applies an <see cref="EdgeFilter"/> to this cell.
39+ /// </summary>
40+ /// <param name="filter">The filter to apply.</param>
3841 public void FilterCell ( EdgeFilter filter )
3942 {
4043 if ( possibleModules . Count == 1 ) return ;
@@ -97,6 +100,7 @@ public void RemoveModule(Module module)
97100 }
98101 }
99102
103+
100104 public void SetModule ( Module module )
101105 {
102106 possibleModules = new List < Module > { module } ;
@@ -121,8 +125,27 @@ public void SetModule(Module module)
121125 if ( neighbours [ i ] == null ) continue ;
122126
123127 // Populate edge changes to neighbour cell
124- var edgeFilter = new EdgeFilter ( i , module . edgeConnections [ i ] , true ) ;
125- neighbours [ i ] . FilterCell ( edgeFilter ) ;
128+ neighbours [ i ] . FilterCell ( new EdgeFilter ( i , module . edgeConnections [ i ] , true ) ) ;
129+ }
130+
131+ Instantiate ( module . moduleGO , transform . position , Quaternion . identity , transform ) ;
132+
133+ isCellSet = true ;
134+ }
135+
136+ public void ForceSetModule ( Module module )
137+ {
138+ possibleModules = new List < Module > { module } ;
139+
140+ // check if it fits to already set neighbour cells
141+ for ( var i = 0 ; i < neighbours . Length ; i ++ )
142+ {
143+ if ( neighbours [ i ] == null || ! neighbours [ i ] . isCellSet ) continue ;
144+
145+ if ( module . edgeConnections [ i ] != neighbours [ i ] . possibleModules [ 0 ] . edgeConnections [ ( i + 2 ) % 4 ] )
146+ Debug . LogError (
147+ $ "Setting module { module } would not fit already set neighbour { neighbours [ i ] . gameObject } !",
148+ gameObject ) ;
126149 }
127150
128151 Instantiate ( module . moduleGO , transform . position , Quaternion . identity , transform ) ;
@@ -131,10 +154,11 @@ public void SetModule(Module module)
131154 }
132155
133156 /// <summary>
134- /// Compares two cells using their solved score
157+ /// Compares two cells using their solved score.
158+ /// TODO: Refactor
135159 /// </summary>
136160 /// <param name="other">Cell to compare</param>
137- /// <returns></returns>
161+ /// <returns>Comparison value </returns>
138162 public int CompareTo ( Cell other )
139163 {
140164 var compare = possibleModules . Count . CompareTo ( other . possibleModules . Count ) ;
0 commit comments