RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.util.parser.impl.StoreParser Class Reference

Parses throug the shops files and creates in-game shop object for the game on startup. More...

Inheritance diagram for com.runehive.util.parser.impl.StoreParser:
Collaboration diagram for com.runehive.util.parser.impl.StoreParser:

Classes

class  LoadedItem

Public Member Functions

 StoreParser ()
Public Member Functions inherited from com.runehive.util.parser.GsonParser
final void deserialize ()
 The method that deserializes the file information.
 GsonParser (String path)
 Creates a new GsonParser.
 GsonParser (String path, boolean log)
 Creates a new GsonParser.
void initialize (int size)
Public Member Functions inherited from com.runehive.util.parser.GenericParser
 GenericParser (String path, String extension, boolean log)
 Creates a new GenericParser.
final int getIndex ()
 Gets the current index of the line being parsed.
void onRead ()
 The method called after all the data has been parsed.
void run ()
String toString ()

Protected Member Functions

void parse (JsonObject data)
 The method allows a user to modify the data as its being parsed.
Protected Member Functions inherited from com.runehive.util.parser.GsonParser
void onEnd ()
 This method handles what happens after the parser has ended.

Additional Inherited Members

Protected Attributes inherited from com.runehive.util.parser.GsonParser
transient Gson builder
 The Gson object.
Protected Attributes inherited from com.runehive.util.parser.GenericParser
int index
 The index of the current line being parsed.
final Path path
 The path of the file to parse.

Detailed Description

Parses throug the shops files and creates in-game shop object for the game on startup.

Author
Daniel | Obey

Definition at line 23 of file StoreParser.java.

Constructor & Destructor Documentation

◆ StoreParser()

com.runehive.util.parser.impl.StoreParser.StoreParser ( )

Definition at line 25 of file StoreParser.java.

25 {
26 super("def/store/stores", false);
27 }

Member Function Documentation

◆ parse()

void com.runehive.util.parser.impl.StoreParser.parse ( JsonObject data)
protected

The method allows a user to modify the data as its being parsed.

Parameters
dataThe JsonObject that contains all serialized information.

Reimplemented from com.runehive.util.parser.GsonParser.

Definition at line 30 of file StoreParser.java.

30 {
31 final String name = Objects.requireNonNull(data.get("name").getAsString());
32 final CurrencyType currency = builder.fromJson(data.get("currency"), CurrencyType.class);
33 final boolean restock = data.get("restock").getAsBoolean();
34 final String sellType = data.get("sellType").getAsString().toUpperCase();
35 final LoadedItem[] loadedItems = builder.fromJson(data.get("items"), LoadedItem[].class);
36
37 final List<StoreItem> storeItems = new ArrayList<>(loadedItems.length);
38
39 for(LoadedItem loadedItem : loadedItems) {
40 if (loadedItem.value == 0) {
41 loadedItem.value = -1;
42 }
43 storeItems.add(new StoreItem(loadedItem.id, loadedItem.amount, OptionalInt.of(loadedItem.value), Optional.ofNullable(loadedItem.type)));
44 }
45
46 StoreItem[] items = storeItems.toArray(new StoreItem[storeItems.size()]);
47 Store.STORES.put(name, new DefaultStore(items, name, SellType.valueOf(sellType), restock, currency));
48 }

References com.runehive.util.parser.GsonParser.builder, and com.runehive.content.store.Store.STORES.


The documentation for this class was generated from the following file: