From bfb98786729afd0fd043d42e18dfd0eb5d5807a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 23 May 2016 16:11:03 +0200 Subject: add PlayerRecord --- .../ch/asynk/rustanddust/util/PlayerRecord.java | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 core/src/ch/asynk/rustanddust/util/PlayerRecord.java diff --git a/core/src/ch/asynk/rustanddust/util/PlayerRecord.java b/core/src/ch/asynk/rustanddust/util/PlayerRecord.java new file mode 100644 index 0000000..efd12de --- /dev/null +++ b/core/src/ch/asynk/rustanddust/util/PlayerRecord.java @@ -0,0 +1,85 @@ +package ch.asynk.rustanddust.util; + +import com.badlogic.gdx.utils.Pool; +import com.badlogic.gdx.utils.Disposable; + +import ch.asynk.rustanddust.ui.List; +import ch.asynk.rustanddust.engine.util.Collection; +import ch.asynk.rustanddust.engine.util.IterableArray; + +public class PlayerRecord implements List.ListElement, Disposable, Pool.Poolable +{ + public int id; + public String name; + public String email; + public String hash; + public String s; + + public static Collection list = new IterableArray(10); + + private static final Pool gameRecordPool = new Pool() + { + @Override + protected PlayerRecord newObject() { + return new PlayerRecord(); + } + }; + + public static void clearPool() + { + gameRecordPool.clear(); + } + + public static PlayerRecord get() + { + PlayerRecord r = gameRecordPool.obtain(); + return r; + } + + public static PlayerRecord get(int idx) + { + return (PlayerRecord) list.get(idx); + } + + public static PlayerRecord remove(int idx) + { + return (PlayerRecord) list.remove(idx); + } + + public static void clearList() + { + for(List.ListElement r : list) + ((PlayerRecord) r).dispose(); + list.clear(); + } + + public PlayerRecord() + { + } + + @Override + public void reset() + { + this.s = null; + } + + @Override + public void dispose() + { + gameRecordPool.free(this); + } + + @Override + public String s() + { + if (s == null) { + s = String.format("%s - %s", name , (hasEmail() ? "OK" : "-")); + } + return s; + } + + public boolean hasEmail() + { + return (this.email != null && !this.email.isEmpty()); + } +} -- cgit v1.1-2-g2b99