public override PassageCode PassageToCode(PassageData passage)
        {
            _input  = passage;
            _output = new PassageCode();

            // Ignore script and stylesheet passages
            if (passage.Tags.Contains("script") || passage.Tags.Contains("stylesheet"))
            {
                _output.Main = "yield break;";
                return(_output);
            }

            Code     = new GeneratedCode();
            NoOutput = false;
            if (passage.Tags.Contains("nobr"))
            {
                Code.Collapsed = true;
            }

            MatchCollection matches = rx_PassageBody.Matches(_input.Body);

            GenerateBody(matches);

            // Get final string
            string code = Code.Buffer.ToString();

            _output.Main = code;

            return(_output);
        }
Exemple #2
0
    public void SetPassageData(PassageData _data)
    {
        if (_data == null)
        {
            return;
        }

        data = _data;
        gameObject.SetActive(false);
    }
        public static List <PassageData> getPassagesfromUrls(HashSet <string> urls)
        {
            List <PassageData> allPD = new List <PassageData>();


            ISearchServiceClient serviceClient = new SearchServiceClient("passageranker", new SearchCredentials("61438B42BF9E15FB1FBAAA6963C3FCB8"));
            ISearchIndexClient   indexClient   = serviceClient.Indexes.GetClient("techpassagesdata");

            HashSet <string> aids = new HashSet <string>();

            foreach (var item in urls)
            {
                CategoryMatchField urlfields = new CategoryMatchField(UrlJoinHelper.geturlmatchfields(item.ToLower()));
                string             key       = urlfields.category + ":" + urlfields.matchfield;
                string             filter    = "urlcategory eq '" + urlfields.category + "' and urlmatchfield eq '" + urlfields.matchfield + "'";
                SearchParameters   parameters;
                DocumentSearchResult <PassageData> results;
                parameters =
                    new SearchParameters()
                {
                    Filter = filter
                };

                string test = "";
                results = indexClient.Documents.Search <PassageData>(test, parameters);
                foreach (var item2 in results.Results)
                {
                    PassageData pd = new PassageData();
                    try
                    {
                        pd.Url              = item2.Document.Url;
                        pd.FinalTitle       = item2.Document.FinalTitle;
                        pd.FinalTitleQASKey = item2.Document.FinalTitleQASKey;
                        pd.HtmlHeadTitle    = item2.Document.HtmlHeadTitle;
                        pd.PassageId        = item2.Document.PassageId;
                        pd.RawAnswer        = item2.Document.RawAnswer;
                        pd.RootQueries      = item2.Document.RootQueries;
                        pd.RubatoAnswer     = item2.Document.RubatoAnswer;
                        pd.Urlcategory      = item2.Document.Urlcategory;
                        pd.Urlmatchfield    = item2.Document.Urlmatchfield;

                        allPD.Add(pd);
                    }
                    catch (Exception e)
                    {
                    }
                }
            }

            return(allPD);
        }
        public static PassageData getPassagefromAnswerId(string AnswerId)
        {
            List <PassageData> allPD = new List <PassageData>();

            ISearchServiceClient serviceClient = new SearchServiceClient("passageranker", new SearchCredentials("61438B42BF9E15FB1FBAAA6963C3FCB8"));
            ISearchIndexClient   indexClient   = serviceClient.Indexes.GetClient("techpassagesdata");

            string           filter = "passageId eq '" + AnswerId + "'";
            SearchParameters parameters;
            DocumentSearchResult <PassageData> results;

            parameters =
                new SearchParameters()
            {
                Filter = filter
            };

            string test = "";

            results = indexClient.Documents.Search <PassageData>(test, parameters);
            foreach (var item2 in results.Results)
            {
                PassageData pd = new PassageData();
                try
                {
                    pd.Url              = item2.Document.Url;
                    pd.FinalTitle       = item2.Document.FinalTitle;
                    pd.FinalTitleQASKey = item2.Document.FinalTitleQASKey;
                    pd.HtmlHeadTitle    = item2.Document.HtmlHeadTitle;
                    pd.PassageId        = item2.Document.PassageId;
                    pd.RawAnswer        = item2.Document.RawAnswer;
                    pd.RootQueries      = item2.Document.RootQueries;
                    pd.RubatoAnswer     = item2.Document.RubatoAnswer;
                    pd.Urlcategory      = item2.Document.Urlcategory;
                    pd.Urlmatchfield    = item2.Document.Urlmatchfield;

                    allPD.Add(pd);
                }
                catch (Exception e)
                {
                }
            }


            //always returns the first
            return(allPD.First());
        }
Exemple #5
0
    /// <summary>
    /// UI상에 복도를 추가적으로 배치한다.
    /// </summary>
    /// <param name="_pass">복도 정보</param>
    /// <param name="_name">복도 이름</param>
    public void AddPassage(PassageData _pass, string _name = "passage")
    {
        // 시작과 끝을 기준으로 방향을 확인함
        // 시작과 끝, 간격을 기준으로 생성
        GameObject    ob = Instantiate(uiObject, transform);
        RectTransform rectTr = ob.GetComponent <RectTransform>();
        Pos           senter = new Pos(mapsize.x / 2, mapsize.y / 2);
        float         x, y;

        if (rectTr == null)
        {
            Debug.Log("생성된 오브젝트의 RectTransform이 존재하지 않습니다.");
            return;

            //rectTr = ob.AddComponent<RectTransform>();
        }

        x = (_pass.from.x + _pass.to.x) * 0.5f;
        y = (_pass.from.y + _pass.to.y) * 0.5f;

        if (_pass.from.x != _pass.to.x)
        {
            rectTr.sizeDelta = (new Vector2(interSize, interSize / 2));
        }
        else if (_pass.from.y != _pass.to.y)
        {
            rectTr.sizeDelta = (new Vector2(interSize / 2, interSize));
        }
        else
        {
            Destroy(ob);
            return;
        }

        x = (x - senter.x) * (interSize * 2);
        y = (y - senter.y) * (interSize * 2);

        rectTr.localPosition = new Vector3(x, y, 0);
        ob.AddComponent <MinimapSell>();
        ob.name = _name;

        isUpdate = true;
    }
Exemple #6
0
        public override PassageCode PassageToCode(PassageData p)
        {
            if (p is HarlowePassageData == false)
            {
                throw new NotSupportedException("HarloweTranscoder called with incompatible passage data");
            }

            StyleCounter = 0;

            _input  = (HarlowePassageData)p;
            _output = new PassageCode();
            Code    = new GeneratedCode();

            GenerateBody(_input.Tokens);

            // Get final string
            string code = Code.Buffer.ToString();

            _output.Main = code;

            return(_output);
        }
Exemple #7
0
        public PassageData GetCoordinates(string authToken, string passageGuid)
        {
            if (authToken != null)
            {
                var pkg = new GetStatistic {
                    token = authToken, passage_guid = passageGuid
                };
                var httpClient = new HttpClient {
                    Timeout = new TimeSpan(0, 0, 10, 0)
                };
                var json                = JsonConvert.SerializeObject(pkg);
                var httpContent         = new StringContent(json, Encoding.UTF8, "application/json");
                var httpResponseMessage = httpClient.PostAsync(PPConfig.EndPointAdress + "statistics", httpContent).Result;
                if (httpResponseMessage.StatusCode == HttpStatusCode.OK)
                {
                    string contents = httpResponseMessage.Content.ReadAsStringAsync().Result;
                    var    result   = JsonConvert.DeserializeObject <PassageData>(contents);
                    _sensors = result;
                    //var res = new PassageData();
                    //double step = result.LocationTimestamp.Count / 500.0;
                    //if (step <= 1)
                    //{
                    //    res.LocationTimestamp = result.LocationTimestamp;
                    //    res.LocationLat = result.LocationLat;
                    //    res.LocationLng = result.LocationLng;
                    //}
                    //else
                    //{
                    //    for (double i = 0; i < result.LocationTimestamp.Count; i += step)
                    //    {
                    //        res.LocationTimestamp.Add(result.LocationTimestamp[(int)i]);
                    //        res.LocationLat.Add(result.LocationLat[(int)i]);
                    //        res.LocationLng.Add(result.LocationLng[(int)i]);
                    //    }
                    //}

                    //step = result.AccTimestamp.Count / 500.0;
                    //if (step <= 1)
                    //{
                    //    res.AccTimestamp = result.AccTimestamp;
                    //    res.AccX = result.AccX;
                    //    res.AccY = result.AccY;
                    //    res.AccZ = result.AccZ;
                    //}
                    //else
                    //{
                    //    for (double i = 0; i < result.AccTimestamp.Count; i += step)
                    //    {
                    //        res.AccTimestamp.Add(result.AccTimestamp[(int)i]);
                    //        res.AccX.Add(result.AccX[(int)i]);
                    //        res.AccY.Add(result.AccY[(int)i]);
                    //        res.AccZ.Add(result.AccZ[(int)i]);
                    //    }
                    //}

                    //step = result.GyroTimestamp.Count / 500.0;
                    //if (step <= 1)
                    //{
                    //    res.GyroTimestamp = result.GyroTimestamp;
                    //    res.GyroX = result.GyroX;
                    //    res.GyroY = result.GyroY;
                    //    res.GyroZ = result.GyroZ;
                    //}
                    //else
                    //{
                    //    for (double i = 0; i < result.GyroTimestamp.Count; i += step)
                    //    {
                    //        res.GyroTimestamp.Add(result.GyroTimestamp[(int)i]);
                    //        res.GyroX.Add(result.GyroX[(int)i]);
                    //        res.GyroY.Add(result.GyroY[(int)i]);
                    //        res.GyroZ.Add(result.GyroZ[(int)i]);
                    //    }
                    //}

                    //step = result.LightTimestamp.Count / 500.0;
                    //if (step <= 1)
                    //{
                    //    res.LightTimestamp = result.LightTimestamp;
                    //    res.LightIntensity = result.LightIntensity;
                    //}
                    //else
                    //{
                    //    for (double i = 0; i < result.LightTimestamp.Count; i += step)
                    //    {
                    //        res.LightTimestamp.Add(result.LightTimestamp[(int)i]);
                    //        res.LightIntensity.Add(result.LightIntensity[(int)i]);
                    //    }
                    //}
                    return(result);
                }
            }

            return(new PassageData());
        }
Exemple #8
0
        public void ParseToStream(string name, string tweeSource, StreamWriter output)
        {
            // ------------------------------------
            // Step 1: do the parsing

            MatchCollection matches = rx_Passages.Matches(tweeSource);
            _vars = new Dictionary<string, string>();
            _passages = new PassageData[matches.Count];

            for (int i = 0; i < matches.Count; i++)
            {
                Match m = matches[i];

                _passages[i] = new PassageData()
                {
                    Name = m.Groups["name"].Value,
                    Tags = ParseTags(m.Groups["tags"].Value),
                    Code = ParseContent(m.Groups["content"].Value.Trim())
                };

                if (_passages[i].Code == null || _passages[i].Code.Trim().Length == 0)
                    _passages[i].Code = "yield break;";
            }
            string[] vars = _vars.Keys.ToArray();

            // ------------------------------------
            // Step 2: generate the code

            output.Write(
            @"/*
            Generated by UnityTwine on {0}
            https://github.com/daterre/UnityTwine
            */
            using UnityEngine;
            using System.Collections;
            using System.Collections.Generic;
            using UnityTwine;

            public class {1}: TwineStory
            {{"
            , DateTime.Now.ToString("G"), name);

            for (int i = 0; i < vars.Length; i++)
                output.Write(@"
            public TwineVar {0};", vars[i]);

            output.Write(@"
            public override TwineVar this[string name]
            {
            get
            {
            switch(name)
            {"
            );
            for (int i = 0; i < vars.Length; i++)
                output.Write(@"
                case ""{0}"": return {0};", vars[i]);

            output.Write(@"
                default: throw new KeyNotFoundException(string.Format(""There is no variable with the name '{0}'."", name));
            }
            }
            set
            {
            switch(name)
            {"
            );
            for (int i = 0; i < vars.Length; i++)
                output.Write(@"
                case ""{0}"": {0} = value; break;", vars[i]);

            output.Write(@"
                default: throw new KeyNotFoundException(string.Format(""There is no variable with the name '{0}'."", name));
            }
            }
            }
            ");

            output.Write(@"

            void Awake() {
            base.Init();"
            );
            for (int i = 0; i < _passages.Length; i++)
                output.Write(@"
            passageInit_{0}();"
                    , i);

            output.Write(@"
            }");

            for (int i = 0; i < _passages.Length; i++)
            {
                PassageData passage = _passages[i];
                output.Write(@"

            // .............
            // #{0}: {1}

            void passageInit_{0}()
            {{
            this.Passages[""{1}""] = new TwinePassage(""{1}"", new string[]{{ {2} }}, passageExecute_{0});
            }}

            IEnumerable<TwineOutput> passageExecute_{0}()
            {{
            {3}
            }}"
                , i, passage.Name, passage.Tags, passage.Code.Replace("\n", "\n\t\t"));
            }

            output.Write(@"

            }"
                );
        }
Exemple #9
0
        public void ParseToStream(string name, string tweeSource, StreamWriter output)
        {
            // ------------------------------------
            // Step 1: do the parsing

            MatchCollection matches = rx_Passages.Matches(tweeSource);

            _vars     = new Dictionary <string, string>();
            _passages = new PassageData[matches.Count];

            for (int i = 0; i < matches.Count; i++)
            {
                Match m = matches[i];

                _passages[i] = new PassageData()
                {
                    Name = m.Groups["name"].Value,
                    Tags = ParseTags(m.Groups["tags"].Value),
                    Code = ParseContent(m.Groups["content"].Value.Trim())
                };

                if (_passages[i].Code == null || _passages[i].Code.Trim().Length == 0)
                {
                    _passages[i].Code = "yield break;";
                }
            }
            string[] vars = _vars.Keys.ToArray();

            // ------------------------------------
            // Step 2: generate the code

            output.Write(
                @"/*
Generated by UnityTwine on {0}
https://github.com/daterre/UnityTwine
*/
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityTwine;

public class {1}: TwineStory
{{"
                , DateTime.Now.ToString("G"), name);

            for (int i = 0; i < vars.Length; i++)
            {
                output.Write(@"
	public TwineVar {0};"    , vars[i]);
            }

            output.Write(@"
	public override TwineVar this[string name]
	{
		get
		{
			switch(name)
			{"
                         );
            for (int i = 0; i < vars.Length; i++)
            {
                output.Write(@"
				case ""{0}"": return {0};"                , vars[i]);
            }

            output.Write(@"
				default: throw new KeyNotFoundException(string.Format(""There is no variable with the name '{0}'."", name));
			}
		}
		set
		{
			switch(name)
			{"
                         );
            for (int i = 0; i < vars.Length; i++)
            {
                output.Write(@"
				case ""{0}"": {0} = value; break;"                , vars[i]);
            }

            output.Write(@"
				default: throw new KeyNotFoundException(string.Format(""There is no variable with the name '{0}'."", name));
			}
		}
	}
");

            output.Write(@"

	void Awake() {
		base.Init();"
                         );
            for (int i = 0; i < _passages.Length; i++)
            {
                output.Write(@"
		passageInit_{0}();"
                             , i);
            }

            output.Write(@"
	}"    );

            for (int i = 0; i < _passages.Length; i++)
            {
                PassageData passage = _passages[i];
                output.Write(@"
    
	// .............
	// #{0}: {1}

	void passageInit_{0}()
	{{
		this.Passages[""{1}""] = new TwinePassage(""{1}"", new string[]{{ {2} }}, passageExecute_{0});
	}}

	IEnumerable<TwineOutput> passageExecute_{0}()
	{{
		{3}	
	}}"
                             , i, passage.Name, passage.Tags, passage.Code.Replace("\n", "\n\t\t"));
            }

            output.Write(@"

}"
                         );
        }
    // ---------- 추가된 함수
    //강제로 방붙이기(1x1칸 기준)
    void CompulsTheRoomAtCreating(int _roomnum, Pos _last)
    {
        //탐색
        List <Pos> checkList  = new List <Pos>();
        Pos        stoppos    = new Pos();
        Pos        currentpos = new Pos(_last.x, _last.y);
        Pos        savepos    = new Pos();

        checkList.Add(currentpos);

        while (checkList.Count > 0)
        {
            currentpos = checkList[0];
            checkList.RemoveAt(0);

            if (CheckTheEmptymap(_roomnum, currentpos, out stoppos))
            {
                if (isDebug)
                {
                    Debug.Log("Find LastRoom Spot! CompulsTheRoomAtCreating(" + stoppos.x + ", " + stoppos.y + ")");
                }
                checkList.Clear();
                break;
            }

            for (int i = 0; i < 4; ++i)
            {
                SelectPlusMius(out savepos.x, out savepos.y, i);
                checkList.Add(new Pos(currentpos.x + savepos.x, currentpos.y + savepos.y));
            }

            savepos.Reset();
            stoppos.Reset();
            currentpos.Reset();
        }

        if (currentpos.isNull())
        {
            if (isDebug)
            {
                Debug.Log("fail CompulsTheRoomAtCreating()");
            }
            return;
        }

        savepos = CheckTheObjectHaveRoomScript(roomObjects[_roomnum]).size;
        roomObjects[_roomnum].GetComponent <Room>().mapPos = new Pos(stoppos.x, stoppos.y);

        PassageData pass = new PassageData();

        pass.from = new Pos(currentpos.x, currentpos.y);        // from
        pass.to   = new Pos(stoppos.x, stoppos.y);              // to
        passageInfo.Add(pass);
        if (isDebug)
        {
            Debug.Log("Last PassageData From" + pass.from.StringPos() + " To" + pass.to.StringPos());
        }

        for (int x = 0; x < savepos.x; ++x)
        {
            for (int y = 0; y < savepos.y; ++y)
            {
                map[stoppos.x + x, stoppos.y + y] = _roomnum;
            }
        }
    }
    //방을 랜덤으로 위치 시키기
    void SettingRandomPosForMap()
    {
        //필요한 데이터 선언 및 초기화
        Pos newpos    = new Pos();
        Pos senter    = new Pos();
        Pos lastpos   = new Pos();
        int select    = -1;
        int roomcount = 0;
        Pos getRoomSize;

        List <int>  nonselectnum = new List <int>(); //선택되지 않은 방번호를 담는다
        List <Pos>  checkList    = new List <Pos>();
        PassageData pass         = null;

        for (int s = 0; s < roomObjects.Length - 1; ++s)
        {
            nonselectnum.Add(s);        //모든 방번호를 담는다.(처음과 끝을 제외한)
        }
        //MapUI에게 방사이즈를 보낸다.
        if (MapUI.instance != null)
        {
            MapUI.instance.SetMapSize(mapSize);
        }

        // 처음방 설정
        nonselectnum.RemoveAt(0);                        //'0'을 가진 리스트항목을 지운다.
        senter.x = (int)(mapSize.x / 2);
        senter.y = (int)(mapSize.y / 2);
        roomObjects[0].GetComponent <Room>().mapPos = new Pos(senter.x, senter.y);
        checkList.Clear();

        getRoomSize = CheckTheObjectHaveRoomScript(roomObjects[0]).size;
        if (getRoomSize == null)
        {
            return;
        }

        for (int x = 0; x < getRoomSize.x; ++x)
        {
            for (int y = 0; y < getRoomSize.y; ++y)
            {
                //맵 중앙 좌표에 시작방 번호를 담는다.
                map[senter.x + x, senter.y + y] = 0;
                ++roomcount;

                //시작 방이 이어질 방의 갯수에 따라 담는다.
                checkList.Add(new Pos(senter.x + x, senter.y + y));
                checkList.Add(new Pos(senter.x + x, senter.y + y));
                checkList.Add(new Pos(senter.x + x, senter.y + y));
            }
        }

        #region 방 랜덤배치 설명
        // 0. 랜덤값, 중앙좌표를 비롯한 사용될 변수를 초기화한다.
        // 1. 큐의 맨 위에 것을 꺼내 그 위치를 중앙좌표으로 삼는다.
        // 2. (0,1) (0,-1) (1,0) (-1,0) 중 하나의 값을 받아온다
        // 3. 중앙좌표에 나온 좌표를 더한 값을 좌표로 선택된 방번호를 맵에 담는다.
        // 3-1. 만약 이미 그 좌표에 값이 존재한다면 <1로 돌아간다>
        // 3-2. 근접하는 방의 갯수에 따라 생성여부를 확인해도 된다.
        // 3-3. 이때 이어지는 방끼리 통로를 잇는다.
        // 4. 이미 사용된 방번호는 확인리스트에서 제외한다.
        // 5. 이어질 방 갯수에 따라 해당 방번호를 여러개 큐에 담는다. (0~3)
        #endregion

        //큐가 비어있으면 혹은 스테이지 최대갯수를 넘기면(미설정) 루프를 종료한다.
        while (checkList.Count > 0 && nonselectnum.Count > 0 && roomcount < maxRoomCount)
        {
            // <0>
            select = -1;
            newpos.Reset();
            senter.Reset();

            select = nonselectnum[Random.Range(0, nonselectnum.Count)];

            // <1>
            senter = checkList[0];
            if (senter.isNull())
            {
                continue;                   //받아온 좌표가 없으면
            }
            checkList.RemoveAt(0);

            if (!CheckTheEmptymap(select, senter, out newpos))
            {
                continue;
            }

            // <4>
            getRoomSize = CheckTheObjectHaveRoomScript(roomObjects[select]).size;
            if (getRoomSize == null)
            {
                continue;
            }

            //map[newpos.x, newpos.y] = select; <5>번과정에서 합류
            roomObjects[select].GetComponent <Room>().mapPos = new Pos(newpos.x, newpos.y);
            nonselectnum.Remove(select);

            lastpos.x = newpos.x;
            lastpos.y = newpos.y;

            // < 3.3>
            pass      = new PassageData();
            pass.from = new Pos(senter.x, senter.y); // from
            pass.to   = new Pos(newpos.x, newpos.y); // to
            passageInfo.Add(pass);                   // 3.1 때문에 중복되는 통로가 생기지 않는다.
            if (isDebug)
            {
                Debug.Log("PassageData From" + pass.from.StringPos() + " To" + pass.to.StringPos());
            }

            // < 수정 부분 >
            // <5>
            for (int x = 0; x < getRoomSize.x; ++x)
            {
                for (int y = 0; y < getRoomSize.y; ++y)
                {
                    map[newpos.x + x, newpos.y + y] = select;
                    ++roomcount;

                    for (int random = Random.Range(1, 3); random > 0; --random)
                    {
                        checkList.Add(new Pos(newpos.x + x, newpos.y + y));
                    }
                }
            }
        }
        // <추가된 코드>
        CompulsTheRoomAtCreating(roomObjects.Length - 1, lastpos);
    }