diff --git a/.gitignore b/.gitignore index 1cd7b4f..64452fc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ Export/ +out/ +.idea/ \#*\# diff --git a/Assets/test.json b/Assets/test.json new file mode 100644 index 0000000..956981a --- /dev/null +++ b/Assets/test.json @@ -0,0 +1,189 @@ +[ + { + "days": [ + { + "weekday": 2, + "time": "11:30-13:20" + }, + { + "weekday": 2, + "time": "14:00-15:00" + }, + { + "weekday": 4, + "time": "13:30-15:20" + } + ], + "start": { + "day": 28, + "month": 9, + "year": 2018 + }, + "end": { + "day": 1, + "month": 11, + "year": 2018 + }, + "homework": [ + [20, 6], + [10, 4], + [30, 3] + ], + "project": 100, + "exception": [3], + "title": "Drawing" + }, + { + "days": [ + { + "weekday": 1, + "time": "10:30-11:20" + }, + { + "weekday": 3, + "time": "10:30-11:20" + }, + { + "weekday": 5, + "time": "10:30-11:20" + }, + { + "weekday": 2, + "time": "15:00-15:30" + }, + { + "weekday": 4, + "time": "15:00-15:30" + } + ], + "start": { + "day": 28, + "month": 9, + "year": 2018 + }, + "end": { + "day": 1, + "month": 11, + "year": 2018 + }, + "homework": [ + [25, 6], + [5, 4], + [30, 3] + ], + "project": 1000, + "exception": [5], + "title": "Evolution and Ecology" + }, + { + "days": [ + { + "weekday": 2, + "time": "17:00-19:50" + } + ], + "start": { + "day": 28, + "month": 9, + "year": 2018 + }, + "end": { + "day": 1, + "month": 11, + "year": 2018 + }, + "homework": [ + [60, 10] + ], + "project": 0, + "exception": [3, 8, 2], + "title": "EE Lab" + }, + { + "days": [ + { + "weekday": 1, + "time": "9:30-10:20" + }, + { + "weekday": 3, + "time": "9:30-10:20" + }, + { + "weekday": 5, + "time": "9:30-10:20" + } + ], + "start": { + "day": 28, + "month": 9, + "year": 2018 + }, + "end": { + "day": 1, + "month": 11, + "year": 2018 + }, + "homework": [ + [25, 6], + [5, 4], + [30, 3] + ], + "project": 0, + "exception": [], + "title": "Chem" + }, + { + "days": [ + { + "weekday": 1, + "time": "18:00-20:50" + } + ], + "start": { + "day": 28, + "month": 9, + "year": 2018 + }, + "end": { + "day": 1, + "month": 11, + "year": 2018 + }, + "homework": [ + [60, 10] + ], + "project": 0, + "exception": [7, 4], + "title": "Chem Lab" + }, + { + "days": [ + { + "weekday": 2, + "time": "15:30-16:50" + }, + { + "weekday": 4, + "time": "15:30-16:50" + } + ], + "start": { + "day": 28, + "month": 9, + "year": 2018 + }, + "end": { + "day": 1, + "month": 11, + "year": 2018 + }, + "homework": [ + [0, 2], + [10, 20] + ], + "project": 0, + "exception": [4, 5], + "title": "How Things Work" + } +] diff --git a/Source/Assignment.hx b/Source/Assignment.hx index e16150c..d0e2cb8 100644 --- a/Source/Assignment.hx +++ b/Source/Assignment.hx @@ -5,8 +5,7 @@ import openfl.display.Shape; import openfl.text.TextField; import openfl.events.MouseEvent; -class Assignment extends Sprite -{ +class Assignment extends Sprite { private var rect:Shape; private var workRect:Shape; private var workSize:Float; @@ -16,64 +15,61 @@ class Assignment extends Sprite private var working:Bool; private var size:Float; private var interestRate:Float; - - public function new (size:Float, height:Float, color:Int, barWidth:Int, interestRate:Float, workRate:Float){ - super(); - this.color = color; - this.barWidth = barWidth; - this.size = size; - this.interestRate = interestRate; - this.workRate = workRate; - this.y = -height; + public function new(size:Float, height:Float, color:Int, barWidth:Int, interestRate:Float, workRate:Float) { + super(); - working = false; - - rect = new Shape(); - workRect = new Shape(); - workSize = 0; - drawRectangle(rect, size, color); - addChild(rect); - addChild(workRect); + this.color = color; + this.barWidth = barWidth; + this.size = size; + this.interestRate = interestRate; + this.workRate = workRate; + this.y = -height; - this.addEventListener(MouseEvent.MOUSE_DOWN, - function (e:MouseEvent) - {working=true;}); - this.addEventListener(MouseEvent.MOUSE_UP, - function (e:MouseEvent) - {working=false;}); - this.addEventListener(MouseEvent.MOUSE_OUT, - function (e:MouseEvent) - {working=false;}); + working = false; + + rect = new Shape(); + workRect = new Shape(); + workSize = 0; + drawRectangle(rect, size, color); + addChild(rect); + addChild(workRect); + + this.addEventListener(MouseEvent.MOUSE_DOWN, + function(e:MouseEvent) {working = true;}); + this.addEventListener(MouseEvent.MOUSE_UP, + function(e:MouseEvent) {working = false;}); + this.addEventListener(MouseEvent.MOUSE_OUT, + function(e:MouseEvent) {working = false;}); } - private function drawRectangle(shape:Shape, size:Float, color:Int){ - shape.graphics.clear(); - shape.graphics.lineStyle(0); - shape.graphics.beginFill(color, 1); - shape.graphics.drawRect(-Math.round(barWidth/2),-size,barWidth,size); - shape.graphics.endFill(); + private function drawRectangle(shape:Shape, size:Float, color:Int) { + shape.graphics.clear(); + shape.graphics.lineStyle(0); + shape.graphics.beginFill(color, 1); + shape.graphics.drawRect(-Math.round(barWidth / 2), -size, barWidth, size); + shape.graphics.endFill(); } - public function update (gameDate:Date, delta:Float, height:Float):Float {//returns size - accrueInterest(delta); - this.y = -height; - if(working){ - work(delta); - if (workSize>=size){ - size = 0; // This is an indication that the assignment is done - } - } - return size; + public function update(gameDate:Date, delta:Float, height:Float):Float {//returns size + accrueInterest(delta); + this.y = -height; + if (working) { + work(delta); + if (workSize >= size) { + size = 0; // This is an indication that the assignment is done + } + } + return size; } - private function accrueInterest(delta:Float){ - size += interestRate*(delta/(3600*24))*(size-workSize); // only get interest on part that you didn't do yet - drawRectangle(rect, size, color); + private function accrueInterest(delta:Float) { + size += interestRate * (delta / (3600 * 24)) * (size - workSize); // only get interest on part that you didn't do yet + drawRectangle(rect, size, color); } - private function work(delta:Float){ - workSize += workRate*delta/(3600*24); - drawRectangle(workRect, workSize, 0x897ea9); + private function work(delta:Float) { + workSize += workRate * delta / (3600 * 24); + drawRectangle(workRect, workSize, 0x897ea9); } } diff --git a/Source/Bar.hx b/Source/Bar.hx index 186b39c..51020a7 100644 --- a/Source/Bar.hx +++ b/Source/Bar.hx @@ -1,12 +1,13 @@ package; +import Lecture.LectureObject; +import DateTools; import openfl.display.Sprite; import openfl.display.Shape; import openfl.text.TextField; import openfl.events.MouseEvent; -class Bar extends Sprite -{ +class Bar extends Sprite { private var nameHeight = 15; private var barWidth = 20; private var assignments:Array; @@ -15,63 +16,58 @@ class Bar extends Sprite // private var nameField:TextField; private var interestRate:Float; private var workRate:Float; - private var lectures:Array; - private var lectureNum:Int; - private var lectureEndDate:Date; + private var lectures:Lecture.LectureIterator; private var initGameDate:Date; + private var curLecture:LectureObject; private var color:Int; - + // interestRate is the proportion of the total that increases per day - public function new(interestRate:Float, workRate:Float, startHeight:Int, nameStr:String, lectures:Array, gameDate:Date, color:Int=0x000000) { - super(); + public function new(interestRate:Float, workRate:Float, startHeight:Int, nameStr:String, lectures:Lecture.LectureIterator, gameDate:Date, color:Int = 0x000000) { + super(); - this.color = color; + this.color = color; - assignments = new Array(); - heights = new Array(); - heights.push(0); - numAssignments = 0; + assignments = new Array(); + heights = new Array(); + heights.push(0); + numAssignments = 0; - this.interestRate = interestRate; - this.workRate = workRate; - this.lectures = lectures; - lectureNum = 0; - initGameDate = gameDate; - lectureEndDate = Util.jsonTimeToDate(initGameDate, lectures[lectureNum].times.split(" ")[1]); + this.interestRate = interestRate; + this.workRate = workRate; + this.lectures = lectures; + initGameDate = gameDate; + curLecture = lectures.next(); } public function update(gameDate:Date, delta:Float) { - var i:Int = 0; - var size:Float; - // We need a while loop instead of a for loop because numAssignments can change during, and a for loop converts it to a number at the outset - while (i lectureEndDate.getTime()){ - var size = lectures[lectureNum].size; - var assignment = new Assignment(size, heights[numAssignments], color, barWidth, interestRate, workRate); - assignments.push(assignment); - this.addChild(assignment); - lectureNum++; - if (lectureNum < lectures.length){ - lectureEndDate = Util.jsonTimeToDate(initGameDate, lectures[lectureNum].times.split(" ")[1]); - } - numAssignments++; - } - } + private function getHomework(gameDate:Date) { + if (lectures.hasNext() && gameDate.getTime() > curLecture.endTime.getTime()) { + if (curLecture.hw) { + var size = curLecture.weight; + var assignment = new Assignment(size, heights[numAssignments], color, barWidth, interestRate, workRate); + assignments.push(assignment); + this.addChild(assignment); + numAssignments++; + } + curLecture = lectures.next(); + } } } diff --git a/Source/Calendar.hx b/Source/Calendar.hx index f4b11f0..2579672 100644 --- a/Source/Calendar.hx +++ b/Source/Calendar.hx @@ -7,107 +7,106 @@ import haxe.ds.HashMap; class Calendar extends Sprite { - private var cells:HashMap = new HashMap(); - private var weekdayHeight = 15; - private var today:Day; - - private var xOffset:Int; - private var yOffset:Int; - private var cellWidth:Int; - private var cellHeight:Int; - private var rows:Int; - private var endDate:Date; //first date not in calendar - - public function new(width, height, date:Date){ - super(); - today = Day.fromDate(date); - //round down to nearest Sunday to get endDate because nothing in calendar yet - endDate = DateTools.delta(date, -DateTools.days(date.getDay())); - - xOffset = 0; - yOffset = weekdayHeight; - cellWidth = Math.round(width/7); - cellHeight = Math.round((height-weekdayHeight)/2); - rows = 2; - - makeGrid(); - makeWeekdays(); - cells.get(today).backgroundColor = 0xEE5D15; - } + private var cells:HashMap = new HashMap(); + private var weekdayHeight = 15; + private var today:Day; - private function makeRow (rowNum){ - for (j in 0...7){ - - var cell:TextField = new TextField(); - addChild(cell); - - cell.x = xOffset + j*cellWidth; - cell.y = yOffset + rowNum*cellHeight; - cell.text = Std.string(endDate.getDate()); - trace(endDate); - if (endDate.getDate()==1){ - var ms:Array = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; - var m = ms[endDate.getMonth()]; - trace(ms); - trace(m); - cell.text += " "+m; - } - - cell.background = true; - cell.backgroundColor = 0xFFFFFF; - cell.border = true; - cell.borderColor = 0x000000; - cell.width = cellWidth; - cell.height = cellHeight; + private var xOffset:Int; + private var yOffset:Int; + private var cellWidth:Int; + private var cellHeight:Int; + private var rows:Int; + private var endDate:Date; //first date not in calendar - cells.set(Day.fromDate(endDate),cell); + public function new(width, height, date:Date){ + super(); + today = Day.fromDate(date); + //round down to nearest Sunday to get endDate because nothing in calendar yet + endDate = DateTools.delta(date, -DateTools.days(date.getDay())); - endDate = DateTools.delta(endDate, 24*3600*1000);//DateTools.days(1)); + xOffset = 0; + yOffset = weekdayHeight; + cellWidth = Math.round(width/7); + cellHeight = Math.round((height-weekdayHeight)/2); + rows = 2; + + makeGrid(); + makeWeekdays(); + cells.get(today).backgroundColor = 0xEE5D15; } - } - private function makeGrid() - { - for (i in 0...rows){ - makeRow(i); + private function makeRow (rowNum){ + for (j in 0...7){ + + var cell:TextField = new TextField(); + addChild(cell); + + cell.x = xOffset + j*cellWidth; + cell.y = yOffset + rowNum*cellHeight; + cell.text = Std.string(endDate.getDate()); + trace(endDate); + if (endDate.getDate()==1){ + var ms:Array = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; + var m = ms[endDate.getMonth()]; + trace(ms); + trace(m); + cell.text += " "+m; + } + + cell.background = true; + cell.backgroundColor = 0xFFFFFF; + cell.border = true; + cell.borderColor = 0x000000; + cell.width = cellWidth; + cell.height = cellHeight; + + cells.set(Day.fromDate(endDate),cell); + + endDate = DateTools.delta(endDate, 24*3600*1000);//DateTools.days(1)); + } } - } - private function advanceGrid(){ - for (cell in cells){ - if (cell.y <= yOffset){ - removeChild(cell); - } else { - cell.y -= cellHeight; - } + private function makeGrid(){ + for (i in 0...rows){ + makeRow(i); + } } - makeRow(rows-1); - } - private function makeWeekdays() { - var names:Array = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; - for (i in 0...7) { - var weekday:TextField = new TextField(); - addChild(weekday); + private function advanceGrid(){ + for (cell in cells){ + if (cell.y <= yOffset){ + removeChild(cell); + } else { + cell.y -= cellHeight; + } + } + makeRow(rows-1); + } - weekday.text = names[i]; - weekday.x = xOffset + i*cellWidth; - weekday.y = yOffset - 15; + private function makeWeekdays() { + var names:Array = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; + for (i in 0...7) { + var weekday:TextField = new TextField(); + addChild(weekday); + + weekday.text = names[i]; + weekday.x = xOffset + i*cellWidth; + weekday.y = yOffset - 15; + } } - } - public function update(gameDate:Date) { - //trace("hi"); - var day = Day.fromDate(gameDate); - //trace(today.month+" "+today.day); - //trace(day.month+" "+day.day); - if (!today.equals(day)){ - if (gameDate.getDay()==0){ - advanceGrid(); - } - cells.get(day).backgroundColor = 0xEE5D15; - cells.get(today).backgroundColor = 0xFFFFFF; - today=day; + public function update(gameDate:Date) { + //trace("hi"); + var day = Day.fromDate(gameDate); + //trace(today.month+" "+today.day); + //trace(day.month+" "+day.day); + if (!today.equals(day)){ + if (gameDate.getDay()==0){ + advanceGrid(); + } + cells.get(day).backgroundColor = 0xEE5D15; + cells.get(today).backgroundColor = 0xFFFFFF; + today=day; + } } - } } diff --git a/Source/Day.hx b/Source/Day.hx index 24edaba..228d5a1 100644 --- a/Source/Day.hx +++ b/Source/Day.hx @@ -3,22 +3,24 @@ package; class Day { public var month:Int; public var day:Int; + public var year:Int; - public function new (month:Int, day:Int){ - this.month = month; - this.day = day; + public function new (month:Int, day:Int, year:Int){ + this.month = month; + this.day = day; + this.year = year; } public static function fromDate(date:Date){ - return new Day(date.getMonth(), date.getDate()); + return new Day(date.getMonth(), date.getDate(), date.getFullYear()); } public function equals(other:Day){ - return this.hashCode() == other.hashCode(); + return this.hashCode() == other.hashCode(); } - public function hashCode():Int - { - return month*8+day; + + public function hashCode():Int{ + return month*8+day; } } diff --git a/Source/Lecture.hx b/Source/Lecture.hx index d9f9975..8d45a12 100644 --- a/Source/Lecture.hx +++ b/Source/Lecture.hx @@ -1,7 +1,144 @@ package; typedef Lecture = { - var times:String; - var size:Int; + var days:Array; + var start:SSDate; + var end:SSDate; + var homework:Array>; + var project:Int; + var exception:Array; var title:String; -} \ No newline at end of file +} + +typedef LectureDay = { + var weekday:Int; + var time:String; +} + +typedef SSDate = { + var day:Int; + var month:Int; + var year:Int; +} + +class LectureIterator { + private var startDate:Date; + private var endDate:Date; + private var weekdays:Array; + private var times:Array