public static void FSaveCurrent(DATA_PP_Dif dif) { string path = Application.dataPath + "/FILE_IO/PocketPasser/" + dif.mName + ".txt"; StreamWriter sw = new StreamWriter(path); sw.WriteLine("Difficulty:" + dif.mName); sw.WriteLine("Pocket Scale:" + dif.mPocketScale); sw.WriteLine("TIME_BETWEEN_TARGET_CHANGES:" + dif.mTimeBetweenTargetChanges); sw.WriteLine("NUM_TURRETS:" + dif.mNumTurrets); foreach (Vector3 spot in dif.mTurretSpots) { sw.WriteLine(UT_Strings.FConvertVecToString(spot)); } sw.WriteLine("TURRET_FIRE_RATE:" + dif.mTurretFireRate); sw.WriteLine("NUM_TARGETS:" + dif.mNumTargets); foreach (Vector3 spot in dif.mTargetSpots) { sw.WriteLine(UT_Strings.FConvertVecToString(spot)); } foreach (Vector3 scale in dif.mTargetScales) { sw.WriteLine(UT_Strings.FConvertVecToString(scale)); } sw.WriteLine("BRONZE:" + dif.mBronzeTrophy); sw.WriteLine("SILVER:" + dif.mSilverTrophy); sw.WriteLine("GOLD:" + dif.mGoldTrophy); sw.Close(); }
// Reads in the play and sets everything up. public void ReadInPlay(string sPlayName) { // gonna try and use a streamreader StreamReader sReader = new StreamReader(Application.dataPath + "/Plays/EditorCreatedPlays/" + sPlayName + ".txt"); string sLine = string.Empty; while ((sLine = sReader.ReadLine()) != null) { // use this line to set up our players. Vector3 posOnField = cEdMan.mFootballField.transform.position; string sSpot = UT_Strings.StartAndEndString(sLine, '[', ']'); string sSpotX = UT_Strings.StartAndEndString(sSpot, '[', ','); sSpotX = UT_Strings.DeleteMultipleChars(sSpotX, "[,"); string sSpotZ = UT_Strings.StartAndEndString(sSpot, ',', ']'); sSpotZ = UT_Strings.DeleteMultipleChars(sSpotZ, ",]"); // first place the athlete, on the very center of the field. posOnField.x = cEdMan.mFootballField.transform.position.x; posOnField.y = cEdMan.mFootballField.transform.position.y; // now move the athlete, based on our yards to pixels conversion. float pxToYrd = 53.34f / cEdMan.mFootballField.GetComponent <RectTransform>().rect.width; posOnField.x += float.Parse(sSpotX) * pxToYrd; posOnField.y += float.Parse(sSpotZ) * pxToYrd; posOnField.z = 0f; RT_Player ply = Instantiate(cEdMan.PF_Player, posOnField, cEdMan.mFootballField.transform.rotation); ply.mTag = sLine.Substring(0, sLine.IndexOf(':')); } }
public static void FSaveSet(DATA_RP_Set set) { string sPath = Application.dataPath + "/FILE_IO/PitchAndCatch/" + set.mName + ".txt"; StreamWriter sw = new StreamWriter(sPath); sw.WriteLine("SET FOR PITCH AND CATCH"); sw.WriteLine("NAME"); sw.WriteLine(set.mName); sw.WriteLine("THROW TIME"); sw.WriteLine(set.mTimeToThrow); sw.WriteLine("PC SPOT"); sw.WriteLine(UT_Strings.FConvertVecToString(set.mPCSpot)); sw.WriteLine("RECEIVER DATA"); sw.WriteLine(set.mReceiverData.Count); for (int i = 0; i < set.mReceiverData.Count; i++) { sw.WriteLine(set.mReceiverData[i].mTag); sw.WriteLine(set.mReceiverData[i].mRoute); sw.WriteLine(UT_Strings.FConvertVecToString(set.mReceiverData[i].mStartPos)); } sw.WriteLine("RING DATA"); sw.WriteLine(set.mRingData.Count); foreach (DATA_RP_Ring r in set.mRingData) { sw.WriteLine(r.mTag); sw.WriteLine(UT_Strings.FConvertVecToString(r.mScale)); sw.WriteLine(UT_Strings.FConvertVecToString(r.mDir)); sw.WriteLine(UT_Strings.FConvertVecToString(r.mStartPos)); } sw.Close(); }
public static void FLOAD_ROUTES() { Debug.Log("Loading/Reloading routes"); string sPath = Application.dataPath + "/FILE_IO/Plays/Routes/"; string[] fPathNames = Directory.GetFiles(sPath, "*.txt"); mRoutes = new DATA_Route[fPathNames.Length]; for (int j = 0; j < mRoutes.Length; j++) { StreamReader sr = new StreamReader(fPathNames[j]); string sLine = string.Empty; DATA_Route rt = new DATA_Route(); rt.mName = sr.ReadLine(); rt.mSpots = new Vector2[int.Parse(sr.ReadLine())]; for (int i = 0; i < rt.mSpots.Length; i++) { sLine = sr.ReadLine(); rt.mSpots[i] = UT_Strings.FGetVecFromString(sLine); } sr.Close(); mRoutes[j] = rt; } }
public static DATA_PP_Dif FLoadDifficulty(string sName) { string sPath = Application.dataPath + "/FILE_IO/PocketPasser/" + sName + ".txt"; DATA_PP_Dif dif = new DATA_PP_Dif(); StreamReader sr = new StreamReader(sPath); string sLine = sr.ReadLine(); int k = sLine.IndexOf(':') + 1; dif.mName = sLine.Substring(k); sLine = sr.ReadLine(); k = sLine.IndexOf(':') + 1; dif.mPocketScale = UT_Strings.FGetVec3FromString(sLine.Substring(k)); sLine = sr.ReadLine(); k = sLine.IndexOf(':') + 1; dif.mTimeBetweenTargetChanges = float.Parse(sLine.Substring(k)); sLine = sr.ReadLine(); k = sLine.IndexOf(':') + 1; dif.mNumTurrets = int.Parse(sLine.Substring(k)); dif.mTurretSpots = new Vector3[dif.mNumTurrets]; for (int i = 0; i < dif.mNumTurrets; i++) { sLine = sr.ReadLine(); dif.mTurretSpots[i] = UT_Strings.FGetVec3FromString(sLine); // Debug.Log(dif.mTurretSpots[i]); } sLine = sr.ReadLine(); k = sLine.IndexOf(':') + 1; dif.mTurretFireRate = float.Parse(sLine.Substring(k)); sLine = sr.ReadLine(); k = sLine.IndexOf(':') + 1; dif.mNumTargets = int.Parse(sLine.Substring(k)); dif.mTargetScales = new Vector3[dif.mNumTargets]; dif.mTargetSpots = new Vector3[dif.mNumTargets]; for (int i = 0; i < dif.mNumTargets; i++) { sLine = sr.ReadLine(); dif.mTargetSpots[i] = UT_Strings.FGetVec3FromString(sLine); } for (int i = 0; i < dif.mNumTargets; i++) { sLine = sr.ReadLine(); dif.mTargetScales[i] = UT_Strings.FGetVec3FromString(sLine); } sLine = sr.ReadLine(); k = sLine.IndexOf(':') + 1; dif.mBronzeTrophy = int.Parse(sLine.Substring(k)); sLine = sr.ReadLine(); k = sLine.IndexOf(':') + 1; dif.mSilverTrophy = int.Parse(sLine.Substring(k)); sLine = sr.ReadLine(); k = sLine.IndexOf(':') + 1; dif.mGoldTrophy = int.Parse(sLine.Substring(k)); return(dif); }
/**************************************************************************************** * Takes a string with data for the route, converts it to actual positions. ************************************************************************************** */ public void ReceiveRoute(string sRoute, Vector3 snapPoint) { mPath = new List <Vector3>(); string sCopy = sRoute; while (true) { if (!sRoute.Contains("(") || !sRoute.Contains(")")) { break; } // get the next spot string sNode = UT_Strings.StartAndEndString(sRoute, '(', ')'); // break the spot down into its two positions. string nodeX = UT_Strings.StartAndEndString(sNode, '(', ','); nodeX = nodeX.Replace("(", ""); nodeX = nodeX.Replace(",", ""); string nodeY = UT_Strings.StartAndEndString(sNode, ',', ')'); nodeY = nodeY.Replace(",", ""); nodeY = nodeY.Replace(")", ""); //myString = Regex.Replace(myString, @"[;,\t\r ]|[\n]{2}", "\n"); Vector3 vSpot = new Vector3(); vSpot.x = float.Parse(nodeX); vSpot.z = float.Parse(nodeY); // needs to be z or they'll try to move upwards. mPath.Add(vSpot); // skip ahead to the next position sRoute = sRoute.Substring(sRoute.IndexOf(')') + 1); } // now we set the starting position, relative to the "snap point" passed in. if (!sCopy.Contains("[") || !sCopy.Contains("]")) { Debug.Log("No start position found\n"); return; } string sSpot = UT_Strings.StartAndEndString(sCopy, '[', ']'); string xSpot = UT_Strings.StartAndEndString(sSpot, '[', ','); xSpot = xSpot.Replace("[", ""); xSpot = xSpot.Replace(",", ""); string ySpot = UT_Strings.StartAndEndString(sSpot, ',', ']'); ySpot = ySpot.Replace(",", ""); ySpot = ySpot.Replace("]", ""); mStartPos = transform.position; mStartPos.x = float.Parse(xSpot) + snapPoint.x; mStartPos.z = float.Parse(ySpot) + snapPoint.z; transform.position = mStartPos; }
public static DATA_RP_Set FLoadSet(string sName) { string sPath = Application.dataPath + "/FILE_IO/PitchAndCatch/" + sName + ".txt"; string[] sLines = System.IO.File.ReadAllLines(sPath); DATA_RP_Set s = new DATA_RP_Set(); s.mReceiverData = new List <DATA_RP_Receiver>(); s.mRingData = new List <DATA_RP_Ring>(); for (int i = 0; i < sLines.Length; i++) { if (sLines[i].Contains("NAME")) { s.mName = sLines[i + 1]; } if (sLines[i].Contains("THROW")) { s.mTimeToThrow = float.Parse(sLines[i + 1]); } if (sLines[i].Contains("PC")) { s.mPCSpot = UT_Strings.FGetVec3FromString(sLines[i + 1]); } if (sLines[i].Contains("RECEIVER")) { int num = int.Parse(sLines[i + 1]); int ind = i + 2; for (int j = 0; j < num; j++) { DATA_RP_Receiver r = new DATA_RP_Receiver(); r.mTag = sLines[ind++]; r.mRoute = sLines[ind++]; r.mStartPos = UT_Strings.FGetVec3FromString(sLines[ind++]); s.mReceiverData.Add(r); } } if (sLines[i].Contains("RING")) { int num = int.Parse(sLines[i + 1]); int ind = i + 2; for (int j = 0; j < num; j++) { DATA_RP_Ring r = new DATA_RP_Ring(); r.mTag = sLines[ind++]; r.mScale = UT_Strings.FGetVec3FromString(sLines[ind++]); r.mDir = UT_Strings.FGetVec3FromString(sLines[ind++]); r.mStartPos = UT_Strings.FGetVec3FromString(sLines[ind++]); s.mRingData.Add(r); } } } return(s); }
public static void FWriteSet(DT_RP_Set set) { // ------------------------- ERROR Checking if (set.mName == "NAME ME") { Debug.Log("ERROR. No name given"); return; } if (set.mHoops.Count != set.mRecs.Count || set.mRecs.Count != set.mRoutes.Count) { Debug.Log("ERROR. Number of receivers, hoops, and routes do not match"); return; } Debug.Log("Things should be saving"); // Huh, I kind of want to not have to give unique names all the time. StreamWriter sw = new StreamWriter(Application.dataPath + "/FILE_IO/RoutePasser/" + set.mName + ".txt"); sw.WriteLine("NAME"); sw.WriteLine(set.mName); sw.WriteLine("Num Recs:"); sw.WriteLine(set.mRecs.Count); // You know, I really might as well just straight up write all at once. for (int i = 0; i < set.mRecs.Count; i++) { sw.WriteLine(UT_Strings.FConvertVecToString(set.mRecs[i].mStart)); sw.WriteLine(set.mRecs[i].mTag); } sw.WriteLine("Num Hoops:"); sw.WriteLine(set.mHoops.Count); for (int i = 0; i < set.mHoops.Count; i++) { sw.WriteLine(UT_Strings.FConvertVecToString(set.mHoops[i].mStart)); sw.WriteLine(set.mHoops[i].mSize); sw.WriteLine(set.mHoops[i].mTag); } sw.WriteLine("Num Routes:"); sw.WriteLine(set.mRoutes.Count); for (int i = 0; i < set.mRoutes.Count; i++) { sw.WriteLine(set.mRoutes[i].mOwner); sw.WriteLine(set.mRoutes[i].mSpots.Count); for (int j = 0; j < set.mRoutes[i].mSpots.Count; j++) { sw.WriteLine(UT_Strings.FConvertVecToString(set.mRoutes[i].mSpots[j])); } } sw.Close(); }
private void SetUpPlay() { GE_PLY_Restart.Raise(null); //if we've already instantiated players, delete them for (int i = 0; i < mRoutes.Count; i++) { Destroy(mRoutes[i].gameObject); } for (int i = 0; i < mDefenders.Count; i++) { Destroy(mDefenders[i].gameObject); } mRoutes = new List <AI_Route>(); string path = Application.dataPath + "/Plays/"; if (mLoadFromEditorFolder) { path += "EditorCreatedPlays/"; } path += mOffPlayName + ".txt"; StreamReader sReader = new StreamReader(path); string sLine = string.Empty; while ((sLine = sReader.ReadLine()) != null) { var clone = Instantiate(RefAthlete, transform.position, transform.rotation); clone.GetComponent <AI_Route>().ReceiveRoute(sLine, mSnapSpot.transform.position); clone.GetComponent <AI_Athlete>().mTag = UT_Strings.StartAndEndString(sLine, ':'); // Debug.Log("Tag: " + clone.GetComponent<AI_Athlete>().mTag); if (clone.GetComponent <AI_Athlete>().mTag.Contains("G")) { Destroy(clone); continue; } mRoutes.Add(clone.GetComponent <AI_Route>()); } // Now we set up the defenders. mDefenders = new List <AI_ZoneDefence>(); sReader = new StreamReader(Application.dataPath + "/Plays/Defense/" + mDefPlayName + ".txt"); sLine = string.Empty; while ((sLine = sReader.ReadLine()) != null) { var clone = Instantiate(PF_Defender, transform.position, transform.rotation); clone.GetComponent <AI_ZoneDefence>().ReceivePlayAssignment(sLine, mSnapSpot.transform.position); mDefenders.Add(clone.GetComponent <AI_ZoneDefence>()); } }
// given at the start of the play. public void ReceivePlayAssignment(string sAssign, Vector3 snapPoint) { // our starting alignment first. string sLineup = UT_Strings.StartAndEndString(sAssign, '[', ']'); string sXStart = UT_Strings.StartAndEndString(sLineup, '[', ','); sXStart = sXStart.Replace("[", ""); sXStart = sXStart.Replace(",", ""); string sYStart = UT_Strings.StartAndEndString(sLineup, ',', ']'); sYStart = sYStart.Replace(",", ""); sYStart = sYStart.Replace("]", ""); Vector3 lSpot = new Vector3(); lSpot.x = float.Parse(sXStart) + snapPoint.x; lSpot.z = float.Parse(sYStart) + snapPoint.z; lSpot.y = 1f; transform.position = lSpot; // our zone position second string sPos = UT_Strings.StartAndEndString(sAssign, '(', ')'); string sXPos = UT_Strings.StartAndEndString(sPos, '(', ','); sXPos = sXPos.Replace(",", ""); sXPos = sXPos.Replace("(", ""); string sYPos = UT_Strings.StartAndEndString(sPos, ',', ')'); sYPos = sYPos.Replace(",", ""); sYPos = sYPos.Replace(")", ""); Vector3 vSpot = new Vector3(); vSpot.x = float.Parse(sXPos); vSpot.z = float.Parse(sYPos); vSpot.y = 0f; mZoneSpot = vSpot + transform.position; }
// I still want this to return a valid new formation every time, not a reference to the already loaded one. Subject to change. public static DATA_Formation FLOAD_FORMATION(string sName) { string sPath = Application.dataPath + "/FILE_IO/Formations/" + sName + ".txt"; string[] sLines = System.IO.File.ReadAllLines(sPath); DATA_Formation f = new DATA_Formation(); for (int i = 0; i < sLines.Length; i++) { if (sLines[i].Contains("NUM PLAY")) { int numPlayers = int.Parse(sLines[i + 1]); f.mTags = new string[numPlayers]; f.mSpots = new Vector2[numPlayers]; } } for (int i = 0; i < sLines.Length; i++) { if (sLines[i].Contains("NAME")) { f.mName = sLines[i + 1]; } if (sLines[i].Contains("POSITIONS AND")) { int ind = i + 1; for (int j = 0; j < f.mTags.Length; j++) { f.mTags[j] = sLines[ind++]; f.mSpots[j] = UT_Strings.FGetVecFromString(sLines[ind++]); } } } return(f); }
public static void FWRITE_FORMATION(DATA_Formation f) { if (f.mSpots.Length != f.mTags.Length) { Debug.Log("ERROR SAVING FORMATION, spot tag length mismatch"); return; } string sName = f.mName; StreamWriter sw = new StreamWriter(Application.dataPath + "/FILE_IO/Formations/" + sName + ".txt"); sw.WriteLine("NAME"); sw.WriteLine(f.mName); sw.WriteLine("NUM PLAYERS"); sw.WriteLine(f.mSpots.Length); sw.WriteLine("POSITIONS AND TAGS"); for (int i = 0; i < f.mSpots.Length; i++) { sw.WriteLine(f.mTags[i]); sw.WriteLine(UT_Strings.FConvertVecToString(f.mSpots[i])); } sw.Close(); }
public static void FWritePlay(DATA_OffPlay p) { // ----------------------------------- First do some error checking to make sure the play is valid. if (p.mName == "NAME ME") { Debug.Log("ERROR. This play must be given a unique name"); return; } // Should also check against a list of valid tags. eg. RB1 valid, NO_TAG not valid. foreach (string s in p.mRoles) { if (s == "NO ROLE") { Debug.Log("ERROR. One or more players without a role"); return; } } foreach (string s in p.mTags) { if (s == "NO TAG") { Debug.Log("ERROR. One or more players without a tag"); return; } } if (p.mRoles.Length != p.mTags.Length) { Debug.Log("ERROR. Tag/Role length mismatches"); Debug.Log("Num tags: " + p.mTags.Length); Debug.Log("Num Roles: " + p.mRoles.Length); return; } foreach (DATA_ORoute r in p.mRoutes) { bool ownerValid = false; foreach (string s in p.mTags) { if (s == r.mOwner) { ownerValid = true; } } if (!ownerValid) { Debug.Log("ERROR. One or more routes does not have a valid owner."); Debug.Log("OWNER: " + r.mOwner); } } // ---------------------------------- Save to disc string sName = p.mName; StreamWriter sw = new StreamWriter(Application.dataPath + "/FILE_IO/OffensivePlays/" + sName + ".txt"); sw.WriteLine("NAME"); sw.WriteLine(p.mName); sw.WriteLine("FORMATION"); sw.WriteLine(p.mFormation); sw.WriteLine("NUM PLAYERS"); sw.WriteLine(p.mTags.Length); for (int i = 0; i < p.mTags.Length; i++) { sw.WriteLine(p.mTags[i]); sw.WriteLine(p.mRoles[i]); } sw.WriteLine("NUM RECEIVERS"); sw.WriteLine(p.mRoutes.Count); sw.WriteLine("ROUTES"); for (int i = 0; i < p.mRoutes.Count; i++) { sw.WriteLine(p.mRoutes[i].mOwner); sw.WriteLine("NUM SPOTS"); sw.WriteLine(p.mRoutes[i].mSpots.Count); for (int j = 0; j < p.mRoutes[i].mSpots.Count; j++) { sw.WriteLine(UT_Strings.FConvertVecToString(p.mRoutes[i].mSpots[j])); } } sw.Close(); }
public static DATA_OffPlay FLoadPlay(string name) { string path = Application.dataPath + "/FILE_IO/OffensivePlays/" + name + ".txt"; string[] sLines = System.IO.File.ReadAllLines(path); DATA_OffPlay p = new DATA_OffPlay(); for (int i = 0; i < sLines.Length; i++) { if (sLines[i].Contains("NUM PLAYERS")) { int numPlayers = int.Parse(sLines[i + 1]); p.mTags = new string[numPlayers]; p.mRoles = new string[numPlayers]; } } for (int i = 0; i < sLines.Length; i++) { if (sLines[i].Contains("NAME")) { p.mName = sLines[i + 1]; } if (sLines[i].Contains("FORMATION")) { p.mFormation = sLines[i + 1]; } if (sLines[i].Contains("NUM PLAYERS")) { int ix = i + 2; for (int j = 0; j < p.mTags.Length; j++) { p.mTags[j] = sLines[ix++]; p.mRoles[j] = sLines[ix++]; } } if (sLines[i].Contains("NUM RECEIVERS")) { int num = int.Parse(sLines[i + 1]); int ix = i + 3; for (int j = 0; j < num; j++) { DATA_ORoute r = new DATA_ORoute(); r.mOwner = sLines[ix++]; ix++; // skip over NUM SPOTS line int numSpots = int.Parse(sLines[ix++]); r.mSpots = new List <Vector2>(); for (int k = 0; k < numSpots; k++) { Vector2 v = UT_Strings.FGetVecFromString(sLines[ix++]); r.mSpots.Add(v); } p.mRoutes.Add(r); } } } return(p); }
public static DT_RP_Set FLoadSet(string name) { string path = Application.dataPath + "/FILE_IO/RoutePasser/" + name + ".txt"; string[] sLines = System.IO.File.ReadAllLines(path); DT_RP_Set set = new DT_RP_Set(); for (int i = 0; i < sLines.Length; i++) { if (sLines[i].Contains("NAME")) { set.mName = sLines[i + 1]; } if (sLines[i].Contains("Num Recs")) { int numRecs = int.Parse(sLines[i + 1]); int ix = i + 2; for (int j = 0; j < numRecs; j++) { DT_RP_Rec r = new DT_RP_Rec(); r.mStart = UT_Strings.FGetVec3FromString(sLines[ix++]); r.mTag = sLines[ix++]; set.mRecs.Add(r); } } if (sLines[i].Contains("Num Hoops")) { int numHoops = int.Parse(sLines[i + 1]); int ix = i + 2; for (int j = 0; j < numHoops; j++) { DT_RP_Hoop h = new DT_RP_Hoop(); h.mStart = UT_Strings.FGetVec3FromString(sLines[ix++]); h.mSize = float.Parse(sLines[ix++]); h.mTag = sLines[ix++]; set.mHoops.Add(h); } } if (sLines[i].Contains("Num Routes")) { int numRoutes = int.Parse(sLines[i + 1]); int ix = i + 2; for (int j = 0; j < numRoutes; j++) { DATA_ORoute r = new DATA_ORoute(); r.mOwner = sLines[ix++]; int numSpots = int.Parse(sLines[ix++]); r.mSpots = new List <Vector2>(); for (int k = 0; k < numSpots; k++) { Vector2 v = UT_Strings.FGetVecFromString(sLines[ix++]); r.mSpots.Add(v); } set.mRoutes.Add(r); } } } return(set); }