The always-hot wire from the receptacle is spliced to the black wire on the fixture cable, and to a pigtail that connects back to the hot terminal on the receptacle. At the light fixture box, the black is spliced to the black from the switch cable. At the switch box the black wire is connected to the bottom terminal on the new switch.
This page contains wiring diagrams for a service panel breaker box and circuit breakers including: 15amp, 20amp, 30amp and 50amp, as well as a GFCI breaker and an isolated ground circuit.
Back at the source, the white neutral wire is spliced to the white from the fixture cable and to a pigtail, back to the receptacle neutral terminal. At the fixture the white connects to the neutral terminal on the light. The hot terminal on the light is connected to the red wire from the switch loop cable and the other end is connected to the top terminal on the switch.
The plain wire is the hot. If the cord isn’t marked with a bead then the strands of wire will be different colors. In these cases the silver wire is the neutral and the brass colored wire is the hot. The plug on the lamp cord holds another clue to polarity with the wide prong being the neutral and the narrow one the hot. Older lamp cord will have prongs that are the same size. This is because polarity was not observed on electric lamps until the development of grounded circuits.