Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3055c85
feat: handling timeline deletion
JeremyMeissner May 6, 2022
7c3170f
chore: doing animation section
JeremyMeissner May 6, 2022
02d75b1
docs: add brand identity
JeremyMeissner May 7, 2022
7adcd6f
feat: shape animation list ui
JeremyMeissner May 9, 2022
3732d3c
Merge branch '5-timeline-implementation' of https://github.com/Jeremy…
JeremyMeissner May 9, 2022
6055621
chore: interpolation implementation
JeremyMeissner May 10, 2022
687c8b4
feat: timeline loop
JeremyMeissner May 11, 2022
25f76b3
refactor: global structure
JeremyMeissner May 11, 2022
1e79797
chore: add camera
JeremyMeissner May 12, 2022
548a88d
chore: change timeline logic
JeremyMeissner May 13, 2022
d5a1681
chore: remove loop/reverse
JeremyMeissner May 14, 2022
672470b
feat: angle supported
JeremyMeissner May 14, 2022
80ad23d
refactor: selector
JeremyMeissner May 15, 2022
029cb93
feat: color importation
JeremyMeissner May 16, 2022
1963b2b
refactor: timeline
JeremyMeissner May 16, 2022
432cd5f
refactor: timeline
JeremyMeissner May 17, 2022
053ccc0
refactor: remove unused code
JeremyMeissner May 18, 2022
a7cea3a
feat: add triangle
JeremyMeissner May 20, 2022
a0814c1
refactor: window class
JeremyMeissner May 23, 2022
6dba92e
chore: change d attr regex
JeremyMeissner May 25, 2022
172e538
chore: update shader
JeremyMeissner May 31, 2022
f520c1d
refactor: Renderer
JeremyMeissner Jun 1, 2022
cc7863c
fix: path drawing problem
JeremyMeissner Jun 2, 2022
e774ed9
chore: serialization
JeremyMeissner Jun 2, 2022
d153021
feat: serialization
JeremyMeissner Jun 2, 2022
860a7d2
fix: import form render
JeremyMeissner Jun 3, 2022
8a6c0b2
refactor: path structure
JeremyMeissner Jun 7, 2022
780e5b3
refactor: whole structure
JeremyMeissner Jun 8, 2022
b37ec4f
fix: picker filter reset
JeremyMeissner Jun 8, 2022
c9d0296
refactor: add comments
JeremyMeissner Jun 8, 2022
b585b8c
chore: remove useless close button
JeremyMeissner Jun 9, 2022
0808cba
refactor: whole structure
JeremyMeissner Jun 9, 2022
3666559
refactor: remove useless using
JeremyMeissner Jun 9, 2022
78bdd4c
Merge branch 'master' into 5-timeline-implementation
JeremyMeissner Jun 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 108 additions & 35 deletions FreeFrame/Components/Importer.cs
Original file line number Diff line number Diff line change
@@ -1,70 +1,143 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FreeFrame.Components.Shapes;
using OpenTK.Mathematics;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using FreeFrame.Components.Shapes;

namespace FreeFrame.Components
{
public static class Importer
{
static public (List<Shape>, bool) ImportFromStream(Stream pStream)
/// <summary>
/// Import shapes list and timeline from a stream
/// </summary>
/// <param name="pStream">Given stream</param>
/// <returns>Shape list and timeline</returns>
/// <exception cref="Exception">If something went wrong in the importation</exception>
static private (List<Shape>, SortedDictionary<int, List<Shape>>, bool) ImportFromStream(Stream pStream)
{
List<Shape> shapes = new List<Shape>();
SortedDictionary<int, List<Shape>> timeline = new SortedDictionary<int, List<Shape>>();
bool compatibilityFlag = false;

Shape? previous = null;

using (XmlReader reader = XmlReader.Create(pStream))
{
while (reader.Read())
try
{
//if (reader.HasAttributes)
while (reader.Read())
{
//Console.WriteLine("Attributes of <" + reader.Name + ">");
switch (reader.Name)
if (reader.HasAttributes)
{
case "xml":
case "svg":
break; // Skip knowned elements
case "polygon":
shapes.Add(new SVGPolygon(reader));
break;
case "path":
shapes.Add(new SVGPath(reader));
break;
case "rect":
shapes.Add(new SVGRectangle(reader));
break;
case "circle":
shapes.Add(new SVGCircle(reader));
break;
case "line":
shapes.Add(new SVGLine(reader));
break;
default:
compatibilityFlag = true; // If an element is unknow, the flag is trigger
break;
switch (reader.Name)
{
case "xml":
case "svg":
break; // Skip knowned elements
case "polygon":
shapes.Add(new SVGPolygon(reader));
previous = shapes.Last();
break;
case "path":
shapes.Add(new SVGPath(reader));
previous = shapes.Last();
break;
case "rect":
shapes.Add(new SVGRectangle(reader));
previous = shapes.Last();
break;
case "circle":
shapes.Add(new SVGCircle(reader));
previous = shapes.Last();
break;
case "line":
shapes.Add(new SVGLine(reader));
previous = shapes.Last();
break;
default:
compatibilityFlag = true; // If an element is unknow, the flag is trigger
break;
}
}

}
}
catch (Exception)
{
throw new Exception("Error while importing");
}
}
return (shapes, compatibilityFlag);
return (shapes, new SortedDictionary<int, List<Shape>>(), compatibilityFlag);
}
static public (List<Shape>, bool) ImportFromFile(string pFilename)

/// <summary>
/// Import shapes list and timeline from a file path
/// </summary>
/// <param name="pFilename">File path</param>
/// <returns>Shape list and timeline</returns>
/// <exception cref="ArgumentException">If file cannot be found</exception>
static public (List<Shape>, SortedDictionary<int, List<Shape>>, bool) ImportFromFile(string pFilename)
{
if (!File.Exists(pFilename))
throw new ArgumentException($"'{pFilename}' file cannot be found.", nameof(pFilename)); // TODO: replace by a simple alert window
throw new ArgumentException($"'{pFilename}' file cannot be found.", nameof(pFilename));

byte[] byteArray = Encoding.UTF8.GetBytes(File.ReadAllText(pFilename));

return ImportFromStream(new MemoryStream(byteArray));
}
static public (List<Shape>, bool) ImportFromString(string pString)

/// <summary>
/// Import shapes list and timeline from a string
/// </summary>
/// <param name="pString">Given string</param>
/// <returns>Shape list and timeline</returns>
static public (List<Shape>, SortedDictionary<int, List<Shape>>, bool) ImportFromString(string pString)
{
byte[] byteArray = Encoding.UTF8.GetBytes(pString);

return ImportFromStream(new MemoryStream(byteArray));
}

/// <summary>
/// Export a given shape list into an svg file
/// </summary>
/// <param name="shapes">Shape list</param>
/// <param name="clientSize">Window size</param>
/// <param name="path">File path</param>
static public void ExportToFile(List<Shape> shapes, Vector2i clientSize, string path)
{
using (FileStream fs = new FileStream(path, FileMode.Create))
{
byte[] bytes = Encoding.ASCII.GetBytes($@"<?xml version=""1.0"" encoding=""utf-8"" ?>
<svg xmlns=""http://www.w3.org/2000/svg"" version=""1.1"" width=""{clientSize.X}"" height=""{clientSize.Y}"" >" + Environment.NewLine);

for (int i = 0; i < bytes.Length; i++)
fs.WriteByte(bytes[i]);

foreach (Shape shape in shapes)
{
bytes = Encoding.ASCII.GetBytes(shape.ToString() + Environment.NewLine);
for (int i = 0; i < bytes.Length; i++)
fs.WriteByte(bytes[i]);
}
bytes = Encoding.ASCII.GetBytes("</svg>");
for (int i = 0; i < bytes.Length; i++)
fs.WriteByte(bytes[i]);
}
}

/// <summary>
/// Convert from a string to an Color4 value
/// </summary>
/// <param name="hexadecimal">hexadecimal string</param>
/// <returns>Color4 value</returns>
static public Color4 HexadecimalToRGB(string hexadecimal)
{
float r = Convert.ToInt32(hexadecimal.Substring(1, 2), 16) / 255f;
float g = Convert.ToInt32(hexadecimal.Substring(3, 2), 16) / 255f;
float b = Convert.ToInt32(hexadecimal.Substring(5, 2), 16) / 255f;
float a = Convert.ToInt32(hexadecimal.Substring(7, 2), 16) / 255f;
return new Color4(r, g, b, a);
}
}
}
43 changes: 0 additions & 43 deletions FreeFrame/Components/Shapes/Hitbox.cs

This file was deleted.

Loading