Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reformat code. #5

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1,571 changes: 748 additions & 823 deletions lib/flare.dart

Large diffs are not rendered by default.

308 changes: 145 additions & 163 deletions lib/flare/actor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,172 +13,154 @@ import "stream_reader.dart";
import "block_types.dart";
import "actor_artboard.dart";

class Actor
{
int maxTextureIndex = 0;
int _version = 0;
int _artboardCount = 0;
List<ActorArtboard> _artboards;

Actor();

ActorArtboard get artboard => _artboards.length > 0 ? _artboards.first : null;

int get version
{
return _version;
}

int get texturesUsed
{
return maxTextureIndex + 1;
}

void copyActor(Actor actor)
{
maxTextureIndex = actor.maxTextureIndex;
_artboardCount = actor._artboardCount;
if(_artboardCount > 0)
{
int idx = 0;
_artboards = new List<ActorArtboard>(_artboardCount);
for(ActorArtboard artboard in actor._artboards)
{
if(artboard == null)
{
_artboards[idx++] = null;
continue;
}
ActorArtboard instanceArtboard = artboard.makeInstance();
_artboards[idx++] = instanceArtboard;
}
}
}

ActorArtboard makeArtboard()
{
return new ActorArtboard(this);
}

ActorImage makeImageNode()
{
return new ActorImage();
}

ActorPath makePathNode()
{
return new ActorPath();
}
ActorShape makeShapeNode()
{
return new ActorShape();
}
ActorRectangle makeRectangle()
{
return new ActorRectangle();
class Actor {
int maxTextureIndex = 0;
int _version = 0;
int _artboardCount = 0;
List<ActorArtboard> _artboards;

Actor();

ActorArtboard get artboard => _artboards.length > 0 ? _artboards.first : null;

int get version {
return _version;
}

int get texturesUsed {
return maxTextureIndex + 1;
}

void copyActor(Actor actor) {
maxTextureIndex = actor.maxTextureIndex;
_artboardCount = actor._artboardCount;
if (_artboardCount > 0) {
int idx = 0;
_artboards = new List<ActorArtboard>(_artboardCount);
for (ActorArtboard artboard in actor._artboards) {
if (artboard == null) {
_artboards[idx++] = null;
continue;
}
ActorArtboard instanceArtboard = artboard.makeInstance();
_artboards[idx++] = instanceArtboard;
}
}
ActorTriangle makeTriangle()
{
return new ActorTriangle();
}

ActorArtboard makeArtboard() {
return new ActorArtboard(this);
}

ActorImage makeImageNode() {
return new ActorImage();
}

ActorPath makePathNode() {
return new ActorPath();
}

ActorShape makeShapeNode() {
return new ActorShape();
}

ActorRectangle makeRectangle() {
return new ActorRectangle();
}

ActorTriangle makeTriangle() {
return new ActorTriangle();
}

ActorStar makeStar() {
return new ActorStar();
}

ActorPolygon makePolygon() {
return new ActorPolygon();
}

ActorEllipse makeEllipse() {
return new ActorEllipse();
}

ColorFill makeColorFill() {
return new ColorFill();
}

ColorStroke makeColorStroke() {
return new ColorStroke();
}

GradientFill makeGradientFill() {
return new GradientFill();
}

GradientStroke makeGradientStroke() {
return new GradientStroke();
}

RadialGradientFill makeRadialFill() {
return new RadialGradientFill();
}

RadialGradientStroke makeRadialStroke() {
return new RadialGradientStroke();
}

void load(ByteData data) {
if (data.lengthInBytes < 5) {
throw new UnsupportedError("Not a valid Flare file.");
}
ActorStar makeStar()
{
return new ActorStar();
int F = data.getUint8(0);
int L = data.getUint8(1);
int A = data.getUint8(2);
int R = data.getUint8(3);
int E = data.getUint8(4);

dynamic inputData = data;

if (F != 70 || L != 76 || A != 65 || R != 82 || E != 69) {
Uint8List charCodes = data.buffer.asUint8List();
String stringData = String.fromCharCodes(charCodes);
var jsonActor = jsonDecode(stringData);
Map jsonObject = new Map();
jsonObject["container"] = jsonActor;
inputData = jsonObject;
}
ActorPolygon makePolygon()
{
return new ActorPolygon();

StreamReader reader = new StreamReader(inputData);
_version = reader.readVersion();

StreamReader block;
while ((block = reader.readNextBlock(BlockTypesMap)) != null) {
switch (block.blockType) {
case BlockTypes.Artboards:
readArtboardsBlock(block);
break;
}
}
ActorEllipse makeEllipse()
{
return new ActorEllipse();
}

void readArtboardsBlock(StreamReader block) {
int artboardCount = block.readUint16Length();
_artboards = new List<ActorArtboard>(artboardCount);

for (int artboardIndex = 0, end = _artboards.length; artboardIndex < end;
artboardIndex++) {
StreamReader artboardBlock = block.readNextBlock(BlockTypesMap);
if (artboardBlock == null) {
break;
}
switch (artboardBlock.blockType) {
case BlockTypes.ActorArtboard:
{
ActorArtboard artboard = makeArtboard();
artboard.read(artboardBlock);
_artboards[artboardIndex] = artboard;
break;
}
}
}
ColorFill makeColorFill()
{
return new ColorFill();
}
ColorStroke makeColorStroke()
{
return new ColorStroke();
}
GradientFill makeGradientFill()
{
return new GradientFill();
}
GradientStroke makeGradientStroke()
{
return new GradientStroke();
}
RadialGradientFill makeRadialFill()
{
return new RadialGradientFill();
}
RadialGradientStroke makeRadialStroke()
{
return new RadialGradientStroke();
}

void load(ByteData data)
{
if(data.lengthInBytes < 5)
{
throw new UnsupportedError("Not a valid Flare file.");
}
int F = data.getUint8(0);
int L = data.getUint8(1);
int A = data.getUint8(2);
int R = data.getUint8(3);
int E = data.getUint8(4);

dynamic inputData = data;

if(F != 70 || L != 76 || A != 65 || R != 82 || E != 69)
{
Uint8List charCodes = data.buffer.asUint8List();
String stringData = String.fromCharCodes(charCodes);
var jsonActor = jsonDecode(stringData);
Map jsonObject = new Map();
jsonObject["container"] = jsonActor;
inputData = jsonObject;
}

StreamReader reader = new StreamReader(inputData);
_version = reader.readVersion();

StreamReader block;
while((block=reader.readNextBlock(BlockTypesMap)) != null)
{
switch(block.blockType)
{
case BlockTypes.Artboards:
readArtboardsBlock(block);
break;
}
}
}

void readArtboardsBlock(StreamReader block)
{
int artboardCount = block.readUint16Length();
_artboards = new List<ActorArtboard>(artboardCount);

for(int artboardIndex = 0, end = _artboards.length; artboardIndex < end; artboardIndex++)
{
StreamReader artboardBlock = block.readNextBlock(BlockTypesMap);
if(artboardBlock == null)
{
break;
}
switch(artboardBlock.blockType)
{
case BlockTypes.ActorArtboard:
{
ActorArtboard artboard = makeArtboard();
artboard.read(artboardBlock);
_artboards[artboardIndex] = artboard;
break;
}
}
}
}
}
}
Loading