-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor MapManager to render to a specific Window
Refs #73 Rather than defaulting to whatever window is current, it selects the "current" window on init (eg: createEmpty) and uses that forever unless another window is specified. If provided a non-primary Window, that window will be cleared before the map is rendered into it. Furthermore, we simplify the resize mechanics to match *the specific window* we're rendering into.
- Loading branch information
Showing
12 changed files
with
152 additions
and
45 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
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
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
80 changes: 80 additions & 0 deletions
80
core/src/test/kotlin/net/dhleong/judo/mapping/MapManagerTest.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,80 @@ | ||
package net.dhleong.judo.mapping | ||
|
||
import assertk.all | ||
import assertk.assert | ||
import net.dhleong.judo.IJudoCore | ||
import net.dhleong.judo.StateMap | ||
import net.dhleong.judo.TestableJudoCore | ||
import net.dhleong.judo.TestableJudoRenderer | ||
import net.dhleong.judo.bufferOf | ||
import net.dhleong.judo.doesNotHaveLine | ||
import net.dhleong.judo.hasSize | ||
import net.dhleong.judo.mapping.renderer.SimpleBufferMapRenderer | ||
import net.dhleong.judo.render.toFlavorable | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
/** | ||
* @author dhleong | ||
*/ | ||
class MapManagerTest { | ||
|
||
private lateinit var judo: IJudoCore | ||
private lateinit var mapper: IMapManager | ||
private lateinit var map: IJudoMap | ||
|
||
@Before fun setUp() { | ||
judo = TestableJudoCore(TestableJudoRenderer()) | ||
mapper = MapManager(judo, StateMap(), SimpleBufferMapRenderer()) | ||
|
||
mapper.createEmpty() | ||
map = mapper.current as JudoMap | ||
map.inRoom = 0 | ||
map.add(JudoRoom(0, "0")) | ||
} | ||
|
||
@Test fun `Render to primary window by default`() { | ||
val buffer = judo.renderer.currentTabpage.currentWindow.currentBuffer | ||
assert(buffer).hasSize(0) | ||
|
||
mapper.render() | ||
assert(buffer).hasSize(judo.renderer.windowHeight) | ||
} | ||
|
||
@Test fun `Don't clear the primary window`() { | ||
val buffer = judo.renderer.currentTabpage.currentWindow.currentBuffer | ||
buffer.appendLine("Test".toFlavorable()) | ||
assert(buffer).hasSize(1) | ||
|
||
mapper.render() | ||
assert(buffer).doesNotHaveLine("Test".toFlavorable()) | ||
} | ||
|
||
@Test fun `Render to and control provided window`() { | ||
val primaryWindow = judo.renderer.currentTabpage.currentWindow | ||
val primary = primaryWindow.currentBuffer | ||
assert(primary).hasSize(0) | ||
|
||
val buffer = bufferOf(""" | ||
You can't take | ||
The skies from me | ||
""".trimIndent()) | ||
val window = judo.tabpage.hsplit(10, buffer) | ||
assert(buffer).hasSize(2) | ||
|
||
// swap back to primary window | ||
judo.renderer.currentTabpage.currentWindow = primaryWindow | ||
|
||
mapper.window = window | ||
mapper.render() | ||
assert(buffer).all { | ||
// non-primary window's buffer gets cleared | ||
hasSize(9) | ||
doesNotHaveLine("You can't take".toFlavorable()) | ||
} | ||
|
||
// still nothing in the primary buffer | ||
assert(primary).hasSize(0) | ||
} | ||
} | ||
|
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
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