-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_initial_maps.rb
More file actions
124 lines (98 loc) · 3.43 KB
/
process_initial_maps.rb
File metadata and controls
124 lines (98 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env ruby
# process_initial_maps.rb
# Script to process initial game location maps and generate elevation data
# Processes Earth (FreeCiv + Civ4), Mars (FreeCiv), Venus (FreeCiv + Civ4), Luna (Civ4), Titan (Civ4)
require_relative 'config/environment'
require_relative 'app/services/map_layer_service'
class InitialMapProcessor
def initialize
@map_service = MapLayerService.new
@logger = Logger.new(STDOUT)
end
def process_all_locations
@logger.info("Starting initial map processing for game locations...")
locations = [
{ name: 'Earth', freeciv_path: File.join(GalaxyGame::Paths::FREECIV_MAPS_PATH, 'earth-180x90-v1-3.sav') },
{ name: 'Mars', freeciv_path: File.join(GalaxyGame::Paths::PARTIAL_PLANETARY_MAPS_PATH, 'mars-terraformed-133x64-v2.0.sav') }
]
locations.each do |location|
process_location(location)
end
@logger.info("Initial map processing complete!")
end
private
def process_location(location_config)
name = location_config[:name]
@logger.info("Processing #{name}...")
# Find the celestial body
celestial_body = CelestialBodies::CelestialBody.find_by(name: name)
unless celestial_body
@logger.warn("Celestial body '#{name}' not found, skipping...")
return
end
# Load map data
map_data = load_map_data(location_config)
return if map_data.empty?
# Process layers
layers = @map_service.process_map_layers(map_data)
return if layers.empty? || layers[:error]
# Store in geosphere
success = @map_service.store_in_geosphere(celestial_body, layers)
if success
@logger.info("Successfully processed #{name}: #{layers[:quality]} quality, #{layers[:method]} method")
else
@logger.error("Failed to store #{name} elevation data")
end
end
def load_map_data(location_config)
map_data = {}
# Load FreeCiv data if available
if location_config[:freeciv_path] && File.exist?(location_config[:freeciv_path])
freeciv_data = load_freeciv_map(location_config[:freeciv_path])
map_data.merge!(freeciv_data) if freeciv_data
end
# Load Civ4 data if available
if location_config[:civ4_path] && File.exist?(location_config[:civ4_path])
civ4_data = load_civ4_map(location_config[:civ4_path])
map_data.merge!(civ4_data) if civ4_data
end
map_data
end
def load_freeciv_map(file_path)
@logger.debug("Loading FreeCiv map: #{file_path}")
# Use existing FreeCiv import service
importer = Import::FreecivSavImportService.new
data = importer.import_from_file(file_path)
return nil unless data && data[:terrain_grid]
{
format: :freeciv,
terrain_grid: data[:terrain_grid],
width: data[:width],
height: data[:height]
}
rescue => e
@logger.error("Failed to load FreeCiv map #{file_path}: #{e.message}")
nil
end
def load_civ4_map(file_path)
@logger.debug("Loading Civ4 map: #{file_path}")
# Use existing Civ4 import service
importer = Import::Civ4WbsImportService.new
data = importer.import_from_file(file_path)
return nil unless data && data[:plots]
{
format: :civ4,
plots: data[:plots],
width: data[:width],
height: data[:height]
}
rescue => e
@logger.error("Failed to load Civ4 map #{file_path}: #{e.message}")
nil
end
end
# Run the processor if called directly
if __FILE__ == $0
processor = InitialMapProcessor.new
processor.process_all_locations
end