kapstok / NHL-DePa2 (public) (License: Unspecified) (since 2018-11-09) (hash sha1)
Design Patterns school project; a GUI using multiple Design Patterns.
List of commits:
Subject Hash Author Date (UTC)
Fix file I/O for single entities. 093b7d31a215067212927b1d92bdbbee306ea345 Jan Allersma 2018-11-06 16:49:55
Fix file I/O issue. 25c0b40db223c806eb3ea8bd28238dedc38ca8b5 Jan Allersma 2018-11-02 16:22:59
Cleanup commenting. 445aea4a5115c9110a097bfc7ac9f7d5ad48a9e7 Jan Allersma 2018-11-02 14:33:08
Show Ornaments on Canvas. d8456f15d69550c4cb0aa615cccb96b45a77f6a6 Jan Allersma 2018-11-02 14:08:47
Support Entities for Create & Destruct commands. cc900579eedf9c6288ce1c1883122856794e05a0 Jan Allersma 2018-11-02 13:25:43
Use entities instead of shapes when constructing ornaments. 13f08847624489f60a37db55c2aedbba6b021f98 Jan Allersma 2018-11-01 17:02:47
Remove obsolete 'calcBounds' function. 475ec330736b5800d12d091415480b163dd244e2 Jan Allersma 2018-11-01 14:28:29
Setup for decorator pattern. 762914dec31b1fb1d4cf6bb0cef2e148010652a4 Jan Allersma 2018-11-01 14:12:51
Revert commit '5678eb6'. 6225242719b2cfc5ee0de9f8d05edbc7a69007a7 Jan Allersma 2018-11-01 14:10:27
Make groups movable and resizable. 1ca7c18ab103a8d1055b27f63192038fd75aef3e Jan Allersma 2018-10-17 14:51:32
Use translations instead of positions for moving shapes. 9551c7d2608f01c3950743fd97bd217aab8f5766 Jan Allersma 2018-10-16 16:11:03
Implement Visitor pattern for Groups. bd30477ce616362d3f58cef072d1ebc78077fa85 Jan Allersma 2018-10-16 13:28:37
Implement Visitor pattern for Shapes. e52412c3059c1ee5fa9abdf4a32db0f47981eee1 Jan Allersma 2018-10-16 12:43:17
Setup 'Decorator' and 'Ornament' class. 5678eb6257bcf88502078d08395a394a1c24568b Jan Allersma 2018-10-09 09:29:50
Use different strats instead of seperate Shapes. a56e1e665a0292d15139eddfd8ebdeb8c95251b4 Jan Allersma 2018-10-01 11:37:45
Make ornament interface compatible with Entities. 21383d5f200a338f8255d7d33b6989937c19fed6 Jan Allersma 2018-10-08 20:36:23
Fix bug in Rect from commit 6c91140 in other Shapes as well. 4165a5da98dd9a548a222c6160390e4e54026d48 Jan Allersma 2018-09-28 14:53:40
Build interface for ornament creation. adcf22a4e878edc45ac0775a5e15ebf0bb1a937d Jan Allersma 2018-10-08 13:53:52
Fully implement File I/O. 45cbb48489a24857cfc76144b38b12ccebfd9e61 Jan Allersma 2018-09-27 16:03:40
Fix GroupMenu bug. be41e51819be1a23e7761ea0662eb188ac641aca Jan Allersma 2018-09-27 14:55:20
Commit 093b7d31a215067212927b1d92bdbbee306ea345 - Fix file I/O for single entities.
Author: Jan Allersma
Author date (UTC): 2018-11-06 16:49
Committer name: Jan Allersma
Committer date (UTC): 2018-11-06 16:55
Parent(s): 25c0b40db223c806eb3ea8bd28238dedc38ca8b5
Signing key:
Tree: 21ba5ac0c92d72ae55b1f3baefc9f730c0dd466e
File Lines added Lines deleted
source/commands/load.d 15 15
source/entities/ornament.d 1 1
source/file.d 68 66
source/history.d 1 1
File source/commands/load.d changed (mode: 100644) (index 454a67f..395d82e)
1 1 module dp.command.load; module dp.command.load;
2 2
3 3 import dp.command.cmd; import dp.command.cmd;
4 import dp.ent.shape;
4 import dp.ent.entity;
5 5 import dp.visitor.save; import dp.visitor.save;
6 6
7 7 import Global = dp.global; import Global = dp.global;
8 8
9 9 public class LoadCmd : Command { public class LoadCmd : Command {
10 private Shape[] shapes;
10 private Entity[] entities;
11 11
12 this(Shape[] shapes) {
13 this.shapes = shapes;
12 this(Entity[] entities) {
13 this.entities = entities;
14 14 execute(); // Obsolete, but remained for consistency between 'Command' classes. execute(); // Obsolete, but remained for consistency between 'Command' classes.
15 15 } }
16 16
17 17 public override void execute() { public override void execute() {
18 foreach(s; shapes)
19 s.active = true;
18 foreach(e; entities)
19 e.active = true;
20 20 } }
21 21
22 22 public override void undo() { public override void undo() {
23 foreach(s; shapes)
24 s.active = false;
23 foreach(e; entities)
24 e.active = false;
25 25 } }
26 26
27 27 public override void render() { public override void render() {
28 foreach(s; shapes)
29 s.render();
28 foreach(e; entities)
29 e.render();
30 30 } }
31 31
32 32 public override void check(int x, int y) { public override void check(int x, int y) {
33 foreach(s; shapes)
34 s.checkBounds(x,y);
33 foreach(e; entities)
34 e.checkBounds(x,y);
35 35 } }
36 36
37 37 // Should be done by Visitor self. // Should be done by Visitor self.
38 38 public override void save(Savefile file) { public override void save(Savefile file) {
39 foreach(s; shapes) {
40 if(s.group is null)
41 s.accept(new SaveVisitor(file));
39 foreach(e; entities) {
40 if(e.group is null)
41 e.accept(new SaveVisitor(file));
42 42 } }
43 43 } }
44 44 } }
File source/entities/ornament.d changed (mode: 100644) (index 2fd109b..08bc9a6)
... ... class Ornament : Entity {
42 42
43 43 @property @property
44 44 public override string to_string() { public override string to_string() {
45 return type ~ " " ~ alignment ~ " " ~ value;
45 return type ~ " " ~ alignment ~ " " ~ value ~ "\n";
46 46 } }
47 47
48 48 public override void accept(Visitor v) { public override void accept(Visitor v) {
File source/file.d changed (mode: 100644) (index 6994ac5..84876e4)
... ... import std.conv;
6 6 import std.array; import std.array;
7 7 import std.string; import std.string;
8 8
9 import dp.ent.entity, dp.ent.group, dp.ent.shape;
9 import dp.ent.entity, dp.ent.group, dp.ent.shape, dp.ent.ornament;
10 import dp.dec.entornament;
10 11 import dp.strat.rect; import dp.strat.rect;
11 12 import dp.strat.circle; import dp.strat.circle;
12 13 import dp.strat.ellipse; import dp.strat.ellipse;
 
... ... public class Savefile {
29 30 } }
30 31
31 32 public void load() { public void load() {
32 Entity e;
33 Shape[] entities = [];
33 Entity[] entities = [];
34 34
35 35 Global.Groups.clear(); Global.Groups.clear();
36 36 File f = File(filename, "r"); File f = File(filename, "r");
37 e = fromFile(f, entities);
38
39 while(e !is null)
40 e = fromFile(f, entities);
37 fromFile(f, entities);
41 38
42 39 f.close(); f.close();
43 40
 
... ... public class Savefile {
54 51 content = ""; content = "";
55 52 } }
56 53
57 private Shape parseLine(string line) {
58 auto words = line.split();
59
60 writeln(words);
54 private EntityOrnament parseShape(string shape, string x, string y, string size) {
55 Shape s;
61 56
62 final switch(words[0]) {
57 final switch(shape) {
63 58 case "rectangle": case "rectangle":
64 return new Shape (
65 to!int(words[1]),
66 to!int(words[2]),
67 Global.canvas.newContext,
68 rect,
69 to!double(words[3])
70 );
59 s = new Shape (
60 to!int(x),
61 to!int(y),
62 Global.canvas.newContext,
63 rect,
64 to!double(size)
65 );
66 break;
71 67 case "circle": case "circle":
72 return new Shape (
73 to!int(words[1]),
74 to!int(words[2]),
75 Global.canvas.newContext,
76 circle,
77 to!double(words[3])
78 );
68 s = new Shape (
69 to!int(x),
70 to!int(y),
71 Global.canvas.newContext,
72 circle,
73 to!double(size)
74 );
75 break;
79 76 case "ellipse": case "ellipse":
80 return new Shape (
81 to!int(words[1]),
82 to!int(words[2]),
83 Global.canvas.newContext,
84 ellipse,
85 to!double(words[3])
86 );
77 s = new Shape (
78 to!int(x),
79 to!int(y),
80 Global.canvas.newContext,
81 ellipse,
82 to!double(size)
83 );
84 break;
87 85 } }
86 return new EntityOrnament(s);
88 87 } }
89 88
90 private Entity fromFile(ref File f, ref Shape[] shapes) {
91 int depth = 0;
92 Group group;
89 private void fromFile(ref File f, ref Entity[] entities) {
90 string type;
93 91 string line; string line;
94 92
95 if(f.eof) return null;
96 line = strip(f.readln());
97 if(line == "") return null;
98
99 depth = groupsize(line);
100
101 if(depth > 0) {
102 group = Global.Groups.newGroup;
103
104 for(int i = 0; i < depth; i++) {
105 Entity e = fromFile(f,shapes);
106 if(e is null) return group;
107 else group.add(e);
93 while(!f.eof) {
94 line = strip(f.readln());
95 if(line == "") return;
96
97 entities.length++;
98 auto words = line.split();
99
100 switch(words[0]) {
101 case "group":
102 Entity[] e;
103 entities[entities.length - 1] = Global.Groups.newGroup;
104 fromFile(f,e);
105 foreach(entity; e)
106 (cast(Group)entities[entities.length - 1]).add(entity);
107 writeln("F: group");
108 break;
109 case "rectangle":
110 case "circle":
111 case "ellipse":
112 entities[entities.length - 1] = parseShape(
113 words[0], words[1], words[2], words[3]
114 );
115 writeln("F: shape");
116 break;
117 case "ornament":
118 EntityOrnament eo = new EntityOrnament(entities[entities.length - 2]);
119 eo.setOrnament(new Ornament(eo, words[1], words[2], Global.canvas.newContext));
120 entities[entities.length - 1] = eo;
121 writeln("F: ornament");
122 break;
123 default:
124 writeln("ERROR: unsupported type in 'dp.file.fromFile'!");
125 writeln("Loading aborted.");
126 return;
108 127 } }
109
110 return group;
111 } else {
112 shapes.length++;
113 shapes[shapes.length - 1] = parseLine(line);
114 write("SHAPES: ");
115 writeln(shapes);
116 return shapes[shapes.length - 1];
117 128 } }
118 129 } }
119
120 private int groupsize(string line) {
121 auto words = line.split();
122
123 if(words[0] != "group")
124 return 0;
125
126 return to!int(words[1]);
127 }
128 130 } }
File source/history.d changed (mode: 100644) (index e06e183..a69563a)
... ... static class History {
71 71 command.save(file); command.save(file);
72 72
73 73 foreach(group; Global.Groups.get) { foreach(group; Global.Groups.get) {
74 if(group.group !is null)
74 if(group.group is null)
75 75 file.toFile(group); file.toFile(group);
76 76 } }
77 77
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/kapstok/NHL-DePa2

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/kapstok/NHL-DePa2

Clone this repository using git:
git clone git://git.rocketgit.com/user/kapstok/NHL-DePa2

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main