Skip to content

Commit f0705ae

Browse files
committed
move config editor functions out of, and remove, the ConfigEditor object for easy imports and one less object. Also likewise for the BuildSimulator
1 parent 8d8b37d commit f0705ae

61 files changed

Lines changed: 501 additions & 512 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/kotlin/com/lambda/config/ConfigEditor.kt

Lines changed: 176 additions & 178 deletions
Large diffs are not rendered by default.

src/main/kotlin/com/lambda/config/automation/UserAutomationConfig.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
package com.lambda.config.automation
1919

2020
import com.lambda.config.categories.UserAutomationCategory
21-
import com.lambda.config.settings.collections.CollectionSetting.Companion.onDeselect
22-
import com.lambda.config.settings.collections.CollectionSetting.Companion.onSelect
21+
import com.lambda.config.settings.collections.onDeselect
22+
import com.lambda.config.settings.collections.onSelect
2323
import com.lambda.module.Module
2424
import com.lambda.module.ModuleRegistry.moduleNameMap
2525

src/main/kotlin/com/lambda/config/blocks/BreakSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package com.lambda.config.blocks
1919

2020
import com.lambda.config.Config
2121
import com.lambda.config.ConfigBlock
22-
import com.lambda.config.ConfigEditor.hide
2322
import com.lambda.config.Group
2423
import com.lambda.config.blocks.ActionConfig.SortMode
2524
import com.lambda.config.blocks.BreakConfig.AnimationMode
@@ -29,6 +28,7 @@ import com.lambda.config.blocks.BreakConfig.SwapMode
2928
import com.lambda.config.blocks.BreakConfig.SwingMode
3029
import com.lambda.config.blocks.BreakConfig.WhitelistMode
3130
import com.lambda.config.blocks.BuildConfig.SwingType
31+
import com.lambda.config.hide
3232
import com.lambda.config.withEdits
3333
import com.lambda.event.events.TickEvent
3434
import com.lambda.event.events.TickEvent.Companion.ALL_STAGES

src/main/kotlin/com/lambda/config/blocks/TargetingSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package com.lambda.config.blocks
1919

2020
import com.lambda.config.Config
2121
import com.lambda.config.ConfigBlock
22-
import com.lambda.config.ConfigEditor.hide
22+
import com.lambda.config.hide
2323
import com.lambda.config.withEdits
2424
import com.lambda.context.SafeContext
2525
import com.lambda.interaction.handlers.FriendHandler.isFriend

src/main/kotlin/com/lambda/config/settings/NumericSetting.kt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
package com.lambda.config.settings
1919

2020
import com.lambda.config.Config
21-
import com.lambda.config.ConfigEditor
2221
import com.lambda.config.ConfigEditorD5l
22+
import com.lambda.config.SettingEditBuilder
2323
import com.lambda.config.entries.Setting
2424
import com.lambda.config.entries.SettingEntryLayer
2525
import com.lambda.gui.dsl.ImGuiBuilder
@@ -94,22 +94,22 @@ abstract class NumericSetting<T>(
9494
dummy(calcTextSize(resetButtonText).x + style.framePadding.x * 2.0f, ImGui.getFrameHeight())
9595
}
9696
}
97+
}
9798

98-
@Suppress("unchecked_cast", "unused")
99-
companion object {
100-
@ConfigEditorD5l
101-
fun <T> ConfigEditor.SettingEditBuilder<T>.range(range: ClosedRange<T>) where T : Number, T : Comparable<T> {
102-
(entries as Collection<NumericSetting<T>>).forEach { it.range = range }
103-
}
99+
@Suppress("unchecked_cast")
100+
@ConfigEditorD5l
101+
fun <T> SettingEditBuilder<T>.range(range: ClosedRange<T>) where T : Number, T : Comparable<T> {
102+
(entries as Collection<NumericSetting<T>>).forEach { it.range = range }
103+
}
104104

105-
@ConfigEditorD5l
106-
fun <T> ConfigEditor.SettingEditBuilder<T>.step(step: T) where T : Number, T : Comparable<T> {
107-
(entries as Collection<NumericSetting<T>>).forEach { it.step = step }
108-
}
105+
@Suppress("unchecked_cast")
106+
@ConfigEditorD5l
107+
fun <T> SettingEditBuilder<T>.step(step: T) where T : Number, T : Comparable<T> {
108+
(entries as Collection<NumericSetting<T>>).forEach { it.step = step }
109+
}
109110

110-
@ConfigEditorD5l
111-
fun <T> ConfigEditor.SettingEditBuilder<T>.unit(unit: String) where T : Number, T : Comparable<T> {
112-
(entries as Collection<NumericSetting<T>>).forEach { it.unit = unit }
113-
}
114-
}
111+
@Suppress("unchecked_cast")
112+
@ConfigEditorD5l
113+
fun <T> SettingEditBuilder<T>.unit(unit: String) where T : Number, T : Comparable<T> {
114+
(entries as Collection<NumericSetting<T>>).forEach { it.unit = unit }
115115
}

src/main/kotlin/com/lambda/config/settings/StringSetting.kt

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import com.lambda.brigadier.argument.value
2222
import com.lambda.brigadier.execute
2323
import com.lambda.brigadier.required
2424
import com.lambda.config.Config
25-
import com.lambda.config.ConfigEditor
2625
import com.lambda.config.ConfigEditorD5l
26+
import com.lambda.config.SettingEditBuilder
2727
import com.lambda.config.entries.Setting
2828
import com.lambda.config.entries.SettingEntryLayer
2929
import com.lambda.gui.dsl.ImGuiBuilder
@@ -61,17 +61,16 @@ class StringSetting(
6161
}
6262
}
6363
}
64+
}
6465

65-
@Suppress("unused", "unchecked_cast")
66-
companion object {
67-
@ConfigEditorD5l
68-
fun ConfigEditor.SettingEditBuilder<String>.multiline(multiline: Boolean) {
69-
(entries as Collection<StringSetting>).forEach { it.multiline = multiline }
70-
}
66+
@Suppress("unchecked_cast")
67+
@ConfigEditorD5l
68+
fun SettingEditBuilder<String>.multiline(multiline: Boolean) {
69+
(entries as Collection<StringSetting>).forEach { it.multiline = multiline }
70+
}
7171

72-
@ConfigEditorD5l
73-
fun ConfigEditor.SettingEditBuilder<String>.flags(flags: Int) {
74-
(entries as Collection<StringSetting>).forEach { it.flags = flags }
75-
}
76-
}
77-
}
72+
@Suppress("unchecked_cast")
73+
@ConfigEditorD5l
74+
fun SettingEditBuilder<String>.flags(flags: Int) {
75+
(entries as Collection<StringSetting>).forEach { it.flags = flags }
76+
}

src/main/kotlin/com/lambda/config/settings/collections/CollectionSetting.kt

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
package com.lambda.config.settings.collections
1919

2020
import com.lambda.config.Config
21-
import com.lambda.config.ConfigEditor
2221
import com.lambda.config.ConfigEditorD5l
22+
import com.lambda.config.SettingEditBuilder
2323
import com.lambda.config.entries.ConfigEntryDsl
2424
import com.lambda.config.entries.Setting
2525
import com.lambda.config.entries.SettingEntryLayer
@@ -174,32 +174,29 @@ open class CollectionSetting<R : Any>(
174174
}
175175
}
176176
}
177-
178-
@Suppress("unused")
179-
companion object {
180-
@ConfigEntryDsl
181-
fun <T : CollectionSetting<R>, R : Any> T.onSelect(block: SafeContext.(R) -> Unit) =
182-
apply { selectListeners.add(block) }
183-
184-
@ConfigEntryDsl
185-
fun <T : CollectionSetting<R>, R : Any> T.onSelectUnsafe(block: (R) -> Unit) =
186-
apply { unsafeSelectListeners.add(block) }
187-
188-
@ConfigEntryDsl
189-
fun <T : CollectionSetting<R>, R : Any> T.onDeselect(block: SafeContext.(R) -> Unit) =
190-
apply { deselectListeners.add(block) }
191-
192-
@ConfigEntryDsl
193-
fun <T : CollectionSetting<R>, R : Any> T.onDeselectUnsafe(block: (R) -> Unit) =
194-
apply { unsafeDeselectListeners.add(block) }
195-
196-
@Suppress("unchecked_cast")
197-
@ConfigEditorD5l
198-
fun <T : Any> ConfigEditor.SettingEditBuilder<Collection<T>>.immutableCollection(collection: Collection<T>) {
199-
(entries as Collection<CollectionSetting<T>>).forEach {
200-
it.value.retainAll(collection.toSet())
201-
it.immutableCollection = collection
202-
}
203-
}
177+
}
178+
179+
@ConfigEntryDsl
180+
fun <T : CollectionSetting<R>, R : Any> T.onSelect(block: SafeContext.(R) -> Unit) =
181+
apply { selectListeners.add(block) }
182+
183+
@ConfigEntryDsl
184+
fun <T : CollectionSetting<R>, R : Any> T.onSelectUnsafe(block: (R) -> Unit) =
185+
apply { unsafeSelectListeners.add(block) }
186+
187+
@ConfigEntryDsl
188+
fun <T : CollectionSetting<R>, R : Any> T.onDeselect(block: SafeContext.(R) -> Unit) =
189+
apply { deselectListeners.add(block) }
190+
191+
@ConfigEntryDsl
192+
fun <T : CollectionSetting<R>, R : Any> T.onDeselectUnsafe(block: (R) -> Unit) =
193+
apply { unsafeDeselectListeners.add(block) }
194+
195+
@Suppress("unchecked_cast")
196+
@ConfigEditorD5l
197+
fun <T : Any> SettingEditBuilder<Collection<T>>.immutableCollection(collection: Collection<T>) {
198+
(entries as Collection<CollectionSetting<T>>).forEach {
199+
it.value.retainAll(collection.toSet())
200+
it.immutableCollection = collection
204201
}
205202
}

src/main/kotlin/com/lambda/config/settings/comparable/EnumSetting.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ class EnumSetting<T : Enum<T>>(
7676
}
7777
}
7878

79-
companion object {
80-
val <T : Enum<T>> T.enumValues: Array<T> get() =
81-
declaringJavaClass.enumConstants
82-
}
79+
private val <T : Enum<T>> T.enumValues: Array<T>
80+
get() = declaringJavaClass.enumConstants
8381
}

src/main/kotlin/com/lambda/interaction/construction/simulation/checks/BasicChecker.kt renamed to src/main/kotlin/com/lambda/interaction/construction/simulation/BasicChecker.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,10 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
package com.lambda.interaction.construction.simulation.checks
18+
package com.lambda.interaction.construction.simulation
1919

20-
import com.lambda.config.blocks.BreakConfig.WhitelistMode
20+
import com.lambda.config.blocks.BreakConfig
2121
import com.lambda.context.AutomatedSafeContext
22-
import com.lambda.interaction.construction.simulation.BreakSimInfo
23-
import com.lambda.interaction.construction.simulation.Results
24-
import com.lambda.interaction.construction.simulation.SimDsl
25-
import com.lambda.interaction.construction.simulation.SimInfo
2622
import com.lambda.interaction.construction.simulation.result.results.GenericResult
2723
import com.lambda.interaction.construction.simulation.result.results.PreSimResult
2824
import com.lambda.util.player.PlayerUtils.gamemode
@@ -51,8 +47,8 @@ object BasicChecker : Results<PreSimResult> {
5147
// block should be ignored
5248
if (this@hasBasicRequirements is BreakSimInfo) {
5349
val mode = breakConfig.whitelistMode
54-
if ((mode == WhitelistMode.Whitelist && state.block !in breakConfig.whitelist) ||
55-
(mode == WhitelistMode.Blacklist && state.block in breakConfig.blacklist)
50+
if ((mode == BreakConfig.WhitelistMode.Whitelist && state.block !in breakConfig.whitelist) ||
51+
(mode == BreakConfig.WhitelistMode.Blacklist && state.block in breakConfig.blacklist)
5652
) {
5753
result(GenericResult.Ignored(pos))
5854
return false

src/main/kotlin/com/lambda/interaction/construction/simulation/BuildSimulator.kt

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
package com.lambda.interaction.construction.simulation
1919

2020
import com.lambda.context.AutomatedSafeContext
21-
import com.lambda.interaction.construction.simulation.SimInfo.Companion.sim
22-
import com.lambda.interaction.construction.simulation.checks.BreakSim.Companion.simBreak
23-
import com.lambda.interaction.construction.simulation.checks.InteractSim.Companion.simInteraction
2421
import com.lambda.interaction.construction.simulation.result.BuildResult
2522
import com.lambda.interaction.construction.simulation.result.results.PostSimResult
23+
import com.lambda.interaction.construction.simulation.sims.simBreak
24+
import com.lambda.interaction.construction.simulation.sims.simInteraction
2625
import com.lambda.util.BlockUtils.blockState
2726
import com.lambda.util.extension.Structure
2827
import io.ktor.util.collections.*
@@ -32,38 +31,55 @@ import kotlinx.coroutines.runBlocking
3231
import kotlinx.coroutines.supervisorScope
3332
import net.minecraft.util.math.Vec3d
3433

35-
object BuildSimulator : Sim<PostSimResult>() {
36-
/**
37-
* Iterates over the blueprint and performs the best suited simulation. Each simulation adds [BuildResult]s to
38-
* the provided concurrent set. This method uses coroutines to perform the simulations in parallel. The results
39-
* will likely not be returned in the same order they were simulated due to the parallel nature of the simulations.
40-
*
41-
* @see SimInfo.sim
42-
* @see simInteraction
43-
* @see simBreak
44-
*/
45-
context(automatedSafeContext: AutomatedSafeContext)
46-
fun Structure.simulate(
47-
pov: Vec3d = automatedSafeContext.player.eyePos
48-
): Set<BuildResult> = runBlocking(Dispatchers.Default) {
34+
/**
35+
* Iterates over the blueprint and performs the best suited simulation. Each simulation adds [BuildResult]s to
36+
* the provided concurrent set. This method uses coroutines to perform the simulations in parallel. The results
37+
* will likely not be returned in the same order they were simulated due to the parallel nature of the simulations.
38+
*
39+
* @see SimInfo.sim
40+
* @see simInteraction
41+
* @see simBreak
42+
*/
43+
@SimDsl
44+
context(automatedSafeContext: AutomatedSafeContext)
45+
fun Structure.sim(
46+
pov: Vec3d = automatedSafeContext.player.eyePos
47+
) = BuildSimulator.sim(this, pov)
48+
49+
class BuildSimulator private constructor(
50+
private val structure: Structure,
51+
private val pov: Vec3d,
52+
private val resultsCollection: MutableSet<BuildResult>
53+
) : Sim<PostSimResult>() {
54+
override suspend fun AutomatedSafeContext.sim() {
4955
supervisorScope {
50-
val concurrentSet = ConcurrentSet<BuildResult>()
56+
structure.forEach { (pos, targetState) ->
57+
launch {
58+
sim(
59+
pos,
60+
blockState(pos),
61+
targetState,
62+
pov,
63+
resultsCollection
64+
)
65+
}
66+
}
67+
}
68+
}
5169

70+
companion object {
71+
@SimDsl
72+
context(automatedSafeContext: AutomatedSafeContext)
73+
internal fun sim(
74+
structure: Structure,
75+
pov: Vec3d = automatedSafeContext.player.eyePos
76+
): Set<BuildResult> =
5277
with(automatedSafeContext) {
53-
forEach { (pos, targetState) ->
54-
launch {
55-
sim(
56-
pos,
57-
blockState(pos),
58-
targetState,
59-
pov,
60-
concurrentSet
61-
)
62-
}
78+
runBlocking(Dispatchers.Default) {
79+
val results = ConcurrentSet<BuildResult>()
80+
with(BuildSimulator(structure, pov, results)) { sim() }
81+
results
6382
}
6483
}
65-
66-
concurrentSet
67-
}
6884
}
6985
}

0 commit comments

Comments
 (0)