RuneHive-Game
Loading...
Searching...
No Matches
GlobalObjectParser.java
Go to the documentation of this file.
1package com.runehive.util.parser.impl;
2
3import com.google.gson.JsonObject;
4import com.runehive.game.world.object.ObjectType;
5import com.runehive.game.world.position.Position;
6import com.runehive.game.world.object.CustomGameObject;
7import com.runehive.game.world.object.ObjectDirection;
8import com.runehive.util.parser.GsonParser;
9
10/**
11 * The class that loads all global object on startup.
12 *
13 * @author Daniel
14 */
15public class GlobalObjectParser extends GsonParser {
16
18 super("def/object/global_objects", false);
19 }
20
21 @Override
22 protected void parse(JsonObject data) {
23 int id = data.get("id").getAsInt();
24 ObjectType type = ObjectType.valueOf(data.get("type").getAsInt()).orElseThrow(IllegalArgumentException::new);
25 ObjectDirection rotation = ObjectDirection.valueOf(data.get("rotation").getAsString());
26 Position position = builder.fromJson(data.get("position"), Position.class);
27 new CustomGameObject(id, position, rotation, type).register();
28 }
29}
Represents a static game object loaded from the map fs.
void register()
Registers an entity to the World.
Represents a single tile on the game world.
Definition Position.java:14
GsonParser(String path)
Creates a new GsonParser.
transient Gson builder
The Gson object.
void parse(JsonObject data)
The method allows a user to modify the data as its being parsed.
The enumerated type whose elements represent the directions for objects.
static Optional< ObjectDirection > valueOf(final int id)
Returns a ObjectDirection wrapped in an Optional for the specified id.
The enumerated type whose elements represent all of the object types.
static Optional< ObjectType > valueOf(final int id)
Returns a ObjectType wrapped in an Optional for the specified id.