Commit MetaInfo

Revisión0fa8e0e03b735e8d2608e93feffaaa44f2cfc116 (tree)
Tiempo2021-05-02 17:27:57
AutorRemilia Scarlet <remilia@post...>
CommiterRemilia Scarlet

Log Message

Add doptimpk3

Cambiar Resumen

Diferencia incremental

diff -r 1549f9bf69aa -r 0fa8e0e03b73 shard.yml
--- a/shard.yml Sun May 02 02:20:35 2021 -0600
+++ b/shard.yml Sun May 02 02:27:57 2021 -0600
@@ -19,6 +19,9 @@
1919 dtexturedump:
2020 main: src/dtexturedump/main.cr
2121
22+ doptimpk3:
23+ main: src/doptimpk3/main.cr
24+
2225 dependencies:
2326 libremiliacr:
2427 gitlab: RemiliaScarlet/libremiliacr
diff -r 1549f9bf69aa -r 0fa8e0e03b73 src/doptimpk3/main.cr
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/doptimpk3/main.cr Sun May 02 02:27:57 2021 -0600
@@ -0,0 +1,105 @@
1+#### DTools
2+#### Copyright (C) 2021 Remilia Scarlet <remilia@posteo.jp>
3+####
4+#### This program is free software: you can redistribute it and/or modify it
5+#### under the terms of the GNU General Public License as published by the Free
6+#### Software Foundation, either version 3 of the License, or (at your option)
7+#### any later version.
8+####
9+#### This program is distributed in the hope that it will be useful, but WITHOUT
10+#### ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+#### FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12+#### more details.
13+####
14+#### You should have received a copy of the GNU General Public License along
15+#### with this program. If not, see <http://www.gnu.org/licenses/>.
16+require "compress/zip"
17+
18+require "dwaddle/mapformats"
19+require "dwaddle/level"
20+require "../common-cli"
21+
22+####
23+#### Main entry point
24+####
25+
26+module DTools::DOptimPK3
27+ PROGRAM_NAME = "doptimpk3"
28+ VERSION = "0.1.0"
29+
30+ class MainProgram
31+ @textures = {} of String => Bool
32+
33+ def initialize
34+ # Initialize command line arguments
35+ DOptimPK3.args.addString("file", 'f', help: "The PK3 file to load")
36+ DOptimPK3.args.addMultiString("wad", 'w', help: "Specifies a WAD containing a single map")
37+ DOptimPK3.args.addMultiString("ignore", 'i', help: "Always treat a specific texture as 'used'")
38+ DOptimPK3.args.addString("ignore-file", 'I', help: "Load ignored textures from the given file")
39+ end
40+
41+ def loadPk3Textures(filename)
42+ Compress::Zip::File.open(filename) do |file|
43+ file.entries.each do |ent|
44+ if ent.filename.downcase.starts_with?("textures/") || ent.filename.downcase.starts_with?("flats/")
45+ @textures[ent.filename] = true unless ent.filename.ends_with?('/')
46+ end
47+ end
48+ end
49+
50+ RemiLog.log.log("Textures found: #{@textures.size}")
51+ end
52+
53+ def processWad(filename)
54+ start = Time.local
55+ map, _, _, _ = Dwaddle::Level.fromWad(filename)
56+ finish = Time.local
57+ RemiLog.log.vlog(1, "#{Path["filename"].basename}: map loading took #{finish - start}")
58+
59+ map.sidedefs.each do |side|
60+ @textures.delete(side.upperTexture)
61+ @textures.delete(side.middleTexture)
62+ @textures.delete(side.lowerTexture)
63+ end
64+
65+ map.sectors.each do |sect|
66+ @textures.delete(sect.floorTexture)
67+ @textures.delete(sect.ceilingTexture)
68+ end
69+ end
70+
71+ def run
72+ RemiLog.log.fatal("No PK3 file specified") unless DOptimPK3.args["file"].called
73+ RemiLog.log.fatal("No WADs specified") unless DOptimPK3.args["wad"].called
74+
75+ loadPk3Textures(DOptimPK3.args["file"].str)
76+
77+ DOptimPK3.args["ignore"].as(RemiArgParser::MultiStringArgument).values.each do |tex|
78+ @textures.delete(tex)
79+ @textures.delete(tex.lchop('/'))
80+ end
81+
82+ if DOptimPK3.args["ignore-file"].called
83+ file = File.read(DOptimPK3.args["ignore-file"].str)
84+ file.each_line do |line|
85+ @textures.delete(line)
86+ @textures.delete(line.lchop('/'))
87+ @textures.delete("/#{line}")
88+ end
89+ end
90+
91+ RemiLog.log.dlog(1, "Ignores processed")
92+
93+ DOptimPK3.args["wad"].as(RemiArgParser::MultiStringArgument).values.each do |wad|
94+ processWad(wad)
95+ end
96+
97+ STDOUT << "Unused textures: #{@textures.size}\n"
98+ @textures.each_key do |k|
99+ STDOUT << k << "\n"
100+ end
101+ end
102+ end
103+
104+ include DTools::CLI(DTools::DOptimPK3::MainProgram)
105+end
Show on old repository browser