Skip to content

Commit

Permalink
Merge pull request #44 from hpi-swa-teaching/save_json
Browse files Browse the repository at this point in the history
Save json
  • Loading branch information
nick-bessin committed May 23, 2021
2 parents 5aeaf60 + 2caef76 commit 0170bcb
Show file tree
Hide file tree
Showing 40 changed files with 437 additions and 12 deletions.
6 changes: 3 additions & 3 deletions .squot
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
OrderedDictionary {
'packages\/BaselineOfAnimationsEditor.package' : #SquotCypressCodeSerializer,
'packages\/AnimationsEditor-Tests.package' : #SquotCypressCodeSerializer,
'packages\/AnimationsEditor-Core.package' : #SquotCypressCodeSerializer
'packages/BaselineOfAnimationsEditor.package' : #SquotCypressCodeSerializer,
'packages/AnimationsEditor-Tests.package' : #SquotCypressCodeSerializer,
'packages/AnimationsEditor-Core.package' : #SquotCypressCodeSerializer
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
saveJson
addColorFrame: aTreeNode
| jsonFrame |

jsonFrame := Dictionary
with: #frame -> aTreeNode targetDuration
with: #properties -> {
Dictionary
with: #name -> aTreeNode title asLowercase
with: #value -> aTreeNode targetColor rgbTriplet.
}.

^ jsonFrame.


Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
saveJson
addFrame: aTreeNode

^ { #Position -> [self addPositionFrame: aTreeNode].
#Color -> [self addColorFrame: aTreeNode].
#Rotation -> [self addRotationFrame: aTreeNode].
#Size -> [self addSizeFrame: aTreeNode]. } as: IdentityDictionary.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
saveJson
addMorphToJson: aJsonStructure with: aTreeNode
| frame MorphJson originMorph |

originMorph := aTreeNode copyOfTargetMorph.
MorphJson := self createStartInformation: originMorph.
frame := ((self addFrame: aTreeNode) at: aTreeNode title asSymbol) value.
MorphJson add: #frames -> {frame}.
aJsonStructure add: #morphs -> {MorphJson}.

^ aJsonStructure.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
saveJson
addPositionFrame: aTreeNode
| jsonFrame |

jsonFrame := Dictionary
with: #frame -> aTreeNode targetDuration
with: #properties -> {
Dictionary
with: #name -> (aTreeNode title asLowercase , 'X')
with: #value -> aTreeNode targetPosition x.
Dictionary
with: #name -> (aTreeNode title asLowercase, 'Y')
with: #value -> aTreeNode targetPosition y.
}.

^ jsonFrame.


Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
saveJson
addRotationFrame: aTreeNode
| jsonFrame |

jsonFrame := Dictionary
with: #frame -> aTreeNode targetDuration
with: #properties -> {
Dictionary
with: #name -> aTreeNode title asLowercase
with: #value -> aTreeNode targetRotation.
}.

^ jsonFrame.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
saveJson
addSizeFrame: aTreeNode
| jsonFrame |

jsonFrame := Dictionary
with: #frame -> aTreeNode targetDuration
with: #properties -> {
Dictionary
with: #name -> 'width'
with: #value -> aTreeNode targetSize x.
Dictionary
with: #name -> 'height'
with: #value -> aTreeNode targetSize y.
}.

^ jsonFrame.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
saveJson
createStartInformation: aMorph

^ Dictionary
with: #type -> aMorph class asString
with: #properties -> {
Dictionary
with: #name -> 'rotation'
with: #value -> aMorph rotationDegrees.
Dictionary
with: #name -> 'positionX'
with: #value -> aMorph x.
Dictionary
with: #name -> 'positionY'
with: #value -> aMorph y.
Dictionary
with: #name -> 'width'
with: #value -> aMorph width.
Dictionary
with: #name -> 'height'
with: #value -> aMorph height.
Dictionary
with: #name -> 'color'
with: #value -> aMorph color rgbTriplet.
}.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
saveJson
createStructure: aStartTime with: anEndTime
| jsonStructure |

jsonStructure := Dictionary
with: #start -> aStartTime
with: #end -> anEndTime
with: #morphs -> {}.

^ jsonStructure.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
saveJson
dictionaryToJson: aDictionary
^ String streamContents: [ :stream |
(STON writer on: stream)
prettyPrint: true;
jsonMode: true;
referencePolicy: #error;
nextPut: aDictionary ].
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
saveJson
outputFileDirectory
^ UIManager default saveFilenameRequest: 'Please, enter file name.' initialAnswer: 'animation'.


Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
eventHandling
saveAnimations
self updateInformationText: 'Copied animation code to clipboard!'.
Clipboard clipboardText: self selectedTreeNode animationString.
Clipboard clipboardText: self selectedTreeNode animationString.
self saveToJson: self selectedTreeNode.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
saveJson
saveToJson: aTreeNode
| jsonStructure jsonString |

jsonStructure := self createStructure: self propertyStartEnd startTime with: self propertyStartEnd endTime.
jsonStructure := self addMorphToJson: jsonStructure with: aTreeNode.
jsonString := self dictionaryToJson: jsonStructure.
self writeJsonToFile: jsonString with: self outputFileDirectory.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
saveJson
writeJsonToFile: aJsonString with: aDirectory
aDirectory
ifNotNil: [
FileDirectory default forceNewFileNamed: aDirectory, '.json' do: [:stream |
stream nextPutAll: aJsonString].
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
"class" : {
"open" : "DM 8/4/2020 13:18" },
"instance" : {
"addColorFrame:" : "MH 5/20/2021 09:25",
"addFrame:" : "NB 5/12/2021 09:25",
"addMorphToJson:with:" : "MH 5/15/2021 11:15",
"addPositionFrame:" : "MH 5/20/2021 09:32",
"addRotationFrame:" : "NB 5/19/2021 12:43",
"addSelectedMorphFor:" : "DM 8/5/2020 21:11",
"addTargetMorph:" : "DM 8/7/2020 21:26",
"addSizeFrame:" : "NB 5/19/2021 12:43",
"addTargetMorph:" : "MH 5/13/2021 11:32",
"addTimeline" : "DM 8/7/2020 21:26",
"buildAddMorphButtonWith:" : "LH 8/4/2020 15:42",
"buildButtonBarWith:" : "LH 8/4/2020 15:42",
Expand All @@ -23,8 +29,11 @@
"createPositionPropertyFrom:" : "DM 8/6/2020 10:09",
"createRotationPropertyFrom:" : "DM 7/8/2020 14:29",
"createSizePropertyFrom:" : "DM 7/8/2020 14:29",
"createStartInformation:" : "MH 5/20/2021 11:24",
"createStructure:with:" : "NB 5/13/2021 10:25",
"defaultEmptyPanels" : "DM 8/7/2020 17:37",
"defaultPropertyPanelPosition" : "DM 8/6/2020 10:38",
"dictionaryToJson:" : "NB 5/12/2021 09:37",
"editorTitle" : "LH 8/4/2020 10:31",
"editorTitle:" : "DM 8/3/2020 15:40",
"emptyPanels" : "DM 8/7/2020 17:37",
Expand All @@ -40,7 +49,8 @@
"insertMorph:Into:" : "JIZ 6/3/2020 16:56",
"mainWindow" : "JIZ 6/3/2020 17:04",
"mainWindow:" : "JIZ 6/3/2020 17:04",
"playAnimations" : "DM 8/5/2020 20:04",
"outputFileDirectory" : "NB 5/21/2021 09:07",
"playAnimations" : "MH 5/10/2021 11:48",
"propertyEditorPanel" : "DM 6/22/2020 01:27",
"propertyEditorPanel:" : "DM 6/12/2020 20:41",
"propertyEditorPanelChildren" : "DM 6/22/2020 01:27",
Expand All @@ -52,7 +62,8 @@
"propertyTreeMorph" : "DM 6/22/2020 01:28",
"propertyTreeMorph:" : "DM 6/18/2020 08:59",
"resetTargetMorph" : "DM 8/5/2020 20:05",
"saveAnimations" : "DM 8/4/2020 16:18",
"saveAnimations" : "NB 5/13/2021 09:35",
"saveToJson:" : "NB 5/21/2021 09:05",
"seedProperties" : "DM 8/5/2020 19:54",
"selectMorphByHand" : "DM 8/5/2020 20:07",
"selectedTreeNode" : "JIZ 5/27/2020 15:31",
Expand All @@ -63,4 +74,5 @@
"toolBuilder:" : "JIZ 6/3/2020 16:59",
"updateInformationText:" : "DM 8/4/2020 16:18",
"windowReference" : "DM 8/4/2020 13:19",
"windowReference:" : "DM 8/4/2020 13:19" } }
"windowReference:" : "DM 8/4/2020 13:19",
"writeJsonToFile:with:" : "NB 5/21/2021 08:39" } }
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"buildUIWith:" : "JIZ 6/3/2020 17:10",
"canCreateAnimation" : "DM 8/6/2020 10:26",
"canRenderUI" : "DM 8/5/2020 21:07",
"createAnimationFor:" : "DM 8/6/2020 10:21",
"createAnimationFor:" : "MH 5/13/2021 11:28",
"createAnimationFor:withDuration:" : "DM 8/6/2020 11:03",
"defaultTargetPosition" : "DM 8/6/2020 10:44",
"initialize" : "DM 8/6/2020 10:08",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
animationsEditorInstance: anObject

animationsEditorInstance := anObject.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
animationsEditorInstance

^ animationsEditorInstance
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
saveJson
colorFrameDictionary

^ Dictionary
with: #frame->500
with: #properties->{
Dictionary
with: #name->'color'
with: #value-> #(1.0 0.0 0.0).
}.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
saveJson
colorTreeNode
| aTreeNode animationsEditorProperty |

animationsEditorProperty := self animationsEditorInstance propertyList at: 2.
aTreeNode := AnimationsEditorPropertyColor new.
aTreeNode
copyOfTargetMorph: animationsEditorProperty targetMorph;
targetMorph: aTreeNode copyOfTargetMorph copy.
aTreeNode targetMorph color: Color red.
aTreeNode
targetDuration: animationsEditorProperty defaultTargetDuration;
targetColor: 'red'.

^ aTreeNode.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
saveJson
positionFrameDictionary
^ Dictionary
with: #frame -> 500
with: #properties -> {
Dictionary
with: #name -> 'positionX'
with: #value -> 100.
Dictionary
with: #name -> 'positionY'
with: #value -> 200.
}.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
saveJson
positionTreeNode
| aTreeNode animationsEditorProperty |

animationsEditorProperty := self animationsEditorInstance propertyList at: 2.
aTreeNode := AnimationsEditorPropertyPosition new.
aTreeNode
copyOfTargetMorph: animationsEditorProperty targetMorph;
targetMorph: aTreeNode copyOfTargetMorph copy.
aTreeNode targetMorph position: 100 @ 200.
aTreeNode
targetDuration: animationsEditorProperty defaultTargetDuration;
targetPosition: 100 @ 200.

^ aTreeNode.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
saveJson
rotationFrameDictionary
^ Dictionary
with: #frame -> 500
with: #properties -> {
Dictionary
with: #name -> 'rotation'
with: #value -> 70.
}.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
saveJson
rotationTreeNode
| aTreeNode animationsEditorProperty |

animationsEditorProperty := self animationsEditorInstance propertyList at: 2.
aTreeNode := AnimationsEditorPropertyRotation new.
aTreeNode
copyOfTargetMorph: animationsEditorProperty targetMorph;
targetMorph: aTreeNode copyOfTargetMorph copy.
aTreeNode targetMorph rotationDegrees: 70.
aTreeNode
targetDuration: animationsEditorProperty defaultTargetDuration;
targetRotation: 70.

^ aTreeNode.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
saveJson
setUp
| morph |

super setUp.
self animationsEditorInstance: AnimationsEditor open.
morph := Morph new.
morph openInWorld.
animationsEditorInstance addTargetMorph: morph.


Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
saveJson
sizeFrameDictionary
^ Dictionary
with: #frame -> 500
with: #properties -> {
Dictionary
with: #name -> 'width'
with: #value -> 100.
Dictionary
with: #name -> 'height'
with: #value -> 200.
}.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
saveJson
sizeTreeNode
| aTreeNode animationsEditorProperty |

animationsEditorProperty := self animationsEditorInstance propertyList at: 2.
aTreeNode := AnimationsEditorPropertySize new.
aTreeNode
copyOfTargetMorph: animationsEditorProperty targetMorph;
targetMorph: aTreeNode copyOfTargetMorph copy.
aTreeNode targetMorph extent: 100 @ 200.
aTreeNode
targetDuration: animationsEditorProperty defaultTargetDuration;
targetSize: 100 @ 200.

^ aTreeNode.
Loading

0 comments on commit 0170bcb

Please sign in to comment.