From 7c8c897d60f9114a96e781ec5ced058d405bc4f4 Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Mon, 22 Nov 2021 12:25:48 -0500 Subject: [PATCH] Modularizing the code. --- .../SfOracle.class/instance/fromDictionary..st | 18 +++++------------- .../instance/optionsFromDictionary..st | 12 ++++++++++++ 2 files changed, 17 insertions(+), 13 deletions(-) create mode 100644 RoloLudo.package/SfOracle.class/instance/optionsFromDictionary..st diff --git a/RoloLudo.package/SfOracle.class/instance/fromDictionary..st b/RoloLudo.package/SfOracle.class/instance/fromDictionary..st index b5f081e..85239da 100644 --- a/RoloLudo.package/SfOracle.class/instance/fromDictionary..st +++ b/RoloLudo.package/SfOracle.class/instance/fromDictionary..st @@ -1,16 +1,8 @@ accessing fromDictionary: aDictionary - | optionsTable | - name := aDictionary at: 'Name' ifAbsent: [ name := aDictionary at: 'Display name' ]. + + name := aDictionary + at: 'Name' + ifAbsent: [ name := aDictionary at: 'Display name' ]. intro := aDictionary at: 'Description'. - optionsTable := aDictionary at: 'Table'. - optionsTable doWithIndex: [:opt :i | | key value prevKey | - (i = 1) - ifTrue: [key := 1 to: (opt at: 'Chance') asInteger] - ifFalse: [ - prevKey := ((optionsTable at: (i-1)) at: 'Chance'). - key := (prevKey asInteger + 1) to: (opt at: 'Chance') asInteger. - ]. - value := (opt at: 'Description') capitalized. - self options at: key put: value . - ]. \ No newline at end of file + self optionsFromDictionary: (aDictionary at: 'Table') \ No newline at end of file diff --git a/RoloLudo.package/SfOracle.class/instance/optionsFromDictionary..st b/RoloLudo.package/SfOracle.class/instance/optionsFromDictionary..st new file mode 100644 index 0000000..d048d70 --- /dev/null +++ b/RoloLudo.package/SfOracle.class/instance/optionsFromDictionary..st @@ -0,0 +1,12 @@ +accessing +optionsFromDictionary: aDictionary + + aDictionary doWithIndex: [ :opt :i | + | key value prevKey | + i = 1 + ifTrue: [ key := 1 to: (opt at: 'Chance') asInteger ] + ifFalse: [ + prevKey := (aDictionary at: i - 1) at: 'Chance'. + key := prevKey asInteger + 1 to: (opt at: 'Chance') asInteger ]. + value := (opt at: 'Description') capitalized. + self options at: key put: value ] \ No newline at end of file