From 28a219d5cdfcc81af8532a581b5e74d66d00d6d3 Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Wed, 2 Sep 2020 01:29:24 -0700 Subject: [PATCH] Added support within StatListBuilder to retrieve previously put stat --- .../riiablo/attributes/StatListBuilder.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/core/src/com/riiablo/attributes/StatListBuilder.java b/core/src/com/riiablo/attributes/StatListBuilder.java index d885b113..e2ab31c9 100644 --- a/core/src/com/riiablo/attributes/StatListBuilder.java +++ b/core/src/com/riiablo/attributes/StatListBuilder.java @@ -3,10 +3,14 @@ package com.riiablo.attributes; public final class StatListBuilder { final StatList stats; final int list; + final StatGetter tuple; + int index; StatListBuilder(StatList stats, int list) { this.stats = stats; this.list = list; + this.tuple = new StatGetter(stats); + this.index = -1; } /** @@ -21,27 +25,33 @@ public final class StatListBuilder { return stats.get(list); } + /** @see StatList#get(int) */ + public StatGetter last() { + if (index < 0) throw new IllegalStateException("cannot retrieve last stat when no stats have been added yet!"); + return tuple.update(index); + } + /** @see StatList#put(int, short, int, int) */ public StatListBuilder put(short stat, int param, int value) { - stats.put(list, stat, param, value); + index = stats.put(list, stat, param, value); return this; } /** @see StatList#put(int, short, int) */ public StatListBuilder put(short stat, int value) { - stats.put(list, stat, value); + index = stats.put(list, stat, value); return this; } /** @see StatList#put(int, short, long) */ public StatListBuilder put(short stat, long value) { - stats.put(list, stat, value); + index = stats.put(list, stat, value); return this; } /** @see StatList#put(int, short, float) */ public StatListBuilder put(short stat, float value) { - stats.put(list, stat, value); + index = stats.put(list, stat, value); return this; } }