Skip to content

Commit

Permalink
also add typed default overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
NikkyAI committed Mar 21, 2021
1 parent c44f6f2 commit 8acf4a5
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions voodoo/src/main/kotlin/voodoo/pack/FileEntry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,18 @@ sealed class FileEntry {
}

fun <E : FileEntry> foldOverrides(overrides: Map<String, EntryOverride>): E {
var inititalEntry = this as E
val inititalEntry = this as E
val entryId = inititalEntry.id().takeUnless { it.isNullOrBlank() } ?: error("missing entry id for entry: ")
overrides[""]?.let { defaultOverride ->
inititalEntry = inititalEntry.applyOverride(defaultOverride) as E
val defaultEntryOverrides = listOf(
"", "@common", "@" + inititalEntry.typeKey()
).mapNotNull { key ->
overrides[key]
}
val entry = inititalEntry.applyOverrides.fold(inititalEntry) { acc: E, overrideId ->
val entryWithDefaultOverrides = defaultEntryOverrides.fold(inititalEntry) { e, entryOverride ->
e.applyOverride(entryOverride) as E
}

val entry = inititalEntry.applyOverrides.fold(entryWithDefaultOverrides) { acc: E, overrideId ->
val overrideKeys = listOf(
overrideId,
overrideId + "@common",
Expand Down

0 comments on commit 8acf4a5

Please sign in to comment.