dashcode 1.2.4__tar.gz → 1.2.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dashcode
3
- Version: 1.2.4
3
+ Version: 1.2.6
4
4
  Summary: A library for Geometry Dash level generation using .gmd files
5
5
  Author: IWiterI
6
6
  Project-URL: Homepage, https://github.com/ISviterI/dashcode
@@ -0,0 +1,177 @@
1
+ import base64
2
+ import gzip
3
+ obj_string = ""
4
+ lvlname = ""
5
+
6
+ print("Dashcode loaded! Have fun and also join our discord server please: https://discord.gg/MXv3KTFmPE")
7
+
8
+ class Dashcode:
9
+ def __init__(self):
10
+ self.objects = []
11
+ self.params = {
12
+ "NoTouch": 13,
13
+ "Hide": 12,
14
+ "Group": 57,
15
+ "TGroup": 51,
16
+ "MoveX":28,
17
+ "MoveY":29,
18
+ "LockToPX":34,
19
+ "LockToPY": 35,
20
+ "UseTarget":36,
21
+ "TMoveGroup":39,
22
+ "Duration": 10,
23
+ "Alpha": 11,
24
+ "TouchTrigger": 11,
25
+ "ActivateGroup": 56,
26
+ "ScaleX": 128,
27
+ "ScaleY": 129,
28
+ "Zoom": 107,
29
+ "RotateDegrees": 68,
30
+ "Times360": 69,
31
+ "LockRot": 70,
32
+ "Red":7,
33
+ "Green":8,
34
+ "Blue":9,
35
+ "Fade":10,
36
+ "TargetColor":23,
37
+ "Delay": 63,
38
+ "SpawnTrigger":62,
39
+ "MultiTrigger":87
40
+ }
41
+ self.objectids = {
42
+ "block": 1, "spike": 8, "yorb": 36, "coin": 1329,
43
+ "monster": 918, "bush": 128, "cloud": 129,
44
+ "alpha": 1007, "toggle": 1049, "rotate": 1346,
45
+ "zoom": 1913, "reverse": 1912, "move":901,
46
+ "checkpoint": 2063,
47
+ "spawn":1268,
48
+ "end": 3600,
49
+ "p_blue": 10, "p_yellow": 11, "p_green": 2926,
50
+ "p_cube": 12, "p_ship": 13, "p_ball": 47, "p_ufo": 111,
51
+ "p_wave": 660, "p_robot": 745, "p_spider": 1331, "p_swing": 1933
52
+ }
53
+ self.prefabs = {
54
+ "wall": {"Y":0},
55
+ "platform": {"X":0},
56
+ "square": {"SQ":0},
57
+ "corridor": {"X":1},
58
+ }
59
+ self.timeline = {}
60
+ def setobjects(self, objs:dict):
61
+ self.objectids = objs
62
+ def export_gmd(self, filedata, filename:str="Level"):
63
+ with open(f"{filename}.gmd", "w", encoding="utf-8") as f:
64
+ f.write(filedata)
65
+ def setparams(self, params:dict):
66
+ self.params = params
67
+
68
+ def format_groups(self, group_list):
69
+ if not group_list:
70
+ return ""
71
+ return ".".join(map(str, group_list))
72
+ def get_free_group(self):
73
+ used_groups = set()
74
+ for obj in self.objects:
75
+ if "57" in obj:
76
+ parsed = Dashcode().parse_object_string(obj)
77
+ for i2,v2 in parsed.items():
78
+ #print(i,v,type(i))
79
+ if i2 == "57":
80
+ for v in v2.split("."):
81
+ used_groups.add(int(v))
82
+ current_id = 1
83
+ while current_id in used_groups:
84
+ current_id += 1
85
+ return str(current_id)
86
+
87
+ def addobject(self, obj, params: dict):
88
+ if len(self.objects) <= 0:
89
+ self.objects.append(f"1,1,2,{-10 * 30},3,{-10 * 30},12,1,13,1")
90
+ extraparams = ""
91
+ for param, value in params.items():
92
+ if param in ["X", "Y", "EX", "EY"]:
93
+ continue
94
+ target_id = None
95
+ for i, v in self.params.items():
96
+ if str(param).startswith(str(i)):
97
+ target_id = v
98
+ break
99
+ if target_id is not None:
100
+ if target_id == 57 and isinstance(value, list):
101
+ extraparams += f",57,{self.format_groups(value)}"
102
+ else:
103
+ extraparams += f",{target_id},{value}"
104
+ else:
105
+ extraparams += f",{param},{value}"
106
+ oid = self.objectids.get(obj, obj)
107
+ pos_x = params.get('X', 0) * 30 + 15
108
+ pos_y = params.get('Y', 0) * 30 + 15
109
+ full_obj_string = f"1,{oid},2,{pos_x},3,{pos_y}{extraparams}"
110
+ self.objects.append(full_obj_string)
111
+ def parse_object_string(self,objstr):
112
+ data = objstr.split(',')
113
+ obj_dict = {}
114
+ for i in range(0, len(data) - 1, 2):
115
+ key = data[i]
116
+ value = data[i + 1]
117
+ obj_dict[key] = value
118
+ return obj_dict
119
+
120
+ def addprefab(self, obj: str, params: dict, prefab: str):
121
+ fab = self.prefabs.get(prefab)
122
+ if not fab:
123
+ return
124
+ ex = params.get('EX', 0)
125
+ ey = params.get('EY', 0)
126
+ base_x = params.get('X', 0)
127
+ base_y = params.get('Y', 0)
128
+ def place(x_val, y_val):
129
+ current_params = dict(params)
130
+ current_params["X"] = x_val
131
+ current_params["Y"] = y_val
132
+ self.addobject(obj, current_params)
133
+ if fab.get("X") == 0:
134
+ for i in range(ex):
135
+ place(base_x + i, base_y)
136
+ elif fab.get("Y") == 0:
137
+ for i in range(ey):
138
+ place(base_x, base_y + i)
139
+ elif fab.get("SQ") == 0:
140
+ for i in range(ex):
141
+ for v in range(ey):
142
+ place(base_x + i, base_y + v)
143
+ elif fab.get("X") == 1:
144
+ for i in range(ex):
145
+ place(base_x + i, base_y)
146
+ place(base_x + i, base_y + ey)
147
+ elif fab.get("Y") == 1:
148
+ for i in range(ey):
149
+ place(base_x, base_y + i)
150
+ place(base_x + ex, base_y + i)
151
+ def build_timeline(self, timeline:list):
152
+ cdelay = 0
153
+ for tlobj in timeline:
154
+ i = tlobj.get("Index")
155
+ v = tlobj.get("Value")
156
+ if i == "wait":
157
+ cdelay += v
158
+ elif i == "spawn":
159
+ self.addobject("spawn", {"X":-1, "Y":6, "Delay":str(cdelay),"TGroup":str(v)})
160
+ else:
161
+ params = {"X":-1,"Y":5}
162
+ for i2,v2 in v.items():
163
+ params[i2] = v2
164
+ self.addobject(i,params)
165
+ def create_gmd_file(self, level_name, objects_string):
166
+ global lvlname
167
+ lvlname = level_name
168
+ final_string_to_pack = objects_string
169
+ gzipped = gzip.compress(final_string_to_pack.encode('utf-8'))
170
+ b64_objects = base64.b64encode(gzipped).decode('utf-8').replace('/', '_').replace('+', '-')
171
+ return f'''<?xml version="1.0"?><plist version="1.0" gjver="2.0"><dict><k>kCEK</k><i>4</i><k>k2</k><s>{level_name}</s><k>k4</k><s>{b64_objects}</s><k>k5</k><s>Doesn't matter</s><k>k11</k><i>1091</i><k>k16</k><i>1</i><k>k80</k><i>56</i></dict></plist>'''
172
+
173
+ def decode_objects(self):
174
+ objects = self.objects
175
+ global obj_string
176
+ obj_string = ";".join(objects) + ";"
177
+ return obj_string
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dashcode
3
- Version: 1.2.4
3
+ Version: 1.2.6
4
4
  Summary: A library for Geometry Dash level generation using .gmd files
5
5
  Author: IWiterI
6
6
  Project-URL: Homepage, https://github.com/ISviterI/dashcode
@@ -8,7 +8,7 @@ if os.path.exists("README.md"):
8
8
 
9
9
  setup(
10
10
  name="dashcode",
11
- version="1.2.4",
11
+ version="1.2.6",
12
12
  packages=find_packages(),
13
13
  author="IWiterI",
14
14
  description="A library for Geometry Dash level generation using .gmd files",
@@ -1,166 +0,0 @@
1
- import base64
2
- import gzip
3
- obj_string = ""
4
- lvlname = ""
5
-
6
- class Dashcode:
7
- def __init__(self):
8
- self.objects = []
9
- self.params = {
10
- "NoTouch": 13,
11
- "Hide": 12,
12
- "Group": 57,
13
- "TGroup": 51,
14
- "Duration": 10,
15
- "Alpha": 11,
16
- "TouchTrigger": 11,
17
- "ActivateGroup": 56,
18
- "ScaleX": 128,
19
- "ScaleY": 129,
20
- "Zoom": 107,
21
- "RotateDegrees": 68,
22
- "Times360": 69,
23
- "LockRot": 70,
24
- "Red":7,
25
- "Green":8,
26
- "Blue":9,
27
- "Fade":10,
28
- "TargetColor":23,
29
- "Delay": 63,
30
- "SpawnTrigger":62,
31
- "MultiTrigger":87
32
- }
33
- self.objectids = {
34
- "block": 1, "spike": 8, "yorb": 36, "coin": 1329,
35
- "monster": 918, "bush": 128, "cloud": 129,
36
- "alpha": 1007, "toggle": 1049, "rotate": 1346,
37
- "zoom": 1913, "reverse": 1912,
38
- "checkpoint": 2063,
39
- "spawn":1268,
40
- "end": 3600,
41
- "p_blue": 10, "p_yellow": 11, "p_green": 2926,
42
- "p_cube": 12, "p_ship": 13, "p_ball": 47, "p_ufo": 111,
43
- "p_wave": 660, "p_robot": 745, "p_spider": 1331, "p_swing": 1933
44
- }
45
- self.prefabs = {
46
- "wall": {"Y":0},
47
- "platform": {"X":0},
48
- "square": {"SQ":0},
49
- "corridor": {"X":1},
50
- }
51
- self.timeline = {}
52
- def setobjects(self, objs:dict):
53
- self.objectids = objs
54
- def export_gmd(self, filedata, filename:str="Level"):
55
- with open(f"{filename}.gmd", "w", encoding="utf-8") as f:
56
- f.write(filedata)
57
- def setparams(self, params:dict):
58
- self.params = params
59
-
60
- def addobject(self, obj: str, params: dict):
61
- objects = self.objects
62
- if len(objects) <= 0:
63
- objects.append(
64
- f"1,1,2,{str(-10 * 30)},3,{str(-10 * 30)},12,1,13,1")
65
- extraparams = ""
66
- for param, value in params.items():
67
- if self.params.get(param) is not None:
68
- pid = self.params[param]
69
- extraparams += f",{str(pid)},{value}"
70
- else:
71
- extraparams += f",{str(param)},{value}"
72
-
73
- oid = self.objectids.get(obj, 1)
74
- if oid:
75
- objects.append(
76
- f"1,{str(oid)},2,{str(params.get('X') * 30 + 15)},3,{str(params.get('Y') * 30 + 15)}{extraparams}")
77
- else:
78
- objects.append(
79
- f"1,{str(obj)},2,{str(params.get('X') * 30 + 15)},3,{str(params.get('Y') * 30 + 15)}{extraparams}")
80
- def parse_object_string(self,objstr):
81
- data = objstr.split(',')
82
-
83
- obj_dict = {}
84
- for i in range(0, len(data) - 1, 2):
85
- key = data[i]
86
- value = data[i + 1]
87
- obj_dict[key] = value
88
-
89
- return obj_dict
90
- def addprefab(self, obj:str, params:dict, prefab:str):
91
- objects = self.objects
92
- extraparams = ""
93
- for param, value in params.items():
94
- if self.params.get(param) is not None:
95
- pid = self.params[param]
96
- extraparams += f",{str(pid)},{value}"
97
- else:
98
- extraparams += f",{str(param)},{value}"
99
-
100
- oid = self.objectids.get(obj, 1)
101
- if prefab:
102
- #print("1")
103
- fab = self.prefabs.get(prefab)
104
- if fab:
105
- #print(fab)
106
- #print("2")
107
- newobjs = []
108
- if fab.get("X") == 0:
109
- #print("3")
110
- for i in range(params.get('EX')):
111
- newobjs.append(
112
- f"1,{str(oid)},2,{str(params.get('X') * 30 + 15 + (i * 30))},3,{str(params.get('Y') * 30 + 15)}{extraparams}")
113
- if fab.get("Y") == 0:
114
- #print("3")
115
- for i in range(params.get('EY')):
116
- newobjs.append(
117
- f"1,{str(oid)},2,{str(params.get('X') * 30 + 15)},3,{str(params.get('Y') * 30 + 15 + (i * 30))}{extraparams}")
118
- if fab.get("SQ") == 0:
119
- for i in range(params.get('EX')):
120
- newobjs.append(
121
- f"1,{str(oid)},2,{str(params.get('X') * 30 + 15 + (i * 30))},3,{str(params.get('Y') * 30 + 15)}{extraparams}")
122
- for v in range(params.get('EY') - 1):
123
- newobjs.append(
124
- f"1,{str(oid)},2,{str(params.get('X') * 30 + 15 + (i * 30))},3,{str(params.get('Y') * 30 + 15 + (v * 30) + 30)}{extraparams}")
125
- if fab.get("X") == 1:
126
- for i in range(params.get('EX')):
127
- newobjs.append(
128
- f"1,{str(oid)},2,{str(params.get('X') * 30 + 15 + (i * 30))},3,{str(params.get('Y') * 30 + 15)}{extraparams}")
129
- for i in range(params.get('EX')):
130
- newobjs.append(
131
- f"1,{str(oid)},2,{str(params.get('X') * 30 + 15 + (i * 30))},3,{str(params.get('Y') * 30 + 15 + params.get("EY") * 30)}{extraparams}")
132
- if fab.get("Y") == 1:
133
- for i in range(params.get('EY')):
134
- newobjs.append(
135
- f"1,{str(oid)},2,{str(params.get('X') * 30 + 15)},3,{str(params.get('Y') * 30 + 15 + (i * 30))}{extraparams}")
136
- for i in range(params.get('EY')):
137
- newobjs.append(
138
- f"1,{str(oid)},2,{str(params.get('X') * 30 + 15 + params.get("EX") * 30)},3,{str(params.get('Y') * 30 + 15 + (i * 30))}{extraparams}")
139
- objects += newobjs
140
- def build_timeline(self, timeline:list):
141
- cdelay = 0
142
- for tlobj in timeline:
143
- i = tlobj.get("Index")
144
- v = tlobj.get("Value")
145
- if i == "wait":
146
- cdelay += v
147
- elif i == "spawn":
148
- self.addobject("spawn", {"X":-1, "Y":6, "Delay":str(cdelay),"TGroup":str(v)})
149
- else:
150
- params = {"X":-1,"Y":5}
151
- for i2,v2 in v.items():
152
- params[i2] = v2
153
- self.addobject(i,params)
154
- def create_gmd_file(self, level_name, objects_string):
155
- global lvlname
156
- lvlname = level_name
157
- final_string_to_pack = objects_string
158
- gzipped = gzip.compress(final_string_to_pack.encode('utf-8'))
159
- b64_objects = base64.b64encode(gzipped).decode('utf-8').replace('/', '_').replace('+', '-')
160
- return f'''<?xml version="1.0"?><plist version="1.0" gjver="2.0"><dict><k>kCEK</k><i>4</i><k>k2</k><s>{level_name}</s><k>k4</k><s>{b64_objects}</s><k>k5</k><s>Doesn't matter</s><k>k11</k><i>1091</i><k>k16</k><i>1</i><k>k80</k><i>56</i></dict></plist>'''
161
-
162
- def decode_objects(self):
163
- objects = self.objects
164
- global obj_string
165
- obj_string = ";".join(objects) + ";"
166
- return obj_string
File without changes
File without changes
File without changes