Skip to content

Commit

Permalink
Merge pull request #29 from uramakilab/dev
Browse files Browse the repository at this point in the history
Update JSON
  • Loading branch information
marcgc21 authored Jul 19, 2023
2 parents b0f2f6a + 4660654 commit 1e57429
Show file tree
Hide file tree
Showing 60 changed files with 1,055 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Editor/API.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions Editor/API/APIService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using UnityEngine;
using UnityEngine.Networking;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Net;
using System.IO;

abstract class APIService {

public static File GetDocument() {
HttpWebRequest request = (HttpWebRequest)WebRequest.Create($"https://api.figma.com/v1/files{Global.documentID}");
request.Headers.Add("Authorization", $"Bearer {Global.token}");
using (HttpWebResponse response = (HttpWebResponse) request.GetResponse()) {
StreamReader reader = new StreamReader(response.GetResponseStream());
string json = reader.ReadToEnd();
Regex regex = new Regex("(|(PositionX)|(PositionY)|(PositionZ)|(RotationX)|(RotationY))#[0-9]+:[0-9]+");
json = regex.Replace(json, "$1");
return JsonUtility.FromJson<File>(json);
}
}

public static string GetImage() {
HttpWebRequest request = (HttpWebRequest)WebRequest.Create($"https://api.figma.com/v1/files{Global.documentID}/images");
request.Headers.Add("Authorization", $"Bearer {Global.token}");
using (HttpWebResponse response = (HttpWebResponse) request.GetResponse()) {
StreamReader reader = new StreamReader(response.GetResponseStream());
return reader.ReadToEnd();
}
}

public static string ContentType(string url) {
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string type = response.ContentType;
return type.Remove(0, type.IndexOf("/")+1);
}

public static bool DownloadImage(string url, string path) {
UnityWebRequest uwr = new UnityWebRequest(url, UnityWebRequest.kHttpVerbGET);
uwr.downloadHandler = new DownloadHandlerFile(path);
uwr.SendWebRequest();
while(!uwr.isDone){}
return uwr.responseCode == 200 ? true : false;
}

public static string GetImageID(string id) {
HttpWebRequest request = (HttpWebRequest)WebRequest.Create($"https://api.figma.com/v1/images{Global.documentID}?ids={id}");
request.Headers.Add("Authorization", "Bearer "+ Global.token);
using (HttpWebResponse response = (HttpWebResponse) request.GetResponse()) {
StreamReader reader = new StreamReader(response.GetResponseStream());
return reader.ReadToEnd();
}
}
}
11 changes: 11 additions & 0 deletions Editor/API/APIService.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Editor/API/JSON.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Editor/API/JSON/File.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Editor/API/JSON/File/Document.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[System.Serializable]
public class Document {
public string id;
public string name;
public string type;
public string scrollBehavior;
public Page[] children;
}
11 changes: 11 additions & 0 deletions Editor/API/JSON/File/Document.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Editor/API/JSON/File/File.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[System.Serializable]
public class File {
public Document document;
public string[] components;
public string[] componentSets;
public string[] schemaVersion;
public string[] styles;
public string name;
public string lastModified;
public string thumbnailUrl;
public string version;
public string role;
public string editorType;
public string linkAccess;
}
11 changes: 11 additions & 0 deletions Editor/API/JSON/File/File.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions Editor/API/JSON/File/ObjectProperty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Collections.Generic;

[System.Serializable]
public class ObjectProperty {
public string id;
public string name;
public bool visible = true;
public string type;
public string scrollBehavior;
public ComponentProperty componentPropertyDefinitions;
public string blendMode;
public ObjectProperty[] children = null;
public Absolute absoluteBoundingBox;
public Absolute absoluteRenderBounds;
public Constraints constraits;
public bool clipsContent;
public Fills[] background;
public Fills[] fills;
public Fills[] strokes;
public float cornerRadius;
public float strokeWeight = 0;
public string storekeAlign;
public Color backgroundColor;
// public LayoutGrids[] layoutGrids;
public ExportSettings[] exportSettings;
public string[] effects;
public string characters;
public Style style;
public int layoutVersion;
public string[] characterStyleOverrides;
public string styleOverrideTable;
public string[] lineTypes;
public int[] lineIndentations;
}
11 changes: 11 additions & 0 deletions Editor/API/JSON/File/ObjectProperty.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Editor/API/JSON/File/Objects.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Editor/API/JSON/File/Objects/Absolute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[System.Serializable]
public class Absolute {
public float x;
public float y;
public float width;
public float height;
}
11 changes: 11 additions & 0 deletions Editor/API/JSON/File/Objects/Absolute.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Editor/API/JSON/File/Objects/Color.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[System.Serializable]
public class Color {
public float r;
public float g;
public float b;
public float a;
}
11 changes: 11 additions & 0 deletions Editor/API/JSON/File/Objects/Color.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Editor/API/JSON/File/Objects/ComponentProperty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[System.Serializable]
public class ComponentProperty {
public PropertyDefinitions PositionX;
public PropertyDefinitions PositionY;
public PropertyDefinitions PositionZ;
public PropertyDefinitions RotationX;
public PropertyDefinitions RotationY;
}
11 changes: 11 additions & 0 deletions Editor/API/JSON/File/Objects/ComponentProperty.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Editor/API/JSON/File/Objects/Contraints.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[System.Serializable]
public class Constraints {
public string vertical;
public string horizontal;
}
11 changes: 11 additions & 0 deletions Editor/API/JSON/File/Objects/Contraints.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Editor/API/JSON/File/Objects/Contrait.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[System.Serializable]
public class Constrait {
public string type;
public string value;
}
11 changes: 11 additions & 0 deletions Editor/API/JSON/File/Objects/Contrait.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Editor/API/JSON/File/Objects/ExportSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[System.Serializable]
public class ExportSettings {
public string suffix;
public string format;
public Constrait constrait;
}
11 changes: 11 additions & 0 deletions Editor/API/JSON/File/Objects/ExportSettings.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Editor/API/JSON/File/Objects/Fills.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[System.Serializable]
public class Fills {
public string blendMode;
public string type;
public bool visible = true;
public string scaleMode;
public string imageRef;
public Color color;
}
11 changes: 11 additions & 0 deletions Editor/API/JSON/File/Objects/Fills.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Editor/API/JSON/File/Objects/PropertyDefinitions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[System.Serializable]
public class PropertyDefinitions{
public string type;
public string defaultValue;
}
11 changes: 11 additions & 0 deletions Editor/API/JSON/File/Objects/PropertyDefinitions.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Editor/API/JSON/File/Objects/PrototypeDevice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[System.Serializable]
public class PrototypeDevice {
public string type;
public Size size;
}
11 changes: 11 additions & 0 deletions Editor/API/JSON/File/Objects/PrototypeDevice.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1e57429

Please sign in to comment.