Main Dwaddle repository
Revision | e7f4a66264fc9730f5902a131fd93c4efe8bf0da (tree) |
---|---|
Time | 2021-05-22 07:13:35 |
Author | ![]() |
Commiter | Remilia Scarlet |
Remove references to the old ZUdmf* classes, and add #groupLines
@@ -44,12 +44,6 @@ | ||
44 | 44 | def initialize(vert : MapFormats::Udmf::UdmfVertex) |
45 | 45 | @x = vert.x |
46 | 46 | @y = vert.y |
47 | - end | |
48 | - | |
49 | - # Creates a new `Vertex` by converting a `MapFormats::Udmf::ZUdmfVertex`. | |
50 | - def initialize(vert : MapFormats::Udmf::ZUdmfVertex) | |
51 | - @x = vert.x | |
52 | - @y = vert.y | |
53 | 47 | @floorHeight = vert.floorHeight |
54 | 48 | @ceilingHeight = vert.ceilingHeight |
55 | 49 | end |
@@ -90,7 +84,7 @@ | ||
90 | 84 | property frontSidedef : Sidedef = Sidedef.new |
91 | 85 | |
92 | 86 | # The sidedef for the back side of the linedef. |
93 | - property backSidedef : Sidedef = Sidedef.new | |
87 | + property backSidedef : Sidedef? = nil | |
94 | 88 | |
95 | 89 | # A textual comment. |
96 | 90 | property comment = "" |
@@ -128,82 +122,6 @@ | ||
128 | 122 | def initialize(line : MapFormats::Udmf::UdmfLinedef, vertices : Array(Vertex)|Nil, sidedefs : Array(Sidedef)|Nil) |
129 | 123 | @tag = line.id == -1 ? 0 : line.id |
130 | 124 | @special = line.special |
131 | - [line.arg0, line.arg1, line.arg2, line.arg3, line.arg4].each { |x| @args << x } | |
132 | - @comment = line.comment | |
133 | - | |
134 | - if vertices | |
135 | - @startVertex = if line.startVertex < vertices.size | |
136 | - vertices[line.startVertex] | |
137 | - else | |
138 | - raise DwaddleError.new("Cannot assign a vertex to a Linedef: old index out of range") | |
139 | - end | |
140 | - | |
141 | - @endVertex = if line.endVertex < vertices.size | |
142 | - vertices[line.endVertex] | |
143 | - else | |
144 | - raise DwaddleError.new("Cannot assign a vertex to a Linedef: old index out of range") | |
145 | - end | |
146 | - end | |
147 | - | |
148 | - if sidedefs | |
149 | - @frontSidedef = if line.frontSidedef < sidedefs.size | |
150 | - sidedefs[line.frontSidedef] | |
151 | - else | |
152 | - raise DwaddleError.new("Cannot assign a sidedef to a Linedef: old index out of range") | |
153 | - end | |
154 | - | |
155 | - @backSidedef = if line.backSidedef < sidedefs.size | |
156 | - sidedefs[line.backSidedef] | |
157 | - else | |
158 | - raise DwaddleError.new("Cannot assign a sidedef to a Linedef: old index out of range") | |
159 | - end | |
160 | - end | |
161 | - | |
162 | - @flags = @flags | Flags::Impassable if line.impassable | |
163 | - @flags = @flags | Flags::BlocksMonsters if line.blocksMonsters | |
164 | - @flags = @flags | Flags::BlocksFloatingMonsters if line.blocksFloatingMonsters | |
165 | - @flags = @flags | Flags::TwoSided if line.twoSided | |
166 | - @flags = @flags | Flags::UpperUnpegged if line.upperUnpegged | |
167 | - @flags = @flags | Flags::LowerUnpegged if line.lowerUnpegged | |
168 | - @flags = @flags | Flags::ShownAsOneSided if line.shownAsOneSided | |
169 | - @flags = @flags | Flags::BlocksSound if line.blocksSound | |
170 | - @flags = @flags | Flags::NotShownOnMap if line.notShownOnMap | |
171 | - @flags = @flags | Flags::AlwaysOnMap if line.alwaysOnMap | |
172 | - @flags = @flags | Flags::PassUseThrough if line.passUseThrough | |
173 | - @flags = @flags | Flags::StrifeTranslucent if line.translucent | |
174 | - @flags = @flags | Flags::StrifeRailing if line.strifeRailing | |
175 | - | |
176 | - @activationFlags = @activationFlags | ActivationFlags::PlayerCross if line.onPlayerCross | |
177 | - @activationFlags = @activationFlags | ActivationFlags::PlayerUse if line.onPlayerUse | |
178 | - @activationFlags = @activationFlags | ActivationFlags::PlayerPush if line.onPlayerPush | |
179 | - @activationFlags = @activationFlags | ActivationFlags::MonsterCross if line.onMonsterCross | |
180 | - @activationFlags = @activationFlags | ActivationFlags::MonsterUse if line.onMonsterUse | |
181 | - @activationFlags = @activationFlags | ActivationFlags::MonsterPush if line.onMonsterPush | |
182 | - @activationFlags = @activationFlags | ActivationFlags::Impact if line.onImpact | |
183 | - @activationFlags = @activationFlags | ActivationFlags::ProjectileCross if line.onProjectileCross | |
184 | - @activationFlags = @activationFlags | ActivationFlags::Repeatable if line.repeatable | |
185 | - end | |
186 | - | |
187 | - # Creates a new `Linedef` by converting a `MapFormats::Udmf::ZUdmfLinedef`. | |
188 | - # | |
189 | - # If `vertices` is non-nil, then the | |
190 | - # `MapFormats::Udmf::ZUdmfLinedef#startVertex` and | |
191 | - # `MapFormats::Udmf::ZUdmfLinedef#endVertex` of `line` will be looked up in | |
192 | - # `vertices`. If this fails, a `DwaddleError` is raised. | |
193 | - # | |
194 | - # If `vertices` is nil, the new `Linedef` will have two completely new | |
195 | - # vertices. | |
196 | - # | |
197 | - # If `sidedefs` is non-nil, then the | |
198 | - # `MapFormats::Udmf::ZUdmfLinedef#frontSidedef` and | |
199 | - # `MapFormats::Udmf::ZUdmfLinedef#backSidedef` of `line` will be looked up in | |
200 | - # `sidedefs`. If this fails, a `DwaddleError` is raised. | |
201 | - # | |
202 | - # If `sidedefs` is nil, the new `Linedef` will have two completely new | |
203 | - # sidedefs. | |
204 | - def initialize(line : MapFormats::Udmf::ZUdmfLinedef, vertices : Array(Vertex)|Nil, sidedefs : Array(Sidedef)|Nil) | |
205 | - @tag = line.id == -1 ? 0 : line.id | |
206 | - @special = line.special | |
207 | 125 | @lockNumber = line.lockNumber |
208 | 126 | @comment = line.comment |
209 | 127 |
@@ -234,10 +152,14 @@ | ||
234 | 152 | raise DwaddleError.new("Cannot assign a sidedef to a Linedef: old index out of range") |
235 | 153 | end |
236 | 154 | |
237 | - @backSidedef = if line.backSidedef < sidedefs.size | |
238 | - sidedefs[line.backSidedef] | |
155 | + @backSidedef = if line.backSidedef != 0 | |
156 | + if line.backSidedef < sidedefs.size | |
157 | + sidedefs[line.backSidedef] | |
158 | + else | |
159 | + raise DwaddleError.new("Cannot assign a sidedef to a Linedef: old index out of range") | |
160 | + end | |
239 | 161 | else |
240 | - raise DwaddleError.new("Cannot assign a sidedef to a Linedef: old index out of range") | |
162 | + nil | |
241 | 163 | end |
242 | 164 | end |
243 | 165 |
@@ -341,10 +263,14 @@ | ||
341 | 263 | raise DwaddleError.new("Cannot assign a sidedef to a Linedef: old index out of range") |
342 | 264 | end |
343 | 265 | |
344 | - @backSidedef = if line.backSidedef < sidedefs.size | |
345 | - sidedefs[line.backSidedef] | |
266 | + @backSidedef = if line.backSidedef >= 0 | |
267 | + if line.backSidedef < sidedefs.size | |
268 | + sidedefs[line.backSidedef] | |
269 | + else | |
270 | + raise DwaddleError.new("Cannot assign a sidedef to a Linedef: old index out of range") | |
271 | + end | |
346 | 272 | else |
347 | - raise DwaddleError.new("Cannot assign a sidedef to a Linedef: old index out of range") | |
273 | + nil | |
348 | 274 | end |
349 | 275 | end |
350 | 276 |
@@ -434,34 +360,6 @@ | ||
434 | 360 | # |
435 | 361 | # If `sectors` is nil, the new `Sidedef` will have a completely new sector. |
436 | 362 | def initialize(side : MapFormats::Udmf::UdmfSidedef, sectors : Array(Sector)|Nil) |
437 | - @upperOffsetX = side.xOffset.to_f64! | |
438 | - @middleOffsetX = side.xOffset.to_f64! | |
439 | - @lowerOffsetX = side.xOffset.to_f64! | |
440 | - @upperOffsetY = side.yOffset.to_f64! | |
441 | - @middleOffsetY = side.yOffset.to_f64! | |
442 | - @lowerOffsetY = side.yOffset.to_f64! | |
443 | - @upperTexture = side.upperTexture | |
444 | - @middleTexture = side.middleTexture | |
445 | - @lowerTexture = side.lowerTexture | |
446 | - @comment = side.comment | |
447 | - | |
448 | - if sectors | |
449 | - @sector = if side.sector < sectors.size | |
450 | - sectors[side.sector] | |
451 | - else | |
452 | - raise DwaddleError.new("Cannot assign a sector to a Sidedef: old index out of range") | |
453 | - end | |
454 | - end | |
455 | - end | |
456 | - | |
457 | - # Creates a new `Sidedef` by converting a `MapFormats::Udmf::ZUdmfSidedef`. | |
458 | - # | |
459 | - # If `sectors` is non-nil, then the `MapFormats::Udmf::ZUdmfSidedef#sector` | |
460 | - # of `side` will be looked up in `sectors`. If this fails, a `DwaddleError` | |
461 | - # is raised. | |
462 | - # | |
463 | - # If `sectors` is nil, the new `Sidedef` will have a completely new sector. | |
464 | - def initialize(side : MapFormats::Udmf::ZUdmfSidedef, sectors : Array(Sector)|Nil) | |
465 | 363 | @upperOffsetX = side.upperOffsetX |
466 | 364 | @middleOffsetX = side.middleOffsetX |
467 | 365 | @lowerOffsetX = side.lowerOffsetX |
@@ -661,6 +559,8 @@ | ||
661 | 559 | # The rendering style for the ceiling portal. |
662 | 560 | getter ceilingPortalRenderStyle : RenderStyle = RenderStyle::Translucent |
663 | 561 | |
562 | + property lines : Array(Linedef) = [] of Linedef | |
563 | + | |
664 | 564 | # Creates a new `Sector`. |
665 | 565 | def initialize |
666 | 566 | end |
@@ -670,24 +570,6 @@ | ||
670 | 570 | @tag = sect.id |
671 | 571 | @floorHeight = sect.floorHeight |
672 | 572 | @ceilingHeight = sect.ceilingHeight |
673 | - @floorTexture = sect.floorTexture | |
674 | - @ceilingTexture = sect.ceilingTexture | |
675 | - @light = if sect.light < 0 | |
676 | - 0u8 | |
677 | - elsif sect.light > 255 | |
678 | - 255u8 | |
679 | - else | |
680 | - sect.light.to_u8 | |
681 | - end | |
682 | - @special = sect.special | |
683 | - @comment = sect.comment | |
684 | - end | |
685 | - | |
686 | - # Creates a new `Sidedef` by converting a `MapFormats::Udmf::ZUdmfSector`. | |
687 | - def initialize(sect : MapFormats::Udmf::ZUdmfSector) | |
688 | - @tag = sect.id | |
689 | - @floorHeight = sect.floorHeight | |
690 | - @ceilingHeight = sect.ceilingHeight | |
691 | 573 | @floorPanningX = sect.floorPanningX |
692 | 574 | @floorPanningY = sect.floorPanningY |
693 | 575 | @ceilingPanningX = sect.ceilingPanningX |
@@ -884,39 +766,6 @@ | ||
884 | 766 | @angle = thing.angle |
885 | 767 | @type = thing.type |
886 | 768 | @special = thing.special |
887 | - [thing.arg0, thing.arg1, thing.arg2, thing.arg3, thing.arg4].each { |x| @args << x } | |
888 | - | |
889 | - @flags = @flags | Flags::Ambush if thing.ambush | |
890 | - @flags = @flags | Flags::InSinglePlayer if thing.inSinglePlayer | |
891 | - @flags = @flags | Flags::InDM if thing.inDM | |
892 | - @flags = @flags | Flags::InCoop if thing.inCoop | |
893 | - @flags = @flags | Flags::Friendly if thing.friendly | |
894 | - @flags = @flags | Flags::Dormant if thing.dormant | |
895 | - @flags = @flags | Flags::StrifeNPC if thing.npc | |
896 | - @flags = @flags | Flags::StrifeAlly if thing.ally | |
897 | - @flags = @flags | Flags::StrifeTranslucent if thing.translucent | |
898 | - @flags = @flags | Flags::StrifeInvisible if thing.invisible | |
899 | - | |
900 | - @skills = @skills | SkillLevels::Skill1 if thing.inVeryEasy | |
901 | - @skills = @skills | SkillLevels::Skill2 if thing.inEasy | |
902 | - @skills = @skills | SkillLevels::Skill3 if thing.inNormal | |
903 | - @skills = @skills | SkillLevels::Skill4 if thing.inHard | |
904 | - @skills = @skills | SkillLevels::Skill5 if thing.inVeryHard | |
905 | - | |
906 | - @classes = @classes | Classes::Class1 if thing.class1 | |
907 | - @classes = @classes | Classes::Class2 if thing.class2 | |
908 | - @classes = @classes | Classes::Class3 if thing.class3 | |
909 | - end | |
910 | - | |
911 | - # Creates a new `Sidedef` by converting a `MapFormats::Udmf::ZUdmfThing`. | |
912 | - def initialize(thing : MapFormats::Udmf::ZUdmfThing) | |
913 | - @tag = thing.id | |
914 | - @x = thing.x | |
915 | - @y = thing.y | |
916 | - @z = thing.z | |
917 | - @angle = thing.angle | |
918 | - @type = thing.type | |
919 | - @special = thing.special | |
920 | 769 | @conversation = thing.conversation |
921 | 770 | @gravity = thing.gravity |
922 | 771 | @health = thing.health |
@@ -1066,6 +915,35 @@ | ||
1066 | 915 | def initialize |
1067 | 916 | end |
1068 | 917 | |
918 | + # Groups all of linedefs in this `Level` by sector, then stores this list of | |
919 | + # linedefs in each sector's `Sector#lines`. | |
920 | + # | |
921 | + # If linedefs or sectors are added/removed, this should be re-run to regroup | |
922 | + # them. | |
923 | + def groupLines : Nil | |
924 | + mappings = {} of Sector => Array(Linedef) | |
925 | + @linedefs.each do |line| | |
926 | + frontSect = line.frontSidedef.sector | |
927 | + backSect = line.backSidedef.try &.sector | |
928 | + | |
929 | + if mappings.has_key?(frontSect) | |
930 | + mappings[frontSect] << line | |
931 | + else | |
932 | + mappings[frontSect] = [line] | |
933 | + end | |
934 | + | |
935 | + if backSect | |
936 | + if mappings.has_key?(backSect) | |
937 | + mappings[backSect] << line | |
938 | + else | |
939 | + mappings[backSect] = [line] | |
940 | + end | |
941 | + end | |
942 | + end | |
943 | + | |
944 | + mappings.each { |sect, lines| sect.lines = lines } | |
945 | + end | |
946 | + | |
1069 | 947 | # Converts a `Dwaddle::MapFormats::Udmf::UdmfMap` to a `Level`. |
1070 | 948 | def initialize(map : MapFormats::Udmf::UdmfMap) |
1071 | 949 | map.vertices.each { |obj| @vertices << Vertex.new(obj) } |
@@ -1074,6 +952,7 @@ | ||
1074 | 952 | map.linedefs.each { |obj| @linedefs << Linedef.new(obj, @vertices, @sidedefs) } |
1075 | 953 | map.things.each { |obj| @things << Thing.new(obj) } |
1076 | 954 | @origFormat = Format::UDMF |
955 | + groupLines | |
1077 | 956 | end |
1078 | 957 | |
1079 | 958 | # Converts a `Dwaddle::MapFormats::Vanilla::Map` to a `Level`. |
@@ -1084,6 +963,7 @@ | ||
1084 | 963 | map.linedefs.each { |obj| @linedefs << Linedef.new(obj, @vertices, @sidedefs) } |
1085 | 964 | map.things.each { |obj| @things << Thing.new(obj) } |
1086 | 965 | @origFormat = Format::Vanilla |
966 | + groupLines | |
1087 | 967 | end |
1088 | 968 | |
1089 | 969 | # Loads a level from the given filename. Returns these values in this order: |