Bladeren bron

Add packer

Pabloader 5 jaren geleden
bovenliggende
commit
1632b6d9b7
4 gewijzigde bestanden met toevoegingen van 98 en 1 verwijderingen
  1. 0
    1
      .gitignore
  2. 3
    0
      packer/.gitignore
  3. 26
    0
      packer/Makefile
  4. 69
    0
      packer/packer.cpp

+ 0
- 1
.gitignore Bestand weergeven

@@ -1,5 +1,4 @@
1 1
 awoorwa
2 2
 awoorwae
3
-packer
4 3
 *.exe
5 4
 *.o

+ 3
- 0
packer/.gitignore Bestand weergeven

@@ -0,0 +1,3 @@
1
+*.pack
2
+*.o
3
+packer

+ 26
- 0
packer/Makefile Bestand weergeven

@@ -0,0 +1,26 @@
1
+CPPFLAGS=-Wall -Wno-misleading-indentation -Werror --std=c++1z -O3 -flto
2
+LDFLAGS=
3
+INCLUDES=-I../pge/include
4
+EXECUTABLE=packer
5
+LIBRARIES=
6
+ifeq ($(OS),Windows_NT)
7
+	EXECUTABLE+=.exe
8
+	CPP=i686-w64-mingw32-g++
9
+	CC=i686-w64-mingw32-gcc
10
+else
11
+	CC=gcc
12
+	CPP=g++
13
+endif
14
+SOURCES=packer.cpp ../pge/src/olcPGE_ResourcePack.cpp
15
+OBJECTS=$(SOURCES:.cpp=.o)
16
+
17
+all: $(SOURCES) $(EXECUTABLE)
18
+
19
+clean: 
20
+	$(RM) $(OBJECTS) $(EXECUTABLE)
21
+	
22
+$(EXECUTABLE): $(OBJECTS) 
23
+	$(CPP) $(LDFLAGS) $(OBJECTS) -o $@ $(LIBRARIES)
24
+
25
+.cpp.o:
26
+	$(CPP) $(INCLUDES) -c $(CPPFLAGS) $< -o $@

+ 69
- 0
packer/packer.cpp Bestand weergeven

@@ -0,0 +1,69 @@
1
+#include "olcPGE_ResourcePack.h"
2
+#include <iostream>
3
+#include <string>
4
+
5
+void PrintUsage() {
6
+    std::cout << "Usage: packer --list PACK_FILE"            << std::endl;
7
+    std::cout << "       packer --add PACK_FILE FILE"        << std::endl;
8
+    std::cout << "       packer --remove PACK_FILE FILE"     << std::endl;
9
+    // std::cout << "       packer --convert PNG_FILE SPR_FILE" << std::endl;
10
+}
11
+
12
+void ListEntries(olc::ResourcePack& pack) {
13
+    auto entries = pack.GetEntries();
14
+    std::cout << "Total entries: " << entries.size() << std::endl;
15
+    for (auto entry: entries) {
16
+        std::cout << entry << std::endl;
17
+    }
18
+}
19
+
20
+int main(int argc, char *argv[])
21
+{
22
+    std::string packFile;
23
+    std::string action;
24
+
25
+    if (argc < 3) {
26
+        PrintUsage();
27
+        return -1;
28
+    }
29
+
30
+    action = argv[1];
31
+    packFile = argv[2];
32
+
33
+    olc::ResourcePack pack;
34
+    pack.LoadPack(packFile);
35
+
36
+    if (action == "--list") {
37
+        ListEntries(pack);
38
+    } else if (action == "--add" || action == "--remove") {
39
+        if (argc < 4) {
40
+            PrintUsage();
41
+            return -1;
42
+        }
43
+        for (int i = 3; i < argc; i++) {
44
+            std::string fileName = argv[i];
45
+            if (action == "--add") {
46
+                if (!pack.AddToPack(fileName)) {
47
+                    std::cerr << "Could not open file " << fileName << std::endl;
48
+                    return -3;
49
+                }
50
+                std::cout << "+ " << fileName << std::endl;
51
+            } else if (action == "--remove") {
52
+                if (!pack.RemoveFromPack(fileName)) {
53
+                    std::cerr << "Could not open file " << fileName << std::endl;
54
+                    return -3;
55
+                }
56
+                std::cout << "- " << fileName << std::endl;
57
+            }
58
+        }
59
+        std::cout << std::endl;
60
+        ListEntries(pack);
61
+    } else {
62
+        PrintUsage();
63
+        return -1;
64
+    }
65
+
66
+    pack.SavePack(packFile);
67
+
68
+    return 0;
69
+}

Loading…
Annuleren
Opslaan