#Statistic tracker

1 messages · Page 1 of 1 (latest)

brittle acorn
#

Making a little statistic tracking system for my game instances, what would be the best way to store/track them? I was just gonna roll with something like this for the statistic itself: ```kt
public fun interface TrackableStatistic<G : GameInstance<G>, T> {
public fun get(instance: G, player: UUID): T
}

ruby oriole
#

oj

#

oh

#

not the kotlin

#

😭

#

i cant help with kotlin sorry 😔

brittle acorn
#

dude there's barely any difference to java in this case

#

ffs

#

I guess I'll have like ```kt
public data class StatisticValue<T>(public var value: T)

public interface TrackableStatistic<G : GameInstance<G>, T> {
public val key: Key

public fun getStatisticValue(instance: G, player: UUID): StatisticValue<T>
public operator fun get(instance: G, player: UUID): T = getStatisticValue(instance, player).value

}

public class StatisticTracker {
private val data: MutableMap<UUID, MutableMap<Key, StatisticValue<*>>> = mutableMapOf()
}

#

Actually the statistic itself shouldn't have a getter thingy

brittle acorn
#
@Test
public fun test() {
    val ctx = GameContext(UUID.randomUUID(), GameTypes.SIMPLE_TEST, Audience.empty(), List(5) { UUID.randomUUID() })
    val instance = SimpleTestGameInstance(GameTypes.SIMPLE_TEST, ctx, 0)
    instance.statisticTracker.load(DefaultStatistics)

    val players = ctx.playerList
    players.forEach { player ->
        assertEquals(0, instance.statisticTracker[DefaultStatistics.ELIMINATIONS, player])

        instance.statisticTracker.increment(DefaultStatistics.ELIMINATIONS, player)

        assertEquals(1, instance.statisticTracker[DefaultStatistics.ELIMINATIONS, player])
    }
}
#

it worky

solid plinth
#

um akchutually thats not a proper test method name

brittle acorn
#

i'll changei t just for you

solid plinth
#

is it test_ebic_fuck_off_gamething now