示例#1
0
    // matches to closests to center of match area (if one exists)
    // TODO: EGM would it be better to give an error and not match if two are in the radius?
    public void match(string devID, string[] fNameAndArgs)
    {
        print("matching");
        Dictionary <string, Track> tracks = openPTrack.getTracks();
        float bestDistSqr = matchRadius * matchRadius;
        Track bestTrack   = null;

        foreach (Track track in tracks.Values)
        {
            Vector3 posLoc  = track.getPosition();
            float   d       = posLoc.x - matchLocationX;
            float   distSqr = d * d;
            d        = posLoc.z - matchLocationZ;
            distSqr += d * d;
            if (distSqr <= bestDistSqr)
            {
                bestDistSqr = distSqr;
                bestTrack   = track;
            }
            else
            {
                print("dist to candidate: " + distSqr.ToString() + " " + track.id + "(x: " + posLoc.x.ToString() + ", z:" + posLoc.z.ToString() + ")");
            }
        }
        if (bestTrack == null)
        {
            print("no match  " + devID);
            string html = "<p = class=\"errorMsg\"><b>Please go to that special spot on the floor and click</b>: " +
                          WebComm.expressionLink("Associate me with a track", "match") + "</p>";
            WebComm.publishHtml(devID, html);
        }
        else
        {
            print("got a match");
            devTrackDict [devID] = bestTrack.id;
            string html = "<p> Select an image to drop from your location (track ID: " + bestTrack.id + "):\n  <ul>";
            foreach (string fname in mediaFiles)
            {
                html += "    <li>";
                // can't use full path because we hit a length limit
                // work around for now
                // better solution add html append in addition to replace
                // and automatically cut up long html strings
                html += WebComm.expressionLink(fname, "drop," + fname);
                html += "</li>\n";
            }
            html += "  </ul>\n</p>\n";
            try {
                WebComm.publishHtml(devID, html);
            } catch (Exception e) {
                Debug.LogError("exception publishign " + html);
                Debug.LogError(e);
            }
            //TODO: come up with better copy EGM
        }
    }