示例#1
0
    static public void LoadRoomDataFromItsFile(RoomData rd)
    {
        // First, make empty buckets of all PropDatas.
        rd.ClearAllPropDataLists();

        // Load the file!
        string[] roomFile = GetRoomFileAsStringArray(rd.WorldIndex, rd.RoomKey);

        // NULL room file...
        if (roomFile == null)
        {
            AddEmptyRoomElements(ref rd);
        }
        // There IS a room file!...
        else
        {
            debug_roomDataLoadingRoomKey = rd.RoomKey;             // for printing to console.
            foreach (string lineString in roomFile)
            {
                if (lineString == "")
                {
                    continue;                                   // If this line is EMPTY, skip it!
                }
                int affectNameEndIndex = lineString.IndexOf(' ');
                if (affectNameEndIndex == -1)
                {
                    continue;
                }                                                         // Wrong formatting!
                string affectName       = lineString.Substring(0, affectNameEndIndex);
                string propertiesString = lineString.Substring(affectNameEndIndex + 1);
                // Room Properties
                if (affectName == ROOM_PROPERTIES)
                {
                    SetRoomPropertyFieldValuesFromFieldsString(rd, propertiesString);
                }
                // Props!
                else
                {
                    PropData propData = GetNewPropDataFromAffectName(affectName);
                    if (propData == null)                       // Safety check.
                    {
                        Debug.LogError("Oops! Unidentifiable text in room file: " + rd.RoomKey + ". Text: \"" + lineString + "\"");
                        continue;
                    }
                    SetPropDataFieldValuesFromFieldsString(propData, propertiesString);
                    rd.AddPropData(propData);
                }
            }
        }
    }