forked from Hexworks/zircon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Hexworks#403 from Hexworks/augment-application
Augment application
- Loading branch information
Showing
133 changed files
with
1,799 additions
and
1,554 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
zircon.core/src/commonMain/kotlin/org/hexworks/zircon/api/application/ModifierSupport.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.hexworks.zircon.api.application | ||
|
||
import org.hexworks.zircon.api.builder.application.ModifierSupportBuilder | ||
import org.hexworks.zircon.api.builder.application.ShortcutsConfigBuilder | ||
import org.hexworks.zircon.api.data.Tile | ||
import org.hexworks.zircon.api.modifier.TextureTransformModifier | ||
import org.hexworks.zircon.api.tileset.TextureTransformer | ||
import org.hexworks.zircon.api.tileset.TileTexture | ||
import org.hexworks.zircon.api.uievent.KeyCode | ||
import org.hexworks.zircon.api.uievent.KeyboardEventMatcher | ||
import org.hexworks.zircon.api.uievent.KeyboardEventType | ||
import kotlin.jvm.JvmStatic | ||
import kotlin.reflect.KClass | ||
|
||
/** | ||
* Contains all the necessary data / functionality to support drawing a specific [modifierType]. | ||
*/ | ||
class ModifierSupport<T : Any> internal constructor( | ||
val modifierType: KClass<out TextureTransformModifier>, | ||
val targetType: KClass<T>, | ||
val transformer: TextureTransformer<T> | ||
) { | ||
companion object { | ||
|
||
@JvmStatic | ||
fun <T: Any> newBuilder() = ModifierSupportBuilder.newBuilder<T>() | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
zircon.core/src/commonMain/kotlin/org/hexworks/zircon/api/application/NoOpApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.hexworks.zircon.api.application | ||
|
||
import org.hexworks.cobalt.core.behavior.DisposeState | ||
import org.hexworks.cobalt.core.behavior.DisposedByHand | ||
import org.hexworks.cobalt.events.api.EventBus | ||
import org.hexworks.cobalt.events.api.Subscription | ||
import org.hexworks.zircon.api.grid.TileGrid | ||
import org.hexworks.zircon.internal.application.InternalApplication | ||
import org.hexworks.zircon.internal.event.ZirconScope | ||
|
||
/** | ||
* Use this class when you don't want to have an application implementation, and | ||
* you're using just a Renderer | ||
*/ | ||
class NoOpApplication( | ||
override val config: AppConfig, | ||
override val eventBus: EventBus, | ||
override val eventScope: ZirconScope | ||
) : InternalApplication { | ||
|
||
override lateinit var tileGrid: TileGrid | ||
|
||
override fun start() {} | ||
|
||
override fun pause() {} | ||
|
||
override fun resume() {} | ||
|
||
override fun stop() {} | ||
|
||
override fun beforeRender(listener: (RenderData) -> Unit) = NoOpSubscription | ||
|
||
override fun afterRender(listener: (RenderData) -> Unit) = NoOpSubscription | ||
|
||
override fun asInternal() = this | ||
|
||
object NoOpSubscription : Subscription { | ||
override val disposeState: DisposeState = DisposedByHand | ||
|
||
override fun dispose(disposeState: DisposeState) {} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...c/commonMain/kotlin/org/hexworks/zircon/api/builder/application/ModifierSupportBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.hexworks.zircon.api.builder.application | ||
|
||
import org.hexworks.zircon.api.application.ModifierSupport | ||
import org.hexworks.zircon.api.builder.Builder | ||
import org.hexworks.zircon.api.data.Tile | ||
import org.hexworks.zircon.api.modifier.TextureTransformModifier | ||
import org.hexworks.zircon.api.tileset.TextureTransformer | ||
import org.hexworks.zircon.api.tileset.TileTexture | ||
import org.hexworks.zircon.internal.dsl.ZirconDsl | ||
import org.hexworks.zircon.internal.tileset.impl.DefaultTextureTransformer | ||
import kotlin.reflect.KClass | ||
import kotlin.jvm.JvmStatic | ||
|
||
@ZirconDsl | ||
class ModifierSupportBuilder<T : Any> private constructor( | ||
var modifierType: KClass<out TextureTransformModifier>? = null, | ||
var targetType: KClass<T>? = null, | ||
var transformerFunction: ((texture: TileTexture<T>, tile: Tile) -> TileTexture<T>)? = null, | ||
var transformer: TextureTransformer<T>? = null | ||
) : Builder<ModifierSupport<T>> { | ||
|
||
override fun createCopy() = ModifierSupportBuilder( | ||
modifierType = modifierType, | ||
targetType = targetType, | ||
transformerFunction = transformerFunction | ||
) | ||
|
||
override fun build(): ModifierSupport<T> { | ||
requireNotNull(targetType) { | ||
"Target type is missing." | ||
} | ||
requireNotNull(modifierType) { | ||
"Modifier type is missing" | ||
} | ||
require(transformerFunction != null || transformer != null) { | ||
"Transformer is missing." | ||
} | ||
return ModifierSupport( | ||
modifierType = modifierType!!, | ||
targetType = targetType!!, | ||
transformer = transformer ?: DefaultTextureTransformer(targetType!!, transformerFunction!!) | ||
) | ||
} | ||
|
||
companion object { | ||
|
||
@JvmStatic | ||
fun <T : Any> newBuilder() = ModifierSupportBuilder<T>() | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...rc/commonMain/kotlin/org/hexworks/zircon/api/builder/application/TilesetFactoryBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.hexworks.zircon.api.builder.application | ||
|
||
import org.hexworks.zircon.api.builder.Builder | ||
import org.hexworks.zircon.api.resource.TilesetResource | ||
import org.hexworks.zircon.api.tileset.Tileset | ||
import org.hexworks.zircon.api.tileset.TilesetFactory | ||
import org.hexworks.zircon.internal.dsl.ZirconDsl | ||
import org.hexworks.zircon.internal.resource.TileType | ||
import org.hexworks.zircon.internal.resource.TilesetType | ||
import org.hexworks.zircon.internal.tileset.impl.DefaultTilesetFactory | ||
import kotlin.reflect.KClass | ||
import kotlin.jvm.JvmStatic | ||
|
||
@ZirconDsl | ||
class TilesetFactoryBuilder<S : Any> private constructor( | ||
var targetType: KClass<S>? = null, | ||
var supportedTileType: TileType? = null, | ||
var supportedTilesetType: TilesetType? = null, | ||
var factoryFunction: ((TilesetResource) -> Tileset<S>)? = null | ||
|
||
) : Builder<TilesetFactory<S>> { | ||
|
||
override fun createCopy() = TilesetFactoryBuilder( | ||
targetType = targetType, | ||
supportedTileType = supportedTileType, | ||
supportedTilesetType = supportedTilesetType, | ||
factoryFunction = factoryFunction | ||
) | ||
|
||
override fun build(): TilesetFactory<S> { | ||
requireNotNull(targetType) { | ||
"Target type is missing." | ||
} | ||
requireNotNull(supportedTileType) { | ||
"Supported tile type is missing." | ||
} | ||
requireNotNull(supportedTilesetType) { | ||
"Supported tileset type is missing." | ||
} | ||
requireNotNull(factoryFunction) { | ||
"Factory function is missing" | ||
} | ||
return DefaultTilesetFactory( | ||
targetType = targetType!!, | ||
supportedTileType = supportedTileType!!, | ||
supportedTilesetType = supportedTilesetType!!, | ||
factoryFunction = factoryFunction!! | ||
) | ||
} | ||
|
||
companion object { | ||
|
||
@JvmStatic | ||
fun <S : Any> newBuilder() = TilesetFactoryBuilder<S>() | ||
|
||
} | ||
} |
Oops, something went wrong.