Ejemplo n.º 1
0
        /// Returns strokes read from the passed .tilt file
        public static List <Stroke> GetStrokesFromTilt(string path)
        {
            var            file = new DiskSceneFileInfo(path, readOnly: true);
            SketchMetadata metadata;

            using (var jsonReader = new JsonTextReader(
                       new StreamReader(
                           SaveLoadScript.GetMetadataReadStream(file))))
            {
                // TODO: should cache this?
                var serializer = new JsonSerializer();
                serializer.ContractResolver = new CustomJsonContractResolver();
                serializer.Error           += (sender, args) =>
                {
                    throw new Exception(args.ErrorContext.Error.Message);
                };
                metadata = serializer.Deserialize <SketchMetadata>(jsonReader);
            }

            using (var stream = file.GetReadStream(TiltFile.FN_SKETCH))
            {
                var bufferedStream = new BufferedStream(stream, 4096);
                return(SketchWriter.GetStrokes(
                           bufferedStream, metadata.BrushIndex, BitConverter.IsLittleEndian));
            }
        }
Ejemplo n.º 2
0
        public void TestMemoryListForSave()
        {
            var input = new List <Stroke>();

            foreach (var flags in new[]
            {
                StrokeFlags.None,
                StrokeFlags.None, StrokeFlags.IsGroupContinue, StrokeFlags.IsGroupContinue,
                StrokeFlags.None, StrokeFlags.IsGroupContinue
            })
            {
                var stroke = new Stroke();
                stroke.m_Flags = flags;
                // TODO: put unit test objects under a common parent
                stroke.m_Object = new GameObject("(unit test)");
                stroke.m_Object.SetActive(true);
                stroke.m_ControlPoints = new PointerManager.ControlPoint[0];
                input.Add(stroke);
            }

            // no erased strokes
            var output = SketchWriter.EnumerateAdjustedSnapshots(input).ToList();

            CollectionAssert.AreEqual(
                output.ConvertAll(x => x.adjustedStrokeFlags),
                new[]
            {
                StrokeFlags.None,
                StrokeFlags.None, StrokeFlags.IsGroupContinue, StrokeFlags.IsGroupContinue,
                StrokeFlags.None, StrokeFlags.IsGroupContinue
            });

            CollectionAssert.AreEqual(
                output.ConvertAll(x => x.adjustedStrokeFlags),
                new[]
            {
                StrokeFlags.None,
                StrokeFlags.None, StrokeFlags.IsGroupContinue, StrokeFlags.IsGroupContinue,
                StrokeFlags.None, StrokeFlags.IsGroupContinue
            });

            // head stroke of group erased
            input[1].m_Object.SetActive(false);
            output = SketchWriter.EnumerateAdjustedSnapshots(input).ToList();
            CollectionAssert.AreEqual(
                output.ConvertAll(x => x.adjustedStrokeFlags),
                new[]
            {
                StrokeFlags.None,
                StrokeFlags.None, StrokeFlags.IsGroupContinue,
                StrokeFlags.None, StrokeFlags.IsGroupContinue
            });

            // secondary stroke of group erased
            input[1].m_Object.SetActive(true);
            input[2].m_Object.SetActive(false);
            output = SketchWriter.EnumerateAdjustedSnapshots(input).ToList();
            CollectionAssert.AreEqual(
                output.ConvertAll(x => x.adjustedStrokeFlags),
                new[]
            {
                StrokeFlags.None,
                StrokeFlags.None, StrokeFlags.IsGroupContinue,
                StrokeFlags.None, StrokeFlags.IsGroupContinue
            });

            // orphaned group (head stroke remaining)
            input[3].m_Object.SetActive(false);
            output = SketchWriter.EnumerateAdjustedSnapshots(input).ToList();
            CollectionAssert.AreEqual(
                output.ConvertAll(x => x.adjustedStrokeFlags),
                new[]
            {
                StrokeFlags.None,
                StrokeFlags.None,
                StrokeFlags.None, StrokeFlags.IsGroupContinue
            });

            // orphaned group (1 secondary stroke remaining)
            input[1].m_Object.SetActive(false);
            input[3].m_Object.SetActive(true);
            output = SketchWriter.EnumerateAdjustedSnapshots(input).ToList();
            CollectionAssert.AreEqual(
                output.ConvertAll(x => x.adjustedStrokeFlags),
                new[]
            {
                StrokeFlags.None,
                StrokeFlags.None,
                StrokeFlags.None, StrokeFlags.IsGroupContinue
            });

            // orphaned group (0 strokes remaining)
            input[3].m_Object.SetActive(false);
            output = SketchWriter.EnumerateAdjustedSnapshots(input).ToList();
            CollectionAssert.AreEqual(
                output.ConvertAll(x => x.adjustedStrokeFlags),
                new[]
            {
                StrokeFlags.None,
                StrokeFlags.None, StrokeFlags.IsGroupContinue
            });
        }