-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
59 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 5 additions & 22 deletions
27
src/main/scala/hexacraft/world/entity/EntityModelLoader.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,16 @@ | ||
package hexacraft.world.entity | ||
|
||
import hexacraft.infra.fs.FileUtils | ||
import hexacraft.world.block.HexBox | ||
import hexacraft.world.coord.fp.CylCoords | ||
import hexacraft.world.entity.base.BasicEntityModel | ||
import hexacraft.world.entity.player.PlayerEntityModel | ||
import hexacraft.world.entity.sheep.SheepEntityModel | ||
|
||
import com.eclipsesource.json.{Json, JsonObject} | ||
class EntityModelLoader { | ||
|
||
class EntityModelLoader(basePath: String = "spec/entities") { | ||
private def makeEntity(name: String, setup: JsonObject): EntityModel = name match { | ||
case "player" => PlayerEntityModel.fromJson(setup) | ||
case "sheep" => SheepEntityModel.fromJson(setup) | ||
case _ => BasicEntityModel.create(CylCoords.Offset(0, 0, 0), new HexBox(0, 0, 0)) | ||
} | ||
|
||
def load(name: String): EntityModel = { | ||
FileUtils.getResourceFile(s"$basePath/$name.json") match { | ||
case Some(file) => | ||
val reader = FileUtils.getBufferedReader(file) | ||
if (reader != null) { | ||
val base = Json.parse(reader).asObject() | ||
val name = base.get("texture").asString() | ||
val entity = makeEntity(name, base) | ||
entity | ||
} else makeEntity("", null) | ||
case None => | ||
makeEntity("", null) | ||
} | ||
def load(name: String): EntityModel = name match { | ||
case "player" => PlayerEntityModel.create("player") | ||
case "sheep" => SheepEntityModel.create("sheep") | ||
case _ => BasicEntityModel.create(CylCoords.Offset(0, 0, 0), HexBox(0, 0, 0)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.