Browse Source

Add preset option, but it's not working just right yet.

master
Starbeamrainbowlabs 10 months ago
parent
commit
81935c1050
Signed by: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com> GPG Key ID: 1BE5172E637709C2

+ 339
- 0
.gitignore View File

@@ -94,3 +94,342 @@ _UpgradeReport_Files/
94 94
 Backup*/
95 95
 UpgradeLog*.XML
96 96
 
97
+
98
+# Created by https://www.gitignore.io/api/visualstudio
99
+
100
+### VisualStudio ###
101
+## Ignore Visual Studio temporary files, build results, and
102
+## files generated by popular Visual Studio add-ons.
103
+##
104
+## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
105
+
106
+# User-specific files
107
+*.suo
108
+*.user
109
+*.userosscache
110
+*.sln.docstates
111
+
112
+# User-specific files (MonoDevelop/Xamarin Studio)
113
+*.userprefs
114
+
115
+# Build results
116
+[Dd]ebug/
117
+[Dd]ebugPublic/
118
+[Rr]elease/
119
+[Rr]eleases/
120
+x64/
121
+x86/
122
+bld/
123
+[Bb]in/
124
+[Oo]bj/
125
+[Ll]og/
126
+
127
+# Visual Studio 2015/2017 cache/options directory
128
+.vs/
129
+# Uncomment if you have tasks that create the project's static files in wwwroot
130
+#wwwroot/
131
+
132
+# Visual Studio 2017 auto generated files
133
+Generated\ Files/
134
+
135
+# MSTest test Results
136
+[Tt]est[Rr]esult*/
137
+[Bb]uild[Ll]og.*
138
+
139
+# NUNIT
140
+*.VisualState.xml
141
+TestResult.xml
142
+
143
+# Build Results of an ATL Project
144
+[Dd]ebugPS/
145
+[Rr]eleasePS/
146
+dlldata.c
147
+
148
+# Benchmark Results
149
+BenchmarkDotNet.Artifacts/
150
+
151
+# .NET Core
152
+project.lock.json
153
+project.fragment.lock.json
154
+artifacts/
155
+
156
+# StyleCop
157
+StyleCopReport.xml
158
+
159
+# Files built by Visual Studio
160
+*_i.c
161
+*_p.c
162
+*_i.h
163
+*.ilk
164
+*.meta
165
+*.obj
166
+*.iobj
167
+*.pch
168
+*.pdb
169
+*.ipdb
170
+*.pgc
171
+*.pgd
172
+*.rsp
173
+*.sbr
174
+*.tlb
175
+*.tli
176
+*.tlh
177
+*.tmp
178
+*.tmp_proj
179
+*.log
180
+*.vspscc
181
+*.vssscc
182
+.builds
183
+*.pidb
184
+*.svclog
185
+*.scc
186
+
187
+# Chutzpah Test files
188
+_Chutzpah*
189
+
190
+# Visual C++ cache files
191
+ipch/
192
+*.aps
193
+*.ncb
194
+*.opendb
195
+*.opensdf
196
+*.sdf
197
+*.cachefile
198
+*.VC.db
199
+*.VC.VC.opendb
200
+
201
+# Visual Studio profiler
202
+*.psess
203
+*.vsp
204
+*.vspx
205
+*.sap
206
+
207
+# Visual Studio Trace Files
208
+*.e2e
209
+
210
+# TFS 2012 Local Workspace
211
+$tf/
212
+
213
+# Guidance Automation Toolkit
214
+*.gpState
215
+
216
+# ReSharper is a .NET coding add-in
217
+_ReSharper*/
218
+*.[Rr]e[Ss]harper
219
+*.DotSettings.user
220
+
221
+# JustCode is a .NET coding add-in
222
+.JustCode
223
+
224
+# TeamCity is a build add-in
225
+_TeamCity*
226
+
227
+# DotCover is a Code Coverage Tool
228
+*.dotCover
229
+
230
+# AxoCover is a Code Coverage Tool
231
+.axoCover/*
232
+!.axoCover/settings.json
233
+
234
+# Visual Studio code coverage results
235
+*.coverage
236
+*.coveragexml
237
+
238
+# NCrunch
239
+_NCrunch_*
240
+.*crunch*.local.xml
241
+nCrunchTemp_*
242
+
243
+# MightyMoose
244
+*.mm.*
245
+AutoTest.Net/
246
+
247
+# Web workbench (sass)
248
+.sass-cache/
249
+
250
+# Installshield output folder
251
+[Ee]xpress/
252
+
253
+# DocProject is a documentation generator add-in
254
+DocProject/buildhelp/
255
+DocProject/Help/*.HxT
256
+DocProject/Help/*.HxC
257
+DocProject/Help/*.hhc
258
+DocProject/Help/*.hhk
259
+DocProject/Help/*.hhp
260
+DocProject/Help/Html2
261
+DocProject/Help/html
262
+
263
+# Click-Once directory
264
+publish/
265
+
266
+# Publish Web Output
267
+*.[Pp]ublish.xml
268
+*.azurePubxml
269
+# Note: Comment the next line if you want to checkin your web deploy settings,
270
+# but database connection strings (with potential passwords) will be unencrypted
271
+*.pubxml
272
+*.publishproj
273
+
274
+# Microsoft Azure Web App publish settings. Comment the next line if you want to
275
+# checkin your Azure Web App publish settings, but sensitive information contained
276
+# in these scripts will be unencrypted
277
+PublishScripts/
278
+
279
+# NuGet Packages
280
+*.nupkg
281
+# The packages folder can be ignored because of Package Restore
282
+**/[Pp]ackages/*
283
+# except build/, which is used as an MSBuild target.
284
+!**/[Pp]ackages/build/
285
+# Uncomment if necessary however generally it will be regenerated when needed
286
+#!**/[Pp]ackages/repositories.config
287
+# NuGet v3's project.json files produces more ignorable files
288
+*.nuget.props
289
+*.nuget.targets
290
+
291
+# Microsoft Azure Build Output
292
+csx/
293
+*.build.csdef
294
+
295
+# Microsoft Azure Emulator
296
+ecf/
297
+rcf/
298
+
299
+# Windows Store app package directories and files
300
+AppPackages/
301
+BundleArtifacts/
302
+Package.StoreAssociation.xml
303
+_pkginfo.txt
304
+*.appx
305
+
306
+# Visual Studio cache files
307
+# files ending in .cache can be ignored
308
+*.[Cc]ache
309
+# but keep track of directories ending in .cache
310
+!*.[Cc]ache/
311
+
312
+# Others
313
+ClientBin/
314
+~$*
315
+*~
316
+*.dbmdl
317
+*.dbproj.schemaview
318
+*.jfm
319
+*.pfx
320
+*.publishsettings
321
+orleans.codegen.cs
322
+
323
+# Including strong name files can present a security risk
324
+# (https://github.com/github/gitignore/pull/2483#issue-259490424)
325
+#*.snk
326
+
327
+# Since there are multiple workflows, uncomment next line to ignore bower_components
328
+# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
329
+#bower_components/
330
+
331
+# RIA/Silverlight projects
332
+Generated_Code/
333
+
334
+# Backup & report files from converting an old project file
335
+# to a newer Visual Studio version. Backup files are not needed,
336
+# because we have git ;-)
337
+_UpgradeReport_Files/
338
+Backup*/
339
+UpgradeLog*.XML
340
+UpgradeLog*.htm
341
+ServiceFabricBackup/
342
+*.rptproj.bak
343
+
344
+# SQL Server files
345
+*.mdf
346
+*.ldf
347
+*.ndf
348
+
349
+# Business Intelligence projects
350
+*.rdl.data
351
+*.bim.layout
352
+*.bim_*.settings
353
+*.rptproj.rsuser
354
+
355
+# Microsoft Fakes
356
+FakesAssemblies/
357
+
358
+# GhostDoc plugin setting file
359
+*.GhostDoc.xml
360
+
361
+# Node.js Tools for Visual Studio
362
+.ntvs_analysis.dat
363
+node_modules/
364
+
365
+# Visual Studio 6 build log
366
+*.plg
367
+
368
+# Visual Studio 6 workspace options file
369
+*.opt
370
+
371
+# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
372
+*.vbw
373
+
374
+# Visual Studio LightSwitch build output
375
+**/*.HTMLClient/GeneratedArtifacts
376
+**/*.DesktopClient/GeneratedArtifacts
377
+**/*.DesktopClient/ModelManifest.xml
378
+**/*.Server/GeneratedArtifacts
379
+**/*.Server/ModelManifest.xml
380
+_Pvt_Extensions
381
+
382
+# Paket dependency manager
383
+.paket/paket.exe
384
+paket-files/
385
+
386
+# FAKE - F# Make
387
+.fake/
388
+
389
+# JetBrains Rider
390
+.idea/
391
+*.sln.iml
392
+
393
+# CodeRush
394
+.cr/
395
+
396
+# Python Tools for Visual Studio (PTVS)
397
+__pycache__/
398
+*.pyc
399
+
400
+# Cake - Uncomment if you are using it
401
+# tools/**
402
+# !tools/packages.config
403
+
404
+# Tabs Studio
405
+*.tss
406
+
407
+# Telerik's JustMock configuration file
408
+*.jmconfig
409
+
410
+# BizTalk build output
411
+*.btp.cs
412
+*.btm.cs
413
+*.odx.cs
414
+*.xsd.cs
415
+
416
+# OpenCover UI analysis results
417
+OpenCover/
418
+
419
+# Azure Stream Analytics local run output
420
+ASALocalRun/
421
+
422
+# MSBuild Binary and Structured Log
423
+*.binlog
424
+
425
+# NVidia Nsight GPU debugger configuration file
426
+*.nvuser
427
+
428
+# MFractors (Xamarin productivity tool) working folder
429
+.mfractor/
430
+
431
+# Local History for Visual Studio
432
+.localhistory/
433
+
434
+
435
+# End of https://www.gitignore.io/api/visualstudio

+ 38
- 11
SpritePacker-CLI/Program.cs View File

@@ -1,6 +1,9 @@
1 1
 using System;
2 2
 using System.Collections.Generic;
3 3
 using System.IO;
4
+using System.Text.RegularExpressions;
5
+using System.Linq;
6
+using System.Drawing;
4 7
 
5 8
 namespace SpritePacker
6 9
 {
@@ -32,6 +35,7 @@ namespace SpritePacker
32 35
 		private static OutputFormat outputFormat = OutputFormat.Text;
33 36
 		private static string outputFilename = "spritesheet.png";
34 37
 		private static List<string> values = new List<string>();
38
+		private static string rawSourceLocations = null;
35 39
 
36 40
 		public static bool Verbose = false;
37 41
 
@@ -53,12 +57,14 @@ namespace SpritePacker
53 57
 					case "--verbose":
54 58
 						Verbose = true;
55 59
 						break;
60
+					case "--preset":
61
+						rawSourceLocations = File.ReadAllText(args[++i]);
62
+						break;
56 63
 					case "--csv":
57 64
 						outputFormat = OutputFormat.CSV;
58 65
 						break;
59 66
 					default:
60
-						if(args[i].StartsWith("-"))
61
-						{
67
+						if(args[i].StartsWith("-")) {
62 68
 							Console.Error.WriteLine("Error: Unrecognised flag '{0}'.", args[i]);
63 69
 							return 1;
64 70
 						}
@@ -104,7 +110,25 @@ namespace SpritePacker
104 110
 		public static void RunNormal()
105 111
 		{
106 112
 			spritePacker = new SpritePacker(Verbose);
107
-			addSprites(values);
113
+			List<Sprite> sprites = new List<Sprite>();
114
+			addSprites(values, sprites);
115
+
116
+			// Preset some locations if they were specified
117
+			if (rawSourceLocations != null) {
118
+				foreach (string[] line in parseCSV(rawSourceLocations).Skip(1)) { // Skip the header
119
+				  // index,filename,x,y,width,height
120
+					Sprite currentSprite = sprites.Find((Sprite item) => item.Filename == line[1]);
121
+					currentSprite.Area = new Rectangle(
122
+						int.Parse(line[2]),
123
+						int.Parse(line[3]),
124
+						int.Parse(line[4]),
125
+						int.Parse(line[5])
126
+					);
127
+					currentSprite.Placed = true;
128
+				}
129
+			}
130
+			spritePacker.Add(sprites);
131
+
108 132
 			spritePacker.Arrange();
109 133
 			spritePacker.Output(outputFilename);
110 134
 			switch(outputFormat)
@@ -121,19 +145,17 @@ namespace SpritePacker
121 145
 			}
122 146
 		}
123 147
 
124
-		private static void addSprites(List<string> filenames)
148
+		private static void addSprites(List<string> filenames, List<Sprite> outputSpriteList)
125 149
 		{
126
-			foreach(string filename in values)
150
+			foreach(string filename in filenames)
127 151
 			{
128 152
 				// Make sure that the file actually exists (we don't want the packer to throw a tantrum)
129 153
 				if (File.Exists(filename))
130 154
 				{
131
-					try
132
-					{
133
-						spritePacker.Add(new Sprite(filename));
155
+					try {
156
+						outputSpriteList.Add(new Sprite(filename));
134 157
 					}
135
-					catch(Exception error)
136
-					{
158
+					catch(Exception error) {
137 159
 						Console.Error.WriteLine("Error reading {0}: {1}", filename, error.Message);
138 160
 					}
139 161
 
@@ -141,7 +163,7 @@ namespace SpritePacker
141 163
 					{
142 164
 						// This filename is a directory - recurse over all the files in the directory
143 165
 						string[] dirFiles = Directory.GetFiles(filename);
144
-						addSprites(new List<string>(dirFiles));
166
+						addSprites(new List<string>(dirFiles), outputSpriteList);
145 167
 					}
146 168
 				}
147 169
 				else
@@ -151,5 +173,10 @@ namespace SpritePacker
151 173
 			}
152 174
 
153 175
 		}
176
+
177
+		private static IEnumerable<string[]> parseCSV(string source)
178
+		{
179
+			return Regex.Split(source.Trim(), @"\r?\n").Select((string line) => line.Split(','));
180
+		}
154 181
 	}
155 182
 }

+ 1
- 0
SpritePacker-CLI/Resources/HelpText.txt View File

@@ -11,5 +11,6 @@ Option		Meaning
11 11
 --help		Shows this help message.
12 12
 --version	Shows the version information.
13 13
 --csv		Outputs the final sprite positions in CSV.
14
+--preset	Specifies a csv file of previous location information to use when packing. This will ensure that sprites previously packed don't change their location.
14 15
 
15 16
 More information can be found at https://git.starbeamrainbowlabs.com/sbrl/SpritePacker

+ 3
- 0
SpritePacker-CLI/SpritePacker-CLI.csproj View File

@@ -35,6 +35,9 @@
35 35
   </PropertyGroup>
36 36
   <ItemGroup>
37 37
     <Reference Include="System" />
38
+    <Reference Include="System.Drawing">
39
+      <HintPath>..\..\..\..\..\..\..\usr\lib\mono\4.6.2-api\System.Drawing.dll</HintPath>
40
+    </Reference>
38 41
   </ItemGroup>
39 42
   <ItemGroup>
40 43
     <Compile Include="Program.cs" />

+ 2
- 0
SpritePacker/Sprite.cs View File

@@ -11,6 +11,8 @@ namespace SpritePacker
11 11
 		private string filename;
12 12
 		private Image image;
13 13
 
14
+		public bool Placed { get; set; } = false;
15
+
14 16
 		public Rectangle Area
15 17
 		{
16 18
 			get { return area; }

+ 13
- 1
SpritePacker/SpritePacker.cs View File

@@ -51,6 +51,11 @@ namespace SpritePacker
51 51
 			if(Verbose) Console.WriteLine("Adding {0}.", sprite);
52 52
 			sprites.Add(sprite);
53 53
 		}
54
+		public void Add(IEnumerable<Sprite> sprites)
55
+		{
56
+			foreach (Sprite sprite in sprites)
57
+				Add(sprite);
58
+		}
54 59
 		/// <summary>
55 60
 		/// Adds a sprite to the sprite packer.
56 61
 		/// </summary>
@@ -78,6 +83,11 @@ namespace SpritePacker
78 83
 			List<Sprite> arrangedSprites = new List<Sprite>();
79 84
 			foreach(Sprite cspr in sprites)
80 85
 			{
86
+				if (cspr.Placed) {
87
+					if(Verbose) Console.WriteLine($"Skipping placement of {cspr} as it has been preset");
88
+					continue;
89
+				}
90
+
81 91
 				if(Verbose) Console.WriteLine("Attempting to place {0}.", cspr);
82 92
 				Point scanLines = Point.Empty;
83 93
 				Point nextScanLines = new Point(int.MaxValue, int.MaxValue);
@@ -161,8 +171,10 @@ namespace SpritePacker
161 171
 					}
162 172
 
163 173
 					// If we found a new position, then we don't need to move the scan lines up and try again
164
-					if (foundPosition)
174
+					if (foundPosition) {
175
+						cspr.Placed = true;
165 176
 						break;
177
+					}
166 178
 
167 179
 					if(Verbose) Console.WriteLine("Failed to find a position along the current scan lines.");
168 180
 					if(Verbose) Console.WriteLine("Next candidate scan lines: {0}", nextScanLines);

Loading…
Cancel
Save