Renamed MapLoader to MapParser, added level select menu

This commit is contained in:
2020-01-28 23:41:44 -06:00
parent c1b5e72d7d
commit ea68748234
9 changed files with 42 additions and 20 deletions

View File

@@ -53,6 +53,7 @@ end
require_relative "lib/ui/console"
require_relative "lib/ui/menus/main_menu"
require_relative "lib/ui/menus/settings_menu"
require_relative "lib/ui/menus/level_select_menu"
require_relative "lib/ui/menus/game_pause_menu"
require_relative "lib/states/game_states/game"
@@ -87,7 +88,7 @@ require_relative "lib/wavefront/parser"
require_relative "lib/wavefront/object"
require_relative "lib/wavefront/material"
require_relative "lib/map_loader"
require_relative "lib/map_parser"
require_relative "lib/manifest"
require_relative "lib/map"

View File

@@ -7,7 +7,7 @@ class IMICFPS
end
def insert_entity(package, name, position, orientation, data = {})
ent = MapLoader::Entity.new(package, name, position, orientation, Vector.new(1,1,1))
ent = MapParser::Entity.new(package, name, position, orientation, Vector.new(1,1,1))
add_entity(IMICFPS::Entity.new(map_entity: ent, manifest: Manifest.new(package: package, name: name)))
end

View File

@@ -29,7 +29,7 @@ class IMICFPS
add_entity(Player.new(spawnpoint: @map_loader.spawnpoints.sample, manifest: Manifest.new(package: "base", name: "character")))
# TODO: Load lights from MapLoader
# TODO: Load lights from MapParser
add_light(Light.new(id: available_light, position: Vector.new(30, 10.0, 30)))
add_light(Light.new(id: available_light, position: Vector.new(0, 100, 0), diffuse: Color.new(1.0, 0.5, 0.1)))
end

View File

@@ -1,11 +1,11 @@
class IMICFPS
class MapLoader
class MapParser
attr_reader :metadata, :terrain, :skydome, :entities, :spawnpoints
attr_reader :assets, :missing_assets
def initialize(map_file:)
@metadata = MapLoader::MetaData.new
@terrain = MapLoader::Entity.new
@skydome = MapLoader::Entity.new
@metadata = MapParser::MetaData.new
@terrain = MapParser::Entity.new
@skydome = MapParser::Entity.new
@entities = []
@spawnpoints = []
@@ -78,7 +78,7 @@ class IMICFPS
if section = data["entities"]
section.each do |ent|
entity = MapLoader::Entity.new
entity = MapParser::Entity.new
entity.package = ent["package"]
entity.name = ent["name"]
entity.position = Vector.new(
@@ -135,4 +135,4 @@ class IMICFPS
Entity = Struct.new(:package, :name, :position, :orientation, :scale, :water_level, :scripts)
SpawnPoint = Struct.new(:team, :position, :orientation)
end
end
end

View File

@@ -3,7 +3,7 @@ class IMICFPS
attr_reader :map
def setup
@map = Map.new(map_loader: @options[:map_loader])
@map = Map.new(map_loader: @options[:map_parser])
@map.setup
@player = @map.find_entity_by(name: "character")

View File

@@ -2,11 +2,11 @@ class IMICFPS
class LoadingState < Menu
def setup
window.needs_cursor = false
@map_loader = MapLoader.new(map_file: @options[:map_file])
@map_parser = MapParser.new(map_file: @options[:map_file])
title "I-MIC FPS"
@subheading = Text.new("Loading Map: #{@map_loader.metadata.name}", y: 100, size: 50, alignment: :center)
@description = Text.new("Map created by: #{@map_loader.metadata.authors.join(", ")}\n#{@map_loader.metadata.description}", y: 180, size: 24, alignment: :center)
@subheading = Text.new("Loading Map: #{@map_parser.metadata.name}", y: 100, size: 50, alignment: :center)
@description = Text.new("Map created by: #{@map_parser.metadata.authors.join(", ")}\n#{@map_parser.metadata.description}", y: 180, size: 24, alignment: :center)
@state = Text.new("Preparing...", y: window.height/2-40, size: 40, alignment: :center)
@percentage = Text.new("0%", y: window.height - 100 + 25, size: 50, alignment: :center)
@@ -15,9 +15,9 @@ class IMICFPS
@asset_index = 0
add_asset(:shader, nil, "default")
add_asset(:model, @map_loader.terrain.package, @map_loader.terrain.name)
add_asset(:model, @map_loader.skydome.package, @map_loader.skydome.name)
@map_loader.entities.each do |entity|
add_asset(:model, @map_parser.terrain.package, @map_parser.terrain.name)
add_asset(:model, @map_parser.skydome.package, @map_parser.skydome.name)
@map_parser.entities.each do |entity|
add_asset(:model, entity.package, entity.name)
end
@@ -69,7 +69,7 @@ class IMICFPS
unless @asset_index < @assets.count
if @act && Gosu.milliseconds-@completed_for_ms > 250
push_state(@options[:forward], map_loader: @map_loader)
push_state(@options[:forward], map_parser: @map_parser)
else
@act = true
@completed_for_ms = Gosu.milliseconds unless @lock

View File

@@ -13,7 +13,7 @@ class IMICFPS
push_state(SettingsMenu)
end
link "Disconnect" do
link "Quit" do
push_state(MainMenu)
end
end

View File

@@ -0,0 +1,20 @@
class IMICFPS
class LevelSelectMenu < Menu
def setup
title "I-MIC FPS"
subtitle "Choose a Map"
Dir.glob(GAME_ROOT_PATH + "/maps/*.json").map { |file| [file, MapParser.new(map_file: file)]}.each do |file, map|
link map.metadata.name do
push_state(
LoadingState.new(forward: Game, map_file: file)
)
end
end
link "Back" do
pop_state
end
end
end
end

View File

@@ -3,7 +3,8 @@ class IMICFPS
def setup
title "I-MIC FPS"
link "Single Player" do
push_state(LoadingState.new(forward: Game, map_file: GAME_ROOT_PATH + "/maps/test_map.json"))
push_state(LevelSelectMenu)
# push_state(LoadingState.new(forward: Game, map_file: GAME_ROOT_PATH + "/maps/test_map.json"))
end
link "Settings" do
push_state(SettingsMenu)
@@ -13,4 +14,4 @@ class IMICFPS
end
end
end
end
end