Skip to content

Commit 21b2fd5

Browse files
committed
0.1.1 alpha
1 parent 933a7e5 commit 21b2fd5

File tree

7 files changed

+95
-86
lines changed

7 files changed

+95
-86
lines changed

FinishedGame.gmx/FinishedGame.project.gmx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
<script>scripts\establishVariables.gml</script>
1313
</scripts>
1414
<objects name="objects">
15-
<object>objects\obj_test</object>
1615
</objects>
1716
<rooms name="rooms">
1817
<room>rooms\rm_stage</room>

FinishedGame.gmx/objects/obj_test.object.gmx

Lines changed: 0 additions & 47 deletions
This file was deleted.

FinishedGame.gmx/rooms/rm_stage.room.gmx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,4 @@
5050
<view visible="0" objName="&lt;undefined&gt;" xview="0" yview="0" wview="1024" hview="768" xport="0" yport="0" wport="1024" hport="768" hborder="32" vborder="32" hspeed="-1" vspeed="-1"/>
5151
<view visible="0" objName="&lt;undefined&gt;" xview="0" yview="0" wview="1024" hview="768" xport="0" yport="0" wport="1024" hport="768" hborder="32" vborder="32" hspeed="-1" vspeed="-1"/>
5252
</views>
53-
<instances/>
54-
<tiles/>
55-
<PhysicsWorld>0</PhysicsWorld>
56-
<PhysicsWorldTop>0</PhysicsWorldTop>
57-
<PhysicsWorldLeft>0</PhysicsWorldLeft>
58-
<PhysicsWorldRight>1024</PhysicsWorldRight>
59-
<PhysicsWorldBottom>768</PhysicsWorldBottom>
60-
<PhysicsWorldGravityX>0</PhysicsWorldGravityX>
61-
<PhysicsWorldGravityY>10</PhysicsWorldGravityY>
62-
<PhysicsWorldPixToMeters>0.100000001490116</PhysicsWorldPixToMeters>
63-
</room>
53+
<instances>

GrazeConvert.py

Lines changed: 79 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,40 @@
44
from pathlib import Path
55
with open('scratchproject/project.json') as whatsinhere:
66
gamecode = json.load(whatsinhere)
7+
def make_new_event():
8+
global neweventbaby
9+
neweventbaby = "<event eventtype=\""+str(eventtype)+"\" enumb=\""+str(enumb)+"\">\n <action>\n <libid>1</libid>\n <id>603</id>\n <kind>7</kind>\n <userelative>0</userelative>\n <isquestion>0</isquestion>\n <useapplyto>-1</useapplyto>\n <exetype>2</exetype>\n <functionname></functionname>\n <codestring></codestring>\n <whoName>self</whoName>\n <relative>0</relative>\n <isnot>0</isnot>\n <arguments>\n <argument>\n <kind>1</kind>\n <string>"
10+
def add_to_script():
11+
global writingin
12+
if writingin == "whenGreenFlag":
13+
global greenflag
14+
if greenflag == "":
15+
global eventtype
16+
global enumb
17+
eventtype = 7
18+
enumb = 4
19+
make_new_event()
20+
greenflag = neweventbaby
21+
if greenflag != "":
22+
global codetoadd
23+
greenflag += codetoadd
24+
def convert_block():
25+
global codetoadd
26+
codetoadd = ""
27+
#gotta figure out how to do this block lmao
28+
#if currentblock == 'doRepeat':
29+
# repeatfor = int(AllScripts[codeparse+1])
30+
if currentblock == 'whenGreenFlag':
31+
global writingin
32+
writingin = "whenGreenFlag"
33+
if currentblock == 'gotoXy':
34+
global codeparse
35+
daX = AllScripts[codeparse+1]
36+
daX = int(daX)+480
37+
daY = AllScripts[codeparse+2]
38+
daY = int(daY)+352
39+
codetoadd = "x = "+str(daX)+";\ny = "+str(daY)+";\n"
40+
add_to_script()
741
if ("objName" in gamecode):
842
spritemetadata = "";
943
soundmetadata = "";
@@ -26,13 +60,13 @@
2660
AllCostumes = gamecode['costumes']
2761
costumeamount = len(AllCostumes)
2862
subimage = 0
29-
thecostume = AllCostumes[i]
63+
thecostume = AllCostumes[0]
3064
rotX = thecostume['rotationCenterX']
3165
rotY = thecostume['rotationCenterY']
32-
costumeID = thecostume['baseLayerID']
33-
img = PIL.Image.open("scratchproject/"+str(costumeID)+".png")
34-
wid, hgt = img.size
35-
img.close()
66+
costumeID = (thecostume['baseLayerID'])
67+
imagez = PIL.Image.open("scratchproject/"+str(costumeID)+".png")
68+
wid, hgt = imagez.size
69+
imagez.close()
3670
spritemetadata += " <sprite>sprites\\spr_stage</sprite>\n";
3771
with open('FinishedGame.gmx/sprites/spr_stage.sprite.gmx','x') as f:
3872
f.write("<!--This Document is generated by GameMaker, if you edit it by hand then you do so at your own risk!-->\n<sprite>\n <type>0</type>\n <xorig>"+str(rotX)+"</xorig>\n <yorigin>"+str(rotY)+"</yorigin>\n <colkind>1</colkind>\n <coltolerance>0</coltolerance>\n <sepmasks>0</sepmasks>\n <bboxmode>0</bboxmode>\n <bbox_left>0</bbox_left>\n <bbox_right>"+str(wid-1)+"</bbox_right>\n <bbox_top>0</bbox_top>\n <bbox_bottom>"+str(hgt-1)+"</bbox_bottom>\n <HTile>0</HTile>\n <VTile>0</VTile>\n <TextureGroups>\n <TextureGroup0>0</TextureGroup0>\n </TextureGroups>\n <For3D>0</For3D>\n <width>960</width>\n <height>720</height>\n <frames>\n")
@@ -57,12 +91,16 @@
5791
varcode = varname+" = "+str(varvalue)+";\n"
5892
with open('FinishedGame.gmx/scripts/establishVariables.gml','a') as f:
5993
f.write(varcode)
60-
# Other Sprite Time!
94+
# Other Sprite Time!
95+
allobjmetadata = ""
96+
if ("children" in gamecode):
6197
AllObjects = gamecode['children']
6298
ObjectAmount = len(AllObjects)
6399
for i in range(ObjectAmount):
64100
if 'target' not in AllObjects[i]:#this wont trip up by having a sprite or sound in Scratch be named "target" will it?
65101
CurrentObject = AllObjects[i]
102+
ObjectX = CurrentObject['scratchX']
103+
ObjectY = CurrentObject['scratchY']
66104
# Import Sounds
67105
if ("sounds" in CurrentObject):
68106
print("Importing '"+str(CurrentObject['objName'])+"' sounds...")
@@ -110,26 +148,44 @@
110148
f.write(" </frames>\n</sprite>")
111149
# Start to make Object XML
112150
objectmetadata = "<!--This Document is generated by GameMaker, if you edit it by hand then you do so at your own risk!-->\n<object>\n <spriteName>spr_"+str(CurrentObject['objName'])+"</spriteName>\n <solid>0</solid>\n <visible>-1</visible>\n <depth>0</depth>\n <persistent>0</persistent>\n <parentName>&lt;undefined&gt;</parentName>\n <maskName>&lt;undefined&gt;</maskName>\n <events>\n "
113-
# Game Code, Baby (this stuff doesn't work right now D:)
114-
#greenflag = ""
115-
#if ("scripts" in CurrentObject):
116-
# CurrentScripts = CurrentObject['scripts']
117-
# ScriptAmount = len(CurrentScripts)
118-
# for i in range (ScriptAmount):
119-
# if ("whenGreenFlag" in CurrentScripts[i]):
120-
# if (greenflag == ""):
121-
# greenflag = "<event eventtype=\"0\" enumb=\"0\">\n <action>\n <libid>1</libid>\n <id>603</id>\n <kind>7</kind>\n <userelative>0</userelative>\n <isquestion>0</isquestion>\n <useapplyto>-1</useapplyto>\n <exetype>2</exetype>\n <functionname></functionname>\n <codestring></codestring>\n <whoName>self</whoName>\n <relative>0</relative>\n <isnot>0</isnot>\n <arguments>\n <argument>\n <kind>1</kind>\n <string>"
122-
# whatodo = CurrentScripts["whenGreenFlag"]
123-
# whatodolength = len(whatodo)
124-
# for e in range (whatodolength):
125-
# if ("gotoX:y:" in whatodo[i]):
126-
# greenflag += ""
127-
#Write Object Metadata
151+
# Object Code, Baby
152+
global greenflag
153+
greenflag = ""
154+
if ("scripts" in CurrentObject):
155+
print("Converting '"+str(CurrentObject['objName'])+"' code...")
156+
AllScripts = json.dumps(CurrentObject['scripts'])
157+
badchar = "[],:\""
158+
for character in badchar:
159+
AllScripts = AllScripts.replace(character,"")
160+
AllScripts = AllScripts.split()
161+
global codeparse
162+
global codetoadd
163+
codeparse = 0
164+
global eventtype
165+
global enumb
166+
eventtype = 0
167+
enumb = 0
168+
global writingin
169+
writingin = ""
170+
ScriptAmount = len(AllScripts)
171+
for i in range (ScriptAmount):
172+
currentblock = AllScripts[codeparse]
173+
convert_block()
174+
codeparse += 1
175+
if greenflag != "":
176+
greenflag += "</string>\n </argument>\n </arguments>\n </action>\n </event>\n"
177+
#Write Object Metadata & Write Object Into Room Metadata
178+
objectmetadata += ""+str(greenflag)+" </events>\n <PhysicsObject>0</PhysicsObject>\n <PhysicsObjectSensor>0</PhysicsObjectSensor>\n <PhysicsObjectShape>0</PhysicsObjectShape>\n <PhysicsObjectDensity>0.5</PhysicsObjectDensity>\n <PhysicsObjectRestitution>0.100000001490116</PhysicsObjectRestitution>\n <PhysicsObjectGroup>0</PhysicsObjectGroup>\n <PhysicsObjectLinearDamping>0.100000001490116</PhysicsObjectLinearDamping>\n <PhysicsObjectAngularDamping>0.100000001490116</PhysicsObjectAngularDamping>\n <PhysicsObjectFriction>0.200000002980232</PhysicsObjectFriction>\n <PhysicsObjectAwake>-1</PhysicsObjectAwake>\n <PhysicsObjectKinematic>0</PhysicsObjectKinematic>\n <PhysicsShapePoints/>\n</object>"
179+
allobjmetadata += " <object>objects\obj_"+str(CurrentObject['objName'])+"</object>\n"
128180
with open('FinishedGame.gmx/objects/obj_'+str(CurrentObject['objName'])+'.object.gmx','a') as f:
129181
f.write(str(objectmetadata))
130-
#Rewrite Main Game Metadata
182+
with open('FinishedGame.gmx/rooms/rm_stage.room.gmx','a') as f:
183+
f.write(' <instance objName=\"obj_'+str(CurrentObject['objName'])+'\" x=\"'+str(ObjectX+480)+'\" y=\"'+str(ObjectY+352)+'\" name=\"inst_'+str(CurrentObject['objName'])+'\" locked=\"0\" code=\"\" scaleX=\"1\" scaleY=\"1\" colour=\"4294967295\" rotation=\"0\"/>\n')
184+
#Rewrite Main Game and Room Metadata
131185
with open ('FinishedGame.gmx/FinishedGame.project.gmx','w') as f:
132-
f.write("<!--This Document is generated by GameMaker, if you edit it by hand then you do so at your own risk!-->\n<assets>\n <Configs name=\"configs\">\n <Config>Configs\Default</Config>\n </Configs>\n <NewExtensions/>\n <sounds name=\"sound\">\n"+str(soundmetadata)+" </sounds>\n <sprites name=\"sprites\">\n"+str(spritemetadata)+" </sprites>\n <backgrounds name=\"background\"/>\n <paths name=\"paths\"/>\n <scripts name=\"scripts\">\n <script>scripts\establishVariables.gml</script>\n </scripts>\n <rooms name=\"rooms\">\n <room>rooms\\rm_stage</room>\n </rooms>\n <help>\n <rtf>help.rtf</rtf>\n </help>\n <TutorialState>\n <IsTutorial>0</IsTutorial>\n <TutorialName></TutorialName>\n <TutorialPage>0</TutorialPage>\n </TutorialState>\n</assets>")
186+
f.write("<!--This Document is generated by GameMaker, if you edit it by hand then you do so at your own risk!-->\n<assets>\n <Configs name=\"configs\">\n <Config>Configs\Default</Config>\n </Configs>\n <NewExtensions/>\n <sounds name=\"sound\">\n"+str(soundmetadata)+" </sounds>\n <sprites name=\"sprites\">\n"+str(spritemetadata)+" </sprites>\n <backgrounds name=\"background\"/>\n <paths name=\"paths\"/>\n <scripts name=\"scripts\">\n <script>scripts\establishVariables.gml</script>\n </scripts>\n <objects name=\"objects\">\n"+str(allobjmetadata)+" </objects>\n <rooms name=\"rooms\">\n <room>rooms\\rm_stage</room>\n </rooms>\n <help>\n <rtf>help.rtf</rtf>\n </help>\n <TutorialState>\n <IsTutorial>0</IsTutorial>\n <TutorialName></TutorialName>\n <TutorialPage>0</TutorialPage>\n </TutorialState>\n</assets>")
187+
with open('FinishedGame.gmx/rooms/rm_stage.room.gmx','a') as f:
188+
f.write(' </instances>\n <tiles/>\n <PhysicsWorld>0</PhysicsWorld>\n <PhysicsWorldTop>0</PhysicsWorldTop>\n <PhysicsWorldLeft>0</PhysicsWorldLeft>\n <PhysicsWorldRight>1024</PhysicsWorldRight>\n <PhysicsWorldBottom>768</PhysicsWorldBottom>\n <PhysicsWorldGravityX>0</PhysicsWorldGravityX>\n <PhysicsWorldGravityY>10</PhysicsWorldGravityY>\n <PhysicsWorldPixToMeters>0.100000001490116</PhysicsWorldPixToMeters>\n</room>')
133189
print("*DING* Done!")
134190
else:
135191
print("ERROR: This Scratch project doesn't have a Stage from what we can tell. Is it a valid .sb2 file?")
-851 Bytes
Binary file not shown.

changelog.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
Alpha 0.1.1 (8/26/21):
2+
[Changes]
3+
* CODE SUPPORT BABY!!1
4+
Only two blocks supported right now but the functionality is THERE
5+
for adding more blocks!
6+
* Changed around the GameMaker project template a little I think?
7+
[Future Plans]
8+
* Add moar blocks!
9+
* can we optimize this code??? *thinking emoji*
10+
* I have an idea for Vector (.svg) sprites
11+
12+
113
Alpha 0.1 (8/15/21):
214
[Changes]
315
* Put the project up on GitHub! :D

compatibilitystatus.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
This is where I'd put my compatibility for Scratch blocks in Graze currently...IF I HAD ANY >:C
2-
3-
(Last updated 8/15/21)
1+
(Last updated 8/26/21)
42

53
[Motion]
4+
Go To X+Y
65

76
[Looks]
87

@@ -11,7 +10,7 @@ This is where I'd put my compatibility for Scratch blocks in Graze currently...I
1110
[Events]
1211

1312
[Control]
14-
When Green Flag Clicked - [Nope] (but let's do this first)
13+
When Green Flag Clicked
1514

1615
[Sensing]
1716

0 commit comments

Comments
 (0)