コード例 #1
0
        private void PartModified(LDrawPrimitive part)
        {
            PluginLoader.Log("part modified!");
            if (!(part is LDrawPart))
            {
                return;
            }

            LDrawPart modifiedPart = part as LDrawPart;

            if (customBrickData.ContainsKey(modifiedPart) == false)
            {
                return;
            }

            PluginLoader.Log("Part modified! " + customBrickData[modifiedPart].myID);
        }
コード例 #2
0
        private void ProcessAddBrickRequest(HttpListenerRequest req, HttpListenerResponse resp)
        {
            resp.StatusCode = 200;

            PluginLoader.Log("Processing add brick request...");

            if (CheckForQueryParamExistance("brickTypeID", req, resp) == false)
            {
                return;
            }
            if (CheckForQueryParamExistance("systemID", req, resp) == false)
            {
                return;
            }
            if (CheckForQueryParamExistance("color", req, resp) == false)
            {
                return;
            }
            if (CheckForQueryParamExistance("x", req, resp) == false)
            {
                return;
            }
            if (CheckForQueryParamExistance("y", req, resp) == false)
            {
                return;
            }
            if (CheckForQueryParamExistance("z", req, resp) == false)
            {
                return;
            }
            if (CheckForQueryParamExistance("rx", req, resp) == false)
            {
                return;
            }
            if (CheckForQueryParamExistance("ry", req, resp) == false)
            {
                return;
            }
            if (CheckForQueryParamExistance("rz", req, resp) == false)
            {
                return;
            }

            long systemID = 0;

            if (long.TryParse(req.QueryString["systemID"], out systemID) == false)
            {
                resp.StatusCode = 500;
                resp.OutputStream.WriteString("systemID is not a long!");

                return;
            }

            var exisitngPartsWithTheID = customBrickData.Where(p => p.Value.myID == systemID);

            if (exisitngPartsWithTheID.Any())
            {
                int removals = 0;
                foreach (var brick in exisitngPartsWithTheID.Select(p => p.Key).ToList())
                {
                    if (customBrickData.ContainsKey(brick))
                    {
                        customBrickData.Remove(brick);
                    }
                    BLStudio.Instance.removeBrick(brick);
                    removals++;
                }
                resp.OutputStream.WriteString("Removed " + removals + " bricks on brick add");
            }

            var partToAdd = new LDrawPart(req.QueryString["brickTypeID"] + ".dat");

            if (partToAdd == null)
            {
                resp.StatusCode = 500;
                resp.OutputStream.WriteString("brickTypeID not found!");

                return;
            }

            Color newColor;

            if (ColorUtility.TryParseHtmlString(req.QueryString["color"], out newColor) == false)
            {
                resp.StatusCode = 500;
                resp.OutputStream.WriteString("color is not a color!");

                return;
            }

            Vector3 newBrickPosition = new Vector3(
                float.Parse(req.QueryString["x"]),
                float.Parse(req.QueryString["y"]),
                float.Parse(req.QueryString["z"]));

            Vector3 newBrickRotation = new Vector3(
                float.Parse(req.QueryString["rx"]),
                float.Parse(req.QueryString["ry"]),
                float.Parse(req.QueryString["rz"]));

            partToAdd.TransformMatrix = Matrix4x4.TRS(newBrickPosition, Quaternion.Euler(newBrickRotation), Vector3.one);
            BLStudio.Instance.changeBrickColor(partToAdd, ColorLibrary.Instance.getSimilarColorCodeForColor_RGB(newColor));
            BLStudio.Instance.addBrick(partToAdd);

            customBrickData.Add(partToAdd, new CustomBrickDataComponent()
            {
                myID = systemID
            });
        }